public List <Instruction> CodeGen(int truejump, int falsejump) { var b = new List <Instruction>(); var f1 = S1.AsDirectField() ?? (S1.IsConstant() ? FieldSRef.Imm1() : null); if (f1 == null) { f1 = FieldSRef.ScratchInt(); b.AddRange(S1.FetchToField(f1)); } var f2 = S2.AsDirectField() ?? (S2.IsConstant() ? FieldSRef.Imm2() : null); if (f2 == null) { f2 = FieldSRef.ScratchInt(); b.AddRange(S2.FetchToField(f2)); } b.Add(new Instruction { opcode = Opcode.Branch, op1 = f1, imm1 = S1.IsConstant() ? new IntSExpr(S1.Evaluate()) : null, op2 = f2, imm2 = S2.IsConstant() ? new IntSExpr(S2.Evaluate()) : null, rjmpeq = this.Op.HasFlag(CompSpec.Equal) ? truejump : falsejump, rjmplt = this.Op.HasFlag(CompSpec.Less) ? truejump : falsejump, rjmpgt = this.Op.HasFlag(CompSpec.Greater) ? truejump : falsejump, }); return(b); }
public List <Instruction> CodeGen() { var code = new List <Instruction>(); if (source.IsConstant()) { code.AddRange(target.PutFromInt(source.Evaluate())); } else { var src = source.AsDirectField(); if (src == null) { var tgt = target.AsDirectField(); if (tgt == null) { var scratch = FieldSRef.ScratchInt(); code.AddRange(source.FetchToField(scratch)); code.AddRange(target.PutFromField(scratch)); } else { code.AddRange(source.FetchToField(tgt)); } } else { code.AddRange(target.PutFromField(src)); } } return(code); }
public List <Instruction> FetchToReg(RegVRef dest) { Symbol varsym = new Symbol(); if (Program.CurrentFunction != null) { varsym = Program.CurrentFunction.locals.FirstOrDefault(sym => sym.name == this.arrname); } if (varsym.name == null) { varsym = Program.CurrentProgram.Symbols.FirstOrDefault(sym => sym.name == this.arrname); } if (offset.IsConstant()) { return(new MemVRef(new AddrSExpr(arrname, offset.Evaluate()), varsym.datatype).FetchToReg(dest)); } else { return(new MemVRef(new ArithSExpr(new AddrSExpr(arrname), ArithSpec.Add, offset), varsym.datatype).FetchToReg(dest)); } }