1 #/bin/emblua LUAPREFIX=|
4 | ------------------------------------
5 | ccs = {"O", "NO", "B", "AE", "E", "NE", "BE", "A", "S", "NS", "PE", "PO", "L", "GE", "LE", "G"}
6 | ccalias={C = "B", NAE = "B", NB = "AE", NC = "AE", Z = "E", NZ = "NE", NA = "BE", NBE = "A",
7 | P = "PE", NP = "PO", NGE = "L", NL = "GE", NG = "LE", NLE = "G"}
9 | ------------------------------------
12 | ------------------------------------
13 | for l,w in ipairs{"ADD","OR","AND","SUB","XOR","ADC","SBB","CMP","TEST"} do
16 | ------------------------------------
17 INC_H -> INC_H_x32, INC_H_x64
18 DEC_H -> DEC_H_x32, DEC_H_x64
19 INC_W -> INC_W_x32, INC_W_x64
20 DEC_W -> DEC_W_x32, DEC_W_x64
21 INC_R -> INC_W_x32, INC_D
22 DEC_R -> DEC_W_x32, DEC_D
34 XCHG_RAX_R -> XCHG_EAX_W, XCHG_RAX_D
35 CMPXCHG_RR_RAX -> CMPXCHG_WW_EAX, CMPXCHG_DD_RAX
36 CMPXCHG_MR_RAX -> CMPXCHG_MW_EAX, CMPXCHG_MD_RAX
38 MOV_RI32S -> MOV_WI, MOV_DI32S
39 MOV_RI32U -> MOV_WI, MOV_DI32U
41 MOV_MI32S -> MOV_M32I, MOV_M64I32S
43 | for l,w in pairs(ccalias) do
44 SET%(l)_B -> SET%(w)_B, SET%(w)_B
45 SET%(l)_M8 -> SET%(w)_M8, SET%(w)_M8
46 J%(l)_BB_FT -> J%(w)_BB_FT, J%(w)_BB_FT
49 | for k,v in ipairs{{"B",8},{"H",16}} do
55 MOVSX_RW -> MOV_WW, MOVSX_DW
56 MOVSX_RM32 -> MOV_WM, MOVSX_DM32
57 MOVZX_RW -> MOV_WW, MOV_WW
58 MOVZX_RM32 -> MOV_WM, MOV_WM
60 MOVZX_DW -> INVALID, MOV_WW
61 MOVZX_DM32 -> INVALID, MOV_WM
63 | ------------------------------------
64 | for rm_,rm in ipairs{"rr","rm"} do
65 | local RM = rm=="rr" and "R" or "M"
66 | local Rm = rm=="rr" and "R" or "m"
67 | local HM = rm=="rr" and "H" or "M"
68 | local WM = rm=="rr" and "W" or "M"
69 | local WM32 = rm=="rr" and "W" or "M32"
70 | local DM = rm=="rr" and "D" or "M"
71 | local DM64 = rm=="rr" and "D" or "M64"
73 | ------------------------------------
74 | for l,w in ipairs{"ADD","OR","AND","SUB","XOR","ADC","SBB","CMP","TEST"} do
78 | for l,w in ipairs{"NOT","NEG","DIV","IDIV","MUL","IMUL"} do
81 | for l,w in ipairs{"ROL","ROR","SHL","SHR","SAR","RCL","RCR"} do
85 | for l,w in ipairs{"SHLD","SHRD"} do
101 | for l,w in ipairs(ccs) do
105 | for l,w in pairs(ccalias) do
106 CMOV%(l)_H%(HM) -> CMOV%(w)_H%(HM), CMOV%(w)_H%(HM)
107 CMOV%(l)_W%(WM) -> CMOV%(w)_W%(WM), CMOV%(w)_W%(WM)
108 CMOV%(l)_D%(DM) -> INVALID, CMOV%(w)_D%(DM)
109 CMOV%(l)_R%(RM) -> CMOV%(w)_W%(WM), CMOV%(w)_D%(DM)
111 // ----------------------------------
112 // DISABLED: IJMP_%(RM) -> IJMP_%(WM32)_x32, IJMP_%(DM64)_x64
113 // DISABLED: ICALL_%(RM) -> ICALL_%(WM32)_x32, ICALL_%(DM64)_x64
114 PUSH_%(RM) -> PUSH_%(WM32)_x32, PUSH_%(DM64)_x64
115 POP_%(RM) -> POP_%(WM32)_x32, POP_%(DM64)_x64