|
|
@ -42,6 +42,8 @@ public class CodeGenImpl extends CodeGenBase
|
|
|
|
protected final Label initcharsLabel = new Label("initchars");
|
|
|
|
protected final Label initcharsLabel = new Label("initchars");
|
|
|
|
protected final Label allCharsLabel = new Label("allChars");
|
|
|
|
protected final Label allCharsLabel = new Label("allChars");
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** Variable to indicate if Strings are used in the program for optimization */
|
|
|
|
|
|
|
|
private boolean flag = false;
|
|
|
|
|
|
|
|
|
|
|
|
/** Operation on None. */
|
|
|
|
/** Operation on None. */
|
|
|
|
private final Label errorNone = new Label("error.None");
|
|
|
|
private final Label errorNone = new Label("error.None");
|
|
|
@ -454,6 +456,7 @@ public class CodeGenImpl extends CodeGenBase
|
|
|
|
@Override
|
|
|
|
@Override
|
|
|
|
public Register analyze(StringLiteral node)
|
|
|
|
public Register analyze(StringLiteral node)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
|
|
|
|
flag=true;
|
|
|
|
Label l = constants.getStrConstant(node.value);
|
|
|
|
Label l = constants.getStrConstant(node.value);
|
|
|
|
backend.emitLA(Register.A0, l, "Load string literal");
|
|
|
|
backend.emitLA(Register.A0, l, "Load string literal");
|
|
|
|
return Register.A0;
|
|
|
|
return Register.A0;
|
|
|
@ -498,6 +501,8 @@ public class CodeGenImpl extends CodeGenBase
|
|
|
|
|
|
|
|
|
|
|
|
private Object getVar(Identifier id)
|
|
|
|
private Object getVar(Identifier id)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
|
|
|
|
if(id.getInferredType().equals(Type.STR_TYPE))
|
|
|
|
|
|
|
|
flag=true;
|
|
|
|
SymbolInfo info = sym.get(id.name);
|
|
|
|
SymbolInfo info = sym.get(id.name);
|
|
|
|
if(info instanceof StackVarInfo)
|
|
|
|
if(info instanceof StackVarInfo)
|
|
|
|
return getStackVar((StackVarInfo)info);
|
|
|
|
return getStackVar((StackVarInfo)info);
|
|
|
@ -1145,9 +1150,13 @@ public class CodeGenImpl extends CodeGenBase
|
|
|
|
emitStdFunc("strneql");
|
|
|
|
emitStdFunc("strneql");
|
|
|
|
emitStdFunc("makeint");
|
|
|
|
emitStdFunc("makeint");
|
|
|
|
emitStdFunc("makebool");
|
|
|
|
emitStdFunc("makebool");
|
|
|
|
|
|
|
|
if(flag)
|
|
|
|
|
|
|
|
{
|
|
|
|
emitStdFunc("initchars");
|
|
|
|
emitStdFunc("initchars");
|
|
|
|
emitStdFunc("allChars");
|
|
|
|
emitStdFunc("allChars");
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
else
|
|
|
|
|
|
|
|
emitStdFunc("dummy");
|
|
|
|
emitErrorFunc(errorNone, "Operation on None");
|
|
|
|
emitErrorFunc(errorNone, "Operation on None");
|
|
|
|
emitErrorFunc(errorDiv, "Division by zero");
|
|
|
|
emitErrorFunc(errorDiv, "Division by zero");
|
|
|
|
emitErrorFunc(errorOob, "Index out of bounds");
|
|
|
|
emitErrorFunc(errorOob, "Index out of bounds");
|
|
|
|