From cea1cece1300b77c5b0eba913371ae8e9d4b59d3 Mon Sep 17 00:00:00 2001 From: cfreksen Date: Thu, 9 Nov 2017 15:32:29 +0100 Subject: [PATCH] Add support for print from runtime.c. --- llvm_emulator/stepper.py | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/llvm_emulator/stepper.py b/llvm_emulator/stepper.py index 8a89db1..013756c 100644 --- a/llvm_emulator/stepper.py +++ b/llvm_emulator/stepper.py @@ -25,7 +25,10 @@ class Garbage(Enum): return '<>' -builtins = ['allocRecord', 'initArray'] +builtins = ['allocRecord', 'initArray', 'stringEqual', 'stringNotEq', 'stringLess', + 'stringLessEq', 'stringGreater', 'stringGreaterEq', 'exponent', 'print', + 'flush', 'getChar', 'ord', 'chr', 'size', 'substring', 'concat', 'not', + 'exit_tig'] def step(insns, terminator, blocks, stack_frames, ssa_env, global_env, heap, @@ -580,6 +583,18 @@ def emulate_builtin(name, arguments_v, ssa_env, heap): struct_begin + 1, array_begin, array_init_s)) res = struct_begin + elif name == 'print': + if len(arguments_v) != 2: + err('Number of arguments to {} should be 3' + .format(name)) + else: + struct_begin = arguments_v[1] + print('Printing string, heap[{}]:' + .format(struct_begin)) + printee = heap[struct_begin + 1] + print(printee) + if not isinstance(printee, str): + warn('What was printed, was not stored as a string in the heap') elif name in builtins: TODO('Have not implemented builtin function {}, yet.' .format(name))