示例#1
0
 public SuperHRewriter(SuperHArchitecture arch, EndianImageReader rdr, SuperHState state, IStorageBinder binder, IRewriterHost host)
 {
     this.arch   = arch;
     this.rdr    = rdr;
     this.state  = state;
     this.binder = binder;
     this.host   = host;
     this.dasm   = new SuperHDisassembler(arch, rdr).GetEnumerator();
     this.instr  = null !;
     this.m      = null !;
 }
示例#2
0
            internal SuperHInstruction MakeInstruction()
            {
                var instr = new SuperHInstruction
                {
                    Opcode           = this.opcode,
                    InstructionClass = iclass,
                    Operands         = ops.ToArray()
                };

                return(instr);
            }
示例#3
0
            internal SuperHInstruction MakeInstruction()
            {
                var instr = new SuperHInstruction
                {
                    Opcode = this.opcode,
                };

                if (ops.Count > 0)
                {
                    instr.op1 = ops[0];
                    if (ops.Count > 1)
                    {
                        instr.op2 = ops[1];
                        if (ops.Count > 2)
                        {
                            instr.op3 = ops[2];
                        }
                    }
                }
                return(instr);
            }
示例#4
0
        public IEnumerator <RtlInstructionCluster> GetEnumerator()
        {
            while (dasm.MoveNext())
            {
                this.instr  = dasm.Current;
                this.iclass = InstrClass.Linear;
                var instrs = new List <RtlInstruction>();
                this.m = new RtlEmitter(instrs);
                switch (instr.Mnemonic)
                {
                default:
                    host.Error(
                        dasm.Current.Address,
                        string.Format(
                            "SuperH instruction {0} not supported yet.",
                            dasm.Current.Mnemonic));
                    EmitUnitTest();
                    goto case Mnemonic.invalid;

                case Mnemonic.invalid:
                    Invalid();
                    break;

                case Mnemonic.add: RewriteBinOp(m.IAdd, n => (sbyte)n); break;

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

                case Mnemonic.addv: RewriteAddv(m.IAdd); break;

                case Mnemonic.and: RewriteBinOp(m.And, n => (byte)n); break;

                case Mnemonic.and_b: RewriteBinOp(m.And, n => (byte)n); break;

                case Mnemonic.bf: RewriteBranch(false, false); break;

                case Mnemonic.bf_s: RewriteBranch(false, true); break;

                case Mnemonic.bra: RewriteGoto(); break;

                case Mnemonic.braf: RewriteBraf(); break;

                case Mnemonic.brk: RewriteBrk(); break;

                case Mnemonic.bsr: RewriteBsr(); break;

                case Mnemonic.bsrf: RewriteBsrf(); break;

                case Mnemonic.bt: RewriteBranch(true, false); break;

                case Mnemonic.bt_s: RewriteBranch(true, true); break;

                case Mnemonic.clrmac: RewriteClr(Registers.mac); break;

                case Mnemonic.clrs: RewriteClrtSet(Registers.S, Constant.False()); break;

                case Mnemonic.clrt: RewriteClrtSet(Registers.T, Constant.False()); break;

                case Mnemonic.cmp_eq: RewriteCmp(m.Eq); break;

                case Mnemonic.cmp_ge: RewriteCmp(m.Ge); break;

                case Mnemonic.cmp_gt: RewriteCmp(m.Gt); break;

                case Mnemonic.cmp_hs: RewriteCmp(m.Uge); break;

                case Mnemonic.cmp_hi: RewriteCmp(m.Ugt); break;

                case Mnemonic.cmp_pl: RewriteCmp0(m.Gt0); break;

                case Mnemonic.cmp_pz: RewriteCmp0(m.Ge0); break;

                case Mnemonic.cmp_str: RewriteCmpStr(); break;

                case Mnemonic.div0s: RewriteDiv0s(); break;

                case Mnemonic.div0u: RewriteDiv0u(); break;

                case Mnemonic.div1: RewriteDiv1(); break;

                case Mnemonic.dmuls_l: RewriteDmul(m.SMul); break;

                case Mnemonic.dmulu_l: RewriteDmul(m.UMul); break;

                case Mnemonic.dt: RewriteDt(); break;

                case Mnemonic.exts_b: RewriteExt(PrimitiveType.SByte); break;

                case Mnemonic.exts_w: RewriteExt(PrimitiveType.Int16); break;

                case Mnemonic.extu_b: RewriteExt(PrimitiveType.Byte); break;

                case Mnemonic.extu_w: RewriteExt(PrimitiveType.UInt16); break;

                case Mnemonic.fabs: RewriteFabs(); break;

                case Mnemonic.fadd: RewriteBinOp(m.FAdd, null); break;

                case Mnemonic.fcmp_eq: RewriteCmp(m.FEq); break;

                case Mnemonic.fcmp_gt: RewriteCmp(m.FGt); break;

                case Mnemonic.fcnvds: RewriteUnary(d => m.Cast(PrimitiveType.Real32, d)); break;

                case Mnemonic.fcnvsd: RewriteUnary(d => m.Cast(PrimitiveType.Real64, d)); break;

                case Mnemonic.fdiv: RewriteBinOp(m.FDiv, null); break;

                case Mnemonic.fldi0: RewriteFldi(0.0F); break;

                case Mnemonic.fldi1: RewriteFldi(1.0F); break;

                case Mnemonic.flds: RewriteMov(); break;

                case Mnemonic.fmac: RewriteFmac(); break;

                case Mnemonic.fmov_d: RewriteMov(); break;

                case Mnemonic.fmov_s: RewriteMov(); break;

                case Mnemonic.jmp: RewriteJmp(); break;

                case Mnemonic.jsr: RewriteJsr(); break;

                case Mnemonic.lds: RewriteMov(); break;

                case Mnemonic.lds_l: RewriteMov(); break;

                case Mnemonic.mac_l: RewriteMac(PrimitiveType.Int64); break;

                case Mnemonic.mac_w: RewriteMac(PrimitiveType.Int32); break;

                case Mnemonic.mov: RewriteMov(); break;

                case Mnemonic.mova: RewriteMova(); break;

                case Mnemonic.mov_b: RewriteMov(); break;

                case Mnemonic.mov_w: RewriteMov(); break;

                case Mnemonic.mov_l: RewriteMov(); break;

                case Mnemonic.movt: RewriteMovt(); break;

                case Mnemonic.mul_l: RewriteMul_l(); break;

                case Mnemonic.muls_w: RewriteMul_w(PrimitiveType.Int16, m.SMul); break;

                case Mnemonic.mulu_w: RewriteMul_w(PrimitiveType.UInt16, m.UMul); break;

                case Mnemonic.neg: RewriteUnary(m.Neg); break;

                case Mnemonic.negc: RewriteNegc(); break;

                case Mnemonic.not: RewriteUnary(m.Comp); break;

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

                case Mnemonic.ocbi: RewriteOcbi(); break;

                case Mnemonic.or: RewriteBinOp(m.Or, u => (byte)u); break;

                case Mnemonic.rotcl: RewriteRotc(PseudoProcedure.RolC); break;

                case Mnemonic.rotcr: RewriteRotc(PseudoProcedure.RorC); break;

                case Mnemonic.rotl: RewriteRot(PseudoProcedure.Rol); break;

                case Mnemonic.rotr: RewriteRot(PseudoProcedure.Ror); break;

                case Mnemonic.rts: RewriteRts(); break;

                case Mnemonic.sett: RewriteClrtSet(Registers.T, Constant.True()); break;

                case Mnemonic.shad: RewriteShd(m.Shl, m.Sar); break;

                case Mnemonic.shar: RewriteShift(m.Sar, 1); break;

                case Mnemonic.shld: RewriteShd(m.Shl, m.Shr); break;

                case Mnemonic.shll: RewriteShift(m.Shl, 1); break;

                case Mnemonic.shll2: RewriteShift(m.Shl, 2); break;

                case Mnemonic.shll8: RewriteShift(m.Shl, 8); break;

                case Mnemonic.shll16: RewriteShift(m.Shl, 16); break;

                case Mnemonic.shlr: RewriteShift(m.Shr, 1); break;

                case Mnemonic.shlr2: RewriteShift(m.Shr, 2); break;

                case Mnemonic.shlr8: RewriteShift(m.Shr, 8); break;

                case Mnemonic.shlr16: RewriteShift(m.Shr, 16); break;

                case Mnemonic.stc: RewriteMov(); break;

                case Mnemonic.sts: RewriteMov(); break;

                case Mnemonic.sts_l: RewriteMov(); break;

                case Mnemonic.sub: RewriteBinOp(m.ISub, null); break;

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

                case Mnemonic.swap_w: RewriteSwapW(); break;

                case Mnemonic.tst: RewriteTst(); break;

                case Mnemonic.xor: RewriteBinOp(m.Xor, n => (byte)n); break;

                case Mnemonic.xtrct: RewriteXtrct(); break;
                }
                yield return(m.MakeCluster(instr.Address, instr.Length, this.iclass));
            }
        }
示例#5
0
        public IEnumerator <RtlInstructionCluster> GetEnumerator()
        {
            while (dasm.MoveNext())
            {
                this.instr = dasm.Current;
                var instrs = new List <RtlInstruction>();
                this.m = new RtlEmitter(instrs);
                switch (instr.Opcode)
                {
                case Opcode.invalid:
                default:
                    Invalid();
                    break;

                case Opcode.add: RewriteBinOp(m.IAdd, n => (sbyte)n); break;

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

                case Opcode.addv: RewriteAddv(m.IAdd); break;

                case Opcode.and: RewriteBinOp(m.And, n => (byte)n); break;

                case Opcode.and_b: RewriteBinOp(m.And, n => (byte)n); break;

                case Opcode.bf: RewriteBranch(false, false); break;

                case Opcode.bf_s: RewriteBranch(false, true); break;

                case Opcode.bra: RewriteGoto(); break;

                case Opcode.braf: RewriteBraf(); break;

                case Opcode.brk: RewriteBrk(); break;

                case Opcode.bsr: RewriteBsr(); break;

                case Opcode.bsrf: RewriteBsrf(); break;

                case Opcode.bt: RewriteBranch(true, false); break;

                case Opcode.bt_s: RewriteBranch(true, true); break;

                case Opcode.clrmac: RewriteClr(Registers.mac); break;

                case Opcode.clrt: RewriteClrtSetT(Constant.False()); break;

                case Opcode.cmp_eq: RewriteCmp(m.Eq); break;

                case Opcode.cmp_ge: RewriteCmp(m.Ge); break;

                case Opcode.cmp_gt: RewriteCmp(m.Gt); break;

                case Opcode.cmp_hs: RewriteCmp(m.Uge); break;

                case Opcode.cmp_hi: RewriteCmp(m.Ugt); break;

                case Opcode.cmp_pl: RewriteCmp0(m.Gt0); break;

                case Opcode.cmp_pz: RewriteCmp0(m.Ge0); break;

                case Opcode.div0s: RewriteDiv0s(); break;

                case Opcode.div0u: RewriteDiv0u(); break;

                case Opcode.div1: RewriteDiv1(); break;

                case Opcode.dmuls_l: RewriteDmul(m.SMul); break;

                case Opcode.dmulu_l: RewriteDmul(m.UMul); break;

                case Opcode.dt: RewriteDt(); break;

                case Opcode.exts_b: RewriteExt(PrimitiveType.SByte); break;

                case Opcode.exts_w: RewriteExt(PrimitiveType.Int16); break;

                case Opcode.extu_b: RewriteExt(PrimitiveType.Byte); break;

                case Opcode.extu_w: RewriteExt(PrimitiveType.UInt16); break;

                case Opcode.fabs: RewriteFabs(); break;

                case Opcode.fadd: RewriteBinOp(m.FAdd, null); break;

                case Opcode.fcmp_eq: RewriteCmp(m.FEq); break;

                case Opcode.fcmp_gt: RewriteCmp(m.FGt); break;

                case Opcode.fcnvds: RewriteUnary(d => m.Cast(PrimitiveType.Real32, d)); break;

                case Opcode.fcnvsd: RewriteUnary(d => m.Cast(PrimitiveType.Real64, d)); break;

                case Opcode.fdiv: RewriteBinOp(m.FDiv, null); break;

                case Opcode.fldi0: RewriteFldi(0.0F); break;

                case Opcode.fldi1: RewriteFldi(1.0F); break;

                case Opcode.flds: RewriteMov(); break;

                case Opcode.jmp: RewriteJmp(); break;

                case Opcode.jsr: RewriteJsr(); break;

                case Opcode.lds_l: RewriteMov(); break;

                case Opcode.mov: RewriteMov(); break;

                case Opcode.mova: RewriteMova(); break;

                case Opcode.mov_b: RewriteMov(); break;

                case Opcode.mov_w: RewriteMov(); break;

                case Opcode.mov_l: RewriteMov(); break;

                case Opcode.movt: RewriteMovt(); break;

                case Opcode.mul_l: RewriteMul_l(); break;

                case Opcode.muls_w: RewriteMul_w(PrimitiveType.Int16, m.SMul); break;

                case Opcode.mulu_w: RewriteMul_w(PrimitiveType.UInt16, m.UMul); break;

                case Opcode.neg: RewriteUnary(m.Neg); break;

                case Opcode.negc: RewriteNegc(); break;

                case Opcode.not: RewriteUnary(m.Comp); break;

                case Opcode.nop: this.rtlc = RtlClass.Linear; m.Nop(); break;

                case Opcode.or: RewriteBinOp(m.Or, u => (byte)u); break;

                case Opcode.rotcl: RewriteRotc(PseudoProcedure.RolC); break;

                case Opcode.rotcr: RewriteRotc(PseudoProcedure.RorC); break;

                case Opcode.rotl: RewriteRot(PseudoProcedure.Rol); break;

                case Opcode.rotr: RewriteRot(PseudoProcedure.Ror); break;

                case Opcode.rts: RewriteRts(); break;

                case Opcode.sett: RewriteClrtSetT(Constant.True()); break;

                case Opcode.shad: RewriteShd(m.Shl, m.Sar); break;

                case Opcode.shar: RewriteShift(m.Sar, 1); break;

                case Opcode.shld: RewriteShd(m.Shl, m.Shr); break;

                case Opcode.shll: RewriteShift(m.Shl, 1); break;

                case Opcode.shll2: RewriteShift(m.Shl, 2); break;

                case Opcode.shll8: RewriteShift(m.Shl, 8); break;

                case Opcode.shll16: RewriteShift(m.Shl, 16); break;

                case Opcode.shlr: RewriteShift(m.Shr, 1); break;

                case Opcode.shlr2: RewriteShift(m.Shr, 2); break;

                case Opcode.shlr8: RewriteShift(m.Shr, 8); break;

                case Opcode.shlr16: RewriteShift(m.Shr, 16); break;

                case Opcode.sts: RewriteMov(); break;

                case Opcode.sts_l: RewriteMov(); break;

                case Opcode.sub: RewriteBinOp(m.ISub, null); break;

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

                case Opcode.swap_w: RewriteSwapW(); break;

                case Opcode.tst: RewriteTst(); break;

                case Opcode.xor: RewriteBinOp(m.Xor, n => (byte)n); break;

                case Opcode.xtrct: RewriteXtrct(); break;
                }
                var rtlc = new RtlInstructionCluster(instr.Address, instr.Length, instrs.ToArray())
                {
                    Class = this.rtlc,
                };
                yield return(rtlc);
            }
        }