diff options
author | Mike Pall <mike> | 2024-01-22 19:06:36 +0100 |
---|---|---|
committer | Mike Pall <mike> | 2024-01-22 19:06:36 +0100 |
commit | 4b90f6c4d7420139c135435e1580acb52ea18436 (patch) | |
tree | 1c3543b6baa4f8b30a33e8a624b60edc6feb0206 /src/jit | |
parent | c525bcb9024510cad9e170e12b6209aedb330f83 (diff) | |
download | luajit-4b90f6c4d7420139c135435e1580acb52ea18436.tar.gz luajit-4b90f6c4d7420139c135435e1580acb52ea18436.tar.bz2 luajit-4b90f6c4d7420139c135435e1580acb52ea18436.zip |
Add cross-32/64 bit and deterministic bytecode generation.
Contributed by Peter Cawley. #993 #1008
Diffstat (limited to 'src/jit')
-rw-r--r-- | src/jit/bcsave.lua | 31 |
1 files changed, 21 insertions, 10 deletions
diff --git a/src/jit/bcsave.lua b/src/jit/bcsave.lua index 390d297c..131bf39b 100644 --- a/src/jit/bcsave.lua +++ b/src/jit/bcsave.lua | |||
@@ -29,6 +29,9 @@ Save LuaJIT bytecode: luajit -b[options] input output | |||
29 | -l Only list bytecode. | 29 | -l Only list bytecode. |
30 | -s Strip debug info (default). | 30 | -s Strip debug info (default). |
31 | -g Keep debug info. | 31 | -g Keep debug info. |
32 | -W Generate 32 bit (non-GC64) bytecode. | ||
33 | -X Generate 64 bit (GC64) bytecode. | ||
34 | -d Generate bytecode in deterministic manner. | ||
32 | -n name Set module name (default: auto-detect from input name). | 35 | -n name Set module name (default: auto-detect from input name). |
33 | -t type Set output file type (default: auto-detect from output name). | 36 | -t type Set output file type (default: auto-detect from output name). |
34 | -a arch Override architecture for object files (default: native). | 37 | -a arch Override architecture for object files (default: native). |
@@ -51,8 +54,9 @@ local function check(ok, ...) | |||
51 | end | 54 | end |
52 | 55 | ||
53 | local function readfile(ctx, input) | 56 | local function readfile(ctx, input) |
54 | if type(input) == "function" then return input end | 57 | if ctx.string then |
55 | if ctx.filename then | 58 | return check(loadstring(input, nil, ctx.mode)) |
59 | elseif ctx.filename then | ||
56 | local data | 60 | local data |
57 | if input == "-" then | 61 | if input == "-" then |
58 | data = io.stdin:read("*a") | 62 | data = io.stdin:read("*a") |
@@ -61,10 +65,10 @@ local function readfile(ctx, input) | |||
61 | data = assert(fp:read("*a")) | 65 | data = assert(fp:read("*a")) |
62 | assert(fp:close()) | 66 | assert(fp:close()) |
63 | end | 67 | end |
64 | return check(load(data, ctx.filename)) | 68 | return check(load(data, ctx.filename, ctx.mode)) |
65 | else | 69 | else |
66 | if input == "-" then input = nil end | 70 | if input == "-" then input = nil end |
67 | return check(loadfile(input)) | 71 | return check(loadfile(input, ctx.mode)) |
68 | end | 72 | end |
69 | end | 73 | end |
70 | 74 | ||
@@ -624,7 +628,7 @@ end | |||
624 | 628 | ||
625 | local function bcsave(ctx, input, output) | 629 | local function bcsave(ctx, input, output) |
626 | local f = readfile(ctx, input) | 630 | local f = readfile(ctx, input) |
627 | local s = string.dump(f, ctx.strip) | 631 | local s = string.dump(f, ctx.mode) |
628 | local t = ctx.type | 632 | local t = ctx.type |
629 | if not t then | 633 | if not t then |
630 | t = detecttype(output) | 634 | t = detecttype(output) |
@@ -647,9 +651,11 @@ local function docmd(...) | |||
647 | local n = 1 | 651 | local n = 1 |
648 | local list = false | 652 | local list = false |
649 | local ctx = { | 653 | local ctx = { |
650 | strip = true, arch = jit.arch, os = jit.os:lower(), | 654 | mode = "bt", arch = jit.arch, os = jit.os:lower(), |
651 | type = false, modname = false, | 655 | type = false, modname = false, string = false, |
652 | } | 656 | } |
657 | local strip = "s" | ||
658 | local gc64 = "" | ||
653 | while n <= #arg do | 659 | while n <= #arg do |
654 | local a = arg[n] | 660 | local a = arg[n] |
655 | if type(a) == "string" and a:sub(1, 1) == "-" and a ~= "-" then | 661 | if type(a) == "string" and a:sub(1, 1) == "-" and a ~= "-" then |
@@ -660,14 +666,18 @@ local function docmd(...) | |||
660 | if opt == "l" then | 666 | if opt == "l" then |
661 | list = true | 667 | list = true |
662 | elseif opt == "s" then | 668 | elseif opt == "s" then |
663 | ctx.strip = true | 669 | strip = "s" |
664 | elseif opt == "g" then | 670 | elseif opt == "g" then |
665 | ctx.strip = false | 671 | strip = "" |
672 | elseif opt == "W" or opt == "X" then | ||
673 | gc64 = opt | ||
674 | elseif opt == "d" then | ||
675 | ctx.mode = ctx.mode .. opt | ||
666 | else | 676 | else |
667 | if arg[n] == nil or m ~= #a then usage() end | 677 | if arg[n] == nil or m ~= #a then usage() end |
668 | if opt == "e" then | 678 | if opt == "e" then |
669 | if n ~= 1 then usage() end | 679 | if n ~= 1 then usage() end |
670 | arg[1] = check(loadstring(arg[1])) | 680 | ctx.string = true |
671 | elseif opt == "n" then | 681 | elseif opt == "n" then |
672 | ctx.modname = checkmodname(tremove(arg, n)) | 682 | ctx.modname = checkmodname(tremove(arg, n)) |
673 | elseif opt == "t" then | 683 | elseif opt == "t" then |
@@ -687,6 +697,7 @@ local function docmd(...) | |||
687 | n = n + 1 | 697 | n = n + 1 |
688 | end | 698 | end |
689 | end | 699 | end |
700 | ctx.mode = ctx.mode .. strip .. gc64 | ||
690 | if list then | 701 | if list then |
691 | if #arg == 0 or #arg > 2 then usage() end | 702 | if #arg == 0 or #arg > 2 then usage() end |
692 | bclist(ctx, arg[1], arg[2] or "-") | 703 | bclist(ctx, arg[1], arg[2] or "-") |