Add a preprocessor-only mode

- Very useful for testing and debugging
- Add preprocess() stub and skip compilation in preprocessor mode
This commit is contained in:
Sanne Wouda 2021-01-03 13:32:35 +00:00
parent a18e0c1782
commit 7b8a99db3c
7 changed files with 43 additions and 6 deletions

17
cc.c
View File

@ -25,14 +25,17 @@ void initialize_types();
struct token_list* read_all_tokens(FILE* a, struct token_list* current, char* filename);
struct token_list* reverse_list(struct token_list* head);
void eat_newline_tokens();
void preprocess();
void program();
void recursive_output(struct token_list* i, FILE* out);
void output_tokens(struct token_list *i, FILE* out);
int numerate_string(char *a);
int main(int argc, char** argv)
{
MAX_STRING = 4096;
BOOTSTRAP_MODE = FALSE;
PREPROCESSOR_MODE = FALSE;
int DEBUG = FALSE;
FILE* in = stdin;
FILE* destination_file = stdout;
@ -119,6 +122,11 @@ int main(int argc, char** argv)
file_print(" -f input file\n -o output file\n --help for this message\n --version for file version\n", stdout);
exit(EXIT_SUCCESS);
}
else if(match(argv[i], "-E"))
{
PREPROCESSOR_MODE = TRUE;
i = i + 1;
}
else if(match(argv[i], "-V") || match(argv[i], "--version"))
{
file_print("M2-Planet v1.7.0\n", stderr);
@ -146,6 +154,14 @@ int main(int argc, char** argv)
}
global_token = reverse_list(global_token);
preprocess();
if (PREPROCESSOR_MODE)
{
file_print("\n/* Preprocessed source */\n", destination_file);
output_tokens(global_token, destination_file);
goto exit_success;
}
/* the main parser doesn't know how to handle newline tokens */
eat_newline_tokens();
@ -166,6 +182,7 @@ int main(int argc, char** argv)
if(KNIGHT_NATIVE == Architecture) file_print("\n:STACK\n", destination_file);
else if(!DEBUG) file_print("\n:ELF_end\n", destination_file);
exit_success:
if (destination_file != stdout)
{
fclose(destination_file);

View File

@ -1923,3 +1923,13 @@ void recursive_output(struct token_list* head, FILE* out)
i = i->next;
}
}
void output_tokens(struct token_list *i, FILE* out)
{
while(NULL != i)
{
file_print(i->s, out);
file_print(" ", out);
i = i->next;
}
}

View File

@ -41,3 +41,6 @@ struct type* integer;
/* enable bootstrap-mode */
int BOOTSTRAP_MODE;
/* enable preprocessor-only mode */
int PREPROCESSOR_MODE;

View File

@ -44,3 +44,6 @@ extern struct type* integer;
/* enable bootstrap-mode */
extern int BOOTSTRAP_MODE;
/* enable preprocessor-only mode */
extern int PREPROCESSOR_MODE;

View File

@ -54,3 +54,7 @@ void eat_newline_tokens()
}
}
void preprocess()
{
}

View File

@ -169,8 +169,8 @@ a2a83f42119e646b389b98647cf6cf2aa9597185997c9453db746178c8c4c0bf test/results/t
698853b79efb30865a663c4863c050639eb21c7400008f7840830503928973d4 test/results/test0106-knight-native-binary
45c2ba61dc209d7ffa39de9ff0f0a7f8f3ea4d7e38598c72f982fcaf9a05c84a test/results/test0106-knight-posix-binary
944580ff4aae38aafac139faf6eed5bfe4ff68b01a7a3adfa346de8803101182 test/results/test0106-x86-binary
0ab012de93d082dc205137aa7e767f4c39d2609d94c9bc1bdcf08dcb9417d5cd test/results/test1000-aarch64-binary
b8b05d03088b7cff4128b618051c45f26ef386a33513d7d48c64bbdf8f8aad63 test/results/test1000-amd64-binary
bb3cb53f2717e230ea773e6366a553f834421c1427985ea101451a89d426e8c3 test/results/test1000-armv7l-binary
2a165debb8f2dbe877a6d246267e181ad49035eee07a4190a81c195098fb1abb test/results/test1000-knight-posix-binary
f9435eaaadf614936dbe2cab8fa5eb4f088b4e6bb2d25d003083671e9fb2658c test/results/test1000-x86-binary
1cd2d00f69473be2a88d80442e04c90bc3bbeae38144ee20df51a77ccb54c777 test/results/test1000-aarch64-binary
f7f32de24e8aa269fd6c90539aae84fea37d36638d069b9d7710e9491e9c467d test/results/test1000-amd64-binary
f1f6a4b5827ec9ef319ea6a7ebb6ddce9677bb7a5111a6517c67d86cd0aea550 test/results/test1000-armv7l-binary
0296515603b07ad2e28ec43cd19e89385a59af838c305fd99dd74d9f0c3879e3 test/results/test1000-knight-posix-binary
0002f0bea9345bb4c5bc712154ddf39038bd9a8300c51ddd1c97d086c74ba497 test/results/test1000-x86-binary

View File

@ -1 +1 @@
12ed7170da8642ed218a9eef2c11f65dae37cc65a331431aa7ff58063ed8734a test/test1000/proof
e5309b1a65e0627f3011fbd68aed1f6585cd9f30c620b8398841908c6730ab1a test/test1000/proof