|
@@ -178,6 +178,24 @@ class ReturnFlow(FlowInstruction):
|
|
|
def __str__(self):
|
|
|
return 'return %s' % self.value.ref_str()
|
|
|
|
|
|
+class ThrowFlow(FlowInstruction):
|
|
|
+ """Represents a control flow instruction which throws an exception."""
|
|
|
+ def __init__(self, exception):
|
|
|
+ FlowInstruction.__init__(self)
|
|
|
+ self.exception = exception
|
|
|
+ assert isinstance(exception, Definition)
|
|
|
+
|
|
|
+ def get_dependencies(self):
|
|
|
+ """Gets all definitions and instructions on which this instruction depends."""
|
|
|
+ return [self.exception]
|
|
|
+
|
|
|
+ def branches(self):
|
|
|
+ """Gets a list of basic blocks targeted by this flow instruction."""
|
|
|
+ return []
|
|
|
+
|
|
|
+ def __str__(self):
|
|
|
+ return 'throw %s' % self.exception.ref_str()
|
|
|
+
|
|
|
class UnreachableFlow(FlowInstruction):
|
|
|
"""Represents a control flow instruction which is unreachable."""
|
|
|
def get_dependencies(self):
|
|
@@ -244,14 +262,15 @@ class Literal(Value):
|
|
|
def __str__(self):
|
|
|
return 'literal %r' % self.literal
|
|
|
|
|
|
-class JitFunctionCall(Value):
|
|
|
+class FunctionCall(Value):
|
|
|
"""A value that is the result of a function call."""
|
|
|
- def __init__(self, target, argument_list):
|
|
|
+ def __init__(self, target, argument_list, calling_convention='jit'):
|
|
|
Value.__init__(self)
|
|
|
assert isinstance(target, Definition)
|
|
|
self.target = target
|
|
|
assert all([isinstance(val, Definition) for _, val in argument_list])
|
|
|
self.argument_list = argument_list
|
|
|
+ self.calling_convention = calling_convention
|
|
|
|
|
|
def has_side_effects(self):
|
|
|
"""Tells if this instruction has side-effects."""
|
|
@@ -262,7 +281,8 @@ class JitFunctionCall(Value):
|
|
|
return [self.target] + [val for _, val in self.argument_list]
|
|
|
|
|
|
def __str__(self):
|
|
|
- return 'call %s(%s)' % (
|
|
|
+ return 'call %r %s(%s)' % (
|
|
|
+ self.calling_convention,
|
|
|
self.target.ref_str(),
|
|
|
', '.join(['%s=%s' % (key, val.ref_str()) for key, val in self.argument_list]))
|
|
|
|
|
@@ -447,6 +467,23 @@ class Output(Value):
|
|
|
def __str__(self):
|
|
|
return 'output %s' % self.value.ref_str()
|
|
|
|
|
|
+class Binary(Value):
|
|
|
+ """A value that applies a binary operator to two other values."""
|
|
|
+ def __init__(self, lhs, operator, rhs):
|
|
|
+ Value.__init__(self)
|
|
|
+ self.lhs = lhs
|
|
|
+ assert isinstance(lhs, Definition)
|
|
|
+ self.operator = operator
|
|
|
+ self.rhs = rhs
|
|
|
+ assert isinstance(rhs, Definition)
|
|
|
+
|
|
|
+ def get_dependencies(self):
|
|
|
+ """Gets all definitions and instructions on which this instruction depends."""
|
|
|
+ return [self.lhs, self.rhs]
|
|
|
+
|
|
|
+ def __str__(self):
|
|
|
+ return 'binary %s, %r, %s' % (self.lhs.ref_str(), self.operator, self.rhs.ref_str())
|
|
|
+
|
|
|
def create_jump(block, arguments=None):
|
|
|
"""Creates a jump to the given block with the given argument list."""
|
|
|
return JumpFlow(Branch(block, arguments))
|