public override void ExitSum2(ssuplParser.Sum2Context context) { //sum : sum MINUS term #sum2 code.Put(context, code.Get(context.sum()), code.Get(context.term()), "pop rbx", //value from term "pop rax", //value from sum "sub rax,rbx", "push rax" ); }
public override void ExitSum2(ssuplParser.Sum2Context context) { //sum : sum MINUS term #sum2 if (type(context.sum()) != type(context.term())) { throw new Exception("Type mismatch"); } typeAttr.Put(context, type(context.sum())); switch (type(context.sum())) { case VarType.INT: code.Put(context, code.Get(context.sum()), code.Get(context.term()), "pop rbx", //value from term "pop rax", //value from sum "sub rax,rbx", "push rax" ); break; case VarType.DOUBLE: code.Put(context, code.Get(context.sum()), code.Get(context.term()), "movq xmm1, [rsp]", //pop value... "add rsp,8", //...from term "movq xmm0, [rsp]", //pop value... "add rsp,8", //...from sum "subsd xmm0,xmm1", //xmm0 <- xmm0-xmm1 "sub rsp,8", //do the push... "movq [rsp], xmm0" //...of the result ); break; case VarType.VEC4: code.Put(context, code.Get(context.sum()), code.Get(context.term()), "movq xmm4, [rsp]", //term.x "movq xmm0, [rsp+32]", //sum.x "subsd xmm0,xmm4", //result.x "movq xmm4, [rsp+8]", //term.y "movq xmm1, [rsp+40]", //sum.y "subsd xmm1,xmm4", //result.y "movq xmm4, [rsp+16]", //term.z "movq xmm2, [rsp+48]", //sum.z "subsd xmm2,xmm4", //result.z "movq xmm4, [rsp+24]", //term.w "movq xmm3, [rsp+56]", //sum.w "subsd xmm3,xmm4", //result.w "add rsp,32", //pop 64 bytes, push 32 "movq [rsp], xmm0", //result.x "movq [rsp+8], xmm1", //result.y "movq [rsp+16], xmm2", //result.z "movq [rsp+24], xmm3" //result.w ); break; } }
public override void ExitSum2(ssuplParser.Sum2Context context) { //sum : sum MINUS term #sum2 if (type(context.sum()) != type(context.term())) { throw new Exception("Type mismatch"); } typeAttr.Put(context, type(context.sum())); switch (type(context.sum())) { case VarType.INT: code.Put(context, code.Get(context.sum()), code.Get(context.term()), "pop rbx", //value from term "pop rax", //value from sum "sub rax,rbx", "push rax" ); break; case VarType.DOUBLE: code.Put(context, code.Get(context.sum()), code.Get(context.term()), "movq xmm1, [rsp]", //pop value... "add rsp,8", //...from term "movq xmm0, [rsp]", //pop value... "add rsp,8", //...from sum "subsd xmm0,xmm1", //xmm0 <- xmm0-xmm1 "sub rsp,8", //do the push... "movq [rsp], xmm0" //...of the result ); break; } }