Esempio n. 1
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);
        }