|
@@ -419,18 +419,34 @@ SIMPLE_POSITIONAL_CALLING_CONVENTION = 'simple-positional'
|
|
|
JIT_CALLING_CONVENTION = 'jit'
|
|
|
"""The calling convention for jitted functions."""
|
|
|
|
|
|
+MACRO_POSITIONAL_CALLING_CONVENTION = 'macro-positional'
|
|
|
+"""The calling convention for well-known functions that are expanded as macros during codegen."""
|
|
|
+
|
|
|
+PRINT_MACRO_NAME = 'print'
|
|
|
+"""The name of the 'print' macro."""
|
|
|
+
|
|
|
class DirectFunctionCall(Value):
|
|
|
"""A value that is the result of a direct function call."""
|
|
|
- def __init__(self, target_name, argument_list, calling_convention=JIT_CALLING_CONVENTION):
|
|
|
+ def __init__(
|
|
|
+ self, target_name, argument_list,
|
|
|
+ calling_convention=JIT_CALLING_CONVENTION,
|
|
|
+ has_value=True,
|
|
|
+ has_side_effects=True):
|
|
|
Value.__init__(self)
|
|
|
self.target_name = target_name
|
|
|
assert all([isinstance(val, Definition) for _, val in argument_list])
|
|
|
self.argument_list = argument_list
|
|
|
self.calling_convention = calling_convention
|
|
|
+ self.has_value_val = has_value
|
|
|
+ self.has_side_effects_val = has_side_effects
|
|
|
|
|
|
def has_side_effects(self):
|
|
|
"""Tells if this instruction has side-effects."""
|
|
|
- return True
|
|
|
+ return self.has_side_effects_val
|
|
|
+
|
|
|
+ def has_value(self):
|
|
|
+ """Tells if this value produces a result that is not None."""
|
|
|
+ return self.has_value_val
|
|
|
|
|
|
def create(self, new_dependencies):
|
|
|
"""Creates an instruction of this type from the given set of dependencies."""
|
|
@@ -438,7 +454,7 @@ class DirectFunctionCall(Value):
|
|
|
self.target_name,
|
|
|
[(name, new_val)
|
|
|
for new_val, (name, _) in zip(new_dependencies, self.argument_list)],
|
|
|
- self.calling_convention)
|
|
|
+ self.calling_convention, self.has_value_val, self.has_side_effects_val)
|
|
|
|
|
|
def get_dependencies(self):
|
|
|
"""Gets all definitions and instructions on which this instruction depends."""
|
|
@@ -748,6 +764,13 @@ def create_jump(block, arguments=None):
|
|
|
"""Creates a jump to the given block with the given argument list."""
|
|
|
return JumpFlow(Branch(block, arguments))
|
|
|
|
|
|
+def create_print(argument):
|
|
|
+ """Creates a value that prints the specified argument."""
|
|
|
+ return DirectFunctionCall(
|
|
|
+ PRINT_MACRO_NAME, [('argument', argument)],
|
|
|
+ calling_convention=MACRO_POSITIONAL_CALLING_CONVENTION,
|
|
|
+ has_value=False)
|
|
|
+
|
|
|
def get_def_value(def_or_value):
|
|
|
"""Returns the given value, or the underlying value of the given definition, whichever is
|
|
|
appropriate."""
|