mirror of
https://gitlab.com/camelot/kickc.git
synced 2024-11-20 02:32:36 +00:00
Renamed for clarity
This commit is contained in:
parent
65c92716f0
commit
2a14671496
@ -79,7 +79,7 @@ public class Pass1FixLValuesLoHi extends Pass1Base {
|
|||||||
VariableIntermediate tmpVar = currentScope.addVariableIntermediate();
|
VariableIntermediate tmpVar = currentScope.addVariableIntermediate();
|
||||||
VariableRef tmpVarRef = tmpVar.getRef();
|
VariableRef tmpVarRef = tmpVar.getRef();
|
||||||
statementLValue.setlValue(tmpVarRef);
|
statementLValue.setlValue(tmpVarRef);
|
||||||
PassNTypeInference.inferLValue(getProgram(), statementLValue);
|
PassNTypeInference.updateInferedTypeLValue(getProgram(), statementLValue);
|
||||||
// Insert an extra "set low" assignment statement
|
// Insert an extra "set low" assignment statement
|
||||||
Statement setLoHiAssignment = new StatementAssignment(loHiVar, loHiVar, loHiOperator, tmpVarRef, statementLValue.getSource(), new ArrayList<>());
|
Statement setLoHiAssignment = new StatementAssignment(loHiVar, loHiVar, loHiOperator, tmpVarRef, statementLValue.getSource(), new ArrayList<>());
|
||||||
statementsIt.add(setLoHiAssignment);
|
statementsIt.add(setLoHiAssignment);
|
||||||
|
@ -15,7 +15,6 @@ import dk.camelot64.kickc.model.values.VariableRef;
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Pass through the generated statements inferring types of unresolved variables.
|
* Pass through the generated statements inferring types of unresolved variables.
|
||||||
* Also updates procedure calls to point to the actual procedure called.
|
|
||||||
*/
|
*/
|
||||||
public class PassNTypeInference extends Pass2SsaOptimization {
|
public class PassNTypeInference extends Pass2SsaOptimization {
|
||||||
|
|
||||||
@ -23,17 +22,16 @@ public class PassNTypeInference extends Pass2SsaOptimization {
|
|||||||
super(program);
|
super(program);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean step() {
|
public boolean step() {
|
||||||
for(ControlFlowBlock block : getGraph().getAllBlocks()) {
|
for(ControlFlowBlock block : getGraph().getAllBlocks()) {
|
||||||
for(Statement statement : block.getStatements()) {
|
for(Statement statement : block.getStatements()) {
|
||||||
try {
|
try {
|
||||||
if(statement instanceof StatementLValue) {
|
if(statement instanceof StatementLValue) {
|
||||||
inferLValue(getProgram(), (StatementLValue) statement);
|
updateInferedTypeLValue(getProgram(), (StatementLValue) statement);
|
||||||
} else if(statement instanceof StatementPhiBlock) {
|
} else if(statement instanceof StatementPhiBlock) {
|
||||||
for(StatementPhiBlock.PhiVariable phiVariable : ((StatementPhiBlock) statement).getPhiVariables()) {
|
for(StatementPhiBlock.PhiVariable phiVariable : ((StatementPhiBlock) statement).getPhiVariables()) {
|
||||||
inferPhiVariable(getProgram(), phiVariable);
|
updateInferedTypePhiVariable(getProgram(), phiVariable);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} catch(CompileError e) {
|
} catch(CompileError e) {
|
||||||
@ -44,20 +42,20 @@ public class PassNTypeInference extends Pass2SsaOptimization {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void inferLValue(Program program, StatementLValue statementLValue) {
|
static void updateInferedTypeLValue(Program program, StatementLValue statementLValue) {
|
||||||
if(statementLValue instanceof StatementAssignment) {
|
if(statementLValue instanceof StatementAssignment) {
|
||||||
inferAssignmentLValue(program, (StatementAssignment) statementLValue);
|
updateInferedTypeAssignmentLValue(program, (StatementAssignment) statementLValue);
|
||||||
} else if(statementLValue instanceof StatementCall) {
|
} else if(statementLValue instanceof StatementCall) {
|
||||||
inferCallLValue(program, (StatementCall) statementLValue);
|
updateInferedTypeCallLValue(program, (StatementCall) statementLValue);
|
||||||
} else if(statementLValue instanceof StatementCallPointer) {
|
} else if(statementLValue instanceof StatementCallPointer) {
|
||||||
inferCallPointerLValue(program, (StatementCallPointer) statementLValue);
|
updateInferedTypeCallPointerLValue(program, (StatementCallPointer) statementLValue);
|
||||||
} else {
|
} else {
|
||||||
throw new RuntimeException("LValue statement not implemented " + statementLValue);
|
throw new RuntimeException("LValue statement not implemented " + statementLValue);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
private static void inferCallLValue(Program program, StatementCall call) {
|
private static void updateInferedTypeCallLValue(Program program, StatementCall call) {
|
||||||
ProgramScope programScope = program.getScope();
|
ProgramScope programScope = program.getScope();
|
||||||
LValue lValue = call.getlValue();
|
LValue lValue = call.getlValue();
|
||||||
if(lValue instanceof VariableRef) {
|
if(lValue instanceof VariableRef) {
|
||||||
@ -70,7 +68,7 @@ public class PassNTypeInference extends Pass2SsaOptimization {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void inferCallPointerLValue(Program program, StatementCallPointer call) {
|
private static void updateInferedTypeCallPointerLValue(Program program, StatementCallPointer call) {
|
||||||
ProgramScope programScope = program.getScope();
|
ProgramScope programScope = program.getScope();
|
||||||
LValue lValue = call.getlValue();
|
LValue lValue = call.getlValue();
|
||||||
if(lValue instanceof VariableRef) {
|
if(lValue instanceof VariableRef) {
|
||||||
@ -85,7 +83,7 @@ public class PassNTypeInference extends Pass2SsaOptimization {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void inferPhiVariable(Program program, StatementPhiBlock.PhiVariable phiVariable) {
|
private static void updateInferedTypePhiVariable(Program program, StatementPhiBlock.PhiVariable phiVariable) {
|
||||||
ProgramScope programScope = program.getScope();
|
ProgramScope programScope = program.getScope();
|
||||||
Variable symbol = programScope.getVariable(phiVariable.getVariable());
|
Variable symbol = programScope.getVariable(phiVariable.getVariable());
|
||||||
if(SymbolType.VAR.equals(symbol.getType()) || SymbolType.NUMBER.equals(symbol.getType())) {
|
if(SymbolType.VAR.equals(symbol.getType()) || SymbolType.NUMBER.equals(symbol.getType())) {
|
||||||
@ -109,7 +107,7 @@ public class PassNTypeInference extends Pass2SsaOptimization {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void inferAssignmentLValue(Program program, StatementAssignment assignment) {
|
private static void updateInferedTypeAssignmentLValue(Program program, StatementAssignment assignment) {
|
||||||
ProgramScope programScope = program.getScope();
|
ProgramScope programScope = program.getScope();
|
||||||
LValue lValue = assignment.getlValue();
|
LValue lValue = assignment.getlValue();
|
||||||
if(lValue instanceof VariableRef) {
|
if(lValue instanceof VariableRef) {
|
||||||
|
Loading…
Reference in New Issue
Block a user