diff --git a/src/dk/camelot64/kickc/CompileLog.java b/src/dk/camelot64/kickc/CompileLog.java index 02a112573..770a7f37e 100644 --- a/src/dk/camelot64/kickc/CompileLog.java +++ b/src/dk/camelot64/kickc/CompileLog.java @@ -12,7 +12,7 @@ public class CompileLog { public void append(String msg) { log.append(msg); log.append("\n"); - //System.out.printf(msg+"\n"); + System.out.printf(msg+"\n"); } public StringBuilder getLog() { diff --git a/src/dk/camelot64/kickc/TODO.txt b/src/dk/camelot64/kickc/TODO.txt index 37b9f9747..35b2818fe 100644 --- a/src/dk/camelot64/kickc/TODO.txt +++ b/src/dk/camelot64/kickc/TODO.txt @@ -10,6 +10,7 @@ Features - Implement inline compilation of functions (and a mechanism for choosing which methods / calls to inline) - Add ability to call ASM code from KC. - Add ability to call KC code from ASM. (Maybe declare some functions external to ensure their interface is well defined. Maybe generate ASM call stubs.) +- 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 + Create a proper main function for the compiler diff --git a/src/dk/camelot64/kickc/icl/ControlFlowGraph.java b/src/dk/camelot64/kickc/icl/ControlFlowGraph.java index 9d32f92e9..2e8e0ae98 100644 --- a/src/dk/camelot64/kickc/icl/ControlFlowGraph.java +++ b/src/dk/camelot64/kickc/icl/ControlFlowGraph.java @@ -114,4 +114,13 @@ public class ControlFlowGraph { return sequence; } + public ControlFlowBlock getMainBlock() { + for (ControlFlowBlock block : getAllBlocks()) { + Label label = block.getLabel(); + if(label.getFullName().equals("main")) { + return block; + } + } + return null; + } } diff --git a/src/dk/camelot64/kickc/icl/Pass3BlockSequencePlanner.java b/src/dk/camelot64/kickc/icl/Pass3BlockSequencePlanner.java index f52ce6698..b0cb9edfa 100644 --- a/src/dk/camelot64/kickc/icl/Pass3BlockSequencePlanner.java +++ b/src/dk/camelot64/kickc/icl/Pass3BlockSequencePlanner.java @@ -17,6 +17,10 @@ public class Pass3BlockSequencePlanner { public void plan() { Stack todo = new Stack<>(); + ControlFlowBlock mainBlock = controlFlowGraph.getMainBlock(); + if (mainBlock != null) { + todo.push(mainBlock); + } todo.push(controlFlowGraph.getFirstBlock()); List sequence = new ArrayList<>(); while(!todo.empty()){ diff --git a/src/dk/camelot64/kickc/icl/Pass3RegisterAllocation.java b/src/dk/camelot64/kickc/icl/Pass3RegisterAllocation.java index 28da6d4b1..c1d8153b7 100644 --- a/src/dk/camelot64/kickc/icl/Pass3RegisterAllocation.java +++ b/src/dk/camelot64/kickc/icl/Pass3RegisterAllocation.java @@ -19,8 +19,6 @@ public class Pass3RegisterAllocation { performAllocation(symbols, allocation); //allocation.allocate(symbols.getVariable("i#0"), RegisterAllocation.getRegisterX()); - //allocation.allocate(symbols.getVariable("i#1"), RegisterAllocation.getRegisterX()); - //allocation.allocate(symbols.getVariable("i#2"), RegisterAllocation.getRegisterX()); //allocation.allocate(symbols.getVariable("i#3"), RegisterAllocation.getRegisterX()); //allocation.allocate(symbols.getVariable("i#4"), RegisterAllocation.getRegisterX()); //allocation.allocate(symbols.getVariable("i#5"), RegisterAllocation.getRegisterX()); @@ -59,9 +57,6 @@ public class Pass3RegisterAllocation { //allocation.allocate(symbols.getVariable("$0"), new RegisterAllocation.RegisterAByte()); //allocation.allocate(symbols.getVariable("$2"), new RegisterAllocation.RegisterAByte()); //allocation.allocate(symbols.getVariable("$3"), new RegisterAllocation.RegisterAByte()); - //allocation.allocate(symbols.getVariable("$1"), new RegisterAllocation.RegisterAByte()); - //allocation.allocate(symbols.getVariable("$3"), new RegisterAllocation.RegisterALUByte()); - //allocation.allocate(symbols.getVariable("$4"), new RegisterAllocation.RegisterAByte()); //allocation.allocate(symbols.getVariable("$5"), new RegisterAllocation.RegisterAByte()); //allocation.allocate(symbols.getVariable("$6"), new RegisterAllocation.RegisterALUByte()); //allocation.allocate(symbols.getVariable("$7"), new RegisterAllocation.RegisterAByte()); @@ -72,6 +67,14 @@ public class Pass3RegisterAllocation { //allocation.allocate(symbols.getVariable("a#1"), new RegisterAllocation.RegisterAByte()); //allocation.allocate(symbols.getVariable("a#0"), new RegisterAllocation.RegisterAByte()); + // Register allocation for fibmem.kc + allocation.allocate(symbols.getVariable("i#1"), RegisterAllocation.getRegisterX()); + allocation.allocate(symbols.getVariable("i#2"), RegisterAllocation.getRegisterX()); + allocation.allocate(symbols.getVariable("$1"), new RegisterAllocation.RegisterAByte()); + allocation.allocate(symbols.getVariable("$3"), new RegisterAllocation.RegisterALUByte()); + //allocation.allocate(symbols.getVariable("$4"), new RegisterAllocation.RegisterAByte()); + + // Registers for postinc.kc /* allocation.allocate(symbols.getVariable("c#0"), RegisterAllocation.getRegisterA()); @@ -91,6 +94,7 @@ public class Pass3RegisterAllocation { */ // Optimal Registers for flipper-rex2.kc + /* allocation.allocate(symbols.getVariable("plot::i#0"), RegisterAllocation.getRegisterX()); allocation.allocate(symbols.getVariable("plot::i#1"), RegisterAllocation.getRegisterX()); allocation.allocate(symbols.getVariable("plot::i#2"), RegisterAllocation.getRegisterX()); @@ -146,6 +150,9 @@ public class Pass3RegisterAllocation { allocation.allocate(symbols.getVariable("main::c#2"), RegisterAllocation.getRegisterX()); allocation.allocate(symbols.getVariable("main::c#3"), RegisterAllocation.getRegisterX()); allocation.allocate(symbols.getVariable("main::c#4"), RegisterAllocation.getRegisterX()); + */ + + symbols.setAllocation(allocation); } diff --git a/src/dk/camelot64/kickc/test/TestCompilationOutput.java b/src/dk/camelot64/kickc/test/TestCompilationOutput.java index bec8e9bb5..c016d570a 100644 --- a/src/dk/camelot64/kickc/test/TestCompilationOutput.java +++ b/src/dk/camelot64/kickc/test/TestCompilationOutput.java @@ -30,8 +30,10 @@ public class TestCompilationOutput { public static void main(String[] args) throws IOException, URISyntaxException { TestCompilationOutput tester = new TestCompilationOutput(); - tester.testFile("flipper-rex2"); - tester.testFile("bresenham"); + tester.testFile("fibmem"); + //tester.testFile("flipper-rex2"); + //tester.testFile("bresenham"); + //tester.testFile("unused"); } private void testFile(String fileName) throws IOException, URISyntaxException { diff --git a/src/dk/camelot64/kickc/test/unused.kc b/src/dk/camelot64/kickc/test/unused.kc new file mode 100644 index 000000000..82a3d1071 --- /dev/null +++ b/src/dk/camelot64/kickc/test/unused.kc @@ -0,0 +1,18 @@ +byte *SCREEN = $0400; + +byte c = (*SCREEN); +fillscreen(c); + +void fillscreen(byte c) { + byte j=0; + do { + byte* SCREEN2 = SCREEN+$100; + byte* SCREEN3 = SCREEN+$200; + byte* SCREEN4 = SCREEN+$3e8; + SCREEN[j] = c; + SCREEN2[j] = c; + SCREEN3[j] = c; + SCREEN4[j] = c; + } while(++j!=0) +} +