-
-
Notifications
You must be signed in to change notification settings - Fork 573
FOR COMMENT ONLY Skel backends #710
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
Draft
Mightyjo
wants to merge
39
commits into
westes:master
Choose a base branch
from
Mightyjo:skel_backends
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from 1 commit
Commits
Show all changes
39 commits
Select commit
Hold shift + click to select a range
bd9bed7
refactor(backend): Begin definition of C backend
Mightyjo a70446c
refactor(backends): Replace out* calls with backend emits.
Mightyjo c6b4e93
refactor(backend): Hide backend implementation details.
Mightyjo ffdfe88
feat(backend): Add backend stack.
Mightyjo eb2330d
fix: Restore BUILT_SOURCES because parallel builds are broken
Mightyjo 2874c68
feat: Shakeout backend stack bugs
Mightyjo aeb7715
feat: Shakeout backend stack bugs
Mightyjo d4e058e
feat: Shakeout backend stack bugs
Mightyjo 7404570
fix: Add BUILT_SOURCES sync points for parallel make
Mightyjo ba8e9f1
test: Rename alloc_extra_r.l to match it's reentrant behavior
Mightyjo ce6091b
test: Add reentrant option to c99 tests
Mightyjo ac5656d
test: Add reentrant option to c99 tests
Mightyjo ae9c274
test\!: UNDO Turn off tests for fake Go backend
Mightyjo bfedecf
test\!: UNDO Turn off tests for fake Go backend
Mightyjo 49b6857
feat(skel): Add DEAFULT skel ID to enum
Mightyjo 1d041ed
feat(skel): Comment backend api
Mightyjo b1bec53
feat(skel): remove out, outn, outc, and comment methods
Mightyjo 4c48cc3
feat: Improve comments
Mightyjo 468f83f
feat: Refactor out_m4_define away
Mightyjo 538a0df
feat: Refactor YY_SC_DEFS emission
Mightyjo 3a02656
feat: Refactor out_m4_define away
Mightyjo 8000f16
feat: Refactor out_str_dec away
Mightyjo 25547c4
feat: Remove out_hex
Mightyjo e6ba991
feat: Remove out_dec
Mightyjo 8093d7c
feat: Remove out_dec2
Mightyjo d744205
feat: Remove out_str
Mightyjo 625864e
feat: Name backend handle more clearly
Mightyjo eafe5ee
feat: Name backend handle more clearly
Mightyjo 9380076
feat: Refactor use of optimize_pack output
Mightyjo 4720aab
feat: Add C99 backend
Mightyjo fd0d12b
feat: Add C99 backend
Mightyjo 259052d
revert: 3a368c0 and 91982ad
Mightyjo 9c0d379
feat: Refactor format string getters out of emission code for use in …
Mightyjo 5d34821
feat: Refactor common emitter code into skeletons.c
Mightyjo ca18127
feat: Replace M4_HOOK with backend calls in parse.y
Mightyjo df8b0f2
feat: Set backend in parse.y when ctrl.emit option is recognized.
Mightyjo 23d1533
feat: Fix conditional blocking around backend setup in parse.y
Mightyjo 1b91cde
Remove mistakenly tracked tests outputs
Mightyjo 31777cd
chore: Remove committed test binary
Mightyjo File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,351 @@ | ||
| /* cpp-backend.c - C++ backend file for flex */ | ||
|
|
||
| /* Copyright (c) 1990 The Regents of the University of California. */ | ||
| /* All rights reserved. */ | ||
|
|
||
| /* This code is derived from software contributed to Berkeley by */ | ||
| /* Vern Paxson. */ | ||
|
|
||
| /* The United States Government has rights in this work pursuant */ | ||
| /* to contract no. DE-AC03-76SF00098 between the United States */ | ||
| /* Department of Energy and the University of California. */ | ||
|
|
||
| /* This file is part of flex. */ | ||
|
|
||
| /* Redistribution and use in source and binary forms, with or without */ | ||
| /* modification, are permitted provided that the following conditions */ | ||
| /* are met: */ | ||
|
|
||
| /* 1. Redistributions of source code must retain the above copyright */ | ||
| /* notice, this list of conditions and the following disclaimer. */ | ||
| /* 2. Redistributions in binary form must reproduce the above copyright */ | ||
| /* notice, this list of conditions and the following disclaimer in the */ | ||
| /* documentation and/or other materials provided with the distribution. */ | ||
|
|
||
| /* Neither the name of the University nor the names of its contributors */ | ||
| /* may be used to endorse or promote products derived from this software */ | ||
| /* without specific prior written permission. */ | ||
|
|
||
| /* THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR */ | ||
| /* IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED */ | ||
| /* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR */ | ||
| /* PURPOSE. */ | ||
|
|
||
|
|
||
| #include "flexdef.h" | ||
| #include "cpp-backend.h" | ||
|
|
||
| const int CPP_BACKEND_MAX_INDENT = 256; | ||
|
|
||
| const char *cpp_skel[] = { | ||
| #include "cpp-flex.h" | ||
| 0 | ||
| }; | ||
|
|
||
| const char * cpp_get_int32_type ( struct flex_backend_t *b ) { | ||
| return "flex_int32_t"; | ||
| } | ||
|
|
||
| static const char * cpp_get_int16_type ( struct flex_backend_t *b ) { | ||
| return "flex_int16_t"; | ||
| } | ||
|
|
||
| static void cpp_open_block_comment ( struct flex_backend_t *b ) { | ||
| fputs("/* ", stdout); | ||
| } | ||
|
|
||
| static void cpp_close_block_comment ( struct flex_backend_t *b ) { | ||
| fputs(" */", stdout); | ||
| } | ||
|
|
||
| static void cpp_comment ( struct flex_backend_t *b, const char *c ) { | ||
| b->indent(b); | ||
| fprintf(stdout, "/* %s */", c); | ||
| } | ||
|
|
||
| static void cpp_record_separator ( struct flex_backend_t *b ) { | ||
| fputs("},\n", stdout); | ||
| } | ||
|
|
||
| static void cpp_column_separator ( struct flex_backend_t *b ){ | ||
| fputs(", ", stdout); | ||
| } | ||
|
|
||
| static void cpp_newline ( struct flex_backend_t *b ) { | ||
| fputs("\n", stdout); | ||
| } | ||
|
|
||
| static void cpp_increase_indent ( struct flex_backend_t *b ) { | ||
| if ( b->indent_level < CPP_BACKEND_MAX_INDENT ) { | ||
| b->indent_level += 1; | ||
| } | ||
| } | ||
|
|
||
| static void cpp_decrease_indent ( struct flex_backend_t *b ) { | ||
| if (b->indent_level > 0) { | ||
| b->indent_level -= 1; | ||
| } | ||
| } | ||
|
|
||
| static void cpp_indent ( struct flex_backend_t *b ) { | ||
| int i = 0; | ||
| while ( i < b->indent_level ) { | ||
| fputs("\t", stdout); | ||
| ++i; | ||
| } | ||
| } | ||
|
|
||
| static const char * cpp_get_trace_line_format ( struct flex_backend_t *b ) { | ||
| return "#line %d \"%s\"\n"; | ||
| } | ||
|
|
||
| static void cpp_line_directive_out ( struct flex_backend_t * b, FILE *output_file, char *path, int linenum ) { | ||
| char directive[MAXLINE*2], filename[MAXLINE]; | ||
| char *s1, *s2, *s3; | ||
|
|
||
| if (!ctrl.gen_line_dirs) { | ||
| return; | ||
| } | ||
|
|
||
| /* char *infilename is in the global namespace */ | ||
| s1 = (path != NULL) ? path : infilename; | ||
|
|
||
| if ((path != NULL) && !s1) { | ||
| s1 = "<stdin>"; | ||
| } | ||
|
|
||
| s2 = filename; | ||
| s3 = &filename[sizeof (filename) - 2]; | ||
|
|
||
| while (s2 < s3 && *s1) { | ||
| if (*s1 == '\\' || *s1 == '"') { | ||
| /* Escape the '\' or '"' */ | ||
| *s2++ = '\\'; | ||
| } | ||
|
|
||
| *s2++ = *s1++; | ||
| } | ||
|
|
||
| *s2 = '\0'; | ||
|
|
||
| if (path != NULL) { | ||
| snprintf (directive, sizeof(directive), b->get_trace_line_format(b), linenum, filename); | ||
| } else { | ||
| snprintf (directive, sizeof(directive), b->get_trace_line_format(b), 0, filename); | ||
| } | ||
|
|
||
| /* If output_file is nil then we should put the directive in | ||
| * the accumulated actions. | ||
| */ | ||
| if (output_file) { | ||
| fputs (directive, output_file); | ||
| } | ||
| else { | ||
| add_action (directive); | ||
| } | ||
| } | ||
|
|
||
| static void cpp_open_table ( struct flex_backend_t *b ) { | ||
| fputs("{", stdout); | ||
| } | ||
|
|
||
| static void cpp_continue_table ( struct flex_backend_t *b ) { | ||
| fputs("},\n", stdout); | ||
| } | ||
|
|
||
| static void cpp_close_table ( struct flex_backend_t *b ) { | ||
| fputs("};\n", stdout); | ||
| } | ||
|
|
||
| static void cpp_relativize ( struct flex_backend_t *b, const char *s ) { | ||
| fputs(s, stdout); | ||
| } | ||
|
|
||
| static void cpp_format_state_table_entry ( struct flex_backend_t * b, int t ) { | ||
| b->indent(b); | ||
| fprintf(stdout, "&yy_transition[%d],\n", t); | ||
| } | ||
|
|
||
| static void cpp_format_normal_state_case_arm ( struct flex_backend_t *b, int c ) { | ||
| b->indent(b); | ||
| fprintf(stdout, "case %d:", c); | ||
| } | ||
|
|
||
| static void cpp_format_eof_state_case_arm ( struct flex_backend_t *b, int c ) { | ||
| b->indent(b); | ||
| fprintf(stdout, "case YY_STATE_EOF(%d):", c); | ||
| } | ||
|
|
||
| static void cpp_eof_state_case_fallthrough ( struct flex_backend_t *b ) { | ||
| b->indent(b); | ||
| b->comment(b, "FALLTHROUGH"); | ||
| } | ||
|
|
||
| static void cpp_eof_state_case_terminate ( struct flex_backend_t *b ) { | ||
| b->indent(b); | ||
| fputs("yyterminate();\n", stdout); | ||
| } | ||
|
|
||
| static void cpp_take_yytext ( struct flex_backend_t *b ) { | ||
| b->indent(b); | ||
| fputs("YY_DO_BEFORE_ACTION; /* set up yytext */", stdout); | ||
| } | ||
|
|
||
| static void cpp_release_yytext ( struct flex_backend_t *b ) { | ||
| b->indent(b); | ||
| fputs( "*yy_cp = YY_G(yy_hold_char); /* undo effects of setting up yytext */", stdout); | ||
| } | ||
|
|
||
| static void cpp_format_char_rewind ( struct flex_backend_t *b, int c ) { | ||
| b->indent(b); | ||
| fprintf(stdout, "YY_G(yy_c_buf_p) = yy_cp -= %d;", c); | ||
| } | ||
|
|
||
| static void cpp_format_line_rewind ( struct flex_backend_t *b, int l ) { | ||
| b->indent(b); | ||
| fprintf(stdout, "YY_LINENO_REWIND_TO(yy_cp - %d);", l); | ||
| } | ||
|
|
||
| static void cpp_format_char_forward ( struct flex_backend_t *b, int c ) { | ||
| b->indent(b); | ||
| fprintf(stdout, "YY_G(yy_c_buf_p) = yy_cp = yy_bp + %d;", c); | ||
| } | ||
|
|
||
| static void cpp_format_line_forward ( struct flex_backend_t *b, int l ) { | ||
| b->indent(b); | ||
| fprintf(stdout, "YY_LINENO_REWIND_TO(yy_bp + %d);", l); | ||
| } | ||
|
|
||
| static void cpp_format_byte_const ( struct flex_backend_t *b, const char *n, const int c ) { | ||
| fprintf(stdout, "#define %s %d\n", n, c); | ||
| } | ||
|
|
||
| static void cpp_format_state_const ( struct flex_backend_t *b, const char *n, const int s ) { | ||
| fprintf(stdout, "#define %s %d\n", n, s); | ||
| } | ||
|
|
||
| static void cpp_format_uint_const ( struct flex_backend_t *b, const char *n, const unsigned int u ) { | ||
| fprintf(stdout, "#define %s %u\n", n, u); | ||
| } | ||
|
|
||
| static void cpp_format_bool_const ( struct flex_backend_t *b, const char *n, const int t ){ | ||
| fprintf(stdout, "#define %s %d\n", n, t); | ||
| } | ||
|
|
||
| static void cpp_format_const ( struct flex_backend_t *b, const char *n, const char *v ) { | ||
| fprintf(stdout, "#define %s %s\n", n, v); | ||
| } | ||
|
|
||
| static void cpp_format_offset_type ( struct flex_backend_t *b, const char *t ) { | ||
| b->format_const(b, "YY_OFFSET_TYPE", t); | ||
| } | ||
|
|
||
| static void cpp_format_yy_decl ( struct flex_backend_t *b, const char *d ) { | ||
| b->format_const(b, "YY_DECL", d); | ||
| } | ||
|
|
||
| static void cpp_format_userinit ( struct flex_backend_t *b, const char *d ) { | ||
| b->format_const(b, "YY_USER_INIT", d); | ||
| } | ||
|
|
||
| static void cpp_format_rule_setup ( struct flex_backend_t *b ) { | ||
| b->relativize(b, "YY_RULE_SETUP"); | ||
| b->newline(b); | ||
| } | ||
|
|
||
| static void cpp_format_user_preaction ( struct flex_backend_t *b, const char *d ) { | ||
| b->format_const(b, "YY_USER_ACTION", d); | ||
| } | ||
|
|
||
| static void cpp_format_state_case_break ( struct flex_backend_t *b ) { | ||
| b->indent(b); | ||
| if (!ctrl.postaction) { | ||
| fputs("/*LINTED*/break;", stdout); | ||
| } | ||
| else { | ||
| fputs(ctrl.postaction, stdout); | ||
| } | ||
| } | ||
|
|
||
| static void cpp_format_user_postaction ( struct flex_backend_t *b, const char *d ) { | ||
| if (d != NULL) { | ||
| b->format_const(b, "YY_STATE_CASE_BREAK", d); | ||
| } | ||
| else { | ||
| b->format_const(b, "YY_STATE_CASE_BREAK", "/*LINTED*/break;"); | ||
| } | ||
| } | ||
|
|
||
| static void cpp_format_fatal_error ( struct flex_backend_t *b, const char *e ) { | ||
| b->indent(b); | ||
| fprintf(stdout, "yypanic(%s M4_YY_CALL_LAST_ARG);", e); | ||
| } | ||
|
|
||
| static void cpp_echo ( struct flex_backend_t *b ) { | ||
| b->indent(b); | ||
| fputs("yyecho();", stdout); | ||
| } | ||
|
|
||
| static void cpp_format_yyterminate ( struct flex_backend_t *b, const char *d ) { | ||
| if (d != NULL) { | ||
| b->format_const(b, "yyterminate", d); | ||
| } | ||
| else { | ||
| b->format_const(b, "yyterminate", "return NULL"); | ||
| } | ||
| } | ||
|
|
||
| static void cpp_format_yyreject ( struct flex_backend_t *b ) { | ||
| b->indent(b); | ||
| fputs("yyreject()", stdout); | ||
| } | ||
|
|
||
| struct flex_backend_t cpp_backend = { | ||
| .skel = cpp_skel, | ||
| .indent_level = 0, | ||
| .get_int32_type = cpp_get_int32_type, | ||
| .get_int16_type = cpp_get_int16_type, | ||
| .open_block_comment = cpp_open_block_comment, | ||
| .close_block_comment = cpp_close_block_comment, | ||
| .comment = cpp_comment, | ||
| .record_separator = cpp_record_separator, | ||
| .column_separator = cpp_column_separator, | ||
| .newline = cpp_newline, | ||
| .increase_indent = cpp_increase_indent, | ||
| .decrease_indent = cpp_decrease_indent, | ||
| .indent = cpp_indent, | ||
| .get_trace_line_format = cpp_get_trace_line_format, | ||
| .line_directive_out = cpp_line_directive_out, | ||
| .open_table = cpp_open_table, | ||
| .continue_table = cpp_continue_table, | ||
| .close_table = cpp_close_table, | ||
| .relativize = cpp_relativize, | ||
| .format_state_table_entry = cpp_format_state_table_entry, | ||
| .format_normal_state_case_arm = cpp_format_normal_state_case_arm, | ||
| .format_eof_state_case_arm = cpp_format_eof_state_case_arm, | ||
| .eof_state_case_fallthrough = cpp_eof_state_case_fallthrough, | ||
| .eof_state_case_terminate = cpp_eof_state_case_terminate, | ||
| .take_yytext = cpp_take_yytext, | ||
| .release_yytext = cpp_release_yytext, | ||
| .format_char_rewind = cpp_format_char_rewind, | ||
| .format_line_rewind = cpp_format_line_rewind, | ||
| .format_char_forward = cpp_format_char_forward, | ||
| .format_line_forward = cpp_format_line_forward, | ||
| .format_byte_const = cpp_format_byte_const, | ||
| .format_state_const = cpp_format_state_const, | ||
| .format_uint_const = cpp_format_uint_const, | ||
| .format_bool_const = cpp_format_bool_const, | ||
| .format_const = cpp_format_const, | ||
| .format_offset_type = cpp_format_offset_type, | ||
| .format_yy_decl = cpp_format_yy_decl, | ||
| .format_userinit = cpp_format_userinit, | ||
| .format_rule_setup = cpp_format_rule_setup, | ||
| .format_user_preaction = cpp_format_user_preaction, | ||
| .format_state_case_break = cpp_format_state_case_break, | ||
| .format_user_postaction = cpp_format_user_postaction, | ||
| .format_fatal_error = cpp_format_fatal_error, | ||
| .echo = cpp_echo, | ||
| .format_yyterminate = cpp_format_yyterminate, | ||
| .format_yyreject = cpp_format_yyreject | ||
| }; | ||
|
|
||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Try adding this line in src/Makefile.am to fix the dependency problem:
cpp-backend.$(OBJEXT): cpp-flex.hThat way you won't need BUILT_SOURCES for the job.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That's what I thought too, but make started telling me it was ignoring these rules with the message, "ignoring prerequisites on suffix rule definition." It is still running our instructions again, it's just not enforcing the strict ordering we specify. While I always see that message from make, the ordering doesn't seem to cause a problem for make -j 8 or less.
The most recent version of the Automake manual I read goes into more detail on this pattern than I've seen before. I expect between that and what you've already written we'll figure it out.
I'm going to drop that patch from this and the breakout I'm doing now.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This suggested change is nothing to do with the suffix rule.
The "suffix rule" in makefiles will look like this:
.c.o: $(CC) -c $(CFLAGS) $(CPPFLAGS) -o $@ $<Note the two file extensions (
.c.o) specified together.What I suggested (
cpp-backend.$(OBJEXT): cpp-flex.h) is to tellmakeabout a dependency. Sincecpp-flex.his built,makeneeds to be told thatcpp-backend.ocannot be made in parallel withcpp-flex.h, but the former needs to wait for the latter.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You're right, those warnings are coming from tests/Makefile.am at lines 325, 328, and 362. Suffix rules I added a decade ago.
Working on a fix. Maybe they're what's been jamming my wide builds, idk.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
https://github.com/westes/flex/pull/710/changes#diff-32103f666ff2fb42b025a47ccf1b959bbcc6db89f217e5943b1de73c81a4f9dbL325
A workaround is to use this: