|
@@ -180,6 +180,34 @@ class ModelverseKernel(object):
|
|
|
getattr(source, function_names[i]),
|
|
|
function_names[i])
|
|
|
|
|
|
+ def print_instruction(self, inst, indent=0):
|
|
|
+ inst_type, = yield [("RV", [inst])]
|
|
|
+ #print(" %s (%s)" % (inst, inst_type["value"]))
|
|
|
+ if inst_type["value"] == "if":
|
|
|
+ cond, true, false = yield [("RD", [inst, "cond"]),
|
|
|
+ ("RD", [inst, "then"]),
|
|
|
+ ("RD", [inst, "else"])]
|
|
|
+ #print("Cond: %s; True: %s; False: %s" % (cond, true, false))
|
|
|
+ cond, = yield [("CALL_ARGS", [self.print_instruction, (cond, 0)])]
|
|
|
+ true, = yield [("CALL_ARGS", [self.print_instruction, (true, indent+1)])]
|
|
|
+ if false:
|
|
|
+ false, = yield [("CALL_ARGS", [self.print_instruction, (false, indent+1)])]
|
|
|
+ false = (" " * indent + "else:\n%s\n") % false
|
|
|
+ else:
|
|
|
+ false = ""
|
|
|
+
|
|
|
+ next_inst, = yield[("RD", [inst, "next"])]
|
|
|
+ if next_inst:
|
|
|
+ next_inst, = yield [("CALL_ARGS", [self.print_instruction, (next_inst, indent)])]
|
|
|
+ else:
|
|
|
+ next_inst = ""
|
|
|
+ raise primitive_functions.PrimitiveFinished(" " * indent + "if(" + cond + "):\n" + true + "\n" + false + next_inst)
|
|
|
+ elif inst_type["value"] == "const":
|
|
|
+ node, = yield [("RD", [inst, "node"])]
|
|
|
+ #print("Node: %s" % (node))
|
|
|
+
|
|
|
+ raise primitive_functions.PrimitiveFinished("(no_printer_for_%s)" % inst_type["value"])
|
|
|
+
|
|
|
def read_function(self, inst):
|
|
|
initial_instruction = inst
|
|
|
suggested_name = self.jit.get_global_name(inst)
|
|
@@ -190,8 +218,9 @@ class ModelverseKernel(object):
|
|
|
raise jit.JitCompilationFailedException("FAIL")
|
|
|
|
|
|
print("Reading function: %s" % suggested_name)
|
|
|
- inst_type, = yield [("RV", [inst])]
|
|
|
- print(" %s (%s)" % (inst, inst_type["value"]))
|
|
|
+ printed, = yield [("CALL_ARGS", [self.print_instruction, (inst, 0)])]
|
|
|
+ print("Total printed function: ")
|
|
|
+ print(printed)
|
|
|
|
|
|
def jit_compile(self, task_root, inst):
|
|
|
# Try to retrieve the suggested name.
|