mirror of
https://gitlab.com/camelot/kickc.git
synced 2025-01-14 09:30:57 +00:00
Eliminated old getAssignment() methods.
This commit is contained in:
parent
92acd45493
commit
6c4a99240d
@ -3,6 +3,7 @@ package dk.camelot64.kickc.model;
|
||||
import dk.camelot64.kickc.model.statements.Statement;
|
||||
import dk.camelot64.kickc.model.statements.StatementLValue;
|
||||
import dk.camelot64.kickc.model.statements.StatementPhiBlock;
|
||||
import dk.camelot64.kickc.model.statements.StatementSource;
|
||||
import dk.camelot64.kickc.model.symbols.Label;
|
||||
import dk.camelot64.kickc.model.symbols.Procedure;
|
||||
import dk.camelot64.kickc.model.symbols.ProgramScope;
|
||||
@ -120,6 +121,30 @@ public class ControlFlowGraph implements Serializable {
|
||||
this.variableInitValue = variableInitValue;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
StringBuilder s = new StringBuilder();
|
||||
if(block!=null)
|
||||
s.append(block.getLabel()).append("::");
|
||||
if(statementLValue!=null)
|
||||
s.append(statementLValue.toString());
|
||||
if(statementPhi!=null)
|
||||
s.append(statementPhi.toString()).append(" ");
|
||||
if(statementPhiVariable!=null)
|
||||
s.append(statementPhiVariable.toString());
|
||||
if(variableInitValue!=null)
|
||||
s.append(variableInitValue.toString());
|
||||
return s.toString();
|
||||
}
|
||||
|
||||
public StatementSource getSource() {
|
||||
if(statementLValue!=null)
|
||||
return statementLValue.getSource();
|
||||
if(statementPhi!=null)
|
||||
return statementPhi.getSource();
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -2,6 +2,7 @@ package dk.camelot64.kickc.passes;
|
||||
|
||||
import dk.camelot64.kickc.model.CompileError;
|
||||
import dk.camelot64.kickc.model.ControlFlowBlock;
|
||||
import dk.camelot64.kickc.model.ControlFlowGraph;
|
||||
import dk.camelot64.kickc.model.Program;
|
||||
import dk.camelot64.kickc.model.statements.Statement;
|
||||
import dk.camelot64.kickc.model.statements.StatementLValue;
|
||||
@ -9,6 +10,8 @@ import dk.camelot64.kickc.model.values.LValue;
|
||||
import dk.camelot64.kickc.model.values.LvalueIntermediate;
|
||||
import dk.camelot64.kickc.model.values.VariableRef;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Asserts that all intermediate lvalues have been replaced by something else
|
||||
*/
|
||||
@ -26,8 +29,9 @@ public class Pass1AssertNoLValueIntermediate extends Pass1Base {
|
||||
LValue lValue = ((StatementLValue) statement).getlValue();
|
||||
if(lValue instanceof LvalueIntermediate) {
|
||||
VariableRef intermediateVar = ((LvalueIntermediate) lValue).getVariable();
|
||||
StatementLValue assignment = getGraph().getAssignment(intermediateVar);
|
||||
throw new CompileError("Error! LValue is illegal. " + statement + " - definition of lValue " + assignment, assignment.getSource());
|
||||
final List<ControlFlowGraph.VarAssignment> varAssignments = ControlFlowGraph.getVarAssignments(intermediateVar, getGraph(), getScope());
|
||||
final ControlFlowGraph.VarAssignment varAssignment = varAssignments.get(0);
|
||||
throw new CompileError("Error! LValue is illegal. " + statement + " - definition of lValue " + varAssignment, varAssignment.getSource());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,6 +1,7 @@
|
||||
package dk.camelot64.kickc.passes;
|
||||
|
||||
import dk.camelot64.kickc.model.ControlFlowBlock;
|
||||
import dk.camelot64.kickc.model.ControlFlowGraph;
|
||||
import dk.camelot64.kickc.model.Program;
|
||||
import dk.camelot64.kickc.model.operators.Operator;
|
||||
import dk.camelot64.kickc.model.operators.Operators;
|
||||
@ -43,9 +44,11 @@ public class Pass1FixLValuesLoHi extends Pass1Base {
|
||||
if(statement instanceof StatementLValue && ((StatementLValue) statement).getlValue() instanceof LvalueIntermediate) {
|
||||
StatementLValue statementLValue = (StatementLValue) statement;
|
||||
LvalueIntermediate intermediate = (LvalueIntermediate) statementLValue.getlValue();
|
||||
StatementLValue intermediateStmtLValue = getProgram().getGraph().getAssignment(intermediate.getVariable());
|
||||
if(intermediateStmtLValue instanceof StatementAssignment) {
|
||||
StatementAssignment intermediateAssignment = (StatementAssignment) intermediateStmtLValue;
|
||||
final List<ControlFlowGraph.VarAssignment> varAssignments = ControlFlowGraph.getVarAssignments(intermediate.getVariable(), getGraph(), programScope);
|
||||
if(varAssignments.size() == 1) {
|
||||
final ControlFlowGraph.VarAssignment varAssignment = varAssignments.get(0);
|
||||
if(varAssignment.type.equals(ControlFlowGraph.VarAssignment.Type.STATEMENT_LVALUE) && varAssignment.statementLValue instanceof StatementAssignment) {
|
||||
StatementAssignment intermediateAssignment = (StatementAssignment) varAssignment.statementLValue;
|
||||
if(Operators.LOWBYTE.equals(intermediateAssignment.getOperator()) && intermediateAssignment.getrValue1() == null) {
|
||||
// Found assignment to an intermediate low byte lValue <x = ...
|
||||
fixLoHiLValue(programScope, statementsIt, statementLValue, intermediate, intermediateAssignment, Operators.SET_LOWBYTE);
|
||||
@ -59,6 +62,7 @@ public class Pass1FixLValuesLoHi extends Pass1Base {
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Remove intermediates from the code
|
||||
Pass2SsaOptimization.removeAssignments(getGraph(), intermediates);
|
||||
|
Loading…
x
Reference in New Issue
Block a user