1
0
mirror of https://gitlab.com/camelot/kickc.git synced 2024-11-14 23:04:57 +00:00

Restructured code in new packages

This commit is contained in:
Jesper Gravgaard 2017-07-18 18:10:12 +02:00
parent 32a2c9eb2b
commit 92747454c7
32 changed files with 97 additions and 43 deletions

View File

@ -4,9 +4,9 @@ import dk.camelot64.kickc.asm.AsmProgram;
import dk.camelot64.kickc.icl.*;
import dk.camelot64.kickc.parser.KickCLexer;
import dk.camelot64.kickc.parser.KickCParser;
import dk.camelot64.kickc.passes.*;
import org.antlr.v4.runtime.*;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

View File

@ -1,4 +1,4 @@
package dk.camelot64.kickc.icl;
package dk.camelot64.kickc;
/** Parser for converting literal numbers to the corresponding Java Integer/Double */
public class NumberParser {

View File

@ -1,7 +1,6 @@
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.
- 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 imports
- 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 inline ASM (maybe?)
- Handle long branches
- Allow complex array expressions in lValues eg. (SCREEN+$100)[idx]
+ Create a proper main function for the compiler
+ 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
- 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
@ -31,10 +48,8 @@ Testing
+ Test the ASM program output resulting from compiling specific KC program input.
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.
- This phase could also help simplify LDA xx, CMP#0, BNE by expressing these in a language where CMP can be eliminated before.
Usages
- Implement library for memory allocation in main memory

View File

@ -1,5 +1,6 @@
package dk.camelot64.kickc.asm;
import dk.camelot64.kickc.NumberParser;
import dk.camelot64.kickc.asm.parser.Asm6502BaseVisitor;
import dk.camelot64.kickc.asm.parser.Asm6502Lexer;
import dk.camelot64.kickc.asm.parser.Asm6502Parser;
@ -9,7 +10,6 @@ import org.antlr.v4.runtime.*;
import java.io.IOException;
import java.io.InputStream;
import java.net.URL;
import java.util.HashMap;
import java.util.LinkedHashMap;
import java.util.Map;

View File

@ -1,6 +1,6 @@
package dk.camelot64.kickc.asm;
import dk.camelot64.kickc.icl.NumberParser;
import dk.camelot64.kickc.NumberParser;
import java.util.ArrayList;
import java.util.Arrays;

View File

@ -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 */
public class PointerDereferenceRegisterZpByte implements PointerDereference {

View File

@ -16,7 +16,13 @@ public class ConstantInteger implements Constant {
}
public SymbolType getType() {
return Pass1TypeInference.inferType(this);
SymbolType type;
if (getNumber() < 256) {
type = SymbolTypeBasic.BYTE;
} else {
type = SymbolTypeBasic.WORD;
}
return type;
}
@Override

View File

@ -7,7 +7,6 @@ import java.util.*;
public class ControlFlowGraph {
private Map<Symbol, ControlFlowBlock> blocks;
private ControlFlowBlock firstBlock;
private List<ControlFlowBlock> sequence;

View File

@ -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.KickCParser;
import org.antlr.v4.runtime.tree.TerminalNode;

View File

@ -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.Map;

View File

@ -1,6 +1,7 @@
package dk.camelot64.kickc.icl;
package dk.camelot64.kickc.passes;
import dk.camelot64.kickc.CompileLog;
import dk.camelot64.kickc.icl.*;
import java.util.LinkedHashMap;
import java.util.Map;

View File

@ -1,6 +1,8 @@
package dk.camelot64.kickc.icl;
package dk.camelot64.kickc.passes;
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.KickCParser;
import org.antlr.v4.runtime.ParserRuleContext;

View File

@ -1,4 +1,6 @@
package dk.camelot64.kickc.icl;
package dk.camelot64.kickc.passes;
import dk.camelot64.kickc.icl.*;
import java.util.List;

View File

@ -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 */
public class Pass1ProcedureCallsReturnValue extends ControlFlowGraphCopyVisitor {

View File

@ -1,4 +1,6 @@
package dk.camelot64.kickc.icl;
package dk.camelot64.kickc.passes;
import dk.camelot64.kickc.icl.*;
import java.util.Stack;
@ -148,11 +150,7 @@ public class Pass1TypeInference {
type = rSymbol.getType();
} else if (rValue instanceof ConstantInteger) {
ConstantInteger rInt = (ConstantInteger) rValue;
if (rInt.getNumber() < 256) {
type = SymbolTypeBasic.BYTE;
} else {
type = SymbolTypeBasic.WORD;
}
return rInt.getType();
} else if (rValue instanceof ConstantString) {
type = SymbolTypeBasic.STRING;
} else if (rValue instanceof ConstantBool) {

View File

@ -1,6 +1,7 @@
package dk.camelot64.kickc.icl;
package dk.camelot64.kickc.passes;
import dk.camelot64.kickc.CompileLog;
import dk.camelot64.kickc.icl.*;
import java.util.*;

View File

@ -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 */
public class Pass2AssertBlocks extends Pass2SsaAssertion {

View File

@ -1,4 +1,6 @@
package dk.camelot64.kickc.icl;
package dk.camelot64.kickc.passes;
import dk.camelot64.kickc.icl.*;
import java.util.HashSet;

View File

@ -1,6 +1,7 @@
package dk.camelot64.kickc.icl;
package dk.camelot64.kickc.passes;
import dk.camelot64.kickc.CompileLog;
import dk.camelot64.kickc.icl.*;
import java.util.ArrayList;
import java.util.List;

View File

@ -1,8 +1,8 @@
package dk.camelot64.kickc.icl;
package dk.camelot64.kickc.passes;
import dk.camelot64.kickc.CompileLog;
import dk.camelot64.kickc.icl.*;
import java.util.HashMap;
import java.util.Map;
/**

View File

@ -1,8 +1,8 @@
package dk.camelot64.kickc.icl;
package dk.camelot64.kickc.passes;
import dk.camelot64.kickc.CompileLog;
import dk.camelot64.kickc.icl.*;
import java.util.HashMap;
import java.util.LinkedHashMap;
import java.util.Map;

View File

@ -1,6 +1,7 @@
package dk.camelot64.kickc.icl;
package dk.camelot64.kickc.passes;
import dk.camelot64.kickc.CompileLog;
import dk.camelot64.kickc.icl.*;
import java.util.*;

View File

@ -1,8 +1,8 @@
package dk.camelot64.kickc.icl;
package dk.camelot64.kickc.passes;
import dk.camelot64.kickc.CompileLog;
import dk.camelot64.kickc.icl.*;
import java.util.HashMap;
import java.util.LinkedHashMap;
import java.util.Map;

View File

@ -1,6 +1,10 @@
package dk.camelot64.kickc.icl;
package dk.camelot64.kickc.passes;
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;

View File

@ -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 */
public abstract class Pass2SsaAssertion {

View File

@ -1,6 +1,7 @@
package dk.camelot64.kickc.icl;
package dk.camelot64.kickc.passes;
import dk.camelot64.kickc.CompileLog;
import dk.camelot64.kickc.icl.*;
import java.util.*;

View File

@ -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.List;

View File

@ -1,6 +1,7 @@
package dk.camelot64.kickc.icl;
package dk.camelot64.kickc.passes;
import dk.camelot64.kickc.asm.*;
import dk.camelot64.kickc.icl.*;
import java.util.*;

View File

@ -1,4 +1,6 @@
package dk.camelot64.kickc.icl;
package dk.camelot64.kickc.passes;
import dk.camelot64.kickc.icl.*;
/**
* Register Allocation for variables

View File

@ -1,4 +1,4 @@
package dk.camelot64.kickc.icl;
package dk.camelot64.kickc.passes;
import dk.camelot64.kickc.CompileLog;
import dk.camelot64.kickc.asm.AsmLine;

View File

@ -1,4 +1,4 @@
package dk.camelot64.kickc.icl;
package dk.camelot64.kickc.passes;
import dk.camelot64.kickc.CompileLog;
import dk.camelot64.kickc.asm.AsmInstruction;

View File

@ -1,4 +1,4 @@
package dk.camelot64.kickc.icl;
package dk.camelot64.kickc.passes;
import dk.camelot64.kickc.CompileLog;
import dk.camelot64.kickc.asm.*;