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

Fixed problem with ++ being added twice in *(char_cursor++) = *str;

This commit is contained in:
jespergravgaard 2017-11-28 01:23:59 +01:00
parent 663b885196
commit 1edb436dfd
3 changed files with 7 additions and 15 deletions

View File

@ -387,9 +387,7 @@ public class Pass1GenerateStatementSequence extends KickCBaseVisitor<Object> {
@Override
public Object visitLvaluePtrExpr(KickCParser.LvaluePtrExprContext ctx) {
PrePostModifierHandler.addPreModifiers(this, ctx.expr());
RValue rValue = (RValue) this.visit(ctx.expr());
PrePostModifierHandler.addPostModifiers(this, ctx.expr());
return new PointerDereferenceSimple(rValue);
}

View File

@ -49,18 +49,7 @@ public class Pass3VariableRegisterWeightAnalysis extends Pass2Base {
}
} else if (statement instanceof StatementAssignment) {
// Add weights for the definition of the variable
LValue lValue = ((StatementAssignment) statement).getlValue();
if (lValue instanceof VariableRef) {
double w = addWeight((VariableRef) lValue, block.getLabel());
//log.append("Definition of " + lValue + " w+:" + w + " - [" + statement.getIndex()+"]");
}
// Also add weight to used pointers
if(lValue instanceof PointerDereferenceSimple) {
addUsageWeightRValue(((PointerDereferenceSimple) lValue).getPointer(), statement, block.getLabel());
} else if(lValue instanceof PointerDereferenceIndexed) {
addUsageWeightRValue(((PointerDereferenceIndexed) lValue).getPointer(), statement, block.getLabel());
addUsageWeightRValue(((PointerDereferenceIndexed) lValue).getIndex(), statement, block.getLabel());
}
addUsageWeightRValue(((StatementAssignment) statement).getlValue(), statement, block.getLabel());
// Add weights for each usage of variables
addUsageWeightRValue(((StatementAssignment) statement).getrValue1(), statement, block.getLabel());
addUsageWeightRValue(((StatementAssignment) statement).getrValue2(), statement, block.getLabel());
@ -80,6 +69,11 @@ public class Pass3VariableRegisterWeightAnalysis extends Pass2Base {
if (rValue instanceof VariableRef) {
double w = addWeight((VariableRef) rValue, block);
//log.append("Usage of " + rValue + " w+:" + w + " - [" + statement.getIndex()+"]");
} else if(rValue instanceof PointerDereferenceSimple) {
addUsageWeightRValue(((PointerDereferenceSimple) rValue).getPointer(), statement, block);
} else if(rValue instanceof PointerDereferenceIndexed) {
addUsageWeightRValue(((PointerDereferenceIndexed) rValue).getPointer(), statement, block);
addUsageWeightRValue(((PointerDereferenceIndexed) rValue).getIndex(), statement, block);
}
}

View File

@ -15,7 +15,7 @@ byte* char_cursor = line_cursor;
// Print a zero-terminated string
void print_str(byte* str) {
while(*str!='@') {
*(char_cursor++) = *str;
*(char_cursor++) = *(str++);
}
}