cg68k2.pas 91 KB

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