From 8007ae9ce69a8369579d3b18483df33cb780d38d Mon Sep 17 00:00:00 2001 From: Jeremiah Orians Date: Fri, 5 Feb 2021 20:39:54 -0500 Subject: [PATCH] Add support for #if defined(__M2__) to enable M2-Planet specific functionality --- cc.c | 2 ++ cc_macro.c | 12 ++++++++++++ test/test.answers | 10 +++++----- test/test1000/proof.answer | 2 +- 4 files changed, 20 insertions(+), 6 deletions(-) diff --git a/cc.c b/cc.c index cf57bf8..8a69b1c 100644 --- a/cc.c +++ b/cc.c @@ -30,6 +30,7 @@ struct token_list* remove_line_comment_tokens(struct token_list* head); struct token_list* remove_preprocessor_directives(struct token_list* head); void eat_newline_tokens(); +void init_macro_env(char* sym, char* value, char* source, int num); void preprocess(); void program(); void recursive_output(struct token_list* i, FILE* out); @@ -45,6 +46,7 @@ int main(int argc, char** argv) FILE* in = stdin; FILE* destination_file = stdout; Architecture = KNIGHT_NATIVE; /* Assume Knight-native */ + init_macro_env("__M2__", "42", "__INTERNAL_M2__", 0); /* Setup __M2__ */ char* arch; char* name; diff --git a/cc_macro.c b/cc_macro.c index 81a4a38..f23f6c1 100644 --- a/cc_macro.c +++ b/cc_macro.c @@ -42,6 +42,18 @@ struct conditional_inclusion* conditional_inclusion_top; /* point where we are currently modifying the global_token list */ struct token_list* macro_token; +void init_macro_env(char* sym, char* value, char* source, int num) +{ + struct macro_list* hold = macro_env; + macro_env = calloc(1, sizeof(struct macro_list)); + macro_env->symbol = sym; + macro_env->next = hold; + macro_env->expansion = calloc(1, sizeof(struct token_list)); + macro_env->expansion->s = value; + macro_env->expansion->filename = source; + macro_env->expansion->linenumber = num; +} + void eat_current_token() { int update_global_token = FALSE; diff --git a/test/test.answers b/test/test.answers index 354892e..9ab3685 100644 --- a/test/test.answers +++ b/test/test.answers @@ -179,8 +179,8 @@ ba2e2e1bbe66fea15d5984678175229fcb0adc6faa394be2cfde8bea1d3026de test/results/t 5afa9027627815aed92b0f239f4ac85318ca11c15c0c44ae0a0b9bc4ca599119 test/results/test0106-knight-native-binary 44d0b9e0433f12b5567ecddc9285b6a7d41ea646a7134e6fc3c394b4a973f6ba test/results/test0106-knight-posix-binary 1f83e1cbac44aabd9f87eae601e020b584b572e7edb738d6274972d6d100fa3c test/results/test0106-x86-binary -0d0434bf7cb456375765ee2b049b1a0e656ab428a8445236dfc40892e47556ca test/results/test1000-aarch64-binary -8a85c62b07cc8b5203e50ca0f2400b2ffa522e196726648b4d128fb62a034913 test/results/test1000-amd64-binary -3b951779a5ea70097d4a46c420a19413c5e99df5108e93be39cff5a4abd1c12d test/results/test1000-armv7l-binary -3758195a742867a22237a1371a5f4b19c4e9b8a0c6675d76f09fd748a46aed46 test/results/test1000-knight-posix-binary -72b941a1c9708605eb531702bbf2ddc2a21fc1a7f60977fa936dc6fbca3bea19 test/results/test1000-x86-binary +97b0faf131290244f627423e935168f5d5efb2a89d128c49fd7ad11711a9ea2f test/results/test1000-aarch64-binary +c68ae25541d200d184cd679ab8a5cb0c369d602f65a62ace73d103010983738d test/results/test1000-amd64-binary +615b5c95ee931e36e984aa7824a444fc550fdf0d218464e6808d5bbc3459092d test/results/test1000-armv7l-binary +eed78f27d9644cf465ed2223df05085bdaa4933d3d6a726734f568d5fcb82606 test/results/test1000-knight-posix-binary +c523cb219dc92a9c4c887d9104cc1b759845f96fd8cd9b680f86c7b45691b894 test/results/test1000-x86-binary diff --git a/test/test1000/proof.answer b/test/test1000/proof.answer index 9225ce9..e3c80b5 100644 --- a/test/test1000/proof.answer +++ b/test/test1000/proof.answer @@ -1 +1 @@ -c2edf691fa75b56e42a15b5dc62124a2a2f006cd38ad2f34d48be2563bd78620 test/test1000/proof +f8c98a3b045c02c171d3c0148d9f0f428cc6ada6d4d67e014ff3c1e33106c255 test/test1000/proof