Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Fix invalid LLVM module from recursive procedure

  • Loading branch information...
commit 7c97446005fc23d782799d511f0268383c0b9122 1 parent cb27343
Nick Gasson authored
49 src/cgen.c
@@ -2466,38 +2466,44 @@ static void cgen_case(tree_t t, cgen_ctx_t *ctx)
2466 2466 cgen_case_scalar(t, ctx);
2467 2467 }
2468 2468
  2469 +static void cgen_builtin_pcall(ident_t builtin, LLVMValueRef *args)
  2470 +{
  2471 + if (icmp(builtin, "deallocate")) {
  2472 + LLVMBuildFree(builder, args[0]);
  2473 + // XXX: setting pointer to NULL broken until inout parameters work
  2474 + //LLVMBuildStore(builder, LLVMConstNull(LLVMTypeOf(args[0])), args[0]);
  2475 + }
  2476 + else
  2477 + fatal("cannot generate code for builtin %s", istr(builtin));
  2478 +}
  2479 +
2469 2480 static void cgen_pcall(tree_t t, cgen_ctx_t *ctx)
2470 2481 {
2471 2482 tree_t decl = tree_ref(t);
2472 2483
2473   - const int nparams = tree_params(t);
2474   - LLVMValueRef args[nparams + 1];
2475   - cgen_call_args(t, args, ctx);
2476   -
2477   - // Final parameter to a procedure is its dynamic context
2478   - args[nparams] = NULL;
2479   -
2480 2484 const bool in_function =
2481 2485 (ctx->fdecl != NULL) && (tree_kind(ctx->fdecl) == T_FUNC_BODY);
2482 2486
  2487 + const int nparams = tree_params(t);
  2488 +
2483 2489 ident_t builtin = tree_attr_str(decl, ident_new("builtin"));
2484   - if (builtin != NULL) {
2485   - if (icmp(builtin, "deallocate")) {
2486   - LLVMBuildFree(builder, args[0]);
2487   - // XXX: setting pointer to NULL broken until inout parameters work
2488   - //LLVMBuildStore(builder, LLVMConstNull(LLVMTypeOf(args[0])), args[0]);
2489   - }
2490   - else
2491   - fatal_at(tree_loc(t), "cannot generate code for builtin %s",
2492   - istr(builtin));
2493   - return;
2494   - }
2495 2490
2496   - if (tree_attr_int(decl, never_waits_i, 0) || in_function) {
  2491 + if (tree_attr_int(decl, never_waits_i, 0) || in_function || builtin) {
2497 2492 // Simple case where the called procedure never waits so we can ignore
2498 2493 // the return value
  2494 +
  2495 + LLVMValueRef args[nparams + 1];
  2496 + cgen_call_args(t, args, ctx);
  2497 +
  2498 + // Final parameter to a procedure is its dynamic context
2499 2499 args[nparams] = LLVMConstNull(llvm_void_ptr());
2500   - LLVMBuildCall(builder, cgen_pdecl(decl), args, nparams + 1, "");
  2500 +
  2501 + if (builtin != NULL)
  2502 + cgen_builtin_pcall(builtin, args);
  2503 + else {
  2504 + // Regular procedure call
  2505 + LLVMBuildCall(builder, cgen_pdecl(decl), args, nparams + 1, "");
  2506 + }
2501 2507 }
2502 2508 else {
2503 2509 // Find the basic block to jump to when the procedure resumes
@@ -2515,7 +2521,10 @@ static void cgen_pcall(tree_t t, cgen_ctx_t *ctx)
2515 2521 LLVMValueRef context_ptr = LLVMBuildStructGEP(builder, ctx->state, 1, "");
2516 2522 LLVMBuildStore(builder, llvm_int32(it->state_num), state_ptr);
2517 2523
  2524 + LLVMValueRef args[nparams + 1];
  2525 + cgen_call_args(t, args, ctx);
2518 2526 args[nparams] = LLVMBuildLoad(builder, context_ptr, "context");
  2527 +
2519 2528 LLVMValueRef ret =
2520 2529 LLVMBuildCall(builder, cgen_pdecl(decl), args, nparams + 1, "");
2521 2530
22 test/regress/access1.vhd
@@ -22,13 +22,13 @@ architecture test of access1 is
22 22 return n;
23 23 end function;
24 24
25   - --procedure list_print(l : in list_ptr) is
26   - --begin
27   - -- if l /= null then
28   - -- report integer'image(l.all.value);
29   - -- list_print(l.all.link);
30   - -- end if;
31   - --end procedure;
  25 + procedure list_print(l : in list_ptr) is
  26 + begin
  27 + if l /= null then
  28 + report integer'image(l.all.value);
  29 + list_print(l.all.link);
  30 + end if;
  31 + end procedure;
32 32
33 33 signal p1_done : boolean := false;
34 34
@@ -60,13 +60,7 @@ begin
60 60 l := list_add(l, i);
61 61 end loop;
62 62
63   - --p := l;
64   - --while p /= null loop
65   - -- --report integer'image(p.value);
66   - -- p := p.link;
67   - --end loop;
68   -
69   - --list_print(l);
  63 + list_print(l);
70 64 --list_free(l);
71 65
72 66 wait;
10 test/regress/gold/access1.txt
... ... @@ -0,0 +1,10 @@
  1 +0ms+1: Report Note: 10
  2 +0ms+1: Report Note: 9
  3 +0ms+1: Report Note: 8
  4 +0ms+1: Report Note: 7
  5 +0ms+1: Report Note: 6
  6 +0ms+1: Report Note: 5
  7 +0ms+1: Report Note: 4
  8 +0ms+1: Report Note: 3
  9 +0ms+1: Report Note: 2
  10 +0ms+1: Report Note: 1
2  test/regress/testlist.txt
@@ -77,4 +77,4 @@ driver2 normal
77 77 delay1 normal
78 78 record1 normal
79 79 proc3 normal
80   -access1 normal
  80 +access1 normal,gold

0 comments on commit 7c97446

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