@@ -46,8 +46,8 @@ local action_names = {
46
46
" SETLABEL" , " REL_A" ,
47
47
-- action arg (1 byte) or int arg, 2 buffer pos (link, offset):
48
48
" REL_LG" , " REL_PC" ,
49
- -- action arg (1 byte) or ptrdiff_t arg, 1 buffer pos (link):
50
- " IMM_LG" , " IMM_LG64 " , " IMM_PC" , " IMM_PC64 " ,
49
+ -- action arg (1 byte) or int arg, 1 buffer pos (link):
50
+ " IMM_LG" , " IMM_PC" ,
51
51
-- action arg (1 byte) or int arg, 1 buffer pos (offset):
52
52
" LABEL_LG" , " LABEL_PC" ,
53
53
-- action arg (1 byte), 1 buffer pos (offset):
@@ -438,16 +438,6 @@ local function wputlabel(aprefix, imm, num)
438
438
end
439
439
end
440
440
441
- -- Put action for label arg (IMM_LG64, IMM_PC64, REL_LG, REL_PC).
442
- local function wputlabel64 (aprefix , imm , num )
443
- if type (imm ) == " number" then
444
- waction (" IMM_LG64" , nil , num );
445
- wputxb (imm )
446
- else
447
- waction (" IMM_PC64" , imm , num )
448
- end
449
- end
450
-
451
441
-- Put signed byte or arg.
452
442
local function wputsbarg (n )
453
443
if type (n ) == " number" then
@@ -479,38 +469,34 @@ local function wputwarg(n)
479
469
else waction (" IMM_W" , n ) end
480
470
end
481
471
482
- -- Put signed or unsigned qword or arg.
483
- local function wputqarg (n )
472
+ -- Put signed or unsigned dword or arg.
473
+ local function wputdarg (n )
484
474
local tn = type (n )
485
475
if tn == " number" then
486
476
wputb (band (n , 255 ))
487
477
wputb (band (shr (n , 8 ), 255 ))
488
478
wputb (band (shr (n , 16 ), 255 ))
489
- wputb (band (shr (n , 24 ), 255 ))
490
- wputb (band (shr (n , 32 ), 255 ))
491
- wputb (band (shr (n , 40 ), 255 ))
492
- wputb (band (shr (n , 48 ), 255 ))
493
- wputb (shr (n , 56 ))
479
+ wputb (shr (n , 24 ))
494
480
elseif tn == " table" then
495
- wputlabel64 (" IMM_" , n [1 ], 1 )
481
+ wputlabel (" IMM_" , n [1 ], 1 )
496
482
else
497
- waction (" IMM_D" , format (" (unsigned int)(%s)" , n ))
498
- waction (" IMM_D" , format (" (unsigned int)((%s)>>32)" , n ))
483
+ waction (" IMM_D" , n )
499
484
end
500
485
end
501
486
502
- -- Put signed or unsigned dword or arg.
503
- local function wputdarg (n )
487
+ -- Put signed or unsigned qword or arg.
488
+ local function wputqarg (n )
504
489
local tn = type (n )
505
- if tn == " number" then
490
+ if tn == " number" then -- This is only used for numbers from -2^31..2^32-1.
506
491
wputb (band (n , 255 ))
507
492
wputb (band (shr (n , 8 ), 255 ))
508
493
wputb (band (shr (n , 16 ), 255 ))
509
494
wputb (shr (n , 24 ))
510
- elseif tn == " table " then
511
- wputlabel ( " IMM_ " , n [ 1 ], 1 )
495
+ local sign = n < 0 and 255 or 0
496
+ wputb ( sign ); wputb ( sign ); wputb ( sign ); wputb ( sign )
512
497
else
513
- waction (" IMM_D" , n )
498
+ waction (" IMM_D" , format (" (unsigned int)(%s)" , n ))
499
+ waction (" IMM_D" , format (" (unsigned int)((unsigned long long)(%s)>>32)" , n ))
514
500
end
515
501
end
516
502
@@ -693,10 +679,16 @@ local function opmodestr(op, args)
693
679
end
694
680
695
681
-- Convert number to valid integer or nil.
696
- local function toint (expr )
682
+ local function toint (expr , isqword )
697
683
local n = tonumber (expr )
698
684
if n then
699
- if n % 1 ~= 0 or n < - 2147483648 or n > 4294967295 then
685
+ if n % 1 ~= 0 then
686
+ werror (" not an integer number `" .. expr .. " '" )
687
+ elseif isqword then
688
+ if n < - 2147483648 or n > 2147483647 then
689
+ n = nil -- Handle it as an expression to avoid precision loss.
690
+ end
691
+ elseif n < - 2147483648 or n > 4294967295 then
700
692
werror (" bad integer number `" .. expr .. " '" )
701
693
end
702
694
return n
@@ -779,7 +771,7 @@ local function rtexpr(expr)
779
771
end
780
772
781
773
-- Parse operand and return { mode, opsize, reg, xreg, xsc, disp, imm }.
782
- local function parseoperand (param )
774
+ local function parseoperand (param , isqword )
783
775
local t = {}
784
776
785
777
local expr = param
@@ -867,7 +859,7 @@ local function parseoperand(param)
867
859
t .disp = dispexpr (tailx )
868
860
else
869
861
-- imm or opsize*imm
870
- local imm = toint (expr )
862
+ local imm = toint (expr , isqword )
871
863
if not imm and sub (expr , 1 , 1 ) == " *" and t .opsize then
872
864
imm = toint (sub (expr , 2 ))
873
865
if imm then
@@ -1982,7 +1974,7 @@ local function dopattern(pat, args, sz, op, needrex)
1982
1974
local a = args [narg ]
1983
1975
narg = narg + 1
1984
1976
local mode , imm = a .mode , a .imm
1985
- if mode == " iJ" and not match (" iIJ" , c ) then
1977
+ if mode == " iJ" and not match (x64 and " J " or " iIJ" , c ) then
1986
1978
werror (" bad operand size for label" )
1987
1979
end
1988
1980
if c == " S" then
@@ -2174,24 +2166,18 @@ end
2174
2166
local function op_data (params )
2175
2167
if not params then return " imm..." end
2176
2168
local sz = sub (params .op , 2 , 2 )
2177
- if sz == " a" then sz = addrsize end
2169
+ if sz == " l " then sz = " d " elseif sz == " a" then sz = addrsize end
2178
2170
for _ ,p in ipairs (params ) do
2179
- local a = parseoperand (p )
2171
+ local a = parseoperand (p , sz == " q " )
2180
2172
if sub (a .mode , 1 , 1 ) ~= " i" or (a .opsize and a .opsize ~= sz ) then
2181
2173
werror (" bad mode or size in `" .. p .. " '" )
2182
2174
end
2183
2175
if a .mode == " iJ" then
2184
- if sz == ' q' then
2185
- wputlabel64 (" IMM_" , a .imm , 1 )
2186
- else
2187
- wputlabel (" IMM_" , a .imm , 1 )
2188
- end
2176
+ wputlabel (" IMM_" , a .imm , 1 )
2177
+ elseif sz == " q" then
2178
+ wputqarg (a .imm )
2189
2179
else
2190
- if sz == ' q' then
2191
- wputqarg (a .imm )
2192
- else
2193
- wputszarg (sz , a .imm )
2194
- end
2180
+ wputszarg (sz , a .imm )
2195
2181
end
2196
2182
if secpos + 2 > maxsecpos then wflush () end
2197
2183
end
@@ -2201,7 +2187,11 @@ map_op[".byte_*"] = op_data
2201
2187
map_op [" .sbyte_*" ] = op_data
2202
2188
map_op [" .word_*" ] = op_data
2203
2189
map_op [" .dword_*" ] = op_data
2190
+ map_op [" .qword_*" ] = op_data
2204
2191
map_op [" .aword_*" ] = op_data
2192
+ map_op [" .long_*" ] = op_data
2193
+ map_op [" .quad_*" ] = op_data
2194
+ map_op [" .addr_*" ] = op_data
2205
2195
2206
2196
---- --------------------------------------------------------------------------
2207
2197
0 commit comments