1
0
mirror of https://gitlab.com/camelot/kickc.git synced 2025-02-16 18:30:37 +00:00

Renamed constantValue getter/setter.

This commit is contained in:
jespergravgaard 2019-10-31 22:51:31 +01:00
parent 445f104309
commit 79d4f6f1a5
21 changed files with 931 additions and 946 deletions

View File

@ -91,7 +91,7 @@ public class AsmFragmentInstance {
String constantValueAsm = AsmFormat.getAsmConstant(program, constantVar.getRef(), 99, codeScopeRef);
boolean constantValueZp = SymbolType.BYTE.equals(constantVar.getType());
if(!constantValueZp) {
constantValueZp = isConstantValueZp(constantVar.getValue());
constantValueZp = isConstantValueZp(constantVar.getConstantValue());
}
return new AsmParameter(constantValueAsm, constantValueZp);
} else if(boundValue instanceof ConstantValue) {
@ -128,7 +128,7 @@ public class AsmFragmentInstance {
}
if(boundConst instanceof ConstantRef) {
ConstantVar reffedConstant = program.getScope().getConstant((ConstantRef) boundConst);
return isConstantValueZp(reffedConstant.getValue());
return isConstantValueZp(reffedConstant.getConstantValue());
}
if(boundConst instanceof ConstantCastValue) {
SymbolType toType = ((ConstantCastValue) boundConst).getToType();

View File

@ -638,12 +638,12 @@ public interface ProgramValue {
@Override
public Value get() {
return constantVar.getValue();
return constantVar.getConstantValue();
}
@Override
public void set(Value val) {
constantVar.setValue((ConstantValue) val);
constantVar.setConstantValue((ConstantValue) val);
}
}

View File

@ -10,7 +10,7 @@ public class ConstantVar extends SymbolVariable {
public ConstantVar(String name, Scope scope, SymbolType type, ConstantValue value, String dataSegment) {
super(name, scope, type, StorageStrategy.CONSTANT, MemoryArea.MAIN_MEMORY, dataSegment);
setValue(value);
setConstantValue(value);
}
@Override

View File

@ -368,7 +368,7 @@ public abstract class Scope implements Symbol, Serializable {
}
if(symbol instanceof ConstantVar) {
ConstantVar constVar = (ConstantVar) symbol;
res.append(" = " + constVar.getValue().toString(program));
res.append(" = " + constVar.getConstantValue().toString(program));
}
}
res.append("\n");

View File

@ -85,7 +85,7 @@ public abstract class SymbolVariable implements Symbol {
private String dataSegment;
/** The constant value if the variable is a constant. Null otherwise. */
private ConstantValue value;
private ConstantValue constantValue;
public SymbolVariable(String name, Scope scope, SymbolType type, StorageStrategy storageStrategy, MemoryArea memoryArea, String dataSegment) {
this.name = name;
@ -105,12 +105,12 @@ public abstract class SymbolVariable implements Symbol {
fullName = (scopeName.length() > 0) ? scopeName + "::" + name : name;
}
public ConstantValue getValue() {
return value;
public ConstantValue getConstantValue() {
return constantValue;
}
public void setValue(ConstantValue value) {
this.value = value;
public void setConstantValue(ConstantValue value) {
this.constantValue = value;
}
public String getDataSegment() {

View File

@ -20,7 +20,7 @@ public class ConstantRef extends SymbolVariableRef implements ConstantValue {
@Override
public ConstantLiteral calculateLiteral(ProgramScope scope) {
ConstantVar constantVar = scope.getConstant(this);
ConstantValue constantVarValue = constantVar.getValue();
ConstantValue constantVarValue = constantVar.getConstantValue();
return constantVarValue.calculateLiteral(scope);
}
}

File diff suppressed because it is too large Load Diff

View File

@ -349,30 +349,6 @@ public class KickCParserBaseListener implements KickCParserListener {
* <p>The default implementation does nothing.</p>
*/
@Override public void exitDirectiveMaybeConst(KickCParser.DirectiveMaybeConstContext ctx) { }
/**
* {@inheritDoc}
*
* <p>The default implementation does nothing.</p>
*/
@Override public void enterDirectiveExtern(KickCParser.DirectiveExternContext ctx) { }
/**
* {@inheritDoc}
*
* <p>The default implementation does nothing.</p>
*/
@Override public void exitDirectiveExtern(KickCParser.DirectiveExternContext ctx) { }
/**
* {@inheritDoc}
*
* <p>The default implementation does nothing.</p>
*/
@Override public void enterDirectiveExport(KickCParser.DirectiveExportContext ctx) { }
/**
* {@inheritDoc}
*
* <p>The default implementation does nothing.</p>
*/
@Override public void exitDirectiveExport(KickCParser.DirectiveExportContext ctx) { }
/**
* {@inheritDoc}
*
@ -433,6 +409,30 @@ public class KickCParserBaseListener implements KickCParserListener {
* <p>The default implementation does nothing.</p>
*/
@Override public void exitDirectiveMemoryAreaAddress(KickCParser.DirectiveMemoryAreaAddressContext ctx) { }
/**
* {@inheritDoc}
*
* <p>The default implementation does nothing.</p>
*/
@Override public void enterDirectiveVolatile(KickCParser.DirectiveVolatileContext ctx) { }
/**
* {@inheritDoc}
*
* <p>The default implementation does nothing.</p>
*/
@Override public void exitDirectiveVolatile(KickCParser.DirectiveVolatileContext ctx) { }
/**
* {@inheritDoc}
*
* <p>The default implementation does nothing.</p>
*/
@Override public void enterDirectiveNotVolatile(KickCParser.DirectiveNotVolatileContext ctx) { }
/**
* {@inheritDoc}
*
* <p>The default implementation does nothing.</p>
*/
@Override public void exitDirectiveNotVolatile(KickCParser.DirectiveNotVolatileContext ctx) { }
/**
* {@inheritDoc}
*
@ -457,6 +457,30 @@ public class KickCParserBaseListener implements KickCParserListener {
* <p>The default implementation does nothing.</p>
*/
@Override public void exitDirectiveFormNotSsa(KickCParser.DirectiveFormNotSsaContext ctx) { }
/**
* {@inheritDoc}
*
* <p>The default implementation does nothing.</p>
*/
@Override public void enterDirectiveExtern(KickCParser.DirectiveExternContext ctx) { }
/**
* {@inheritDoc}
*
* <p>The default implementation does nothing.</p>
*/
@Override public void exitDirectiveExtern(KickCParser.DirectiveExternContext ctx) { }
/**
* {@inheritDoc}
*
* <p>The default implementation does nothing.</p>
*/
@Override public void enterDirectiveExport(KickCParser.DirectiveExportContext ctx) { }
/**
* {@inheritDoc}
*
* <p>The default implementation does nothing.</p>
*/
@Override public void exitDirectiveExport(KickCParser.DirectiveExportContext ctx) { }
/**
* {@inheritDoc}
*
@ -469,30 +493,6 @@ public class KickCParserBaseListener implements KickCParserListener {
* <p>The default implementation does nothing.</p>
*/
@Override public void exitDirectiveInline(KickCParser.DirectiveInlineContext ctx) { }
/**
* {@inheritDoc}
*
* <p>The default implementation does nothing.</p>
*/
@Override public void enterDirectiveVolatile(KickCParser.DirectiveVolatileContext ctx) { }
/**
* {@inheritDoc}
*
* <p>The default implementation does nothing.</p>
*/
@Override public void exitDirectiveVolatile(KickCParser.DirectiveVolatileContext ctx) { }
/**
* {@inheritDoc}
*
* <p>The default implementation does nothing.</p>
*/
@Override public void enterDirectiveNotVolatile(KickCParser.DirectiveNotVolatileContext ctx) { }
/**
* {@inheritDoc}
*
* <p>The default implementation does nothing.</p>
*/
@Override public void exitDirectiveNotVolatile(KickCParser.DirectiveNotVolatileContext ctx) { }
/**
* {@inheritDoc}
*

View File

@ -209,20 +209,6 @@ public class KickCParserBaseVisitor<T> extends AbstractParseTreeVisitor<T> imple
* {@link #visitChildren} on {@code ctx}.</p>
*/
@Override public T visitDirectiveMaybeConst(KickCParser.DirectiveMaybeConstContext ctx) { return visitChildren(ctx); }
/**
* {@inheritDoc}
*
* <p>The default implementation returns the result of calling
* {@link #visitChildren} on {@code ctx}.</p>
*/
@Override public T visitDirectiveExtern(KickCParser.DirectiveExternContext ctx) { return visitChildren(ctx); }
/**
* {@inheritDoc}
*
* <p>The default implementation returns the result of calling
* {@link #visitChildren} on {@code ctx}.</p>
*/
@Override public T visitDirectiveExport(KickCParser.DirectiveExportContext ctx) { return visitChildren(ctx); }
/**
* {@inheritDoc}
*
@ -258,6 +244,20 @@ public class KickCParserBaseVisitor<T> extends AbstractParseTreeVisitor<T> imple
* {@link #visitChildren} on {@code ctx}.</p>
*/
@Override public T visitDirectiveMemoryAreaAddress(KickCParser.DirectiveMemoryAreaAddressContext ctx) { return visitChildren(ctx); }
/**
* {@inheritDoc}
*
* <p>The default implementation returns the result of calling
* {@link #visitChildren} on {@code ctx}.</p>
*/
@Override public T visitDirectiveVolatile(KickCParser.DirectiveVolatileContext ctx) { return visitChildren(ctx); }
/**
* {@inheritDoc}
*
* <p>The default implementation returns the result of calling
* {@link #visitChildren} on {@code ctx}.</p>
*/
@Override public T visitDirectiveNotVolatile(KickCParser.DirectiveNotVolatileContext ctx) { return visitChildren(ctx); }
/**
* {@inheritDoc}
*
@ -272,6 +272,20 @@ public class KickCParserBaseVisitor<T> extends AbstractParseTreeVisitor<T> imple
* {@link #visitChildren} on {@code ctx}.</p>
*/
@Override public T visitDirectiveFormNotSsa(KickCParser.DirectiveFormNotSsaContext ctx) { return visitChildren(ctx); }
/**
* {@inheritDoc}
*
* <p>The default implementation returns the result of calling
* {@link #visitChildren} on {@code ctx}.</p>
*/
@Override public T visitDirectiveExtern(KickCParser.DirectiveExternContext ctx) { return visitChildren(ctx); }
/**
* {@inheritDoc}
*
* <p>The default implementation returns the result of calling
* {@link #visitChildren} on {@code ctx}.</p>
*/
@Override public T visitDirectiveExport(KickCParser.DirectiveExportContext ctx) { return visitChildren(ctx); }
/**
* {@inheritDoc}
*
@ -279,20 +293,6 @@ public class KickCParserBaseVisitor<T> extends AbstractParseTreeVisitor<T> imple
* {@link #visitChildren} on {@code ctx}.</p>
*/
@Override public T visitDirectiveInline(KickCParser.DirectiveInlineContext ctx) { return visitChildren(ctx); }
/**
* {@inheritDoc}
*
* <p>The default implementation returns the result of calling
* {@link #visitChildren} on {@code ctx}.</p>
*/
@Override public T visitDirectiveVolatile(KickCParser.DirectiveVolatileContext ctx) { return visitChildren(ctx); }
/**
* {@inheritDoc}
*
* <p>The default implementation returns the result of calling
* {@link #visitChildren} on {@code ctx}.</p>
*/
@Override public T visitDirectiveNotVolatile(KickCParser.DirectiveNotVolatileContext ctx) { return visitChildren(ctx); }
/**
* {@inheritDoc}
*

View File

@ -321,30 +321,6 @@ public interface KickCParserListener extends ParseTreeListener {
* @param ctx the parse tree
*/
void exitDirectiveMaybeConst(KickCParser.DirectiveMaybeConstContext ctx);
/**
* Enter a parse tree produced by the {@code directiveExtern}
* labeled alternative in {@link KickCParser#directive}.
* @param ctx the parse tree
*/
void enterDirectiveExtern(KickCParser.DirectiveExternContext ctx);
/**
* Exit a parse tree produced by the {@code directiveExtern}
* labeled alternative in {@link KickCParser#directive}.
* @param ctx the parse tree
*/
void exitDirectiveExtern(KickCParser.DirectiveExternContext ctx);
/**
* Enter a parse tree produced by the {@code directiveExport}
* labeled alternative in {@link KickCParser#directive}.
* @param ctx the parse tree
*/
void enterDirectiveExport(KickCParser.DirectiveExportContext ctx);
/**
* Exit a parse tree produced by the {@code directiveExport}
* labeled alternative in {@link KickCParser#directive}.
* @param ctx the parse tree
*/
void exitDirectiveExport(KickCParser.DirectiveExportContext ctx);
/**
* Enter a parse tree produced by the {@code directiveAlign}
* labeled alternative in {@link KickCParser#directive}.
@ -405,6 +381,30 @@ public interface KickCParserListener extends ParseTreeListener {
* @param ctx the parse tree
*/
void exitDirectiveMemoryAreaAddress(KickCParser.DirectiveMemoryAreaAddressContext ctx);
/**
* Enter a parse tree produced by the {@code directiveVolatile}
* labeled alternative in {@link KickCParser#directive}.
* @param ctx the parse tree
*/
void enterDirectiveVolatile(KickCParser.DirectiveVolatileContext ctx);
/**
* Exit a parse tree produced by the {@code directiveVolatile}
* labeled alternative in {@link KickCParser#directive}.
* @param ctx the parse tree
*/
void exitDirectiveVolatile(KickCParser.DirectiveVolatileContext ctx);
/**
* Enter a parse tree produced by the {@code directiveNotVolatile}
* labeled alternative in {@link KickCParser#directive}.
* @param ctx the parse tree
*/
void enterDirectiveNotVolatile(KickCParser.DirectiveNotVolatileContext ctx);
/**
* Exit a parse tree produced by the {@code directiveNotVolatile}
* labeled alternative in {@link KickCParser#directive}.
* @param ctx the parse tree
*/
void exitDirectiveNotVolatile(KickCParser.DirectiveNotVolatileContext ctx);
/**
* Enter a parse tree produced by the {@code directiveFormSsa}
* labeled alternative in {@link KickCParser#directive}.
@ -429,6 +429,30 @@ public interface KickCParserListener extends ParseTreeListener {
* @param ctx the parse tree
*/
void exitDirectiveFormNotSsa(KickCParser.DirectiveFormNotSsaContext ctx);
/**
* Enter a parse tree produced by the {@code directiveExtern}
* labeled alternative in {@link KickCParser#directive}.
* @param ctx the parse tree
*/
void enterDirectiveExtern(KickCParser.DirectiveExternContext ctx);
/**
* Exit a parse tree produced by the {@code directiveExtern}
* labeled alternative in {@link KickCParser#directive}.
* @param ctx the parse tree
*/
void exitDirectiveExtern(KickCParser.DirectiveExternContext ctx);
/**
* Enter a parse tree produced by the {@code directiveExport}
* labeled alternative in {@link KickCParser#directive}.
* @param ctx the parse tree
*/
void enterDirectiveExport(KickCParser.DirectiveExportContext ctx);
/**
* Exit a parse tree produced by the {@code directiveExport}
* labeled alternative in {@link KickCParser#directive}.
* @param ctx the parse tree
*/
void exitDirectiveExport(KickCParser.DirectiveExportContext ctx);
/**
* Enter a parse tree produced by the {@code directiveInline}
* labeled alternative in {@link KickCParser#directive}.
@ -441,30 +465,6 @@ public interface KickCParserListener extends ParseTreeListener {
* @param ctx the parse tree
*/
void exitDirectiveInline(KickCParser.DirectiveInlineContext ctx);
/**
* Enter a parse tree produced by the {@code directiveVolatile}
* labeled alternative in {@link KickCParser#directive}.
* @param ctx the parse tree
*/
void enterDirectiveVolatile(KickCParser.DirectiveVolatileContext ctx);
/**
* Exit a parse tree produced by the {@code directiveVolatile}
* labeled alternative in {@link KickCParser#directive}.
* @param ctx the parse tree
*/
void exitDirectiveVolatile(KickCParser.DirectiveVolatileContext ctx);
/**
* Enter a parse tree produced by the {@code directiveNotVolatile}
* labeled alternative in {@link KickCParser#directive}.
* @param ctx the parse tree
*/
void enterDirectiveNotVolatile(KickCParser.DirectiveNotVolatileContext ctx);
/**
* Exit a parse tree produced by the {@code directiveNotVolatile}
* labeled alternative in {@link KickCParser#directive}.
* @param ctx the parse tree
*/
void exitDirectiveNotVolatile(KickCParser.DirectiveNotVolatileContext ctx);
/**
* Enter a parse tree produced by the {@code directiveInterrupt}
* labeled alternative in {@link KickCParser#directive}.

View File

@ -196,20 +196,6 @@ public interface KickCParserVisitor<T> extends ParseTreeVisitor<T> {
* @return the visitor result
*/
T visitDirectiveMaybeConst(KickCParser.DirectiveMaybeConstContext ctx);
/**
* Visit a parse tree produced by the {@code directiveExtern}
* labeled alternative in {@link KickCParser#directive}.
* @param ctx the parse tree
* @return the visitor result
*/
T visitDirectiveExtern(KickCParser.DirectiveExternContext ctx);
/**
* Visit a parse tree produced by the {@code directiveExport}
* labeled alternative in {@link KickCParser#directive}.
* @param ctx the parse tree
* @return the visitor result
*/
T visitDirectiveExport(KickCParser.DirectiveExportContext ctx);
/**
* Visit a parse tree produced by the {@code directiveAlign}
* labeled alternative in {@link KickCParser#directive}.
@ -245,6 +231,20 @@ public interface KickCParserVisitor<T> extends ParseTreeVisitor<T> {
* @return the visitor result
*/
T visitDirectiveMemoryAreaAddress(KickCParser.DirectiveMemoryAreaAddressContext ctx);
/**
* Visit a parse tree produced by the {@code directiveVolatile}
* labeled alternative in {@link KickCParser#directive}.
* @param ctx the parse tree
* @return the visitor result
*/
T visitDirectiveVolatile(KickCParser.DirectiveVolatileContext ctx);
/**
* Visit a parse tree produced by the {@code directiveNotVolatile}
* labeled alternative in {@link KickCParser#directive}.
* @param ctx the parse tree
* @return the visitor result
*/
T visitDirectiveNotVolatile(KickCParser.DirectiveNotVolatileContext ctx);
/**
* Visit a parse tree produced by the {@code directiveFormSsa}
* labeled alternative in {@link KickCParser#directive}.
@ -259,6 +259,20 @@ public interface KickCParserVisitor<T> extends ParseTreeVisitor<T> {
* @return the visitor result
*/
T visitDirectiveFormNotSsa(KickCParser.DirectiveFormNotSsaContext ctx);
/**
* Visit a parse tree produced by the {@code directiveExtern}
* labeled alternative in {@link KickCParser#directive}.
* @param ctx the parse tree
* @return the visitor result
*/
T visitDirectiveExtern(KickCParser.DirectiveExternContext ctx);
/**
* Visit a parse tree produced by the {@code directiveExport}
* labeled alternative in {@link KickCParser#directive}.
* @param ctx the parse tree
* @return the visitor result
*/
T visitDirectiveExport(KickCParser.DirectiveExportContext ctx);
/**
* Visit a parse tree produced by the {@code directiveInline}
* labeled alternative in {@link KickCParser#directive}.
@ -266,20 +280,6 @@ public interface KickCParserVisitor<T> extends ParseTreeVisitor<T> {
* @return the visitor result
*/
T visitDirectiveInline(KickCParser.DirectiveInlineContext ctx);
/**
* Visit a parse tree produced by the {@code directiveVolatile}
* labeled alternative in {@link KickCParser#directive}.
* @param ctx the parse tree
* @return the visitor result
*/
T visitDirectiveVolatile(KickCParser.DirectiveVolatileContext ctx);
/**
* Visit a parse tree produced by the {@code directiveNotVolatile}
* labeled alternative in {@link KickCParser#directive}.
* @param ctx the parse tree
* @return the visitor result
*/
T visitDirectiveNotVolatile(KickCParser.DirectiveNotVolatileContext ctx);
/**
* Visit a parse tree produced by the {@code directiveInterrupt}
* labeled alternative in {@link KickCParser#directive}.

View File

@ -1500,7 +1500,7 @@ public class Pass0GenerateStatementSequence extends KickCParserBaseVisitor<Objec
Scope parentScope = getCurrentScope();
while(parentScope instanceof StructDefinition) parentScope = parentScope.getScope();
for(ConstantVar member : enumDefinition.getAllConstants(false)) {
parentScope.add(new ConstantVar(member.getLocalName(), parentScope, SymbolType.BYTE, member.getValue(), currentDataSegment));
parentScope.add(new ConstantVar(member.getLocalName(), parentScope, SymbolType.BYTE, member.getConstantValue(), currentDataSegment));
}
return SymbolType.BYTE;
} catch(CompileError e) {
@ -1525,7 +1525,7 @@ public class Pass0GenerateStatementSequence extends KickCParserBaseVisitor<Objec
enumValue = new ConstantInteger(0L, SymbolType.BYTE);
} else {
ConstantVar prevEnumMember = values.get(values.size() - 1);
ConstantValue prevValue = prevEnumMember.getValue();
ConstantValue prevValue = prevEnumMember.getConstantValue();
if(prevValue instanceof ConstantInteger) {
enumValue = new ConstantInteger(((ConstantInteger) prevValue).getInteger() + 1, SymbolType.BYTE);
} else {

View File

@ -66,7 +66,7 @@ public class Pass2ArrayInStructInlining extends Pass2SsaOptimization {
if(constantValue.getType(getProgram().getScope()).equals(SymbolType.STRING)) {
if(constantValue instanceof ConstantRef) {
ConstantVar constantStringVar = getScope().getConstant((ConstantRef) constantValue);
inline.put((ConstantRef) constantValue, constantStringVar.getValue());
inline.put((ConstantRef) constantValue, constantStringVar.getConstantValue());
}
}
}

View File

@ -83,7 +83,7 @@ public class Pass2ConstantCallPointerIdentification extends Pass2SsaOptimization
private ProcedureRef findConstProcedure(RValue procedurePointer) {
if(procedurePointer instanceof ConstantRef) {
ConstantVar constant = getScope().getConstant((ConstantRef) procedurePointer);
return findConstProcedure(constant.getValue());
return findConstProcedure(constant.getConstantValue());
} else if(procedurePointer instanceof ConstantSymbolPointer) {
ConstantSymbolPointer pointer = (ConstantSymbolPointer) procedurePointer;
if(pointer.getToSymbol() instanceof ProcedureRef) {

View File

@ -94,7 +94,7 @@ public class Pass2ConstantIdentification extends Pass2SsaOptimization {
constScope.remove(variable);
constScope.add(constantVar);
constAliases.put(constRef, constantVar.getRef());
getLog().append("Constant " + constantVar.toString(getProgram()) + " = " + constantVar.getValue());
getLog().append("Constant " + constantVar.toString(getProgram()) + " = " + constantVar.getConstantValue());
}
// Remove assignments to constants in the code
removeAssignments(getGraph(), constants.keySet());

View File

@ -95,8 +95,8 @@ public class Pass2ConstantInlining extends Pass2SsaOptimization {
Collection<ConstantVar> allConstants = getProgram().getScope().getAllConstants(true);
for(ConstantVar constant : allConstants) {
if(constant.getRef().isIntermediate()) {
if(!(constant.getType().equals(SymbolType.STRING)) && !(constant.getValue() instanceof ConstantArray)) {
unnamed.put(constant.getRef(), constant.getValue());
if(!(constant.getType().equals(SymbolType.STRING)) && !(constant.getConstantValue() instanceof ConstantArray)) {
unnamed.put(constant.getRef(), constant.getConstantValue());
}
}
}
@ -113,14 +113,14 @@ public class Pass2ConstantInlining extends Pass2SsaOptimization {
ProgramScope programScope = getProgram().getScope();
Collection<ConstantVar> allConstants = programScope.getAllConstants(true);
for(ConstantVar constant : allConstants) {
ConstantValue constantValue = constant.getValue();
ConstantValue constantValue = constant.getConstantValue();
if(constantValue instanceof ConstantRef) {
if(((ConstantRef) constantValue).isIntermediate()) {
// The value is an intermediate constant - replace all uses of the intermediate with uses of the referrer instead.
aliases.put((ConstantRef) constant.getValue(), constant.getRef());
constant.setValue(programScope.getConstant((ConstantRef) constantValue).getValue());
aliases.put((ConstantRef) constant.getConstantValue(), constant.getRef());
constant.setConstantValue(programScope.getConstant((ConstantRef) constantValue).getConstantValue());
} else {
aliases.put(constant.getRef(), constant.getValue());
aliases.put(constant.getRef(), constant.getConstantValue());
}
}
}
@ -145,13 +145,13 @@ public class Pass2ConstantInlining extends Pass2SsaOptimization {
Collection<Symbol> scopeSymbols = constant.getScope().getAllSymbols();
for(Symbol symbol : scopeSymbols) {
if(symbol.getRef().isVersion() && symbol.getRef().getFullNameUnversioned().equals(baseName)) {
ConstantValue value = constant.getValue();
ConstantValue value = constant.getConstantValue();
if(symbol instanceof Variable) {
aliases.put(constant.getRef(), value);
getLog().append("Inlining constant with var siblings " + constant);
break;
} else if(symbol instanceof ConstantVar) {
ConstantValue otherValue = ((ConstantVar) symbol).getValue();
ConstantValue otherValue = ((ConstantVar) symbol).getConstantValue();
if(!otherValue.equals(value) && !(value instanceof ConstantString) && !(value instanceof ConstantArray) && !(otherValue instanceof ConstantRef)) {
aliases.put(constant.getRef(), value);
getLog().append("Inlining constant with different constant siblings " + constant);

View File

@ -32,7 +32,7 @@ public class Pass2ConstantStringConsolidation extends Pass2SsaOptimization {
// Build a map with all constant strings
Map<ConstantString, List<ConstantVar>> constantStringMap = new LinkedHashMap<>();
for(ConstantVar constVar : getScope().getAllConstants(true)) {
ConstantValue constVal = constVar.getValue();
ConstantValue constVal = constVar.getConstantValue();
if(constVal instanceof ConstantString) {
ConstantString constString = (ConstantString) constVal;
List<ConstantVar> constantVars = constantStringMap.computeIfAbsent(constString, k -> new ArrayList<>());
@ -97,7 +97,7 @@ public class Pass2ConstantStringConsolidation extends Pass2SsaOptimization {
// Modify all other constants to be references to the root constant
for(ConstantVar constantVar : constantVars) {
if(!constantVar.equals(rootConstant)) {
constantVar.setValue(new ConstantRef(rootConstant));
constantVar.setConstantValue(new ConstantRef(rootConstant));
modified = true;
}
}

View File

@ -35,7 +35,7 @@ public class Pass3AssertArrayLengths extends Pass2SsaAssertion {
}
Integer declaredSizeInt = ((ConstantInteger) declaredSizeVal).getInteger().intValue();
// A constant size was found - Check that a value with the same size is present
ConstantValue constantValue = constantVar.getValue();
ConstantValue constantValue = constantVar.getConstantValue();
if(constantValue == null) {
throw new CompileError("Error! Array with a size not initialized " + constantVar.toString(getProgram()));
} else if(constantValue instanceof ConstantArrayFilled) {

View File

@ -300,7 +300,7 @@ public class Pass4CodeGeneration {
}
private boolean hasData(ConstantVar constantVar) {
ConstantValue constantValue = constantVar.getValue();
ConstantValue constantValue = constantVar.getConstantValue();
if(constantValue instanceof ConstantArray) {
return true;
} else {
@ -400,9 +400,9 @@ public class Pass4CodeGeneration {
// Add any comments
generateComments(asm, constantVar.getComments());
// Ensure encoding is good
ensureEncoding(asm, constantVar.getValue());
ensureEncoding(asm, constantVar.getConstantValue());
// Find the constant value calculation
String asmConstant = AsmFormat.getAsmConstant(program, constantVar.getValue(), 99, scopeRef);
String asmConstant = AsmFormat.getAsmConstant(program, constantVar.getConstantValue(), 99, scopeRef);
if(constantVar.getType() instanceof SymbolTypePointer) {
// Must use a label for pointers
asm.addLabelDecl(AsmFormat.asmFix(asmName), asmConstant);
@ -482,7 +482,7 @@ public class Pass4CodeGeneration {
String alignment = AsmFormat.getAsmNumber(declaredAlignment);
asm.addDataAlignment(alignment);
}
ConstantValue constantValue = constantVar.getValue();
ConstantValue constantValue = constantVar.getConstantValue();
if(constantValue instanceof ConstantArrayList || constantValue instanceof ConstantArrayFilled || constantValue instanceof ConstantArrayKickAsm || constantValue instanceof ConstantString) {
AsmDataChunk asmDataChunk = new AsmDataChunk();
addChunkData(asmDataChunk, constantValue, constantVar.getType(), scopeRef);

View File

@ -116,7 +116,7 @@ public class Pass4RegistersFinalize extends Pass2Base {
}
}
for(ConstantVar constantVar : scope.getAllConstants(false)) {
Registers.Register allocation = new Registers.RegisterConstant(constantVar.getValue());
Registers.Register allocation = new Registers.RegisterConstant(constantVar.getConstantValue());
shortenAsmName(shortNames, constantVar, allocation);
}
}

View File

@ -80,9 +80,9 @@ public class PassNSizeOfSimplification extends Pass2SsaOptimization {
ConstantRef sizeOfConstantVar = OperatorSizeOf.getSizeOfConstantVar(getScope(), arrayType.getElementType());
programValue.set(new ConstantBinary((ConstantValue) arraySize, Operators.MULTIPLY, sizeOfConstantVar));
modified.set(true);
} else if(constant.getValue() instanceof ConstantArrayList) {
} else if(constant.getConstantValue() instanceof ConstantArrayList) {
getLog().append("Resolving array sizeof() " + unary.toString(getProgram()));
int size = ((ConstantArrayList) constant.getValue()).getElements().size();
int size = ((ConstantArrayList) constant.getConstantValue()).getElements().size();
ConstantRef sizeOfConstantVar = OperatorSizeOf.getSizeOfConstantVar(getScope(), arrayType.getElementType());
programValue.set(new ConstantBinary(new ConstantInteger((long) size), Operators.MULTIPLY, sizeOfConstantVar));
modified.set(true);
@ -90,7 +90,7 @@ public class PassNSizeOfSimplification extends Pass2SsaOptimization {
// Try to calculate the literal to check if it is a string
ConstantLiteral stringLiteral = null;
try {
stringLiteral = constant.getValue().calculateLiteral(getProgram().getScope());
stringLiteral = constant.getConstantValue().calculateLiteral(getProgram().getScope());
} catch(ConstantNotLiteral e) {
// Ignore
}