Skip to content

Commit

Permalink
Create a method table for the C back end,
Browse files Browse the repository at this point in the history
#3 in the retargeting patch series.
  • Loading branch information
eric-s-raymond committed Sep 20, 2020
1 parent a05e39a commit f1bfe65
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 6 deletions.
8 changes: 8 additions & 0 deletions src/flexdef.h
Original file line number Diff line number Diff line change
Expand Up @@ -303,6 +303,12 @@
*/
#define MAX_SHORT 32700

/* Method table describing a language-specific back end */

struct flex_backend_t {
void (*prolog)(void);
void (*wrap)(void);
};

/* Declarations for global variables. */

Expand Down Expand Up @@ -369,6 +375,8 @@ extern int yymore_used, reject, real_reject, continued_action, in_rule;
extern int yymore_really_used, reject_really_used;
extern int trace_hex;

extern struct flex_backend_t *backend;

/* Variables used in the flex input routines:
* datapos - characters on current output line
* dataline - number of contiguous lines of data in current data
Expand Down
20 changes: 14 additions & 6 deletions src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -44,10 +44,9 @@ static char flex_version[] = FLEX_VERSION;

void flexinit(int, char **);
void readin(void);
void cpp_prolog(void);
void cpp_wrap(void);
void set_up_initial_allocations(void);

extern struct flex_backend_t cpp_backend;

/* these globals are all defined and commented in flexdef.h */
int printstats, syntaxerror, eofseen, ddebug, trace, nowarn, spprdflt;
Expand Down Expand Up @@ -109,6 +108,8 @@ jmp_buf flex_main_jmp_buf;
bool *rule_has_nl, *ccl_has_nl;
int nlch = '\n';

struct flex_backend_t *backend;

bool tablesext, tablesverify, gentables;
char *tablesfilename=0,*tablesname=0;
struct yytbl_writer tableswr;
Expand Down Expand Up @@ -171,7 +172,7 @@ int flex_main (int argc, char *argv[])

readin ();

cpp_prolog ();
backend->prolog ();

skelout ();
/* %% [1.5] DFA */
Expand Down Expand Up @@ -530,7 +531,7 @@ void flexend (int exit_status)
skelname);
}

cpp_wrap();
backend->wrap();

if (exit_status != 0 && outfile_created) {
if (ferror (stdout))
Expand Down Expand Up @@ -1292,6 +1293,8 @@ void flexinit (int argc, char **argv)
lastprot = 1;

set_up_initial_allocations ();

backend = &cpp_backend;
}


Expand Down Expand Up @@ -1570,7 +1573,7 @@ void usage (void)
* Unicode code-point type like Go's 'rune' is may be appropriate.
*/

void cpp_prolog (void)
static void cpp_prolog (void)
{
static char yy_stdinit[] = "FILE *yyin = stdin, *yyout = stdout;";
static char yy_nostdinit[] =
Expand Down Expand Up @@ -1702,7 +1705,7 @@ void cpp_prolog (void)
}
}

void cpp_wrap (void)
static void cpp_wrap (void)
{
#if 0
fprintf (header_out,
Expand Down Expand Up @@ -1892,3 +1895,8 @@ void cpp_wrap (void)
fclose (header_out);
#endif
}

struct flex_backend_t cpp_backend = {
.prolog = cpp_prolog,
.wrap = cpp_wrap,
};

0 comments on commit f1bfe65

Please sign in to comment.