Commit 778b9b2f authored by Kunshan Wang's avatar Kunshan Wang

IR/API stubs for boot img

parent b60e8b56
......@@ -103,9 +103,12 @@ typedef MuChildNode MuFuncVerNode; // Function version
typedef MuChildNode MuBBNode; // Basic block
typedef MuChildNode MuInstNode; // Instruction (itself, not result)
// C-style '\0'-terminated string
typedef char *MuCString;
// Identifiers and names of Mu
typedef uint32_t MuID;
typedef char *MuName;
typedef MuCString MuName;
// Convenient types for the void* type and the void(*)() type in C
typedef void *MuCPtr;
......@@ -286,11 +289,16 @@ struct MuVM {
MuName (*name_of)(MuVM *mvm, MuID id);
// Set handlers
void (*set_trap_handler )(MuVM *mvm, MuTrapHandler trap_handler, MuCPtr userdata);
void (*set_trap_handler)(MuVM *mvm, MuTrapHandler trap_handler, MuCPtr userdata);
// Proprietary API of refimpl2: Let the micro VM execute.
void (*execute)(MuVM *mvm);
// Build boot image
void (*make_boot_image)(MuVM *mvm,
MuID* whitelist, MuArraySize whitelist_sz,
MuCString output_file); /// MUAPIPARSER whitelist:array:whitelist_sz
// Proprietary API of refimpl2: Get the pointer to the internal error
// number allocate in the micro VM. It is set to non-zero whenever an
// exception is thrown when the client calls through this C API. This gives
......@@ -523,6 +531,7 @@ struct MuCtx {
MuConstNode (*new_const_null )(MuCtx *ctx, MuBundleNode b, MuTypeNode ty);
// new_const_seq works for structs, arrays and vectors. Constants are non-recursive, so there is no set_const_seq.
MuConstNode (*new_const_seq )(MuCtx *ctx, MuBundleNode b, MuTypeNode ty, MuConstNode *elems, MuArraySize nelems); /// MUAPIPARSER elems:array:nelems
MuConstNode (*new_const_extern )(MuCtx *ctx, MuBundleNode b, MuTypeNode ty, MuCString symbol);
// Create global cell
MuGlobalNode (*new_global_cell )(MuCtx *ctx, MuBundleNode b, MuTypeNode ty);
......
"""
USAGE: python3 migrate_scripts/irbuildertomuctx.py < src/main/scala/uvm/ir/irbuilder/IRBuilder.scala | xclip -selection c
USAGE: python3 migrate_scripts/irbuildertomuctx.py
And then paste the result into src/main/scala/uvm/refimpl/MuCtxIRBuilderPart.scala
Use pbcopy on Mac.
And then paste the result intoUse pbcopy on Mac.
"""
import re
import sys
import sys, os.path, io
import injecttools
from refimpl2injectablefiles import injectable_files
begin = "SCRIPT: BEGIN HERE"
end = "SCRIPT: END HERE"
......@@ -41,38 +42,46 @@ arg = re.compile(r'(\w*):\s+([a-zA-Z0-9\[\]]+)')
node_like = re.compile(r'Mu\w+Node')
node_seq_like = re.compile(r'Seq\[Mu\w+Node\]')
lines = sys.stdin.read().splitlines()
l1 = [n for (n,l) in enumerate(lines) if begin in l][0]
l2 = [n for (n,l) in enumerate(lines) if end in l][0]
_my_dir = os.path.dirname(__file__)
_refimpl2_root = os.path.join(_my_dir, "..")
irbuilder_path = os.path.join(_refimpl2_root, "src/main/scala/uvm/ir/irbuilder/IRBuilder.scala")
def main():
with open(irbuilder_path) as f:
lines = f.read()
text = "\n".join(lines[l1+1:l2])
text = injecttools.extract_lines(lines, begin, end)
for p, t in replaces:
text = p.sub(t, text)
for p, t in replaces:
text = p.sub(t, text)
#print(text)
output = io.StringIO()
#sys.exit(0)
for whole, name, arglist in sig.findall(text):
print(whole, "{", file=output)
argnames = []
for an,at in arg.findall(arglist):
argnames.append(an)
#print(an, at)
if node_seq_like.match(at) is not None:
print(' for((n,i) <- {}.zipWithIndex) require(!n.isNull, "{}[%d] must not be NULL".format(i))'.format(an, an), file=output)
elif node_like.match(at) is not None:
print(' require(!{}.isNull, "{} must not be NULL")'.format(an, an), file=output)
if name.startswith("new"):
print(' addHandle(irBuilder.{}({}))'.format(name, ", ".join(argnames)), file=output)
else:
print(' irBuilder.{}({})'.format(name, ", ".join(argnames)), file=output)
print(" }", file=output)
print(file=output)
#print(whole, name, args)
#for n,a in sig.findall(line):
#args = arg_name.findall(a)
#print(" addHandle(irBuilder.{}({}))".format(n, ", ".join(args)))
for whole, name, arglist in sig.findall(text):
print(whole, "{")
argnames = []
for an,at in arg.findall(arglist):
argnames.append(an)
#print(an, at)
if node_seq_like.match(at) is not None:
print(' for((n,i) <- {}.zipWithIndex) require(!n.isNull, "{}[%d] must not be NULL".format(i))'.format(an, an))
elif node_like.match(at) is not None:
print(' require(!{}.isNull, "{} must not be NULL")'.format(an, an))
if name.startswith("new"):
print(' addHandle(irBuilder.{}({}))'.format(name, ", ".join(argnames)))
else:
print(' irBuilder.{}({})'.format(name, ", ".join(argnames)))
print(" }")
print()
#print(whole, name, args)
#for n,a in sig.findall(line):
#args = arg_name.findall(a)
#print(" addHandle(irBuilder.{}({}))".format(n, ", ".join(args)))
injectable_files["MuCtxIRBuilderPart.scala"].inject_many({
"METHODS": output.getvalue(),
})
if __name__=='__main__':
main()
......@@ -176,11 +176,13 @@ _array_converters = {
"char*" : "readCharArray",
"uint64_t*" : "readLongArray",
"MuFlag*" : "readFlagArray",
"MuID*" : "readIntArray",
}
_special_converters = {
"MuBool" : "intToBoolean",
"MuName" : "readCString",
"MuCString" : "readCString",
"MuMemOrd" : "toMemoryOrder",
"MuAtomicRMWOptr" : "toAtomicRMWOptr",
"MuBinOptr" : "toBinOptr",
......
......@@ -32,6 +32,7 @@ _type_map = {
"void" : "",
"MuID" : "int<32>",
"MuName" : "iref<int<8>>",
"MuCString" : "iref<int<8>>",
"MuBool" : "int<32>",
"MuWPID" : "int<32>",
"MuArraySize" : "int<64>",
......@@ -313,6 +314,10 @@ def gen_comminst_impl(comminst):
bool_name = "_bool_" + cname
lines.append(' val {} = {} != 0'.format(bool_name, cname))
ir_builder_args.append(bool_name)
elif cty in ["MuName", "MuCString"]:
str_name = "_str_" + cname
lines.append(' val {} = loadCString({})'.format(str_name, cname))
ir_builder_args.append(str_name)
else:
ir_builder_args.append(cname)
......@@ -332,7 +337,7 @@ def gen_comminst_impl(comminst):
_blacklist = [
"load_bundle_from_node",
"abort_bundle_node",
"set_name",
#"set_name",
"new_const_int_ex",
]
......
......@@ -21,4 +21,6 @@ injectable_files = injecttools.make_injectable_file_set(_refimpl2_root, [
["IRBUILDER_RETVALS"]),
("ir-ci-exec", "src/main/scala/uvm/refimpl/itpr/IRBuilderCommInstExecutor.scala",
["IRBUILDER_IMPL"]),
("MuCtxIRBuilderPart.scala", "src/main/scala/uvm/refimpl/MuCtxIRBuilderPart.scala",
["METHODS"]),
])
......@@ -230,8 +230,9 @@ CMuInstResNode = CMuLocalVarNode
CMuFuncVerNode = CMuChildNode
CMuBBNode = CMuChildNode
CMuInstNode = CMuChildNode
CMuCString = ctypes.c_char_p
CMuID = ctypes.c_uint32
CMuName = ctypes.c_char_p
CMuName = CMuCString
CMuCPtr = ctypes.c_void_p
CMuBool = ctypes.c_int
CMuArraySize = ctypes.c_uint64
......@@ -1230,6 +1231,7 @@ _initialize_methods(MuVM, [
('name_of', CMuName, [CMuID]),
('set_trap_handler_', None, [CMuTrapHandler, CMuCPtr]),
('execute', None, []),
('make_boot_image', None, [ctypes.c_void_p, CMuArraySize, CMuCString]),
('get_mu_error_ptr', ctypes.c_void_p, []),
## GEN:END:MuVM
])
......@@ -1360,6 +1362,7 @@ _initialize_methods(MuCtx, [
('new_const_double', MuConstNode, [MuBundleNode, MuTypeNode, ctypes.c_double]),
('new_const_null', MuConstNode, [MuBundleNode, MuTypeNode]),
('new_const_seq', MuConstNode, [MuBundleNode, MuTypeNode, ctypes.c_void_p, CMuArraySize]),
('new_const_extern', MuConstNode, [MuBundleNode, MuTypeNode, CMuCString]),
('new_global_cell', MuGlobalNode, [MuBundleNode, MuTypeNode]),
('new_func', MuFuncNode, [MuBundleNode, MuFuncSigNode]),
('new_func_ver', MuFuncVerNode, [MuBundleNode, MuFuncNode]),
......
......@@ -46,20 +46,22 @@ typeConstructor
: 'int' '<' length=intLiteral '>' # TypeInt
| 'float' # TypeFloat
| 'double' # TypeDouble
| 'uptr' '<' ty=type '>' # TypeUPtr
| 'ufuncptr' '<' funcSig '>' # TypeUFuncPtr
| 'struct' '<' fieldTys+=type+ '>' # TypeStruct
| 'hybrid' '<' fieldTys+=type* varTy=type '>' # TypeHybrid
| 'array' '<' ty=type length=intLiteral '>' # TypeArray
| 'vector' '<' ty=type length=intLiteral '>' # TypeVector
| 'void' # TypeVoid
| 'ref' '<' ty=type '>' # TypeRef
| 'iref' '<' ty=type '>' # TypeIRef
| 'weakref' '<' ty=type '>' # TypeWeakRef
| 'struct' '<' fieldTys+=type+ '>' # TypeStruct
| 'array' '<' ty=type length=intLiteral '>' # TypeArray
| 'hybrid' '<' fieldTys+=type* varTy=type '>' # TypeHybrid
| 'void' # TypeVoid
| 'tagref64' # TypeTagRef64
| 'funcref' '<' funcSig '>' # TypeFuncRef
| 'threadref' # TypeThreadRef
| 'stackref' # TypeStackRef
| 'tagref64' # TypeTagRef64
| 'vector' '<' ty=type length=intLiteral '>' # TypeVector
| 'uptr' '<' ty=type '>' # TypeUPtr
| 'ufuncptr' '<' funcSig '>' # TypeUFuncPtr
| 'framecursorref' # TypeFrameCursorRef
| 'irnoderef' # TypeIRNodeRef
;
funcSigConstructor
......@@ -70,8 +72,9 @@ constConstructor
: intLiteral # CtorInt
| floatLiteral # CtorFloat
| doubleLiteral # CtorDouble
| '{' globalVar* '}' # CtorList
| 'NULL' # CtorNull
| '{' globalVar* '}' # CtorList
| 'EXTERN' symbol=stringLiteral # CtorExtern
;
type
......@@ -314,6 +317,10 @@ doubleLiteral
| NAN 'd' # DoubleNan
| 'bitsd' '(' intLiteral ')' # DoubleBits
;
stringLiteral
: STRING_LITERAL
;
name
: globalName
......@@ -360,6 +367,10 @@ LOCAL_NAME
FLAG
: FLAG_PREFIX [A-Z_]+
;
STRING_LITERAL
: '"' NON_QUOTE* '"'
;
fragment
DIGIT
......@@ -400,6 +411,11 @@ IDCHAR
| '.'
;
fragment
NON_QUOTE
: [!#-~]
;
WS : [ \t\r\n]+ -> skip ; // skip spaces, tabs, newlines
LINE_COMMENT
......
......@@ -105,56 +105,57 @@ object CommInsts extends SimpleNamespace[CommInst] {
commInst(0x323, "@uvm.irbuilder.new_const_double")
commInst(0x324, "@uvm.irbuilder.new_const_null")
commInst(0x325, "@uvm.irbuilder.new_const_seq")
commInst(0x326, "@uvm.irbuilder.new_global_cell")
commInst(0x327, "@uvm.irbuilder.new_func")
commInst(0x328, "@uvm.irbuilder.new_func_ver")
commInst(0x329, "@uvm.irbuilder.new_exp_func")
commInst(0x32a, "@uvm.irbuilder.new_bb")
commInst(0x32b, "@uvm.irbuilder.new_nor_param")
commInst(0x32c, "@uvm.irbuilder.new_exc_param")
commInst(0x32d, "@uvm.irbuilder.new_inst_res")
commInst(0x32e, "@uvm.irbuilder.add_dest")
commInst(0x32f, "@uvm.irbuilder.add_keepalives")
commInst(0x330, "@uvm.irbuilder.new_binop")
commInst(0x331, "@uvm.irbuilder.new_cmp")
commInst(0x332, "@uvm.irbuilder.new_conv")
commInst(0x333, "@uvm.irbuilder.new_select")
commInst(0x334, "@uvm.irbuilder.new_branch")
commInst(0x335, "@uvm.irbuilder.new_branch2")
commInst(0x336, "@uvm.irbuilder.new_switch")
commInst(0x337, "@uvm.irbuilder.add_switch_dest")
commInst(0x338, "@uvm.irbuilder.new_call")
commInst(0x339, "@uvm.irbuilder.new_tailcall")
commInst(0x33a, "@uvm.irbuilder.new_ret")
commInst(0x33b, "@uvm.irbuilder.new_throw")
commInst(0x33c, "@uvm.irbuilder.new_extractvalue")
commInst(0x33d, "@uvm.irbuilder.new_insertvalue")
commInst(0x33e, "@uvm.irbuilder.new_extractelement")
commInst(0x33f, "@uvm.irbuilder.new_insertelement")
commInst(0x340, "@uvm.irbuilder.new_shufflevector")
commInst(0x341, "@uvm.irbuilder.new_new")
commInst(0x342, "@uvm.irbuilder.new_newhybrid")
commInst(0x343, "@uvm.irbuilder.new_alloca")
commInst(0x344, "@uvm.irbuilder.new_allocahybrid")
commInst(0x345, "@uvm.irbuilder.new_getiref")
commInst(0x346, "@uvm.irbuilder.new_getfieldiref")
commInst(0x347, "@uvm.irbuilder.new_getelemiref")
commInst(0x348, "@uvm.irbuilder.new_shiftiref")
commInst(0x349, "@uvm.irbuilder.new_getvarpartiref")
commInst(0x34a, "@uvm.irbuilder.new_load")
commInst(0x34b, "@uvm.irbuilder.new_store")
commInst(0x34c, "@uvm.irbuilder.new_cmpxchg")
commInst(0x34d, "@uvm.irbuilder.new_atomicrmw")
commInst(0x34e, "@uvm.irbuilder.new_fence")
commInst(0x34f, "@uvm.irbuilder.new_trap")
commInst(0x350, "@uvm.irbuilder.new_watchpoint")
commInst(0x351, "@uvm.irbuilder.new_wpbranch")
commInst(0x352, "@uvm.irbuilder.new_ccall")
commInst(0x353, "@uvm.irbuilder.new_newthread")
commInst(0x354, "@uvm.irbuilder.new_swapstack_ret")
commInst(0x355, "@uvm.irbuilder.new_swapstack_kill")
commInst(0x356, "@uvm.irbuilder.set_newstack_pass_values")
commInst(0x357, "@uvm.irbuilder.set_newstack_throw_exc")
commInst(0x358, "@uvm.irbuilder.new_comminst")
commInst(0x326, "@uvm.irbuilder.new_const_extern")
commInst(0x327, "@uvm.irbuilder.new_global_cell")
commInst(0x328, "@uvm.irbuilder.new_func")
commInst(0x329, "@uvm.irbuilder.new_func_ver")
commInst(0x32a, "@uvm.irbuilder.new_exp_func")
commInst(0x32b, "@uvm.irbuilder.new_bb")
commInst(0x32c, "@uvm.irbuilder.new_nor_param")
commInst(0x32d, "@uvm.irbuilder.new_exc_param")
commInst(0x32e, "@uvm.irbuilder.new_inst_res")
commInst(0x32f, "@uvm.irbuilder.add_dest")
commInst(0x330, "@uvm.irbuilder.add_keepalives")
commInst(0x331, "@uvm.irbuilder.new_binop")
commInst(0x332, "@uvm.irbuilder.new_cmp")
commInst(0x333, "@uvm.irbuilder.new_conv")
commInst(0x334, "@uvm.irbuilder.new_select")
commInst(0x335, "@uvm.irbuilder.new_branch")
commInst(0x336, "@uvm.irbuilder.new_branch2")
commInst(0x337, "@uvm.irbuilder.new_switch")
commInst(0x338, "@uvm.irbuilder.add_switch_dest")
commInst(0x339, "@uvm.irbuilder.new_call")
commInst(0x33a, "@uvm.irbuilder.new_tailcall")
commInst(0x33b, "@uvm.irbuilder.new_ret")
commInst(0x33c, "@uvm.irbuilder.new_throw")
commInst(0x33d, "@uvm.irbuilder.new_extractvalue")
commInst(0x33e, "@uvm.irbuilder.new_insertvalue")
commInst(0x33f, "@uvm.irbuilder.new_extractelement")
commInst(0x340, "@uvm.irbuilder.new_insertelement")
commInst(0x341, "@uvm.irbuilder.new_shufflevector")
commInst(0x342, "@uvm.irbuilder.new_new")
commInst(0x343, "@uvm.irbuilder.new_newhybrid")
commInst(0x344, "@uvm.irbuilder.new_alloca")
commInst(0x345, "@uvm.irbuilder.new_allocahybrid")
commInst(0x346, "@uvm.irbuilder.new_getiref")
commInst(0x347, "@uvm.irbuilder.new_getfieldiref")
commInst(0x348, "@uvm.irbuilder.new_getelemiref")
commInst(0x349, "@uvm.irbuilder.new_shiftiref")
commInst(0x34a, "@uvm.irbuilder.new_getvarpartiref")
commInst(0x34b, "@uvm.irbuilder.new_load")
commInst(0x34c, "@uvm.irbuilder.new_store")
commInst(0x34d, "@uvm.irbuilder.new_cmpxchg")
commInst(0x34e, "@uvm.irbuilder.new_atomicrmw")
commInst(0x34f, "@uvm.irbuilder.new_fence")
commInst(0x350, "@uvm.irbuilder.new_trap")
commInst(0x351, "@uvm.irbuilder.new_watchpoint")
commInst(0x352, "@uvm.irbuilder.new_wpbranch")
commInst(0x353, "@uvm.irbuilder.new_ccall")
commInst(0x354, "@uvm.irbuilder.new_newthread")
commInst(0x355, "@uvm.irbuilder.new_swapstack_ret")
commInst(0x356, "@uvm.irbuilder.new_swapstack_kill")
commInst(0x357, "@uvm.irbuilder.set_newstack_pass_values")
commInst(0x358, "@uvm.irbuilder.set_newstack_throw_exc")
commInst(0x359, "@uvm.irbuilder.new_comminst")
/// GEN:END:IRBUILDER_COMMINSTS
}
......@@ -111,6 +111,7 @@ class IRBuilder(globalBundle: GlobalBundle, idFactory: IDFactory) {
def newConstDouble(b: BN, ty: CN[Type], value: Double): CN[ConstDouble] = newObj(b.constantNs, ConstDouble(ty, value))
def newConstNull (b: BN, ty: CN[Type]): CN[ConstNull] = newObj(b.constantNs, ConstNull(ty))
def newConstSeq (b: BN, ty: CN[Type], elems: Seq[CN[Constant]]): CN[ConstSeq] = newObj(b.constantNs, ConstSeq(ty, elems))
def newConstExtern(b: BN, ty: CN[Type], symbol: String): CN[ConstExtern] = newObj(b.constantNs, ConstExtern(ty, symbol))
// format: ON
def newGlobalCell(b: BN, ty: CN[Type]): CN[GlobalCell] = newObj(b.globalCellNs, new GlobalCell(ty))
......
......@@ -19,10 +19,12 @@ import uvm.utils.AdvancedAntlrHelper
import uvm.utils.AntlrHelpers.AccumulativeAntlrErrorListener
import org.slf4j.LoggerFactory
import com.typesafe.scalalogging.Logger
import uvm.ir.textinput.gen.UIRParser.StringLiteralContext
import uvm.ir.textinput.gen.UIRParser.StringLiteralContext
class UIRTextReader(val idFactory: IDFactory, val recordSourceInfo: Boolean = true) {
import UIRTextReader._
def read(ir: java.io.Reader, globalBundle: GlobalBundle): TrantientBundle = {
logger.debug("Slurping from reader...")
val src = IOHelpers.slurp(ir)
......@@ -34,7 +36,7 @@ class UIRTextReader(val idFactory: IDFactory, val recordSourceInfo: Boolean = tr
val input = new ANTLRInputStream(ir)
read(ir, input, globalBundle)
}
def parse(source: String, ais: ANTLRInputStream): IrContext = {
logger.debug("Creating AccumulativeAntlrErrorListener...")
val ea = new AccumulativeAntlrErrorListener(source)
......@@ -47,13 +49,13 @@ class UIRTextReader(val idFactory: IDFactory, val recordSourceInfo: Boolean = tr
val parser = new UIRParser(tokens)
parser.removeErrorListeners()
parser.addErrorListener(ea)
logger.debug("Antlr parsing IR...")
val ast = parser.ir()
if (ea.hasError) {
throw new TextIRParsingException("Syntax error:\n" + ea.getMessages)
}
ast
}
......@@ -170,23 +172,25 @@ private[textinput] class InstanceUIRTextReader(idFactory: IDFactory, source: Str
def mkType(tc: TypeConstructorContext): Type = {
val ty = tc match {
case t: TypeIntContext => TypeInt(t.length.intValue())
case t: TypeFloatContext => TypeFloat()
case t: TypeDoubleContext => TypeDouble()
case t: TypeRefContext => TypeRef(null).later(phase1) { _.ty = t.ty }
case t: TypeIRefContext => TypeIRef(null).later(phase1) { _.ty = t.ty }
case t: TypeWeakRefContext => TypeWeakRef(null).later(phase1) { _.ty = t.ty }
case t: TypeStructContext => TypeStruct(null).later(phase1) { _.fieldTys = t.fieldTys.map(resTy) }
case t: TypeArrayContext => TypeArray(null, t.length.longValue()).later(phase1) { _.elemTy = t.ty }
case t: TypeHybridContext => TypeHybrid(null, null).later(phase1) { tt => tt.fieldTys = t.fieldTys.map(resTy); tt.varTy = t.varTy }
case t: TypeVoidContext => TypeVoid()
case t: TypeFuncRefContext => TypeFuncRef(null).later(phase1) { _.sig = t.funcSig() }
case t: TypeThreadRefContext => TypeThreadRef()
case t: TypeStackRefContext => TypeStackRef()
case t: TypeTagRef64Context => TypeTagRef64()
case t: TypeVectorContext => TypeVector(null, t.length.longValue()).later(phase1) { _.elemTy = t.ty }
case t: TypeUPtrContext => TypeUPtr(null).later(phase1) { _.ty = t.ty }
case t: TypeUFuncPtrContext => TypeUFuncPtr(null).later(phase1) { _.sig = t.funcSig }
case t: TypeIntContext => TypeInt(t.length.intValue())
case t: TypeFloatContext => TypeFloat()
case t: TypeDoubleContext => TypeDouble()
case t: TypeUPtrContext => TypeUPtr(null).later(phase1) { _.ty = t.ty }
case t: TypeUFuncPtrContext => TypeUFuncPtr(null).later(phase1) { _.sig = t.funcSig }
case t: TypeStructContext => TypeStruct(null).later(phase1) { _.fieldTys = t.fieldTys.map(resTy) }
case t: TypeHybridContext => TypeHybrid(null, null).later(phase1) { tt => tt.fieldTys = t.fieldTys.map(resTy); tt.varTy = t.varTy }
case t: TypeArrayContext => TypeArray(null, t.length.longValue()).later(phase1) { _.elemTy = t.ty }
case t: TypeVectorContext => TypeVector(null, t.length.longValue()).later(phase1) { _.elemTy = t.ty }
case t: TypeVoidContext => TypeVoid()
case t: TypeRefContext => TypeRef(null).later(phase1) { _.ty = t.ty }
case t: TypeIRefContext => TypeIRef(null).later(phase1) { _.ty = t.ty }
case t: TypeWeakRefContext => TypeWeakRef(null).later(phase1) { _.ty = t.ty }
case t: TypeTagRef64Context => TypeTagRef64()
case t: TypeFuncRefContext => TypeFuncRef(null).later(phase1) { _.sig = t.funcSig() }
case t: TypeThreadRefContext => TypeThreadRef()
case t: TypeStackRefContext => TypeStackRef()
case t: TypeFrameCursorRefContext => TypeFrameCursorRef()
case t: TypeIRNodeRefContext => TypeIRNodeRef()
}
return ty
}
......@@ -231,6 +235,7 @@ private[textinput] class InstanceUIRTextReader(idFactory: IDFactory, source: Str
_.elems = for (gn <- cc.globalVar()) yield resGlobalVar(gn)
}
case _: CtorNullContext => ConstNull(t)
case cc: CtorExternContext => ConstExtern(t, cc.symbol)
}
return con
}
......@@ -419,7 +424,7 @@ private[textinput] class InstanceUIRTextReader(idFactory: IDFactory, source: Str
}
implicit def resThreadLocalClause(tlc: ThreadLocalClauseContext): Option[SSAVariable] =
Option(tlc).map { theTlc => resVar(theTlc.value()) }
Option(tlc).map { theTlc => resVar(theTlc.value()) }
implicit def resNewStackClause(nsc: NewStackClauseContext): NewStackAction = {
nsc match {
......@@ -702,6 +707,11 @@ object UIRTextReader {
case _: DoubleNanContext => java.lang.Double.NaN
case bits: DoubleBitsContext => java.lang.Double.longBitsToDouble(bits.intLiteral().longValue())
}
implicit def stringLiteralToString(sl: StringLiteralContext): String = {
val txt = terminalToString(sl.STRING_LITERAL())
txt.substring(1, txt.length-1)
}
def cascadeLookup[T <: Identified](name: String, ns1: Namespace[T], ns2: Namespace[T]): T =
ns1.get(name).getOrElse(ns2(name))
......
......@@ -141,6 +141,13 @@ class MicroVM(vmConf: VMConf) {
def setTrapHandler(trapHandler: TrapHandler): Unit = {
trapManager.trapHandler = trapHandler
}
/**
* Make boot image.
*/
def makeBootImage(whiteList: Seq[Int], outputFile: String): Unit = {
???
}
/**
* Execute. This is the external pusher of the execution.
......
......@@ -72,7 +72,8 @@ trait MuCtxIRBuilderPart {
// no op
}
def newBundle(): MuBundleNode = {
/// GEN:BEGIN:METHODS
def newBundle(): MuBundleNode = {
addHandle(irBuilder.newBundle())
}
......@@ -267,6 +268,12 @@ trait MuCtxIRBuilderPart {
addHandle(irBuilder.newConstSeq(b, ty, elems))
}
def newConstExtern(b: MuBundleNode, ty: MuTypeNode, symbol: String): MuConstNode = {
require(!b.isNull, "b must not be NULL")
require(!ty.isNull, "ty must not be NULL")
addHandle(irBuilder.newConstExtern(b, ty, symbol))
}
def newGlobalCell(b: MuBundleNode, ty: MuTypeNode): MuGlobalNode = {
require(!b.isNull, "b must not be NULL")
require(!ty.isNull, "ty must not be NULL")
......@@ -629,6 +636,5 @@ trait MuCtxIRBuilderPart {
addHandle(irBuilder.newCommInst(bb, opcode, flags, tys, sigs, args))
}
// BEGIN: auto-generated code
// END: auto-generated code
}
\ No newline at end of file
/// GEN:END:METHODS
}
......@@ -233,6 +233,7 @@ object TypeInferer {
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)
......
......@@ -66,7 +66,13 @@ trait IRBuilderCommInstExecutor extends InterpreterActions with ObjectPinner {
val (obj,off) = ir
val loc = obj + off
MemoryOperations.loadInt32Array(loc, sz).map(toFlag)
}
}
protected def loadCString(ir: (Word, Word)): String = {
val (obj,off) = ir
val loc = obj + off
MemoryOperations.bytesToStr(loc)
}
def interpretCurrentIRBuilderCommonInstruction(): Unit = {
assert(curInst.isInstanceOf[InstCommInst])
......@@ -84,14 +90,6 @@ trait IRBuilderCommInstExecutor extends InterpreterActions with ObjectPinner {
// no-op
continueNormally()
}
case "@uvm.irbuilder.set_name" => {
val b = argList(0).asIRNode.getOrElse(throw new UvmNullGenRefException("CommInst arg %b must not be null")).asInstanceOf[BundleNode]
val node = argList(1).asIRNode.getOrElse(throw new UvmNullGenRefException("CommInst arg %node must not be null"))
val name = argList(2).asIRef
val nameStr = MemoryOperations.bytesToStr(name._1 + name._2)
irBuilder.setName(b, node, nameStr)
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[BundleNode]
val ty = argList(1).asIRNode.getOrElse(throw new UvmNullGenRefException("CommInst arg %ty must not be null"))
......@@ -124,6 +122,14 @@ trait IRBuilderCommInstExecutor extends InterpreterActions with ObjectPinner {
results(0).asInt32 = _rv
continueNormally()
}
case "@uvm.irbuilder.set_name" => {
val b = argList(0).asIRNode.getOrElse(throw new UvmNullGenRefException("CommInst arg %b must not be null")).asInstanceOf[BundleNode]
val node = argList(1).asIRNode.getOrElse(throw new UvmNullGenRefException("CommInst arg %node must not be null"))
val name = argList(2).asIRef
val _str_name = loadCString(name)
val _rv = irBuilder.setName(b, node, _str_name)
continueNormally()
}
case "@uvm.irbuilder.new_type_int" => {
val b = argList(0).asIRNode.getOrElse(throw new UvmNullGenRefException("CommInst arg %b must not be null")).asInstanceOf[BundleNode]
val len = argList(1).asInt32.toInt
......@@ -339,6 +345,15 @@ trait IRBuilderCommInstExecutor extends InterpreterActions with ObjectPinner {
results(0).asIRNode = Some(_rv)
continueNormally()
}
case "@uvm.irbuilder.new_const_extern" => {
val b = argList(0).asIRNode.getOrElse(throw new UvmNullGenRefException("CommInst arg %b must not be null")).asInstanceOf[BundleNode]
val ty = argList(1).asIRNode.getOrElse(throw new UvmNullGenRefException("CommInst arg %ty must not be null"))
val symbol = argList(2).asIRef
val _str_symbol = loadCString(symbol)
val _rv = irBuilder.newConstExtern(b, ty, _str_symbol)
results(0).asIRNode = Some(_rv)
continueNormally()
}
case "@uvm.irbuilder.new_global_cell" => {
val b = argList(0).asIRNode.getOrElse(throw new UvmNullGenRefException("CommInst arg %b must not be null")).asInstanceOf[BundleNode]
val ty = argList(1).asIRNode.getOrElse(throw new UvmNullGenRefException("CommInst arg %ty must not be null"))
......
......@@ -56,19 +56,30 @@ val _raw_mvm = _jffiBuffer.getAddress(0)
val mvm = getMicroVM(_raw_mvm)
val _RV = mvm.execute()
}
val MUVM__MAKE_BOOT_IMAGE = exposedMethod("MuVM.make_boot_image", JType.VOID, Array(JType.POINTER, JType.POINTER, JType.POINTER, JType.POINTER)) { _jffiBuffer =>
val _raw_mvm = _jffiBuffer.getAddress(0)
val _raw_whitelist = _jffiBuffer.getAddress(1)
val _raw_whitelist_sz = _jffiBuffer.getAddress(2)
val _raw_output_file = _jffiBuffer.getAddress(3)
val mvm = getMicroVM(_raw_mvm)
val whitelist = readIntArray(_raw_whitelist, _raw_whitelist_sz)
val output_file = readCString(_raw_output_file)
val _RV = mvm.makeBootImage(whitelist, output_file)
}
val MUVM__GET_MU_ERROR_PTR = exposedMethod("MuVM.get_mu_error_ptr", JType.POINTER, Array(JType.POINTER)) { _jffiBuffer =>
val _raw_mvm = _jffiBuffer.getAddress(0)
val mvm = getMicroVM(_raw_mvm)
val _RV = mvm.getMuErrorPtr()
_jffiBuffer.setAddressReturn(_RV)
}
val stubsOfMuVM = new Array[Word](6)
val stubsOfMuVM = new Array[Word](7)
stubsOfMuVM(0) = MUVM__NEW_CONTEXT.address
stubsOfMuVM(1) = MUVM__ID_OF.address
stubsOfMuVM(2) = MUVM__NAME_OF.address
stubsOfMuVM(3) = MUVM__SET_TRAP_HANDLER.address
stubsOfMuVM(4) = MUVM__EXECUTE.address
stubsOfMuVM(5) = MUVM__GET_MU_ERROR_PTR.address
stubsOfMuVM(5) = MUVM__MAKE_BOOT_IMAGE.address
stubsOfMuVM(6) = MUVM__GET_MU_ERROR_PTR.address
val MUCTX__ID_OF = exposedMethod("MuCtx.id_of", JType.UINT32, Array(JType.POINTER, JType.POINTER)) { _jffiBuffer =>
val _raw_ctx = _jffiBuffer.getAddress(0)
val _raw_name = _jffiBuffer.getAddress(1)
......@@ -1278,6 +1289,19 @@ val _RV = ctx.newConstSeq(b, ty, elems)
val _RV_FAK = exposeMuValue(ctx, _RV)
_jffiBuffer.setAddressReturn(_RV_FAK)
}
val MUCTX__NEW_CONST_EXTERN = exposedMethod("MuCtx.new_const_extern", JType.POINTER, Array(JType.POINTER, JType.POINTER, JType.POINTER, JType.POINTER)) { _jffiBuffer =>
val _raw_ctx = _jffiBuffer.getAddress(0)
val _raw_b = _jffiBuffer.getAddress(1)
val _raw_ty = _jffiBuffer.getAddress(2)
val _raw_symbol = _jffiBuffer.getAddress(3)
val ctx = getMuCtx(_raw_ctx)
val b = getMuValueNotNull(_raw_b).asInstanceOf[MuBundleNode]
val ty = getMuValueNotNull(_raw_ty).asInstanceOf[MuTypeNode]
val symbol = readCString(_raw_symbol)
val _RV = ctx.newConstExtern(b, ty, symbol)
val _RV_FAK = exposeMuValue(ctx, _RV)
_jffiBuffer.setAddressReturn(_RV_FAK)
}
val MUCTX__NEW_GLOBAL_CELL = exposedMethod("MuCtx.new_global_cell", JType.POINTER, Array(JType.POINTER, JType.POINTER, JType.POINTER)) { _jffiBuffer =>
val _raw_ctx = _jffiBuffer.getAddress(0)
val _raw_b = _jffiBuffer.getAddress(1)