-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implement Late Externalization for STRONG externalization type
Take the following code as example: ``` \#include <stdio.h> int main(void) { printf("Hello, world\n"); return 0; } ``` And assume we want to strongly externalize the function `printf`. The resulting code would be: ``` \#define _STDIO_H 1 \#define __GLIBC_INTERNAL_STARTING_HEADER_IMPLEMENTATION \#include <bits/libc-header-start.h> \#define __need_size_t \#define __need_NULL \#include <stddef.h> \#define __need___va_list \#include <stdarg.h> \#include <bits/types.h> \#include <bits/types/__fpos_t.h> \#include <bits/types/__fpos64_t.h> \#include <bits/types/__FILE.h> \#include <bits/types/FILE.h> \#include <bits/types/struct_FILE.h> \# include <bits/types/cookie_io_functions_t.h> \#define L_tmpnam 20 \#include <bits/stdio_lim.h> \#define __attr_dealloc_fclose __attr_dealloc (fclose, 1) /** clang-extract: from /usr/include/stdio.h:361:1 */ static int (*klpe_printf)(const char *restrict, ...); \#include <bits/floatn.h> /** clang-extract: from /tmp/rewrite-3.c:5:1 */ int main(void) { (*klpe_printf)("Hello, world!\n"); return 0; } ``` Clearly, those headers and defines could be avoided. For example, this would be perfectly valid: ``` \#include <stdio.h> /** clang-extract: from /tmp/rewrite-3.c:5:1 */ static int (*klpe_printf)(const char *restrict, ...); /** clang-extract: from /tmp/rewrite-3.c:4:1 */ int main(void) { (*klpe_printf)("Hello, world!\n"); return 0; } ``` Because the definition of `klpe_printf` is located right before its first use. This commit does this by computing a possible place where the externalized variable can be output *just before* the first use, hence we externalize the variable later than the original code would suggest. To enable this option, the user must pass `-DCE_LATE_EXTERNALIZE` to clang-extract. Signed-off-by: Giuliano Belinassi <[email protected]>
- Loading branch information
1 parent
d8e2bb0
commit 74a63c6
Showing
19 changed files
with
371 additions
and
49 deletions.
There are no files selected for viewing
This file contains 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 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 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 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 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 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 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
Oops, something went wrong.