Exemplo n.º 1
0
        public override void ExitAndexp1(ssuplParser.Andexp1Context context)
        {
            //andexp  : andexp AND notexp
            if (type(context.andexp()) != VarType.INT)
            {
                throw new Exception("First operand to OR must be integer");
            }
            if (type(context.notexp()) != VarType.INT)
            {
                throw new Exception("Second operand to OR must be integer");
            }
            typeAttr.Put(context, VarType.INT);
            var firstWasTrue = label();
            var done         = label();

            code.Put(context,
                     code.Get(context.andexp()), //first term
                     "pop rax",                  //result of first term
                     "cmp rax,0",                //see if it's zero
                     $"jne {firstWasTrue}",      //if so, end
                     "push qword 0",
                     $"jmp {done}",              //skip second test
                     $"{firstWasTrue}:",         //start of second test
                     code.Get(context.notexp()), //second term
                     "pop rax",                  //result of second term
                     "cmp rax,0",                //see if it's zero
                     "setne al",                 //al gets to set to either 1 or 0
                     "movzx qword rax,al",       //clear all values but the 1 or 0
                     "push rax",                 //push result
                     $"{done}:"
                     );
        }
Exemplo n.º 2
0
        public override void ExitAndexp1(ssuplParser.Andexp1Context context)
        {
            //andexp  : andexp AND notexp
            var firstWasTrue = label();
            var done         = label();

            code.Put(context,
                     code.Get(context.andexp()), //first term
                     "pop rax",                  //result of first term
                     "cmp rax,0",                //see if it's zero
                     $"jne {firstWasTrue}",      //if so, end
                     "push qword 0",
                     $"jmp {done}",              //skip second test
                     $"{firstWasTrue}:",         //start of second test
                     code.Get(context.notexp()), //second term
                     "pop rax",                  //result of second term
                     "cmp rax,0",                //see if it's zero
                     "setne al",                 //al gets to set to either 1 or 0
                     "movzx qword rax,al",       //clear all values but the 1 or 0
                     "push rax",                 //push result
                     $"{done}:"
                     );
        }
 /// <summary>
 /// Exit a parse tree produced by the <c>andexp1</c>
 /// labeled alternative in <see cref="ssuplParser.andexp"/>.
 /// <para>The default implementation does nothing.</para>
 /// </summary>
 /// <param name="context">The parse tree.</param>
 public virtual void ExitAndexp1([NotNull] ssuplParser.Andexp1Context context)
 {
 }