Skip to content

Commit

Permalink
An arguably less worse workaround to keep .endleaf_opaque available.
Browse files Browse the repository at this point in the history
  • Loading branch information
katef committed Jul 4, 2024
1 parent 0ae60db commit 49118f5
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 5 deletions.
2 changes: 1 addition & 1 deletion src/libfsm/print/llvm.c
Original file line number Diff line number Diff line change
Expand Up @@ -565,7 +565,7 @@ fsm_print_llvmfrag(FILE *f, const struct dfavm_assembler_ir *a,
if (opt->endleaf != NULL) {
if (-1 == opt->endleaf(f,
retlist.a[i].ids, retlist.a[i].count,
&i)) // XXX: passing &i rather than opt->endleaf_opaque is a hack
opt->endleaf_opaque))
{
return -1;
}
Expand Down
17 changes: 13 additions & 4 deletions src/re/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -503,11 +503,20 @@ endleaf_llvm(FILE *f,
unsigned n;
size_t i;

/* hack for llvm codegen only */
const size_t *ret = endleaf_opaque;
assert(ret != NULL);
/*
* XXX: Hack for llvm codegen only, we don't have a way to pass this
* value from fsm_print_llvm(). We're working around that by making
* an assumption about the ordering for ret label numbers, that
* they're output sequentially.
*
* And also it's not very forward-thinking to keep this in static storage.
*/
static size_t ret = 0;

assert(endleaf_opaque == NULL);

(void) f;
(void) endleaf_opaque;

n = 0;

Expand All @@ -517,7 +526,7 @@ endleaf_llvm(FILE *f,
}
}

fprintf(f, "[u%#x, %%ret%zu],", (unsigned) n, *ret);
fprintf(f, "[u%#x, %%ret%zu],", (unsigned) n, ret++);

fprintf(f, " ; ");

Expand Down

0 comments on commit 49118f5

Please sign in to comment.