stage0-new_macros-tmp.patch 28 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149
  1. From d93e6b0a8aeaca1b8b75731132216f4227727bb1 Mon Sep 17 00:00:00 2001
  2. From: deesix <deesix@tuta.io>
  3. Date: Wed, 5 Jan 2021 00:00:00
  4. Subject: [PATCH] cc_aarch64 using new asm-like macros
  5. ---
  6. stage2/High_level_prototypes/cc_aarch64/cc_core.c | 188 +++++++--------
  7. stage2/cc_aarch64.s | 282 +++++++++++-----------
  8. 2 files changed, 235 insertions(+), 235 deletions(-)
  9. diff --git a/stage2/High_level_prototypes/cc_aarch64/cc_core.c b/stage2/High_level_prototypes/cc_aarch64/cc_core.c
  10. index 7b1f117..78af8cc 100644
  11. --- a/stage2/High_level_prototypes/cc_aarch64/cc_core.c
  12. +++ b/stage2/High_level_prototypes/cc_aarch64/cc_core.c
  13. @@ -115,22 +115,22 @@ void function_call(char* s, int bool)
  14. {
  15. require_match("ERROR in process_expression_list\nNo ( was found\n", "(");
  16. int passed = 0;
  17. - emit_out("PUSH_X16\t# Protect a tmp register we're going to use\n");
  18. - emit_out("PUSH_LR\t# Protect the old return pointer (link)\n");
  19. - emit_out("PUSH_BP\t# Protect the old base pointer\n");
  20. - emit_out("SET_X16_FROM_SP\t# The base pointer to-be\n");
  21. + emit_out("STR____X16,[X18,-8]!\t# Protect a tmp register we're going to use\n");
  22. + emit_out("STR____X30,[X18,-8]!\t# Protect the old return pointer (link)\n");
  23. + emit_out("STR____X17,[X18,-8]!\t# Protect the old base pointer\n");
  24. + emit_out("MOV____X16,X18\t# The base pointer to-be\n");
  25. if(global_token->s[0] != ')')
  26. {
  27. expression();
  28. - emit_out("PUSH_X0\t#_process_expression1\n");
  29. + emit_out("STR____X0,[X18,-8]!\t#_process_expression1\n");
  30. passed = 1;
  31. while(global_token->s[0] == ',')
  32. {
  33. global_token = global_token->next;
  34. expression();
  35. - emit_out("PUSH_X0\t#_process_expression2\n");
  36. + emit_out("STR____X0,[X18,-8]!\t#_process_expression2\n");
  37. passed = passed + 1;
  38. }
  39. }
  40. @@ -139,36 +139,36 @@ void function_call(char* s, int bool)
  41. if(TRUE == bool)
  42. {
  43. - emit_out("SET_X0_FROM_BP\n");
  44. - emit_out("LOAD_W1_AHEAD\nSKIP_32_DATA\n%");
  45. + emit_out("MOV____X0,X17\n");
  46. + emit_out("LDR____W1,8\nB______8\n%");
  47. emit_out(s);
  48. - emit_out("\nSUB_X0_X0_X1\n");
  49. - emit_out("DEREF_X0\n");
  50. - emit_out("SET_BP_FROM_X16\n");
  51. - emit_out("SET_X16_FROM_X0\n");
  52. - emit_out("BLR_X16\n");
  53. + emit_out("\nSUB____X0,X0,X1\n");
  54. + emit_out("LDR____X0,[X0]\n");
  55. + emit_out("MOV____X17,X16\n");
  56. + emit_out("MOV____X16,X0\n");
  57. + emit_out("BLR____X16\n");
  58. }
  59. else
  60. {
  61. - emit_out("SET_BP_FROM_X16\n");
  62. - emit_out("LOAD_W16_AHEAD\nSKIP_32_DATA\n&FUNCTION_");
  63. + emit_out("MOV____X17,X16\n");
  64. + emit_out("LDR____W16,8\nB______8\n&FUNCTION_");
  65. emit_out(s);
  66. emit_out("\n");
  67. - emit_out("BLR_X16\n");
  68. + emit_out("BLR____X16\n");
  69. }
  70. for(; passed > 0; passed = passed - 1)
  71. {
  72. - emit_out("POP_X1\t# _process_expression_locals\n");
  73. + emit_out("LDR____X1,[X18],8\t# _process_expression_locals\n");
  74. }
  75. - emit_out("POP_BP\t# Restore the old base pointer\n");
  76. - emit_out("POP_LR\t# Restore the old return pointer (link)\n");
  77. - emit_out("POP_X16\t# Restore a register we used as tmp\n");
  78. + emit_out("LDR____X17,[X18],8\t# Restore the old base pointer\n");
  79. + emit_out("LDR____X30,[X18],8\t# Restore the old return pointer (link)\n");
  80. + emit_out("LDR____X16,[X18],8\t# Restore a register we used as tmp\n");
  81. }
  82. void constant_load(struct token_list* a)
  83. {
  84. - emit_out("LOAD_W0_AHEAD\nSKIP_32_DATA\n%");
  85. + emit_out("LDRSW__X0,8\nB______8\n%");
  86. emit_out(a->arguments->s);
  87. emit_out("\n");
  88. }
  89. @@ -181,14 +181,14 @@ void variable_load(struct token_list* a)
  90. return;
  91. }
  92. current_target = a->type;
  93. - emit_out("SET_X0_FROM_BP\nLOAD_W1_AHEAD\nSKIP_32_DATA\n%");
  94. + emit_out("MOV____X0,X17\nLDR____W1,8\nB______8\n%");
  95. emit_out(numerate_number(a->depth));
  96. - emit_out("\nSUB_X0_X0_X1\n\n");
  97. + emit_out("\nSUB____X0,X0,X1\n\n");
  98. if(TRUE == Address_of) return;
  99. if(match("=", global_token->s)) return;
  100. - emit_out("DEREF_X0\n");
  101. + emit_out("LDR____X0,[X0]\n");
  102. }
  103. void function_load(struct token_list* a)
  104. @@ -199,7 +199,7 @@ void function_load(struct token_list* a)
  105. return;
  106. }
  107. - emit_out("LOAD_W0_AHEAD\nSKIP_32_DATA\n&FUNCTION_");
  108. + emit_out("LDRSW__X0,8\nB______8\n&FUNCTION_");
  109. emit_out(a->s);
  110. emit_out("\n");
  111. }
  112. @@ -207,10 +207,10 @@ void function_load(struct token_list* a)
  113. void global_load(struct token_list* a)
  114. {
  115. current_target = a->type;
  116. - emit_out("LOAD_W0_AHEAD\nSKIP_32_DATA\n&GLOBAL_");
  117. + emit_out("LDRSW__X0,8\nB______8\n&GLOBAL_");
  118. emit_out(a->s);
  119. emit_out("\n");
  120. - if(!match("=", global_token->s)) emit_out("DEREF_X0\n");
  121. + if(!match("=", global_token->s)) emit_out("LDR____X0,[X0]\n");
  122. }
  123. /*
  124. @@ -236,7 +236,7 @@ void primary_expr_string()
  125. {
  126. char* number_string = numerate_number(current_count);
  127. current_count = current_count + 1;
  128. - emit_out("LOAD_W0_AHEAD\nSKIP_32_DATA\n&STRING_");
  129. + emit_out("LDRSW__X0,8\nB______8\n&STRING_");
  130. uniqueID_out(function->s, number_string);
  131. /* The target */
  132. @@ -250,7 +250,7 @@ void primary_expr_string()
  133. void primary_expr_char()
  134. {
  135. - emit_out("LOAD_W0_AHEAD\nSKIP_32_DATA\n%");
  136. + emit_out("LDRSW__X0,8\nB______8\n%");
  137. emit_out(numerate_number(escape_lookup(global_token->s + 1)));
  138. emit_out("\n");
  139. global_token = global_token->next;
  140. @@ -258,7 +258,7 @@ void primary_expr_char()
  141. void primary_expr_number()
  142. {
  143. - emit_out("LOAD_W0_AHEAD\nSKIP_32_DATA\n%");
  144. + emit_out("LDRSW__X0,8\nB______8\n%");
  145. emit_out(global_token->s);
  146. emit_out("\n");
  147. global_token = global_token->next;
  148. @@ -336,10 +336,10 @@ void common_recursion(FUNCTION f)
  149. {
  150. last_type = current_target;
  151. global_token = global_token->next;
  152. - emit_out("PUSH_X0\t#_common_recursion\n");
  153. + emit_out("STR____X0,[X18,-8]!\t#_common_recursion\n");
  154. f();
  155. current_target = promote_type(current_target, last_type);
  156. - emit_out("POP_X1\t# _common_recursion\n");
  157. + emit_out("LDR____X1,[X18],8\t# _common_recursion\n");
  158. }
  159. void general_recursion( FUNCTION f, char* s, char* name, FUNCTION iterate)
  160. @@ -389,14 +389,14 @@ void postfix_expr_arrow()
  161. if(0 != i->offset)
  162. {
  163. emit_out("# -> offset calculation\n");
  164. - emit_out("LOAD_W1_AHEAD\nSKIP_32_DATA\n%");
  165. + emit_out("LDR____W1,8\nB______8\n%");
  166. emit_out(numerate_number(i->offset));
  167. - emit_out("\nADD_X0_X1_X0\n");
  168. + emit_out("\nADD____X0,X1,X0\n");
  169. }
  170. if(!match("=", global_token->s) && (8 == i->size))
  171. {
  172. - emit_out("DEREF_X0\n");
  173. + emit_out("LDR____X0,[X0]\n");
  174. }
  175. }
  176. @@ -405,21 +405,21 @@ void postfix_expr_array()
  177. struct type* array = current_target;
  178. common_recursion(expression);
  179. current_target = array;
  180. - char* assign = "DEREF_X0\n";
  181. + char* assign = "LDR____X0,[X0]\n";
  182. /* Add support for Ints */
  183. if(match("char*", current_target->name))
  184. {
  185. - assign = "DEREF_X0_BYTE\n";
  186. + assign = "LDRB___W0,[X0]\n";
  187. }
  188. else
  189. {
  190. - emit_out("LOAD_W2_AHEAD\nSKIP_32_DATA\n%");
  191. + emit_out("LDR____W2,8\nB______8\n%");
  192. emit_out(numerate_number(ceil_log2(current_target->indirect->size)));
  193. - emit_out("\nLSHIFT_X0_X0_X2\n");
  194. + emit_out("\nLSL____X0,X0,X2\n");
  195. }
  196. - emit_out("ADD_X0_X1_X0\n");
  197. + emit_out("ADD____X0,X1,X0\n");
  198. require_match("ERROR in postfix_expr\nMissing ]\n", "]");
  199. if(match("=", global_token->s))
  200. @@ -445,7 +445,7 @@ void unary_expr_sizeof()
  201. struct type* a = type_name();
  202. require_match("ERROR in unary_expr\nMissing )\n", ")");
  203. - emit_out("LOAD_W0_AHEAD\nSKIP_32_DATA\n%");
  204. + emit_out("LDRSW__X0,8\nB______8\n%");
  205. emit_out(numerate_number(a->size));
  206. emit_out("\n");
  207. }
  208. @@ -484,12 +484,12 @@ void postfix_expr()
  209. */
  210. void additive_expr_stub()
  211. {
  212. - general_recursion(postfix_expr, "ADD_X0_X1_X0\n", "+", additive_expr_stub);
  213. - general_recursion(postfix_expr, "SUB_X0_X1_X0\n", "-", additive_expr_stub);
  214. - general_recursion(postfix_expr, "MUL_X0_X1_X0\n", "*", additive_expr_stub);
  215. - general_recursion(postfix_expr, "UDIV_X0_X1_X0\n", "/", additive_expr_stub);
  216. - general_recursion(postfix_expr, "UDIV_X2_X1_X0\nMSUB_X0_X0_X2_X1\n", "%", additive_expr_stub);
  217. - general_recursion(postfix_expr, "LSHIFT_X0_X1_X0\n", "<<", additive_expr_stub);
  218. + general_recursion(postfix_expr, "ADD____X0,X1,X0\n", "+", additive_expr_stub);
  219. + general_recursion(postfix_expr, "SUB____X0,X1,X0\n", "-", additive_expr_stub);
  220. + general_recursion(postfix_expr, "MUL____X0,X1,X0\n", "*", additive_expr_stub);
  221. + general_recursion(postfix_expr, "UDIV___X0,X1,X0\n", "/", additive_expr_stub);
  222. + general_recursion(postfix_expr, "UDIV___X2,X1,X0\nMSUB___X0,X0,X2,X1\n", "%", additive_expr_stub);
  223. + general_recursion(postfix_expr, "LSL____X0,X1,X0\n", "<<", additive_expr_stub);
  224. general_recursion(postfix_expr, "RSHIFT_X0_X1_X0\n", ">>", additive_expr_stub);
  225. }
  226. @@ -512,12 +512,12 @@ void additive_expr()
  227. void relational_expr_stub()
  228. {
  229. - general_recursion(additive_expr, "CMP_X1_X0\nSET_X0_TO_1\nSKIP_INST_LT\nSET_X0_TO_0\n", "<", relational_expr_stub);
  230. - general_recursion(additive_expr, "CMP_X1_X0\nSET_X0_TO_1\nSKIP_INST_LE\nSET_X0_TO_0\n", "<=", relational_expr_stub);
  231. - general_recursion(additive_expr, "CMP_X1_X0\nSET_X0_TO_1\nSKIP_INST_GE\nSET_X0_TO_0\n", ">=", relational_expr_stub);
  232. - general_recursion(additive_expr, "CMP_X1_X0\nSET_X0_TO_1\nSKIP_INST_GT\nSET_X0_TO_0\n", ">", relational_expr_stub);
  233. - general_recursion(additive_expr, "CMP_X1_X0\nSET_X0_TO_1\nSKIP_INST_EQ\nSET_X0_TO_0\n", "==", relational_expr_stub);
  234. - general_recursion(additive_expr, "CMP_X1_X0\nSET_X0_TO_1\nSKIP_INST_NE\nSET_X0_TO_0\n", "!=", relational_expr_stub);
  235. + general_recursion(additive_expr, "CMP____X1,X0\nMOV____X0,1\nB.LT___8\nMOV____X0,0\n", "<", relational_expr_stub);
  236. + general_recursion(additive_expr, "CMP____X1,X0\nMOV____X0,1\nB.LE___8\nMOV____X0,0\n", "<=", relational_expr_stub);
  237. + general_recursion(additive_expr, "CMP____X1,X0\nMOV____X0,1\nB.GE___8\nMOV____X0,0\n", ">=", relational_expr_stub);
  238. + general_recursion(additive_expr, "CMP____X1,X0\nMOV____X0,1\nB.GT___8\nMOV____X0,0\n", ">", relational_expr_stub);
  239. + general_recursion(additive_expr, "CMP____X1,X0\nMOV____X0,1\nB.EQ___8\nMOV____X0,0\n", "==", relational_expr_stub);
  240. + general_recursion(additive_expr, "CMP____X1,X0\nMOV____X0,1\nB.NE___8\nMOV____X0,0\n", "!=", relational_expr_stub);
  241. }
  242. void relational_expr()
  243. @@ -537,11 +537,11 @@ void relational_expr()
  244. */
  245. void bitwise_expr_stub()
  246. {
  247. - general_recursion(relational_expr, "AND_X0_X1_X0\n", "&", bitwise_expr_stub);
  248. - general_recursion(relational_expr, "AND_X0_X1_X0\n", "&&", bitwise_expr_stub);
  249. - general_recursion(relational_expr, "OR_X0_X1_X0\n", "|", bitwise_expr_stub);
  250. - general_recursion(relational_expr, "OR_X0_X1_X0\n", "||", bitwise_expr_stub);
  251. - general_recursion(relational_expr, "XOR_X0_X1_X0\n", "^", bitwise_expr_stub);
  252. + general_recursion(relational_expr, "AND____X0,X1,X0\n", "&", bitwise_expr_stub);
  253. + general_recursion(relational_expr, "AND____X0,X1,X0\n", "&&", bitwise_expr_stub);
  254. + general_recursion(relational_expr, "ORR____X0,X1,X0\n", "|", bitwise_expr_stub);
  255. + general_recursion(relational_expr, "ORR____X0,X1,X0\n", "||", bitwise_expr_stub);
  256. + general_recursion(relational_expr, "EOR____X0,X0,X1\n", "^", bitwise_expr_stub);
  257. }
  258. @@ -572,15 +572,15 @@ void primary_expr()
  259. if(match("sizeof", global_token->s)) unary_expr_sizeof();
  260. else if('-' == global_token->s[0])
  261. {
  262. - emit_out("SET_X0_TO_0\n");
  263. + emit_out("MOV____X0,0\n");
  264. common_recursion(primary_expr);
  265. - emit_out("SUB_X0_X1_X0\n");
  266. + emit_out("SUB____X0,X1,X0\n");
  267. }
  268. else if('!' == global_token->s[0])
  269. {
  270. - emit_out("SET_X0_TO_1\n");
  271. + emit_out("MOV____X0,1\n");
  272. common_recursion(postfix_expr);
  273. - emit_out("XOR_X0_X1_X0\n");
  274. + emit_out("EOR____X0,X0,X1\n");
  275. }
  276. else if(global_token->s[0] == '(')
  277. {
  278. @@ -603,11 +603,11 @@ void expression()
  279. char* store;
  280. if(!match("]", global_token->prev->s) || !match("char*", current_target->name))
  281. {
  282. - store = "STR_X0_[X1]\n";
  283. + store = "STR____X0,[X1]\n";
  284. }
  285. else
  286. {
  287. - store = "STR_BYTE_W0_[X1]\n";
  288. + store = "STRB___W0,[X1]\n";
  289. }
  290. common_recursion(expression);
  291. @@ -655,7 +655,7 @@ void collect_local()
  292. require_match("ERROR in collect_local\nMissing ;\n", ";");
  293. - emit_out("PUSH_X0\t#");
  294. + emit_out("STR____X0,[X18,-8]!\t#");
  295. emit_out(a->s);
  296. emit_out("\n");
  297. }
  298. @@ -675,16 +675,16 @@ void process_if()
  299. require_match("ERROR in process_if\nMISSING (\n", "(");
  300. expression();
  301. - emit_out("CBNZ_X0_PAST_BR\nLOAD_W16_AHEAD\nSKIP_32_DATA\n&ELSE_");
  302. + emit_out("CBNZ___X0,20\nLDR____W16,8\nB______8\n&ELSE_");
  303. uniqueID_out(function->s, number_string);
  304. - emit_out("\nBR_X16\n");
  305. + emit_out("\nBR_____X16\n");
  306. require_match("ERROR in process_if\nMISSING )\n", ")");
  307. statement();
  308. - emit_out("LOAD_W16_AHEAD\nSKIP_32_DATA\n&_END_IF_");
  309. + emit_out("LDR____W16,8\nB______8\n&_END_IF_");
  310. uniqueID_out(function->s, number_string);
  311. - emit_out("\nBR_X16\n:ELSE_");
  312. + emit_out("\nBR_____X16\n:ELSE_");
  313. uniqueID_out(function->s, number_string);
  314. if(match("else", global_token->s))
  315. @@ -728,27 +728,27 @@ void process_for()
  316. require_match("ERROR in process_for\nMISSING ;1\n", ";");
  317. expression();
  318. - emit_out("CBNZ_X0_PAST_BR\nLOAD_W16_AHEAD\nSKIP_32_DATA\n&FOR_END_");
  319. + emit_out("CBNZ___X0,20\nLDR____W16,8\nB______8\n&FOR_END_");
  320. uniqueID_out(function->s, number_string);
  321. - emit_out("\nBR_X16\nLOAD_W16_AHEAD\nSKIP_32_DATA\n&FOR_THEN_");
  322. + emit_out("\nBR_____X16\nLDR____W16,8\nB______8\n&FOR_THEN_");
  323. uniqueID_out(function->s, number_string);
  324. - emit_out("\nBR_X16\n:FOR_ITER_");
  325. + emit_out("\nBR_____X16\n:FOR_ITER_");
  326. uniqueID_out(function->s, number_string);
  327. require_match("ERROR in process_for\nMISSING ;2\n", ";");
  328. expression();
  329. - emit_out("LOAD_W16_AHEAD\nSKIP_32_DATA\n&FOR_");
  330. + emit_out("LDR____W16,8\nB______8\n&FOR_");
  331. uniqueID_out(function->s, number_string);
  332. - emit_out("\nBR_X16\n:FOR_THEN_");
  333. + emit_out("\nBR_____X16\n:FOR_THEN_");
  334. uniqueID_out(function->s, number_string);
  335. require_match("ERROR in process_for\nMISSING )\n", ")");
  336. statement();
  337. - emit_out("LOAD_W16_AHEAD\nSKIP_32_DATA\n&FOR_ITER_");
  338. + emit_out("LDR____W16,8\nB______8\n&FOR_ITER_");
  339. uniqueID_out(function->s, number_string);
  340. - emit_out("\nBR_X16\n:FOR_END_");
  341. + emit_out("\nBR_____X16\n:FOR_END_");
  342. uniqueID_out(function->s, number_string);
  343. break_target_head = nested_break_head;
  344. @@ -800,9 +800,9 @@ void process_do()
  345. require_match("ERROR in process_do\nMISSING )\n", ")");
  346. require_match("ERROR in process_do\nMISSING ;\n", ";");
  347. - emit_out("CBZ_X0_PAST_BR\nLOAD_W16_AHEAD\nSKIP_32_DATA\n&DO_");
  348. + emit_out("CBZ____X0,20\nLDR____W16,8\nB______8\n&DO_");
  349. uniqueID_out(function->s, number_string);
  350. - emit_out("\nBR_X16\n:DO_END_");
  351. + emit_out("\nBR_____X16\n:DO_END_");
  352. uniqueID_out(function->s, number_string);
  353. break_frame = nested_locals;
  354. @@ -835,17 +835,17 @@ void process_while()
  355. require_match("ERROR in process_while\nMISSING (\n", "(");
  356. expression();
  357. - emit_out("CBNZ_X0_PAST_BR\nLOAD_W16_AHEAD\nSKIP_32_DATA\n&END_WHILE_");
  358. + emit_out("CBNZ___X0,20\nLDR____W16,8\nB______8\n&END_WHILE_");
  359. uniqueID_out(function->s, number_string);
  360. - emit_out("\nBR_X16\n# THEN_while_");
  361. + emit_out("\nBR_____X16\n# THEN_while_");
  362. uniqueID_out(function->s, number_string);
  363. require_match("ERROR in process_while\nMISSING )\n", ")");
  364. statement();
  365. - emit_out("LOAD_W16_AHEAD\nSKIP_32_DATA\n&WHILE_");
  366. + emit_out("LDR____W16,8\nB______8\n&WHILE_");
  367. uniqueID_out(function->s, number_string);
  368. - emit_out("\nBR_X16\n:END_WHILE_");
  369. + emit_out("\nBR_____X16\n:END_WHILE_");
  370. uniqueID_out(function->s, number_string);
  371. break_target_head = nested_break_head;
  372. @@ -865,9 +865,9 @@ void return_result()
  373. struct token_list* i;
  374. for(i = function->locals; NULL != i; i = i->next)
  375. {
  376. - emit_out("POP_X1\t# _return_result_locals\n");
  377. + emit_out("LDR____X1,[X18],8\t# _return_result_locals\n");
  378. }
  379. - emit_out("RETURN\n");
  380. + emit_out("RET\n");
  381. }
  382. void process_break()
  383. @@ -882,16 +882,16 @@ void process_break()
  384. while(i != break_frame)
  385. {
  386. if(NULL == i) break;
  387. - emit_out("POP_X1\t# break_cleanup_locals\n");
  388. + emit_out("LDR____X1,[X18],8\t# break_cleanup_locals\n");
  389. i = i->next;
  390. }
  391. global_token = global_token->next;
  392. - emit_out("LOAD_W16_AHEAD\nSKIP_32_DATA\n&");
  393. + emit_out("LDR____W16,8\nB______8\n&");
  394. emit_out(break_target_head);
  395. emit_out(break_target_func);
  396. emit_out("_");
  397. emit_out(break_target_num);
  398. - emit_out("\nBR_X16\n");
  399. + emit_out("\nBR_____X16\n");
  400. require_match("ERROR in break statement\nMissing ;\n", ";");
  401. }
  402. @@ -907,12 +907,12 @@ void recursive_statement()
  403. global_token = global_token->next;
  404. /* Clean up any locals added */
  405. - if(!match("RETURN\n", out->s))
  406. + if(!match("RET\n", out->s))
  407. {
  408. struct token_list* i;
  409. for(i = function->locals; frame != i; i = i->next)
  410. {
  411. - emit_out( "POP_X1\t# _recursive_statement_locals\n");
  412. + emit_out( "LDR____X1,[X18],8\t# _recursive_statement_locals\n");
  413. }
  414. }
  415. function->locals = frame;
  416. @@ -977,9 +977,9 @@ void statement()
  417. else if(match("goto", global_token->s))
  418. {
  419. global_token = global_token->next;
  420. - emit_out("LOAD_W16_AHEAD\nSKIP_32_DATA\n&");
  421. + emit_out("LDR____W16,8\nB______8\n&");
  422. emit_out(global_token->s);
  423. - emit_out("\nBR_X16\n");
  424. + emit_out("\nBR_____X16\n");
  425. global_token = global_token->next;
  426. require_match("ERROR in statement\nMissing ;\n", ";");
  427. }
  428. @@ -1061,10 +1061,10 @@ void declare_function()
  429. emit_out("\n");
  430. statement();
  431. - /* Prevent duplicate RETURNS */
  432. - if(!match("RETURN\n", out->s))
  433. + /* Prevent duplicate RETS */
  434. + if(!match("RET\n", out->s))
  435. {
  436. - emit_out("RETURN\n");
  437. + emit_out("RET\n");
  438. }
  439. }
  440. }
  441. diff --git a/stage2/cc_aarch64.s b/stage2/cc_aarch64.s
  442. index ac46dea..8c8b1a2 100644
  443. --- a/stage2/cc_aarch64.s
  444. +++ b/stage2/cc_aarch64.s
  445. @@ -771,8 +771,8 @@ Missing (
  446. Missing )
  447. "
  448. :unary_expr_sizeof_string2
  449. - "LOAD_W0_AHEAD
  450. -SKIP_32_DATA
  451. + "LDRSW__X0,8
  452. +B______8
  453. %"
  454. @@ -792,8 +792,8 @@ SKIP_32_DATA
  455. RET R15
  456. :constant_load_string0
  457. - "LOAD_W0_AHEAD
  458. -SKIP_32_DATA
  459. + "LDRSW__X0,8
  460. +B______8
  461. %"
  462. @@ -854,16 +854,16 @@ SKIP_32_DATA
  463. RET R15
  464. :variable_load_string0
  465. - "SET_X0_FROM_BP
  466. -LOAD_W1_AHEAD
  467. -SKIP_32_DATA
  468. + "MOV____X0,X17
  469. +LDR____W1,8
  470. +B______8
  471. %"
  472. :variable_load_string1
  473. - "DEREF_X0
  474. + "LDR____X0,[X0]
  475. "
  476. :variable_load_string2
  477. "
  478. -SUB_X0_X0_X1
  479. +SUB____X0,X0,X1
  480. "
  481. @@ -900,8 +900,8 @@ SUB_X0_X0_X1
  482. RET R15
  483. :function_load_string0
  484. - "LOAD_W0_AHEAD
  485. -SKIP_32_DATA
  486. + "LDRSW__X0,8
  487. +B______8
  488. &FUNCTION_"
  489. @@ -936,11 +936,11 @@ SKIP_32_DATA
  490. RET R15
  491. :global_load_string0
  492. - "LOAD_W0_AHEAD
  493. -SKIP_32_DATA
  494. + "LDRSW__X0,8
  495. +B______8
  496. &GLOBAL_"
  497. :global_load_string1
  498. - "DEREF_X0
  499. + "LDR____X0,[X0]
  500. "
  501. @@ -1017,8 +1017,8 @@ SKIP_32_DATA
  502. RET R15
  503. :primary_expr_string_string0
  504. - "LOAD_W0_AHEAD
  505. -SKIP_32_DATA
  506. + "LDRSW__X0,8
  507. +B______8
  508. &STRING_"
  509. :primary_expr_string_string1
  510. ":STRING_"
  511. @@ -1052,8 +1052,8 @@ SKIP_32_DATA
  512. RET R15
  513. :primary_expr_char_string0
  514. - "LOAD_W0_AHEAD
  515. -SKIP_32_DATA
  516. + "LDRSW__X0,8
  517. +B______8
  518. %"
  519. @@ -1076,8 +1076,8 @@ SKIP_32_DATA
  520. RET R15
  521. :primary_expr_number_string0
  522. - "LOAD_W0_AHEAD
  523. -SKIP_32_DATA
  524. + "LDRSW__X0,8
  525. +B______8
  526. %"
  527. @@ -1246,10 +1246,10 @@ SKIP_32_DATA
  528. RET R15
  529. :common_recursion_string0
  530. - "PUSH_X0 #_common_recursion
  531. + "STR____X0,[X18,-8]! #_common_recursion
  532. "
  533. :common_recursion_string1
  534. - "POP_X1 # _common_recursion
  535. + "LDR____X1,[X18],8 # _common_recursion
  536. "
  537. @@ -1383,15 +1383,15 @@ SKIP_32_DATA
  538. "# -> offset calculation
  539. "
  540. :postfix_expr_arrow_string2
  541. - "LOAD_W1_AHEAD
  542. -SKIP_32_DATA
  543. + "LDR____W1,8
  544. +B______8
  545. %"
  546. :postfix_expr_arrow_string3
  547. "
  548. -ADD_X0_X1_X0
  549. +ADD____X0,X1,X0
  550. "
  551. :postfix_expr_arrow_string4
  552. - "DEREF_X0
  553. + "LDR____X0,[X0]
  554. "
  555. @@ -1455,17 +1455,17 @@ ADD_X0_X1_X0
  556. RET R15
  557. :postfix_expr_array_string0
  558. - "DEREF_X0
  559. + "LDR____X0,[X0]
  560. "
  561. :postfix_expr_array_string1
  562. - "DEREF_X0_BYTE
  563. + "LDRB___W0,[X0]
  564. "
  565. :postfix_expr_array_string2
  566. - "LOAD_W2_AHEAD
  567. -SKIP_32_DATA
  568. + "LDR____W2,8
  569. +B______8
  570. %"
  571. :postfix_expr_array_string3
  572. - "ADD_X0_X1_X0
  573. + "ADD____X0,X1,X0
  574. "
  575. :postfix_expr_array_string4
  576. "ERROR in postfix_expr
  577. @@ -1475,7 +1475,7 @@ Missing ]
  578. ""
  579. :postfix_expr_array_string6
  580. "
  581. -LSHIFT_X0_X0_X2
  582. +LSL____X0,X0,X2
  583. "
  584. ;; postfix_expr_stub function
  585. @@ -1585,23 +1585,23 @@ LSHIFT_X0_X0_X2
  586. RET R15
  587. :additive_expr_stub_string0
  588. - "ADD_X0_X1_X0
  589. + "ADD____X0,X1,X0
  590. "
  591. :additive_expr_stub_string1
  592. - "SUB_X0_X1_X0
  593. + "SUB____X0,X1,X0
  594. "
  595. :additive_expr_stub_string2
  596. - "MUL_X0_X1_X0
  597. + "MUL____X0,X1,X0
  598. "
  599. :additive_expr_stub_string3
  600. - "UDIV_X0_X1_X0
  601. + "UDIV___X0,X1,X0
  602. "
  603. :additive_expr_stub_string4
  604. - "UDIV_X2_X1_X0
  605. -MSUB_X0_X0_X2_X1
  606. + "UDIV___X2,X1,X0
  607. +MSUB___X0,X0,X2,X1
  608. "
  609. :additive_expr_stub_string5
  610. - "LSHIFT_X0_X1_X0
  611. + "LSL____X0,X1,X0
  612. "
  613. :additive_expr_stub_string6
  614. "RSHIFT_X0_X1_X0
  615. @@ -1673,40 +1673,40 @@ MSUB_X0_X0_X2_X1
  616. RET R15
  617. :relational_expr_stub_string0
  618. - "CMP_X1_X0
  619. -SET_X0_TO_1
  620. -SKIP_INST_LT
  621. -SET_X0_TO_0
  622. + "CMP____X1,X0
  623. +MOV____X0,1
  624. +B.LT___8
  625. +MOV____X0,0
  626. "
  627. :relational_expr_stub_string1
  628. - "CMP_X1_X0
  629. -SET_X0_TO_1
  630. -SKIP_INST_LE
  631. -SET_X0_TO_0
  632. + "CMP____X1,X0
  633. +MOV____X0,1
  634. +B.LE___8
  635. +MOV____X0,0
  636. "
  637. :relational_expr_stub_string2
  638. - "CMP_X1_X0
  639. -SET_X0_TO_1
  640. -SKIP_INST_GE
  641. -SET_X0_TO_0
  642. + "CMP____X1,X0
  643. +MOV____X0,1
  644. +B.GE___8
  645. +MOV____X0,0
  646. "
  647. :relational_expr_stub_string3
  648. - "CMP_X1_X0
  649. -SET_X0_TO_1
  650. -SKIP_INST_GT
  651. -SET_X0_TO_0
  652. + "CMP____X1,X0
  653. +MOV____X0,1
  654. +B.GT___8
  655. +MOV____X0,0
  656. "
  657. :relational_expr_stub_string4
  658. - "CMP_X1_X0
  659. -SET_X0_TO_1
  660. -SKIP_INST_EQ
  661. -SET_X0_TO_0
  662. + "CMP____X1,X0
  663. +MOV____X0,1
  664. +B.EQ___8
  665. +MOV____X0,0
  666. "
  667. :relational_expr_stub_string5
  668. - "CMP_X1_X0
  669. -SET_X0_TO_1
  670. -SKIP_INST_NE
  671. -SET_X0_TO_0
  672. + "CMP____X1,X0
  673. +MOV____X0,1
  674. +B.NE___8
  675. +MOV____X0,0
  676. "
  677. @@ -1770,13 +1770,13 @@ SET_X0_TO_0
  678. RET R15
  679. :bitwise_expr_stub_string0
  680. - "AND_X0_X1_X0
  681. + "AND____X0,X1,X0
  682. "
  683. :bitwise_expr_stub_string1
  684. - "OR_X0_X1_X0
  685. + "ORR____X0,X1,X0
  686. "
  687. :bitwise_expr_stub_string2
  688. - "XOR_X0_X1_X0
  689. + "EOR____X0,X0,X1
  690. "
  691. @@ -1900,16 +1900,16 @@ SET_X0_TO_0
  692. RET R15
  693. :primary_expr_str0
  694. - "SET_X0_TO_0
  695. + "MOV____X0,0
  696. "
  697. :primary_expr_str1
  698. - "SUB_X0_X1_X0
  699. + "SUB____X0,X1,X0
  700. "
  701. :primary_expr_str2
  702. - "SET_X0_TO_1
  703. + "MOV____X0,1
  704. "
  705. :primary_expr_str3
  706. - "XOR_X0_X1_X0
  707. + "EOR____X0,X0,X1
  708. "
  709. :primary_expr_str4
  710. "Error in Primary expression
  711. @@ -1973,10 +1973,10 @@ Didn't get )
  712. RET R15
  713. :expression_string0
  714. - "STR_X0_[X1]
  715. + "STR____X0,[X1]
  716. "
  717. :expression_string1
  718. - "STR_BYTE_W0_[X1]
  719. + "STRB___W0,[X1]
  720. "
  721. ;; process_if function
  722. @@ -2060,27 +2060,27 @@ Didn't get )
  723. MISSING (
  724. "
  725. :process_if_string2
  726. - "CBNZ_X0_PAST_BR
  727. -LOAD_W16_AHEAD
  728. -SKIP_32_DATA
  729. + "CBNZ___X0,20
  730. +LDR____W16,8
  731. +B______8
  732. &ELSE_"
  733. :process_if_string3
  734. "ERROR in process_if
  735. MISSING )
  736. "
  737. :process_if_string4
  738. - "LOAD_W16_AHEAD
  739. -SKIP_32_DATA
  740. + "LDR____W16,8
  741. +B______8
  742. &_END_IF_"
  743. :process_if_string5
  744. "
  745. -BR_X16
  746. +BR_____X16
  747. :ELSE_"
  748. :process_if_string6
  749. ":_END_IF_"
  750. :process_if_string7
  751. "
  752. -BR_X16
  753. +BR_____X16
  754. "
  755. ;; save_break_frame microfunction
  756. @@ -2251,43 +2251,43 @@ MISSING (
  757. MISSING ;1
  758. "
  759. :process_for_string5
  760. - "CBNZ_X0_PAST_BR
  761. -LOAD_W16_AHEAD
  762. -SKIP_32_DATA
  763. + "CBNZ___X0,20
  764. +LDR____W16,8
  765. +B______8
  766. &FOR_END_"
  767. :process_for_string6
  768. "
  769. -BR_X16
  770. -LOAD_W16_AHEAD
  771. -SKIP_32_DATA
  772. +BR_____X16
  773. +LDR____W16,8
  774. +B______8
  775. &FOR_THEN_"
  776. :process_for_string7
  777. "
  778. -BR_X16
  779. +BR_____X16
  780. :FOR_ITER_"
  781. :process_for_string8
  782. "ERROR in process_for
  783. MISSING ;2
  784. "
  785. :process_for_string9
  786. - "LOAD_W16_AHEAD
  787. -SKIP_32_DATA
  788. + "LDR____W16,8
  789. +B______8
  790. &FOR_"
  791. :process_for_string10
  792. "
  793. -BR_X16
  794. +BR_____X16
  795. :FOR_THEN_"
  796. :process_for_string11
  797. "ERROR in process_for
  798. MISSING )
  799. "
  800. :process_for_string12
  801. - "LOAD_W16_AHEAD
  802. -SKIP_32_DATA
  803. + "LDR____W16,8
  804. +B______8
  805. &FOR_ITER_"
  806. :process_for_string13
  807. "
  808. -BR_X16
  809. +BR_____X16
  810. :FOR_END_"
  811. @@ -2374,13 +2374,13 @@ MISSING )
  812. MISSING ;
  813. "
  814. :process_do_string6
  815. - "CBZ_X0_PAST_BR
  816. -LOAD_W16_AHEAD
  817. -SKIP_32_DATA
  818. + "CBZ____X0,20
  819. +LDR____W16,8
  820. +B______8
  821. &DO_"
  822. :process_do_string7
  823. "
  824. -BR_X16
  825. +BR_____X16
  826. :DO_END_"
  827. @@ -2459,25 +2459,25 @@ BR_X16
  828. MISSING (
  829. "
  830. :process_while_string3
  831. - "CBNZ_X0_PAST_BR
  832. -LOAD_W16_AHEAD
  833. -SKIP_32_DATA
  834. + "CBNZ___X0,20
  835. +LDR____W16,8
  836. +B______8
  837. &END_WHILE_"
  838. :process_while_string4
  839. "
  840. -BR_X16
  841. +BR_____X16
  842. # THEN_while_"
  843. :process_while_string5
  844. "ERROR in process_while
  845. MISSING )
  846. "
  847. :process_while_string6
  848. - "LOAD_W16_AHEAD
  849. -SKIP_32_DATA
  850. + "LDR____W16,8
  851. +B______8
  852. &WHILE_"
  853. :process_while_string7
  854. "
  855. -BR_X16
  856. +BR_____X16
  857. :END_WHILE_"
  858. @@ -2520,10 +2520,10 @@ BR_X16
  859. MISSING ;
  860. "
  861. :return_result_string1
  862. - "POP_X1 # _return_result_locals
  863. + "LDR____X1,[X18],8 # _return_result_locals
  864. "
  865. :return_result_string2
  866. - "RETURN
  867. + "RET
  868. "
  869. @@ -2588,11 +2588,11 @@ MISSING ;
  870. "Not inside of a loop or case statement
  871. "
  872. :process_break_string1
  873. - "POP_X1 # break_cleanup_locals
  874. + "LDR____X1,[X18],8 # break_cleanup_locals
  875. "
  876. :process_break_string2
  877. - "LOAD_W16_AHEAD
  878. -SKIP_32_DATA
  879. + "LDR____W16,8
  880. +B______8
  881. &"
  882. :process_break_string3
  883. "ERROR in break statement
  884. @@ -2600,7 +2600,7 @@ Missing ;
  885. "
  886. :process_break_string4
  887. "
  888. -BR_X16
  889. +BR_____X16
  890. "
  891. :break_frame
  892. @@ -2703,8 +2703,8 @@ MISSING ;
  893. :recursive_statement_cleanup
  894. LOAD32 R13 R13 0 ; GLOBAL_TOKEN = GLOBAL_TOKEN->NEXT
  895. LOAD32 R1 R12 8 ; OUT->S
  896. - LOADUI R0 $recursive_statement_string0 ; "RETURN\n"
  897. - CALLI R15 @match ; IF OUT->S == "RETURN\n"
  898. + LOADUI R0 $recursive_statement_string0 ; "RET\n"
  899. + CALLI R15 @match ; IF OUT->S == "RET\n"
  900. JUMP.NZ R0 @recursive_statement_done ; Save some work
  901. ;; Lets pop them all off
  902. @@ -2725,10 +2725,10 @@ MISSING ;
  903. RET R15
  904. :recursive_statement_string0
  905. - "RETURN
  906. + "RET
  907. "
  908. :recursive_statement_string1
  909. - "POP_X1 # _recursive_statement_locals
  910. + "LDR____X1,[X18],8 # _recursive_statement_locals
  911. "
  912. @@ -2899,8 +2899,8 @@ MISSING ;
  913. " #C goto label
  914. "
  915. :statement_string1
  916. - "LOAD_W16_AHEAD
  917. -SKIP_32_DATA
  918. + "LDR____W16,8
  919. +B______8
  920. &"
  921. :statement_string2
  922. "ERROR in statement
  923. @@ -2912,7 +2912,7 @@ MISSING ;
  924. "
  925. :statement_string4
  926. "
  927. -BR_X16
  928. +BR_____X16
  929. "
  930. ;; collect_local function
  931. @@ -3024,7 +3024,7 @@ BR_X16
  932. Missing ;
  933. "
  934. :collect_local_string2
  935. - "PUSH_X0 #"
  936. + "STR____X0,[X18,-8]! #"
  937. ;; collect_arguments function
  938. @@ -3165,7 +3165,7 @@ Missing ;
  939. :declare_function_string1
  940. ":FUNCTION_"
  941. :declare_function_string2
  942. - "RETURN
  943. + "RET
  944. "
  945. :current_count
  946. @@ -3484,62 +3484,62 @@ Missing ;
  947. No ( was found
  948. "
  949. :function_call_string1
  950. - "PUSH_X16 # Protect a tmp register we're going to use
  951. -PUSH_LR # Protect the old return pointer (link)
  952. + "STR____X16,[X18,-8]! # Protect a tmp register we're going to use
  953. +STR____X30,[X18,-8]! # Protect the old return pointer (link)
  954. "
  955. :function_call_string2
  956. - "PUSH_BP # Protect the old base pointer
  957. + "STR____X17,[X18,-8]! # Protect the old base pointer
  958. "
  959. :function_call_string3
  960. - "SET_X16_FROM_SP # The base pointer to-be
  961. + "MOV____X16,X18 # The base pointer to-be
  962. "
  963. :function_call_string4
  964. - "PUSH_X0 #_process_expression1
  965. + "STR____X0,[X18,-8]! #_process_expression1
  966. "
  967. :function_call_string5
  968. - "PUSH_X0 #_process_expression2
  969. + "STR____X0,[X18,-8]! #_process_expression2
  970. "
  971. :function_call_string6
  972. "ERROR in process_expression_list
  973. No ) was found
  974. "
  975. :function_call_string7
  976. - "SET_X0_FROM_BP
  977. -LOAD_W1_AHEAD
  978. -SKIP_32_DATA
  979. + "MOV____X0,X17
  980. +LDR____W1,8
  981. +B______8
  982. %"
  983. :function_call_string8
  984. "
  985. -SUB_X0_X0_X1
  986. -DEREF_X0
  987. +SUB____X0,X0,X1
  988. +LDR____X0,[X0]
  989. "
  990. :function_call_string9
  991. - "SET_BP_FROM_X16
  992. + "MOV____X17,X16
  993. "
  994. :function_call_string10
  995. - "SET_X16_FROM_X0
  996. -BLR_X16
  997. + "MOV____X16,X0
  998. +BLR____X16
  999. "
  1000. :function_call_string11
  1001. - "SET_BP_FROM_X16
  1002. + "MOV____X17,X16
  1003. "
  1004. :function_call_string12
  1005. - "LOAD_W16_AHEAD
  1006. -SKIP_32_DATA
  1007. + "LDR____W16,8
  1008. +B______8
  1009. &FUNCTION_"
  1010. :function_call_string13
  1011. - "POP_X1 # _process_expression_locals
  1012. + "LDR____X1,[X18],8 # _process_expression_locals
  1013. "
  1014. :function_call_string14
  1015. - "POP_BP # Restore the old base pointer
  1016. + "LDR____X17,[X18],8 # Restore the old base pointer
  1017. "
  1018. :function_call_string15
  1019. - "POP_LR # Restore the old return pointer (link)
  1020. -POP_X16 # Restore a register we used as tmp
  1021. + "LDR____X30,[X18],8 # Restore the old return pointer (link)
  1022. +LDR____X16,[X18],8 # Restore a register we used as tmp
  1023. "
  1024. :function_call_string16
  1025. "
  1026. -BLR_X16
  1027. +BLR____X16
  1028. "
  1029. ;; emit function
  1030. @@ -3791,7 +3791,7 @@ BLR_X16
  1031. STORE32 R5 R3 20 ; I->TYPE = MEMBER_TYPE
  1032. STORE32 R6 R3 8 ; I->OFFSET = OFFSET
  1033. MOVE R1 R6 ; Restore OFFSET
  1034. - MOVE R0 R3 ; RETURN I in R0
  1035. + MOVE R0 R3 ; RET I in R0
  1036. POPR R6 R15 ; Restore R6
  1037. POPR R5 R15 ; Restore R5
  1038. POPR R4 R15 ; Restore R4
  1039. --
  1040. 2.11.0