diff --git a/CHANGELOG.org b/CHANGELOG.org index 299e2e5..192bafe 100644 --- a/CHANGELOG.org +++ b/CHANGELOG.org @@ -18,6 +18,8 @@ ** Added ** Changed +Tweaked cc_types.c to better match amd64 assembly +Replaced out with output_list in cc_core.c ** Fixed diff --git a/cc.c b/cc.c index 525fa46..a229d1e 100644 --- a/cc.c +++ b/cc.c @@ -23,7 +23,7 @@ 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); -struct token_list* program(); +void program(); void recursive_output(struct token_list* i, FILE* out); int match(char* a, char* b); void file_print(char* s, FILE* f); @@ -125,7 +125,8 @@ int main(int argc, char** argv) initialize_types(); reset_hold_string(); - struct token_list* output_list = program(); + output_list = NULL; + program(); /* Output the program we have compiled */ file_print("\n# Core program\n", destination_file); diff --git a/cc.h b/cc.h index 202e83f..685f967 100644 --- a/cc.h +++ b/cc.h @@ -85,6 +85,7 @@ struct type* prim_types; struct token_list* global_token; /* Output reorder collections*/ +struct token_list* output_list; struct token_list* strings_list; struct token_list* globals_list; diff --git a/cc_core.c b/cc_core.c index d4b996a..bf5b34c 100644 --- a/cc_core.c +++ b/cc_core.c @@ -27,7 +27,6 @@ struct token_list* global_constant_list; /* Core lists for this file */ struct token_list* function; -struct token_list* out; /* What we are currently working on */ struct type* current_target; @@ -56,7 +55,7 @@ struct token_list* emit(char *s, struct token_list* head) void emit_out(char* s) { - out = emit(s, out); + output_list = emit(s, output_list); } struct token_list* uniqueID(char* s, struct token_list* l, char* num) @@ -67,7 +66,7 @@ struct token_list* uniqueID(char* s, struct token_list* l, char* num) void uniqueID_out(char* s, char* num) { - out = uniqueID(s, out, num); + output_list = uniqueID(s, output_list, num); } struct token_list* sym_declare(char *s, struct type* t, struct token_list* list) @@ -1322,10 +1321,10 @@ void recursive_statement() /* Clean up any locals added */ - if(((X86 == Architecture) && !match("RETURN\n", out->s)) || - ((AMD64 == Architecture) && !match("RETURN\n", out->s)) || - (((KNIGHT_POSIX == Architecture) || (KNIGHT_NATIVE == Architecture)) && !match("RET R15\n", out->s)) || - ((ARMV7L == Architecture) && !match("'1' LR RETURN\n", out->s))) + if(((X86 == Architecture) && !match("RETURN\n", output_list->s)) || + ((AMD64 == Architecture) && !match("RETURN\n", output_list->s)) || + (((KNIGHT_POSIX == Architecture) || (KNIGHT_NATIVE == Architecture)) && !match("RET R15\n", output_list->s)) || + ((ARMV7L == Architecture) && !match("'1' LR RETURN\n", output_list->s))) { struct token_list* i; for(i = function->locals; frame != i; i = i->next) @@ -1498,10 +1497,10 @@ void declare_function() statement(); /* Prevent duplicate RETURNS */ - if(((KNIGHT_POSIX == Architecture) || (KNIGHT_NATIVE == Architecture)) && !match("RET R15\n", out->s)) emit_out("RET R15\n"); - else if((X86 == Architecture) && !match("RETURN\n", out->s)) emit_out("RETURN\n"); - else if((AMD64 == Architecture) && !match("RETURN\n", out->s)) emit_out("RETURN\n"); - else if((ARMV7L == Architecture) && !match("'1' LR RETURN\n", out->s)) emit_out("'1' LR RETURN\n"); + if(((KNIGHT_POSIX == Architecture) || (KNIGHT_NATIVE == Architecture)) && !match("RET R15\n", output_list->s)) emit_out("RET R15\n"); + else if((X86 == Architecture) && !match("RETURN\n", output_list->s)) emit_out("RETURN\n"); + else if((AMD64 == Architecture) && !match("RETURN\n", output_list->s)) emit_out("RETURN\n"); + else if((ARMV7L == Architecture) && !match("'1' LR RETURN\n", output_list->s)) emit_out("'1' LR RETURN\n"); } } @@ -1523,15 +1522,14 @@ void declare_function() * parameter-declaration: * type-name identifier-opt */ -struct token_list* program() +void program() { - out = NULL; function = NULL; Address_of = FALSE; struct type* type_size; new_type: - if (NULL == global_token) return out; + if (NULL == global_token) return; if(match("CONSTANT", global_token->s)) { global_token = global_token->next; diff --git a/cc_types.c b/cc_types.c index c8d6cc0..7fa197e 100644 --- a/cc_types.c +++ b/cc_types.c @@ -235,27 +235,29 @@ void create_struct() */ struct type* type_name() { - int structure = match("struct", global_token->s); + struct type* ret; - if(structure) + if(match("struct", global_token->s)) { global_token = global_token->next; + ret = lookup_type(global_token->s, global_types); + if(NULL == ret) + { + create_struct(); + return NULL; + } } - - struct type* ret = lookup_type(global_token->s, global_types); - - if(NULL == ret && !structure) + else { - file_print("Unknown type ", stderr); - file_print(global_token->s, stderr); - file_print("\n", stderr); - line_error(); - exit(EXIT_FAILURE); - } - else if(NULL == ret) - { - create_struct(); - return NULL; + ret = lookup_type(global_token->s, global_types); + if(NULL == ret) + { + file_print("Unknown type ", stderr); + file_print(global_token->s, stderr); + file_print("\n", stderr); + line_error(); + exit(EXIT_FAILURE); + } } global_token = global_token->next; diff --git a/test/common_armv7l/libc-core.M1 b/test/common_armv7l/libc-core.M1 index 1f14aae..e12aaf1 100644 --- a/test/common_armv7l/libc-core.M1 +++ b/test/common_armv7l/libc-core.M1 @@ -18,7 +18,7 @@ '0' SP BP NO_SHIFT MOVE_ALWAYS ; Setup Base Pointer ;; Prepare argv - !4 R0 ADD BP ARITH_ALWAYS ; ARGV_address = EBP + 4 + !4 R0 ADD BP ARITH_ALWAYS ; ARGV_address = BP + 4 {R0} PUSH_ALWAYS ; Put argv on the stack ;; Prepare envp @@ -26,11 +26,11 @@ !0 R0 LOAD32 R0 MEMORY ; Get ARGC !2 R0 ADD R0 ARITH_ALWAYS ; OFFSET = ARGC + 2 '0' R0 R0 '1' MOVE_ALWAYS ; OFFSET = OFFSET * WORDSIZE - '0' R0 R0 ADD BP ARITH2_ALWAYS ; ENVP_address = EBP + OFFSET + '0' R0 R0 ADD BP ARITH2_ALWAYS ; ENVP_address = BP + OFFSET {R0} PUSH_ALWAYS ; Put envp on the stack ;; Stack offset - !4 BP ADD BP ARITH_ALWAYS ; Fix ebp + !4 BP ADD BP ARITH_ALWAYS ; Fix BP ^~FUNCTION_main CALL_ALWAYS ; Jump right into main !1 R7 LOADI8_ALWAYS ; Setup for final exit diff --git a/test/test.answers b/test/test.answers index 643b53c..d255f58 100644 --- a/test/test.answers +++ b/test/test.answers @@ -53,10 +53,10 @@ a9cf4422e05075395ad75bbfe4b2659aec4541edd46d8c6b5064d3496b06a0b6 test/results/t 1154f39f25dcd6d914e9a542306f95280926baf985d011b2152c7ea0b87ab42d test/results/test10-knight-native-binary c1b5a2a3cd46c5e95e5540e871c2a916e028684ca80f51c001ef489342e27625 test/results/test10-knight-posix-binary b3e13d54aab689137628fb9c4487bfd8288f9bd18bef8fe756577c8d2dce1f1f test/results/test10-x86-binary -e5b1330fafc33c866396b341896e7fb52a2c403c90f25f1775bb0981c88b9bef test/results/test100-amd64-binary -7dad3a8ee61228623586d154b89a0747dab009f9dcc847360ae2753e6a5416df test/results/test100-armv7l-binary -dc04621732e4ea6f771bb6a33188290779a590f6c3bd12fda4ce7524341165db test/results/test100-knight-posix-binary -e7f064a169acd5b6a8094f85f3bb195adcfe8d56190042ef595c477c9887abd0 test/results/test100-x86-binary +68862cbb943373c84f41d454ede6318fe5d20217624dc72ae7f6cf968e661aee test/results/test100-amd64-binary +7fdb5af1f3f3a11d616b0fa41dca001142780287e2c3b4e43dbd6a6839cc2455 test/results/test100-armv7l-binary +c5ecaae26e27fc58b6055182dc31b2d76fcfade0c0e62113e23a8d31852cddba test/results/test100-knight-posix-binary +fb19b73f76074f6144d3e2e0c9c00148a604c423b8f83521ec383e03af343421 test/results/test100-x86-binary 34e6d535e30ef8826a4ad1a4d08b76cfa370c54595599ad3be784b64c9cd8ec5 test/results/test11-amd64-binary d9d465340abbce2d5964a6bc58e6cdd0ef93fb3d0199eaa823c86ec6abd0452a test/results/test11-armv7l-binary 955b564d2c89abf2cfc6c80d766cd11479d146b828dec69e654b0958a62d5e6e test/results/test11-knight-native-binary diff --git a/test/test100/proof.answer b/test/test100/proof.answer index 7a5eee1..b8d3066 100644 --- a/test/test100/proof.answer +++ b/test/test100/proof.answer @@ -1 +1 @@ -46607975aee72aa608ceab592f0f67eb45c63bb83a0b49ea944a48a79c4aca75 test/test100/proof +a055c6feac7ac8980d6c0369a18d91750795470a1817587490e7bf386c51e2b7 test/test100/proof