fix: main outputs to current dir

This commit is contained in:
Gleb Koval 2025-02-21 18:46:10 +00:00
parent 1c6ea16b6e
commit ab28f0950a
Signed by: cyclane
GPG Key ID: 15E168A8B332382C

View File

@ -216,15 +216,18 @@ _readi:
case _ => List()
}
def compile(filename: String)(using stdout: PrintStream = Console.out): Int =
def compile(filename: String, outFile: Option[File] = None)(using
stdout: PrintStream = Console.out
): Int =
frontend(os.read(os.Path(filename))) match {
case Left(typedProg) =>
val asmFile = outFile.getOrElse(File(filename.stripSuffix(".wacc") + ".s"))
println("OUTPUT TO" + asmFile.getAbsolutePath())
backend(typedProg) match {
case s: String =>
os.write.over(os.Path(filename.stripSuffix(".wacc") + ".s"), s)
os.write.over(os.Path(asmFile.getAbsolutePath), s)
case ops: List[asm.AsmLine] => {
val outFile = File(filename.stripSuffix(".wacc") + ".s")
writer.writeTo(ops, PrintStream(outFile))
writer.writeTo(ops, PrintStream(asmFile))
}
}
0
@ -233,6 +236,10 @@ def compile(filename: String)(using stdout: PrintStream = Console.out): Int =
def main(args: Array[String]): Unit =
OParser.parse(cliParser, args, CliConfig()) match {
case Some(config) => compile(config.file.getAbsolutePath)
case None =>
case Some(config) =>
compile(
config.file.getAbsolutePath,
outFile = Some(File(".", config.file.getName.stripSuffix(".wacc") + ".s"))
)
case None =>
}