1
0
mirror of https://gitlab.com/camelot/kickc.git synced 2024-12-21 14:30:21 +00:00

Optimized registers for fibmem.

This commit is contained in:
Jesper Gravgaard 2017-07-18 16:46:52 +02:00
parent a7e0e2b1d0
commit 32a2c9eb2b
7 changed files with 49 additions and 8 deletions

View File

@ -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() {

View File

@ -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

View File

@ -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;
}
}

View File

@ -17,6 +17,10 @@ public class Pass3BlockSequencePlanner {
public void plan() {
Stack<ControlFlowBlock> todo = new Stack<>();
ControlFlowBlock mainBlock = controlFlowGraph.getMainBlock();
if (mainBlock != null) {
todo.push(mainBlock);
}
todo.push(controlFlowGraph.getFirstBlock());
List<ControlFlowBlock> sequence = new ArrayList<>();
while(!todo.empty()){

View File

@ -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);
}

View File

@ -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 {

View File

@ -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)
}