mirror of
https://gitlab.com/camelot/kickc.git
synced 2025-01-12 11:31:11 +00:00
Working on static initialization rewrite _init(). #257
This commit is contained in:
parent
ea52aa7f2b
commit
57d5d4500b
@ -217,8 +217,11 @@ public class Compiler {
|
|||||||
getLog().append(procedureCompilation.getStatementSequence().toString(program));
|
getLog().append(procedureCompilation.getStatementSequence().toString(program));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
new Pass1GenerateControlFlowGraph(program).execute();
|
new Pass1GenerateControlFlowGraph(program).execute();
|
||||||
|
if(getLog().isVerbosePass1CreateSsa()) {
|
||||||
|
getLog().append("FIRST CONTROL FLOW GRAPH");
|
||||||
|
getLog().append(program.getGraph().toString(program));
|
||||||
|
}
|
||||||
new Pass1ResolveForwardReferences(program).execute();
|
new Pass1ResolveForwardReferences(program).execute();
|
||||||
new Pass1AssertProcedureDefined(program).execute();
|
new Pass1AssertProcedureDefined(program).execute();
|
||||||
new Pass1AssertVariableDefined(program).execute();
|
new Pass1AssertVariableDefined(program).execute();
|
||||||
|
@ -35,6 +35,13 @@ public class Pass1GenerateControlFlowGraph extends Pass1Base {
|
|||||||
ControlFlowBlock procBlock = getOrCreateBlock(procedure.getLabel().getRef(), procedure.getRef());
|
ControlFlowBlock procBlock = getOrCreateBlock(procedure.getLabel().getRef(), procedure.getRef());
|
||||||
currentBlock = procBlock;
|
currentBlock = procBlock;
|
||||||
for(Statement statement : sequence.getStatements()) {
|
for(Statement statement : sequence.getStatements()) {
|
||||||
|
Symbol currentBlockLabel = getProgram().getScope().getSymbol(currentBlock.getLabel());
|
||||||
|
Scope currentBlockScope;
|
||||||
|
if(currentBlockLabel instanceof Procedure) {
|
||||||
|
currentBlockScope = (Scope) currentBlockLabel;
|
||||||
|
} else {
|
||||||
|
currentBlockScope = currentBlockLabel.getScope();
|
||||||
|
}
|
||||||
if(statement instanceof StatementProcedureBegin) {
|
if(statement instanceof StatementProcedureBegin) {
|
||||||
// Do nothing
|
// Do nothing
|
||||||
} else if(statement instanceof StatementProcedureEnd) {
|
} else if(statement instanceof StatementProcedureEnd) {
|
||||||
@ -42,7 +49,7 @@ public class Pass1GenerateControlFlowGraph extends Pass1Base {
|
|||||||
currentBlock.setDefaultSuccessor(new Label(SymbolRef.PROCEXIT_BLOCK_NAME, programScope, false).getRef());
|
currentBlock.setDefaultSuccessor(new Label(SymbolRef.PROCEXIT_BLOCK_NAME, programScope, false).getRef());
|
||||||
} else if(statement instanceof StatementLabel) {
|
} else if(statement instanceof StatementLabel) {
|
||||||
StatementLabel statementLabel = (StatementLabel) statement;
|
StatementLabel statementLabel = (StatementLabel) statement;
|
||||||
ControlFlowBlock nextBlock = getOrCreateBlock(statementLabel.getLabel(), procedure.getRef());
|
ControlFlowBlock nextBlock = getOrCreateBlock(statementLabel.getLabel(), currentBlock.getScope());
|
||||||
nextBlock.setComments(statementLabel.getComments());
|
nextBlock.setComments(statementLabel.getComments());
|
||||||
currentBlock.setDefaultSuccessor(nextBlock.getLabel());
|
currentBlock.setDefaultSuccessor(nextBlock.getLabel());
|
||||||
currentBlock = nextBlock;
|
currentBlock = nextBlock;
|
||||||
@ -50,13 +57,13 @@ public class Pass1GenerateControlFlowGraph extends Pass1Base {
|
|||||||
StatementJump statementJump = (StatementJump) statement;
|
StatementJump statementJump = (StatementJump) statement;
|
||||||
ControlFlowBlock jmpBlock = getOrCreateBlock(statementJump.getDestination(), currentBlock.getScope());
|
ControlFlowBlock jmpBlock = getOrCreateBlock(statementJump.getDestination(), currentBlock.getScope());
|
||||||
currentBlock.setDefaultSuccessor(jmpBlock.getLabel());
|
currentBlock.setDefaultSuccessor(jmpBlock.getLabel());
|
||||||
ControlFlowBlock nextBlock = getOrCreateBlock(procedure.addLabelIntermediate().getRef(), currentBlock.getScope());
|
ControlFlowBlock nextBlock = getOrCreateBlock(currentBlockScope.addLabelIntermediate().getRef(), currentBlock.getScope());
|
||||||
currentBlock = nextBlock;
|
currentBlock = nextBlock;
|
||||||
} else if(statement instanceof StatementConditionalJump) {
|
} else if(statement instanceof StatementConditionalJump) {
|
||||||
currentBlock.addStatement(statement);
|
currentBlock.addStatement(statement);
|
||||||
StatementConditionalJump statementConditionalJump = (StatementConditionalJump) statement;
|
StatementConditionalJump statementConditionalJump = (StatementConditionalJump) statement;
|
||||||
ControlFlowBlock jmpBlock = getOrCreateBlock(statementConditionalJump.getDestination(), currentBlock.getScope());
|
ControlFlowBlock jmpBlock = getOrCreateBlock(statementConditionalJump.getDestination(), currentBlock.getScope());
|
||||||
ControlFlowBlock nextBlock = getOrCreateBlock(procedure.addLabelIntermediate().getRef(), currentBlock.getScope());
|
ControlFlowBlock nextBlock = getOrCreateBlock(currentBlockScope.addLabelIntermediate().getRef(), currentBlock.getScope());
|
||||||
currentBlock.setDefaultSuccessor(nextBlock.getLabel());
|
currentBlock.setDefaultSuccessor(nextBlock.getLabel());
|
||||||
currentBlock.setConditionalSuccessor(jmpBlock.getLabel());
|
currentBlock.setConditionalSuccessor(jmpBlock.getLabel());
|
||||||
currentBlock = nextBlock;
|
currentBlock = nextBlock;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user