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}:" ); }
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}:" ); }