Esempio n. 1
0
 public Rl78Rewriter(Rl78Architecture 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 LookaheadEnumerator <Rl78Instruction>(new Rl78Disassembler(arch, rdr));
     this.instr  = null !;
     this.m      = null !;
 }
Esempio n. 2
0
        public IEnumerator <RtlInstructionCluster> GetEnumerator()
        {
            while (dasm.MoveNext())
            {
                this.instr = dasm.Current;
                var instrs = new List <RtlInstruction>();
                this.m      = new RtlEmitter(instrs);
                this.iclass = dasm.Current.InstructionClass;
                switch (instr.Mnemonic)
                {
                case Mnemonic.invalid:
                    m.Invalid(); break;

                case Mnemonic.brk:
                case Mnemonic.cmps:
                case Mnemonic.movs:
                case Mnemonic.retb:
                case Mnemonic.stop:
                default:
                    EmitUnitTest();
                    this.iclass = InstrClass.Invalid;
                    m.Invalid();
                    break;

                case Mnemonic.add: RewriteAdd(); break;

                case Mnemonic.addc: RewriteAddcSubc(m.IAdd); break;

                case Mnemonic.addw: RewriteAddw(); break;

                case Mnemonic.and: RewriteLogical(m.And); break;

                case Mnemonic.and1: RewriteLogical1(m.And); break;

                case Mnemonic.bc: RewriteBranch(ConditionCode.ULT, C()); break;

                case Mnemonic.bf: RewriteBf(); break;

                case Mnemonic.bh: RewriteBranch(ConditionCode.UGT, CZ()); break;

                case Mnemonic.bnc: RewriteBranch(ConditionCode.UGE, C()); break;

                case Mnemonic.bnh: RewriteBranch(ConditionCode.ULE, CZ()); break;

                case Mnemonic.bnz: RewriteBranch(ConditionCode.NE, Z()); break;

                case Mnemonic.br: RewriteBr(); break;

                case Mnemonic.bt: RewriteBt(); break;

                case Mnemonic.btclr: RewriteBtclr(); break;

                case Mnemonic.bz: RewriteBranch(ConditionCode.EQ, Z()); break;

                case Mnemonic.call: RewriteCall(); break;

                case Mnemonic.callt: RewriteCall(); break;

                case Mnemonic.clr1: RewriteClr1(); break;

                case Mnemonic.clrb: RewriteClr(PrimitiveType.Byte); break;

                case Mnemonic.clrw: RewriteClr(PrimitiveType.Word16); break;

                case Mnemonic.cmp: RewriteCmp(); break;

                case Mnemonic.cmp0: RewriteCmp0(); break;

                case Mnemonic.cmpw: RewriteCmp(); break;

                case Mnemonic.dec: RewriteIncDec((a, b) => m.ISubS(a, 1)); break;

                case Mnemonic.decw: RewriteIncwDecw((a, b) => m.ISubS(a, 1)); break;

                case Mnemonic.halt: RewriteHalt(); break;

                case Mnemonic.inc: RewriteIncDec((a, b) => m.IAddS(a, 1)); break;

                case Mnemonic.incw: RewriteIncwDecw((a, b) => m.IAddS(a, 1)); break;

                case Mnemonic.mov: RewriteMov(); break;

                case Mnemonic.mov1: RewriteMov1(); break;

                case Mnemonic.movw: RewriteMov(); break;

                case Mnemonic.mulu: RewriteMulu(); break;

                case Mnemonic.oneb: RewriteOne(PrimitiveType.Byte); break;

                case Mnemonic.onew: RewriteOne(PrimitiveType.Word16); break;

                case Mnemonic.or: RewriteLogical(m.Or); break;

                case Mnemonic.or1: RewriteLogical1(m.Or); break;

                case Mnemonic.nop: m.Nop(); break;

                case Mnemonic.not1: RewriteNot1(); break;

                case Mnemonic.pop: RewritePop(); break;

                case Mnemonic.push: RewritePush(); break;

                case Mnemonic.ret: RewriteRet(); break;

                case Mnemonic.reti: RewriteRet(); break;

                case Mnemonic.rol: RewriteRotate(PseudoProcedure.Rol); break;

                case Mnemonic.rolc: RewriteRotateC(PseudoProcedure.RolC); break;

                case Mnemonic.rolwc: RewriteRotateC(PseudoProcedure.RolC); break;

                case Mnemonic.ror: RewriteRotate(PseudoProcedure.Ror); break;

                case Mnemonic.rorc: RewriteRotate(PseudoProcedure.RorC); break;

                case Mnemonic.sar: RewriteShift(m.Sar); break;

                case Mnemonic.sarw: RewriteShiftw(m.Sar); break;

                case Mnemonic.sel: RewriteSel(); break;

                case Mnemonic.set1: RewriteSet1(); break;

                case Mnemonic.shl: RewriteShift(m.Shl); break;

                case Mnemonic.shlw: RewriteShiftw(m.Shl); break;

                case Mnemonic.shr: RewriteShift(m.Shr); break;

                case Mnemonic.shrw: RewriteShiftw(m.Shr); break;

                case Mnemonic.skc: RewriteSkip(ConditionCode.ULT, C()); break;

                case Mnemonic.skh: RewriteSkip(ConditionCode.UGT, CZ()); break;

                case Mnemonic.sknc: RewriteSkip(ConditionCode.UGE, C()); break;

                case Mnemonic.sknh: RewriteSkip(ConditionCode.ULE, CZ()); break;

                case Mnemonic.sknz: RewriteSkip(ConditionCode.NE, Z()); break;

                case Mnemonic.skz: RewriteSkip(ConditionCode.EQ, Z()); break;

                case Mnemonic.sub: RewriteSub(); break;

                case Mnemonic.subc: RewriteAddcSubc(m.ISub); break;

                case Mnemonic.subw: RewriteSubw(); break;

                case Mnemonic.xch: RewriteXch(); break;

                case Mnemonic.xchw: RewriteXch(); break;

                case Mnemonic.xor: RewriteLogical(m.Xor); break;

                case Mnemonic.xor1: RewriteLogical1(m.Xor); break;
                }
                yield return(m.MakeCluster(instr.Address, instr.Length, iclass));
            }
        }