mirror of
https://github.com/LuaJIT/LuaJIT.git
synced 2025-02-07 23:24:09 +00:00
Add -F option to override filename in jit.bcsave (luajit -b).
Suggested by Mathias Westerdahl.
This commit is contained in:
parent
975ec13f5d
commit
03080b795a
@ -111,6 +111,7 @@ are accepted:
|
|||||||
<li><tt>-t type</tt> — Set output file type (default: auto-detect from output name).</li>
|
<li><tt>-t type</tt> — Set output file type (default: auto-detect from output name).</li>
|
||||||
<li><tt>-a arch</tt> — Override architecture for object files (default: native).</li>
|
<li><tt>-a arch</tt> — Override architecture for object files (default: native).</li>
|
||||||
<li><tt>-o os</tt> — Override OS for object files (default: native).</li>
|
<li><tt>-o os</tt> — Override OS for object files (default: native).</li>
|
||||||
|
<li><tt>-F name</tt> — Override filename (default: input filename).</li>
|
||||||
<li><tt>-e chunk</tt> — Use chunk string as input.</li>
|
<li><tt>-e chunk</tt> — Use chunk string as input.</li>
|
||||||
<li><tt>-</tt> (a single minus sign) — Use stdin as input and/or stdout as output.</li>
|
<li><tt>-</tt> (a single minus sign) — Use stdin as input and/or stdout as output.</li>
|
||||||
</ul>
|
</ul>
|
||||||
|
@ -33,6 +33,7 @@ Save LuaJIT bytecode: luajit -b[options] input output
|
|||||||
-t type Set output file type (default: auto-detect from output name).
|
-t type Set output file type (default: auto-detect from output name).
|
||||||
-a arch Override architecture for object files (default: native).
|
-a arch Override architecture for object files (default: native).
|
||||||
-o os Override OS for object files (default: native).
|
-o os Override OS for object files (default: native).
|
||||||
|
-F name Override filename (default: input filename).
|
||||||
-e chunk Use chunk string as input.
|
-e chunk Use chunk string as input.
|
||||||
-- Stop handling options.
|
-- Stop handling options.
|
||||||
- Use stdin as input and/or stdout as output.
|
- Use stdin as input and/or stdout as output.
|
||||||
@ -49,10 +50,22 @@ local function check(ok, ...)
|
|||||||
os.exit(1)
|
os.exit(1)
|
||||||
end
|
end
|
||||||
|
|
||||||
local function readfile(input)
|
local function readfile(ctx, input)
|
||||||
if type(input) == "function" then return input end
|
if type(input) == "function" then return input end
|
||||||
if input == "-" then input = nil end
|
if ctx.filename then
|
||||||
return check(loadfile(input))
|
local data
|
||||||
|
if input == "-" then
|
||||||
|
data = io.stdin:read("*a")
|
||||||
|
else
|
||||||
|
local fp = assert(io.open(input, "rb"))
|
||||||
|
data = assert(fp:read("*a"))
|
||||||
|
assert(fp:close())
|
||||||
|
end
|
||||||
|
return check(load(data, ctx.filename))
|
||||||
|
else
|
||||||
|
if input == "-" then input = nil end
|
||||||
|
return check(loadfile(input))
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
local function savefile(name, mode)
|
local function savefile(name, mode)
|
||||||
@ -604,13 +617,13 @@ end
|
|||||||
|
|
||||||
------------------------------------------------------------------------------
|
------------------------------------------------------------------------------
|
||||||
|
|
||||||
local function bclist(input, output)
|
local function bclist(ctx, input, output)
|
||||||
local f = readfile(input)
|
local f = readfile(ctx, input)
|
||||||
require("jit.bc").dump(f, savefile(output, "w"), true)
|
require("jit.bc").dump(f, savefile(output, "w"), true)
|
||||||
end
|
end
|
||||||
|
|
||||||
local function bcsave(ctx, input, output)
|
local function bcsave(ctx, input, output)
|
||||||
local f = readfile(input)
|
local f = readfile(ctx, input)
|
||||||
local s = string.dump(f, ctx.strip)
|
local s = string.dump(f, ctx.strip)
|
||||||
local t = ctx.type
|
local t = ctx.type
|
||||||
if not t then
|
if not t then
|
||||||
@ -663,6 +676,8 @@ local function docmd(...)
|
|||||||
ctx.arch = checkarg(tremove(arg, n), map_arch, "architecture")
|
ctx.arch = checkarg(tremove(arg, n), map_arch, "architecture")
|
||||||
elseif opt == "o" then
|
elseif opt == "o" then
|
||||||
ctx.os = checkarg(tremove(arg, n), map_os, "OS name")
|
ctx.os = checkarg(tremove(arg, n), map_os, "OS name")
|
||||||
|
elseif opt == "F" then
|
||||||
|
ctx.filename = "@"..tremove(arg, n)
|
||||||
else
|
else
|
||||||
usage()
|
usage()
|
||||||
end
|
end
|
||||||
@ -674,7 +689,7 @@ local function docmd(...)
|
|||||||
end
|
end
|
||||||
if list then
|
if list then
|
||||||
if #arg == 0 or #arg > 2 then usage() end
|
if #arg == 0 or #arg > 2 then usage() end
|
||||||
bclist(arg[1], arg[2] or "-")
|
bclist(ctx, arg[1], arg[2] or "-")
|
||||||
else
|
else
|
||||||
if #arg ~= 2 then usage() end
|
if #arg ~= 2 then usage() end
|
||||||
bcsave(ctx, arg[1], arg[2])
|
bcsave(ctx, arg[1], arg[2])
|
||||||
|
Loading…
Reference in New Issue
Block a user