-
Notifications
You must be signed in to change notification settings - Fork 249
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
c291b9c
commit 17e2683
Showing
3 changed files
with
76 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
import mainargs.{ParserForMethods, main} | ||
|
||
import scala.collection.mutable | ||
|
||
object NodeRegistry { | ||
val allNodes: mutable.Set[IR] = mutable.Set.empty[IR] | ||
} | ||
|
||
sealed abstract class AttOrChild { | ||
val name: String | ||
def generateDeclaration: String | ||
} | ||
|
||
final case class Att(name: String, typ: String) extends AttOrChild { | ||
override def generateDeclaration: String = s"$name: $typ" | ||
} | ||
|
||
final case class Child(name: String) extends AttOrChild { | ||
override def generateDeclaration: String = s"$name: IR" | ||
} | ||
|
||
sealed abstract class IR(implicit val name: sourcecode.Name) { | ||
NodeRegistry.allNodes += this | ||
|
||
val attsAndChildren: Seq[AttOrChild] | ||
val isTrivial: Boolean = false | ||
|
||
def generateDef: String = | ||
(s"final case class $name(${attsAndChildren.map(_.generateDeclaration).mkString(",")}) extends IR" | ||
+ (if (isTrivial) " with TrivialIR" else "")) | ||
} | ||
|
||
object I32 extends IR { | ||
override val attsAndChildren = Seq(Att("x", "Int")) | ||
override val isTrivial = true | ||
} | ||
|
||
object I64 extends IR { | ||
override val attsAndChildren = Seq(Att("x", "Int")) | ||
override val isTrivial = true | ||
} | ||
|
||
object Main { | ||
@main | ||
def main(path: String) = { | ||
val gen = "package is.hail.expr.ir\n" + NodeRegistry.allNodes.map(_.generateDef).mkString("\n") | ||
os.write(os.Path(path) / "IR_gen.scala", gen) | ||
} | ||
|
||
def main(args: Array[String]): Unit = ParserForMethods(this).runOrExit(args) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters