Skip to content
Browse files

Move signal lvalue generation into a separate function

  • Loading branch information...
1 parent fad3c9c commit 1fa7ac6ca7cb7d4208e8241295e08a18088706d9 @nickg committed May 19, 2012
Showing with 43 additions and 40 deletions.
  1. +43 −40 src/cgen.c
View
83 src/cgen.c
@@ -1767,59 +1767,62 @@ static void cgen_array_signal_store(LLVMValueRef lhs, type_t lhs_type,
LLVMBuildCall(builder, llvm_fn(name), args, ARRAY_LEN(args), "");
}
-static void cgen_signal_assign(tree_t t, cgen_ctx_t ctx)
+static LLVMValueRef cgen_signal_lvalue(tree_t t, cgen_ctx_t ctx)
{
- for (unsigned i = 0; i < tree_waveforms(t); i++) {
- tree_t w = tree_waveform(t, i);
+ switch (tree_kind(t)) {
+ case T_REF:
+ {
+ tree_t decl = tree_ref(t);
+ return cgen_array_signal_ptr(decl, llvm_int32(0));
+ }
+ break;
- tree_t target = tree_target(t);
- tree_t value = tree_value(w);
+ case T_ARRAY_REF:
+ {
+ assert(tree_kind(tree_value(t)) == T_REF);
- LLVMValueRef rhs = cgen_expr(value, ctx);
- LLVMValueRef after = (tree_has_delay(w)
- ? cgen_expr(tree_delay(w), ctx)
- : llvm_int64(0));
+ tree_t decl = tree_ref(tree_value(t));
+ assert(type_is_array(tree_type(decl)));
- LLVMValueRef p_signal = NULL;
+ param_t p = tree_param(t, 0);
+ assert(p.kind == P_POS);
- switch (tree_kind(target)) {
- case T_REF:
- {
- tree_t decl = tree_ref(target);
- p_signal = cgen_array_signal_ptr(decl, llvm_int32(0));
- }
- break;
+ LLVMValueRef elem = cgen_expr(p.value, ctx);
+ return cgen_array_signal_ptr(decl, elem);
+ }
+ break;
- case T_ARRAY_REF:
- {
- assert(tree_kind(tree_value(target)) == T_REF);
+ case T_ARRAY_SLICE:
+ {
+ assert(tree_kind(tree_value(t)) == T_REF);
- tree_t decl = tree_ref(tree_value(target));
- assert(type_kind(tree_type(decl)) == T_CARRAY);
+ tree_t decl = tree_ref(tree_value(t));
+ assert(type_kind(tree_type(decl)) == T_CARRAY);
- param_t p = tree_param(target, 0);
- assert(p.kind == P_POS);
+ LLVMValueRef low = cgen_range_low(tree_range(t), ctx);
+ return cgen_array_signal_ptr(decl, low);
+ }
+ break;
- LLVMValueRef elem = cgen_expr(p.value, ctx);
- p_signal = cgen_array_signal_ptr(decl, elem);
- }
- break;
+ default:
+ assert(false);
+ }
+}
- case T_ARRAY_SLICE:
- {
- assert(tree_kind(tree_value(target)) == T_REF);
+static void cgen_signal_assign(tree_t t, cgen_ctx_t ctx)
+{
+ for (unsigned i = 0; i < tree_waveforms(t); i++) {
+ tree_t w = tree_waveform(t, i);
- tree_t decl = tree_ref(tree_value(target));
- assert(type_kind(tree_type(decl)) == T_CARRAY);
+ tree_t target = tree_target(t);
+ tree_t value = tree_value(w);
- LLVMValueRef low = cgen_range_low(tree_range(target), ctx);
- p_signal = cgen_array_signal_ptr(decl, low);
- }
- break;
+ LLVMValueRef rhs = cgen_expr(value, ctx);
+ LLVMValueRef after = (tree_has_delay(w)
+ ? cgen_expr(tree_delay(w), ctx)
+ : llvm_int64(0));
- default:
- assert(false);
- }
+ LLVMValueRef p_signal = cgen_signal_lvalue(tree_target(t), ctx);
if (type_is_array(tree_type(value)))
cgen_array_signal_store(p_signal, tree_type(target),

0 comments on commit 1fa7ac6

Please sign in to comment.
Something went wrong with that request. Please try again.