From 49118f53930f4c7af396f716ca16ccdaa445a41c Mon Sep 17 00:00:00 2001 From: Kate F Date: Thu, 4 Jul 2024 08:31:34 +0100 Subject: [PATCH] An arguably less worse workaround to keep .endleaf_opaque available. --- src/libfsm/print/llvm.c | 2 +- src/re/main.c | 17 +++++++++++++---- 2 files changed, 14 insertions(+), 5 deletions(-) diff --git a/src/libfsm/print/llvm.c b/src/libfsm/print/llvm.c index a2728dafd..90828ce95 100644 --- a/src/libfsm/print/llvm.c +++ b/src/libfsm/print/llvm.c @@ -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; } diff --git a/src/re/main.c b/src/re/main.c index c29108ab9..e164279f7 100644 --- a/src/re/main.c +++ b/src/re/main.c @@ -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; @@ -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, " ; ");