From ab28f0950a047a80d976e8cb55f0f66a760ad108 Mon Sep 17 00:00:00 2001 From: Gleb Koval Date: Fri, 21 Feb 2025 18:46:10 +0000 Subject: [PATCH] fix: main outputs to current dir --- src/main/wacc/Main.scala | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/src/main/wacc/Main.scala b/src/main/wacc/Main.scala index 8221440..637923d 100644 --- a/src/main/wacc/Main.scala +++ b/src/main/wacc/Main.scala @@ -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 => }