Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add cdata codegen, with eager output support #30

Merged
merged 15 commits into from
Oct 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion fuzz/target.c
Original file line number Diff line number Diff line change
Expand Up @@ -423,7 +423,7 @@ static int
fuzz_eager_output(const uint8_t *data, size_t size)
{
if (size > 0) {
unsigned seed = data[0];
const unsigned seed = data[0];
srand(seed);
}

Expand Down
2 changes: 2 additions & 0 deletions include/fsm/print.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@ enum fsm_print_lang {
FSM_PRINT_VMC, /* ISO C90 code, VM style */
FSM_PRINT_VMDOT, /* Graphviz Dot format, showing VM opcodes */

FSM_PRINT_CDATA, /* C data tables and small interpreter */

FSM_PRINT_VMOPS_C, /* VM opcodes as a datastructure */
FSM_PRINT_VMOPS_H,
FSM_PRINT_VMOPS_MAIN
Expand Down
4 changes: 3 additions & 1 deletion src/libfsm/print.c
Original file line number Diff line number Diff line change
Expand Up @@ -327,6 +327,8 @@ fsm_print(FILE *f, const struct fsm *fsm,
case FSM_PRINT_VMC: print_vm = fsm_print_vmc; break;
case FSM_PRINT_VMDOT: print_vm = fsm_print_vmdot; break;

case FSM_PRINT_CDATA: print_ir = fsm_print_cdata; break;

case FSM_PRINT_VMOPS_C: print_vm = fsm_print_vmops_c; break;
case FSM_PRINT_VMOPS_H: print_vm = fsm_print_vmops_h; break;
case FSM_PRINT_VMOPS_MAIN: print_vm = fsm_print_vmops_main; break;
Expand Down Expand Up @@ -363,7 +365,7 @@ fsm_print(FILE *f, const struct fsm *fsm,
}

if (print_ir != NULL) {
r = print_ir(f, opt, hooks, ir);
r = print_ir(f, fsm->alloc, opt, hooks, ir);
goto done;
}

Expand Down
2 changes: 2 additions & 0 deletions src/libfsm/print.h
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ typedef int fsm_print_f(FILE *f,
const struct fsm *fsm);

typedef int ir_print_f(FILE *f,
const struct fsm_alloc *alloc,
const struct fsm_options *opt,
const struct fsm_hooks *hooks,
const struct ir *ir);
Expand Down Expand Up @@ -88,6 +89,7 @@ vm_print_f fsm_print_llvm;
vm_print_f fsm_print_rust;
vm_print_f fsm_print_sh;
vm_print_f fsm_print_vmc;
ir_print_f fsm_print_cdata;

vm_print_f fsm_print_vmdot;
vm_print_f fsm_print_vmops_c;
Expand Down
1 change: 1 addition & 0 deletions src/libfsm/print/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ SRC += src/libfsm/print/irdot.c
SRC += src/libfsm/print/irjson.c
SRC += src/libfsm/print/json.c
SRC += src/libfsm/print/llvm.c
SRC += src/libfsm/print/cdata.c
SRC += src/libfsm/print/rust.c
SRC += src/libfsm/print/sh.c
SRC += src/libfsm/print/vmasm.c
Expand Down
2 changes: 2 additions & 0 deletions src/libfsm/print/c.c
Original file line number Diff line number Diff line change
Expand Up @@ -530,11 +530,13 @@ fsm_print_c_body(FILE *f, const struct ir *ir,

int
fsm_print_c(FILE *f,
const struct fsm_alloc *alloc,
const struct fsm_options *opt,
const struct fsm_hooks *hooks,
const struct ir *ir)
{
const char *prefix;
(void)alloc;

assert(f != NULL);
assert(opt != NULL);
Expand Down
Loading