private int GenJmp(CodeGenScope scope, OpCode op, int pc) { int pos; scope.lastpc = scope.pc; scope.PushOP(new Instr(op, pc)); pos = scope.pc; return(pos); }
private int GenJmp2(CodeGenScope scope, OpCode op, int a, int pc, int val) { int pos; if (val != NOVAL) { Instr instr = scope.Last; if (instr.insn == OpCode.Move && instr.a == a) { scope.pc = scope.lastpc; a = instr.b; } } scope.lastpc = scope.pc; scope.PushOP(new Instr(op, a, pc)); pos = scope.pc; return(pos); }
private void GenMove(CodeGenScope s, int dst, int src, bool nopeep) { if (no_peephole(s)) { goto normal; } else { Instr data = s.Last; switch (data.insn) { case OpCode.Move: if (dst == src) { return; /* remove useless MOVE */ } if (data.b == dst && data.a == src) /* skip swapping MOVE */ { return; } goto normal; case OpCode.LoadNIL: case OpCode.LoadSelf: if (nopeep || data.a != src /*|| data.a < s->nlocals*/) { goto normal; } s.pc = s.lastpc; GenOp_1(s, data.insn, dst); break; case OpCode.LoadI: case OpCode.GetGV: case OpCode.GetIV: case OpCode.GetCV: case OpCode.GetConst: case OpCode.String: case OpCode.Lambda: case OpCode.Block: case OpCode.Method: if (nopeep || data.a != src /*|| data.a < s.nlocals*/) { goto normal; } s.pc = s.lastpc; GenOp_2(s, data.insn, dst, data.b); break; default: goto normal; } } return; normal: s.PushOP(new Instr(OpCode.Move, dst, src)); // TODO: on_eval return; }
private void GenOp_3(CodeGenScope s, OpCode op, int a, int b, int c) { s.PushOP(new Instr(op, a, b, c)); }
private void GenOp_2(CodeGenScope s, OpCode op, int a, int b) { s.PushOP(new Instr(op, a, b)); }
private void GenOp_1(CodeGenScope s, OpCode op, int a) { s.PushOP(new Instr(op, a)); }
private void GenOp_0(CodeGenScope s, OpCode op) { s.PushOP(new Instr(op)); }