1
0
mirror of https://gitlab.com/camelot/kickc.git synced 2024-11-17 12:08:54 +00:00

Added more general pointer support

This commit is contained in:
jespergravgaard 2017-05-28 17:58:02 +02:00
parent b3dfb503f5
commit 5c907162f3
7 changed files with 40 additions and 3 deletions

View File

@ -0,0 +1,4 @@
txa
clc
adc #{coby1}
sta {zpby1}

View File

@ -0,0 +1,7 @@
lda {zpptrby2}
clc
adc #1
sta {zpptrby1}
lda {zpptrby2}+1
adc #0
sta {zpptrby1}+1

View File

@ -40,6 +40,15 @@ 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);
}
}
}
}

View File

@ -154,8 +154,13 @@ public class Pass1GenerateStatementSequence extends KickCBaseVisitor<Object> {
@Override
public LValue visitLvaluePtr(KickCParser.LvaluePtrContext ctx) {
LValue lval = (LValue) visit(ctx.lvalue());
if(lval instanceof Variable) {
return new PointerDereferenceVariable((Variable) lval);
} else {
throw new RuntimeException("Not implemented");
}
}
@Override
public LValue visitLvalueArray(KickCParser.LvalueArrayContext ctx) {
@ -185,7 +190,8 @@ public class Pass1GenerateStatementSequence extends KickCBaseVisitor<Object> {
@Override
public SymbolType visitTypePtr(KickCParser.TypePtrContext ctx) {
throw new RuntimeException("Not implemented");
SymbolType elementType = (SymbolType) visit(ctx.typeDecl());
return new SymbolTypePointer(elementType);
}
@Override

View File

@ -31,6 +31,9 @@ public class Pass3RegisterAllocation {
allocation.allocate(symbols.getVariable("i#3"), RegisterAllocation.getRegisterX());
allocation.allocate(symbols.getVariable("n1#1"), RegisterAllocation.getRegisterY());
allocation.allocate(symbols.getVariable("n1#2"), RegisterAllocation.getRegisterY());
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));
symbols.setAllocation(allocation);
}

View File

@ -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/fibmem.kc";
final String fileName = "src/dk/camelot64/kickc/test/memptr.kc";
final CharStream input = CharStreams.fromFileName(fileName);
System.out.println(input.toString());
KickCLexer lexer = new KickCLexer(input);

View File

@ -0,0 +1,8 @@
byte[256] tab = $1100;
byte* ptr = tab;
byte i=0;
do {
*ptr = i;
ptr = ptr+1;
i = i+1;
} while (i!=0)