nmos6502add.pas 30 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684
  1. {
  2. Copyright (c) 2008 by Florian Klaempfl
  3. Code generation for add nodes on the MOS Technolog 6502
  4. This program is free software; you can redistribute it and/or modify
  5. it under the terms of the GNU General Public License as published by
  6. the Free Software Foundation; either version 2 of the License, or
  7. (at your option) any later version.
  8. This program is distributed in the hope that it will be useful,
  9. but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. GNU General Public License for more details.
  12. You should have received a copy of the GNU General Public License
  13. along with this program; if not, write to the Free Software
  14. Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  15. ****************************************************************************
  16. }
  17. unit nmos6502add;
  18. {$i fpcdefs.inc}
  19. interface
  20. uses
  21. node,ncgadd, symtype,cpubase;
  22. type
  23. { TMOS6502AddNode }
  24. TMOS6502AddNode = class(tcgaddnode)
  25. //private
  26. // function GetResFlags(unsigned:Boolean;anodetype:tnodetype):TResFlags;
  27. protected
  28. function use_mul_helper: boolean;override;
  29. function first_cmppointer: tnode;override;
  30. function pass_1 : tnode;override;
  31. procedure second_cmpordinal;override;
  32. procedure second_cmpsmallset;override;
  33. procedure second_cmp64bit;override;
  34. //procedure second_cmp16_32_64bit;
  35. procedure second_cmp;
  36. end;
  37. implementation
  38. uses
  39. globtype,systems,
  40. cutils,verbose,globals,
  41. symconst,symdef,paramgr,
  42. aasmbase,aasmtai,aasmdata,aasmcpu,defutil,htypechk,
  43. cgbase,cgutils,cgcpu,
  44. cpuinfo,pass_1,pass_2,procinfo,
  45. cpupara,
  46. ncon,nset,nadd,
  47. ncgutil,tgobj,rgobj,rgcpu,cgobj,cg64f32,
  48. hlcgobj;
  49. {*****************************************************************************
  50. TMOS6502AddNode
  51. *****************************************************************************}
  52. //function TMOS6502AddNode.GetResFlags(unsigned: Boolean; anodetype: tnodetype): TResFlags;
  53. // begin
  54. // case anodetype of
  55. // equaln:
  56. // GetResFlags:=F_E;
  57. // unequaln:
  58. // GetResFlags:=F_NE;
  59. // else
  60. // if not(unsigned) then
  61. // begin
  62. // { signed }
  63. // if nf_swapped in flags then
  64. // case anodetype of
  65. // ltn:
  66. // GetResFlags:=F_NotPossible;
  67. // lten:
  68. // GetResFlags:=F_P;
  69. // gtn:
  70. // GetResFlags:=F_M;
  71. // gten:
  72. // GetResFlags:=F_NotPossible;
  73. // else
  74. // internalerror(2014082020);
  75. // end
  76. // else
  77. // case anodetype of
  78. // ltn:
  79. // GetResFlags:=F_M;
  80. // lten:
  81. // GetResFlags:=F_NotPossible;
  82. // gtn:
  83. // GetResFlags:=F_NotPossible;
  84. // gten:
  85. // GetResFlags:=F_P;
  86. // else
  87. // internalerror(2014082021);
  88. // end;
  89. // end
  90. // else
  91. // begin
  92. // { unsigned }
  93. // if nf_swapped in Flags then
  94. // case anodetype of
  95. // ltn:
  96. // GetResFlags:=F_NotPossible;
  97. // lten:
  98. // GetResFlags:=F_NC;
  99. // gtn:
  100. // GetResFlags:=F_C;
  101. // gten:
  102. // GetResFlags:=F_NotPossible;
  103. // else
  104. // internalerror(2014082022);
  105. // end
  106. // else
  107. // case anodetype of
  108. // ltn:
  109. // GetResFlags:=F_C;
  110. // lten:
  111. // GetResFlags:=F_NotPossible;
  112. // gtn:
  113. // GetResFlags:=F_NotPossible;
  114. // gten:
  115. // GetResFlags:=F_NC;
  116. // else
  117. // internalerror(2014082023);
  118. // end;
  119. // end;
  120. // end;
  121. // end;
  122. function TMOS6502AddNode.use_mul_helper: boolean;
  123. begin
  124. result:=(nodetype=muln);
  125. end;
  126. function TMOS6502AddNode.first_cmppointer: tnode;
  127. begin
  128. result:=nil;
  129. expectloc:=LOC_JUMP;
  130. end;
  131. procedure TMOS6502AddNode.second_cmpsmallset;
  132. begin
  133. //case nodetype of
  134. // equaln,unequaln:
  135. // begin
  136. // if left.resultdef.size>=2 then
  137. // internalerror(2021100302);
  138. // second_cmp;
  139. // end;
  140. // lten,gten:
  141. // begin
  142. // if left.resultdef.size>=2 then
  143. // internalerror(2021100302);
  144. //
  145. // pass_left_right;
  146. //
  147. // if (not(nf_swapped in flags) and (nodetype = lten)) or
  148. // ((nf_swapped in flags) and (nodetype = gten)) then
  149. // swapleftright;
  150. //
  151. // if left.location.loc<>LOC_REGISTER then
  152. // hlcg.location_force_reg(current_asmdata.CurrAsmList,left.location,left.resultdef,left.resultdef,false);
  153. //
  154. // if right.location.loc in [LOC_REFERENCE,LOC_CREFERENCE] then
  155. // begin
  156. // if is_ref_in_opertypes(right.location.reference,[OT_REF_IX_d,OT_REF_IY_d,OT_REF_HL]) then
  157. // begin
  158. // cg.getcpuregister(current_asmdata.CurrAsmList,NR_A);
  159. // cg.a_load_loc_reg(current_asmdata.CurrAsmList,def_cgsize(left.resultdef),left.location,NR_A);
  160. // current_asmdata.CurrAsmList.Concat(taicpu.op_reg_ref(A_AND,NR_A,right.location.reference));
  161. // current_asmdata.CurrAsmList.Concat(taicpu.op_reg_ref(A_CP,NR_A,right.location.reference));
  162. // cg.ungetcpuregister(current_asmdata.CurrAsmList,NR_A);
  163. // end
  164. // else
  165. // hlcg.location_force_reg(current_asmdata.CurrAsmList,right.location,right.resultdef,right.resultdef,false);
  166. // end;
  167. // case right.location.loc of
  168. // LOC_CONSTANT:
  169. // begin
  170. // cg.getcpuregister(current_asmdata.CurrAsmList,NR_A);
  171. // cg.a_load_loc_reg(current_asmdata.CurrAsmList,def_cgsize(left.resultdef),left.location,NR_A);
  172. // current_asmdata.CurrAsmList.Concat(taicpu.op_reg_const(A_AND,NR_A,right.location.value));
  173. // current_asmdata.CurrAsmList.Concat(taicpu.op_reg_const(A_CP,NR_A,right.location.value));
  174. // cg.ungetcpuregister(current_asmdata.CurrAsmList,NR_A);
  175. // end;
  176. // LOC_REGISTER,LOC_CREGISTER:
  177. // begin
  178. // cg.getcpuregister(current_asmdata.CurrAsmList,NR_A);
  179. // cg.a_load_loc_reg(current_asmdata.CurrAsmList,def_cgsize(left.resultdef),left.location,NR_A);
  180. // current_asmdata.CurrAsmList.Concat(taicpu.op_reg_reg(A_AND,NR_A,right.location.register));
  181. // current_asmdata.CurrAsmList.Concat(taicpu.op_reg_reg(A_CP,NR_A,right.location.register));
  182. // cg.ungetcpuregister(current_asmdata.CurrAsmList,NR_A);
  183. // end;
  184. // LOC_REFERENCE,LOC_CREFERENCE:
  185. // begin
  186. // { Already handled before the case statement. Nothing to do here. }
  187. // end;
  188. // else
  189. // internalerror(2021100303);
  190. // end;
  191. //
  192. // location_reset(location,LOC_FLAGS,OS_NO);
  193. // location.resflags:=F_E;
  194. // end
  195. // else
  196. // internalerror(2021100301);
  197. //end;
  198. end;
  199. procedure TMOS6502AddNode.second_cmp;
  200. //var
  201. // unsigned : boolean;
  202. // tmpreg1,tmpreg2 : tregister;
  203. // i : longint;
  204. // opdef: tdef;
  205. // opsize: TCgSize;
  206. // l: TAsmLabel;
  207. begin
  208. //unsigned:=not(is_signed(left.resultdef)) or
  209. // not(is_signed(right.resultdef));
  210. //opdef:=left.resultdef;
  211. //opsize:=def_cgsize(opdef);
  212. //
  213. //pass_left_right;
  214. //
  215. //if (opsize=OS_8) or ((opsize=OS_S8) and (NodeType in [equaln,unequaln])) then
  216. // begin
  217. // if getresflags(unsigned,NodeType)=F_NotPossible then
  218. // swapleftright;
  219. //
  220. // if left.location.loc<>LOC_REGISTER then
  221. // hlcg.location_force_reg(current_asmdata.CurrAsmList,left.location,left.resultdef,left.resultdef,false);
  222. //
  223. // if right.location.loc in [LOC_REFERENCE,LOC_CREFERENCE] then
  224. // begin
  225. // if is_ref_in_opertypes(right.location.reference,[OT_REF_IX_d,OT_REF_IY_d,OT_REF_HL]) then
  226. // begin
  227. // cg.getcpuregister(current_asmdata.CurrAsmList,NR_A);
  228. // cg.a_load_loc_reg(current_asmdata.CurrAsmList,def_cgsize(left.resultdef),left.location,NR_A);
  229. // current_asmdata.CurrAsmList.Concat(taicpu.op_reg_ref(A_CP,NR_A,right.location.reference));
  230. // cg.ungetcpuregister(current_asmdata.CurrAsmList,NR_A);
  231. // end
  232. // else
  233. // hlcg.location_force_reg(current_asmdata.CurrAsmList,right.location,right.resultdef,right.resultdef,false);
  234. // end;
  235. // case right.location.loc of
  236. // LOC_CONSTANT:
  237. // begin
  238. // cg.getcpuregister(current_asmdata.CurrAsmList,NR_A);
  239. // cg.a_load_loc_reg(current_asmdata.CurrAsmList,def_cgsize(left.resultdef),left.location,NR_A);
  240. // current_asmdata.CurrAsmList.Concat(taicpu.op_reg_const(A_CP,NR_A,right.location.value));
  241. // cg.ungetcpuregister(current_asmdata.CurrAsmList,NR_A);
  242. // end;
  243. // LOC_REGISTER,LOC_CREGISTER:
  244. // begin
  245. // cg.getcpuregister(current_asmdata.CurrAsmList,NR_A);
  246. // cg.a_load_loc_reg(current_asmdata.CurrAsmList,def_cgsize(left.resultdef),left.location,NR_A);
  247. // current_asmdata.CurrAsmList.Concat(taicpu.op_reg_reg(A_CP,NR_A,right.location.register));
  248. // cg.ungetcpuregister(current_asmdata.CurrAsmList,NR_A);
  249. // end;
  250. // LOC_REFERENCE,LOC_CREFERENCE:
  251. // begin
  252. // { Already handled before the case statement. Nothing to do here. }
  253. // end;
  254. // else
  255. // internalerror(2020040402);
  256. // end;
  257. //
  258. // location_reset(location,LOC_FLAGS,OS_NO);
  259. // location.resflags:=getresflags(unsigned,NodeType);
  260. // end
  261. //else if opsize=OS_S8 then
  262. // begin
  263. // if getresflags(unsigned,NodeType)=F_NotPossible then
  264. // swapleftright;
  265. //
  266. // if left.location.loc<>LOC_REGISTER then
  267. // hlcg.location_force_reg(current_asmdata.CurrAsmList,left.location,left.resultdef,left.resultdef,false);
  268. //
  269. // if right.location.loc in [LOC_REFERENCE,LOC_CREFERENCE] then
  270. // begin
  271. // if is_ref_in_opertypes(right.location.reference,[OT_REF_IX_d,OT_REF_IY_d,OT_REF_HL]) then
  272. // begin
  273. // cg.getcpuregister(current_asmdata.CurrAsmList,NR_A);
  274. // cg.a_load_loc_reg(current_asmdata.CurrAsmList,def_cgsize(left.resultdef),left.location,NR_A);
  275. // current_asmdata.CurrAsmList.Concat(taicpu.op_reg_ref(A_SUB,NR_A,right.location.reference));
  276. // end
  277. // else
  278. // hlcg.location_force_reg(current_asmdata.CurrAsmList,right.location,right.resultdef,right.resultdef,false);
  279. // end;
  280. // case right.location.loc of
  281. // LOC_CONSTANT:
  282. // begin
  283. // cg.getcpuregister(current_asmdata.CurrAsmList,NR_A);
  284. // cg.a_load_loc_reg(current_asmdata.CurrAsmList,def_cgsize(left.resultdef),left.location,NR_A);
  285. // current_asmdata.CurrAsmList.Concat(taicpu.op_reg_const(A_SUB,NR_A,right.location.value));
  286. // end;
  287. // LOC_REGISTER,LOC_CREGISTER:
  288. // begin
  289. // cg.getcpuregister(current_asmdata.CurrAsmList,NR_A);
  290. // cg.a_load_loc_reg(current_asmdata.CurrAsmList,def_cgsize(left.resultdef),left.location,NR_A);
  291. // current_asmdata.CurrAsmList.Concat(taicpu.op_reg_reg(A_SUB,NR_A,right.location.register));
  292. // end;
  293. // LOC_REFERENCE,LOC_CREFERENCE:
  294. // begin
  295. // { Already handled before the case statement. Nothing to do here. }
  296. // end;
  297. // else
  298. // internalerror(2020040403);
  299. // end;
  300. // current_asmdata.getjumplabel(l);
  301. // cg.a_jmp_flags(current_asmdata.CurrAsmList,F_PO,l);
  302. // current_asmdata.CurrAsmList.Concat(taicpu.op_reg_const(A_XOR,NR_A,$80));
  303. // cg.a_label(current_asmdata.CurrAsmList,l);
  304. // cg.ungetcpuregister(current_asmdata.CurrAsmList,NR_A);
  305. //
  306. // location_reset(location,LOC_FLAGS,OS_NO);
  307. // location.resflags:=getresflags(unsigned,NodeType);
  308. // end
  309. //else
  310. // internalerror(2020040401);
  311. end;
  312. procedure TMOS6502AddNode.second_cmp64bit;
  313. begin
  314. //second_cmp16_32_64bit;
  315. end;
  316. //procedure TMOS6502AddNode.second_cmp16_32_64bit;
  317. // var
  318. // truelabel,
  319. // falselabel: tasmlabel;
  320. // unsigned : boolean;
  321. // i, size: Integer;
  322. // tmpref: treference;
  323. // op: TAsmOp;
  324. // actualnodetype: tnodetype;
  325. // begin
  326. // truelabel:=nil;
  327. // falselabel:=nil;
  328. // pass_left_right;
  329. //
  330. // unsigned:=not(is_signed(left.resultdef)) or
  331. // not(is_signed(right.resultdef));
  332. //
  333. // { we have LOC_JUMP as result }
  334. // current_asmdata.getjumplabel(truelabel);
  335. // current_asmdata.getjumplabel(falselabel);
  336. // location_reset_jump(location,truelabel,falselabel);
  337. //
  338. // size:=tcgsize2size[def_cgsize(left.resultdef)];
  339. //
  340. // if NodeType in [equaln,unequaln] then
  341. // begin
  342. // if left.location.loc<>LOC_REGISTER then
  343. // hlcg.location_force_reg(current_asmdata.CurrAsmList,left.location,left.resultdef,left.resultdef,false);
  344. //
  345. // if right.location.loc in [LOC_REFERENCE,LOC_CREFERENCE] then
  346. // begin
  347. // if is_ref_in_opertypes(right.location.reference,[OT_REF_IX_d,OT_REF_IY_d,OT_REF_HL]) then
  348. // begin
  349. // cg.getcpuregister(current_asmdata.CurrAsmList,NR_A);
  350. // tmpref:=right.location.reference;
  351. // for i:=0 to size-1 do
  352. // begin
  353. // cg.a_load_reg_reg(current_asmdata.CurrAsmList,OS_8,OS_8,tcgz80(cg).GetOffsetReg64(left.location.register,left.location.registerhi,i),NR_A);
  354. // current_asmdata.CurrAsmList.Concat(taicpu.op_reg_ref(A_CP,NR_A,tmpref));
  355. // case NodeType of
  356. // equaln:
  357. // if i<>(size-1) then
  358. // cg.a_jmp_flags(current_asmdata.CurrAsmList,F_NE,falselabel)
  359. // else
  360. // cg.a_jmp_flags(current_asmdata.CurrAsmList,F_E,truelabel);
  361. // unequaln:
  362. // cg.a_jmp_flags(current_asmdata.CurrAsmList,F_NE,truelabel);
  363. // else
  364. // internalerror(2020042102);
  365. // end;
  366. // if i<>(size-1) then
  367. // tcgz80(cg).adjust_normalized_ref(current_asmdata.CurrAsmList,tmpref,1);
  368. // end;
  369. // cg.ungetcpuregister(current_asmdata.CurrAsmList,NR_A);
  370. // cg.a_jmp_always(current_asmdata.CurrAsmList,falselabel);
  371. // end
  372. // else
  373. // hlcg.location_force_reg(current_asmdata.CurrAsmList,right.location,right.resultdef,right.resultdef,false);
  374. // end;
  375. // case right.location.loc of
  376. // LOC_CONSTANT:
  377. // begin
  378. // cg.getcpuregister(current_asmdata.CurrAsmList,NR_A);
  379. // for i:=0 to size-1 do
  380. // begin
  381. // cg.a_load_reg_reg(current_asmdata.CurrAsmList,OS_8,OS_8,tcgz80(cg).GetOffsetReg64(left.location.register,left.location.registerhi,i),NR_A);
  382. // current_asmdata.CurrAsmList.Concat(taicpu.op_reg_const(A_CP,NR_A,byte(right.location.value shr (i*8))));
  383. // case NodeType of
  384. // equaln:
  385. // if i<>(size-1) then
  386. // cg.a_jmp_flags(current_asmdata.CurrAsmList,F_NE,falselabel)
  387. // else
  388. // cg.a_jmp_flags(current_asmdata.CurrAsmList,F_E,truelabel);
  389. // unequaln:
  390. // cg.a_jmp_flags(current_asmdata.CurrAsmList,F_NE,truelabel);
  391. // else
  392. // internalerror(2020042104);
  393. // end;
  394. // end;
  395. // cg.ungetcpuregister(current_asmdata.CurrAsmList,NR_A);
  396. // cg.a_jmp_always(current_asmdata.CurrAsmList,falselabel);
  397. // end;
  398. // LOC_REGISTER,LOC_CREGISTER:
  399. // begin
  400. // cg.getcpuregister(current_asmdata.CurrAsmList,NR_A);
  401. // for i:=0 to size-1 do
  402. // begin
  403. // cg.a_load_reg_reg(current_asmdata.CurrAsmList,OS_8,OS_8,tcgz80(cg).GetOffsetReg64(left.location.register,left.location.registerhi,i),NR_A);
  404. // current_asmdata.CurrAsmList.Concat(taicpu.op_reg_reg(A_CP,NR_A,tcgz80(cg).GetOffsetReg64(right.location.register,right.location.registerhi,i)));
  405. // case NodeType of
  406. // equaln:
  407. // if i<>(size-1) then
  408. // cg.a_jmp_flags(current_asmdata.CurrAsmList,F_NE,falselabel)
  409. // else
  410. // cg.a_jmp_flags(current_asmdata.CurrAsmList,F_E,truelabel);
  411. // unequaln:
  412. // cg.a_jmp_flags(current_asmdata.CurrAsmList,F_NE,truelabel);
  413. // else
  414. // internalerror(2020042105);
  415. // end;
  416. // end;
  417. // cg.ungetcpuregister(current_asmdata.CurrAsmList,NR_A);
  418. // cg.a_jmp_always(current_asmdata.CurrAsmList,falselabel);
  419. // end;
  420. // LOC_REFERENCE,LOC_CREFERENCE:
  421. // begin
  422. // { Already handled before the case statement. Nothing to do here. }
  423. // end;
  424. // else
  425. // internalerror(2020042103);
  426. // end;
  427. // end
  428. // else
  429. // begin
  430. // if nf_swapped in Flags then
  431. // begin
  432. // case NodeType of
  433. // ltn:
  434. // actualnodetype:=gtn;
  435. // lten:
  436. // actualnodetype:=gten;
  437. // gtn:
  438. // actualnodetype:=ltn;
  439. // gten:
  440. // actualnodetype:=lten;
  441. // else
  442. // internalerror(2020042701);
  443. // end;
  444. // end
  445. // else
  446. // actualnodetype:=NodeType;
  447. //
  448. // if left.location.loc<>LOC_REGISTER then
  449. // hlcg.location_force_reg(current_asmdata.CurrAsmList,left.location,left.resultdef,left.resultdef,false);
  450. //
  451. // if right.location.loc in [LOC_REFERENCE,LOC_CREFERENCE] then
  452. // begin
  453. // if is_ref_in_opertypes(right.location.reference,[OT_REF_IX_d,OT_REF_IY_d,OT_REF_HL]) then
  454. // begin
  455. // cg.getcpuregister(current_asmdata.CurrAsmList,NR_A);
  456. // tmpref:=right.location.reference;
  457. // tcgz80(cg).adjust_normalized_ref(current_asmdata.CurrAsmList,tmpref,size-1);
  458. // for i:=size-1 downto 0 do
  459. // begin
  460. // cg.a_load_reg_reg(current_asmdata.CurrAsmList,OS_8,OS_8,tcgz80(cg).GetOffsetReg64(left.location.register,left.location.registerhi,i),NR_A);
  461. // if (i=(size-1)) and (not unsigned) then
  462. // op:=A_SUB
  463. // else
  464. // op:=A_CP;
  465. // current_asmdata.CurrAsmList.Concat(taicpu.op_reg_ref(op,NR_A,tmpref));
  466. // if (i=(size-1)) and (not unsigned) then
  467. // case actualnodetype of
  468. // ltn,
  469. // lten:
  470. // tcgz80(cg).a_jmp_signed_cmp_3way(current_asmdata.CurrAsmList,truelabel,nil,falselabel);
  471. // gtn,
  472. // gten:
  473. // tcgz80(cg).a_jmp_signed_cmp_3way(current_asmdata.CurrAsmList,falselabel,nil,truelabel);
  474. // else
  475. // internalerror(2020042202);
  476. // end
  477. // else if i<>0 then
  478. // case actualnodetype of
  479. // ltn,
  480. // lten:
  481. // tcgz80(cg).a_jmp_unsigned_cmp_3way(current_asmdata.CurrAsmList,truelabel,nil,falselabel);
  482. // gtn,
  483. // gten:
  484. // tcgz80(cg).a_jmp_unsigned_cmp_3way(current_asmdata.CurrAsmList,falselabel,nil,truelabel);
  485. // else
  486. // internalerror(2020042207);
  487. // end
  488. // else
  489. // case actualnodetype of
  490. // ltn:
  491. // tcgz80(cg).a_jmp_unsigned_cmp_3way(current_asmdata.CurrAsmList,truelabel,falselabel,falselabel);
  492. // lten:
  493. // tcgz80(cg).a_jmp_unsigned_cmp_3way(current_asmdata.CurrAsmList,truelabel,truelabel,falselabel);
  494. // gtn:
  495. // tcgz80(cg).a_jmp_unsigned_cmp_3way(current_asmdata.CurrAsmList,falselabel,falselabel,truelabel);
  496. // gten:
  497. // tcgz80(cg).a_jmp_unsigned_cmp_3way(current_asmdata.CurrAsmList,falselabel,truelabel,truelabel);
  498. // else
  499. // internalerror(2020042203);
  500. // end;
  501. // if i<>0 then
  502. // tcgz80(cg).adjust_normalized_ref(current_asmdata.CurrAsmList,tmpref,-1);
  503. // end;
  504. // cg.ungetcpuregister(current_asmdata.CurrAsmList,NR_A);
  505. // end
  506. // else
  507. // hlcg.location_force_reg(current_asmdata.CurrAsmList,right.location,right.resultdef,right.resultdef,false);
  508. // end;
  509. // case right.location.loc of
  510. // LOC_CONSTANT:
  511. // begin
  512. // cg.getcpuregister(current_asmdata.CurrAsmList,NR_A);
  513. // for i:=size-1 downto 0 do
  514. // begin
  515. // cg.a_load_reg_reg(current_asmdata.CurrAsmList,OS_8,OS_8,tcgz80(cg).GetOffsetReg64(left.location.register,left.location.registerhi,i),NR_A);
  516. // if (i=(size-1)) and (not unsigned) then
  517. // op:=A_SUB
  518. // else
  519. // op:=A_CP;
  520. // current_asmdata.CurrAsmList.Concat(taicpu.op_reg_const(op,NR_A,byte(right.location.value shr (i*8))));
  521. // if (i=(size-1)) and (not unsigned) then
  522. // case actualnodetype of
  523. // ltn,
  524. // lten:
  525. // tcgz80(cg).a_jmp_signed_cmp_3way(current_asmdata.CurrAsmList,truelabel,nil,falselabel);
  526. // gtn,
  527. // gten:
  528. // tcgz80(cg).a_jmp_signed_cmp_3way(current_asmdata.CurrAsmList,falselabel,nil,truelabel);
  529. // else
  530. // internalerror(2020042210);
  531. // end
  532. // else if i<>0 then
  533. // case actualnodetype of
  534. // ltn,
  535. // lten:
  536. // tcgz80(cg).a_jmp_unsigned_cmp_3way(current_asmdata.CurrAsmList,truelabel,nil,falselabel);
  537. // gtn,
  538. // gten:
  539. // tcgz80(cg).a_jmp_unsigned_cmp_3way(current_asmdata.CurrAsmList,falselabel,nil,truelabel);
  540. // else
  541. // internalerror(2020042211);
  542. // end
  543. // else
  544. // case actualnodetype of
  545. // ltn:
  546. // tcgz80(cg).a_jmp_unsigned_cmp_3way(current_asmdata.CurrAsmList,truelabel,falselabel,falselabel);
  547. // lten:
  548. // tcgz80(cg).a_jmp_unsigned_cmp_3way(current_asmdata.CurrAsmList,truelabel,truelabel,falselabel);
  549. // gtn:
  550. // tcgz80(cg).a_jmp_unsigned_cmp_3way(current_asmdata.CurrAsmList,falselabel,falselabel,truelabel);
  551. // gten:
  552. // tcgz80(cg).a_jmp_unsigned_cmp_3way(current_asmdata.CurrAsmList,falselabel,truelabel,truelabel);
  553. // else
  554. // internalerror(2020042215);
  555. // end;
  556. // end;
  557. // cg.ungetcpuregister(current_asmdata.CurrAsmList,NR_A);
  558. // end;
  559. // LOC_REGISTER,LOC_CREGISTER:
  560. // begin
  561. // cg.getcpuregister(current_asmdata.CurrAsmList,NR_A);
  562. // for i:=size-1 downto 0 do
  563. // begin
  564. // cg.a_load_reg_reg(current_asmdata.CurrAsmList,OS_8,OS_8,tcgz80(cg).GetOffsetReg64(left.location.register,left.location.registerhi,i),NR_A);
  565. // if (i=(size-1)) and (not unsigned) then
  566. // op:=A_SUB
  567. // else
  568. // op:=A_CP;
  569. // current_asmdata.CurrAsmList.Concat(taicpu.op_reg_reg(op,NR_A,tcgz80(cg).GetOffsetReg64(right.location.register,right.location.registerhi,i)));
  570. // if (i=(size-1)) and (not unsigned) then
  571. // case actualnodetype of
  572. // ltn,
  573. // lten:
  574. // tcgz80(cg).a_jmp_signed_cmp_3way(current_asmdata.CurrAsmList,truelabel,nil,falselabel);
  575. // gtn,
  576. // gten:
  577. // tcgz80(cg).a_jmp_signed_cmp_3way(current_asmdata.CurrAsmList,falselabel,nil,truelabel);
  578. // else
  579. // internalerror(2020042212);
  580. // end
  581. // else if i<>0 then
  582. // case actualnodetype of
  583. // ltn,
  584. // lten:
  585. // tcgz80(cg).a_jmp_unsigned_cmp_3way(current_asmdata.CurrAsmList,truelabel,nil,falselabel);
  586. // gtn,
  587. // gten:
  588. // tcgz80(cg).a_jmp_unsigned_cmp_3way(current_asmdata.CurrAsmList,falselabel,nil,truelabel);
  589. // else
  590. // internalerror(2020042213);
  591. // end
  592. // else
  593. // case actualnodetype of
  594. // ltn:
  595. // tcgz80(cg).a_jmp_unsigned_cmp_3way(current_asmdata.CurrAsmList,truelabel,falselabel,falselabel);
  596. // lten:
  597. // tcgz80(cg).a_jmp_unsigned_cmp_3way(current_asmdata.CurrAsmList,truelabel,truelabel,falselabel);
  598. // gtn:
  599. // tcgz80(cg).a_jmp_unsigned_cmp_3way(current_asmdata.CurrAsmList,falselabel,falselabel,truelabel);
  600. // gten:
  601. // tcgz80(cg).a_jmp_unsigned_cmp_3way(current_asmdata.CurrAsmList,falselabel,truelabel,truelabel);
  602. // else
  603. // internalerror(2020042216);
  604. // end;
  605. // end;
  606. // cg.ungetcpuregister(current_asmdata.CurrAsmList,NR_A);
  607. // end;
  608. // LOC_REFERENCE,LOC_CREFERENCE:
  609. // begin
  610. // { Already handled before the case statement. Nothing to do here. }
  611. // end;
  612. // else
  613. // internalerror(2020042106);
  614. // end;
  615. // end;
  616. // end;
  617. function TMOS6502AddNode.pass_1 : tnode;
  618. begin
  619. result:=inherited pass_1;
  620. {$ifdef dummy}
  621. if not(assigned(result)) then
  622. begin
  623. unsigned:=not(is_signed(left.resultdef)) or
  624. not(is_signed(right.resultdef));
  625. if is_64bit(left.resultdef) and
  626. ((nodetype in [equaln,unequaln]) or
  627. (unsigned and (nodetype in [ltn,lten,gtn,gten]))
  628. ) then
  629. expectloc:=LOC_FLAGS;
  630. end;
  631. { handling boolean expressions }
  632. if not(assigned(result)) and
  633. (
  634. not(is_boolean(left.resultdef)) or
  635. not(is_boolean(right.resultdef)) or
  636. is_dynamic_array(left.resultdef)
  637. ) then
  638. expectloc:=LOC_FLAGS;
  639. {$endif dummy}
  640. end;
  641. procedure TMOS6502AddNode.second_cmpordinal;
  642. begin
  643. //if left.resultdef.size>=2 then
  644. // second_cmp16_32_64bit
  645. //else
  646. // second_cmp;
  647. end;
  648. begin
  649. caddnode:=TMOS6502AddNode;
  650. end.