mirror of
https://gitlab.com/camelot/kickc.git
synced 2024-11-27 04:49:27 +00:00
Working on casts
This commit is contained in:
parent
71cedd4d29
commit
0876603ca7
@ -261,12 +261,11 @@ public class Compiler {
|
||||
optimizations.add(new Pass2TypeInference(program));
|
||||
optimizations.add(new PassNEliminateUnusedVars(program, true));
|
||||
optimizations.add(new Pass2EliminateRedundantCasts(program));
|
||||
optimizations.add(new Pass2NopCastElimination(program));
|
||||
//optimizations.add(new Pass2NopCastElimination(program));
|
||||
optimizations.add(new Pass2EliminateUnusedBlocks(program));
|
||||
optimizations.add(new Pass2RangeResolving(program));
|
||||
optimizations.add(new Pass2ComparisonOptimization(program));
|
||||
optimizations.add(new Pass2ConstantCallPointerIdentification(program));
|
||||
optimizations.add(new Pass2MultiplyToShiftRewriting(program));
|
||||
optimizations.add(new Pass2SizeOfSimplification(program));
|
||||
optimizations.add(new Pass2InlineDerefIdx(program));
|
||||
optimizations.add(new Pass2DeInlineWordDerefIdx(program));
|
||||
@ -303,6 +302,7 @@ public class Compiler {
|
||||
private void pass2InlineConstants() {
|
||||
// Constant inlining optimizations - as the last step to ensure that constant identification has been completed
|
||||
List<Pass2SsaOptimization> constantOptimizations = new ArrayList<>();
|
||||
constantOptimizations.add(new Pass2MultiplyToShiftRewriting(program));
|
||||
constantOptimizations.add(new Pass2AliasElimination(program));
|
||||
constantOptimizations.add(new Pass2ConstantInlining(program));
|
||||
constantOptimizations.add(new Pass2ConstantStringConsolidation(program));
|
||||
|
@ -26,11 +26,7 @@ public class OperatorShiftLeft extends OperatorBinary {
|
||||
|
||||
@Override
|
||||
public SymbolType inferType(SymbolTypeSimple left, SymbolTypeSimple right) {
|
||||
if(SymbolType.isInteger(left) && SymbolType.isInteger(right)) {
|
||||
return SymbolTypeConversion.convertedMathType( (SymbolTypeInteger) left, (SymbolTypeInteger)right);
|
||||
} else {
|
||||
return left;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -25,11 +25,7 @@ public class OperatorShiftRight extends OperatorBinary {
|
||||
|
||||
@Override
|
||||
public SymbolType inferType(SymbolTypeSimple left, SymbolTypeSimple right) {
|
||||
if(SymbolType.isInteger(left) && SymbolType.isInteger(right)) {
|
||||
return SymbolTypeConversion.convertedMathType( (SymbolTypeInteger) left, (SymbolTypeInteger)right);
|
||||
} else {
|
||||
return left;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
@ -6,6 +6,7 @@ import dk.camelot64.kickc.model.Program;
|
||||
import dk.camelot64.kickc.model.operators.Operators;
|
||||
import dk.camelot64.kickc.model.statements.Statement;
|
||||
import dk.camelot64.kickc.model.statements.StatementAssignment;
|
||||
import dk.camelot64.kickc.model.types.SymbolType;
|
||||
import dk.camelot64.kickc.model.values.*;
|
||||
|
||||
import java.util.ListIterator;
|
||||
@ -44,12 +45,12 @@ public class Pass2MultiplyToShiftRewriting extends Pass2SsaOptimization {
|
||||
if(Operators.MULTIPLY.equals(assignment.getOperator())) {
|
||||
getLog().append("Rewriting multiplication to use shift "+statement.toString(getProgram(), false));
|
||||
assignment.setOperator(Operators.SHIFT_LEFT);
|
||||
assignment.setrValue2(new ConstantInteger((long)power2));
|
||||
assignment.setrValue2(new ConstantInteger((long)power2, SymbolType.BYTE));
|
||||
optimized = true;
|
||||
} else if(Operators.DIVIDE.equals(assignment.getOperator())) {
|
||||
getLog().append("Rewriting division to use shift "+statement.toString(getProgram(), false));
|
||||
assignment.setOperator(Operators.SHIFT_RIGHT);
|
||||
assignment.setrValue2(new ConstantInteger((long)power2));
|
||||
assignment.setrValue2(new ConstantInteger((long)power2, SymbolType.BYTE));
|
||||
optimized = true;
|
||||
}
|
||||
}
|
||||
|
@ -333,7 +333,7 @@ public class TestPrograms {
|
||||
|
||||
@Test
|
||||
public void testPointerCast2() throws IOException, URISyntaxException {
|
||||
compileAndCompare("pointer-cast-2");
|
||||
compileAndCompare("pointer-cast-2", log());
|
||||
}
|
||||
|
||||
@Test
|
||||
|
Loading…
Reference in New Issue
Block a user