public override void ExitAssign1(ssuplParser.Assign1Context context) { // assign ``:`` ID EQ expr string vname = context.ID().GetText(); if (!symtable.Contains(vname)) { throw new Exception("Undeclared variable: " + vname); } if (type(context.expr()) != symtable.Get(vname).type) { throw new Exception("Variable type mismatch in assignment"); } VarType vtype = symtable.Get(vname).type; int vsizeInQuads = SizeForType(vtype) / 8; string lbl = symtable.Get(vname).location; ASM asmcode = new ASM(); asmcode += code.Get(context.expr()); for (int i = 0; i < vsizeInQuads; i++) { asmcode += "pop rax"; asmcode += $"mov [{lbl}+{i * 8}],rax"; } code.Put(context, asmcode); typeAttr.Put(context, vtype); }
/// <summary> /// Exit a parse tree produced by the <c>assign1</c> /// labeled alternative in <see cref="ssuplParser.assign"/>. /// <para>The default implementation does nothing.</para> /// </summary> /// <param name="context">The parse tree.</param> public virtual void ExitAssign1([NotNull] ssuplParser.Assign1Context context) { }