mirror of
https://gitlab.com/camelot/kickc.git
synced 2025-04-10 13:38:18 +00:00
Implemented simple bresenhm
This commit is contained in:
parent
5367a41bcf
commit
38408825cd
@ -0,0 +1,4 @@
|
||||
lda #{coby1}
|
||||
cmp {zpby1}
|
||||
bcc {la1}
|
||||
beq {la1}
|
@ -0,0 +1,3 @@
|
||||
lda #{coby1}
|
||||
cmp {zpby1}
|
||||
bcc {la1}
|
@ -5,4 +5,4 @@ beq !t+
|
||||
!f: lda #0
|
||||
jmp !d+
|
||||
!t: lda #$ff
|
||||
!d: sta {zpbo1
|
||||
!d: sta {zpbo1}
|
@ -0,0 +1,4 @@
|
||||
lda {zpby1}
|
||||
sec
|
||||
sbc #{coby1}
|
||||
sta {zpby1}
|
@ -0,0 +1 @@
|
||||
inc {zpby1}
|
@ -0,0 +1,4 @@
|
||||
lda {zpby1}
|
||||
clc
|
||||
adc #{coby1}
|
||||
sta {zpby1}
|
@ -1,4 +1,4 @@
|
||||
lda {zpby1}
|
||||
lda {zpby2}
|
||||
clc
|
||||
adc #1
|
||||
sta {zpby2}
|
||||
sta {zpby1}
|
@ -0,0 +1,7 @@
|
||||
lda {zpptrby1}
|
||||
clc
|
||||
adc #{coby1}
|
||||
sta {zpptrby1}
|
||||
lda {zpptrby1}+1
|
||||
adc #0
|
||||
sta {zpptrby1}+1
|
@ -40,15 +40,6 @@ public class Pass1GenerateSingleStaticAssignmentForm {
|
||||
VariableUnversioned assignedSymbol = (VariableUnversioned) lValue;
|
||||
VariableVersion version = symbols.createVersion(assignedSymbol);
|
||||
assignment.setLValue(version);
|
||||
} else if(lValue instanceof PointerDereferenceVariable) {
|
||||
PointerDereferenceVariable deref = (PointerDereferenceVariable) lValue;
|
||||
Variable pointer = deref.getPointer();
|
||||
if(pointer instanceof VariableUnversioned) {
|
||||
// Assignment to a non-versioned non-intermediary variable
|
||||
VariableUnversioned assignedSymbol = (VariableUnversioned) pointer;
|
||||
VariableVersion version = symbols.createVersion(assignedSymbol);
|
||||
deref.setPointerVariable(version);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -82,6 +73,13 @@ public class Pass1GenerateSingleStaticAssignmentForm {
|
||||
if (lValue instanceof VariableVersion) {
|
||||
VariableVersion versioned = (VariableVersion) lValue;
|
||||
blockVersions.put(versioned.getVersionOf(), versioned);
|
||||
} else if(lValue instanceof PointerDereferenceVariable) {
|
||||
PointerDereferenceVariable deref = (PointerDereferenceVariable) lValue;
|
||||
Variable pointer = deref.getPointer();
|
||||
VariableVersion version = findOrCreateVersion(pointer, blockVersions, blockNewPhis);
|
||||
if (version != null) {
|
||||
deref.setPointerVariable(version);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -104,6 +104,13 @@ public class Pass2ConstantPropagation extends Pass2SsaOptimization {
|
||||
return new ConstantDouble(getDouble(c1) * getDouble(c2));
|
||||
}
|
||||
}
|
||||
case "/": {
|
||||
if (c1 instanceof ConstantInteger && c2 instanceof ConstantInteger) {
|
||||
return new ConstantInteger(getInteger(c1) / getInteger(c2));
|
||||
} else {
|
||||
return new ConstantDouble(getDouble(c1) / getDouble(c2));
|
||||
}
|
||||
}
|
||||
default:
|
||||
throw new RuntimeException("Unhandled Binary Operator " + operator.getOperator());
|
||||
}
|
||||
|
@ -34,6 +34,19 @@ public class Pass3RegisterAllocation {
|
||||
allocation.allocate(symbols.getVariable("ptr#1"), new RegisterAllocation.RegisterZpPointerByte(2));
|
||||
allocation.allocate(symbols.getVariable("ptr#2"), new RegisterAllocation.RegisterZpPointerByte(2));
|
||||
allocation.allocate(symbols.getVariable("ptr#3"), new RegisterAllocation.RegisterZpPointerByte(2));
|
||||
allocation.allocate(symbols.getVariable("y#1"), new RegisterAllocation.RegisterZpByte(4));
|
||||
allocation.allocate(symbols.getVariable("y#2"), new RegisterAllocation.RegisterZpByte(4));
|
||||
allocation.allocate(symbols.getVariable("y#5"), new RegisterAllocation.RegisterZpByte(4));
|
||||
allocation.allocate(symbols.getVariable("x#2"), new RegisterAllocation.RegisterZpByte(8));
|
||||
allocation.allocate(symbols.getVariable("x#5"), new RegisterAllocation.RegisterZpByte(8));
|
||||
allocation.allocate(symbols.getVariable("cursor#2"), new RegisterAllocation.RegisterZpPointerByte(5));
|
||||
allocation.allocate(symbols.getVariable("cursor#3"), new RegisterAllocation.RegisterZpPointerByte(5));
|
||||
allocation.allocate(symbols.getVariable("cursor#4"), new RegisterAllocation.RegisterZpPointerByte(5));
|
||||
allocation.allocate(symbols.getVariable("cursor#5"), new RegisterAllocation.RegisterZpPointerByte(5));
|
||||
allocation.allocate(symbols.getVariable("e#2"), new RegisterAllocation.RegisterZpByte(7));
|
||||
allocation.allocate(symbols.getVariable("e#3"), new RegisterAllocation.RegisterZpByte(7));
|
||||
allocation.allocate(symbols.getVariable("e#4"), new RegisterAllocation.RegisterZpByte(7));
|
||||
allocation.allocate(symbols.getVariable("e#5"), new RegisterAllocation.RegisterZpByte(7));
|
||||
symbols.setAllocation(allocation);
|
||||
}
|
||||
|
||||
|
@ -13,7 +13,7 @@ import java.util.List;
|
||||
/** Test my KickC Grammar */
|
||||
public class Main {
|
||||
public static void main(String[] args) throws IOException {
|
||||
final String fileName = "src/dk/camelot64/kickc/test/memptr.kc";
|
||||
final String fileName = "src/dk/camelot64/kickc/test/bresenham.kc";
|
||||
final CharStream input = CharStreams.fromFileName(fileName);
|
||||
System.out.println(input.toString());
|
||||
KickCLexer lexer = new KickCLexer(input);
|
||||
@ -78,7 +78,6 @@ public class Main {
|
||||
asmOptimized = pass5NextJumpElimination.optimize();
|
||||
}
|
||||
|
||||
|
||||
System.out.println("SYMBOLS");
|
||||
System.out.println(symbolTable.toString());
|
||||
System.out.println("CONTROL FLOW GRAPH");
|
||||
|
23
src/dk/camelot64/kickc/test/bresenham.kc
Normal file
23
src/dk/camelot64/kickc/test/bresenham.kc
Normal file
@ -0,0 +1,23 @@
|
||||
byte STAR = 81;
|
||||
byte[40*25] SCREEN = $0400;
|
||||
byte x0 = 0;
|
||||
byte y0 = 0;
|
||||
byte x1 = 39;
|
||||
byte y1 = 24;
|
||||
byte xd = x1-x0;
|
||||
byte yd = y1-y0;
|
||||
byte x = x0;
|
||||
byte y = y0;
|
||||
byte e = yd/2;
|
||||
byte *cursor = SCREEN+y*40+x;
|
||||
do {
|
||||
*cursor = STAR;
|
||||
x = x + 1;
|
||||
cursor = cursor + 1;
|
||||
e = e+yd;
|
||||
if(xd<e) {
|
||||
y = y+1;
|
||||
cursor = cursor + 40;
|
||||
e = e - xd;
|
||||
}
|
||||
} while (x<(x1+1))
|
Loading…
x
Reference in New Issue
Block a user