cg68k2.pas 91 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987
  1. {
  2. $Id$
  3. Copyright (c) 1993-98 by Florian Klaempfl, Carl Eric Codere
  4. This unit generates 68000 (or better) assembler from the parse tree
  5. This program is free software; you can redistribute it and/or modify
  6. it under the terms of the GNU General Public License as published by
  7. the Free Software Foundation; either version 2 of the License, or
  8. (at your option) any later version.
  9. This program is distributed in the hope that it will be useful,
  10. but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. GNU General Public License for more details.
  13. You should have received a copy of the GNU General Public License
  14. along with this program; if not, write to the Free Software
  15. Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  16. ****************************************************************************
  17. }
  18. {$ifdef tp}
  19. {$E+,F+,N+,D+,L+,Y+}
  20. {$endif}
  21. Unit Cg68k2;
  22. Interface
  23. uses
  24. objects,verbose,cobjects,systems,globals,tree,
  25. symtable,types,strings,pass_1,hcodegen,temp_gen,
  26. aasm,m68k,tgen68k,files,cga68k;
  27. const
  28. { process condition codes bit definitions }
  29. CARRY_FLAG = $01;
  30. OVFL_FLAG = $02;
  31. ZERO_FLAG = $04;
  32. NEG_FLAG = $08;
  33. { to set OR with flags }
  34. { to clear AND (NOT flag) }
  35. procedure secondadd(var p : ptree);
  36. procedure processcc(p: ptree);
  37. procedure secondfor(var p : ptree);
  38. procedure secondas(var p : ptree);
  39. procedure secondraise(var p : ptree);
  40. procedure secondin(var p : ptree);
  41. procedure secondexpr(var p : ptree);
  42. procedure secondblockn(var p : ptree);
  43. procedure second_while_repeatn(var p : ptree);
  44. procedure secondifn(var p : ptree);
  45. procedure secondbreakn(var p : ptree);
  46. { copies p a set element into the d0.b register }
  47. procedure loadsetelement(var p : ptree);
  48. Implementation
  49. uses cg68k;
  50. procedure secondadd(var p : ptree);
  51. { is also being used for xor, and "mul", "sub, or and comparative }
  52. { operators }
  53. label do_normal;
  54. var
  55. swapp : ptree;
  56. hregister : tregister;
  57. pushed,mboverflow,cmpop : boolean;
  58. op : tasmop;
  59. pushedregs : tpushed;
  60. flags : tresflags;
  61. otl,ofl : plabel;
  62. power : longint;
  63. href : treference;
  64. opsize : topsize;
  65. swapl : tlocation;
  66. tmpref: treference;
  67. { true, if unsigned types are compared }
  68. unsigned : boolean;
  69. { is_in_dest if the result is put directly into }
  70. { the resulting refernce or varregister }
  71. { true, if a small set is handled with the longint code }
  72. is_set : boolean;
  73. is_in_dest : boolean;
  74. { true, if for sets subtractions the extra not should generated }
  75. extra_not : boolean;
  76. begin
  77. unsigned:=false;
  78. is_in_dest := false;
  79. extra_not:=false;
  80. opsize:=S_L;
  81. { calculate the operator which is more difficult }
  82. firstcomplex(p);
  83. { handling boolean expressions extra: }
  84. if ((p^.left^.resulttype^.deftype=orddef) and
  85. (porddef(p^.left^.resulttype)^.typ=bool8bit)) then
  86. { ((p^.right^.resulttype^.deftype=orddef) and
  87. (porddef(p^.right^.resulttype)^.typ=bool8bit)) then }
  88. begin
  89. if (p^.treetype=andn) or (p^.treetype=orn) then
  90. begin
  91. p^.location.loc:=LOC_JUMP;
  92. cmpop:=false;
  93. case p^.treetype of
  94. andn : begin
  95. otl:=truelabel;
  96. getlabel(truelabel);
  97. secondpass(p^.left);
  98. maketojumpbool(p^.left);
  99. emitl(A_LABEL,truelabel);
  100. truelabel:=otl;
  101. end;
  102. orn : begin
  103. ofl:=falselabel;
  104. getlabel(falselabel);
  105. secondpass(p^.left);
  106. maketojumpbool(p^.left);
  107. emitl(A_LABEL,falselabel);
  108. falselabel:=ofl;
  109. end;
  110. else Message(sym_e_type_mismatch);
  111. end; { end case }
  112. secondpass(p^.right);
  113. maketojumpbool(p^.right);
  114. end { endif }
  115. else if p^.treetype in [unequaln,equaln,xorn] then
  116. begin
  117. opsize:=S_B;
  118. if p^.left^.treetype=ordconstn then
  119. begin
  120. swapp:=p^.right;
  121. p^.right:=p^.left;
  122. p^.left:=swapp;
  123. p^.swaped:=not(p^.swaped);
  124. end;
  125. secondpass(p^.left);
  126. p^.location:=p^.left^.location;
  127. (* register needed *)
  128. pushed:=maybe_push(p^.right^.registers32,p);
  129. secondpass(p^.right);
  130. if pushed then restore(p);
  131. goto do_normal;
  132. end { endif }
  133. else Message(sym_e_type_mismatch);
  134. end { endif }
  135. { also handle string operations seperately }
  136. else if (p^.left^.resulttype^.deftype=stringdef) then
  137. begin
  138. { string operations are not commutative }
  139. if p^.swaped then
  140. begin
  141. swapp:=p^.left;
  142. p^.left:=p^.right;
  143. p^.right:=swapp;
  144. { because of jump being produced at comparison below: }
  145. p^.swaped:=not(p^.swaped);
  146. end;
  147. case p^.treetype of
  148. addn : begin
  149. cmpop:=false;
  150. secondpass(p^.left);
  151. if (p^.left^.treetype<>addn) then
  152. begin
  153. { can only reference be }
  154. { string in register would be funny }
  155. { therefore produce a temporary string }
  156. { release the registers }
  157. del_reference(p^.left^.location.reference);
  158. gettempofsizereference(256,href);
  159. copystring(href,p^.left^.location.reference,255);
  160. ungetiftemp(p^.left^.location.reference);
  161. { does not hurt: }
  162. p^.left^.location.loc:=LOC_MEM;
  163. p^.left^.location.reference:=href;
  164. end;
  165. secondpass(p^.right);
  166. { on the right we do not need the register anymore too }
  167. del_reference(p^.right^.location.reference);
  168. pushusedregisters(pushedregs,$ffff);
  169. { WE INVERSE THE PARAMETERS!!! }
  170. { Because parameters are inversed in the rtl }
  171. emitpushreferenceaddr(p^.right^.location.reference);
  172. emitpushreferenceaddr(p^.left^.location.reference);
  173. emitcall('STRCONCAT',true);
  174. maybe_loadA5;
  175. popusedregisters(pushedregs);
  176. set_location(p^.location,p^.left^.location);
  177. ungetiftemp(p^.right^.location.reference);
  178. end; { this case }
  179. ltn,lten,gtn,gten,
  180. equaln,unequaln :
  181. begin
  182. secondpass(p^.left);
  183. { are too few registers free? }
  184. pushed:=maybe_push(p^.right^.registers32,p);
  185. secondpass(p^.right);
  186. if pushed then restore(p);
  187. cmpop:=true;
  188. del_reference(p^.right^.location.reference);
  189. del_reference(p^.left^.location.reference);
  190. { generates better code }
  191. { s='' and s<>'' }
  192. if (p^.treetype in [equaln,unequaln]) and
  193. (
  194. ((p^.left^.treetype=stringconstn) and
  195. (p^.left^.values^='')) or
  196. ((p^.right^.treetype=stringconstn) and
  197. (p^.right^.values^=''))
  198. ) then
  199. begin
  200. { only one node can be stringconstn }
  201. { else pass 1 would have evaluted }
  202. { this node }
  203. if p^.left^.treetype=stringconstn then
  204. exprasmlist^.concat(new(pai68k,op_ref(
  205. A_TST,S_B,newreference(p^.right^.location.reference))))
  206. else
  207. exprasmlist^.concat(new(pai68k,op_ref(
  208. A_TST,S_B,newreference(p^.left^.location.reference))));
  209. end
  210. else
  211. begin
  212. pushusedregisters(pushedregs,$ffff);
  213. { parameters are directly passed via registers }
  214. { this has several advantages, no loss of the flags }
  215. { on exit ,and MUCH faster on m68k machines }
  216. { speed difference (68000) }
  217. { normal routine: entry, exit code + push = 124 }
  218. { (best case) }
  219. { assembler routine: param setup (worst case) = 48 }
  220. exprasmlist^.concat(new(pai68k,op_ref_reg(
  221. A_LEA,S_L,newreference(p^.left^.location.reference),R_A0)));
  222. exprasmlist^.concat(new(pai68k,op_ref_reg(
  223. A_LEA,S_L,newreference(p^.right^.location.reference),R_A1)));
  224. {
  225. emitpushreferenceaddr(p^.left^.location.reference);
  226. emitpushreferenceaddr(p^.right^.location.reference); }
  227. emitcall('STRCMP',true);
  228. maybe_loada5;
  229. popusedregisters(pushedregs);
  230. end;
  231. ungetiftemp(p^.left^.location.reference);
  232. ungetiftemp(p^.right^.location.reference);
  233. end; { end this case }
  234. else Message(sym_e_type_mismatch);
  235. end; { end case }
  236. end { end else if }
  237. else
  238. begin
  239. { in case of constant put it to the left }
  240. if p^.left^.treetype=ordconstn then
  241. begin
  242. swapp:=p^.right;
  243. p^.right:=p^.left;
  244. p^.left:=swapp;
  245. p^.swaped:=not(p^.swaped);
  246. end;
  247. secondpass(p^.left);
  248. set_location(p^.location,p^.left^.location);
  249. { are to few registers free? }
  250. pushed:=maybe_push(p^.right^.registers32,p);
  251. secondpass(p^.right);
  252. if pushed then restore(p);
  253. if (p^.left^.resulttype^.deftype=pointerdef) or
  254. (p^.right^.resulttype^.deftype=pointerdef) or
  255. ((p^.right^.resulttype^.deftype=objectdef) and
  256. pobjectdef(p^.right^.resulttype)^.isclass and
  257. (p^.left^.resulttype^.deftype=objectdef) and
  258. pobjectdef(p^.left^.resulttype)^.isclass
  259. ) or
  260. (p^.left^.resulttype^.deftype=classrefdef) or
  261. (p^.left^.resulttype^.deftype=procvardef) or
  262. (p^.left^.resulttype^.deftype=enumdef) or
  263. ((p^.left^.resulttype^.deftype=orddef) and
  264. (porddef(p^.left^.resulttype)^.typ=s32bit)) or
  265. ((p^.right^.resulttype^.deftype=orddef) and
  266. (porddef(p^.right^.resulttype)^.typ=s32bit)) or
  267. ((p^.left^.resulttype^.deftype=orddef) and
  268. (porddef(p^.left^.resulttype)^.typ=u32bit)) or
  269. ((p^.right^.resulttype^.deftype=orddef) and
  270. (porddef(p^.right^.resulttype)^.typ=u32bit))
  271. { SMALL SETS DO NOT WORK BECAUSE OF ENDIAN! }
  272. or { as well as small sets }
  273. ((p^.left^.resulttype^.deftype=setdef) and
  274. (psetdef(p^.left^.resulttype)^.settype=smallset))
  275. then
  276. begin
  277. do_normal:
  278. mboverflow:=false;
  279. cmpop:=false;
  280. if (p^.left^.resulttype^.deftype=pointerdef) or
  281. (p^.right^.resulttype^.deftype=pointerdef) or
  282. ((p^.left^.resulttype^.deftype=orddef) and
  283. (porddef(p^.left^.resulttype)^.typ=u32bit)) or
  284. ((p^.right^.resulttype^.deftype=orddef) and
  285. (porddef(p^.right^.resulttype)^.typ=u32bit)) then
  286. unsigned:=true;
  287. is_set:=p^.resulttype^.deftype=setdef;
  288. case p^.treetype of
  289. addn : begin
  290. if is_set then
  291. begin
  292. op:=A_OR;
  293. mboverflow:=false;
  294. unsigned:=false;
  295. end
  296. else
  297. begin
  298. op:=A_ADD;
  299. mboverflow:=true;
  300. end;
  301. end; { end this case }
  302. symdifn : begin
  303. { the symetric diff is only for sets }
  304. if is_set then
  305. begin
  306. op:=A_EOR;
  307. mboverflow:=false;
  308. unsigned:=false;
  309. end
  310. else
  311. begin
  312. Message(sym_e_type_mismatch);
  313. end;
  314. end;
  315. muln : begin
  316. if is_set then
  317. begin
  318. op:=A_AND;
  319. mboverflow:=false;
  320. unsigned:=false;
  321. end
  322. else
  323. begin
  324. if unsigned then
  325. op:=A_MULU
  326. else
  327. op:=A_MULS;
  328. mboverflow:=true;
  329. end;
  330. end; { end this case }
  331. subn : begin
  332. if is_set then
  333. begin
  334. op:=A_AND;
  335. mboverflow:=false;
  336. unsigned:=false;
  337. extra_not:=true;
  338. end
  339. else
  340. begin
  341. op:=A_SUB;
  342. mboverflow:=true;
  343. end;
  344. end; {end this case }
  345. ltn,lten,gtn,gten,
  346. equaln,unequaln :
  347. begin
  348. op:=A_CMP;
  349. cmpop:=true;
  350. end;
  351. xorn : op:=A_EOR;
  352. orn : op:=A_OR;
  353. andn : op:=A_AND;
  354. else Message(sym_e_type_mismatch);
  355. end; {end case }
  356. { left and right no register? }
  357. { then one must be demanded }
  358. if (p^.left^.location.loc<>LOC_REGISTER) and
  359. (p^.right^.location.loc<>LOC_REGISTER) then
  360. begin
  361. { register variable ? }
  362. if (p^.left^.location.loc=LOC_CREGISTER) then
  363. begin
  364. { it is OK if this is the destination }
  365. if is_in_dest then
  366. begin
  367. hregister:=p^.location.register;
  368. emit_reg_reg(A_MOVE,opsize,p^.left^.location.register,
  369. hregister);
  370. end
  371. else
  372. if cmpop then
  373. begin
  374. { do not disturb the register }
  375. hregister:=p^.location.register;
  376. end
  377. else
  378. begin
  379. hregister := getregister32;
  380. emit_reg_reg(A_MOVE,opsize,p^.left^.location.register,
  381. hregister);
  382. end
  383. end
  384. else
  385. begin
  386. del_reference(p^.left^.location.reference);
  387. if is_in_dest then
  388. begin
  389. hregister:=p^.location.register;
  390. exprasmlist^.concat(new(pai68k,op_ref_reg(A_MOVE,opsize,
  391. newreference(p^.left^.location.reference),hregister)));
  392. end
  393. else
  394. begin
  395. { first give free, then demand new register }
  396. hregister := getregister32;
  397. exprasmlist^.concat(new(pai68k,op_ref_reg(A_MOVE,opsize,
  398. newreference(p^.left^.location.reference),
  399. hregister)));
  400. end;{ endif p^... }
  401. end;
  402. p^.location.loc:=LOC_REGISTER;
  403. p^.location.register:=hregister;
  404. end
  405. else
  406. { if on the right the register then swap }
  407. if (p^.right^.location.loc=LOC_REGISTER) then
  408. begin
  409. swap_location(p^.location,p^.right^.location);
  410. { newly swapped also set swapped flag }
  411. p^.swaped:=not(p^.swaped);
  412. end;
  413. { endif p^...<> LOC_REGISTER }
  414. { at this point, p^.location.loc should be LOC_REGISTER }
  415. { and p^.location.register should be a valid register }
  416. { containing the left result }
  417. if p^.right^.location.loc<>LOC_REGISTER then
  418. begin
  419. if (p^.treetype=subn) and p^.swaped then
  420. begin
  421. if p^.right^.location.loc=LOC_CREGISTER then
  422. begin
  423. if extra_not then
  424. exprasmlist^.concat(new(pai68k,op_reg(A_NOT,opsize,p^.location.register)));
  425. emit_reg_reg(A_MOVE,opsize,p^.right^.location.register,R_D6);
  426. emit_reg_reg(op,opsize,p^.location.register,R_D6);
  427. emit_reg_reg(A_MOVE,opsize,R_D6,p^.location.register);
  428. end
  429. else
  430. begin
  431. if extra_not then
  432. exprasmlist^.concat(new(pai68k,op_reg(A_NOT,opsize,p^.location.register)));
  433. exprasmlist^.concat(new(pai68k,op_ref_reg(A_MOVE,opsize,
  434. newreference(p^.right^.location.reference),R_D6)));
  435. exprasmlist^.concat(new(pai68k,op_reg_reg(op,opsize,p^.location.register,R_D6)));
  436. exprasmlist^.concat(new(pai68k,op_reg_reg(A_MOVE,opsize,R_D6,p^.location.register)));
  437. del_reference(p^.right^.location.reference);
  438. end;
  439. end
  440. { end subn ... }
  441. else
  442. begin
  443. if (p^.right^.treetype=ordconstn) and (op=A_CMP) and
  444. (p^.right^.value=0) then
  445. begin
  446. exprasmlist^.concat(new(pai68k,op_reg(A_TST,opsize,p^.location.register)));
  447. end
  448. else if (p^.right^.treetype=ordconstn) and (op=A_MULS) and
  449. (ispowerof2(p^.right^.value,power)) then
  450. begin
  451. if (power <= 8) then
  452. exprasmlist^.concat(new(pai68k,op_const_reg(A_ASL,opsize,power,
  453. p^.location.register)))
  454. else
  455. begin
  456. exprasmlist^.concat(new(pai68k,op_const_reg(A_MOVE,S_L,power,
  457. R_D6)));
  458. exprasmlist^.concat(new(pai68k,op_reg_reg(A_ASL,opsize,R_D6,
  459. p^.location.register)))
  460. end;
  461. end
  462. else
  463. begin
  464. if (p^.right^.location.loc=LOC_CREGISTER) then
  465. begin
  466. if extra_not then
  467. begin
  468. emit_reg_reg(A_MOVE,S_L,p^.right^.location.register,R_D6);
  469. exprasmlist^.concat(new(pai68k,op_reg(A_NOT,S_L,R_D6)));
  470. emit_reg_reg(A_AND,S_L,R_D6,
  471. p^.location.register);
  472. end
  473. else
  474. begin
  475. if (op=A_MULS) and (opsize = S_L) and (aktoptprocessor=MC68000) then
  476. { Emulation for MC68000 }
  477. begin
  478. emit_reg_reg(A_MOVE,opsize,p^.right^.location.register,
  479. R_D0);
  480. emit_reg_reg(A_MOVE,opsize,p^.location.register,R_D1);
  481. emitcall('LONGMUL',true);
  482. emit_reg_reg(A_MOVE,opsize,R_D0,p^.location.register);
  483. end
  484. else
  485. if (op=A_MULU) and (opsize = S_L) and (aktoptprocessor=MC68000) then
  486. Message(cg_f_32bit_not_supported_in_68000)
  487. else
  488. emit_reg_reg(op,opsize,p^.right^.location.register,
  489. p^.location.register);
  490. end;
  491. end
  492. else
  493. begin
  494. if extra_not then
  495. begin
  496. exprasmlist^.concat(new(pai68k,op_ref_reg(A_MOVE,S_L,newreference(
  497. p^.right^.location.reference),R_D6)));
  498. exprasmlist^.concat(new(pai68k,op_reg(A_NOT,S_L,R_D6)));
  499. emit_reg_reg(A_AND,S_L,R_D6,
  500. p^.location.register);
  501. end
  502. else
  503. begin
  504. if (op=A_MULS) and (opsize = S_L) and (aktoptprocessor=MC68000) then
  505. { Emulation for MC68000 }
  506. begin
  507. exprasmlist^.concat(new(pai68k,op_ref_reg(A_MOVE, opsize,
  508. newreference(p^.right^.location.reference),R_D1)));
  509. emit_reg_reg(A_MOVE,opsize,p^.location.register,R_D0);
  510. emitcall('LONGMUL',true);
  511. emit_reg_reg(A_MOVE,opsize,R_D0,p^.location.register);
  512. end
  513. else
  514. if (op=A_MULU) and (opsize = S_L) and (aktoptprocessor=MC68000) then
  515. Message(cg_f_32bit_not_supported_in_68000)
  516. else
  517. exprasmlist^.concat(new(pai68k,op_ref_reg(op,opsize,newreference(
  518. p^.right^.location.reference),p^.location.register)));
  519. end;
  520. del_reference(p^.right^.location.reference);
  521. end;
  522. end;
  523. end;
  524. end
  525. else
  526. begin
  527. { when swapped another result register }
  528. if (p^.treetype=subn) and p^.swaped then
  529. begin
  530. if extra_not then
  531. exprasmlist^.concat(new(pai68k,op_reg(A_NOT,S_L,p^.location.register)));
  532. exprasmlist^.concat(new(pai68k,op_reg_reg(op,opsize,
  533. p^.location.register,p^.right^.location.register)));
  534. swap_location(p^.location,p^.right^.location);
  535. { newly swapped also set swapped flag }
  536. { just to maintain ordering }
  537. p^.swaped:=not(p^.swaped);
  538. end
  539. else
  540. begin
  541. if extra_not then
  542. exprasmlist^.concat(new(pai68k,op_reg(A_NOT,S_L,p^.right^.location.register)));
  543. if (op=A_MULS) and (opsize = S_L) and (aktoptprocessor=MC68000) then
  544. { Emulation for MC68000 }
  545. begin
  546. emit_reg_reg(A_MOVE,opsize,p^.right^.location.register,
  547. R_D0);
  548. emit_reg_reg(A_MOVE,opsize,p^.location.register,R_D1);
  549. emitcall('LONGMUL',true);
  550. emit_reg_reg(A_MOVE,opsize,R_D0,p^.location.register);
  551. end
  552. else
  553. if (op=A_MULU) and (opsize = S_L) and (aktoptprocessor=MC68000) then
  554. Message(cg_f_32bit_not_supported_in_68000)
  555. else
  556. exprasmlist^.concat(new(pai68k,op_reg_reg(op,opsize,
  557. p^.right^.location.register,
  558. p^.location.register)));
  559. end;
  560. ungetregister32(p^.right^.location.register);
  561. end;
  562. if cmpop then
  563. ungetregister32(p^.location.register);
  564. { only in case of overflow operations }
  565. { produce overflow code }
  566. if mboverflow then
  567. emitoverflowcheck(p);
  568. end
  569. else if ((p^.left^.resulttype^.deftype=orddef) and
  570. (porddef(p^.left^.resulttype)^.typ=uchar)) then
  571. begin
  572. case p^.treetype of
  573. ltn,lten,gtn,gten,
  574. equaln,unequaln :
  575. cmpop:=true;
  576. else Message(sym_e_type_mismatch);
  577. end;
  578. unsigned:=true;
  579. { left and right no register? }
  580. { the one must be demanded }
  581. if (p^.location.loc<>LOC_REGISTER) and
  582. (p^.right^.location.loc<>LOC_REGISTER) then
  583. begin
  584. if p^.location.loc=LOC_CREGISTER then
  585. begin
  586. if cmpop then
  587. { do not disturb register }
  588. hregister:=p^.location.register
  589. else
  590. begin
  591. hregister:=getregister32;
  592. emit_reg_reg(A_MOVE,S_B,p^.location.register,
  593. hregister);
  594. end;
  595. end
  596. else
  597. begin
  598. del_reference(p^.location.reference);
  599. { first give free then demand new register }
  600. hregister:=getregister32;
  601. exprasmlist^.concat(new(pai68k,op_ref_reg(A_MOVE,S_B,newreference(p^.location.reference),
  602. hregister)));
  603. end;
  604. p^.location.loc:=LOC_REGISTER;
  605. p^.location.register:=hregister;
  606. end;
  607. { now p always a register }
  608. if (p^.right^.location.loc=LOC_REGISTER) and
  609. (p^.location.loc<>LOC_REGISTER) then
  610. begin
  611. swap_location(p^.location,p^.right^.location);
  612. { newly swapped also set swapped flag }
  613. p^.swaped:=not(p^.swaped);
  614. end;
  615. if p^.right^.location.loc<>LOC_REGISTER then
  616. begin
  617. if p^.right^.location.loc=LOC_CREGISTER then
  618. begin
  619. emit_reg_reg(A_CMP,S_B,
  620. p^.right^.location.register,p^.location.register);
  621. end
  622. else
  623. begin
  624. exprasmlist^.concat(new(pai68k,op_ref_reg(A_CMP,S_B,newreference(
  625. p^.right^.location.reference),p^.location.register)));
  626. del_reference(p^.right^.location.reference);
  627. end;
  628. end
  629. else
  630. begin
  631. emit_reg_reg(A_CMP,S_B,p^.right^.location.register,
  632. p^.location.register);
  633. ungetregister32(p^.right^.location.register);
  634. end;
  635. ungetregister32(p^.location.register);
  636. end
  637. {*********************************************************************}
  638. else if (p^.left^.resulttype^.deftype=floatdef) and
  639. (pfloatdef(p^.left^.resulttype)^.typ<>f32bit) then
  640. begin
  641. { real constants to the left }
  642. if p^.left^.treetype=realconstn then
  643. begin
  644. swapp:=p^.right;
  645. p^.right:=p^.left;
  646. p^.left:=swapp;
  647. p^.swaped:=not(p^.swaped);
  648. end;
  649. cmpop:=false;
  650. case p^.treetype of
  651. addn : op:=A_FADD;
  652. muln : op:=A_FMUL;
  653. subn : op:=A_FSUB;
  654. slashn : op:=A_FDIV;
  655. ltn,lten,gtn,gten,
  656. equaln,unequaln : begin
  657. op:=A_FCMP;
  658. cmpop:=true;
  659. end;
  660. else Message(sym_e_type_mismatch);
  661. end;
  662. if (p^.left^.location.loc <> LOC_FPU) and
  663. (p^.right^.location.loc <> LOC_FPU) then
  664. begin
  665. { we suppose left in reference }
  666. del_reference(p^.left^.location.reference);
  667. { get a copy, since we don't want to modify the same }
  668. { node at the same time. }
  669. tmpref:=p^.left^.location.reference;
  670. if assigned(p^.left^.location.reference.symbol) then
  671. tmpref.symbol:=stringdup(p^.left^.location.reference.symbol^);
  672. floatload(pfloatdef(p^.left^.resulttype)^.typ, tmpref,
  673. p^.left^.location);
  674. clear_reference(tmpref);
  675. end
  676. else
  677. begin
  678. if (p^.right^.location.loc = LOC_FPU)
  679. and(p^.left^.location.loc <> LOC_FPU) then
  680. begin
  681. swap_location(p^.left^.location, p^.right^.location);
  682. p^.swaped := not(p^.swaped);
  683. end
  684. end;
  685. { ---------------- LEFT = LOC_FPUREG -------------------- }
  686. if ((p^.treetype =subn) or (p^.treetype = slashn)) and (p^.swaped) then
  687. { fpu_reg = right(FP1) / fpu_reg }
  688. { fpu_reg = right(FP1) - fpu_reg }
  689. begin
  690. if (cs_fp_emulation in aktmoduleswitches) then
  691. begin
  692. { fpu_reg = right / D1 }
  693. { fpu_reg = right - D1 }
  694. exprasmlist^.concat(new(pai68k,op_reg_reg(A_MOVE,S_L,p^.left^.location.fpureg,R_D0)));
  695. { load value into D1 }
  696. if p^.right^.location.loc <> LOC_FPU then
  697. exprasmlist^.concat(new(pai68k,op_ref_reg(A_MOVE,S_L,
  698. newreference(p^.right^.location.reference),R_D1)))
  699. else
  700. emit_reg_reg(A_MOVE,S_L,p^.right^.location.fpureg,R_D1);
  701. { probably a faster way to do this but... }
  702. case op of
  703. A_FADD: emitcall('SINGLE_ADD',true);
  704. A_FMUL: emitcall('SINGLE_MUL',true);
  705. A_FSUB: emitcall('SINGLE_SUB',true);
  706. A_FDIV: emitcall('SINGLE_DIV',true);
  707. A_FCMP: emitcall('SINGLE_CMP',true);
  708. end;
  709. if not cmpop then { only flags are affected with cmpop }
  710. exprasmlist^.concat(new(pai68k,op_reg_reg(A_MOVE,S_L,R_D0,
  711. p^.left^.location.fpureg)));
  712. { if this was a reference, then delete as it }
  713. { it no longer required. }
  714. if p^.right^.location.loc <> LOC_FPU then
  715. del_reference(p^.right^.location.reference);
  716. end
  717. else
  718. begin
  719. if p^.right^.location.loc <> LOC_FPU then
  720. exprasmlist^.concat(new(pai68k,op_ref_reg(A_FMOVE,
  721. getfloatsize(pfloatdef(p^.left^.resulttype)^.typ),
  722. newreference(p^.right^.location.reference),
  723. R_FP1)))
  724. else
  725. { FPm --> FPn must use extended precision }
  726. emit_reg_reg(A_FMOVE,S_FX,p^.right^.location.fpureg,R_FP1);
  727. { arithmetic expression performed in extended mode }
  728. exprasmlist^.concat(new(pai68k,op_reg_reg(op,S_FX,
  729. p^.left^.location.fpureg,R_FP1)));
  730. { cmpop does not change any floating point register!! }
  731. if not cmpop then
  732. emit_reg_reg(A_FMOVE,S_FX,R_FP1,p^.left^.location.fpureg)
  733. { exprasmlist^.concat(new(pai68k,op_reg_reg(A_FMOVE,
  734. getfloatsize(pfloatdef(p^.left^.resulttype)^.typ),
  735. R_FP1,p^.left^.location.fpureg)))}
  736. else
  737. { process comparison, to make it compatible with the rest of the code }
  738. processcc(p);
  739. { if this was a reference, then delete as it }
  740. { it no longer required. }
  741. if p^.right^.location.loc <> LOC_FPU then
  742. del_reference(p^.right^.location.reference);
  743. end;
  744. end
  745. else { everything is in the right order }
  746. begin
  747. { fpu_reg = fpu_reg / right }
  748. { fpu_reg = fpu_reg - right }
  749. { + commutative ops }
  750. if cs_fp_emulation in aktmoduleswitches then
  751. begin
  752. { load value into D7 }
  753. if p^.right^.location.loc <> LOC_FPU then
  754. exprasmlist^.concat(new(pai68k,op_ref_reg(A_MOVE,S_L,
  755. newreference(p^.right^.location.reference),R_D0)))
  756. else
  757. emit_reg_reg(A_MOVE,S_L,p^.right^.location.fpureg,R_D0);
  758. emit_reg_reg(A_MOVE,S_L,p^.left^.location.fpureg,R_D1);
  759. { probably a faster way to do this but... }
  760. case op of
  761. A_FADD: emitcall('SINGLE_ADD',true);
  762. A_FMUL: emitcall('SINGLE_MUL',true);
  763. A_FSUB: emitcall('SINGLE_SUB',true);
  764. A_FDIV: emitcall('SINGLE_DIV',true);
  765. A_FCMP: emitcall('SINGLE_CMP',true);
  766. end;
  767. if not cmpop then { only flags are affected with cmpop }
  768. exprasmlist^.concat(new(pai68k,op_reg_reg(A_MOVE,S_L,R_D0,
  769. p^.left^.location.fpureg)));
  770. { if this was a reference, then delete as it }
  771. { it no longer required. }
  772. if p^.right^.location.loc <> LOC_FPU then
  773. del_reference(p^.right^.location.reference);
  774. end
  775. else
  776. begin
  777. if p^.right^.location.loc <> LOC_FPU then
  778. exprasmlist^.concat(new(pai68k,op_ref_reg(A_FMOVE,
  779. getfloatsize(pfloatdef(p^.left^.resulttype)^.typ),
  780. newreference(p^.right^.location.reference),R_FP1)))
  781. else
  782. emit_reg_reg(A_FMOVE,getfloatsize(pfloatdef(p^.left^.resulttype)^.typ),
  783. p^.right^.location.fpureg,R_FP1);
  784. emit_reg_reg(op,S_FX,R_FP1,p^.left^.location.fpureg);
  785. if cmpop then
  786. processcc(p);
  787. { if this was a reference, then delete as it }
  788. { it no longer required. }
  789. if p^.right^.location.loc <> LOC_FPU then
  790. del_reference(p^.right^.location.reference);
  791. end
  792. end; { endif treetype = .. }
  793. if cmpop then
  794. begin
  795. if p^.swaped then
  796. case p^.treetype of
  797. equaln: flags := F_E;
  798. unequaln: flags := F_NE;
  799. ltn : flags := F_G;
  800. lten : flags := F_GE;
  801. gtn : flags := F_L;
  802. gten: flags := F_LE;
  803. end
  804. else
  805. case p^.treetype of
  806. equaln: flags := F_E;
  807. unequaln : flags := F_NE;
  808. ltn: flags := F_L;
  809. lten : flags := F_LE;
  810. gtn : flags := F_G;
  811. gten: flags := F_GE;
  812. end;
  813. p^.location.loc := LOC_FLAGS;
  814. p^.location.resflags := flags;
  815. cmpop := false;
  816. end
  817. else
  818. begin
  819. p^.location.loc := LOC_FPU;
  820. if p^.left^.location.loc = LOC_FPU then
  821. { copy fpu register result . }
  822. { HERE ON EXIT FPU REGISTER IS IN EXTENDED MODE! }
  823. p^.location.fpureg := p^.left^.location.fpureg
  824. else
  825. begin
  826. InternalError(34);
  827. end;
  828. end;
  829. end
  830. {*********************************************************************}
  831. else if (p^.left^.resulttype^.deftype=setdef) then
  832. begin
  833. { not commutative }
  834. if p^.swaped then
  835. begin
  836. swapp:=p^.left;
  837. p^.left:=p^.right;
  838. p^.right:=swapp;
  839. { because of jump being produced by comparison }
  840. p^.swaped:=not(p^.swaped);
  841. end;
  842. case p^.treetype of
  843. equaln,unequaln : begin
  844. cmpop:=true;
  845. del_reference(p^.left^.location.reference);
  846. del_reference(p^.right^.location.reference);
  847. pushusedregisters(pushedregs,$ffff);
  848. { emitpushreferenceaddr(p^.right^.location.reference);
  849. emitpushreferenceaddr(p^.left^.location.reference);}
  850. exprasmlist^.concat(new(pai68k,op_ref_reg(A_LEA,S_L,
  851. newreference(p^.left^.location.reference),R_A0)));
  852. exprasmlist^.concat(new(pai68k,op_ref_reg(A_LEA,S_L,
  853. newreference(p^.right^.location.reference),R_A1)));
  854. emitcall('SET_COMP_SETS',true);
  855. maybe_loada5;
  856. popusedregisters(pushedregs);
  857. ungetiftemp(p^.left^.location.reference);
  858. ungetiftemp(p^.right^.location.reference);
  859. end;
  860. addn,subn,muln,symdifn : begin
  861. cmpop:=false;
  862. del_reference(p^.left^.location.reference);
  863. del_reference(p^.right^.location.reference);
  864. href.symbol:=nil;
  865. pushusedregisters(pushedregs,$ffff);
  866. gettempofsizereference(32,href);
  867. emitpushreferenceaddr(href);
  868. { wrong place !! was hard to find out
  869. pushusedregisters(pushedregs,$ff);}
  870. emitpushreferenceaddr(p^.right^.location.reference);
  871. emitpushreferenceaddr(p^.left^.location.reference);
  872. case p^.treetype of
  873. subn : exprasmlist^.concat(new(pai68k,op_csymbol(A_JSR,S_NO,
  874. newcsymbol('SET_SUB_SETS',0))));
  875. addn : exprasmlist^.concat(new(pai68k,op_csymbol(A_JSR,S_NO,
  876. newcsymbol('SET_ADD_SETS',0))));
  877. muln : exprasmlist^.concat(new(pai68k,op_csymbol(A_JSR,S_NO,
  878. newcsymbol('SET_MUL_SETS',0))));
  879. symdifn:
  880. emitcall('SET_SYMDIF_SETS',true);
  881. end;
  882. maybe_loada5;
  883. popusedregisters(pushedregs);
  884. ungetiftemp(p^.left^.location.reference);
  885. ungetiftemp(p^.right^.location.reference);
  886. p^.location.loc:=LOC_MEM;
  887. stringdispose(p^.location.reference.symbol);
  888. p^.location.reference:=href;
  889. end;
  890. else Message(sym_e_type_mismatch);
  891. end; { end case }
  892. end {else if begin }
  893. else Message(sym_e_type_mismatch);
  894. end; { endif }
  895. if (p^.left^.resulttype^.deftype<>stringdef) and
  896. not ((p^.left^.resulttype^.deftype=setdef) and
  897. (psetdef(p^.left^.resulttype)^.settype<>smallset)) then
  898. begin
  899. { this can be useful if for instance length(string) is called }
  900. if (p^.left^.location.loc=LOC_REFERENCE) or
  901. (p^.left^.location.loc=LOC_MEM) then
  902. ungetiftemp(p^.left^.location.reference);
  903. if (p^.right^.location.loc=LOC_REFERENCE) or
  904. (p^.right^.location.loc=LOC_MEM) then
  905. ungetiftemp(p^.right^.location.reference);
  906. end;
  907. { in case of comparison operation the put result in the flags }
  908. if cmpop then
  909. begin
  910. if not(unsigned) then
  911. begin
  912. if p^.swaped then
  913. case p^.treetype of
  914. equaln : flags:=F_E;
  915. unequaln : flags:=F_NE;
  916. ltn : flags:=F_G;
  917. lten : flags:=F_GE;
  918. gtn : flags:=F_L;
  919. gten : flags:=F_LE;
  920. end
  921. else
  922. case p^.treetype of
  923. equaln : flags:=F_E;
  924. unequaln : flags:=F_NE;
  925. ltn : flags:=F_L;
  926. lten : flags:=F_LE;
  927. gtn : flags:=F_G;
  928. gten : flags:=F_GE;
  929. end;
  930. end
  931. else
  932. begin
  933. if p^.swaped then
  934. case p^.treetype of
  935. equaln : flags:=F_E;
  936. unequaln : flags:=F_NE;
  937. ltn : flags:=F_A;
  938. lten : flags:=F_AE;
  939. gtn : flags:=F_B;
  940. gten : flags:=F_BE;
  941. end
  942. else
  943. case p^.treetype of
  944. equaln : flags:=F_E;
  945. unequaln : flags:=F_NE;
  946. ltn : flags:=F_B;
  947. lten : flags:=F_BE;
  948. gtn : flags:=F_A;
  949. gten : flags:=F_AE;
  950. end;
  951. end; { end begin }
  952. p^.location.loc:=LOC_FLAGS;
  953. p^.location.resflags:=flags;
  954. end; { endif cmpop }
  955. end;
  956. procedure processcc(p: ptree);
  957. var
  958. label1,label2: plabel;
  959. (*************************************************************************)
  960. (* Description: This routine handles the conversion of Floating point *)
  961. (* condition codes to normal cpu condition codes. *)
  962. (*************************************************************************)
  963. begin
  964. getlabel(label1);
  965. getlabel(label2);
  966. case p^.treetype of
  967. equaln,unequaln: begin
  968. { not equal clear zero flag }
  969. emitl(A_FBEQ,label1);
  970. exprasmlist^.concat(new(pai68k, op_const_reg(
  971. A_AND, S_B, NOT ZERO_FLAG, R_CCR)));
  972. emitl(A_BRA,label2);
  973. emitl(A_LABEL,label1);
  974. { equal - set zero flag }
  975. exprasmlist^.concat(new(pai68k, op_const_reg(
  976. A_OR,S_B, ZERO_FLAG, R_CCR)));
  977. emitl(A_LABEL,label2);
  978. end;
  979. ltn: begin
  980. emitl(A_FBLT,label1);
  981. { not less than }
  982. { clear N and V flags }
  983. exprasmlist^.concat(new(pai68k, op_const_reg(
  984. A_AND, S_B, NOT (NEG_FLAG OR OVFL_FLAG), R_CCR)));
  985. emitl(A_BRA,label2);
  986. emitl(A_LABEL,label1);
  987. { less than }
  988. exprasmlist^.concat(new(pai68k, op_const_reg(
  989. A_OR,S_B, NEG_FLAG, R_CCR)));
  990. exprasmlist^.concat(new(pai68k, op_const_reg(
  991. A_AND,S_B, NOT OVFL_FLAG, R_CCR)));
  992. emitl(A_LABEL,label2);
  993. end;
  994. gtn: begin
  995. emitl(A_FBGT,label1);
  996. { not greater than }
  997. { set Z flag }
  998. exprasmlist^.concat(new(pai68k, op_const_reg(
  999. A_OR, S_B, ZERO_FLAG, R_CCR)));
  1000. emitl(A_BRA,label2);
  1001. emitl(A_LABEL,label1);
  1002. { greater than }
  1003. { set N and V flags }
  1004. exprasmlist^.concat(new(pai68k, op_const_reg(
  1005. A_OR,S_B, NEG_FLAG OR OVFL_FLAG , R_CCR)));
  1006. emitl(A_LABEL,label2);
  1007. end;
  1008. gten: begin
  1009. emitl(A_FBGE,label1);
  1010. { not greater or equal }
  1011. { set N and clear V }
  1012. exprasmlist^.concat(new(pai68k, op_const_reg(
  1013. A_AND, S_B, NOT OVFL_FLAG, R_CCR)));
  1014. exprasmlist^.concat(new(pai68k, op_const_reg(
  1015. A_OR,S_B, NEG_FLAG, R_CCR)));
  1016. emitl(A_BRA,label2);
  1017. emitl(A_LABEL,label1);
  1018. { greater or equal }
  1019. { clear V and N flags }
  1020. exprasmlist^.concat(new(pai68k, op_const_reg(
  1021. A_AND, S_B, NOT (OVFL_FLAG OR NEG_FLAG), R_CCR)));
  1022. emitl(A_LABEL,label2);
  1023. end;
  1024. lten: begin
  1025. emitl(A_FBLE,label1);
  1026. { not less or equal }
  1027. { clear Z, N and V }
  1028. exprasmlist^.concat(new(pai68k, op_const_reg(
  1029. A_AND, S_B, NOT (ZERO_FLAG OR NEG_FLAG OR OVFL_FLAG), R_CCR)));
  1030. emitl(A_BRA,label2);
  1031. emitl(A_LABEL,label1);
  1032. { less or equal }
  1033. { set Z and N }
  1034. { and clear V }
  1035. exprasmlist^.concat(new(pai68k, op_const_reg(
  1036. A_OR,S_B, ZERO_FLAG OR NEG_FLAG, R_CCR)));
  1037. exprasmlist^.concat(new(pai68k, op_const_reg(
  1038. A_AND,S_B, NOT OVFL_FLAG, R_CCR)));
  1039. emitl(A_LABEL,label2);
  1040. end;
  1041. else
  1042. begin
  1043. InternalError(34);
  1044. end;
  1045. end; { end case }
  1046. end;
  1047. procedure secondfor(var p : ptree);
  1048. var
  1049. l1,l3,oldclabel,oldblabel : plabel;
  1050. omitfirstcomp,temptovalue : boolean;
  1051. hs : byte;
  1052. temp1 : treference;
  1053. hop : tasmop;
  1054. cmpreg,cmp32 : tregister;
  1055. opsize : topsize;
  1056. count_var_is_signed : boolean;
  1057. begin
  1058. oldclabel:=aktcontinuelabel;
  1059. oldblabel:=aktbreaklabel;
  1060. getlabel(aktcontinuelabel);
  1061. getlabel(aktbreaklabel);
  1062. getlabel(l3);
  1063. { could we spare the first comparison ? }
  1064. omitfirstcomp:=false;
  1065. if p^.right^.treetype=ordconstn then
  1066. if p^.left^.right^.treetype=ordconstn then
  1067. omitfirstcomp:=(p^.backward and (p^.left^.right^.value>=p^.right^.value))
  1068. or (not(p^.backward) and (p^.left^.right^.value<=p^.right^.value));
  1069. { only calculate reference }
  1070. cleartempgen;
  1071. secondpass(p^.t2);
  1072. if not(simple_loadn) then
  1073. Message(cg_e_illegal_count_var);
  1074. { produce start assignment }
  1075. cleartempgen;
  1076. secondpass(p^.left);
  1077. count_var_is_signed:=is_signed(porddef(p^.t2^.resulttype));
  1078. hs:=p^.t2^.resulttype^.size;
  1079. cmp32:=getregister32;
  1080. cmpreg:=cmp32;
  1081. case hs of
  1082. 1 : begin
  1083. opsize:=S_B;
  1084. end;
  1085. 2 : begin
  1086. opsize:=S_W;
  1087. end;
  1088. 4 : begin
  1089. opsize:=S_L;
  1090. end;
  1091. end;
  1092. cleartempgen;
  1093. secondpass(p^.right);
  1094. { calculate pointer value and check if changeable and if so }
  1095. { load into temporary variable }
  1096. if p^.right^.treetype<>ordconstn then
  1097. begin
  1098. temp1.symbol:=nil;
  1099. gettempofsizereference(hs,temp1);
  1100. temptovalue:=true;
  1101. if (p^.right^.location.loc=LOC_REGISTER) or
  1102. (p^.right^.location.loc=LOC_CREGISTER) then
  1103. begin
  1104. exprasmlist^.concat(new(pai68k,op_reg_ref(A_MOVE,opsize,p^.right^.location.register,
  1105. newreference(temp1))));
  1106. end
  1107. else
  1108. concatcopy(p^.right^.location.reference,temp1,hs,false);
  1109. end
  1110. else temptovalue:=false;
  1111. if temptovalue then
  1112. begin
  1113. if p^.t2^.location.loc=LOC_CREGISTER then
  1114. begin
  1115. exprasmlist^.concat(new(pai68k,op_ref_reg(A_CMP,opsize,newreference(temp1),
  1116. p^.t2^.location.register)));
  1117. end
  1118. else
  1119. begin
  1120. exprasmlist^.concat(new(pai68k,op_ref_reg(A_MOVE,opsize,newreference(p^.t2^.location.reference),
  1121. cmpreg)));
  1122. exprasmlist^.concat(new(pai68k,op_ref_reg(A_CMP,opsize,newreference(temp1),
  1123. cmpreg)));
  1124. end;
  1125. end
  1126. else
  1127. begin
  1128. if not(omitfirstcomp) then
  1129. begin
  1130. if p^.t2^.location.loc=LOC_CREGISTER then
  1131. exprasmlist^.concat(new(pai68k,op_const_reg(A_CMP,opsize,p^.right^.value,
  1132. p^.t2^.location.register)))
  1133. else
  1134. exprasmlist^.concat(new(pai68k,op_const_ref(A_CMP,opsize,p^.right^.value,
  1135. newreference(p^.t2^.location.reference))));
  1136. end;
  1137. end;
  1138. if p^.backward then
  1139. begin
  1140. if count_var_is_signed then
  1141. hop:=A_BLT
  1142. else
  1143. hop:=A_BCS;
  1144. end
  1145. else
  1146. if count_var_is_signed then
  1147. hop:=A_BGT
  1148. else hop:=A_BHI;
  1149. if not(omitfirstcomp) or temptovalue then
  1150. emitl(hop,aktbreaklabel);
  1151. emitl(A_LABEL,l3);
  1152. { help register must not be in instruction block }
  1153. cleartempgen;
  1154. if assigned(p^.t1) then
  1155. secondpass(p^.t1);
  1156. emitl(A_LABEL,aktcontinuelabel);
  1157. { makes no problems there }
  1158. cleartempgen;
  1159. { demand help register again }
  1160. cmp32:=getregister32;
  1161. case hs of
  1162. 1 : begin
  1163. opsize:=S_B;
  1164. end;
  1165. 2 : begin
  1166. opsize:=S_W;
  1167. end;
  1168. 4 : opsize:=S_L;
  1169. end;
  1170. { produce comparison and the corresponding }
  1171. { jump }
  1172. if temptovalue then
  1173. begin
  1174. if p^.t2^.location.loc=LOC_CREGISTER then
  1175. begin
  1176. exprasmlist^.concat(new(pai68k,op_ref_reg(A_CMP,opsize,newreference(temp1),
  1177. p^.t2^.location.register)));
  1178. end
  1179. else
  1180. begin
  1181. exprasmlist^.concat(new(pai68k,op_ref_reg(A_MOVE,opsize,newreference(p^.t2^.location.reference),
  1182. cmpreg)));
  1183. exprasmlist^.concat(new(pai68k,op_ref_reg(A_CMP,opsize,newreference(temp1),
  1184. cmpreg)));
  1185. end;
  1186. end
  1187. else
  1188. begin
  1189. if p^.t2^.location.loc=LOC_CREGISTER then
  1190. exprasmlist^.concat(new(pai68k,op_const_reg(A_CMP,opsize,p^.right^.value,
  1191. p^.t2^.location.register)))
  1192. else
  1193. exprasmlist^.concat(new(pai68k,op_const_ref(A_CMP,opsize,p^.right^.value,
  1194. newreference(p^.t2^.location.reference))));
  1195. end;
  1196. if p^.backward then
  1197. if count_var_is_signed then
  1198. hop:=A_BLE
  1199. else
  1200. hop :=A_BLS
  1201. else
  1202. if count_var_is_signed then
  1203. hop:=A_BGE
  1204. else
  1205. hop:=A_BCC;
  1206. emitl(hop,aktbreaklabel);
  1207. { according to count direction DEC or INC... }
  1208. { must be after the test because of 0to 255 for bytes !! }
  1209. if p^.backward then
  1210. hop:=A_SUB
  1211. else hop:=A_ADD;
  1212. if p^.t2^.location.loc=LOC_CREGISTER then
  1213. exprasmlist^.concat(new(pai68k,op_const_reg(hop,opsize,1,p^.t2^.location.register)))
  1214. else
  1215. exprasmlist^.concat(new(pai68k,op_const_ref(hop,opsize,1,newreference(p^.t2^.location.reference))));
  1216. emitl(A_JMP,l3);
  1217. { this is the break label: }
  1218. emitl(A_LABEL,aktbreaklabel);
  1219. ungetregister32(cmp32);
  1220. if temptovalue then
  1221. ungetiftemp(temp1);
  1222. aktcontinuelabel:=oldclabel;
  1223. aktbreaklabel:=oldblabel;
  1224. end;
  1225. procedure secondas(var p : ptree);
  1226. var
  1227. pushed : tpushed;
  1228. begin
  1229. secondpass(p^.left);
  1230. { save all used registers }
  1231. pushusedregisters(pushed,$ffff);
  1232. { push instance to check: }
  1233. case p^.left^.location.loc of
  1234. LOC_REGISTER,LOC_CREGISTER:
  1235. exprasmlist^.concat(new(pai68k,op_reg_reg(A_MOVE,
  1236. S_L,p^.left^.location.register,R_SPPUSH)));
  1237. LOC_MEM,LOC_REFERENCE:
  1238. exprasmlist^.concat(new(pai68k,op_ref_reg(A_MOVE,
  1239. S_L,newreference(p^.left^.location.reference),R_SPPUSH)));
  1240. else internalerror(100);
  1241. end;
  1242. { we doesn't modifiy the left side, we check only the type }
  1243. set_location(p^.location,p^.left^.location);
  1244. { generate type checking }
  1245. secondpass(p^.right);
  1246. case p^.right^.location.loc of
  1247. LOC_REGISTER,LOC_CREGISTER:
  1248. begin
  1249. exprasmlist^.concat(new(pai68k,op_reg_reg(A_MOVE,
  1250. S_L,p^.right^.location.register,R_SPPUSH)));
  1251. ungetregister32(p^.right^.location.register);
  1252. end;
  1253. LOC_MEM,LOC_REFERENCE:
  1254. begin
  1255. exprasmlist^.concat(new(pai68k,op_ref_reg(A_MOVE,
  1256. S_L,newreference(p^.right^.location.reference),R_SPPUSH)));
  1257. del_reference(p^.right^.location.reference);
  1258. end;
  1259. else internalerror(100);
  1260. end;
  1261. emitcall('DO_AS',true);
  1262. { restore register, this restores automatically the }
  1263. { result }
  1264. popusedregisters(pushed);
  1265. end;
  1266. { generates the code for a raise statement }
  1267. procedure secondraise(var p : ptree);
  1268. var
  1269. a : plabel;
  1270. begin
  1271. if assigned(p^.left) then
  1272. begin
  1273. { generate the address }
  1274. if assigned(p^.right) then
  1275. begin
  1276. secondpass(p^.right);
  1277. if codegenerror then
  1278. exit;
  1279. end
  1280. else
  1281. begin
  1282. getlabel(a);
  1283. emitl(A_LABEL,a);
  1284. exprasmlist^.concat(new(pai68k,
  1285. op_csymbol_reg(A_MOVE,S_L,newcsymbol(lab2str(a),0),R_SPPUSH)));
  1286. end;
  1287. secondpass(p^.left);
  1288. if codegenerror then
  1289. exit;
  1290. case p^.left^.location.loc of
  1291. LOC_MEM,LOC_REFERENCE : emitpushreferenceaddr(p^.left^.location.reference);
  1292. LOC_CREGISTER,LOC_REGISTER : exprasmlist^.concat(new(pai68k,op_reg_reg(A_MOVE,S_L,
  1293. p^.left^.location.register,R_SPPUSH)));
  1294. else Message(sym_e_type_mismatch);
  1295. end;
  1296. emitcall('DO_RAISE',true);
  1297. end
  1298. else
  1299. emitcall('DO_RERAISE',true);
  1300. end;
  1301. { This routine needs to be further checked to see if it works correctly }
  1302. { because contrary to the intel version, all large set elements are read }
  1303. { as 32-bit values, and then decomposed to find the correct byte. }
  1304. { CHECKED -> Requires 32-bit read. }
  1305. procedure loadsetelement(var p : ptree);
  1306. var
  1307. hr : tregister;
  1308. begin
  1309. { copy the element in the d0.b register, slightly complicated }
  1310. case p^.location.loc of
  1311. LOC_REGISTER,
  1312. LOC_CREGISTER : begin
  1313. hr:=p^.location.register;
  1314. emit_reg_reg(A_MOVE,S_L,hr,R_D0);
  1315. ungetregister32(hr);
  1316. end;
  1317. else
  1318. begin
  1319. exprasmlist^.concat(new(pai68k,op_ref_reg(A_MOVE,S_L,
  1320. newreference(p^.location.reference),R_D0)));
  1321. { exprasmlist^.concat(new(pai68k,op_const_reg(A_AND,S_L,
  1322. $ff,R_D0))); }
  1323. del_reference(p^.location.reference);
  1324. end;
  1325. end;
  1326. end;
  1327. { could be built into secondadd but it }
  1328. { should be easy to read }
  1329. procedure secondin(var p : ptree);
  1330. type Tsetpart=record
  1331. range:boolean; {Part is a range.}
  1332. start,stop:byte; {Start/stop when range; Stop=element
  1333. when an element.}
  1334. end;
  1335. var
  1336. pushed,ranges : boolean;
  1337. hr : tregister;
  1338. setparts:array[1..8] of Tsetpart;
  1339. i,numparts:byte;
  1340. href,href2:Treference;
  1341. l,l2 : plabel;
  1342. hl,hl1 : plabel;
  1343. hl2, hl3: plabel;
  1344. function analizeset(Aset:Pconstset):boolean;
  1345. var compares,maxcompares:word;
  1346. i:byte;
  1347. type byteset=set of byte;
  1348. begin
  1349. analizeset:=false;
  1350. ranges:=false;
  1351. numparts:=0;
  1352. compares:=0;
  1353. {Lots of comparisions take a lot of time, so do not allow
  1354. too much comparisions. 8 comparisions are, however, still
  1355. smalller than emitting the set.}
  1356. maxcompares:=5;
  1357. if cs_littlesize in aktglobalswitches then
  1358. maxcompares:=8;
  1359. for i:=0 to 255 do
  1360. if i in byteset(Aset^) then
  1361. begin
  1362. if (numparts=0) or
  1363. (i<>setparts[numparts].stop+1) then
  1364. begin
  1365. {Set element is a separate element.}
  1366. inc(compares);
  1367. if compares>maxcompares then
  1368. exit;
  1369. inc(numparts);
  1370. setparts[numparts].range:=false;
  1371. setparts[numparts].stop:=i;
  1372. end
  1373. else
  1374. {Set element is part of a range.}
  1375. if not setparts[numparts].range then
  1376. begin
  1377. {Transform an element into a range.}
  1378. setparts[numparts].range:=true;
  1379. setparts[numparts].start:=
  1380. setparts[numparts].stop;
  1381. setparts[numparts].stop:=i;
  1382. inc(compares);
  1383. if compares>maxcompares then
  1384. exit;
  1385. end
  1386. else
  1387. begin
  1388. {Extend a range.}
  1389. setparts[numparts].stop:=i;
  1390. {A range of two elements can better
  1391. be checked as two separate ones.
  1392. When extending a range, our range
  1393. becomes larger than two elements.}
  1394. ranges:=true;
  1395. end;
  1396. end;
  1397. analizeset:=true;
  1398. end; { end analizeset }
  1399. begin
  1400. if psetdef(p^.right^.resulttype)^.settype=smallset then
  1401. begin
  1402. if p^.left^.treetype=ordconstn then
  1403. begin
  1404. { only compulsory }
  1405. secondpass(p^.left);
  1406. secondpass(p^.right);
  1407. if codegenerror then
  1408. exit;
  1409. p^.location.resflags:=F_NE;
  1410. { Because of the Endian of the m68k, we have to consider this as a }
  1411. { normal set and load it byte per byte, otherwise we will never get }
  1412. { the correct result. }
  1413. case p^.right^.location.loc of
  1414. LOC_REGISTER,LOC_CREGISTER :
  1415. begin
  1416. emit_reg_reg(A_MOVE,S_L,p^.right^.location.register,R_D1);
  1417. exprasmlist^.concat(new(pai68k,
  1418. op_const_reg(A_AND,S_L, 1 shl (p^.left^.value and 31),R_D1)));
  1419. end;
  1420. else
  1421. begin
  1422. exprasmlist^.concat(new(pai68k,op_ref_reg(A_MOVE,S_L,newreference(
  1423. p^.right^.location.reference),R_D1)));
  1424. exprasmlist^.concat(new(pai68k,op_const_reg(
  1425. A_AND,S_L,1 shl (p^.left^.value and 31) ,R_D1)));
  1426. end;
  1427. end;
  1428. del_reference(p^.right^.location.reference);
  1429. end
  1430. else
  1431. begin
  1432. { calculate both operators }
  1433. { the complex one first }
  1434. firstcomplex(p);
  1435. secondpass(p^.left);
  1436. { are too few registers free? }
  1437. pushed:=maybe_push(p^.right^.registers32,p^.left);
  1438. secondpass(p^.right);
  1439. if pushed then
  1440. restore(p^.left);
  1441. { of course not commutative }
  1442. if p^.swaped then
  1443. swaptree(p);
  1444. { load index into register }
  1445. case p^.left^.location.loc of
  1446. LOC_REGISTER,
  1447. LOC_CREGISTER :
  1448. hr:=p^.left^.location.register;
  1449. else
  1450. begin
  1451. { the set element isn't never samller than a byte }
  1452. { and because it's a small set we need only 5 bits }
  1453. { but 8 bits are eaiser to load }
  1454. exprasmlist^.concat(new(pai68k,op_ref_reg(A_MOVE,S_L,
  1455. newreference(p^.left^.location.reference),R_D1)));
  1456. hr:=R_D1;
  1457. del_reference(p^.left^.location.reference);
  1458. end;
  1459. end;
  1460. case p^.right^.location.loc of
  1461. LOC_REGISTER,
  1462. LOC_CREGISTER : exprasmlist^.concat(new(pai68k, op_reg_reg(A_BTST,S_L,hr,p^.right^.location.register)));
  1463. else
  1464. begin
  1465. { OOPS ... bug here thanks Florian!! }
  1466. exprasmlist^.concat(new(pai68k,op_ref_reg(A_MOVE,S_L,newreference(p^.right^.location.reference),
  1467. R_D0)));
  1468. exprasmlist^.concat(new(pai68k,op_reg_reg(A_BTST,S_L,hr,R_D0)));
  1469. del_reference(p^.right^.location.reference);
  1470. end;
  1471. end;
  1472. { support carry routines }
  1473. { sets the carry flags according to the result of BTST }
  1474. { i.e the Z flag. }
  1475. getlabel(hl);
  1476. emitl(A_BNE,hl);
  1477. { leave all bits unchanged except Carry = 0 }
  1478. exprasmlist^.concat(new(pai68k, op_const_reg(A_AND, S_B, $FE, R_CCR)));
  1479. getlabel(hl1);
  1480. emitl(A_BRA,hl1);
  1481. emitl(A_LABEL, hl);
  1482. { set carry to 1 }
  1483. exprasmlist^.concat(new(pai68k, op_const_reg(A_OR, S_B, $01, R_CCR)));
  1484. emitl(A_LABEL, hl1);
  1485. { end support carry routines }
  1486. p^.location.loc:=LOC_FLAGS;
  1487. p^.location.resflags:=F_C;
  1488. end;
  1489. end
  1490. else { NOT a small set }
  1491. begin
  1492. if p^.left^.treetype=ordconstn then
  1493. begin
  1494. { only compulsory }
  1495. secondpass(p^.left);
  1496. secondpass(p^.right);
  1497. if codegenerror then
  1498. exit;
  1499. p^.location.resflags:=F_NE;
  1500. inc(p^.right^.location.reference.offset,(p^.left^.value div 32)*4);
  1501. exprasmlist^.concat(new(pai68k, op_ref_reg(A_MOVE, S_L,
  1502. newreference(p^.right^.location.reference), R_D1)));
  1503. exprasmlist^.concat(new(pai68k, op_const_reg(A_AND, S_L,
  1504. 1 shl (p^.left^.value mod 32),R_D1)));
  1505. del_reference(p^.right^.location.reference);
  1506. end
  1507. else
  1508. begin
  1509. if (p^.right^.treetype=setconstrn) and
  1510. analizeset(p^.right^.constset) then
  1511. begin
  1512. {It gives us advantage to check for the set elements
  1513. separately instead of using the SET_IN_BYTE procedure.
  1514. To do: Build in support for LOC_JUMP.}
  1515. secondpass(p^.left);
  1516. {We won't do a second pass on p^.right, because
  1517. this will emit the constant set.}
  1518. case p^.left^.location.loc of
  1519. LOC_REGISTER,
  1520. LOC_CREGISTER :
  1521. exprasmlist^.concat(new(pai68k,op_const_reg(A_AND,S_L,
  1522. 255,p^.left^.location.register)));
  1523. else
  1524. Begin
  1525. exprasmlist^.concat(new(pai68k,op_ref_reg(A_MOVE,S_B,
  1526. newreference(p^.left^.location.reference),R_D0)));
  1527. exprasmlist^.concat(new(pai68k,op_const_reg(A_AND,S_L,
  1528. 255,R_D0)));
  1529. end;
  1530. end;
  1531. {Get a label to jump to the end.}
  1532. p^.location.loc:=LOC_FLAGS;
  1533. {It's better to use the zero flag when there are no ranges.}
  1534. if ranges then
  1535. p^.location.resflags:=F_C
  1536. else
  1537. p^.location.resflags:=F_E;
  1538. href.symbol := nil;
  1539. clear_reference(href);
  1540. getlabel(l);
  1541. href.symbol:=stringdup(lab2str(l));
  1542. for i:=1 to numparts do
  1543. if setparts[i].range then
  1544. begin
  1545. {Check if left is in a range.}
  1546. {Get a label to jump over the check.}
  1547. href2.symbol := nil;
  1548. clear_reference(href2);
  1549. getlabel(l2);
  1550. href.symbol:=stringdup(lab2str(l2));
  1551. if setparts[i].start=setparts[i].stop-1 then
  1552. begin
  1553. case p^.left^.location.loc of
  1554. LOC_REGISTER,
  1555. LOC_CREGISTER :
  1556. exprasmlist^.concat(new(pai68k,op_const_reg(A_CMP,S_W,
  1557. setparts[i].start,p^.left^.location.register)));
  1558. else
  1559. exprasmlist^.concat(new(pai68k,op_const_reg(A_CMP,S_W,
  1560. setparts[i].start,R_D0)));
  1561. { exprasmlist^.concat(new(pai68k,op_const_ref(A_CMP,S_B,
  1562. setparts[i].start,newreference(p^.left^.location.reference))));}
  1563. end;
  1564. {Result should be in carry flag when ranges are used.}
  1565. { Here the m68k does not affect any flag except the }
  1566. { flag which is OR'ed }
  1567. if ranges then
  1568. exprasmlist^.concat(new(pai68k,op_const_reg(A_OR,S_B,$01,R_CCR)));
  1569. {If found, jump to end.}
  1570. emitl(A_BEQ,l);
  1571. case p^.left^.location.loc of
  1572. LOC_REGISTER,
  1573. LOC_CREGISTER :
  1574. exprasmlist^.concat(new(pai68k,op_const_reg(A_CMP,S_W,
  1575. setparts[i].stop,p^.left^.location.register)));
  1576. else
  1577. exprasmlist^.concat(new(pai68k,op_const_reg(A_CMP,S_W,
  1578. setparts[i].stop,R_D0)));
  1579. { exprasmlist^.concat(new(pai68k,op_const_ref(A_CMP,S_B,
  1580. setparts[i].stop,newreference(p^.left^.location.reference))));}
  1581. end;
  1582. {Result should be in carry flag when ranges are used.}
  1583. { Here the m68k does not affect any flag except the }
  1584. { flag which is OR'ed }
  1585. if ranges then
  1586. exprasmlist^.concat(new(pai68k,op_const_reg(A_OR,S_B,$01,R_CCR)));
  1587. {If found, jump to end.}
  1588. emitl(A_BEQ,l);
  1589. end
  1590. else
  1591. begin
  1592. if setparts[i].start<>0 then
  1593. begin
  1594. {We only check for the lower bound if it is > 0, because
  1595. set elements lower than 0 do nt exist.}
  1596. case p^.left^.location.loc of
  1597. LOC_REGISTER,
  1598. LOC_CREGISTER :
  1599. exprasmlist^.concat(new(pai68k,op_const_reg(A_CMP,S_W,
  1600. setparts[i].start,p^.left^.location.register)));
  1601. else
  1602. exprasmlist^.concat(new(pai68k,op_const_reg(A_CMP,S_W,
  1603. setparts[i].start,R_D0)));
  1604. { exprasmlist^.concat(new(pai68k,op_const_ref(A_CMP,S_B,
  1605. setparts[i].start,newreference(p^.left^.location.reference)))); }
  1606. end;
  1607. {If lower, jump to next check.}
  1608. emitl(A_BCS,l2);
  1609. end;
  1610. if setparts[i].stop<>255 then
  1611. begin
  1612. {We only check for the high bound if it is < 255, because
  1613. set elements higher than 255 do nt exist.}
  1614. case p^.left^.location.loc of
  1615. LOC_REGISTER,
  1616. LOC_CREGISTER :
  1617. exprasmlist^.concat(new(pai68k,op_const_reg(A_CMP,S_W,
  1618. setparts[i].stop+1,p^.left^.location.register)));
  1619. else
  1620. exprasmlist^.concat(new(pai68k,op_const_reg(A_CMP,S_W,
  1621. setparts[i].stop+1,R_D0)));
  1622. { exprasmlist^.concat(new(pai68k,op_const_ref(A_CMP,S_B,
  1623. setparts[i].stop+1,newreference(p^.left^.location.reference))));}
  1624. end; { end case }
  1625. {If higher, element is in set.}
  1626. emitl(A_BCS,l);
  1627. end;
  1628. end;
  1629. {Emit the jump over label.}
  1630. exprasmlist^.concat(new(pai_label,init(l2)));
  1631. end
  1632. else
  1633. begin
  1634. {Emit code to check if left is an element.}
  1635. case p^.left^.location.loc of
  1636. LOC_REGISTER,
  1637. LOC_CREGISTER :
  1638. exprasmlist^.concat(new(pai68k,op_const_reg(A_CMP,S_W,
  1639. setparts[i].stop,p^.left^.location.register)));
  1640. else
  1641. { exprasmlist^.concat(new(pai68k,op_const_ref(A_CMP,S_B,
  1642. setparts[i].stop,newreference(p^.left^.location.reference))));}
  1643. exprasmlist^.concat(new(pai68k,op_const_reg(A_CMP,S_W,
  1644. setparts[i].stop,R_D0)));
  1645. end;
  1646. {Result should be in carry flag when ranges are used.}
  1647. if ranges then
  1648. exprasmlist^.concat(new(pai68k, op_const_reg(A_OR,S_B,$01,R_CCR)));
  1649. {If found, jump to end.}
  1650. emitl(A_BEQ,l);
  1651. end;
  1652. if ranges then
  1653. { clear carry flag }
  1654. exprasmlist^.concat(new(pai68k,op_const_reg(A_AND,S_B,$FE,R_CCR)));
  1655. {To compensate for not doing a second pass.}
  1656. stringdispose(p^.right^.location.reference.symbol);
  1657. {Now place the end label.}
  1658. exprasmlist^.concat(new(pai_label,init(l)));
  1659. end
  1660. else
  1661. begin
  1662. { calculate both operators }
  1663. { the complex one first }
  1664. firstcomplex(p);
  1665. secondpass(p^.left);
  1666. set_location(p^.location,p^.left^.location);
  1667. { are too few registers free? }
  1668. pushed:=maybe_push(p^.right^.registers32,p);
  1669. secondpass(p^.right);
  1670. if pushed then restore(p);
  1671. { of course not commutative }
  1672. if p^.swaped then
  1673. swaptree(p);
  1674. { SET_IN_BYTE is an inline assembler procedure instead }
  1675. { of a normal procedure, which is *MUCH* faster }
  1676. { Parameters are passed by registers, and FLAGS are set }
  1677. { according to the result. }
  1678. { a0 = address of set }
  1679. { d0.b = value to compare with }
  1680. { CARRY SET IF FOUND ON EXIT }
  1681. loadsetelement(p^.left);
  1682. exprasmlist^.concat(new(pai68k,op_ref_reg(A_LEA,S_L,
  1683. newreference(p^.right^.location.reference),R_A0)));;
  1684. { emitpushreferenceaddr(p^.right^.location.reference);}
  1685. del_reference(p^.right^.location.reference);
  1686. emitcall('SET_IN_BYTE',true);
  1687. { ungetiftemp(p^.right^.location.reference); }
  1688. p^.location.loc:=LOC_FLAGS;
  1689. p^.location.resflags:=F_C;
  1690. end;
  1691. end;
  1692. end;
  1693. end;
  1694. procedure secondexpr(var p : ptree);
  1695. begin
  1696. secondpass(p^.left);
  1697. end;
  1698. procedure secondblockn(var p : ptree);
  1699. var
  1700. hp : ptree;
  1701. begin
  1702. hp:=p^.left;
  1703. while assigned(hp) do
  1704. begin
  1705. { assignments could be distance optimized }
  1706. if assigned(hp^.right) then
  1707. begin
  1708. cleartempgen;
  1709. secondpass(hp^.right);
  1710. end;
  1711. hp:=hp^.left;
  1712. end;
  1713. end;
  1714. procedure second_while_repeatn(var p : ptree);
  1715. var
  1716. l1,l2,l3,oldclabel,oldblabel : plabel;
  1717. otlabel,oflabel : plabel;
  1718. begin
  1719. getlabel(l1);
  1720. getlabel(l2);
  1721. { arrange continue and breaklabels: }
  1722. oldclabel:=aktcontinuelabel;
  1723. oldblabel:=aktbreaklabel;
  1724. if p^.treetype=repeatn then
  1725. begin
  1726. emitl(A_LABEL,l1);
  1727. aktcontinuelabel:=l1;
  1728. aktbreaklabel:=l2;
  1729. cleartempgen;
  1730. if assigned(p^.right) then
  1731. secondpass(p^.right);
  1732. otlabel:=truelabel;
  1733. oflabel:=falselabel;
  1734. truelabel:=l2;
  1735. falselabel:=l1;
  1736. cleartempgen;
  1737. secondpass(p^.left);
  1738. maketojumpbool(p^.left);
  1739. emitl(A_LABEL,l2);
  1740. truelabel:=otlabel;
  1741. falselabel:=oflabel;
  1742. end
  1743. else
  1744. begin
  1745. { handling code at the end as it is much more efficient }
  1746. emitl(A_JMP,l2);
  1747. emitl(A_LABEL,l1);
  1748. cleartempgen;
  1749. getlabel(l3);
  1750. aktcontinuelabel:=l1;
  1751. aktbreaklabel:=l3;
  1752. if assigned(p^.right) then
  1753. secondpass(p^.right);
  1754. emitl(A_LABEL,l2);
  1755. otlabel:=truelabel;
  1756. oflabel:=falselabel;
  1757. truelabel:=l1;
  1758. falselabel:=l3;
  1759. cleartempgen;
  1760. secondpass(p^.left);
  1761. maketojumpbool(p^.left);
  1762. emitl(A_LABEL,l3);
  1763. truelabel:=otlabel;
  1764. falselabel:=oflabel;
  1765. end;
  1766. aktcontinuelabel:=oldclabel;
  1767. aktbreaklabel:=oldblabel;
  1768. end;
  1769. procedure secondifn(var p : ptree);
  1770. var
  1771. hl,otlabel,oflabel : plabel;
  1772. begin
  1773. otlabel:=truelabel;
  1774. oflabel:=falselabel;
  1775. getlabel(truelabel);
  1776. getlabel(falselabel);
  1777. cleartempgen;
  1778. secondpass(p^.left);
  1779. maketojumpbool(p^.left);
  1780. if assigned(p^.right) then
  1781. begin
  1782. emitl(A_LABEL,truelabel);
  1783. cleartempgen;
  1784. secondpass(p^.right);
  1785. end;
  1786. if assigned(p^.t1) then
  1787. begin
  1788. if assigned(p^.right) then
  1789. begin
  1790. getlabel(hl);
  1791. emitl(A_JMP,hl);
  1792. end;
  1793. emitl(A_LABEL,falselabel);
  1794. cleartempgen;
  1795. secondpass(p^.t1);
  1796. if assigned(p^.right) then
  1797. emitl(A_LABEL,hl);
  1798. end
  1799. else
  1800. emitl(A_LABEL,falselabel);
  1801. if not(assigned(p^.right)) then
  1802. emitl(A_LABEL,truelabel);
  1803. truelabel:=otlabel;
  1804. falselabel:=oflabel;
  1805. end;
  1806. procedure secondbreakn(var p : ptree);
  1807. begin
  1808. if aktbreaklabel<>nil then
  1809. emitl(A_JMP,aktbreaklabel)
  1810. else
  1811. Message(cg_e_break_not_allowed);
  1812. end;
  1813. end.
  1814. {
  1815. $Log$
  1816. Revision 1.7 1998-08-10 14:43:17 peter
  1817. * string type st_ fixed
  1818. Revision 1.6 1998/07/10 10:51:00 peter
  1819. * m68k updates
  1820. Revision 1.5 1998/06/08 13:13:37 pierre
  1821. + temporary variables now in temp_gen.pas unit
  1822. because it is processor independent
  1823. * mppc68k.bat modified to undefine i386 and support_mmx
  1824. (which are defaults for i386)
  1825. Revision 1.4 1998/06/04 23:51:35 peter
  1826. * m68k compiles
  1827. + .def file creation moved to gendef.pas so it could also be used
  1828. for win32
  1829. Revision 1.3 1998/04/29 10:33:45 pierre
  1830. + added some code for ansistring (not complete nor working yet)
  1831. * corrected operator overloading
  1832. * corrected nasm output
  1833. + started inline procedures
  1834. + added starstarn : use ** for exponentiation (^ gave problems)
  1835. + started UseTokenInfo cond to get accurate positions
  1836. }