ModuleBuilder.scala 1.51 KB
Newer Older
Jens Korinth's avatar
Jens Korinth committed
1
package chisel.packaging
Jens Korinth's avatar
Jens Korinth committed
2
3
import  chisel3._
import  scala.sys.process._
Jens Korinth's avatar
Jens Korinth committed
4

5
6
7
8
9
10
11
/** Module definition.
 *  @param config Optional, arbitrary configuration object, passed to post build actions.
 *  @param constr Module constructor function.
 *  @param core   Core definition.
 **/
final case class ModuleDef(config: Option[Any], constr: () => Module, core: CoreDefinition)

Jens Korinth's avatar
Jens Korinth committed
12
13
14
15
16
17
18
19
20
/**
 * 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") {
Jens Korinth's avatar
Jens Korinth committed
21
  val chiselArgs = Array[String]()
22
23
  /** List of modules to build. */
  val modules: Seq[ModuleDef]
Jens Korinth's avatar
Jens Korinth committed
24
25

  def main(args: Array[String]) {
26
27
    assert ((modules map (_.core.name.toLowerCase)).toSet.size == modules.length, "module names must be unique")
    val fm = modules filter (m => args.length == 0 || args.map(_.toLowerCase).contains(m.core.name.toLowerCase))
28
29
    assert (fm.length > 0, "no matching cores found for: " + args.mkString(", "))
    fm foreach { m =>
30
31
32
33
      Driver.execute(chiselArgs ++ Array("--target-dir", m.core.root), m.constr)
      m.core.postBuildActions map (fn => fn.apply(m.config))
      val json = "%s/%s.json".format(m.core.root, m.core.name)
      m.core.write(json)
Jens Korinth's avatar
Jens Korinth committed
34
35
36
37
      "%s/package.py %s".format(packagingDir, json) !
    }
  }
}