From 669064bd37dae72f3aa3e851b388263f865c020d Mon Sep 17 00:00:00 2001 From: jespergravgaard Date: Wed, 22 May 2019 23:59:43 +0200 Subject: [PATCH] Eliminated SymbolTypeNumberInference. --- .../fragment/AsmFragmentInstanceSpec.java | 20 ++++++++++++-- .../types/SymbolTypeNumberInference.java | 27 ------------------- .../passes/PassNTypeIdSimplification.java | 25 ----------------- 3 files changed, 18 insertions(+), 54 deletions(-) delete mode 100644 src/main/java/dk/camelot64/kickc/model/types/SymbolTypeNumberInference.java diff --git a/src/main/java/dk/camelot64/kickc/fragment/AsmFragmentInstanceSpec.java b/src/main/java/dk/camelot64/kickc/fragment/AsmFragmentInstanceSpec.java index 09d9be44f..9a003f18b 100644 --- a/src/main/java/dk/camelot64/kickc/fragment/AsmFragmentInstanceSpec.java +++ b/src/main/java/dk/camelot64/kickc/fragment/AsmFragmentInstanceSpec.java @@ -4,7 +4,6 @@ import dk.camelot64.kickc.model.Program; import dk.camelot64.kickc.model.statements.Statement; import dk.camelot64.kickc.model.types.SymbolType; import dk.camelot64.kickc.model.types.SymbolTypeIntegerFixed; -import dk.camelot64.kickc.model.types.SymbolTypeNumberInference; import dk.camelot64.kickc.model.values.*; import java.util.*; @@ -49,6 +48,7 @@ public class AsmFragmentInstanceSpec { this.codeScopeRef = codeScopeRef; } + public String getSignature() { return signature; } @@ -95,7 +95,7 @@ public class AsmFragmentInstanceSpec { if(value instanceof ConstantValue) { ConstantLiteral constantLiteral = ((ConstantValue) value).calculateLiteral(program.getScope()); if(constantLiteral instanceof ConstantInteger) { - List types = SymbolTypeNumberInference.inferTypes(((ConstantInteger) constantLiteral).getValue()); + List types = getVariationTypes(((ConstantInteger) constantLiteral).getValue()); if(types.size() > 1) { // Found constant value with multiple types variationConstant = (ConstantValue) value; @@ -118,6 +118,22 @@ public class AsmFragmentInstanceSpec { return variationIterator.hasNext(); } + /** + * Find any fixed integer types that can contain the passed integer value + * @param value the value to examine + * @return All fixed size integer types capable of representing the passed value + */ + public static List getVariationTypes(Long value) { + ArrayList potentialTypes = new ArrayList<>(); + for(SymbolTypeIntegerFixed typeInteger : SymbolTypeIntegerFixed.getIntegerFixedTypes()) { + if(typeInteger.contains(value)) { + potentialTypes.add(typeInteger); + } + } + return potentialTypes; + } + + /** * Updates the ASM fragment instance specification to the next available variation. * If no more variations exist the ASM fragment instance specification will become unusable. diff --git a/src/main/java/dk/camelot64/kickc/model/types/SymbolTypeNumberInference.java b/src/main/java/dk/camelot64/kickc/model/types/SymbolTypeNumberInference.java deleted file mode 100644 index 9a1519369..000000000 --- a/src/main/java/dk/camelot64/kickc/model/types/SymbolTypeNumberInference.java +++ /dev/null @@ -1,27 +0,0 @@ -package dk.camelot64.kickc.model.types; - -import java.util.ArrayList; -import java.util.List; - -/** - * Interference of possible types for constant expressions with the {@link SymbolType#NUMBER} type. - * This is done by evaluating the constant expression to find the literal value. - */ -public class SymbolTypeNumberInference { - - /** - * Find any fixed integer types that can contain the passed integer value - * @param value the value to examine - * @return All fixed size integer types capable of representing the passed value - */ - public static List inferTypes(Long value) { - ArrayList potentialTypes = new ArrayList<>(); - for(SymbolTypeIntegerFixed typeInteger : SymbolTypeIntegerFixed.getIntegerFixedTypes()) { - if(typeInteger.contains(value)) { - potentialTypes.add(typeInteger); - } - } - return potentialTypes; - } - -} diff --git a/src/main/java/dk/camelot64/kickc/passes/PassNTypeIdSimplification.java b/src/main/java/dk/camelot64/kickc/passes/PassNTypeIdSimplification.java index 1b110077d..1e6b5ffd0 100644 --- a/src/main/java/dk/camelot64/kickc/passes/PassNTypeIdSimplification.java +++ b/src/main/java/dk/camelot64/kickc/passes/PassNTypeIdSimplification.java @@ -42,31 +42,6 @@ public class PassNTypeIdSimplification extends Pass2SsaOptimization { } }); - /* - for(ControlFlowBlock block : getGraph().getAllBlocks()) { - for(Statement statement : block.getStatements()) { - if(statement instanceof StatementAssignment) { - StatementAssignment assignment = (StatementAssignment) statement; - if(Operators.TYPEID.equals(assignment.getOperator())) { - RValue rValue = assignment.getrValue2(); - SymbolType symbolType = SymbolTypeInference.inferType(getSymbols(), rValue); - if(SymbolType.NUMBER.equals(symbolType)) { - if(rValue instanceof ConstantValue) { - List fixedTypes = SymbolTypeNumberInference.inferTypes(getSymbols(), (ConstantLiteral) rValue); - throw new InternalError("TODO: Implement typeof(const)!"); - } - } else { - getLog().append("Resolving typeid() " + assignment.toString(getProgram(), false)); - ConstantRef typeIDConstantVar = OperatorTypeId.getTypeIdConstantVar(getSymbols(), symbolType); - assignment.setrValue2(typeIDConstantVar); - assignment.setOperator(null); - modified = true; - } - } - } - } - } - */ return modified.get(); } }