From 81e214cee309c9a0264441a025e53573aea9c521 Mon Sep 17 00:00:00 2001 From: Jesper Gravgaard Date: Sun, 22 Jul 2018 16:24:08 +0900 Subject: [PATCH] Now replacing in both control flow graph and symbol table per default. --- src/main/java/dk/camelot64/kickc/CompileLog.java | 2 +- .../kickc/passes/Pass2ConstantInlining.java | 13 +------------ .../kickc/passes/Pass2SsaOptimization.java | 4 ++-- .../dk/camelot64/kickc/test/ref/flipper-rex2.log | 8 ++++---- .../dk/camelot64/kickc/test/ref/flipper-rex2.sym | 4 ++-- 5 files changed, 10 insertions(+), 21 deletions(-) diff --git a/src/main/java/dk/camelot64/kickc/CompileLog.java b/src/main/java/dk/camelot64/kickc/CompileLog.java index 579113205..108e34535 100644 --- a/src/main/java/dk/camelot64/kickc/CompileLog.java +++ b/src/main/java/dk/camelot64/kickc/CompileLog.java @@ -35,7 +35,7 @@ public class CompileLog { /** * Should the log be output to System.out while being built */ - private boolean sysOut = false; + private boolean sysOut = true; public CompileLog() { this.log = new StringBuilder(); diff --git a/src/main/java/dk/camelot64/kickc/passes/Pass2ConstantInlining.java b/src/main/java/dk/camelot64/kickc/passes/Pass2ConstantInlining.java index 6307a7242..179d8c4ea 100644 --- a/src/main/java/dk/camelot64/kickc/passes/Pass2ConstantInlining.java +++ b/src/main/java/dk/camelot64/kickc/passes/Pass2ConstantInlining.java @@ -48,12 +48,10 @@ public class Pass2ConstantInlining extends Pass2SsaOptimization { // Perform alias replacement within the constant values inside the aliases replaceInValues(inline); - // Replace all usages of the constants in the control flow graph + // Replace all usages of the constants in the control flow graph or symbol table replaceVariables(inline); // Remove from symbol table deleteSymbols(inline.keySet()); - // Replace all usages of the constants in constant definitions inside the symbol table - replaceInSymbolTable(inline); for(ConstantRef constantRef : inline.keySet()) { getLog().append("Constant inlined " + constantRef.toString() + " = " + inline.get(constantRef).toString(getProgram())); @@ -84,15 +82,6 @@ public class Pass2ConstantInlining extends Pass2SsaOptimization { } } - /** - * Replace any alias within the constant defintions inside the symbol table - * - * @param inline The replacements to make - */ - private void replaceInSymbolTable(Map inline) { - ProgramValueIterator.execute(getScope(), new AliasReplacer(inline)); - } - /** * Find all unnamed constants $1 = VIC+$20 * diff --git a/src/main/java/dk/camelot64/kickc/passes/Pass2SsaOptimization.java b/src/main/java/dk/camelot64/kickc/passes/Pass2SsaOptimization.java index 39a7ecf34..4d9ab0e58 100644 --- a/src/main/java/dk/camelot64/kickc/passes/Pass2SsaOptimization.java +++ b/src/main/java/dk/camelot64/kickc/passes/Pass2SsaOptimization.java @@ -41,12 +41,12 @@ public abstract class Pass2SsaOptimization extends Pass1Base { public abstract boolean step(); /** - * Replace all usages of variables in statements with aliases. + * Replace all usages of variables in statements (or symbol table) with aliases. * * @param aliases Variables that have alias values. */ public void replaceVariables(final Map aliases) { - ProgramValueIterator.execute(getGraph(), new AliasReplacer(aliases)); + ProgramValueIterator.execute(getProgram(), new AliasReplacer(aliases)); } /** diff --git a/src/test/java/dk/camelot64/kickc/test/ref/flipper-rex2.log b/src/test/java/dk/camelot64/kickc/test/ref/flipper-rex2.log index 39520a9fd..d4f2c46a5 100644 --- a/src/test/java/dk/camelot64/kickc/test/ref/flipper-rex2.log +++ b/src/test/java/dk/camelot64/kickc/test/ref/flipper-rex2.log @@ -1030,8 +1030,8 @@ Loop head: prepare::@1 tails: prepare::@1 blocks: prepare::@1 depth: 1 VARIABLE REGISTER WEIGHTS (byte*) RASTER (byte*) SCREEN -(byte[$0]) buffer1 -(byte[$1]) buffer2 +(byte[16*16]) buffer1 +(byte[16*16]) buffer2 (void()) flip() (byte) flip::c (byte) flip::c#1 1501.5 @@ -1823,9 +1823,9 @@ FINAL SYMBOL TABLE (const byte*) RASTER#0 RASTER = ((byte*))(word/dword/signed dword) 53266 (byte*) SCREEN (const byte*) SCREEN#0 SCREEN = ((byte*))(word/signed word/dword/signed dword) 1024 -(byte[$0]) buffer1 +(byte[16*16]) buffer1 (const byte[16*16]) buffer1#0 buffer1 = { fill( 16*16, 0) } -(byte[$1]) buffer2 +(byte[16*16]) buffer2 (const byte[16*16]) buffer2#0 buffer2 = { fill( 16*16, 0) } (void()) flip() (label) flip::@1 diff --git a/src/test/java/dk/camelot64/kickc/test/ref/flipper-rex2.sym b/src/test/java/dk/camelot64/kickc/test/ref/flipper-rex2.sym index 2c38ec2c2..d57fa8ea7 100644 --- a/src/test/java/dk/camelot64/kickc/test/ref/flipper-rex2.sym +++ b/src/test/java/dk/camelot64/kickc/test/ref/flipper-rex2.sym @@ -5,9 +5,9 @@ (const byte*) RASTER#0 RASTER = ((byte*))(word/dword/signed dword) 53266 (byte*) SCREEN (const byte*) SCREEN#0 SCREEN = ((byte*))(word/signed word/dword/signed dword) 1024 -(byte[$0]) buffer1 +(byte[16*16]) buffer1 (const byte[16*16]) buffer1#0 buffer1 = { fill( 16*16, 0) } -(byte[$1]) buffer2 +(byte[16*16]) buffer2 (const byte[16*16]) buffer2#0 buffer2 = { fill( 16*16, 0) } (void()) flip() (label) flip::@1