public ARCompactRewriter(ARCompactArchitecture arch, EndianImageReader rdr, ProcessorState state, IStorageBinder binder, IRewriterHost host) { this.arch = arch; this.rdr = rdr; this.state = state; this.binder = binder; this.host = host; this.dasm = new ArcDisassembler(arch, rdr).GetEnumerator(); this.instr = null !; this.m = null !; }
public override ArcInstruction Decode(uint wInstr, ArcDisassembler dasm) { foreach (var m in mutators) { if (!m(wInstr, dasm)) { return(dasm.CreateInvalidInstruction()); } } var instr = new ArcInstruction { InstructionClass = iclass, Mnemonic = mnemonic, Operands = dasm.ops.ToArray() }; return(instr); }
public IEnumerator <RtlInstructionCluster> GetEnumerator() { while (dasm.MoveNext()) { this.instr = dasm.Current; this.iclass = instr.InstructionClass; var instrs = new List <RtlInstruction>(); m = new RtlEmitter(instrs); switch (instr.Mnemonic) { case Mnemonic.abs: case Mnemonic.abss: case Mnemonic.abssw: case Mnemonic.adds: case Mnemonic.asls: case Mnemonic.asrs: case Mnemonic.ex: case Mnemonic.jcc: case Mnemonic.jcs: case Mnemonic.jge: case Mnemonic.jgt: case Mnemonic.jhi: case Mnemonic.jle: case Mnemonic.jls: case Mnemonic.jlt: case Mnemonic.jmi: case Mnemonic.jne: case Mnemonic.jpl: case Mnemonic.jpnz: case Mnemonic.jvc: case Mnemonic.jvs: case Mnemonic.negs: case Mnemonic.negsw: case Mnemonic.norm: case Mnemonic.normw: case Mnemonic.rlc: case Mnemonic.rnd16: case Mnemonic.rrc: case Mnemonic.sat16: case Mnemonic.subs: case Mnemonic.swap: case Mnemonic.abs_s: case Mnemonic.not_s: case Mnemonic.unimp_s: default: EmitUnitTest(this.instr); break; case Mnemonic.Invalid: this.iclass = InstrClass.Invalid; m.Invalid(); break; case Mnemonic.adc: RewriteAluOp(Adc, ZNCV); break; case Mnemonic.add: case Mnemonic.add_s: RewriteAluOp(m.IAdd, ZNCV); break; case Mnemonic.add1: case Mnemonic.add1_s: RewriteAluOp(Add1, ZNCV); break; case Mnemonic.add2: case Mnemonic.add2_s: RewriteAluOp(Add2, ZNCV); break; case Mnemonic.add3: case Mnemonic.add3_s: RewriteAluOp(Add3, ZNCV); break; case Mnemonic.addsdw: RewriteAddSubsdw("__addsdw"); break; case Mnemonic.and: case Mnemonic.and_s: RewriteAluOp(m.And, ZN); break; case Mnemonic.asl: case Mnemonic.asl_s: RewriteShift(m.Shl, ZNCV); break; case Mnemonic.asr: case Mnemonic.asr_s: RewriteShift(m.Sar, ZNCV); break; case Mnemonic.b: case Mnemonic.b_s: RewriteB(ArcCondition.AL); break; case Mnemonic.bcc: case Mnemonic.bhs_s: RewriteB(ArcCondition.CC); break; case Mnemonic.bcs: case Mnemonic.blo_s: RewriteB(ArcCondition.CS); break; case Mnemonic.beq: case Mnemonic.beq_s: RewriteB(ArcCondition.EQ); break; case Mnemonic.bge: case Mnemonic.bge_s: RewriteB(ArcCondition.GE); break; case Mnemonic.bgt: case Mnemonic.bgt_s: RewriteB(ArcCondition.GT); break; case Mnemonic.bhi: case Mnemonic.bhi_s: RewriteB(ArcCondition.HI); break; case Mnemonic.ble: case Mnemonic.ble_s: RewriteB(ArcCondition.LE); break; case Mnemonic.bls: case Mnemonic.bls_s: RewriteB(ArcCondition.LS); break; case Mnemonic.blt: case Mnemonic.blt_s: RewriteB(ArcCondition.LT); break; case Mnemonic.bmi: RewriteB(ArcCondition.MI); break; case Mnemonic.bne: case Mnemonic.bne_s: RewriteB(ArcCondition.NE); break; case Mnemonic.bpl: RewriteB(ArcCondition.PL); break; case Mnemonic.bpnz: RewriteB(ArcCondition.PNZ); break; case Mnemonic.bvc: RewriteB(ArcCondition.VC); break; case Mnemonic.bvs: RewriteB(ArcCondition.VS); break; case Mnemonic.bsc: RewriteB(ArcCondition.SC); break; case Mnemonic.bss: RewriteB(ArcCondition.SS); break; case Mnemonic.bbit0: RewriteBbit(false); break; case Mnemonic.bbit1: RewriteBbit(true); break; case Mnemonic.bclr: case Mnemonic.bclr_s: RewriteAluOp(Bclr, ZN); break; case Mnemonic.bl: case Mnemonic.bl_s: RewriteBl(ArcCondition.AL); break; case Mnemonic.blal: RewriteBl(ArcCondition.AL); break; case Mnemonic.blcc: RewriteBl(ArcCondition.CC); break; case Mnemonic.blcs: RewriteBl(ArcCondition.CS); break; case Mnemonic.bleq: RewriteBl(ArcCondition.EQ); break; case Mnemonic.blge: RewriteBl(ArcCondition.GE); break; case Mnemonic.blgt: RewriteBl(ArcCondition.GT); break; case Mnemonic.blhi: RewriteBl(ArcCondition.HI); break; case Mnemonic.blle: RewriteBl(ArcCondition.LE); break; case Mnemonic.blls: RewriteBl(ArcCondition.LS); break; case Mnemonic.bllt: RewriteBl(ArcCondition.LT); break; case Mnemonic.blmi: RewriteBl(ArcCondition.MI); break; case Mnemonic.blne: RewriteBl(ArcCondition.NE); break; case Mnemonic.blpl: RewriteBl(ArcCondition.PL); break; case Mnemonic.blpnz: RewriteBl(ArcCondition.PNZ); break; case Mnemonic.blvc: RewriteBl(ArcCondition.VC); break; case Mnemonic.blvs: RewriteBl(ArcCondition.VS); break; case Mnemonic.breq: case Mnemonic.breq_s: RewriteBr(m.Eq); break; case Mnemonic.brge: RewriteBr(m.Ge); break; case Mnemonic.brhs: RewriteBr(m.Uge); break; case Mnemonic.brlo: RewriteBr(m.Ult); break; case Mnemonic.brlt: RewriteBr(m.Lt); break; case Mnemonic.brne: case Mnemonic.brne_s: RewriteBr(m.Ne); break; case Mnemonic.brk: case Mnemonic.brk_s: RewriteBrk(); break; case Mnemonic.bic: case Mnemonic.bic_s: RewriteAluOp(AndNot, ZN); break; case Mnemonic.bmsk: case Mnemonic.bmsk_s: RewriteAluOp(Bmsk, ZN); break; case Mnemonic.bset: case Mnemonic.bset_s: RewriteAluOp(Bset, ZN); break; case Mnemonic.btst: case Mnemonic.btst_s: RewriteCondInstr(Btst, ZN); break; case Mnemonic.bxor: RewriteAluOp(Bxor, ZN); break; case Mnemonic.cmp: case Mnemonic.cmp_s: RewriteCondInstr(m.ISub, ZNCV); break; case Mnemonic.divaw: RewriteDivaw(); break; case Mnemonic.extb: case Mnemonic.extb_s: RewriteExt(PrimitiveType.Byte, PrimitiveType.Word32); break; case Mnemonic.extw: case Mnemonic.extw_s: RewriteExt(PrimitiveType.Word16, PrimitiveType.Word32); break; case Mnemonic.flag: RewriteFlag(); break; case Mnemonic.j: case Mnemonic.j_s: RewriteJ(ArcCondition.AL); break; case Mnemonic.jeq: RewriteJ(ArcCondition.EQ); break; case Mnemonic.jl: case Mnemonic.jl_s: RewriteJl(); break; case Mnemonic.ld: case Mnemonic.ld_s: RewriteLoad(PrimitiveType.Word32); break; case Mnemonic.ldb: case Mnemonic.ldb_s: RewriteLoad(PrimitiveType.Byte); break; case Mnemonic.ldw: case Mnemonic.ldw_s: RewriteLoad(PrimitiveType.Word16); break; case Mnemonic.lp: RewriteLp(ArcCondition.AL); break; case Mnemonic.lpcc: RewriteLp(ArcCondition.CC); break; case Mnemonic.lpcs: RewriteLp(ArcCondition.CS); break; case Mnemonic.lpeq: RewriteLp(ArcCondition.EQ); break; case Mnemonic.lpge: RewriteLp(ArcCondition.GE); break; case Mnemonic.lpgt: RewriteLp(ArcCondition.GT); break; case Mnemonic.lphi: RewriteLp(ArcCondition.HI); break; case Mnemonic.lple: RewriteLp(ArcCondition.LE); break; case Mnemonic.lpls: RewriteLp(ArcCondition.LS); break; case Mnemonic.lplt: RewriteLp(ArcCondition.LT); break; case Mnemonic.lpmi: RewriteLp(ArcCondition.MI); break; case Mnemonic.lpne: RewriteLp(ArcCondition.NE); break; case Mnemonic.lppl: RewriteLp(ArcCondition.PL); break; case Mnemonic.lppnz: RewriteLp(ArcCondition.PNZ); break; case Mnemonic.lpvc: RewriteLp(ArcCondition.VC); break; case Mnemonic.lpvs: RewriteLp(ArcCondition.VS); break; case Mnemonic.lr: RewriteLr(); break; case Mnemonic.lsr: case Mnemonic.lsr_s: RewriteShift(m.Shr, ZNC); break; case Mnemonic.max: RewriteAluOp(Max, ZNCV); break; case Mnemonic.min: RewriteAluOp(Min, ZNCV); break; case Mnemonic.mov: case Mnemonic.mov_s: RewriteMov(); break; case Mnemonic.mul64: case Mnemonic.mul64_s: RewriteMul(m.SMul, PrimitiveType.Int64); break; case Mnemonic.mulu64: RewriteMul(m.UMul, PrimitiveType.UInt64); break; case Mnemonic.neg_s: RewriteAluOp(m.Neg, ZNCV); break; case Mnemonic.nop: m.Nop(); break; case Mnemonic.not: RewriteAluOp(m.Comp, ZN); break; case Mnemonic.or: case Mnemonic.or_s: RewriteAluOp(m.Or, ZN); break; case Mnemonic.pop_s: RewritePop(); break; case Mnemonic.push_s: RewritePush(); break; case Mnemonic.rcmp: RewriteCondInstr(Rsub, ZNCV); break; case Mnemonic.ror: RewriteShift(Ror, ZNC); break; case Mnemonic.rsub: RewriteAluOp(Rsub, ZNCV); break; case Mnemonic.sbc: RewriteAluOp(Sbc, ZNCV); break; case Mnemonic.sexb: case Mnemonic.sexb_s: RewriteExt(PrimitiveType.SByte, PrimitiveType.Int32); break; case Mnemonic.sexw: case Mnemonic.sexw_s: RewriteExt(PrimitiveType.Int16, PrimitiveType.Int32); break; case Mnemonic.sr: RewriteSr(); break; case Mnemonic.st: case Mnemonic.st_s: RewriteStore(PrimitiveType.Word32); break; case Mnemonic.stb: case Mnemonic.stb_s: RewriteStore(PrimitiveType.Byte); break; case Mnemonic.stw: case Mnemonic.stw_s: RewriteStore(PrimitiveType.Word16); break; case Mnemonic.sub: case Mnemonic.sub_s: RewriteAluOp(m.ISub, ZNCV); break; case Mnemonic.sub1: RewriteAluOp(Sub1, ZNCV); break; case Mnemonic.sub2: RewriteAluOp(Sub2, ZNCV); break; case Mnemonic.sub3: RewriteAluOp(Sub3, ZNCV); break; case Mnemonic.subsdw: RewriteAddSubsdw("__subsdw"); break; case Mnemonic.trap_s: case Mnemonic.trap0: RewriteTrap(); break; case Mnemonic.tst: case Mnemonic.tst_s: RewriteCondInstr(m.And, ZN); break; case Mnemonic.xor: case Mnemonic.xor_s: RewriteAluOp(m.Xor, ZN); break; } TryHandlingZeroOverheadLoop(); yield return(new RtlInstructionCluster(instr.Address, instr.Length, instrs.ToArray()) { Class = iclass }); } }