First toolflow version

This commit is contained in:
2025-09-30 18:20:38 +02:00
parent b1bbd48d19
commit 2d48221e45
15 changed files with 305 additions and 0 deletions

View File

@@ -0,0 +1,10 @@
package com.minres.tgc.hammer
import os.Path
object Global {
def pathFromEnv(env: String): Option[Path] = sys.env.get("string").map { rawPath => Path(rawPath, os.pwd) }
lazy val HAMMER: Path = pathFromEnv("TGC_HAMMER_HOME").get
lazy val WORKDIR: Path = pathFromEnv("TGC_HAMMER_WORKDIR").get
lazy val TREENAIL: Path = HAMMER / "deps" / "treenail"
}

View File

@@ -0,0 +1,17 @@
package com.minres.tgc.hammer
import com.minres.tgc.hammer.cli.{HammerConf, MySubcommand}
object Main {
def main(args: Array[String]): Unit = {
val conf = new HammerConf(args.toIndexedSeq)
conf.subcommand match {
case Some(c: MySubcommand) =>
val tasks = c.getRequiredTasks
tasks.foreach(_.validate())
tasks.foreach(_.execute())
case _ =>
}
}
}

View File

@@ -0,0 +1,9 @@
package com.minres.tgc.hammer.cli
import org.rogach.scallop.ScallopConf
class HammerConf(arguments: Seq[String]) extends ScallopConf(arguments) {
addSubcommand(new TreenailCommand)
verify()
}

View File

@@ -0,0 +1,8 @@
package com.minres.tgc.hammer.cli
import com.minres.tgc.hammer.tasks.Task
import org.rogach.scallop.Subcommand
abstract class MySubcommand(name: String) extends Subcommand(name) {
def getRequiredTasks: Seq[Task]
}

View File

@@ -0,0 +1,19 @@
package com.minres.tgc.hammer.cli
import com.minres.tgc.hammer.tasks.{Task, TreenailTask}
import org.rogach.scallop.*
import java.io.File
import os.Path
class TreenailCommand extends MySubcommand("parseCoreDSL") {
val coreDSL: ScallopOption[File] = trailArg[File]("coreDSL")
val output: ScallopOption[File] = opt[File](short = 'o', default = Some(new File("isax.mlir")))
validateFileExists(coreDSL)
validateFileIsFile(coreDSL)
override def getRequiredTasks: Seq[Task] = Seq(
new TreenailTask(Path(coreDSL(), os.pwd), Path(output(), os.pwd))
)
}

View File

@@ -0,0 +1,12 @@
package com.minres.tgc.hammer.tasks
import os.{Path, Shellable}
trait Task {
def validate(): Unit
def execute(): Unit
def runExecutable(execPath: Path, args: Shellable*): os.CommandResult = {
os.proc(execPath, args).call()
}
}

View File

@@ -0,0 +1,16 @@
package com.minres.tgc.hammer.tasks
import com.minres.tgc.hammer.Global
import os.*
class TreenailTask(coreDSLInput: Path, output: Path) extends Task {
private val EXECUTABLE = Global.TREENAIL / "app" / "build" / "install" / "app" / "bin" / "app"
override def validate(): Unit = {
assert(isFile(EXECUTABLE), "Treenail Executable is missing, build Treenail")
}
override def execute(): Unit = {
runExecutable(EXECUTABLE, "-o", output, coreDSLInput)
}
}

View File

@@ -0,0 +1,9 @@
// For more information on writing tests, see
// https://scalameta.org/munit/docs/getting-started.html
class MySuite extends munit.FunSuite {
test("example test that succeeds") {
val obtained = 42
val expected = 42
assertEquals(obtained, expected)
}
}