mirror of
https://gitlab.com/camelot/kickc.git
synced 2024-12-18 08:30:18 +00:00
Added support for multiple procs
This commit is contained in:
parent
5254d7d3a6
commit
e5f1f7f387
@ -1,7 +1,14 @@
|
||||
package dk.camelot64.kickc.icl;
|
||||
|
||||
/**
|
||||
* Compiler Pass eliminating several additions of constants by consolidating them to a single (compile time) constant c1+v+c2 => (c1+c2)+v
|
||||
* Compiler Pass eliminating several additions of constants by consolidating them to a single (compile time) constant c1+v+c2 => (c1+c2)+v
|
||||
*
|
||||
* TODO:
|
||||
* - If sub variable is used in other places consolidation is not allowed!
|
||||
* Example: With only a & b the constants c1 & c2 could be consolidated to b=(c1+c2)+a, a=v. Since c also uses a this is not an option.
|
||||
* a = c1 + v
|
||||
* b = c2 + a
|
||||
* c = a + c3
|
||||
*/
|
||||
public class Pass2ConstantAdditionElimination extends Pass2SsaOptimization {
|
||||
|
||||
|
@ -104,14 +104,20 @@ public class Scope implements Symbol {
|
||||
if (pos >= 0) {
|
||||
String scopeName = name.substring(0, pos);
|
||||
String rest = name.substring(pos + 2);
|
||||
Symbol scopeSym = symbols.get(scopeName);
|
||||
Symbol scopeSym = getSymbol(scopeName);
|
||||
if (scopeSym instanceof Scope) {
|
||||
return ((Scope) scopeSym).getSymbol(rest);
|
||||
} else {
|
||||
throw new RuntimeException("Error looking up symbol " + name);
|
||||
}
|
||||
} else {
|
||||
return symbols.get(name);
|
||||
Symbol symbol = symbols.get(name);
|
||||
if(symbol==null) {
|
||||
if(parentScope!=null) {
|
||||
symbol = parentScope.getSymbol(name);
|
||||
}
|
||||
}
|
||||
return symbol;
|
||||
}
|
||||
}
|
||||
|
||||
@ -159,7 +165,7 @@ public class Scope implements Symbol {
|
||||
}
|
||||
|
||||
public Procedure getProcedure(String name) {
|
||||
Symbol symbol = symbols.get(name);
|
||||
Symbol symbol = getSymbol(name);
|
||||
if (symbol != null && symbol instanceof Procedure) {
|
||||
return (Procedure) symbol;
|
||||
} else {
|
||||
|
@ -64,7 +64,7 @@ public class Main {
|
||||
List<Pass2SsaOptimization> optimizations = new ArrayList<>();
|
||||
optimizations.add(new Pass2CullEmptyBlocks(controlFlowGraph, programScope));
|
||||
optimizations.add(new Pass2ConstantPropagation(controlFlowGraph, programScope));
|
||||
optimizations.add(new Pass2ConstantAdditionElimination(controlFlowGraph, programScope));
|
||||
//optimizations.add(new Pass2ConstantAdditionElimination(controlFlowGraph, programScope));
|
||||
optimizations.add(new Pass2AliasElimination(controlFlowGraph, programScope));
|
||||
optimizations.add(new Pass2RedundantPhiElimination(controlFlowGraph, programScope));
|
||||
optimizations.add(new Pass2SelfPhiElimination(controlFlowGraph, programScope));
|
||||
|
@ -1,10 +1,14 @@
|
||||
byte a = 12;
|
||||
byte s = sum(5,a);
|
||||
a = a+s; q
|
||||
a = a+s;
|
||||
a = sum(s, a);
|
||||
|
||||
byte sum(byte b1, byte b2) {
|
||||
byte b = b1+b2;
|
||||
return b;
|
||||
return inc(b);
|
||||
}
|
||||
|
||||
byte inc(byte b) {
|
||||
return b+1;
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user