Minor tweaks to better match amd64 assembly

This commit is contained in:
Jeremiah Orians 2019-06-03 21:01:14 -04:00
parent d5937fa5f1
commit f43aa4a44c
No known key found for this signature in database
GPG Key ID: 5410E91C14959E87
8 changed files with 44 additions and 40 deletions

View File

@ -18,6 +18,8 @@
** Added ** Added
** Changed ** Changed
Tweaked cc_types.c to better match amd64 assembly
Replaced out with output_list in cc_core.c
** Fixed ** Fixed

5
cc.c
View File

@ -23,7 +23,7 @@
void initialize_types(); void initialize_types();
struct token_list* read_all_tokens(FILE* a, struct token_list* current, char* filename); 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* reverse_list(struct token_list* head);
struct token_list* program(); void program();
void recursive_output(struct token_list* i, FILE* out); void recursive_output(struct token_list* i, FILE* out);
int match(char* a, char* b); int match(char* a, char* b);
void file_print(char* s, FILE* f); void file_print(char* s, FILE* f);
@ -125,7 +125,8 @@ int main(int argc, char** argv)
initialize_types(); initialize_types();
reset_hold_string(); reset_hold_string();
struct token_list* output_list = program(); output_list = NULL;
program();
/* Output the program we have compiled */ /* Output the program we have compiled */
file_print("\n# Core program\n", destination_file); file_print("\n# Core program\n", destination_file);

1
cc.h
View File

@ -85,6 +85,7 @@ struct type* prim_types;
struct token_list* global_token; struct token_list* global_token;
/* Output reorder collections*/ /* Output reorder collections*/
struct token_list* output_list;
struct token_list* strings_list; struct token_list* strings_list;
struct token_list* globals_list; struct token_list* globals_list;

View File

@ -27,7 +27,6 @@ struct token_list* global_constant_list;
/* Core lists for this file */ /* Core lists for this file */
struct token_list* function; struct token_list* function;
struct token_list* out;
/* What we are currently working on */ /* What we are currently working on */
struct type* current_target; struct type* current_target;
@ -56,7 +55,7 @@ struct token_list* emit(char *s, struct token_list* head)
void emit_out(char* s) 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) 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) 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) 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 */ /* Clean up any locals added */
if(((X86 == Architecture) && !match("RETURN\n", out->s)) || if(((X86 == Architecture) && !match("RETURN\n", output_list->s)) ||
((AMD64 == Architecture) && !match("RETURN\n", out->s)) || ((AMD64 == Architecture) && !match("RETURN\n", output_list->s)) ||
(((KNIGHT_POSIX == Architecture) || (KNIGHT_NATIVE == Architecture)) && !match("RET R15\n", out->s)) || (((KNIGHT_POSIX == Architecture) || (KNIGHT_NATIVE == Architecture)) && !match("RET R15\n", output_list->s)) ||
((ARMV7L == Architecture) && !match("'1' LR RETURN\n", out->s))) ((ARMV7L == Architecture) && !match("'1' LR RETURN\n", output_list->s)))
{ {
struct token_list* i; struct token_list* i;
for(i = function->locals; frame != i; i = i->next) for(i = function->locals; frame != i; i = i->next)
@ -1498,10 +1497,10 @@ void declare_function()
statement(); statement();
/* Prevent duplicate RETURNS */ /* Prevent duplicate RETURNS */
if(((KNIGHT_POSIX == Architecture) || (KNIGHT_NATIVE == Architecture)) && !match("RET R15\n", out->s)) emit_out("RET R15\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", out->s)) emit_out("RETURN\n"); else if((X86 == Architecture) && !match("RETURN\n", output_list->s)) emit_out("RETURN\n");
else if((AMD64 == Architecture) && !match("RETURN\n", out->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", out->s)) emit_out("'1' LR 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: * parameter-declaration:
* type-name identifier-opt * type-name identifier-opt
*/ */
struct token_list* program() void program()
{ {
out = NULL;
function = NULL; function = NULL;
Address_of = FALSE; Address_of = FALSE;
struct type* type_size; struct type* type_size;
new_type: new_type:
if (NULL == global_token) return out; if (NULL == global_token) return;
if(match("CONSTANT", global_token->s)) if(match("CONSTANT", global_token->s))
{ {
global_token = global_token->next; global_token = global_token->next;

View File

@ -235,27 +235,29 @@ void create_struct()
*/ */
struct type* type_name() 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; global_token = global_token->next;
ret = lookup_type(global_token->s, global_types);
if(NULL == ret)
{
create_struct();
return NULL;
}
} }
else
struct type* ret = lookup_type(global_token->s, global_types);
if(NULL == ret && !structure)
{ {
file_print("Unknown type ", stderr); ret = lookup_type(global_token->s, global_types);
file_print(global_token->s, stderr); if(NULL == ret)
file_print("\n", stderr); {
line_error(); file_print("Unknown type ", stderr);
exit(EXIT_FAILURE); file_print(global_token->s, stderr);
} file_print("\n", stderr);
else if(NULL == ret) line_error();
{ exit(EXIT_FAILURE);
create_struct(); }
return NULL;
} }
global_token = global_token->next; global_token = global_token->next;

View File

@ -18,7 +18,7 @@
'0' SP BP NO_SHIFT MOVE_ALWAYS ; Setup Base Pointer '0' SP BP NO_SHIFT MOVE_ALWAYS ; Setup Base Pointer
;; Prepare argv ;; 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 {R0} PUSH_ALWAYS ; Put argv on the stack
;; Prepare envp ;; Prepare envp
@ -26,11 +26,11 @@
!0 R0 LOAD32 R0 MEMORY ; Get ARGC !0 R0 LOAD32 R0 MEMORY ; Get ARGC
!2 R0 ADD R0 ARITH_ALWAYS ; OFFSET = ARGC + 2 !2 R0 ADD R0 ARITH_ALWAYS ; OFFSET = ARGC + 2
'0' R0 R0 '1' MOVE_ALWAYS ; OFFSET = OFFSET * WORDSIZE '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 {R0} PUSH_ALWAYS ; Put envp on the stack
;; Stack offset ;; 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 ^~FUNCTION_main CALL_ALWAYS ; Jump right into main
!1 R7 LOADI8_ALWAYS ; Setup for final exit !1 R7 LOADI8_ALWAYS ; Setup for final exit

View File

@ -53,10 +53,10 @@ a9cf4422e05075395ad75bbfe4b2659aec4541edd46d8c6b5064d3496b06a0b6 test/results/t
1154f39f25dcd6d914e9a542306f95280926baf985d011b2152c7ea0b87ab42d test/results/test10-knight-native-binary 1154f39f25dcd6d914e9a542306f95280926baf985d011b2152c7ea0b87ab42d test/results/test10-knight-native-binary
c1b5a2a3cd46c5e95e5540e871c2a916e028684ca80f51c001ef489342e27625 test/results/test10-knight-posix-binary c1b5a2a3cd46c5e95e5540e871c2a916e028684ca80f51c001ef489342e27625 test/results/test10-knight-posix-binary
b3e13d54aab689137628fb9c4487bfd8288f9bd18bef8fe756577c8d2dce1f1f test/results/test10-x86-binary b3e13d54aab689137628fb9c4487bfd8288f9bd18bef8fe756577c8d2dce1f1f test/results/test10-x86-binary
e5b1330fafc33c866396b341896e7fb52a2c403c90f25f1775bb0981c88b9bef test/results/test100-amd64-binary 68862cbb943373c84f41d454ede6318fe5d20217624dc72ae7f6cf968e661aee test/results/test100-amd64-binary
7dad3a8ee61228623586d154b89a0747dab009f9dcc847360ae2753e6a5416df test/results/test100-armv7l-binary 7fdb5af1f3f3a11d616b0fa41dca001142780287e2c3b4e43dbd6a6839cc2455 test/results/test100-armv7l-binary
dc04621732e4ea6f771bb6a33188290779a590f6c3bd12fda4ce7524341165db test/results/test100-knight-posix-binary c5ecaae26e27fc58b6055182dc31b2d76fcfade0c0e62113e23a8d31852cddba test/results/test100-knight-posix-binary
e7f064a169acd5b6a8094f85f3bb195adcfe8d56190042ef595c477c9887abd0 test/results/test100-x86-binary fb19b73f76074f6144d3e2e0c9c00148a604c423b8f83521ec383e03af343421 test/results/test100-x86-binary
34e6d535e30ef8826a4ad1a4d08b76cfa370c54595599ad3be784b64c9cd8ec5 test/results/test11-amd64-binary 34e6d535e30ef8826a4ad1a4d08b76cfa370c54595599ad3be784b64c9cd8ec5 test/results/test11-amd64-binary
d9d465340abbce2d5964a6bc58e6cdd0ef93fb3d0199eaa823c86ec6abd0452a test/results/test11-armv7l-binary d9d465340abbce2d5964a6bc58e6cdd0ef93fb3d0199eaa823c86ec6abd0452a test/results/test11-armv7l-binary
955b564d2c89abf2cfc6c80d766cd11479d146b828dec69e654b0958a62d5e6e test/results/test11-knight-native-binary 955b564d2c89abf2cfc6c80d766cd11479d146b828dec69e654b0958a62d5e6e test/results/test11-knight-native-binary

View File

@ -1 +1 @@
46607975aee72aa608ceab592f0f67eb45c63bb83a0b49ea944a48a79c4aca75 test/test100/proof a055c6feac7ac8980d6c0369a18d91750795470a1817587490e7bf386c51e2b7 test/test100/proof