Commit 67b84bed authored by Jens Korinth's avatar Jens Korinth
Browse files

Implemented base module builder

* ModuleBuilder generalizes the building of modules:
  user needs only supply list of CoreDefinitions to build
* provides main() to run automatically
* CoreDefinition: additional constructor to automatically
  supply root dir in ip/<name> subdir
parent a95601dd
......@@ -21,6 +21,15 @@ case class CoreDefinition(name: String, vendor: String, library: String, version
* Contains methods for reading a core definition from Json.
**/
object CoreDefinition {
/** Alternative constructor: supplies root dir as ip/<name>. **/
def apply(name: String, vendor: String, library: String, version: String) = CoreDefinition(
name,
vendor,
library,
version,
java.nio.file.Paths.get(".").toAbsolutePath.resolveSibling("ip").resolve(name).toString
)
implicit val coreDefinitionWrites : Writes[CoreDefinition] = (
(JsPath \ "name").write[String] ~
(JsPath \ "vendor").write[String] ~
......@@ -37,6 +46,10 @@ object CoreDefinition {
(JsPath \ "root").read[String]
)(CoreDefinition.apply _)
/**
* Read CoreDefinition from file containing Json format.
* @param filename Name (and path) of file.
**/
def read(filename: String) : Option[CoreDefinition] = try {
val contents = Source.fromFile(filename).getLines.mkString("\n")
val json = Json.parse(contents)
......
package chisel.packaging
import Chisel._
import scala.sys.process._
/**
* Abstract IP-XACT builder class:
* Objects can inherit from ModuleBuilder to automate the building
* and packaging process. Provides main method that can be run
* automatically via sbt run, takes arguments which cores to build.
* @param packagingDir Base directory of packaging submodule
* (default: ./packaging)
**/
abstract class ModuleBuilder(packagingDir: String = "packaging") {
val chiselArgs = Array("--backend", "v", "--compile")
val modules: List[(() => Module, CoreDefinition)]
def main(args: Array[String]) {
modules foreach { m =>
chiselMain(chiselArgs ++ Array("--targetDir", m._2.root), m._1)
val json = "%s/%s.json".format(m._2.root, m._2.name)
m._2.write(json)
"%s/package.py %s".format(packagingDir, json) !
}
}
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment