Permalink
Browse files

Fix broken LLVM module with recursive types

  • Loading branch information...
nickg committed Dec 27, 2012
1 parent 04c1e5b commit cb27343a731c430e8da9775955cda68fce8b594d
Showing with 66 additions and 5 deletions.
  1. +14 −4 src/cgen.c
  2. +52 −1 test/regress/access1.vhd
View
@@ -241,6 +241,15 @@ static LLVMTypeRef llvm_type(type_t t)
case T_RECORD:
{
+ const char *rec_name = istr(type_ident(t));
+ LLVMTypeRef lltype = LLVMGetTypeByName(module, rec_name);
+ if (lltype != NULL)
+ return lltype;
+
+ lltype = LLVMStructCreateNamed(LLVMGetGlobalContext(), rec_name);
+ if (lltype == NULL)
+ fatal("failed to add record type %s", rec_name);
+
const int nfields = type_fields(t);
LLVMTypeRef llfields[nfields];
@@ -249,7 +258,8 @@ static LLVMTypeRef llvm_type(type_t t)
llfields[i] = llvm_type(tree_type(field));
}
- return LLVMStructType(llfields, nfields, false);
+ LLVMStructSetBody(lltype, llfields, nfields, false);
+ return lltype;
}
case T_ACCESS:
@@ -1738,7 +1748,7 @@ static LLVMValueRef cgen_const_record(tree_t t, cgen_ctx_t *ctx)
for (int i = 0; i < nfields; i++)
assert(vals[i] != NULL);
- return LLVMConstStruct(vals, nfields, false);
+ return LLVMConstNamedStruct(llvm_type(type), vals, nfields);
}
static LLVMValueRef cgen_aggregate(tree_t t, cgen_ctx_t *ctx)
@@ -1925,8 +1935,8 @@ static LLVMValueRef cgen_until_func(tree_t wait, cgen_ctx_t *ctx)
else {
tree_t expr = tree_value(wait);
- char name[128];
- snprintf(name, sizeof(name), "until_%p", expr);
+ char name[256];
+ snprintf(name, sizeof(name), "until_%s", istr(tree_ident(wait)));
LLVMValueRef fn = LLVMAddFunction(module, name,
cgen_until_func_type());
View
@@ -3,9 +3,38 @@ end entity;
architecture test of access1 is
type int_ptr is access integer;
+
+ type list;
+
+ type list_ptr is access list;
+
+ type list is record
+ link : list_ptr;
+ value : integer;
+ end record;
+
+ function list_add(l : list_ptr; v : integer) return list_ptr is
+ variable n : list_ptr;
+ begin
+ n := new list;
+ n.link := l;
+ n.value := v;
+ return n;
+ end function;
+
+ --procedure list_print(l : in list_ptr) is
+ --begin
+ -- if l /= null then
+ -- report integer'image(l.all.value);
+ -- list_print(l.all.link);
+ -- end if;
+ --end procedure;
+
+ signal p1_done : boolean := false;
+
begin
- process is
+ p1: process is
variable p, q : int_ptr;
begin
assert p = null;
@@ -18,6 +47,28 @@ begin
assert p.all = 6;
deallocate(p);
--assert p = null;
+ p1_done <= true;
+ wait;
+ end process;
+
+ p2: process is
+ variable l, p : list_ptr;
+ begin
+ wait until p1_done;
+
+ for i in 1 to 10 loop
+ l := list_add(l, i);
+ end loop;
+
+ --p := l;
+ --while p /= null loop
+ -- --report integer'image(p.value);
+ -- p := p.link;
+ --end loop;
+
+ --list_print(l);
+ --list_free(l);
+
wait;
end process;

0 comments on commit cb27343

Please sign in to comment.