Permalink
Browse files

Code generation for nested array references

  • Loading branch information...
1 parent eee3f78 commit 62716eaacb162c7f4fcf144541e1a545dc59ea6c @nickg committed Aug 12, 2012
Showing with 17 additions and 8 deletions.
  1. +16 −7 src/cgen.c
  2. +1 −1 test/regress/signal8.vhd
View
@@ -1241,16 +1241,23 @@ static LLVMValueRef cgen_array_data_ptr(type_t type, LLVMValueRef var)
static LLVMValueRef cgen_array_ref(tree_t t, cgen_ctx_t *ctx)
{
- assert(tree_kind(tree_value(t)) == T_REF);
+ tree_t decl = NULL;
+ class_t class = C_VARIABLE;
+ LLVMValueRef array = NULL;
- tree_t decl = tree_ref(tree_value(t));
- type_t type = tree_type(decl);
+ tree_t value = tree_value(t);
+ if (tree_kind(value) == T_REF) {
+ decl = tree_ref(value);
- LLVMValueRef array = NULL;
- class_t class = cgen_get_class(decl);
+ class = cgen_get_class(decl);
- if (class == C_VARIABLE || class == C_CONSTANT || class == C_DEFAULT)
- array = cgen_get_var(decl, ctx);
+ if (class == C_VARIABLE || class == C_CONSTANT || class == C_DEFAULT)
+ array = cgen_get_var(decl, ctx);
+ }
+ else
+ array = cgen_expr(value, ctx);
+
+ type_t type = tree_type(value);
LLVMValueRef idx = llvm_int32(0);
for (unsigned i = 0; i < tree_params(t); i++) {
@@ -1283,6 +1290,8 @@ static LLVMValueRef cgen_array_ref(tree_t t, cgen_ctx_t *ctx)
case C_SIGNAL:
{
+ assert(decl != NULL);
+
LLVMValueRef signal_array = tree_attr_ptr(decl, sig_struct_i);
LLVMValueRef indexes[] = { llvm_int32(0), idx };
LLVMValueRef signal = LLVMBuildGEP(builder, signal_array,
View
@@ -22,7 +22,7 @@ begin
-- report "b(" & integer'image(i) & ") = " & integer'image(b(i));
--end loop;
assert b = ( 1, 99, 3, 4 );
--- assert a(1)(2) = 2;
+ assert a(1)(2) = 99;
-- a := ( others => ( 1, 2, 3, 4 ) );
-- b := a(1);
-- assert b = ( 1, 2, 3, 4);

0 comments on commit 62716ea

Please sign in to comment.