mirror of
https://github.com/LuaJIT/LuaJIT.git
synced 2025-04-21 14:23:26 +00:00
Add option to set custom filename to bcsave+bclist
This commit is contained in:
parent
633f265f67
commit
79678697b2
@ -29,6 +29,7 @@ Save LuaJIT bytecode: luajit -b[options] input output
|
|||||||
-l Only list bytecode.
|
-l Only list bytecode.
|
||||||
-s Strip debug info (default).
|
-s Strip debug info (default).
|
||||||
-g Keep debug info.
|
-g Keep debug info.
|
||||||
|
-f Set custom file name (passed to loadstring. default: input filename)
|
||||||
-n name Set module name (default: auto-detect from input name).
|
-n name Set module name (default: auto-detect from input name).
|
||||||
-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).
|
||||||
@ -49,10 +50,13 @@ local function check(ok, ...)
|
|||||||
os.exit(1)
|
os.exit(1)
|
||||||
end
|
end
|
||||||
|
|
||||||
local function readfile(input)
|
local function readfile(input, filename)
|
||||||
if type(input) == "function" then return input end
|
if type(input) == "function" then return input end
|
||||||
if input == "-" then input = nil end
|
if input == "-" then input = nil end
|
||||||
return check(loadfile(input))
|
local f = assert(io.open(input, "r"))
|
||||||
|
local src = f:read("*all")
|
||||||
|
f:close()
|
||||||
|
return check(loadstring(src, filename))
|
||||||
end
|
end
|
||||||
|
|
||||||
local function savefile(name, mode)
|
local function savefile(name, mode)
|
||||||
@ -604,13 +608,13 @@ end
|
|||||||
|
|
||||||
------------------------------------------------------------------------------
|
------------------------------------------------------------------------------
|
||||||
|
|
||||||
local function bclist(input, output)
|
local function bclist(input, output, filename)
|
||||||
local f = readfile(input)
|
local f = readfile(input, filename)
|
||||||
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, filename)
|
||||||
local f = readfile(input)
|
local f = readfile(input, filename)
|
||||||
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
|
||||||
@ -633,6 +637,7 @@ local function docmd(...)
|
|||||||
local arg = {...}
|
local arg = {...}
|
||||||
local n = 1
|
local n = 1
|
||||||
local list = false
|
local list = false
|
||||||
|
local filename = nil
|
||||||
local ctx = {
|
local ctx = {
|
||||||
strip = true, arch = jit.arch, os = jit.os:lower(),
|
strip = true, arch = jit.arch, os = jit.os:lower(),
|
||||||
type = false, modname = false,
|
type = false, modname = false,
|
||||||
@ -663,6 +668,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
|
||||||
|
filename = tremove(arg, n)
|
||||||
else
|
else
|
||||||
usage()
|
usage()
|
||||||
end
|
end
|
||||||
@ -674,10 +681,10 @@ 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(arg[1], arg[2] or "-", filename or arg[1])
|
||||||
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], filename or arg[1])
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user