Exemplo n.º 1
0
        public override void ExitAssign2(ssuplParser.Assign2Context context)
        {
            // assign ``:`` ID DOT FIELD EQ expr
            //Console.WriteLine("Exitassign2");
            string vname = context.ID().GetText();

            if (!symtable.Contains(vname))
            {
                throw new Exception("Undeclared variable: " + vname);
            }
            if (type(context.expr()) != VarType.DOUBLE || symtable.Get(vname).type != VarType.VEC4)
            {
                throw new Exception("Variable type mismatch in assignment");
            }
            VarType vtype        = symtable.Get(vname).type;
            int     vsizeInQuads = SizeForType(vtype) / 8;

            ASM asmcode = new ASM();

            asmcode += code.Get(context.expr());
            asmcode += "pop rax";
            string lbl = symtable.Get(vname).location;

            switch (context.FIELD().GetText())
            {
            case ".x":
                asmcode += $"mov [{lbl}+{0}], rax";
                break;

            case ".y":
                asmcode += $"mov [{lbl}+{8}], rax";
                break;

            case ".z":
                asmcode += $"mov [{lbl}+{16}], rax";
                break;

            case ".w":
                asmcode += $"mov [{lbl}+{24}], rax";
                break;
            }
            code.Put(context, asmcode);
            typeAttr.Put(context, vtype);
        }
Exemplo n.º 2
0
 /// <summary>
 /// Exit a parse tree produced by the <c>assign2</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 ExitAssign2([NotNull] ssuplParser.Assign2Context context)
 {
 }