Skip to content
This repository has been archived by the owner on Jun 16, 2024. It is now read-only.

Commit

Permalink
ChryseApp: add custom subcommands.
Browse files Browse the repository at this point in the history
  • Loading branch information
kivikakk committed May 26, 2024
1 parent 484d8fc commit d5d4c4e
Showing 1 changed file with 16 additions and 2 deletions.
18 changes: 16 additions & 2 deletions src/main/scala/ee/hrzn/chryse/ChryseApp.scala
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@ abstract class ChryseApp {
val name: String
def genTop()(implicit platform: Platform): Module
val targetPlatforms: Seq[PlatformBoard[_ <: PlatformBoardResources]]
val cxxrtlOptions: Option[CXXRTLOptions] = None
val cxxrtlOptions: Option[CXXRTLOptions] = None
val additionalSubcommands: Seq[ChryseSubcommand] = Seq()

def main(args: Array[String]): Unit = {
val appVersion = getClass().getPackage().getImplementationVersion()
Expand Down Expand Up @@ -80,6 +81,9 @@ abstract class ChryseApp {
)
}
if (cxxrtlOptions.isDefined) addSubcommand(cxxsim)

for { sc <- additionalSubcommands }
addSubcommand(sc)
}
Conf.verify()

Expand Down Expand Up @@ -111,7 +115,12 @@ abstract class ChryseApp {
)
case None =>
Conf.printHelp()
case _ =>
case Some(chosen) =>
for { sc <- additionalSubcommands }
if (sc == chosen) {
sc.execute()
return
}
throw new Exception("unhandled subcommand")
}
}
Expand All @@ -123,3 +132,8 @@ object ChryseApp {

class ChryseAppStepFailureException(step: String)
extends Exception(s"Chryse step failed: $step") {}

abstract class ChryseSubcommand(commandNameAndAliases: String*)
extends Subcommand(commandNameAndAliases: _*) {
def execute(): Unit
}

0 comments on commit d5d4c4e

Please sign in to comment.