Verified Commit 0685fda6 authored by Recolic Keghart's avatar Recolic Keghart 🎱

fix id_global and negate

parent afecd941
Pipeline #297 passed with stages
in 23 minutes and 35 seconds
......@@ -6,6 +6,7 @@ import java.util.*;
import chocopy.common.analysis.SymbolTable;
import chocopy.common.analysis.AbstractNodeAnalyzer;
import chocopy.common.analysis.types.SymbolType;
import chocopy.common.analysis.types.ValueType;
import chocopy.common.astnodes.*;
import chocopy.common.codegen.*;
......@@ -602,25 +603,19 @@ public class CodeGenImpl extends CodeGenBase {
@Override
public RiscVBackend.Register analyze(UnaryExpr node) {
RiscVBackend.Register operandReg = node.operand.dispatch(this);
RiscVBackend.Register operand = node.operand.dispatch(this);
RiscVBackend.Register operandReg = regMgr.borrowOnePersist();
backend.emitMV(operandReg, operand, "save operand to persist reg");
regMgr.returnOne(operand); // allocPrototype will destroy it!
switch (node.operator) {
case "-":
RiscVBackend.Register savedOpAddr = regMgr.borrowOneTmp();
RiscVBackend.Register savedResult = regMgr.borrowOnePersist();
backend.emitMV(savedOpAddr, operandReg, "Save operand addr in register");
// TODO FIXME NOOOOO! YOU"RE DOINT THINGS WRONGLY. I'll complete the merge and fix it later.
if (node.operand instanceof IntegerLiteral) {
backend.emitLW(operandReg, operandReg, 3 * backend.getWordSize(), "Load operand value");
} else if (node.operand instanceof Identifier) {
backend.emitLW(operandReg, operandReg, 0, "Load operand value");
}
backend.emitSUB(savedResult, ZERO, operandReg, "Unary Operator-::INT save in same operand reg");
RiscVBackend.Register heapObject = allocPrototype(SymbolType.INT_TYPE, savedResult);
regMgr.returnOne(operandReg);
regMgr.returnOne(savedOpAddr);
regMgr.returnOne(savedResult);
backend.emitLW(operandReg, operandReg, 3 * backend.getWordSize(), "Load operand value");
backend.emitSUB(operandReg, ZERO, operandReg, "Unary Operator-::INT save in same operand reg");
RiscVBackend.Register heapObject = allocPrototype(SymbolType.INT_TYPE, operandReg);
regMgr.returnOne(operandReg);
return heapObject;
}
return null;
}
......@@ -630,9 +625,12 @@ public class CodeGenImpl extends CodeGenBase {
SymbolInfo id = sym.get(node.name);
if (id instanceof GlobalVarInfo) {
GlobalVarInfo globalVarInfo = (GlobalVarInfo) id;
RiscVBackend.Register tmpReg = regMgr.borrowOneTmp();
backend.emitLA(tmpReg, globalVarInfo.getLabel(), "Load address of the global var.");
return tmpReg; // FIXME: The global var contains a bare int rather than a INT OBJECT>
RiscVBackend.Register tmpReg = regMgr.borrowOnePersist();
backend.emitLW(tmpReg, globalVarInfo.getLabel(), "Load address of the global var.");
// It at least works for int.
RiscVBackend.Register heapObject = allocPrototype(globalVarInfo.getVarType(), tmpReg);
regMgr.returnOne(tmpReg);
return heapObject;
}
// FIXME: not implemented
return null;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment