From 7954a9dbe35b6cc190eb5e4d402daeb3177cf018 Mon Sep 17 00:00:00 2001 From: Johannes Wirth Date: Mon, 6 Oct 2025 18:29:03 +0200 Subject: [PATCH] Handle tool output --- .../src/main/scala/com/minres/tgc/hammer/Global.scala | 1 + toolflow/src/main/scala/com/minres/tgc/hammer/Main.scala | 1 + .../scala/com/minres/tgc/hammer/cli/HammerConf.scala | 2 ++ .../main/scala/com/minres/tgc/hammer/tasks/Task.scala | 9 +++++++-- .../scala/com/minres/tgc/hammer/tasks/TreenailTask.scala | 6 +++--- .../tgc/hammer/tasks/longnail/LongnailHLSTask.scala | 3 ++- .../tgc/hammer/tasks/longnail/LongnailMergeTask.scala | 3 ++- .../tgc/hammer/tasks/longnail/LongnailScheduleTask.scala | 3 ++- 8 files changed, 20 insertions(+), 8 deletions(-) diff --git a/toolflow/src/main/scala/com/minres/tgc/hammer/Global.scala b/toolflow/src/main/scala/com/minres/tgc/hammer/Global.scala index f6cb7e6..be1488b 100644 --- a/toolflow/src/main/scala/com/minres/tgc/hammer/Global.scala +++ b/toolflow/src/main/scala/com/minres/tgc/hammer/Global.scala @@ -11,5 +11,6 @@ object Global { lazy val BASE_DIR: Path = os.pwd def OUT_DIR: Path = Main.conf.outputDirectory() def TMP_DIR: Path = OUT_DIR / "tmp" + def LOG_DIR: Path = OUT_DIR / "logs" lazy val CORE_DATASHEETS: Path = HAMMER / "coreDatasheets" } diff --git a/toolflow/src/main/scala/com/minres/tgc/hammer/Main.scala b/toolflow/src/main/scala/com/minres/tgc/hammer/Main.scala index 3007fa4..4b40a99 100644 --- a/toolflow/src/main/scala/com/minres/tgc/hammer/Main.scala +++ b/toolflow/src/main/scala/com/minres/tgc/hammer/Main.scala @@ -25,6 +25,7 @@ object Main { logger.trace(s"Creating output directory ${Global.OUT_DIR}") if (conf.emptyOutputDir()) os.remove.all(Global.OUT_DIR) os.makeDir.all(Global.OUT_DIR) + os.makeDir.all(Global.LOG_DIR) logger.trace(s"Creating temp directory ${Global.TMP_DIR}") os.makeDir.all(Global.TMP_DIR) conf.subcommand match { diff --git a/toolflow/src/main/scala/com/minres/tgc/hammer/cli/HammerConf.scala b/toolflow/src/main/scala/com/minres/tgc/hammer/cli/HammerConf.scala index 29b0fc8..89eb175 100644 --- a/toolflow/src/main/scala/com/minres/tgc/hammer/cli/HammerConf.scala +++ b/toolflow/src/main/scala/com/minres/tgc/hammer/cli/HammerConf.scala @@ -1,5 +1,6 @@ package com.minres.tgc.hammer.cli +import com.minres.tgc.hammer.Global.LOG_DIR import org.rogach.scallop.* import os.Path import com.minres.tgc.hammer.util.FileUtils.* @@ -8,6 +9,7 @@ class HammerConf(arguments: Seq[String]) extends ScallopConf(arguments) { val outputDirectory: ScallopOption[Path] = opt[Path](default = Some("output".path()), descr = "The base output directory") val verbose: ScallopOption[Int] = tally(short = 'v', descr = "Controls the logging of tgc-hammer itself, using it multiple times (-vv) will print more. (0x => WARN, 1x => INFO, 2x => DEBUG, 3x => TRACE)") val emptyOutputDir: ScallopOption[Boolean] = toggle(default = Some(true), descrYes = "Whether to empty the output directory at the start; defaults to true") + val printToolOutput: ScallopOption[Boolean] = toggle(descrYes = s"Whether to directly print all output of the underlying tools to the terminal. Otherwise the output will be written to files in $LOG_DIR") addSubcommand(new LongnailCommand) addSubcommand(new TreenailCommand) addSubcommand(new LongnailMergeCommand) diff --git a/toolflow/src/main/scala/com/minres/tgc/hammer/tasks/Task.scala b/toolflow/src/main/scala/com/minres/tgc/hammer/tasks/Task.scala index 49ee796..adb0a47 100644 --- a/toolflow/src/main/scala/com/minres/tgc/hammer/tasks/Task.scala +++ b/toolflow/src/main/scala/com/minres/tgc/hammer/tasks/Task.scala @@ -1,5 +1,6 @@ package com.minres.tgc.hammer.tasks +import com.minres.tgc.hammer.Main import com.minres.tgc.hammer.util.Logging import os.{Path, Shellable} @@ -17,10 +18,14 @@ trait Task { trait TaskImpl[T <: Task : ClassTag] extends Task with Logging[T] { - def runExecutable(execPath: Path, args: Shellable*): os.CommandResult = { + def runExecutable(execPath: Path, args: Shellable*)(logFile: os.Path): os.CommandResult = { val command = s"$execPath ${args.flatMap(_.value).mkString(" ")}" log.info(s"Running external program: ") log.info(command) - os.proc("bash", "-c", command).call(stdout = os.Inherit) + val output: os.ProcessOutput = if (Main.conf.printToolOutput()) + os.Inherit + else + logFile + os.proc("bash", "-c", command).call(stdout = output) } } diff --git a/toolflow/src/main/scala/com/minres/tgc/hammer/tasks/TreenailTask.scala b/toolflow/src/main/scala/com/minres/tgc/hammer/tasks/TreenailTask.scala index 688c1a9..3843735 100644 --- a/toolflow/src/main/scala/com/minres/tgc/hammer/tasks/TreenailTask.scala +++ b/toolflow/src/main/scala/com/minres/tgc/hammer/tasks/TreenailTask.scala @@ -1,17 +1,17 @@ package com.minres.tgc.hammer.tasks -import com.minres.tgc.hammer.Global +import com.minres.tgc.hammer.Global.* import com.minres.tgc.hammer.util.FileUtils.* import os.* case class TreenailTask(coreDSLInput: Path, output: Path) extends TaskImpl[TreenailTask] { - private val EXECUTABLE = Global.TREENAIL / "app" / "build" / "install" / "app" / "bin" / "app" + private val EXECUTABLE = TREENAIL / "app" / "build" / "install" / "app" / "bin" / "app" override def validate(): Unit = { assert(isFile(EXECUTABLE), "Treenail Executable is missing, build Treenail") assert(isCoreDSLFile(coreDSLInput), "Input file does not exist") } override def execute(): Unit = { - runExecutable(EXECUTABLE, "-o", output, coreDSLInput) + runExecutable(EXECUTABLE, "-o", output, coreDSLInput)(LOG_DIR / "treenail.log") } } diff --git a/toolflow/src/main/scala/com/minres/tgc/hammer/tasks/longnail/LongnailHLSTask.scala b/toolflow/src/main/scala/com/minres/tgc/hammer/tasks/longnail/LongnailHLSTask.scala index cdc5355..0e51f4c 100644 --- a/toolflow/src/main/scala/com/minres/tgc/hammer/tasks/longnail/LongnailHLSTask.scala +++ b/toolflow/src/main/scala/com/minres/tgc/hammer/tasks/longnail/LongnailHLSTask.scala @@ -1,5 +1,6 @@ package com.minres.tgc.hammer.tasks.longnail +import com.minres.tgc.hammer.Global.LOG_DIR import com.minres.tgc.hammer.util.FileUtils.* import os.* @@ -27,6 +28,6 @@ class LongnailHLSTask(schedulingSolutionFile: Path, schedulingSelectionFile: Opt "--hw-legalize-modules", s"--export-split-verilog=dir-name=$outDirectory", schedulingSolutionFile - ) + )(LOG_DIR / "longnail_hls.log") } } diff --git a/toolflow/src/main/scala/com/minres/tgc/hammer/tasks/longnail/LongnailMergeTask.scala b/toolflow/src/main/scala/com/minres/tgc/hammer/tasks/longnail/LongnailMergeTask.scala index 22c3887..dc4f5a5 100644 --- a/toolflow/src/main/scala/com/minres/tgc/hammer/tasks/longnail/LongnailMergeTask.scala +++ b/toolflow/src/main/scala/com/minres/tgc/hammer/tasks/longnail/LongnailMergeTask.scala @@ -1,5 +1,6 @@ package com.minres.tgc.hammer.tasks.longnail +import com.minres.tgc.hammer.Global.LOG_DIR import com.minres.tgc.hammer.util.FileUtils.* import os.* @@ -17,6 +18,6 @@ class LongnailMergeTask(mlirFiles: Seq[Path], concatMLIR: Path, mergedMLIR: Path runExecutable(EXECUTABLE, "--merge-multiple-isaxes", concatMLIR, "-o", mergedMLIR - ) + )(LOG_DIR / "longnail_merge.log") } } diff --git a/toolflow/src/main/scala/com/minres/tgc/hammer/tasks/longnail/LongnailScheduleTask.scala b/toolflow/src/main/scala/com/minres/tgc/hammer/tasks/longnail/LongnailScheduleTask.scala index eee382d..bf2ea76 100644 --- a/toolflow/src/main/scala/com/minres/tgc/hammer/tasks/longnail/LongnailScheduleTask.scala +++ b/toolflow/src/main/scala/com/minres/tgc/hammer/tasks/longnail/LongnailScheduleTask.scala @@ -1,5 +1,6 @@ package com.minres.tgc.hammer.tasks.longnail +import com.minres.tgc.hammer.Global.LOG_DIR import com.minres.tgc.hammer.tasks.longnail.LongnailBaseTask import com.minres.tgc.hammer.util.FileUtils.isMLIRFile import os.* @@ -17,7 +18,7 @@ class LongnailScheduleTask(isaxMLIR: Path, coreDatasheet: Path, params: Scheduli "--lower-coredsl-to-lil", params.getToolParameters, isaxMLIR - ) + )(LOG_DIR / "longnail_schedule.log") } }