diff options
author | Mike Pall <mike> | 2022-08-15 14:16:58 +0200 |
---|---|---|
committer | Mike Pall <mike> | 2022-08-15 14:16:58 +0200 |
commit | 03080b795aa3496ed62d4a0697c9f4767e7ca7e5 (patch) | |
tree | c69815093757d849842233dc70376e84c8839a1b | |
parent | 975ec13f5d5aefcac1dbb15fa867e660e07c93a1 (diff) | |
download | luajit-03080b795aa3496ed62d4a0697c9f4767e7ca7e5.tar.gz luajit-03080b795aa3496ed62d4a0697c9f4767e7ca7e5.tar.bz2 luajit-03080b795aa3496ed62d4a0697c9f4767e7ca7e5.zip |
Add -F option to override filename in jit.bcsave (luajit -b).
Suggested by Mathias Westerdahl.
-rw-r--r-- | doc/running.html | 1 | ||||
-rw-r--r-- | src/jit/bcsave.lua | 29 |
2 files changed, 23 insertions, 7 deletions
diff --git a/doc/running.html b/doc/running.html index 177e6357..91a719f9 100644 --- a/doc/running.html +++ b/doc/running.html | |||
@@ -111,6 +111,7 @@ are accepted: | |||
111 | <li><tt>-t type</tt> — Set output file type (default: auto-detect from output name).</li> | 111 | <li><tt>-t type</tt> — Set output file type (default: auto-detect from output name).</li> |
112 | <li><tt>-a arch</tt> — Override architecture for object files (default: native).</li> | 112 | <li><tt>-a arch</tt> — Override architecture for object files (default: native).</li> |
113 | <li><tt>-o os</tt> — Override OS for object files (default: native).</li> | 113 | <li><tt>-o os</tt> — Override OS for object files (default: native).</li> |
114 | <li><tt>-F name</tt> — Override filename (default: input filename).</li> | ||
114 | <li><tt>-e chunk</tt> — Use chunk string as input.</li> | 115 | <li><tt>-e chunk</tt> — Use chunk string as input.</li> |
115 | <li><tt>-</tt> (a single minus sign) — Use stdin as input and/or stdout as output.</li> | 116 | <li><tt>-</tt> (a single minus sign) — Use stdin as input and/or stdout as output.</li> |
116 | </ul> | 117 | </ul> |
diff --git a/src/jit/bcsave.lua b/src/jit/bcsave.lua index f8ed3a1b..90fe9daf 100644 --- a/src/jit/bcsave.lua +++ b/src/jit/bcsave.lua | |||
@@ -33,6 +33,7 @@ Save LuaJIT bytecode: luajit -b[options] input output | |||
33 | -t type Set output file type (default: auto-detect from output name). | 33 | -t type Set output file type (default: auto-detect from output name). |
34 | -a arch Override architecture for object files (default: native). | 34 | -a arch Override architecture for object files (default: native). |
35 | -o os Override OS for object files (default: native). | 35 | -o os Override OS for object files (default: native). |
36 | -F name Override filename (default: input filename). | ||
36 | -e chunk Use chunk string as input. | 37 | -e chunk Use chunk string as input. |
37 | -- Stop handling options. | 38 | -- Stop handling options. |
38 | - Use stdin as input and/or stdout as output. | 39 | - Use stdin as input and/or stdout as output. |
@@ -49,10 +50,22 @@ local function check(ok, ...) | |||
49 | os.exit(1) | 50 | os.exit(1) |
50 | end | 51 | end |
51 | 52 | ||
52 | local function readfile(input) | 53 | local function readfile(ctx, input) |
53 | if type(input) == "function" then return input end | 54 | if type(input) == "function" then return input end |
54 | if input == "-" then input = nil end | 55 | if ctx.filename then |
55 | return check(loadfile(input)) | 56 | local data |
57 | if input == "-" then | ||
58 | data = io.stdin:read("*a") | ||
59 | else | ||
60 | local fp = assert(io.open(input, "rb")) | ||
61 | data = assert(fp:read("*a")) | ||
62 | assert(fp:close()) | ||
63 | end | ||
64 | return check(load(data, ctx.filename)) | ||
65 | else | ||
66 | if input == "-" then input = nil end | ||
67 | return check(loadfile(input)) | ||
68 | end | ||
56 | end | 69 | end |
57 | 70 | ||
58 | local function savefile(name, mode) | 71 | local function savefile(name, mode) |
@@ -604,13 +617,13 @@ end | |||
604 | 617 | ||
605 | ------------------------------------------------------------------------------ | 618 | ------------------------------------------------------------------------------ |
606 | 619 | ||
607 | local function bclist(input, output) | 620 | local function bclist(ctx, input, output) |
608 | local f = readfile(input) | 621 | local f = readfile(ctx, input) |
609 | require("jit.bc").dump(f, savefile(output, "w"), true) | 622 | require("jit.bc").dump(f, savefile(output, "w"), true) |
610 | end | 623 | end |
611 | 624 | ||
612 | local function bcsave(ctx, input, output) | 625 | local function bcsave(ctx, input, output) |
613 | local f = readfile(input) | 626 | local f = readfile(ctx, input) |
614 | local s = string.dump(f, ctx.strip) | 627 | local s = string.dump(f, ctx.strip) |
615 | local t = ctx.type | 628 | local t = ctx.type |
616 | if not t then | 629 | if not t then |
@@ -663,6 +676,8 @@ local function docmd(...) | |||
663 | ctx.arch = checkarg(tremove(arg, n), map_arch, "architecture") | 676 | ctx.arch = checkarg(tremove(arg, n), map_arch, "architecture") |
664 | elseif opt == "o" then | 677 | elseif opt == "o" then |
665 | ctx.os = checkarg(tremove(arg, n), map_os, "OS name") | 678 | ctx.os = checkarg(tremove(arg, n), map_os, "OS name") |
679 | elseif opt == "F" then | ||
680 | ctx.filename = "@"..tremove(arg, n) | ||
666 | else | 681 | else |
667 | usage() | 682 | usage() |
668 | end | 683 | end |
@@ -674,7 +689,7 @@ local function docmd(...) | |||
674 | end | 689 | end |
675 | if list then | 690 | if list then |
676 | if #arg == 0 or #arg > 2 then usage() end | 691 | if #arg == 0 or #arg > 2 then usage() end |
677 | bclist(arg[1], arg[2] or "-") | 692 | bclist(ctx, arg[1], arg[2] or "-") |
678 | else | 693 | else |
679 | if #arg ~= 2 then usage() end | 694 | if #arg ~= 2 then usage() end |
680 | bcsave(ctx, arg[1], arg[2]) | 695 | bcsave(ctx, arg[1], arg[2]) |