forked from M-Labs/artiq
transforms.llvm_ir_generator: quote recrusive objects correctly (fixes #213).
This commit is contained in:
parent
027d54ca94
commit
f2f1deb9db
|
@ -1123,21 +1123,23 @@ class LLVMIRGenerator:
|
||||||
llty = self.llty_of_type(typ)
|
llty = self.llty_of_type(typ)
|
||||||
|
|
||||||
if types.is_constructor(typ) or types.is_instance(typ):
|
if types.is_constructor(typ) or types.is_instance(typ):
|
||||||
|
llglobal = None
|
||||||
llfields = []
|
llfields = []
|
||||||
for attr in typ.attributes:
|
for attr in typ.attributes:
|
||||||
if attr == "__objectid__":
|
if attr == "__objectid__":
|
||||||
objectid = self.object_map.store(value)
|
objectid = self.object_map.store(value)
|
||||||
llfields.append(ll.Constant(lli32, objectid))
|
llfields.append(ll.Constant(lli32, objectid))
|
||||||
global_name = "object.{}".format(objectid)
|
|
||||||
|
assert llglobal is None
|
||||||
|
llglobal = ll.GlobalVariable(self.llmodule, llty.pointee,
|
||||||
|
name="object.{}".format(objectid))
|
||||||
|
self.llobject_map[value_id] = llglobal
|
||||||
else:
|
else:
|
||||||
llfields.append(self._quote(getattr(value, attr), typ.attributes[attr],
|
llfields.append(self._quote(getattr(value, attr), typ.attributes[attr],
|
||||||
lambda: path() + [attr]))
|
lambda: path() + [attr]))
|
||||||
llconst = ll.Constant(llty.pointee, llfields)
|
|
||||||
|
|
||||||
llglobal = ll.GlobalVariable(self.llmodule, llconst.type, global_name)
|
llglobal.initializer = ll.Constant(llty.pointee, llfields)
|
||||||
llglobal.initializer = llconst
|
|
||||||
llglobal.linkage = "private"
|
llglobal.linkage = "private"
|
||||||
self.llobject_map[value_id] = llglobal
|
|
||||||
return llglobal
|
return llglobal
|
||||||
elif builtins.is_none(typ):
|
elif builtins.is_none(typ):
|
||||||
assert value is None
|
assert value is None
|
||||||
|
|
Loading…
Reference in New Issue