Handle tool output

This commit is contained in:
2025-10-06 18:29:03 +02:00
parent 3824dd4d29
commit 7954a9dbe3
8 changed files with 20 additions and 8 deletions

View File

@@ -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"
}

View File

@@ -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 {

View File

@@ -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)

View File

@@ -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)
}
}

View File

@@ -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")
}
}

View File

@@ -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")
}
}

View File

@@ -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")
}
}

View File

@@ -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")
}
}