1
0
mirror of https://gitlab.com/camelot/kickc.git synced 2024-09-29 03:56:15 +00:00

Removed const/volatile from Variable. #121

This commit is contained in:
jespergravgaard 2021-04-30 16:21:38 +02:00
parent 38d62b5759
commit 8fd8bb1832
11 changed files with 28 additions and 100 deletions

View File

@ -59,13 +59,6 @@ public class VariableBuilder {
SymbolType typeQualified = type.getQualified(this.isVolatile(), this.isNoModify());
Variable variable = new Variable(varName, getKind(), typeQualified, scope, getMemoryArea(), dataSegment, null);
// Todo: #121 remove!
variable.setNoModify(this.isNoModify());
variable.setVolatile(this.isVolatile());
variable.setToNoModify(this.isToNoModify());
variable.setToVolatile(this.isToVolatile());
variable.setExport(this.isExport());
variable.setPermanent(this.isPermanent());
variable.setOptimize(this.isOptimize());

View File

@ -59,21 +59,9 @@ public class Variable implements Symbol {
/** The type of the variable. VAR means the type is unknown, and has not been inferred yet. [ALL] */
private SymbolType type;
/** Specifies that the variable is not allowed to be modified (const keyword) */
private boolean noModify;
/** Specifies that the variable is a local permanent variable (local variable static keyword) */
private boolean permanent;
/** Specifies that the variable must always live in memory to be available for any multi-threaded accees (eg. in interrupts). (volatile keyword) [Only Variables] */
private boolean isVolatile;
/** Specifies that the variable points to a volatile. (volatile* keyword) */
private boolean isToVolatile;
/** Specifies that the variable points to a a nomodify. (const* keyword) */
private boolean isToNoModify;
/** Specifies that the variable must always be added to the output ASM even if it is never used anywhere. (export keyword) */
private boolean export;
@ -193,13 +181,6 @@ public class Variable implements Symbol {
version.setMemoryAlignment(phiMaster.getMemoryAlignment());
version.setMemoryAddress(phiMaster.getMemoryAddress());
version.setOptimize(phiMaster.isOptimize());
// TODO: #121 remove
version.setVolatile(phiMaster.isVolatile());
version.setNoModify(phiMaster.isNoModify());
version.setToNoModify(phiMaster.isToNoModify());
version.setToVolatile(phiMaster.isToVolatile());
version.setRegister(phiMaster.getRegister());
version.setPermanent(phiMaster.isPermanent());
version.setExport(phiMaster.isExport());
@ -243,12 +224,6 @@ public class Variable implements Symbol {
constVar.setMemoryAddress(variable.getMemoryAddress());
constVar.setOptimize(variable.isOptimize());
constVar.setRegister(variable.getRegister());
// Todo: #121 remove
constVar.setVolatile(variable.isVolatile());
constVar.setNoModify(variable.isNoModify());
constVar.setToNoModify(variable.isToNoModify());
constVar.setToVolatile(variable.isToVolatile());
constVar.setPermanent(variable.isPermanent());
constVar.setExport(variable.isExport());
constVar.setComments(variable.getComments());
@ -268,13 +243,6 @@ public class Variable implements Symbol {
copy.setMemoryAddress(original.getMemoryAddress());
copy.setOptimize(original.isOptimize());
copy.setPermanent(original.isPermanent());
// Todo: #121 remove
copy.setVolatile(original.isVolatile());
copy.setNoModify(original.isNoModify());
copy.setToNoModify(original.isToNoModify());
copy.setToVolatile(original.isToVolatile());
copy.setExport(original.isExport());
copy.setRegister(original.getRegister());
copy.setComments(original.getComments());
@ -296,24 +264,17 @@ public class Variable implements Symbol {
if(isParameter && memberDefinition.isArray()) {
// Array struct members are converted to pointers when unwound (use same kind as the struct variable)
SymbolTypePointer arrayType = (SymbolTypePointer) memberDefinition.getType();
SymbolType typeQualified = new SymbolTypePointer(arrayType.getElementType()).getQualified(structVar.isVolatile, structVar.isNoModify());
SymbolType typeQualified = new SymbolTypePointer(arrayType.getElementType()).getQualified(structVar.isVolatile(), structVar.isNoModify());
memberVariable = new Variable(name, structVar.getKind(), typeQualified, structVar.getScope(), memoryArea, structVar.getDataSegment(), null);
} else if(memberDefinition.isKindConstant()) {
// Constant members are unwound as constants
SymbolType typeQualified = memberDefinition.getType().getQualified(structVar.isVolatile, structVar.isNoModify());
SymbolType typeQualified = memberDefinition.getType().getQualified(structVar.isVolatile(), structVar.isNoModify());
memberVariable = new Variable(name, Kind.CONSTANT, typeQualified, structVar.getScope(), memoryArea, structVar.getDataSegment(), memberDefinition.getInitValue());
} else {
// For others the kind is preserved from the member definition
SymbolType typeQualified = memberDefinition.getType().getQualified(structVar.isVolatile, structVar.isNoModify());
SymbolType typeQualified = memberDefinition.getType().getQualified(structVar.isVolatile(), structVar.isNoModify());
memberVariable = new Variable(name, structVar.getKind(),typeQualified, structVar.getScope(), memoryArea, structVar.getDataSegment(), memberDefinition.getInitValue());
}
// Todo: #121 fix struct member qualifiers - and remove!
memberVariable.setVolatile(structVar.isVolatile());
memberVariable.setNoModify(structVar.isNoModify());
memberVariable.setToNoModify(structVar.isToNoModify());
memberVariable.setToVolatile(structVar.isToVolatile());
memberVariable.setExport(structVar.isExport());
memberVariable.setPermanent(structVar.isPermanent());
return memberVariable;
@ -503,35 +464,19 @@ public class Variable implements Symbol {
}
public boolean isNoModify() {
return noModify;
}
public void setNoModify(boolean noModify) {
this.noModify = noModify;
return type.isNomodify();
}
public boolean isVolatile() {
return isVolatile;
}
public void setVolatile(boolean aVolatile) {
this.isVolatile = aVolatile;
return type.isVolatile();
}
public boolean isToNoModify() {
return isToNoModify;
}
public void setToNoModify(boolean toNoModify) {
isToNoModify = toNoModify;
return type instanceof SymbolTypePointer && ((SymbolTypePointer) type).getElementType().isNomodify();
}
public boolean isToVolatile() {
return isToVolatile;
}
public void setToVolatile(boolean toVolatile) {
isToVolatile = toVolatile;
return type instanceof SymbolTypePointer && ((SymbolTypePointer) type).getElementType().isVolatile();
}
public boolean isPermanent() {

View File

@ -63,16 +63,12 @@ public class Pass1AddressOfHandling extends Pass2SsaOptimization {
variable.setKind(Variable.Kind.LOAD_STORE);
SymbolType typeQualified = variable.getType().getQualified(true, variable.getType().isNomodify());
variable.setType(typeQualified);
// TODO: #121 remove
variable.setVolatile(true);
getLog().append("Setting struct to load/store in variable affected by address-of " + stmtStr);
//getLog().append("Setting struct to load/store in variable affected by address-of: " + variable.toString() + " in " + stmtStr);
} else {
variable.setKind(Variable.Kind.LOAD_STORE);
SymbolType typeQualified = variable.getType().getQualified(true, variable.getType().isNomodify());
variable.setType(typeQualified);
// TODO: #121 remove
variable.setVolatile(true);
getLog().append("Setting inferred volatile on symbol affected by address-of " + stmtStr);
//getLog().append("Setting inferred volatile on symbol affected by address-of: " + variable.toString() + " in " + stmtStr);
}

View File

@ -46,8 +46,6 @@ public class Pass1AsmUsesHandling extends Pass2SsaOptimization {
variable.setKind(Variable.Kind.LOAD_STORE);
SymbolType typeQualified = variable.getType().getQualified(true, variable.getType().isNomodify());
variable.setType(typeQualified);
// TODO: #121 Remove
variable.setVolatile(true);
getLog().append("Setting inferred volatile on symbol affected by address-of: " + variable.toString() + " in " + stmtStr);
}
}

View File

@ -41,10 +41,6 @@ public class Pass2DeInlineWordDerefIdx extends Pass2SsaOptimization {
programValue.set(new PointerDereferenceSimple(tmpVar.getRef()));
SymbolType pointerType = SymbolTypeInference.inferType(getScope(), new AssignmentRValue(tmpVarAssignment));
tmpVar.setType(pointerType);
if(((SymbolTypePointer)pointerType).getElementType().isNomodify())
tmpVar.setToNoModify(true);
if(((SymbolTypePointer)pointerType).getElementType().isVolatile())
tmpVar.setToVolatile(true);
optimized.set(true);
}
}

View File

@ -1254,13 +1254,13 @@ byte main::initNES1_i#1
byte main::initNES1_i#2
number~ main::initNES1_waitForVBlank1_$0
bool~ main::initNES1_waitForVBlank1_$1
byte*~ main::initNES1_waitForVBlank1_$2
byte*~ main::initNES1_waitForVBlank1_$3
to_volatile byte*~ main::initNES1_waitForVBlank1_$2
to_volatile byte*~ main::initNES1_waitForVBlank1_$3
bool~ main::initNES1_waitForVBlank1_$4
number~ main::initNES1_waitForVBlank2_$0
bool~ main::initNES1_waitForVBlank2_$1
byte*~ main::initNES1_waitForVBlank2_$2
byte*~ main::initNES1_waitForVBlank2_$3
to_volatile byte*~ main::initNES1_waitForVBlank2_$2
to_volatile byte*~ main::initNES1_waitForVBlank2_$3
bool~ main::initNES1_waitForVBlank2_$4
byte main::screensizex1_return
byte main::screensizex1_return#0

View File

@ -702,13 +702,13 @@ byte main::initNES1_i#1
byte main::initNES1_i#2
number~ main::initNES1_waitForVBlank1_$0
bool~ main::initNES1_waitForVBlank1_$1
byte*~ main::initNES1_waitForVBlank1_$2
byte*~ main::initNES1_waitForVBlank1_$3
to_volatile byte*~ main::initNES1_waitForVBlank1_$2
to_volatile byte*~ main::initNES1_waitForVBlank1_$3
bool~ main::initNES1_waitForVBlank1_$4
number~ main::initNES1_waitForVBlank2_$0
bool~ main::initNES1_waitForVBlank2_$1
byte*~ main::initNES1_waitForVBlank2_$2
byte*~ main::initNES1_waitForVBlank2_$3
to_volatile byte*~ main::initNES1_waitForVBlank2_$2
to_volatile byte*~ main::initNES1_waitForVBlank2_$3
bool~ main::initNES1_waitForVBlank2_$4
byte main::x
byte main::x#0

View File

@ -537,13 +537,13 @@ byte main::initNES1_i#1
byte main::initNES1_i#2
number~ main::initNES1_waitForVBlank1_$0
bool~ main::initNES1_waitForVBlank1_$1
byte*~ main::initNES1_waitForVBlank1_$2
byte*~ main::initNES1_waitForVBlank1_$3
to_volatile byte*~ main::initNES1_waitForVBlank1_$2
to_volatile byte*~ main::initNES1_waitForVBlank1_$3
bool~ main::initNES1_waitForVBlank1_$4
number~ main::initNES1_waitForVBlank2_$0
bool~ main::initNES1_waitForVBlank2_$1
byte*~ main::initNES1_waitForVBlank2_$2
byte*~ main::initNES1_waitForVBlank2_$3
to_volatile byte*~ main::initNES1_waitForVBlank2_$2
to_volatile byte*~ main::initNES1_waitForVBlank2_$3
bool~ main::initNES1_waitForVBlank2_$4
byte main::s
byte main::s#0

View File

@ -1803,8 +1803,8 @@ word* bsearch16u::return#3
word* bsearch16u::return#4
word* bsearch16u::return#5
void doplasma(byte* doplasma::screen)
byte*~ doplasma::$0
byte*~ doplasma::$1
to_nomodify byte*~ doplasma::$0
to_nomodify byte*~ doplasma::$1
byte~ doplasma::$2
bool~ doplasma::$3
bool~ doplasma::$4

View File

@ -59,12 +59,12 @@ __start::@return: scope:[__start] from __start::@2
SYMBOL TABLE SSA
void __start()
void incscreen(word incscreen::ptr)
byte*~ incscreen::$0
byte*~ incscreen::$10
byte*~ incscreen::$11
byte*~ incscreen::$20
byte*~ incscreen::$21
byte*~ incscreen::$9
to_nomodify byte*~ incscreen::$0
to_nomodify byte*~ incscreen::$10
to_nomodify byte*~ incscreen::$11
to_nomodify byte*~ incscreen::$20
to_nomodify byte*~ incscreen::$21
to_nomodify byte*~ incscreen::$9
word incscreen::ptr
word incscreen::ptr#0
word incscreen::ptr#1

View File

@ -69,7 +69,7 @@ byte~ main::$0
byte~ main::$1
byte*~ main::$10
bool~ main::$11
struct Setting*~ main::$2
to_nomodify struct Setting*~ main::$2
bool~ main::$3
bool~ main::$4
bool~ main::$5