Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: m-labs/artiq
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: f7c8625f6189
Choose a base ref
...
head repository: m-labs/artiq
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: 9791cbba4dac
Choose a head ref
  • 4 commits
  • 3 files changed
  • 1 contributor

Commits on Aug 27, 2015

  1. LLVMIRGenerator: remove debug print.

    whitequark committed Aug 27, 2015

    Verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature.
    Copy the full SHA
    71ebe17 View commit details
  2. LLVMIRGenerator: handle self-referential class types.

    whitequark committed Aug 27, 2015
    Copy the full SHA
    84e32db View commit details
  3. compiler.types: fix module paths in __repr__.

    whitequark committed Aug 27, 2015
    Copy the full SHA
    a3284f8 View commit details
  4. Copy the full SHA
    9791cbb View commit details
Showing with 38 additions and 14 deletions.
  1. +28 −5 artiq/compiler/embedding.py
  2. +3 −2 artiq/compiler/transforms/llvm_ir_generator.py
  3. +7 −7 artiq/compiler/types.py
33 changes: 28 additions & 5 deletions artiq/compiler/embedding.py
Original file line number Diff line number Diff line change
@@ -8,7 +8,7 @@
import os, re, linecache, inspect, textwrap
from collections import OrderedDict, defaultdict

from pythonparser import ast, source, diagnostic, parse_buffer
from pythonparser import ast, algorithm, source, diagnostic, parse_buffer

from . import types, builtins, asttyped, prelude
from .transforms import ASTTypedRewriter, Inferencer, IntMonomorphizer
@@ -101,6 +101,7 @@ def quote(self, value):

constructor_type = types.TConstructor(instance_type)
constructor_type.attributes['__objectid__'] = builtins.TInt(types.TValue(32))
instance_type.constructor = constructor_type

self.type_map[typ] = instance_type, constructor_type

@@ -253,6 +254,24 @@ def proxy_diagnostic(diag):

super().visit_AttributeT(node)

class TypedtreeHasher(algorithm.Visitor):
def generic_visit(self, node):
def freeze(obj):
if isinstance(obj, ast.AST):
return self.visit(obj)
elif isinstance(obj, types.Type):
return hash(obj.find())
elif isinstance(obj, list):
return tuple(obj)
else:
assert obj is None or isinstance(obj, (bool, int, float, str))
return obj

fields = node._fields
if hasattr(node, '_types'):
fields = fields + node._types
return hash(tuple(freeze(getattr(node, field_name)) for field_name in fields))

class Stitcher:
def __init__(self, engine=None):
if engine is None:
@@ -275,12 +294,17 @@ def finalize(self):
inferencer = StitchingInferencer(engine=self.engine,
value_map=self.value_map,
quote=self._quote)
hasher = TypedtreeHasher()

# Iterate inference to fixed point.
self.inference_finished = False
while not self.inference_finished:
self.inference_finished = True
old_typedtree_hash = None
while True:
inferencer.visit(self.typedtree)
typedtree_hash = hasher.visit(self.typedtree)

if old_typedtree_hash == typedtree_hash:
break
old_typedtree_hash = typedtree_hash

# After we have found all functions, synthesize a module to hold them.
source_buffer = source.Buffer("", "<synthesized>")
@@ -488,7 +512,6 @@ def _quote_function(self, function, loc):
# the final call.
function_node = self._quote_embedded_function(function)
self.typedtree.insert(0, function_node)
self.inference_finished = False
return function_node.name
elif function.artiq_embedded.syscall is not None:
# Insert a storage-less global whose type instructs the compiler
5 changes: 3 additions & 2 deletions artiq/compiler/transforms/llvm_ir_generator.py
Original file line number Diff line number Diff line change
@@ -270,6 +270,9 @@ def llty_of_type(self, typ, bare=False, for_return=False):

llty = self.llcontext.get_identified_type(name)
if llty.elements is None:
# First setting elements to [] will allow us to handle
# self-referential types.
llty.elements = []
llty.elements = [self.llty_of_type(attrtyp)
for attrtyp in typ.attributes.values()]

@@ -942,8 +945,6 @@ def process_Call(self, insn):
llstackptr = self.llbuilder.call(self.llbuiltin("llvm.stacksave"), [])

llresultslot = self.llbuilder.alloca(llfun.type.pointee.args[0].pointee)
print(llfun)
print(llresultslot)
self.llbuilder.call(llfun, [llresultslot] + llargs)
llresult = self.llbuilder.load(llresultslot)

14 changes: 7 additions & 7 deletions artiq/compiler/types.py
Original file line number Diff line number Diff line change
@@ -78,7 +78,7 @@ def fold(self, accum, fn):

def __repr__(self):
if self.parent is self:
return "<py2llvm.types.TVar %d>" % id(self)
return "<artiq.compiler.types.TVar %d>" % id(self)
else:
return repr(self.find())

@@ -121,7 +121,7 @@ def fold(self, accum, fn):
return fn(accum, self)

def __repr__(self):
return "py2llvm.types.TMono(%s, %s)" % (repr(self.name), repr(self.params))
return "artiq.compiler.types.TMono(%s, %s)" % (repr(self.name), repr(self.params))

def __getitem__(self, param):
return self.params[param]
@@ -167,7 +167,7 @@ def fold(self, accum, fn):
return fn(accum, self)

def __repr__(self):
return "py2llvm.types.TTuple(%s)" % repr(self.elts)
return "artiq.compiler.types.TTuple(%s)" % repr(self.elts)

def __eq__(self, other):
return isinstance(other, TTuple) and \
@@ -231,7 +231,7 @@ def fold(self, accum, fn):
return fn(accum, self)

def __repr__(self):
return "py2llvm.types.TFunction({}, {}, {})".format(
return "artiq.compiler.types.TFunction({}, {}, {})".format(
repr(self.args), repr(self.optargs), repr(self.ret))

def __eq__(self, other):
@@ -311,7 +311,7 @@ def fold(self, accum, fn):
return fn(accum, self)

def __repr__(self):
return "py2llvm.types.{}({})".format(type(self).__name__, repr(self.name))
return "artiq.compiler.types.{}({})".format(type(self).__name__, repr(self.name))

def __eq__(self, other):
return isinstance(other, TBuiltin) and \
@@ -364,7 +364,7 @@ def __init__(self, name, attributes=OrderedDict()):
self.attributes = attributes

def __repr__(self):
return "py2llvm.types.TInstance({}, {})".format(
return "artiq.compiler.types.TInstance({}, {})".format(
repr(self.name), repr(self.attributes))

class TMethod(TMono):
@@ -401,7 +401,7 @@ def fold(self, accum, fn):
return fn(accum, self)

def __repr__(self):
return "py2llvm.types.TValue(%s)" % repr(self.value)
return "artiq.compiler.types.TValue(%s)" % repr(self.value)

def __eq__(self, other):
return isinstance(other, TValue) and \