Added -o/--output option

This commit is contained in:
Mattia Giambirtone 2022-12-16 15:19:38 +01:00
parent cf6d20e757
commit 382244f7a7
1 changed files with 11 additions and 5 deletions

View File

@ -160,7 +160,7 @@ proc repl(warnings: seq[WarningKind] = @[], mismatches: bool = false, mode: Comp
proc runFile(f: string, fromString: bool = false, dump: bool = true, breakpoints: seq[uint64] = @[], dis: bool = false,
warnings: seq[WarningKind] = @[], mismatches: bool = false, mode: CompileMode = Debug, run: bool = true,
backend: PeonBackend = PeonBackend.Bytecode) =
backend: PeonBackend = PeonBackend.Bytecode, output: string) =
var
tokens: seq[Token] = @[]
tree: seq[Declaration] = @[]
@ -213,12 +213,13 @@ proc runFile(f: string, fromString: bool = false, dump: bool = true, breakpoints
styledEcho fgCyan, "Compilation step:\n"
debugger.disassembleChunk(compiled, f)
echo ""
var path = splitFile(f).dir
var path = splitFile(if output.len() > 0: output else: f).dir
if path.len() > 0:
path &= "/"
path &= splitFile(f).name & ".pbc"
if not path.endsWith(".pbc"):
path &= splitFile(if output.len() > 0: output else: f).name & ".pbc"
if dump and not fromString:
serializer.dumpFile(compiled, f, path)
serializer.dumpFile(compiled, f , path)
serialized = serializer.loadFile(path)
else:
serialized = serializer.loadBytes(serializer.dumpBytes(compiled, f))
@ -291,6 +292,7 @@ when isMainModule:
var mode: CompileMode = CompileMode.Debug
var run: bool = true
var backend: PeonBackend
var output: string = ""
for kind, key, value in optParser.getopt():
case kind:
of cmdArgument:
@ -354,6 +356,8 @@ when isMainModule:
dis = true
of "compile":
run = false
of "output":
output = value
of "backend":
case value:
of "bytecode":
@ -367,6 +371,8 @@ when isMainModule:
quit()
of cmdShortOption:
case key:
of "o":
output = value
of "h":
echo HELP_MESSAGE
quit()
@ -401,4 +407,4 @@ when isMainModule:
if file == "":
repl(warnings, mismatches, mode)
else:
runFile(file, fromString, dump, breaks, dis, warnings, mismatches, mode, run, backend)
runFile(file, fromString, dump, breaks, dis, warnings, mismatches, mode, run, backend, output)