123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149 |
- From d93e6b0a8aeaca1b8b75731132216f4227727bb1 Mon Sep 17 00:00:00 2001
- From: deesix <deesix@tuta.io>
- Date: Wed, 5 Jan 2021 00:00:00
- Subject: [PATCH] cc_aarch64 using new asm-like macros
- ---
- stage2/High_level_prototypes/cc_aarch64/cc_core.c | 188 +++++++--------
- stage2/cc_aarch64.s | 282 +++++++++++-----------
- 2 files changed, 235 insertions(+), 235 deletions(-)
- diff --git a/stage2/High_level_prototypes/cc_aarch64/cc_core.c b/stage2/High_level_prototypes/cc_aarch64/cc_core.c
- index 7b1f117..78af8cc 100644
- --- a/stage2/High_level_prototypes/cc_aarch64/cc_core.c
- +++ b/stage2/High_level_prototypes/cc_aarch64/cc_core.c
- @@ -115,22 +115,22 @@ void function_call(char* s, int bool)
- {
- require_match("ERROR in process_expression_list\nNo ( was found\n", "(");
- int passed = 0;
- - emit_out("PUSH_X16\t# Protect a tmp register we're going to use\n");
- - emit_out("PUSH_LR\t# Protect the old return pointer (link)\n");
- - emit_out("PUSH_BP\t# Protect the old base pointer\n");
- - emit_out("SET_X16_FROM_SP\t# The base pointer to-be\n");
- + emit_out("STR____X16,[X18,-8]!\t# Protect a tmp register we're going to use\n");
- + emit_out("STR____X30,[X18,-8]!\t# Protect the old return pointer (link)\n");
- + emit_out("STR____X17,[X18,-8]!\t# Protect the old base pointer\n");
- + emit_out("MOV____X16,X18\t# The base pointer to-be\n");
-
- if(global_token->s[0] != ')')
- {
- expression();
- - emit_out("PUSH_X0\t#_process_expression1\n");
- + emit_out("STR____X0,[X18,-8]!\t#_process_expression1\n");
- passed = 1;
-
- while(global_token->s[0] == ',')
- {
- global_token = global_token->next;
- expression();
- - emit_out("PUSH_X0\t#_process_expression2\n");
- + emit_out("STR____X0,[X18,-8]!\t#_process_expression2\n");
- passed = passed + 1;
- }
- }
- @@ -139,36 +139,36 @@ void function_call(char* s, int bool)
-
- if(TRUE == bool)
- {
- - emit_out("SET_X0_FROM_BP\n");
- - emit_out("LOAD_W1_AHEAD\nSKIP_32_DATA\n%");
- + emit_out("MOV____X0,X17\n");
- + emit_out("LDR____W1,8\nB______8\n%");
- emit_out(s);
- - emit_out("\nSUB_X0_X0_X1\n");
- - emit_out("DEREF_X0\n");
- - emit_out("SET_BP_FROM_X16\n");
- - emit_out("SET_X16_FROM_X0\n");
- - emit_out("BLR_X16\n");
- + emit_out("\nSUB____X0,X0,X1\n");
- + emit_out("LDR____X0,[X0]\n");
- + emit_out("MOV____X17,X16\n");
- + emit_out("MOV____X16,X0\n");
- + emit_out("BLR____X16\n");
- }
- else
- {
- - emit_out("SET_BP_FROM_X16\n");
- - emit_out("LOAD_W16_AHEAD\nSKIP_32_DATA\n&FUNCTION_");
- + emit_out("MOV____X17,X16\n");
- + emit_out("LDR____W16,8\nB______8\n&FUNCTION_");
- emit_out(s);
- emit_out("\n");
- - emit_out("BLR_X16\n");
- + emit_out("BLR____X16\n");
- }
-
- for(; passed > 0; passed = passed - 1)
- {
- - emit_out("POP_X1\t# _process_expression_locals\n");
- + emit_out("LDR____X1,[X18],8\t# _process_expression_locals\n");
- }
- - emit_out("POP_BP\t# Restore the old base pointer\n");
- - emit_out("POP_LR\t# Restore the old return pointer (link)\n");
- - emit_out("POP_X16\t# Restore a register we used as tmp\n");
- + emit_out("LDR____X17,[X18],8\t# Restore the old base pointer\n");
- + emit_out("LDR____X30,[X18],8\t# Restore the old return pointer (link)\n");
- + emit_out("LDR____X16,[X18],8\t# Restore a register we used as tmp\n");
- }
-
- void constant_load(struct token_list* a)
- {
- - emit_out("LOAD_W0_AHEAD\nSKIP_32_DATA\n%");
- + emit_out("LDRSW__X0,8\nB______8\n%");
- emit_out(a->arguments->s);
- emit_out("\n");
- }
- @@ -181,14 +181,14 @@ void variable_load(struct token_list* a)
- return;
- }
- current_target = a->type;
- - emit_out("SET_X0_FROM_BP\nLOAD_W1_AHEAD\nSKIP_32_DATA\n%");
- + emit_out("MOV____X0,X17\nLDR____W1,8\nB______8\n%");
- emit_out(numerate_number(a->depth));
- - emit_out("\nSUB_X0_X0_X1\n\n");
- + emit_out("\nSUB____X0,X0,X1\n\n");
-
- if(TRUE == Address_of) return;
- if(match("=", global_token->s)) return;
-
- - emit_out("DEREF_X0\n");
- + emit_out("LDR____X0,[X0]\n");
- }
-
- void function_load(struct token_list* a)
- @@ -199,7 +199,7 @@ void function_load(struct token_list* a)
- return;
- }
-
- - emit_out("LOAD_W0_AHEAD\nSKIP_32_DATA\n&FUNCTION_");
- + emit_out("LDRSW__X0,8\nB______8\n&FUNCTION_");
- emit_out(a->s);
- emit_out("\n");
- }
- @@ -207,10 +207,10 @@ void function_load(struct token_list* a)
- void global_load(struct token_list* a)
- {
- current_target = a->type;
- - emit_out("LOAD_W0_AHEAD\nSKIP_32_DATA\n&GLOBAL_");
- + emit_out("LDRSW__X0,8\nB______8\n&GLOBAL_");
- emit_out(a->s);
- emit_out("\n");
- - if(!match("=", global_token->s)) emit_out("DEREF_X0\n");
- + if(!match("=", global_token->s)) emit_out("LDR____X0,[X0]\n");
- }
-
- /*
- @@ -236,7 +236,7 @@ void primary_expr_string()
- {
- char* number_string = numerate_number(current_count);
- current_count = current_count + 1;
- - emit_out("LOAD_W0_AHEAD\nSKIP_32_DATA\n&STRING_");
- + emit_out("LDRSW__X0,8\nB______8\n&STRING_");
- uniqueID_out(function->s, number_string);
-
- /* The target */
- @@ -250,7 +250,7 @@ void primary_expr_string()
-
- void primary_expr_char()
- {
- - emit_out("LOAD_W0_AHEAD\nSKIP_32_DATA\n%");
- + emit_out("LDRSW__X0,8\nB______8\n%");
- emit_out(numerate_number(escape_lookup(global_token->s + 1)));
- emit_out("\n");
- global_token = global_token->next;
- @@ -258,7 +258,7 @@ void primary_expr_char()
-
- void primary_expr_number()
- {
- - emit_out("LOAD_W0_AHEAD\nSKIP_32_DATA\n%");
- + emit_out("LDRSW__X0,8\nB______8\n%");
- emit_out(global_token->s);
- emit_out("\n");
- global_token = global_token->next;
- @@ -336,10 +336,10 @@ void common_recursion(FUNCTION f)
- {
- last_type = current_target;
- global_token = global_token->next;
- - emit_out("PUSH_X0\t#_common_recursion\n");
- + emit_out("STR____X0,[X18,-8]!\t#_common_recursion\n");
- f();
- current_target = promote_type(current_target, last_type);
- - emit_out("POP_X1\t# _common_recursion\n");
- + emit_out("LDR____X1,[X18],8\t# _common_recursion\n");
- }
-
- void general_recursion( FUNCTION f, char* s, char* name, FUNCTION iterate)
- @@ -389,14 +389,14 @@ void postfix_expr_arrow()
- if(0 != i->offset)
- {
- emit_out("# -> offset calculation\n");
- - emit_out("LOAD_W1_AHEAD\nSKIP_32_DATA\n%");
- + emit_out("LDR____W1,8\nB______8\n%");
- emit_out(numerate_number(i->offset));
- - emit_out("\nADD_X0_X1_X0\n");
- + emit_out("\nADD____X0,X1,X0\n");
- }
-
- if(!match("=", global_token->s) && (8 == i->size))
- {
- - emit_out("DEREF_X0\n");
- + emit_out("LDR____X0,[X0]\n");
- }
- }
-
- @@ -405,21 +405,21 @@ void postfix_expr_array()
- struct type* array = current_target;
- common_recursion(expression);
- current_target = array;
- - char* assign = "DEREF_X0\n";
- + char* assign = "LDR____X0,[X0]\n";
-
- /* Add support for Ints */
- if(match("char*", current_target->name))
- {
- - assign = "DEREF_X0_BYTE\n";
- + assign = "LDRB___W0,[X0]\n";
- }
- else
- {
- - emit_out("LOAD_W2_AHEAD\nSKIP_32_DATA\n%");
- + emit_out("LDR____W2,8\nB______8\n%");
- emit_out(numerate_number(ceil_log2(current_target->indirect->size)));
- - emit_out("\nLSHIFT_X0_X0_X2\n");
- + emit_out("\nLSL____X0,X0,X2\n");
- }
-
- - emit_out("ADD_X0_X1_X0\n");
- + emit_out("ADD____X0,X1,X0\n");
- require_match("ERROR in postfix_expr\nMissing ]\n", "]");
-
- if(match("=", global_token->s))
- @@ -445,7 +445,7 @@ void unary_expr_sizeof()
- struct type* a = type_name();
- require_match("ERROR in unary_expr\nMissing )\n", ")");
-
- - emit_out("LOAD_W0_AHEAD\nSKIP_32_DATA\n%");
- + emit_out("LDRSW__X0,8\nB______8\n%");
- emit_out(numerate_number(a->size));
- emit_out("\n");
- }
- @@ -484,12 +484,12 @@ void postfix_expr()
- */
- void additive_expr_stub()
- {
- - general_recursion(postfix_expr, "ADD_X0_X1_X0\n", "+", additive_expr_stub);
- - general_recursion(postfix_expr, "SUB_X0_X1_X0\n", "-", additive_expr_stub);
- - general_recursion(postfix_expr, "MUL_X0_X1_X0\n", "*", additive_expr_stub);
- - general_recursion(postfix_expr, "UDIV_X0_X1_X0\n", "/", additive_expr_stub);
- - general_recursion(postfix_expr, "UDIV_X2_X1_X0\nMSUB_X0_X0_X2_X1\n", "%", additive_expr_stub);
- - general_recursion(postfix_expr, "LSHIFT_X0_X1_X0\n", "<<", additive_expr_stub);
- + general_recursion(postfix_expr, "ADD____X0,X1,X0\n", "+", additive_expr_stub);
- + general_recursion(postfix_expr, "SUB____X0,X1,X0\n", "-", additive_expr_stub);
- + general_recursion(postfix_expr, "MUL____X0,X1,X0\n", "*", additive_expr_stub);
- + general_recursion(postfix_expr, "UDIV___X0,X1,X0\n", "/", additive_expr_stub);
- + general_recursion(postfix_expr, "UDIV___X2,X1,X0\nMSUB___X0,X0,X2,X1\n", "%", additive_expr_stub);
- + general_recursion(postfix_expr, "LSL____X0,X1,X0\n", "<<", additive_expr_stub);
- general_recursion(postfix_expr, "RSHIFT_X0_X1_X0\n", ">>", additive_expr_stub);
- }
-
- @@ -512,12 +512,12 @@ void additive_expr()
-
- void relational_expr_stub()
- {
- - general_recursion(additive_expr, "CMP_X1_X0\nSET_X0_TO_1\nSKIP_INST_LT\nSET_X0_TO_0\n", "<", relational_expr_stub);
- - general_recursion(additive_expr, "CMP_X1_X0\nSET_X0_TO_1\nSKIP_INST_LE\nSET_X0_TO_0\n", "<=", relational_expr_stub);
- - general_recursion(additive_expr, "CMP_X1_X0\nSET_X0_TO_1\nSKIP_INST_GE\nSET_X0_TO_0\n", ">=", relational_expr_stub);
- - general_recursion(additive_expr, "CMP_X1_X0\nSET_X0_TO_1\nSKIP_INST_GT\nSET_X0_TO_0\n", ">", relational_expr_stub);
- - general_recursion(additive_expr, "CMP_X1_X0\nSET_X0_TO_1\nSKIP_INST_EQ\nSET_X0_TO_0\n", "==", relational_expr_stub);
- - general_recursion(additive_expr, "CMP_X1_X0\nSET_X0_TO_1\nSKIP_INST_NE\nSET_X0_TO_0\n", "!=", relational_expr_stub);
- + general_recursion(additive_expr, "CMP____X1,X0\nMOV____X0,1\nB.LT___8\nMOV____X0,0\n", "<", relational_expr_stub);
- + general_recursion(additive_expr, "CMP____X1,X0\nMOV____X0,1\nB.LE___8\nMOV____X0,0\n", "<=", relational_expr_stub);
- + general_recursion(additive_expr, "CMP____X1,X0\nMOV____X0,1\nB.GE___8\nMOV____X0,0\n", ">=", relational_expr_stub);
- + general_recursion(additive_expr, "CMP____X1,X0\nMOV____X0,1\nB.GT___8\nMOV____X0,0\n", ">", relational_expr_stub);
- + general_recursion(additive_expr, "CMP____X1,X0\nMOV____X0,1\nB.EQ___8\nMOV____X0,0\n", "==", relational_expr_stub);
- + general_recursion(additive_expr, "CMP____X1,X0\nMOV____X0,1\nB.NE___8\nMOV____X0,0\n", "!=", relational_expr_stub);
- }
-
- void relational_expr()
- @@ -537,11 +537,11 @@ void relational_expr()
- */
- void bitwise_expr_stub()
- {
- - general_recursion(relational_expr, "AND_X0_X1_X0\n", "&", bitwise_expr_stub);
- - general_recursion(relational_expr, "AND_X0_X1_X0\n", "&&", bitwise_expr_stub);
- - general_recursion(relational_expr, "OR_X0_X1_X0\n", "|", bitwise_expr_stub);
- - general_recursion(relational_expr, "OR_X0_X1_X0\n", "||", bitwise_expr_stub);
- - general_recursion(relational_expr, "XOR_X0_X1_X0\n", "^", bitwise_expr_stub);
- + general_recursion(relational_expr, "AND____X0,X1,X0\n", "&", bitwise_expr_stub);
- + general_recursion(relational_expr, "AND____X0,X1,X0\n", "&&", bitwise_expr_stub);
- + general_recursion(relational_expr, "ORR____X0,X1,X0\n", "|", bitwise_expr_stub);
- + general_recursion(relational_expr, "ORR____X0,X1,X0\n", "||", bitwise_expr_stub);
- + general_recursion(relational_expr, "EOR____X0,X0,X1\n", "^", bitwise_expr_stub);
- }
-
-
- @@ -572,15 +572,15 @@ void primary_expr()
- if(match("sizeof", global_token->s)) unary_expr_sizeof();
- else if('-' == global_token->s[0])
- {
- - emit_out("SET_X0_TO_0\n");
- + emit_out("MOV____X0,0\n");
- common_recursion(primary_expr);
- - emit_out("SUB_X0_X1_X0\n");
- + emit_out("SUB____X0,X1,X0\n");
- }
- else if('!' == global_token->s[0])
- {
- - emit_out("SET_X0_TO_1\n");
- + emit_out("MOV____X0,1\n");
- common_recursion(postfix_expr);
- - emit_out("XOR_X0_X1_X0\n");
- + emit_out("EOR____X0,X0,X1\n");
- }
- else if(global_token->s[0] == '(')
- {
- @@ -603,11 +603,11 @@ void expression()
- char* store;
- if(!match("]", global_token->prev->s) || !match("char*", current_target->name))
- {
- - store = "STR_X0_[X1]\n";
- + store = "STR____X0,[X1]\n";
- }
- else
- {
- - store = "STR_BYTE_W0_[X1]\n";
- + store = "STRB___W0,[X1]\n";
- }
-
- common_recursion(expression);
- @@ -655,7 +655,7 @@ void collect_local()
-
- require_match("ERROR in collect_local\nMissing ;\n", ";");
-
- - emit_out("PUSH_X0\t#");
- + emit_out("STR____X0,[X18,-8]!\t#");
- emit_out(a->s);
- emit_out("\n");
- }
- @@ -675,16 +675,16 @@ void process_if()
- require_match("ERROR in process_if\nMISSING (\n", "(");
- expression();
-
- - emit_out("CBNZ_X0_PAST_BR\nLOAD_W16_AHEAD\nSKIP_32_DATA\n&ELSE_");
- + emit_out("CBNZ___X0,20\nLDR____W16,8\nB______8\n&ELSE_");
- uniqueID_out(function->s, number_string);
- - emit_out("\nBR_X16\n");
- + emit_out("\nBR_____X16\n");
-
- require_match("ERROR in process_if\nMISSING )\n", ")");
- statement();
-
- - emit_out("LOAD_W16_AHEAD\nSKIP_32_DATA\n&_END_IF_");
- + emit_out("LDR____W16,8\nB______8\n&_END_IF_");
- uniqueID_out(function->s, number_string);
- - emit_out("\nBR_X16\n:ELSE_");
- + emit_out("\nBR_____X16\n:ELSE_");
- uniqueID_out(function->s, number_string);
-
- if(match("else", global_token->s))
- @@ -728,27 +728,27 @@ void process_for()
- require_match("ERROR in process_for\nMISSING ;1\n", ";");
- expression();
-
- - emit_out("CBNZ_X0_PAST_BR\nLOAD_W16_AHEAD\nSKIP_32_DATA\n&FOR_END_");
- + emit_out("CBNZ___X0,20\nLDR____W16,8\nB______8\n&FOR_END_");
- uniqueID_out(function->s, number_string);
- - emit_out("\nBR_X16\nLOAD_W16_AHEAD\nSKIP_32_DATA\n&FOR_THEN_");
- + emit_out("\nBR_____X16\nLDR____W16,8\nB______8\n&FOR_THEN_");
- uniqueID_out(function->s, number_string);
- - emit_out("\nBR_X16\n:FOR_ITER_");
- + emit_out("\nBR_____X16\n:FOR_ITER_");
- uniqueID_out(function->s, number_string);
-
- require_match("ERROR in process_for\nMISSING ;2\n", ";");
- expression();
-
- - emit_out("LOAD_W16_AHEAD\nSKIP_32_DATA\n&FOR_");
- + emit_out("LDR____W16,8\nB______8\n&FOR_");
- uniqueID_out(function->s, number_string);
- - emit_out("\nBR_X16\n:FOR_THEN_");
- + emit_out("\nBR_____X16\n:FOR_THEN_");
- uniqueID_out(function->s, number_string);
-
- require_match("ERROR in process_for\nMISSING )\n", ")");
- statement();
-
- - emit_out("LOAD_W16_AHEAD\nSKIP_32_DATA\n&FOR_ITER_");
- + emit_out("LDR____W16,8\nB______8\n&FOR_ITER_");
- uniqueID_out(function->s, number_string);
- - emit_out("\nBR_X16\n:FOR_END_");
- + emit_out("\nBR_____X16\n:FOR_END_");
- uniqueID_out(function->s, number_string);
-
- break_target_head = nested_break_head;
- @@ -800,9 +800,9 @@ void process_do()
- require_match("ERROR in process_do\nMISSING )\n", ")");
- require_match("ERROR in process_do\nMISSING ;\n", ";");
-
- - emit_out("CBZ_X0_PAST_BR\nLOAD_W16_AHEAD\nSKIP_32_DATA\n&DO_");
- + emit_out("CBZ____X0,20\nLDR____W16,8\nB______8\n&DO_");
- uniqueID_out(function->s, number_string);
- - emit_out("\nBR_X16\n:DO_END_");
- + emit_out("\nBR_____X16\n:DO_END_");
- uniqueID_out(function->s, number_string);
-
- break_frame = nested_locals;
- @@ -835,17 +835,17 @@ void process_while()
- require_match("ERROR in process_while\nMISSING (\n", "(");
- expression();
-
- - emit_out("CBNZ_X0_PAST_BR\nLOAD_W16_AHEAD\nSKIP_32_DATA\n&END_WHILE_");
- + emit_out("CBNZ___X0,20\nLDR____W16,8\nB______8\n&END_WHILE_");
- uniqueID_out(function->s, number_string);
- - emit_out("\nBR_X16\n# THEN_while_");
- + emit_out("\nBR_____X16\n# THEN_while_");
- uniqueID_out(function->s, number_string);
-
- require_match("ERROR in process_while\nMISSING )\n", ")");
- statement();
-
- - emit_out("LOAD_W16_AHEAD\nSKIP_32_DATA\n&WHILE_");
- + emit_out("LDR____W16,8\nB______8\n&WHILE_");
- uniqueID_out(function->s, number_string);
- - emit_out("\nBR_X16\n:END_WHILE_");
- + emit_out("\nBR_____X16\n:END_WHILE_");
- uniqueID_out(function->s, number_string);
-
- break_target_head = nested_break_head;
- @@ -865,9 +865,9 @@ void return_result()
- struct token_list* i;
- for(i = function->locals; NULL != i; i = i->next)
- {
- - emit_out("POP_X1\t# _return_result_locals\n");
- + emit_out("LDR____X1,[X18],8\t# _return_result_locals\n");
- }
- - emit_out("RETURN\n");
- + emit_out("RET\n");
- }
-
- void process_break()
- @@ -882,16 +882,16 @@ void process_break()
- while(i != break_frame)
- {
- if(NULL == i) break;
- - emit_out("POP_X1\t# break_cleanup_locals\n");
- + emit_out("LDR____X1,[X18],8\t# break_cleanup_locals\n");
- i = i->next;
- }
- global_token = global_token->next;
- - emit_out("LOAD_W16_AHEAD\nSKIP_32_DATA\n&");
- + emit_out("LDR____W16,8\nB______8\n&");
- emit_out(break_target_head);
- emit_out(break_target_func);
- emit_out("_");
- emit_out(break_target_num);
- - emit_out("\nBR_X16\n");
- + emit_out("\nBR_____X16\n");
- require_match("ERROR in break statement\nMissing ;\n", ";");
- }
-
- @@ -907,12 +907,12 @@ void recursive_statement()
- global_token = global_token->next;
-
- /* Clean up any locals added */
- - if(!match("RETURN\n", out->s))
- + if(!match("RET\n", out->s))
- {
- struct token_list* i;
- for(i = function->locals; frame != i; i = i->next)
- {
- - emit_out( "POP_X1\t# _recursive_statement_locals\n");
- + emit_out( "LDR____X1,[X18],8\t# _recursive_statement_locals\n");
- }
- }
- function->locals = frame;
- @@ -977,9 +977,9 @@ void statement()
- else if(match("goto", global_token->s))
- {
- global_token = global_token->next;
- - emit_out("LOAD_W16_AHEAD\nSKIP_32_DATA\n&");
- + emit_out("LDR____W16,8\nB______8\n&");
- emit_out(global_token->s);
- - emit_out("\nBR_X16\n");
- + emit_out("\nBR_____X16\n");
- global_token = global_token->next;
- require_match("ERROR in statement\nMissing ;\n", ";");
- }
- @@ -1061,10 +1061,10 @@ void declare_function()
- emit_out("\n");
- statement();
-
- - /* Prevent duplicate RETURNS */
- - if(!match("RETURN\n", out->s))
- + /* Prevent duplicate RETS */
- + if(!match("RET\n", out->s))
- {
- - emit_out("RETURN\n");
- + emit_out("RET\n");
- }
- }
- }
- diff --git a/stage2/cc_aarch64.s b/stage2/cc_aarch64.s
- index ac46dea..8c8b1a2 100644
- --- a/stage2/cc_aarch64.s
- +++ b/stage2/cc_aarch64.s
- @@ -771,8 +771,8 @@ Missing (
- Missing )
- "
- :unary_expr_sizeof_string2
- - "LOAD_W0_AHEAD
- -SKIP_32_DATA
- + "LDRSW__X0,8
- +B______8
- %"
-
-
- @@ -792,8 +792,8 @@ SKIP_32_DATA
- RET R15
-
- :constant_load_string0
- - "LOAD_W0_AHEAD
- -SKIP_32_DATA
- + "LDRSW__X0,8
- +B______8
- %"
-
-
- @@ -854,16 +854,16 @@ SKIP_32_DATA
- RET R15
-
- :variable_load_string0
- - "SET_X0_FROM_BP
- -LOAD_W1_AHEAD
- -SKIP_32_DATA
- + "MOV____X0,X17
- +LDR____W1,8
- +B______8
- %"
- :variable_load_string1
- - "DEREF_X0
- + "LDR____X0,[X0]
- "
- :variable_load_string2
- "
- -SUB_X0_X0_X1
- +SUB____X0,X0,X1
-
- "
-
- @@ -900,8 +900,8 @@ SUB_X0_X0_X1
- RET R15
-
- :function_load_string0
- - "LOAD_W0_AHEAD
- -SKIP_32_DATA
- + "LDRSW__X0,8
- +B______8
- &FUNCTION_"
-
-
- @@ -936,11 +936,11 @@ SKIP_32_DATA
- RET R15
-
- :global_load_string0
- - "LOAD_W0_AHEAD
- -SKIP_32_DATA
- + "LDRSW__X0,8
- +B______8
- &GLOBAL_"
- :global_load_string1
- - "DEREF_X0
- + "LDR____X0,[X0]
- "
-
-
- @@ -1017,8 +1017,8 @@ SKIP_32_DATA
- RET R15
-
- :primary_expr_string_string0
- - "LOAD_W0_AHEAD
- -SKIP_32_DATA
- + "LDRSW__X0,8
- +B______8
- &STRING_"
- :primary_expr_string_string1
- ":STRING_"
- @@ -1052,8 +1052,8 @@ SKIP_32_DATA
- RET R15
-
- :primary_expr_char_string0
- - "LOAD_W0_AHEAD
- -SKIP_32_DATA
- + "LDRSW__X0,8
- +B______8
- %"
-
-
- @@ -1076,8 +1076,8 @@ SKIP_32_DATA
- RET R15
-
- :primary_expr_number_string0
- - "LOAD_W0_AHEAD
- -SKIP_32_DATA
- + "LDRSW__X0,8
- +B______8
- %"
-
-
- @@ -1246,10 +1246,10 @@ SKIP_32_DATA
- RET R15
-
- :common_recursion_string0
- - "PUSH_X0 #_common_recursion
- + "STR____X0,[X18,-8]! #_common_recursion
- "
- :common_recursion_string1
- - "POP_X1 # _common_recursion
- + "LDR____X1,[X18],8 # _common_recursion
- "
-
-
- @@ -1383,15 +1383,15 @@ SKIP_32_DATA
- "# -> offset calculation
- "
- :postfix_expr_arrow_string2
- - "LOAD_W1_AHEAD
- -SKIP_32_DATA
- + "LDR____W1,8
- +B______8
- %"
- :postfix_expr_arrow_string3
- "
- -ADD_X0_X1_X0
- +ADD____X0,X1,X0
- "
- :postfix_expr_arrow_string4
- - "DEREF_X0
- + "LDR____X0,[X0]
- "
-
-
- @@ -1455,17 +1455,17 @@ ADD_X0_X1_X0
- RET R15
-
- :postfix_expr_array_string0
- - "DEREF_X0
- + "LDR____X0,[X0]
- "
- :postfix_expr_array_string1
- - "DEREF_X0_BYTE
- + "LDRB___W0,[X0]
- "
- :postfix_expr_array_string2
- - "LOAD_W2_AHEAD
- -SKIP_32_DATA
- + "LDR____W2,8
- +B______8
- %"
- :postfix_expr_array_string3
- - "ADD_X0_X1_X0
- + "ADD____X0,X1,X0
- "
- :postfix_expr_array_string4
- "ERROR in postfix_expr
- @@ -1475,7 +1475,7 @@ Missing ]
- ""
- :postfix_expr_array_string6
- "
- -LSHIFT_X0_X0_X2
- +LSL____X0,X0,X2
- "
-
- ;; postfix_expr_stub function
- @@ -1585,23 +1585,23 @@ LSHIFT_X0_X0_X2
- RET R15
-
- :additive_expr_stub_string0
- - "ADD_X0_X1_X0
- + "ADD____X0,X1,X0
- "
- :additive_expr_stub_string1
- - "SUB_X0_X1_X0
- + "SUB____X0,X1,X0
- "
- :additive_expr_stub_string2
- - "MUL_X0_X1_X0
- + "MUL____X0,X1,X0
- "
- :additive_expr_stub_string3
- - "UDIV_X0_X1_X0
- + "UDIV___X0,X1,X0
- "
- :additive_expr_stub_string4
- - "UDIV_X2_X1_X0
- -MSUB_X0_X0_X2_X1
- + "UDIV___X2,X1,X0
- +MSUB___X0,X0,X2,X1
- "
- :additive_expr_stub_string5
- - "LSHIFT_X0_X1_X0
- + "LSL____X0,X1,X0
- "
- :additive_expr_stub_string6
- "RSHIFT_X0_X1_X0
- @@ -1673,40 +1673,40 @@ MSUB_X0_X0_X2_X1
- RET R15
-
- :relational_expr_stub_string0
- - "CMP_X1_X0
- -SET_X0_TO_1
- -SKIP_INST_LT
- -SET_X0_TO_0
- + "CMP____X1,X0
- +MOV____X0,1
- +B.LT___8
- +MOV____X0,0
- "
- :relational_expr_stub_string1
- - "CMP_X1_X0
- -SET_X0_TO_1
- -SKIP_INST_LE
- -SET_X0_TO_0
- + "CMP____X1,X0
- +MOV____X0,1
- +B.LE___8
- +MOV____X0,0
- "
- :relational_expr_stub_string2
- - "CMP_X1_X0
- -SET_X0_TO_1
- -SKIP_INST_GE
- -SET_X0_TO_0
- + "CMP____X1,X0
- +MOV____X0,1
- +B.GE___8
- +MOV____X0,0
- "
- :relational_expr_stub_string3
- - "CMP_X1_X0
- -SET_X0_TO_1
- -SKIP_INST_GT
- -SET_X0_TO_0
- + "CMP____X1,X0
- +MOV____X0,1
- +B.GT___8
- +MOV____X0,0
- "
- :relational_expr_stub_string4
- - "CMP_X1_X0
- -SET_X0_TO_1
- -SKIP_INST_EQ
- -SET_X0_TO_0
- + "CMP____X1,X0
- +MOV____X0,1
- +B.EQ___8
- +MOV____X0,0
- "
- :relational_expr_stub_string5
- - "CMP_X1_X0
- -SET_X0_TO_1
- -SKIP_INST_NE
- -SET_X0_TO_0
- + "CMP____X1,X0
- +MOV____X0,1
- +B.NE___8
- +MOV____X0,0
- "
-
-
- @@ -1770,13 +1770,13 @@ SET_X0_TO_0
- RET R15
-
- :bitwise_expr_stub_string0
- - "AND_X0_X1_X0
- + "AND____X0,X1,X0
- "
- :bitwise_expr_stub_string1
- - "OR_X0_X1_X0
- + "ORR____X0,X1,X0
- "
- :bitwise_expr_stub_string2
- - "XOR_X0_X1_X0
- + "EOR____X0,X0,X1
- "
-
-
- @@ -1900,16 +1900,16 @@ SET_X0_TO_0
- RET R15
-
- :primary_expr_str0
- - "SET_X0_TO_0
- + "MOV____X0,0
- "
- :primary_expr_str1
- - "SUB_X0_X1_X0
- + "SUB____X0,X1,X0
- "
- :primary_expr_str2
- - "SET_X0_TO_1
- + "MOV____X0,1
- "
- :primary_expr_str3
- - "XOR_X0_X1_X0
- + "EOR____X0,X0,X1
- "
- :primary_expr_str4
- "Error in Primary expression
- @@ -1973,10 +1973,10 @@ Didn't get )
- RET R15
-
- :expression_string0
- - "STR_X0_[X1]
- + "STR____X0,[X1]
- "
- :expression_string1
- - "STR_BYTE_W0_[X1]
- + "STRB___W0,[X1]
- "
-
- ;; process_if function
- @@ -2060,27 +2060,27 @@ Didn't get )
- MISSING (
- "
- :process_if_string2
- - "CBNZ_X0_PAST_BR
- -LOAD_W16_AHEAD
- -SKIP_32_DATA
- + "CBNZ___X0,20
- +LDR____W16,8
- +B______8
- &ELSE_"
- :process_if_string3
- "ERROR in process_if
- MISSING )
- "
- :process_if_string4
- - "LOAD_W16_AHEAD
- -SKIP_32_DATA
- + "LDR____W16,8
- +B______8
- &_END_IF_"
- :process_if_string5
- "
- -BR_X16
- +BR_____X16
- :ELSE_"
- :process_if_string6
- ":_END_IF_"
- :process_if_string7
- "
- -BR_X16
- +BR_____X16
- "
-
- ;; save_break_frame microfunction
- @@ -2251,43 +2251,43 @@ MISSING (
- MISSING ;1
- "
- :process_for_string5
- - "CBNZ_X0_PAST_BR
- -LOAD_W16_AHEAD
- -SKIP_32_DATA
- + "CBNZ___X0,20
- +LDR____W16,8
- +B______8
- &FOR_END_"
- :process_for_string6
- "
- -BR_X16
- -LOAD_W16_AHEAD
- -SKIP_32_DATA
- +BR_____X16
- +LDR____W16,8
- +B______8
- &FOR_THEN_"
- :process_for_string7
- "
- -BR_X16
- +BR_____X16
- :FOR_ITER_"
- :process_for_string8
- "ERROR in process_for
- MISSING ;2
- "
- :process_for_string9
- - "LOAD_W16_AHEAD
- -SKIP_32_DATA
- + "LDR____W16,8
- +B______8
- &FOR_"
- :process_for_string10
- "
- -BR_X16
- +BR_____X16
- :FOR_THEN_"
- :process_for_string11
- "ERROR in process_for
- MISSING )
- "
- :process_for_string12
- - "LOAD_W16_AHEAD
- -SKIP_32_DATA
- + "LDR____W16,8
- +B______8
- &FOR_ITER_"
- :process_for_string13
- "
- -BR_X16
- +BR_____X16
- :FOR_END_"
-
-
- @@ -2374,13 +2374,13 @@ MISSING )
- MISSING ;
- "
- :process_do_string6
- - "CBZ_X0_PAST_BR
- -LOAD_W16_AHEAD
- -SKIP_32_DATA
- + "CBZ____X0,20
- +LDR____W16,8
- +B______8
- &DO_"
- :process_do_string7
- "
- -BR_X16
- +BR_____X16
- :DO_END_"
-
-
- @@ -2459,25 +2459,25 @@ BR_X16
- MISSING (
- "
- :process_while_string3
- - "CBNZ_X0_PAST_BR
- -LOAD_W16_AHEAD
- -SKIP_32_DATA
- + "CBNZ___X0,20
- +LDR____W16,8
- +B______8
- &END_WHILE_"
- :process_while_string4
- "
- -BR_X16
- +BR_____X16
- # THEN_while_"
- :process_while_string5
- "ERROR in process_while
- MISSING )
- "
- :process_while_string6
- - "LOAD_W16_AHEAD
- -SKIP_32_DATA
- + "LDR____W16,8
- +B______8
- &WHILE_"
- :process_while_string7
- "
- -BR_X16
- +BR_____X16
- :END_WHILE_"
-
-
- @@ -2520,10 +2520,10 @@ BR_X16
- MISSING ;
- "
- :return_result_string1
- - "POP_X1 # _return_result_locals
- + "LDR____X1,[X18],8 # _return_result_locals
- "
- :return_result_string2
- - "RETURN
- + "RET
- "
-
-
- @@ -2588,11 +2588,11 @@ MISSING ;
- "Not inside of a loop or case statement
- "
- :process_break_string1
- - "POP_X1 # break_cleanup_locals
- + "LDR____X1,[X18],8 # break_cleanup_locals
- "
- :process_break_string2
- - "LOAD_W16_AHEAD
- -SKIP_32_DATA
- + "LDR____W16,8
- +B______8
- &"
- :process_break_string3
- "ERROR in break statement
- @@ -2600,7 +2600,7 @@ Missing ;
- "
- :process_break_string4
- "
- -BR_X16
- +BR_____X16
- "
-
- :break_frame
- @@ -2703,8 +2703,8 @@ MISSING ;
- :recursive_statement_cleanup
- LOAD32 R13 R13 0 ; GLOBAL_TOKEN = GLOBAL_TOKEN->NEXT
- LOAD32 R1 R12 8 ; OUT->S
- - LOADUI R0 $recursive_statement_string0 ; "RETURN\n"
- - CALLI R15 @match ; IF OUT->S == "RETURN\n"
- + LOADUI R0 $recursive_statement_string0 ; "RET\n"
- + CALLI R15 @match ; IF OUT->S == "RET\n"
- JUMP.NZ R0 @recursive_statement_done ; Save some work
-
- ;; Lets pop them all off
- @@ -2725,10 +2725,10 @@ MISSING ;
- RET R15
-
- :recursive_statement_string0
- - "RETURN
- + "RET
- "
- :recursive_statement_string1
- - "POP_X1 # _recursive_statement_locals
- + "LDR____X1,[X18],8 # _recursive_statement_locals
- "
-
-
- @@ -2899,8 +2899,8 @@ MISSING ;
- " #C goto label
- "
- :statement_string1
- - "LOAD_W16_AHEAD
- -SKIP_32_DATA
- + "LDR____W16,8
- +B______8
- &"
- :statement_string2
- "ERROR in statement
- @@ -2912,7 +2912,7 @@ MISSING ;
- "
- :statement_string4
- "
- -BR_X16
- +BR_____X16
- "
-
- ;; collect_local function
- @@ -3024,7 +3024,7 @@ BR_X16
- Missing ;
- "
- :collect_local_string2
- - "PUSH_X0 #"
- + "STR____X0,[X18,-8]! #"
-
-
- ;; collect_arguments function
- @@ -3165,7 +3165,7 @@ Missing ;
- :declare_function_string1
- ":FUNCTION_"
- :declare_function_string2
- - "RETURN
- + "RET
- "
-
- :current_count
- @@ -3484,62 +3484,62 @@ Missing ;
- No ( was found
- "
- :function_call_string1
- - "PUSH_X16 # Protect a tmp register we're going to use
- -PUSH_LR # Protect the old return pointer (link)
- + "STR____X16,[X18,-8]! # Protect a tmp register we're going to use
- +STR____X30,[X18,-8]! # Protect the old return pointer (link)
- "
- :function_call_string2
- - "PUSH_BP # Protect the old base pointer
- + "STR____X17,[X18,-8]! # Protect the old base pointer
- "
- :function_call_string3
- - "SET_X16_FROM_SP # The base pointer to-be
- + "MOV____X16,X18 # The base pointer to-be
- "
- :function_call_string4
- - "PUSH_X0 #_process_expression1
- + "STR____X0,[X18,-8]! #_process_expression1
- "
- :function_call_string5
- - "PUSH_X0 #_process_expression2
- + "STR____X0,[X18,-8]! #_process_expression2
- "
- :function_call_string6
- "ERROR in process_expression_list
- No ) was found
- "
- :function_call_string7
- - "SET_X0_FROM_BP
- -LOAD_W1_AHEAD
- -SKIP_32_DATA
- + "MOV____X0,X17
- +LDR____W1,8
- +B______8
- %"
- :function_call_string8
- "
- -SUB_X0_X0_X1
- -DEREF_X0
- +SUB____X0,X0,X1
- +LDR____X0,[X0]
- "
- :function_call_string9
- - "SET_BP_FROM_X16
- + "MOV____X17,X16
- "
- :function_call_string10
- - "SET_X16_FROM_X0
- -BLR_X16
- + "MOV____X16,X0
- +BLR____X16
- "
- :function_call_string11
- - "SET_BP_FROM_X16
- + "MOV____X17,X16
- "
- :function_call_string12
- - "LOAD_W16_AHEAD
- -SKIP_32_DATA
- + "LDR____W16,8
- +B______8
- &FUNCTION_"
- :function_call_string13
- - "POP_X1 # _process_expression_locals
- + "LDR____X1,[X18],8 # _process_expression_locals
- "
- :function_call_string14
- - "POP_BP # Restore the old base pointer
- + "LDR____X17,[X18],8 # Restore the old base pointer
- "
- :function_call_string15
- - "POP_LR # Restore the old return pointer (link)
- -POP_X16 # Restore a register we used as tmp
- + "LDR____X30,[X18],8 # Restore the old return pointer (link)
- +LDR____X16,[X18],8 # Restore a register we used as tmp
- "
- :function_call_string16
- "
- -BLR_X16
- +BLR____X16
- "
-
- ;; emit function
- @@ -3791,7 +3791,7 @@ BLR_X16
- STORE32 R5 R3 20 ; I->TYPE = MEMBER_TYPE
- STORE32 R6 R3 8 ; I->OFFSET = OFFSET
- MOVE R1 R6 ; Restore OFFSET
- - MOVE R0 R3 ; RETURN I in R0
- + MOVE R0 R3 ; RET I in R0
- POPR R6 R15 ; Restore R6
- POPR R5 R15 ; Restore R5
- POPR R4 R15 ; Restore R4
- --
- 2.11.0
|