Commit 1595a0e6 authored by Kunshan Wang's avatar Kunshan Wang

WIP: refactoring

parent abf3d0a3
......@@ -58,7 +58,7 @@ typedef void *MuValue; // Any Mu value
// Abstract value type.
typedef MuValue MuSeqValue; // array or vector
typedef MuValue MuGenRefValue; // ref, iref, funcref, threadref, stackref, framecursorref, irnoderef
typedef MuValue MuGenRefValue; // ref, iref, funcref, threadref, stackref, framecursorref, irbuilderref
// concrete value types
typedef MuValue MuIntValue; // int<n>
......@@ -516,6 +516,7 @@ struct MuIRBuilder {
void (*new_type_threadref )(MuIRBuilder *b, MuID id);
void (*new_type_stackref )(MuIRBuilder *b, MuID id);
void (*new_type_framecursorref)(MuIRBuilder *b, MuID id);
void (*new_type_irbuilderref )(MuIRBuilder *b, MuID id);
// Create function signatures
void (*new_funcsig)(MuIRBuilder *b, MuID id,
......@@ -775,6 +776,7 @@ struct MuIRBuilder {
#define MU_CI_UVM_META_ENABLE_WATCHPOINT ((MuCommInst)0x25e) /// MUAPIPARSER muname:@uvm.meta.enable_watchpoint
#define MU_CI_UVM_META_DISABLE_WATCHPOINT ((MuCommInst)0x25f) /// MUAPIPARSER muname:@uvm.meta.disable_watchpoint
#define MU_CI_UVM_META_SET_TRAP_HANDLER ((MuCommInst)0x260) /// MUAPIPARSER muname:@uvm.meta.set_trap_handler
#define MU_CI_UVM_IRBUILDER_NEW_IR_BUILDER ((MuCommInst)0x270) /// MUAPIPARSER muname:@uvm.irbuilder.new_ir_builder
#define MU_CI_UVM_IRBUILDER_LOAD ((MuCommInst)0x300) /// MUAPIPARSER muname:@uvm.irbuilder.load
#define MU_CI_UVM_IRBUILDER_ABORT ((MuCommInst)0x301) /// MUAPIPARSER muname:@uvm.irbuilder.abort
#define MU_CI_UVM_IRBUILDER_GEN_SYM ((MuCommInst)0x302) /// MUAPIPARSER muname:@uvm.irbuilder.gen_sym
......
......@@ -60,7 +60,7 @@ abstract class AbstractBundleSerializer(bundle: Bundle) {
case TypeThreadRef() => "threadref"
case TypeStackRef() => "stackref"
case TypeFrameCursorRef() => "framecursorref"
case TypeIRNodeRef() => "irnoderef"
case TypeIRBuilderRef() => "irbuilderref"
case _ => throw new BundleSerializerException("unknown type " + ty.getClass.getName)
}
output.append(s".typedef ${ty.n} = ${ctor}\n")
......
......@@ -46,7 +46,7 @@ object InternalTypes {
val STACKREF = TypeStackRef() := internal("stackref")
val THREADREF = TypeThreadRef() := internal("threadref")
val FRAMECURSORREF = TypeFrameCursorRef() := internal("framecursorref")
val IRNODEREF = TypeIRNodeRef() := internal("irnoderef")
val IRBUILDERREF = TypeIRBuilderRef() := internal("irbuilderref")
val TAGREF64 = TypeTagRef64() := internal("tagref64")
val BYTES = TypeHybrid(Seq(I64), I8) := (0x260, "@uvm.meta.bytes")
......@@ -198,97 +198,6 @@ object TypeInferer {
case "@uvm.meta.set_trap_handler" => Seq()
/// GEN:BEGIN:IRBUILDER_RETVALS
case "@uvm.irbuilder.new_bundle" => Seq(IRNODEREF)
case "@uvm.irbuilder.load_bundle_from_node" => Seq()
case "@uvm.irbuilder.abort_bundle_node" => Seq()
case "@uvm.irbuilder.get_node" => Seq(IRNODEREF)
case "@uvm.irbuilder.get_id" => Seq(I32)
case "@uvm.irbuilder.set_name" => Seq()
case "@uvm.irbuilder.new_type_int" => Seq(IRNODEREF)
case "@uvm.irbuilder.new_type_float" => Seq(IRNODEREF)
case "@uvm.irbuilder.new_type_double" => Seq(IRNODEREF)
case "@uvm.irbuilder.new_type_uptr" => Seq(IRNODEREF)
case "@uvm.irbuilder.set_type_uptr" => Seq()
case "@uvm.irbuilder.new_type_ufuncptr" => Seq(IRNODEREF)
case "@uvm.irbuilder.set_type_ufuncptr" => Seq()
case "@uvm.irbuilder.new_type_struct" => Seq(IRNODEREF)
case "@uvm.irbuilder.new_type_hybrid" => Seq(IRNODEREF)
case "@uvm.irbuilder.new_type_array" => Seq(IRNODEREF)
case "@uvm.irbuilder.new_type_vector" => Seq(IRNODEREF)
case "@uvm.irbuilder.new_type_void" => Seq(IRNODEREF)
case "@uvm.irbuilder.new_type_ref" => Seq(IRNODEREF)
case "@uvm.irbuilder.set_type_ref" => Seq()
case "@uvm.irbuilder.new_type_iref" => Seq(IRNODEREF)
case "@uvm.irbuilder.set_type_iref" => Seq()
case "@uvm.irbuilder.new_type_weakref" => Seq(IRNODEREF)
case "@uvm.irbuilder.set_type_weakref" => Seq()
case "@uvm.irbuilder.new_type_funcref" => Seq(IRNODEREF)
case "@uvm.irbuilder.set_type_funcref" => Seq()
case "@uvm.irbuilder.new_type_tagref64" => Seq(IRNODEREF)
case "@uvm.irbuilder.new_type_threadref" => Seq(IRNODEREF)
case "@uvm.irbuilder.new_type_stackref" => Seq(IRNODEREF)
case "@uvm.irbuilder.new_type_framecursorref" => Seq(IRNODEREF)
case "@uvm.irbuilder.new_type_irnoderef" => Seq(IRNODEREF)
case "@uvm.irbuilder.new_funcsig" => Seq(IRNODEREF)
case "@uvm.irbuilder.new_const_int" => Seq(IRNODEREF)
case "@uvm.irbuilder.new_const_int_ex" => Seq(IRNODEREF)
case "@uvm.irbuilder.new_const_float" => Seq(IRNODEREF)
case "@uvm.irbuilder.new_const_double" => Seq(IRNODEREF)
case "@uvm.irbuilder.new_const_null" => Seq(IRNODEREF)
case "@uvm.irbuilder.new_const_seq" => Seq(IRNODEREF)
case "@uvm.irbuilder.new_const_extern" => Seq(IRNODEREF)
case "@uvm.irbuilder.new_global_cell" => Seq(IRNODEREF)
case "@uvm.irbuilder.new_func" => Seq(IRNODEREF)
case "@uvm.irbuilder.new_func_ver" => Seq(IRNODEREF)
case "@uvm.irbuilder.new_exp_func" => Seq(IRNODEREF)
case "@uvm.irbuilder.new_bb" => Seq(IRNODEREF)
case "@uvm.irbuilder.new_nor_param" => Seq(IRNODEREF)
case "@uvm.irbuilder.new_exc_param" => Seq(IRNODEREF)
case "@uvm.irbuilder.get_inst_res" => Seq(IRNODEREF)
case "@uvm.irbuilder.get_num_inst_res" => Seq(I32)
case "@uvm.irbuilder.add_dest" => Seq()
case "@uvm.irbuilder.add_keepalives" => Seq()
case "@uvm.irbuilder.new_binop" => Seq(IRNODEREF)
case "@uvm.irbuilder.new_cmp" => Seq(IRNODEREF)
case "@uvm.irbuilder.new_conv" => Seq(IRNODEREF)
case "@uvm.irbuilder.new_select" => Seq(IRNODEREF)
case "@uvm.irbuilder.new_branch" => Seq(IRNODEREF)
case "@uvm.irbuilder.new_branch2" => Seq(IRNODEREF)
case "@uvm.irbuilder.new_switch" => Seq(IRNODEREF)
case "@uvm.irbuilder.add_switch_dest" => Seq()
case "@uvm.irbuilder.new_call" => Seq(IRNODEREF)
case "@uvm.irbuilder.new_tailcall" => Seq(IRNODEREF)
case "@uvm.irbuilder.new_ret" => Seq(IRNODEREF)
case "@uvm.irbuilder.new_throw" => Seq(IRNODEREF)
case "@uvm.irbuilder.new_extractvalue" => Seq(IRNODEREF)
case "@uvm.irbuilder.new_insertvalue" => Seq(IRNODEREF)
case "@uvm.irbuilder.new_extractelement" => Seq(IRNODEREF)
case "@uvm.irbuilder.new_insertelement" => Seq(IRNODEREF)
case "@uvm.irbuilder.new_shufflevector" => Seq(IRNODEREF)
case "@uvm.irbuilder.new_new" => Seq(IRNODEREF)
case "@uvm.irbuilder.new_newhybrid" => Seq(IRNODEREF)
case "@uvm.irbuilder.new_alloca" => Seq(IRNODEREF)
case "@uvm.irbuilder.new_allocahybrid" => Seq(IRNODEREF)
case "@uvm.irbuilder.new_getiref" => Seq(IRNODEREF)
case "@uvm.irbuilder.new_getfieldiref" => Seq(IRNODEREF)
case "@uvm.irbuilder.new_getelemiref" => Seq(IRNODEREF)
case "@uvm.irbuilder.new_shiftiref" => Seq(IRNODEREF)
case "@uvm.irbuilder.new_getvarpartiref" => Seq(IRNODEREF)
case "@uvm.irbuilder.new_load" => Seq(IRNODEREF)
case "@uvm.irbuilder.new_store" => Seq(IRNODEREF)
case "@uvm.irbuilder.new_cmpxchg" => Seq(IRNODEREF)
case "@uvm.irbuilder.new_atomicrmw" => Seq(IRNODEREF)
case "@uvm.irbuilder.new_fence" => Seq(IRNODEREF)
case "@uvm.irbuilder.new_trap" => Seq(IRNODEREF)
case "@uvm.irbuilder.new_watchpoint" => Seq(IRNODEREF)
case "@uvm.irbuilder.new_wpbranch" => Seq(IRNODEREF)
case "@uvm.irbuilder.new_ccall" => Seq(IRNODEREF)
case "@uvm.irbuilder.new_newthread" => Seq(IRNODEREF)
case "@uvm.irbuilder.new_swapstack_ret" => Seq(IRNODEREF)
case "@uvm.irbuilder.new_swapstack_kill" => Seq(IRNODEREF)
case "@uvm.irbuilder.set_newstack_pass_values" => Seq()
case "@uvm.irbuilder.set_newstack_throw_exc" => Seq()
case "@uvm.irbuilder.new_comminst" => Seq(IRNODEREF)
/// GEN:END:IRBUILDER_RETVALS
}
}
......
......@@ -79,23 +79,14 @@ trait IRBuilderCommInstExecutor extends InterpreterActions with ObjectPinner {
assert(ci.name.get.startsWith("@uvm.irbuilder"))
ci.name.get match {
case "@uvm.irbuilder.load_bundle_from_node" => {
val _param0 = argList(0).asIRNodeWeak.get.asInstanceOf[TB]
microVM.addBundle(_param0)
case "@uvm.irbuilder.load" => {
val _param0 = argList(0).asIRBuilder.get
_param0.load()
continueNormally()
}
case "@uvm.irbuilder.abort_bundle_node" => {
// no-op
continueNormally()
}
case "@uvm.irbuilder.new_const_int_ex" => {
val b = argList(0).asIRNode.getOrElse(throw new UvmNullGenRefException("CommInst arg %b must not be null")).asInstanceOf[TB]
val ty = argList(1).asIRNodeWeak.getOrElse(throw new UvmNullGenRefException("CommInst arg %ty must not be null"))
val values = argList(2).asIRef
val nvalues = argList(3).asInt64.toLong
val _ary_values = loadInt64Array(values, nvalues)
val _value_big = unsignedLongSeqToBigInt(_ary_values)
val _rv = irBuilder.newConstInt(b, ty, _value_big)
case "@uvm.irbuilder.abort" => {
val _param0 = argList(0).asIRBuilder.get
_param0.abort()
continueNormally()
}
......
......@@ -13,6 +13,9 @@ import uvm.refimpl.mem.TypeSizes.Word
import uvm.ssavariables._
import uvm.types._
import uvm.refimpl.nat.NativeCallResult
import uvm.refimpl.itpr.BoxIRBuilder
import uvm.ir.irbuilder.IRBuilder
import uvm.refimpl.itpr.BoxIRBuilder
object InterpreterThread {
val logger = Logger(LoggerFactory.getLogger(getClass.getName))
......@@ -517,10 +520,10 @@ object MagicalBox {
def asIRefLoc: Word = box.asInstanceOf[BoxIRef].addr
def asTR64Raw: Long = box.asInstanceOf[BoxTagRef64].raw
def asFunc: Option[Function] = box.asInstanceOf[BoxFunc].func
def asThread: Option[InterpreterThread] = box.asInstanceOf[BoxThread].thread
def asStack: Option[InterpreterStack] = box.asInstanceOf[BoxStack].stack
def asFrameCursor: Option[FrameCursor] = box.asInstanceOf[BoxFrameCursor].cursor
def asIRNode: Option[IRNode] = box.asInstanceOf[BoxIRNode].node
def asThread: Option[InterpreterThread] = box.asInstanceOf[BoxThread].obj
def asStack: Option[InterpreterStack] = box.asInstanceOf[BoxStack].obj
def asFrameCursor: Option[FrameCursor] = box.asInstanceOf[BoxFrameCursor].obj
def asIRBuilder: Option[IRBuilder] = box.asInstanceOf[BoxIRBuilder].obj
def asIntRaw_=(v: BigInt): Unit = box.asInstanceOf[BoxInt].value = v
def asInt1_=(v: BigInt): Unit = box.setInt(v, 1)
......@@ -538,21 +541,14 @@ object MagicalBox {
def asRef_=(v: Word): Unit = box.asInstanceOf[BoxRef].objRef = v
def asIRef_=(oo: (Word, Word)): Unit = box.asInstanceOf[BoxIRef].oo = oo
def asTR64Raw_=(v: Long): Unit = box.asInstanceOf[BoxTagRef64].raw = v
def asFunc_=(v: Option[Function]): Unit = box.asInstanceOf[BoxFunc].func = v
def asThread_=(v: Option[InterpreterThread]): Unit = box.asInstanceOf[BoxThread].thread = v
def asStack_=(v: Option[InterpreterStack]): Unit = box.asInstanceOf[BoxStack].stack = v
def asFrameCursor_=(v: Option[FrameCursor]): Unit = box.asInstanceOf[BoxFrameCursor].cursor = v
def asIRNode_=(v: Option[IRNode]): Unit = box.asInstanceOf[BoxIRNode].node = v
def asFunc_=(v: Option[Function]): Unit = box.asInstanceOf[BoxFunc].obj = v
def asThread_=(v: Option[InterpreterThread]): Unit = box.asInstanceOf[BoxThread].obj = v
def asStack_=(v: Option[InterpreterStack]): Unit = box.asInstanceOf[BoxStack].obj = v
def asFrameCursor_=(v: Option[FrameCursor]): Unit = box.asInstanceOf[BoxFrameCursor].obj = v
def asIRBuilder_=(v: Option[IRBuilder]): Unit = box.asInstanceOf[BoxIRBuilder].obj = v
def getSInt(len: Int): BigInt = OpHelper.prepareSigned(box.asIntRaw, len)
def getUInt(len: Int): BigInt = OpHelper.prepareUnsigned(box.asIntRaw, len)
def setInt(v: BigInt, len: Int): Unit = box.asIntRaw = OpHelper.unprepare(v, len)
// Used by the auto-generated IR builder bindings. The Mu type irnodeiref is weakly typed. It is usable for all
// subtypes of uvm.IRNode, and the user is responsible to use it the right way. Inside the micro VM, we just cast
// them automatically between the strongly and weakly typed worlds.
def asIRNodeWeak[T <: IRNode]: Option[T] = box.asInstanceOf[BoxIRNode].node.asInstanceOf[Option[T]]
def asIRNodeWeak_=[T <: IRNode](v: Option[T]): Unit = box.asInstanceOf[BoxIRNode].node = v
}
}
\ 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