瀏覽代碼

Define more CFG instructions

jonathanvdc 8 年之前
父節點
當前提交
b33e042b5f
共有 1 個文件被更改,包括 138 次插入0 次删除
  1. 138 0
      kernel/modelverse_jit/cfg_ir.py

+ 138 - 0
kernel/modelverse_jit/cfg_ir.py

@@ -248,3 +248,141 @@ class JitFunctionCall(Value):
         return 'call %s(%s)' % (
             self.target.ref_str(),
             ', '.join(['%s=%s' % (key, val.ref_str()) for key, val in self.argument_list]))
+
+class DefineLocal(Value):
+    """A value that defines a local variable."""
+    def __init__(self, variable):
+        Value.__init__(self)
+        self.variable = variable
+
+    def get_dependencies(self):
+        """Gets all definitions and instructions on which this instruction depends."""
+        return []
+
+    def has_side_effects(self):
+        """Tells if this instruction has side-effects."""
+        return True
+
+    def __str__(self):
+        return 'define-local %d' % self.variable.node_id
+
+class DefineGlobal(Value):
+    """A value that defines a global variable."""
+    def __init__(self, variable):
+        Value.__init__(self)
+        self.variable = variable
+
+    def get_dependencies(self):
+        """Gets all definitions and instructions on which this instruction depends."""
+        return []
+
+    def has_side_effects(self):
+        """Tells if this instruction has side-effects."""
+        return True
+
+    def __str__(self):
+        return 'define-global %s' % self.variable.name
+
+class CheckLocalExists(Value):
+    """A value that checks if a local value has been defined (yet)."""
+    def __init__(self, variable):
+        Value.__init__(self)
+        self.variable = variable
+
+    def get_dependencies(self):
+        """Gets all definitions and instructions on which this instruction depends."""
+        return []
+
+    def __str__(self):
+        return 'check-local-exists %d' % self.variable.node_id
+
+class ResolveLocal(Value):
+    """A value that resolves a local as a pointer."""
+    def __init__(self, variable):
+        Value.__init__(self)
+        self.variable = variable
+
+    def get_dependencies(self):
+        """Gets all definitions and instructions on which this instruction depends."""
+        return []
+
+    def __str__(self):
+        return 'resolve-local %d' % self.variable.node_id
+
+class ResolveGlobal(Value):
+    """A value that resolves a global as a pointer."""
+    def __init__(self, variable):
+        Value.__init__(self)
+        self.variable = variable
+
+    def get_dependencies(self):
+        """Gets all definitions and instructions on which this instruction depends."""
+        return []
+
+    def __str__(self):
+        return 'resolve-global %s' % self.variable.name
+
+class LoadPointer(Value):
+    """A value that loads the value assigned to a pointer."""
+    def __init__(self, pointer):
+        Value.__init__(self)
+        self.pointer = pointer
+        assert isinstance(pointer, Definition)
+
+    def get_dependencies(self):
+        """Gets all definitions and instructions on which this instruction depends."""
+        return [self.pointer]
+
+    def __str__(self):
+        return 'load %s' % self.pointer.ref_str()
+
+class StoreAtPointer(Value):
+    """A value that assigns a value to a pointer."""
+    def __init__(self, pointer, value):
+        Value.__init__(self)
+        self.pointer = pointer
+        assert isinstance(pointer, Definition)
+        self.value = value
+        assert isinstance(value, Definition)
+
+    def get_dependencies(self):
+        """Gets all definitions and instructions on which this instruction depends."""
+        return [self.pointer, self.value]
+
+    def has_side_effects(self):
+        """Tells if this instruction has side-effects."""
+        return True
+
+    def __str__(self):
+        return 'store %s, %s' % (self.pointer.ref_str(), self.value.ref_str())
+
+class Input(Value):
+    """A value that pops a node from the input queue."""
+    def get_dependencies(self):
+        """Gets all definitions and instructions on which this instruction depends."""
+        return []
+
+    def has_side_effects(self):
+        """Tells if this instruction has side-effects."""
+        return True
+
+    def __str__(self):
+        return 'input'
+
+class Output(Value):
+    """A value that pushes a node onto the output queue."""
+    def __init__(self, value):
+        Value.__init__(self)
+        self.value = value
+        assert isinstance(value, Definition)
+
+    def get_dependencies(self):
+        """Gets all definitions and instructions on which this instruction depends."""
+        return [self.value]
+
+    def has_side_effects(self):
+        """Tells if this instruction has side-effects."""
+        return True
+
+    def __str__(self):
+        return 'output %s' % self.value.ref_str()