diff --git a/cc.c b/cc.c index da384b8..1ef8516 100644 --- a/cc.c +++ b/cc.c @@ -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); diff --git a/cc_core.c b/cc_core.c index 9270a08..b8c6536 100644 --- a/cc_core.c +++ b/cc_core.c @@ -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; + } +} diff --git a/cc_globals.c b/cc_globals.c index ee74fa4..13f0036 100644 --- a/cc_globals.c +++ b/cc_globals.c @@ -41,3 +41,6 @@ struct type* integer; /* enable bootstrap-mode */ int BOOTSTRAP_MODE; + +/* enable preprocessor-only mode */ +int PREPROCESSOR_MODE; diff --git a/cc_globals.h b/cc_globals.h index 87f520a..cdac985 100644 --- a/cc_globals.h +++ b/cc_globals.h @@ -44,3 +44,6 @@ extern struct type* integer; /* enable bootstrap-mode */ extern int BOOTSTRAP_MODE; + +/* enable preprocessor-only mode */ +extern int PREPROCESSOR_MODE; diff --git a/cc_macro.c b/cc_macro.c index 89af676..14f441a 100644 --- a/cc_macro.c +++ b/cc_macro.c @@ -54,3 +54,7 @@ void eat_newline_tokens() } } + +void preprocess() +{ +} diff --git a/test/test.answers b/test/test.answers index c628e7d..5fb29ab 100644 --- a/test/test.answers +++ b/test/test.answers @@ -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 diff --git a/test/test1000/proof.answer b/test/test1000/proof.answer index e3654e1..0e31ff7 100644 --- a/test/test1000/proof.answer +++ b/test/test1000/proof.answer @@ -1 +1 @@ -12ed7170da8642ed218a9eef2c11f65dae37cc65a331431aa7ff58063ed8734a test/test1000/proof +e5309b1a65e0627f3011fbd68aed1f6585cd9f30c620b8398841908c6730ab1a test/test1000/proof