public override void ExitFactor3(ssuplParser.Factor3Context context) { //factor -> ID string vname = context.ID().GetText(); if (!symtable.Contains(vname)) { throw new Exception("Undeclared variable: " + vname); } string lbl = symtable.Get(vname).location; VarType vtype = symtable.Get(vname).type; int vsizeInQuads = SizeForType(vtype) / 8; ASM asmcode = new ASM(); for (int i = vsizeInQuads - 1; i >= 0; i--) { asmcode += $"mov rax,[{lbl}+{i * 8}]"; asmcode += "push qword rax"; } code.Put(context, asmcode); typeAttr.Put(context, symtable.Get(vname).type); }
public override void ExitAssign(ssuplParser.AssignContext context) { // assign : ID EQ expr string vname = context.ID().GetText(); if (!symtable.Contains(vname)) { throw new Exception("Undeclared variable: " + vname); } code.Put(context, code.Get(context.expr()), "pop rax", $"mov [${symtable.Get(vname).location}],rax" ); }
public override void ExitAssign(ssuplParser.AssignContext context) { // assign : ID EQ expr string vname = context.ID().GetText(); if (symtable.Get(vname).type != type(context.expr()))//invalid input check { throw new Exception("Type mismatch"); } if (!symtable.Contains(vname)) { throw new Exception("Undeclared variable: " + vname); } code.Put(context, code.Get(context.expr()), "pop rax", $"mov [${symtable.Get(vname).location}],rax" //, //"push rax" ); }