26 lines
640 B
MoonBit
26 lines
640 B
MoonBit
///|
|
|
async fn main {
|
|
let args = @env.args()
|
|
// args[0] is the program name
|
|
if args.length() < 3 {
|
|
println("usage: wasm2elf <input.wasm> <output> [entry-export]")
|
|
@env.exit(2)
|
|
}
|
|
let wasm = @fs.read_binary(args[1])
|
|
let entry : String? = if args.length() > 3 { Some(args[3]) } else { None }
|
|
try {
|
|
let elf = @lib.compile(wasm, entry)
|
|
@fs.write_binary(args[2], elf, permission=0o755)
|
|
println("wrote \{args[2]} (\{elf.length()} bytes)")
|
|
} catch {
|
|
@lib.CompileError(msg) => {
|
|
println("error: \{msg}")
|
|
@env.exit(1)
|
|
}
|
|
err => {
|
|
println("error: \{err}")
|
|
@env.exit(1)
|
|
}
|
|
}
|
|
}
|