mirror of
https://gitlab.com/camelot/kickc.git
synced 2024-09-08 17:54:40 +00:00
Call LValue rewrite now using ValueSources.
This commit is contained in:
parent
0057e16517
commit
8a3039112b
@ -70,18 +70,6 @@ public class Pass1UnwindStructValues extends Pass1Base {
|
|||||||
ProgramValueIterator.execute(
|
ProgramValueIterator.execute(
|
||||||
getProgram(), (programValue, currentStmt, stmtIt, currentBlock) -> {
|
getProgram(), (programValue, currentStmt, stmtIt, currentBlock) -> {
|
||||||
if(programValue.get() instanceof StructMemberRef) {
|
if(programValue.get() instanceof StructMemberRef) {
|
||||||
/*
|
|
||||||
StructMemberRef structMemberRef = (StructMemberRef) programValue.get();
|
|
||||||
if(structMemberRef.getStruct() instanceof VariableRef) {
|
|
||||||
StructUnwinding memberVariables = getStructMemberUnwinding(structMemberRef.getStruct(), currentStmt, stmtIt, currentBlock);
|
|
||||||
if(memberVariables != null && memberVariables != POSTPONE_UNWINDING) {
|
|
||||||
RValueUnwinding memberUnwinding = memberVariables.getMemberUnwinding(structMemberRef.getMemberName(), getScope());
|
|
||||||
RValue structMemberVariable = memberUnwinding.getUnwinding(getScope());
|
|
||||||
getLog().append("Replacing struct member reference " + structMemberRef.toString(getProgram()) + " with member unwinding reference " + structMemberVariable.toString(getProgram()));
|
|
||||||
programValue.set(structMemberVariable);
|
|
||||||
}
|
|
||||||
|
|
||||||
*/
|
|
||||||
StructMemberRef structMemberRef = (StructMemberRef) programValue.get();
|
StructMemberRef structMemberRef = (StructMemberRef) programValue.get();
|
||||||
final ValueSource structValueSource = getValueSource(getProgram(), getScope(), structMemberRef.getStruct(), currentStmt, stmtIt, currentBlock);
|
final ValueSource structValueSource = getValueSource(getProgram(), getScope(), structMemberRef.getStruct(), currentStmt, stmtIt, currentBlock);
|
||||||
if(structValueSource != null) {
|
if(structValueSource != null) {
|
||||||
@ -90,8 +78,6 @@ public class Pass1UnwindStructValues extends Pass1Base {
|
|||||||
getLog().append("Replacing struct member reference " + structMemberRef.toString(getProgram()) + " with member unwinding reference " + memberSimpleValue.toString(getProgram()));
|
getLog().append("Replacing struct member reference " + structMemberRef.toString(getProgram()) + " with member unwinding reference " + memberSimpleValue.toString(getProgram()));
|
||||||
programValue.set(memberSimpleValue);
|
programValue.set(memberSimpleValue);
|
||||||
modified.set(true);
|
modified.set(true);
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
@ -106,12 +92,13 @@ public class Pass1UnwindStructValues extends Pass1Base {
|
|||||||
private boolean unwindCall(StatementCall call, ListIterator<Statement> stmtIt, ControlFlowBlock currentBlock) {
|
private boolean unwindCall(StatementCall call, ListIterator<Statement> stmtIt, ControlFlowBlock currentBlock) {
|
||||||
// Unwind struct value return value
|
// Unwind struct value return value
|
||||||
boolean lvalUnwound = false;
|
boolean lvalUnwound = false;
|
||||||
StructUnwinding lValueUnwinding = getStructMemberUnwinding(call.getlValue(), call, stmtIt, currentBlock);
|
|
||||||
if(lValueUnwinding != null && lValueUnwinding != POSTPONE_UNWINDING) {
|
final ValueSource lValueSource = getValueSource(getProgram(), getScope(), call.getlValue(), call, stmtIt, currentBlock);
|
||||||
|
if(lValueSource!=null && lValueSource.isUnwindable()) {
|
||||||
ArrayList<RValue> unwoundMembers = new ArrayList<>();
|
ArrayList<RValue> unwoundMembers = new ArrayList<>();
|
||||||
for(String memberName : lValueUnwinding.getMemberNames()) {
|
for(String memberName : lValueSource.getMemberNames(getScope())) {
|
||||||
RValueUnwinding memberUnwinding = lValueUnwinding.getMemberUnwinding(memberName, getScope());
|
final ValueSource memberUnwinding = lValueSource.getMemberUnwinding(memberName, getProgram(), getScope(), call, currentBlock, stmtIt);
|
||||||
unwoundMembers.add(memberUnwinding.getUnwinding(getScope()));
|
unwoundMembers.add(memberUnwinding.getSimpleValue(getScope()));
|
||||||
}
|
}
|
||||||
ValueList unwoundLValue = new ValueList(unwoundMembers);
|
ValueList unwoundLValue = new ValueList(unwoundMembers);
|
||||||
call.setlValue(unwoundLValue);
|
call.setlValue(unwoundLValue);
|
||||||
@ -295,6 +282,8 @@ public class Pass1UnwindStructValues extends Pass1Base {
|
|||||||
* @return The value source for copying. null if no value source can be created.
|
* @return The value source for copying. null if no value source can be created.
|
||||||
*/
|
*/
|
||||||
public static ValueSource getValueSource(Program program, ProgramScope programScope, Value value, Statement currentStmt, ListIterator<Statement> stmtIt, ControlFlowBlock currentBlock) {
|
public static ValueSource getValueSource(Program program, ProgramScope programScope, Value value, Statement currentStmt, ListIterator<Statement> stmtIt, ControlFlowBlock currentBlock) {
|
||||||
|
if(value==null)
|
||||||
|
return null;
|
||||||
final SymbolType valueType = SymbolTypeInference.inferType(programScope, (RValue) value);
|
final SymbolType valueType = SymbolTypeInference.inferType(programScope, (RValue) value);
|
||||||
if(valueType instanceof SymbolTypeStruct && value instanceof CastValue && ((CastValue) value).getValue() instanceof ValueList) {
|
if(valueType instanceof SymbolTypeStruct && value instanceof CastValue && ((CastValue) value).getValue() instanceof ValueList) {
|
||||||
ValueList valueList = (ValueList) ((CastValue) value).getValue();
|
ValueList valueList = (ValueList) ((CastValue) value).getValue();
|
||||||
|
Loading…
Reference in New Issue
Block a user