예제 #1
0
        public override void ExitFactor3(ssuplParser.Factor3Context context)
        {
            //factor -> ID
            string vname = context.ID().GetText();

            code.Put(context,
                     $"mov rax,[${symtable.Get(vname).location}]",
                     "push qword rax"
                     );
        }
예제 #2
0
        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);
        }
 /// <summary>
 /// Exit a parse tree produced by the <c>factor3</c>
 /// labeled alternative in <see cref="ssuplParser.factor"/>.
 /// <para>The default implementation does nothing.</para>
 /// </summary>
 /// <param name="context">The parse tree.</param>
 public virtual void ExitFactor3([NotNull] ssuplParser.Factor3Context context)
 {
 }