mirror of
https://gitlab.com/camelot/kickc.git
synced 2025-02-22 13:29:18 +00:00
Restructured code in new packages
This commit is contained in:
parent
32a2c9eb2b
commit
92747454c7
@ -4,9 +4,9 @@ import dk.camelot64.kickc.asm.AsmProgram;
|
|||||||
import dk.camelot64.kickc.icl.*;
|
import dk.camelot64.kickc.icl.*;
|
||||||
import dk.camelot64.kickc.parser.KickCLexer;
|
import dk.camelot64.kickc.parser.KickCLexer;
|
||||||
import dk.camelot64.kickc.parser.KickCParser;
|
import dk.camelot64.kickc.parser.KickCParser;
|
||||||
|
import dk.camelot64.kickc.passes.*;
|
||||||
import org.antlr.v4.runtime.*;
|
import org.antlr.v4.runtime.*;
|
||||||
|
|
||||||
import java.io.IOException;
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
package dk.camelot64.kickc.icl;
|
package dk.camelot64.kickc;
|
||||||
|
|
||||||
/** Parser for converting literal numbers to the corresponding Java Integer/Double */
|
/** Parser for converting literal numbers to the corresponding Java Integer/Double */
|
||||||
public class NumberParser {
|
public class NumberParser {
|
@ -1,7 +1,6 @@
|
|||||||
Features
|
Features
|
||||||
- Move the main code into a main() function, and disallow code outside functions. The main function per default has no parameters and exits with RTS.
|
- Move the main code into a main() function, and disallow code outside functions. The main function per default has no parameters and exits with RTS.
|
||||||
- Add a for loop for(init;condition;increment) {stmt} -> { init; do { stmt; increment } while (condition) }
|
- Add a for loop for(init;condition;increment) {stmt} -> { init; do { stmt; increment } while (condition) }
|
||||||
- Implement Register Allocation (that utilize real registers - and non-zeropage memory)
|
|
||||||
- Add Fixed Point number types
|
- Add Fixed Point number types
|
||||||
- Add imports
|
- Add imports
|
||||||
- Add structs
|
- Add structs
|
||||||
@ -13,9 +12,27 @@ Features
|
|||||||
- Add an export keyword ensuring that a function is generated even if it is never called. Maybe export can be handled by generating a call that can be used as stub.
|
- Add an export keyword ensuring that a function is generated even if it is never called. Maybe export can be handled by generating a call that can be used as stub.
|
||||||
- Add inline ASM (maybe?)
|
- Add inline ASM (maybe?)
|
||||||
- Handle long branches
|
- Handle long branches
|
||||||
|
- Allow complex array expressions in lValues eg. (SCREEN+$100)[idx]
|
||||||
+ Create a proper main function for the compiler
|
+ Create a proper main function for the compiler
|
||||||
+ Add ++/-- incrementing/decrementing operators.
|
+ Add ++/-- incrementing/decrementing operators.
|
||||||
|
|
||||||
|
Register Allocation
|
||||||
|
- Matrix Phi operation (instead of separate statements)
|
||||||
|
- Safe-Copy based SSA deconstruction
|
||||||
|
- Optimize phi transitions by ensuring that identical phi-transitions with regards to register allocation are collected into a single transition.
|
||||||
|
- Optimize by finding optimal sequence for multiple phi assignments in entry-segments.
|
||||||
|
- Phi Lifting
|
||||||
|
- Interval Analysis (variable liveness intervals)
|
||||||
|
- PhiLifting & PhiMemCoalesce (http://compilers.cs.ucla.edu/fernando/projects/soc/reports/short_tech.pdf)
|
||||||
|
- ComputeLoopNestDepth(b) - Assign loop nesting levels to blocks.
|
||||||
|
- ComputeRegisterPreference(v), ComputeWeight(v)
|
||||||
|
- CalculateClobbering(i)
|
||||||
|
- Maybe support several fragements for the same operation with different cost and clobbering profiles.
|
||||||
|
- Register types: A, X, Y, ZP, (memory).
|
||||||
|
- Maybe register preference should also incorporate the types of operations that can be effectively performed with the register? (Maybe based on fragment cost?)
|
||||||
|
- Implement a register allocation (coloring) algorithm using by liveness intervals, preferences, weights & clobbering information.
|
||||||
|
- Optimize register allocation by combining with knowledge of ASM program cost (bytes/cycles) and different ASM fragments with different clobbering.
|
||||||
|
|
||||||
Process/Code Structure Improvement
|
Process/Code Structure Improvement
|
||||||
- Make each phase return a separate object graph (allowing for keeeping the history in memory & performing rollbacks)
|
- Make each phase return a separate object graph (allowing for keeeping the history in memory & performing rollbacks)
|
||||||
- Refactor Expression Operator Implementation & Evaluation into one class per operator
|
- Refactor Expression Operator Implementation & Evaluation into one class per operator
|
||||||
@ -31,10 +48,8 @@ Testing
|
|||||||
+ Test the ASM program output resulting from compiling specific KC program input.
|
+ Test the ASM program output resulting from compiling specific KC program input.
|
||||||
|
|
||||||
Optimizations
|
Optimizations
|
||||||
- Optimize phi transitions by ensuring that identical phi-transitions with regards to register allocation are collected into a single transition.
|
|
||||||
- Optimize register allocation by combining with knowledge of ASM program cost (bytes/cycles) and different ASM fragments with different clobbering.
|
|
||||||
- Optimize by finding optimal sequence for multiple phi assignments in entry-segments.
|
|
||||||
- Optimize by allowing resequencing of statements and phi assignemtns in a final phase. Perhaps by converting phi statements to "normal" statements and using some optimization step.
|
- Optimize by allowing resequencing of statements and phi assignemtns in a final phase. Perhaps by converting phi statements to "normal" statements and using some optimization step.
|
||||||
|
- This phase could also help simplify LDA xx, CMP#0, BNE by expressing these in a language where CMP can be eliminated before.
|
||||||
|
|
||||||
Usages
|
Usages
|
||||||
- Implement library for memory allocation in main memory
|
- Implement library for memory allocation in main memory
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
package dk.camelot64.kickc.asm;
|
package dk.camelot64.kickc.asm;
|
||||||
|
|
||||||
|
import dk.camelot64.kickc.NumberParser;
|
||||||
import dk.camelot64.kickc.asm.parser.Asm6502BaseVisitor;
|
import dk.camelot64.kickc.asm.parser.Asm6502BaseVisitor;
|
||||||
import dk.camelot64.kickc.asm.parser.Asm6502Lexer;
|
import dk.camelot64.kickc.asm.parser.Asm6502Lexer;
|
||||||
import dk.camelot64.kickc.asm.parser.Asm6502Parser;
|
import dk.camelot64.kickc.asm.parser.Asm6502Parser;
|
||||||
@ -9,7 +10,6 @@ import org.antlr.v4.runtime.*;
|
|||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
import java.net.URL;
|
import java.net.URL;
|
||||||
import java.util.HashMap;
|
|
||||||
import java.util.LinkedHashMap;
|
import java.util.LinkedHashMap;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
package dk.camelot64.kickc.asm;
|
package dk.camelot64.kickc.asm;
|
||||||
|
|
||||||
import dk.camelot64.kickc.icl.NumberParser;
|
import dk.camelot64.kickc.NumberParser;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
|
@ -1,4 +1,7 @@
|
|||||||
package dk.camelot64.kickc.icl;
|
package dk.camelot64.kickc.asm;
|
||||||
|
|
||||||
|
import dk.camelot64.kickc.icl.PointerDereference;
|
||||||
|
import dk.camelot64.kickc.icl.RegisterAllocation;
|
||||||
|
|
||||||
/** A dereferenced ZP pointer to a byte */
|
/** A dereferenced ZP pointer to a byte */
|
||||||
public class PointerDereferenceRegisterZpByte implements PointerDereference {
|
public class PointerDereferenceRegisterZpByte implements PointerDereference {
|
@ -16,7 +16,13 @@ public class ConstantInteger implements Constant {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public SymbolType getType() {
|
public SymbolType getType() {
|
||||||
return Pass1TypeInference.inferType(this);
|
SymbolType type;
|
||||||
|
if (getNumber() < 256) {
|
||||||
|
type = SymbolTypeBasic.BYTE;
|
||||||
|
} else {
|
||||||
|
type = SymbolTypeBasic.WORD;
|
||||||
|
}
|
||||||
|
return type;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -7,7 +7,6 @@ import java.util.*;
|
|||||||
public class ControlFlowGraph {
|
public class ControlFlowGraph {
|
||||||
|
|
||||||
private Map<Symbol, ControlFlowBlock> blocks;
|
private Map<Symbol, ControlFlowBlock> blocks;
|
||||||
|
|
||||||
private ControlFlowBlock firstBlock;
|
private ControlFlowBlock firstBlock;
|
||||||
private List<ControlFlowBlock> sequence;
|
private List<ControlFlowBlock> sequence;
|
||||||
|
|
||||||
|
@ -1,5 +1,7 @@
|
|||||||
package dk.camelot64.kickc.icl;
|
package dk.camelot64.kickc.passes;
|
||||||
|
|
||||||
|
import dk.camelot64.kickc.NumberParser;
|
||||||
|
import dk.camelot64.kickc.icl.*;
|
||||||
import dk.camelot64.kickc.parser.KickCBaseVisitor;
|
import dk.camelot64.kickc.parser.KickCBaseVisitor;
|
||||||
import dk.camelot64.kickc.parser.KickCParser;
|
import dk.camelot64.kickc.parser.KickCParser;
|
||||||
import org.antlr.v4.runtime.tree.TerminalNode;
|
import org.antlr.v4.runtime.tree.TerminalNode;
|
@ -1,4 +1,6 @@
|
|||||||
package dk.camelot64.kickc.icl;
|
package dk.camelot64.kickc.passes;
|
||||||
|
|
||||||
|
import dk.camelot64.kickc.icl.*;
|
||||||
|
|
||||||
import java.util.LinkedHashMap;
|
import java.util.LinkedHashMap;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
@ -1,6 +1,7 @@
|
|||||||
package dk.camelot64.kickc.icl;
|
package dk.camelot64.kickc.passes;
|
||||||
|
|
||||||
import dk.camelot64.kickc.CompileLog;
|
import dk.camelot64.kickc.CompileLog;
|
||||||
|
import dk.camelot64.kickc.icl.*;
|
||||||
|
|
||||||
import java.util.LinkedHashMap;
|
import java.util.LinkedHashMap;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
@ -1,6 +1,8 @@
|
|||||||
package dk.camelot64.kickc.icl;
|
package dk.camelot64.kickc.passes;
|
||||||
|
|
||||||
import dk.camelot64.kickc.CompileLog;
|
import dk.camelot64.kickc.CompileLog;
|
||||||
|
import dk.camelot64.kickc.NumberParser;
|
||||||
|
import dk.camelot64.kickc.icl.*;
|
||||||
import dk.camelot64.kickc.parser.KickCBaseVisitor;
|
import dk.camelot64.kickc.parser.KickCBaseVisitor;
|
||||||
import dk.camelot64.kickc.parser.KickCParser;
|
import dk.camelot64.kickc.parser.KickCParser;
|
||||||
import org.antlr.v4.runtime.ParserRuleContext;
|
import org.antlr.v4.runtime.ParserRuleContext;
|
@ -1,4 +1,6 @@
|
|||||||
package dk.camelot64.kickc.icl;
|
package dk.camelot64.kickc.passes;
|
||||||
|
|
||||||
|
import dk.camelot64.kickc.icl.*;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
@ -1,4 +1,6 @@
|
|||||||
package dk.camelot64.kickc.icl;
|
package dk.camelot64.kickc.passes;
|
||||||
|
|
||||||
|
import dk.camelot64.kickc.icl.*;
|
||||||
|
|
||||||
/** Pass that modifies a control flow graph to call procedures by passing return value through registers */
|
/** Pass that modifies a control flow graph to call procedures by passing return value through registers */
|
||||||
public class Pass1ProcedureCallsReturnValue extends ControlFlowGraphCopyVisitor {
|
public class Pass1ProcedureCallsReturnValue extends ControlFlowGraphCopyVisitor {
|
@ -1,4 +1,6 @@
|
|||||||
package dk.camelot64.kickc.icl;
|
package dk.camelot64.kickc.passes;
|
||||||
|
|
||||||
|
import dk.camelot64.kickc.icl.*;
|
||||||
|
|
||||||
import java.util.Stack;
|
import java.util.Stack;
|
||||||
|
|
||||||
@ -148,11 +150,7 @@ public class Pass1TypeInference {
|
|||||||
type = rSymbol.getType();
|
type = rSymbol.getType();
|
||||||
} else if (rValue instanceof ConstantInteger) {
|
} else if (rValue instanceof ConstantInteger) {
|
||||||
ConstantInteger rInt = (ConstantInteger) rValue;
|
ConstantInteger rInt = (ConstantInteger) rValue;
|
||||||
if (rInt.getNumber() < 256) {
|
return rInt.getType();
|
||||||
type = SymbolTypeBasic.BYTE;
|
|
||||||
} else {
|
|
||||||
type = SymbolTypeBasic.WORD;
|
|
||||||
}
|
|
||||||
} else if (rValue instanceof ConstantString) {
|
} else if (rValue instanceof ConstantString) {
|
||||||
type = SymbolTypeBasic.STRING;
|
type = SymbolTypeBasic.STRING;
|
||||||
} else if (rValue instanceof ConstantBool) {
|
} else if (rValue instanceof ConstantBool) {
|
@ -1,6 +1,7 @@
|
|||||||
package dk.camelot64.kickc.icl;
|
package dk.camelot64.kickc.passes;
|
||||||
|
|
||||||
import dk.camelot64.kickc.CompileLog;
|
import dk.camelot64.kickc.CompileLog;
|
||||||
|
import dk.camelot64.kickc.icl.*;
|
||||||
|
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
|
|
@ -1,4 +1,6 @@
|
|||||||
package dk.camelot64.kickc.icl;
|
package dk.camelot64.kickc.passes;
|
||||||
|
|
||||||
|
import dk.camelot64.kickc.icl.*;
|
||||||
|
|
||||||
/** Assert that all referenced blocks exist in the program */
|
/** Assert that all referenced blocks exist in the program */
|
||||||
public class Pass2AssertBlocks extends Pass2SsaAssertion {
|
public class Pass2AssertBlocks extends Pass2SsaAssertion {
|
@ -1,4 +1,6 @@
|
|||||||
package dk.camelot64.kickc.icl;
|
package dk.camelot64.kickc.passes;
|
||||||
|
|
||||||
|
import dk.camelot64.kickc.icl.*;
|
||||||
|
|
||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
|
|
@ -1,6 +1,7 @@
|
|||||||
package dk.camelot64.kickc.icl;
|
package dk.camelot64.kickc.passes;
|
||||||
|
|
||||||
import dk.camelot64.kickc.CompileLog;
|
import dk.camelot64.kickc.CompileLog;
|
||||||
|
import dk.camelot64.kickc.icl.*;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
@ -1,8 +1,8 @@
|
|||||||
package dk.camelot64.kickc.icl;
|
package dk.camelot64.kickc.passes;
|
||||||
|
|
||||||
import dk.camelot64.kickc.CompileLog;
|
import dk.camelot64.kickc.CompileLog;
|
||||||
|
import dk.camelot64.kickc.icl.*;
|
||||||
|
|
||||||
import java.util.HashMap;
|
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
/**
|
/**
|
@ -1,8 +1,8 @@
|
|||||||
package dk.camelot64.kickc.icl;
|
package dk.camelot64.kickc.passes;
|
||||||
|
|
||||||
import dk.camelot64.kickc.CompileLog;
|
import dk.camelot64.kickc.CompileLog;
|
||||||
|
import dk.camelot64.kickc.icl.*;
|
||||||
|
|
||||||
import java.util.HashMap;
|
|
||||||
import java.util.LinkedHashMap;
|
import java.util.LinkedHashMap;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
@ -1,6 +1,7 @@
|
|||||||
package dk.camelot64.kickc.icl;
|
package dk.camelot64.kickc.passes;
|
||||||
|
|
||||||
import dk.camelot64.kickc.CompileLog;
|
import dk.camelot64.kickc.CompileLog;
|
||||||
|
import dk.camelot64.kickc.icl.*;
|
||||||
|
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
|
|
@ -1,8 +1,8 @@
|
|||||||
package dk.camelot64.kickc.icl;
|
package dk.camelot64.kickc.passes;
|
||||||
|
|
||||||
import dk.camelot64.kickc.CompileLog;
|
import dk.camelot64.kickc.CompileLog;
|
||||||
|
import dk.camelot64.kickc.icl.*;
|
||||||
|
|
||||||
import java.util.HashMap;
|
|
||||||
import java.util.LinkedHashMap;
|
import java.util.LinkedHashMap;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
@ -1,6 +1,10 @@
|
|||||||
package dk.camelot64.kickc.icl;
|
package dk.camelot64.kickc.passes;
|
||||||
|
|
||||||
import dk.camelot64.kickc.CompileLog;
|
import dk.camelot64.kickc.CompileLog;
|
||||||
|
import dk.camelot64.kickc.icl.ControlFlowGraph;
|
||||||
|
import dk.camelot64.kickc.icl.ControlFlowGraphBaseVisitor;
|
||||||
|
import dk.camelot64.kickc.icl.Scope;
|
||||||
|
import dk.camelot64.kickc.icl.StatementPhi;
|
||||||
|
|
||||||
import java.util.Iterator;
|
import java.util.Iterator;
|
||||||
|
|
@ -1,4 +1,7 @@
|
|||||||
package dk.camelot64.kickc.icl;
|
package dk.camelot64.kickc.passes;
|
||||||
|
|
||||||
|
import dk.camelot64.kickc.icl.ControlFlowGraph;
|
||||||
|
import dk.camelot64.kickc.icl.Scope;
|
||||||
|
|
||||||
/** Assertion checking that a pass 2 representation of the program is consistent */
|
/** Assertion checking that a pass 2 representation of the program is consistent */
|
||||||
public abstract class Pass2SsaAssertion {
|
public abstract class Pass2SsaAssertion {
|
@ -1,6 +1,7 @@
|
|||||||
package dk.camelot64.kickc.icl;
|
package dk.camelot64.kickc.passes;
|
||||||
|
|
||||||
import dk.camelot64.kickc.CompileLog;
|
import dk.camelot64.kickc.CompileLog;
|
||||||
|
import dk.camelot64.kickc.icl.*;
|
||||||
|
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
|
|
@ -1,4 +1,8 @@
|
|||||||
package dk.camelot64.kickc.icl;
|
package dk.camelot64.kickc.passes;
|
||||||
|
|
||||||
|
import dk.camelot64.kickc.icl.ControlFlowBlock;
|
||||||
|
import dk.camelot64.kickc.icl.ControlFlowGraph;
|
||||||
|
import dk.camelot64.kickc.icl.Scope;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
@ -1,6 +1,7 @@
|
|||||||
package dk.camelot64.kickc.icl;
|
package dk.camelot64.kickc.passes;
|
||||||
|
|
||||||
import dk.camelot64.kickc.asm.*;
|
import dk.camelot64.kickc.asm.*;
|
||||||
|
import dk.camelot64.kickc.icl.*;
|
||||||
|
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
|
|
@ -1,4 +1,6 @@
|
|||||||
package dk.camelot64.kickc.icl;
|
package dk.camelot64.kickc.passes;
|
||||||
|
|
||||||
|
import dk.camelot64.kickc.icl.*;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Register Allocation for variables
|
* Register Allocation for variables
|
@ -1,4 +1,4 @@
|
|||||||
package dk.camelot64.kickc.icl;
|
package dk.camelot64.kickc.passes;
|
||||||
|
|
||||||
import dk.camelot64.kickc.CompileLog;
|
import dk.camelot64.kickc.CompileLog;
|
||||||
import dk.camelot64.kickc.asm.AsmLine;
|
import dk.camelot64.kickc.asm.AsmLine;
|
@ -1,4 +1,4 @@
|
|||||||
package dk.camelot64.kickc.icl;
|
package dk.camelot64.kickc.passes;
|
||||||
|
|
||||||
import dk.camelot64.kickc.CompileLog;
|
import dk.camelot64.kickc.CompileLog;
|
||||||
import dk.camelot64.kickc.asm.AsmInstruction;
|
import dk.camelot64.kickc.asm.AsmInstruction;
|
@ -1,4 +1,4 @@
|
|||||||
package dk.camelot64.kickc.icl;
|
package dk.camelot64.kickc.passes;
|
||||||
|
|
||||||
import dk.camelot64.kickc.CompileLog;
|
import dk.camelot64.kickc.CompileLog;
|
||||||
import dk.camelot64.kickc.asm.*;
|
import dk.camelot64.kickc.asm.*;
|
Loading…
x
Reference in New Issue
Block a user