1
0
mirror of https://gitlab.com/camelot/kickc.git synced 2024-11-27 04:49:27 +00:00

Eliminated SymbolTypeNumberInference.

This commit is contained in:
jespergravgaard 2019-05-22 23:59:43 +02:00
parent 864b993f14
commit 669064bd37
3 changed files with 18 additions and 54 deletions

View File

@ -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<SymbolTypeIntegerFixed> types = SymbolTypeNumberInference.inferTypes(((ConstantInteger) constantLiteral).getValue());
List<SymbolTypeIntegerFixed> 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<SymbolTypeIntegerFixed> getVariationTypes(Long value) {
ArrayList<SymbolTypeIntegerFixed> 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.

View File

@ -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<SymbolTypeIntegerFixed> inferTypes(Long value) {
ArrayList<SymbolTypeIntegerFixed> potentialTypes = new ArrayList<>();
for(SymbolTypeIntegerFixed typeInteger : SymbolTypeIntegerFixed.getIntegerFixedTypes()) {
if(typeInteger.contains(value)) {
potentialTypes.add(typeInteger);
}
}
return potentialTypes;
}
}

View File

@ -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<SymbolTypeIntegerFixed> 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();
}
}