-
Notifications
You must be signed in to change notification settings - Fork 147
Major frontend refactor #313
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
base: master
Are you sure you want to change the base?
Conversation
| hashmap_free(CONSTANTS_MAP); | ||
| } | ||
|
|
||
| void dbg_token(token_t *token) |
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.
Is it needed? Use conditional build.
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.
Would it be better to use a global array to store the strings and use token->kind as the index to retrieve the corresponding one?
/* Initialize this array in global_init() */
char *token_str[NUM_OF_TOKENS];if (token->kind >= 0 && token->kind <= T_inclusion_path)
name = token_str[token->kind);
else
name = "<unknown>";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.
I've guarded this function with conditional macro namely DEBUG_BUILD defined in defs.h.
src/globals.c
Outdated
| string_literal_pool->literals = hashmap_create(256); | ||
|
|
||
| SOURCE = strbuf_create(MAX_SOURCE); | ||
| SRC_FILE_MAP = hashmap_create(8); |
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.
How about defining a new macro for the constant value 8?
| hashmap_free(CONSTANTS_MAP); | ||
| } | ||
|
|
||
| void dbg_token(token_t *token) |
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.
Would it be better to use a global array to store the strings and use token->kind as the index to retrieve the corresponding one?
/* Initialize this array in global_init() */
char *token_str[NUM_OF_TOKENS];if (token->kind >= 0 && token->kind <= T_inclusion_path)
name = token_str[token->kind);
else
name = "<unknown>";|
The initial result is benchmarked below, the memory overhead and minor performance overhead are expected to be the outcome of algorithm and data structure used in this patch:
The performance overhead is expected to be came from multiuple token stream traversal, as seen 3 times at least in lexer, preprocessor, and parser. performance benchmark (stage 0)Before
After
performance benchmark (stage 1)Before
After
|
|
There are still some improvements left to do, e.g.:
|
|
I seem to unable to reply to the latest review suggestion so I'll reply here:
Perhaps? The approach requires reorganization of token kind order, and I don't think it's necessary to just boost performance while debugging (I didn't encoutered significant performance overhead when calling it)? |
|
I'm thinking an approach to validate our compiler's expansion only compilation flag (aka
@jserv what do you think? |
Furthermore, we can adapt the preprocessor implementation from slimcc. |
This patch aims to resolve most current preprocessor issues seen in parser unit, including:
__LINE__,__FILE__.In this approach, we introduce a whole new phase dedicated to preprocessing (this practice can be seen in chibicc and other similar cc), instead of binding the preprocessing phase in few different places.
Current status
This draft is still in development, the below screenshot is comparison between result of
cpp -Eandout/shecc -E:comparison
test.c:a.c:Current major compilation workflow hasn't affected by the patch, which is expected to resolve in later commits.
Memory overhead
Memory usage increasement is expected since we now use
token_tstruct to track position, and token stream will be generated at once for preprocessor and parser to use with. Once parser finished, we expect to free all tokens.Summary by cubic
Introduces a dedicated preprocessing phase and rebuilds token handling to fix include guard behavior, add robust macro expansion, and improve error diagnostics. Adds an -E mode to output preprocessed code comparable to cpp -E.
New Features
Bug Fixes
Written for commit a62f3c9. Summary will update automatically on new commits.