UnaryExpr Analyze fixed

master
Apoorva Ranade 4 years ago
parent 748b42fc53
commit a822a4ab69

@ -358,12 +358,19 @@ public class CodeGenImpl extends CodeGenBase
@Override @Override
public Register analyze(UnaryExpr node) public Register analyze(UnaryExpr node)
{ {
node.operand.dispatch(this); if(node.operator.equals("-") && node.getInferredType().equals(Type.INT_TYPE))
if(node.operator.equals("-"))
{ {
node.operand.dispatch(this);
backend.emitLI(Register.T0, -1, "Set value of Register T0 to -1"); backend.emitLI(Register.T0, -1, "Set value of Register T0 to -1");
backend.emitMUL(Register.A0, Register.A0, Register.T0, "Multiply by -1"); backend.emitMUL(Register.A0, Register.A0, Register.T0, "Multiply by -1");
} }
else if(node.operator.equals("not") && node.getInferredType().equals(Type.BOOL_TYPE))
{
node.operand.dispatch(this);
backend.emitSEQZ(Register.T0, Register.A0, "Not operation on Register A0");
}
else
return null;
return Register.A0; return Register.A0;
} }

Loading…
Cancel
Save