Commit 8456f370 authored by Kunshan Wang's avatar Kunshan Wang

WIP: bootimg builder

parent 0e04bfb8
package uvm.refimpl.bootimg
import uvm.refimpl._
import scala.collection.mutable.HashSet
import uvm._
import uvm.types._
import uvm.ssavariables._
class TransitiveClosure(initialSet: Seq[Int]) {
val set = Set[Int](initialSet: _*)
import uvm.refimpl._
import uvm.refimpl.mem.TypeSizes.Word
}
import scala.collection.mutable.Queue
class BootImageBuilder(implicit microVM: MicroVM) {
def makeBootImage(whiteList: Seq[Int], outputFile: String): Unit = {
implicit val tc = new TransitiveClosure(whiteList)
doTypeSigClosure()
tc.doTransitiveClosure()
}
}
object TransitiveClosure {
abstract class Item
case class TopLevel(id: Int) extends Item
case class HeapObj(ref: Word) extends Item
}
class TransitiveClosure(initialSet: Seq[Int])(
implicit microVM: MicroVM) {
import TransitiveClosure._
private val initialItems = initialSet.map(TopLevel)
val set = Set[Item](initialItems: _*)
val queue = Queue[Item](initialItems: _*)
val idVisisted = Set[Int](initialSet: _*)
val objVisited = Set[Word]()
def doTransitiveClosure(): Unit = {
while (!queue.isEmpty) {
val item = queue.dequeue()
if (set contains item) {
// continue
} else {
visitItem(item)
}
}
}
private def visitItem(item: Item): Unit = item match {
case TopLevel(id) => visitTopLevel(id)
case HeapObj(ref) => visitHeapObj(ref)
}
private def visitTopLevel(id: Int): Unit = {
val thing = microVM.globalBundle.allNs(id)
thing match {
case t: Type => visitType(t)
case s: FuncSig => visitFuncSig(s)
case c: Constant => visitConstant(c)
case g: GlobalCell => visitGlobalCell(g)
case f: Function => visitFunction(f)
case e: ExposedFunc => visitExpFunc(e)
}
}
private def visitType(ty: Type): Unit = {
???
}
private def visitFuncSig(s: FuncSig): Unit = {
???
}
private def visitConstant(c: Constant): Unit = {
???
}
private def visitGlobalCell(g: GlobalCell): Unit = {
???
}
private def visitFunction(f: Function): Unit = {
???
}
private def visitExpFunc(e: ExposedFunc): Unit = {
???
}
def doTypeSigClosure()(implicit tc: TransitiveClosure): Unit = {
private def visitInstruction(i: Instruction): Unit = {
???
}
private def visitHeapObj(ref: Word): Unit = {
???
}
}
\ No newline at end of file
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