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

Introduce codegen IR #94

Merged
merged 23 commits into from
Jul 14, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
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
1 change: 1 addition & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ SUBDIR += src/lx
SUBDIR += src
SUBDIR += tests/complement
SUBDIR += tests/intersect
SUBDIR += tests/ir
SUBDIR += tests/subtract
SUBDIR += tests/determinise
SUBDIR += tests/glob
Expand Down
12 changes: 4 additions & 8 deletions examples/iprange/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -443,21 +443,17 @@ carryopaque(const struct fsm_state **set, size_t n,
}

static int
leaf(FILE *f, const struct fsm *fsm, const struct fsm_state *state,
const void *opaque)
leaf(FILE *f, const void *state_opaque, const void *leaf_opaque)
{
const struct record *r;
const struct record *r = state_opaque;

(void) opaque;
(void) leaf_opaque;

if (!fsm_isend(fsm, state)) {
if (r == NULL) {
fprintf(f, "return -1;");
return 0;
}

r = fsm_getopaque(fsm, state);
assert(r != NULL);

fprintf(f, "return 0x%u; /* %s */", r->id, r->rec);

return 0;
Expand Down
4 changes: 2 additions & 2 deletions include/fsm/options.h
Original file line number Diff line number Diff line change
Expand Up @@ -63,11 +63,11 @@ struct fsm_options {
const char *cp;

/* TODO: explain. for C code fragment output */
int (*leaf)(FILE *, const struct fsm *, const struct fsm_state *, const void *);
int (*leaf)(FILE *, const void *state_opaque, const void *leaf_opaque);
void *leaf_opaque;

/* TODO: explain. for C code fragment output */
int (*endleaf)(FILE *, const struct fsm *, const struct fsm_state *, const void *);
int (*endleaf)(FILE *, const void *state_opaque, const void *endleaf_opaque);
void *endleaf_opaque;

/* TODO: explain */
Expand Down
14 changes: 9 additions & 5 deletions include/fsm/print.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,13 @@ struct fsm;
* Print an FSM to the given file stream. The output is written in the format
* specified. The available formats are:
*
* fsm_print_api - C code which calls the fsm(3) API
* fsm_print_c - ISO C90 code
* fsm_print_dot - Graphviz Dot format, intended for rendering graphically
* fsm_print_fsm - fsm(5) .fsm format, suitable for parsing by fsm(1)
* fsm_print_json - JavaScript Object Notation
* fsm_print_api - C code which calls the fsm(3) API
* fsm_print_c - ISO C90 code
* fsm_print_dot - Graphviz Dot format, intended for rendering graphically
* fsm_print_fsm - fsm(5) .fsm format, suitable for parsing by fsm(1)
* fsm_print_ir - Codegen IR as Dot
* fsm_print_irjson - Codegen IR as JSON
* fsm_print_json - JavaScript Object Notation
*
* The output options may be NULL, indicating to use defaults.
*
Expand All @@ -33,6 +35,8 @@ fsm_print fsm_print_api;
fsm_print fsm_print_c;
fsm_print fsm_print_dot;
fsm_print fsm_print_fsm;
fsm_print fsm_print_ir;
fsm_print fsm_print_irjson;
fsm_print fsm_print_json;

#endif
Expand Down
1 change: 1 addition & 0 deletions man/fsm.1/fsm.1.xml
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@
<!ENTITY c.lit "<literal>c</literal>">
<!ENTITY dot.lit "<literal>dot</literal>">
<!ENTITY fsm.lit "<literal>fsm</literal>">
<!ENTITY ir.lit "<literal>ir</literal>">
<!ENTITY json.lit "<literal>json</literal>">
]>

Expand Down
6 changes: 6 additions & 0 deletions man/fsm_lang.5fsm/fsm_lang.5fsm.xml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
<!ENTITY c.lit "<literal>c</literal>">
<!ENTITY dot.lit "<literal>dot</literal>">
<!ENTITY fsm.lit "<literal>fsm</literal>">
<!ENTITY ir.lit "<literal>ir</literal>">
<!ENTITY json.lit "<literal>json</literal>">
]>

Expand Down Expand Up @@ -71,6 +72,11 @@ TODO: blurb
<td>&fsm.ext;</td>
<td>TODO</td>
</tr>
<tr>
<td>&ir.lit;</td>
<td>&ir.ext;</td>
<td>TODO</td>
</tr>
<tr>
<td>&json.lit;</td>
<td>&json.ext;</td>
Expand Down
Loading