#!/usr/bin/env ruby out = Array.new(256, "NULL"); code_list = < 16 then l[2] = l[2][0..15] end if l[2][0..3].to_i(2) < 8 || l[2][0..3].to_i(2) == 15 then b = l[2][0..3] + l[2][12..15] else b = l[2][0..7] end if b =~ /^\d+$/ then no = b.to_i(2) if no == 0x00 || no == 0x01 || no == 0x31 || no == 0x39 then # SH2A 32bit instructions prefix next end next if out[no] == "op" + l[0] if (no >= 0x20 && no <= 0x22) || (no >= 0x60 && no <= 0x62)then l[0] = "MOV_rind" end if no >= 0x24 && no <= 0x26 then l[0] = "MOV_rpd" end if no >= 0x64 && no <= 0x66 then l[0] = "MOV_rpi" end if no == 0x80 || no == 0x81 || no == 0x84 || no == 0x85 then l[0] = "MOV_BW_dsp" end if no == 0x88 then l[0] = "CMP_EQi" end if no == 0xc0 || no == 0xc1 || no == 0xc2 || no == 0xc4 || no == 0xc5 || no == 0xc6 then l[0] = "MOV_gbr" end if out[no] == "NULL" then out[no] = "op" + l[0] else hi = b.to_i(2) / 16 lo = b.to_i(2) % 16 if (hi < 0x8) || (hi >= 0x0f) then out[no] = "op" + hi.to_s(16) + "xx" + lo.to_s(16) else out[no] = "op" + hi.to_s(16) + lo.to_s(16) + "xx" end end else n = (l[2][0..3].to_i(2)) * 16 if n != 0x80 && n != 0xc0 then if n == 0x10 || n == 0x50 then l[0] = "MOV_L_dsp" end if n == 0x90 || n == 0xd0 then l[0] = "MOV_pc" end 16.times { |i| out[n + i] = "op" + l[0] } end end } code = 0 print "bool (*decode[])(uint16_t code, uint64_t address, MCInst *MI, cs_mode mode, sh_info *info, cs_detail *detail) = {\n" (256 / 8).times { |i| bit = "0000000" + code.to_s(2) print "\t/// ", bit[-8,8], "\n\t" 8.times { |j| o = out[i * 8 + j].gsub(/[\.\/]/, '_') print o, ", " code = code.succ } print "\n" } print "};\n"