Commit 93d81f64 authored by Kunshan Wang's avatar Kunshan Wang

Fixed example programs to use get_inst_res

parent 73e6de36
......@@ -98,13 +98,13 @@ int main(int argc, char** argv) {
// convert the string pointer to void*
MuInstNode ptrcast = ctx->new_conv(ctx, entry, MU_CONV_PTRCAST,
ppi8, pvoid, const_ptr_hw_string);
MuInstResNode ptrcast_r = ctx->new_inst_res(ctx, ptrcast);
MuInstResNode ptrcast_r = ctx->get_inst_res(ctx, ptrcast, 0);
// call the write function
MuVarNode write_args[] = { const_i32_1, ptrcast_r, const_i64_hwsz };
MuInstNode write = ctx->new_ccall(ctx, entry, MU_CC_DEFAULT,
write_fp, write_sig, const_fp_write, write_args, 3);
MuInstResNode write_r0 = ctx->new_inst_res(ctx, write);
MuInstResNode write_r0 = ctx->get_inst_res(ctx, write, 0);
// return 0
MuConstNode const_i32_0 = ctx->new_const_int(ctx, b, i32, 0L);
......
......@@ -18,7 +18,10 @@ libc.write.restype = ctypes.c_ssize_t
libc.write.argtypes = [ctypes.c_int, ctypes.c_void_p, ctypes.c_size_t]
dll = MuRefImpl2StartDLL("../cbinding/libmurefimpl2start.so")
mu = dll.mu_refimpl2_new()
mu = dll.mu_refimpl2_new_ex(
#vmLog="DEBUG"
#vmLog="INFO"
)
with mu.new_context() as ctx:
# frequently used function
......@@ -39,6 +42,7 @@ with mu.new_context() as ctx:
# Prepare args.
## new string array
nargs = len(sys.argv)
print("nargs = ", nargs)
hnargs = ctx.handle_from_int(nargs, 64)
args = ctx.new_hybrid(id_of("@array_ref_string"), hnargs)
......
......@@ -36,6 +36,9 @@
%argsv_ir = GETVARPARTIREF <@array_ref_string> %args_ir
%len = LOAD <@i64> %argsf0_ir
//%len32 = TRUNC <@i64 @i32> %len
//RET %len32
BRANCH %head(%argsv_ir @I64_0 %len)
%head(<@iref_ref_string> %argsv_ir <@i64> %i <@i64> %len):
......@@ -43,7 +46,7 @@
BRANCH2 %lt %body(%argsv_ir %i %len) %exit()
%body(<@iref_ref_string> %argsv_ir <@i64> %i <@i64> %len):
%elem_ir = SHIFTIREF <@iref_ref_string @i64> %argsv_ir %i
%elem_ir = SHIFTIREF <@ref_string @i64> %argsv_ir %i
%str_r = LOAD <@ref_string> %elem_ir
CALL <@puts.sig> @puts (%str_r)
%i2 = ADD <@i64> %i @I64_1
......
......@@ -410,6 +410,8 @@ trait InstructionExecutor extends InterpreterActions with CommInstExecutor {
case i @ InstShiftIRef(ptr, referentTy, offTy, opnd, offset) => {
val off = offset.getSInt(offTy.length).longValue
val addrIncr = TypeSizes.shiftOffsetOf(referentTy, off)
logger.trace("SHIFTIREF(0x%x by 0x%x)".format(opnd.asIRefLoc, addrIncr))
incrementBoxIRefOrPointer(ptr, opnd, results(0), addrIncr)
continueNormally()
......
......@@ -43,7 +43,7 @@ class InterpreterThread(val id: Int, initialStack: InterpreterStack, initialThre
override def curThread = this
// Initialisation
threadLocal.asRef = initialThreadLocal
htr match {
......@@ -73,7 +73,7 @@ trait InterpreterThreadState {
/** Object-pinnning multiset. */
val pinSet = new ArrayBuffer[Word]
/** Thread-local object reference. */
val threadLocal = BoxRef(0L)
......@@ -341,11 +341,11 @@ trait InterpreterActions extends InterpreterThreadState {
if (ptr) {
dst.asPtr = src.asPtr + addrIncr
} else {
val (sb,so) = src.asIRef
val (sb, so) = src.asIRef
if (sb == 0L && so == 0L) {
throw new UvmUndefinedBehaviorException(ctx + "Attempted to execute memory addressing instruction on a NULL iref.")
}
dst.asIRef = (sb, so + addrIncr)
dst.asIRef = (sb, so + addrIncr)
}
}
......@@ -514,13 +514,13 @@ object MagicalBox {
def asSeq: Seq[ValueBox] = box.asInstanceOf[BoxSeq].values
def asRef: Word = box.asInstanceOf[BoxRef].objRef
def asIRef: (Word, Word) = box.asInstanceOf[BoxIRef].oo
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 asIRNodeWeak[T <: IRNode]: Option[T] = box.asInstanceOf[BoxIRNode].node.asInstanceOf[Option[T]]
def asIntRaw_=(v: BigInt): Unit = box.asInstanceOf[BoxInt].value = v
def asInt1_=(v: BigInt): Unit = box.setInt(v, 1)
......@@ -543,11 +543,16 @@ object MagicalBox {
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 asIRNodeWeak_=[T <: IRNode](v: Option[T]): Unit = box.asInstanceOf[BoxIRNode].node = 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