nadd.pas 75 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951
  1. {
  2. $Id$
  3. Copyright (c) 1998-2002 by Florian Klaempfl
  4. Type checking and register allocation for add nodes
  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. unit nadd;
  19. {$i fpcdefs.inc}
  20. interface
  21. uses
  22. node;
  23. type
  24. taddnode = class(tbinopnode)
  25. constructor create(tt : tnodetype;l,r : tnode);override;
  26. function pass_1 : tnode;override;
  27. function det_resulttype:tnode;override;
  28. {$ifdef state_tracking}
  29. function track_state_pass(exec_known:boolean):boolean;override;
  30. {$endif}
  31. protected
  32. { override the following if you want to implement }
  33. { parts explicitely in the code generator (JM) }
  34. function first_addstring: tnode; virtual;
  35. function first_addset: tnode; virtual;
  36. { only implements "muln" nodes, the rest always has to be done in }
  37. { the code generator for performance reasons (JM) }
  38. function first_add64bitint: tnode; virtual;
  39. { This routine calls internal runtime library helpers
  40. for all floating point arithmetic in the case
  41. where the emulation switches is on. Otherwise
  42. returns nil, and everything must be done in
  43. the code generation phase.
  44. }
  45. function first_addfloat : tnode; virtual;
  46. end;
  47. taddnodeclass = class of taddnode;
  48. var
  49. { caddnode is used to create nodes of the add type }
  50. { the virtual constructor allows to assign }
  51. { another class type to caddnode => processor }
  52. { specific node types can be created }
  53. caddnode : taddnodeclass;
  54. implementation
  55. uses
  56. globtype,systems,
  57. cutils,verbose,globals,widestr,
  58. symconst,symtype,symdef,symsym,symtable,defbase,
  59. cgbase,
  60. htypechk,pass_1,
  61. nmat,ncnv,ncon,nset,nopt,ncal,ninl,
  62. {$ifdef state_tracking}
  63. nstate,
  64. {$endif}
  65. cpubase,cpuinfo;
  66. {*****************************************************************************
  67. TADDNODE
  68. *****************************************************************************}
  69. {$ifdef fpc}
  70. {$maxfpuregisters 0}
  71. {$endif fpc}
  72. constructor taddnode.create(tt : tnodetype;l,r : tnode);
  73. begin
  74. inherited create(tt,l,r);
  75. end;
  76. function taddnode.det_resulttype:tnode;
  77. var
  78. hp,t : tnode;
  79. lt,rt : tnodetype;
  80. rd,ld : tdef;
  81. htype : ttype;
  82. ot : tnodetype;
  83. concatstrings : boolean;
  84. resultset : Tconstset;
  85. i : longint;
  86. b : boolean;
  87. s1,s2 : pchar;
  88. ws1,ws2 : pcompilerwidestring;
  89. l1,l2 : longint;
  90. rv,lv : tconstexprint;
  91. rvd,lvd : bestreal;
  92. {$ifdef state_tracking}
  93. factval : Tnode;
  94. change : boolean;
  95. {$endif}
  96. begin
  97. result:=nil;
  98. { first do the two subtrees }
  99. resulttypepass(left);
  100. resulttypepass(right);
  101. { both left and right need to be valid }
  102. set_varstate(left,true);
  103. set_varstate(right,true);
  104. if codegenerror then
  105. exit;
  106. { convert array constructors to sets, because there is no other operator
  107. possible for array constructors }
  108. if is_array_constructor(left.resulttype.def) then
  109. begin
  110. arrayconstructor_to_set(left);
  111. resulttypepass(left);
  112. end;
  113. if is_array_constructor(right.resulttype.def) then
  114. begin
  115. arrayconstructor_to_set(right);
  116. resulttypepass(right);
  117. end;
  118. { allow operator overloading }
  119. hp:=self;
  120. if isbinaryoverloaded(hp) then
  121. begin
  122. result:=hp;
  123. exit;
  124. end;
  125. { Kylix allows enum+ordconstn in an enum declaration (blocktype
  126. is bt_type), we need to do the conversion here before the
  127. constant folding }
  128. if (m_delphi in aktmodeswitches) and
  129. (blocktype=bt_type) then
  130. begin
  131. if (left.resulttype.def.deftype=enumdef) and
  132. (right.resulttype.def.deftype=orddef) then
  133. begin
  134. { insert explicit typecast to s32bit }
  135. left:=ctypeconvnode.create(left,s32bittype);
  136. left.toggleflag(nf_explizit);
  137. resulttypepass(left);
  138. end
  139. else
  140. if (left.resulttype.def.deftype=orddef) and
  141. (right.resulttype.def.deftype=enumdef) then
  142. begin
  143. { insert explicit typecast to s32bit }
  144. right:=ctypeconvnode.create(right,s32bittype);
  145. include(right.flags,nf_explizit);
  146. resulttypepass(right);
  147. end;
  148. end;
  149. { is one a real float, then both need to be floats, this
  150. need to be done before the constant folding so constant
  151. operation on a float and int are also handled }
  152. if (right.resulttype.def.deftype=floatdef) or (left.resulttype.def.deftype=floatdef) then
  153. begin
  154. inserttypeconv(right,pbestrealtype^);
  155. inserttypeconv(left,pbestrealtype^);
  156. end;
  157. { if one operand is a widechar or a widestring, both operands }
  158. { are converted to widestring. This must be done before constant }
  159. { folding to allow char+widechar etc. }
  160. if is_widestring(right.resulttype.def) or
  161. is_widestring(left.resulttype.def) or
  162. is_widechar(right.resulttype.def) or
  163. is_widechar(left.resulttype.def) then
  164. begin
  165. inserttypeconv(right,cwidestringtype);
  166. inserttypeconv(left,cwidestringtype);
  167. end;
  168. { load easier access variables }
  169. rd:=right.resulttype.def;
  170. ld:=left.resulttype.def;
  171. rt:=right.nodetype;
  172. lt:=left.nodetype;
  173. if (nodetype = slashn) and
  174. (((rt = ordconstn) and
  175. (tordconstnode(right).value = 0)) or
  176. ((rt = realconstn) and
  177. (trealconstnode(right).value_real = 0.0))) then
  178. begin
  179. Message(parser_e_division_by_zero);
  180. case rt of
  181. ordconstn:
  182. tordconstnode(right).value := 1;
  183. realconstn:
  184. trealconstnode(right).value_real := 1.0;
  185. end;
  186. end;
  187. { both are int constants }
  188. if (((is_constintnode(left) and is_constintnode(right)) or
  189. (is_constboolnode(left) and is_constboolnode(right) and
  190. (nodetype in [slashn,ltn,lten,gtn,gten,equaln,unequaln,andn,xorn,orn])))) or
  191. { support pointer arithmetics on constants (JM) }
  192. ((lt = pointerconstn) and is_constintnode(right) and
  193. (nodetype in [addn,subn])) or
  194. (((lt = pointerconstn) or (lt = niln)) and
  195. ((rt = pointerconstn) or (rt = niln)) and
  196. (nodetype in [ltn,lten,gtn,gten,equaln,unequaln,subn])) then
  197. begin
  198. { when comparing/substracting pointers, make sure they are }
  199. { of the same type (JM) }
  200. if (lt = pointerconstn) and (rt = pointerconstn) then
  201. begin
  202. if not(cs_extsyntax in aktmoduleswitches) and
  203. not(nodetype in [equaln,unequaln]) then
  204. CGMessage(type_e_mismatch)
  205. else
  206. if (nodetype <> subn) and
  207. is_voidpointer(rd) then
  208. inserttypeconv(right,left.resulttype)
  209. else if (nodetype <> subn) and
  210. is_voidpointer(ld) then
  211. inserttypeconv(left,right.resulttype)
  212. else if not(is_equal(ld,rd)) then
  213. CGMessage(type_e_mismatch);
  214. end
  215. else if (lt=ordconstn) and (rt=ordconstn) then
  216. begin
  217. { make left const type the biggest (u32bit is bigger than
  218. s32bit for or,and,xor) }
  219. if (rd.size>ld.size) or
  220. ((torddef(rd).typ=u32bit) and
  221. (torddef(ld).typ=s32bit) and
  222. (nodetype in [orn,andn,xorn])) then
  223. inserttypeconv(left,right.resulttype);
  224. end;
  225. { load values }
  226. case lt of
  227. ordconstn:
  228. lv:=tordconstnode(left).value;
  229. pointerconstn:
  230. lv:=tpointerconstnode(left).value;
  231. niln:
  232. lv:=0;
  233. else
  234. internalerror(2002080202);
  235. end;
  236. case rt of
  237. ordconstn:
  238. rv:=tordconstnode(right).value;
  239. pointerconstn:
  240. rv:=tpointerconstnode(right).value;
  241. niln:
  242. rv:=0;
  243. else
  244. internalerror(2002080203);
  245. end;
  246. if (lt = pointerconstn) and
  247. (rt <> pointerconstn) then
  248. rv := rv * tpointerdef(left.resulttype.def).pointertype.def.size;
  249. if (rt = pointerconstn) and
  250. (lt <> pointerconstn) then
  251. lv := lv * tpointerdef(right.resulttype.def).pointertype.def.size;
  252. case nodetype of
  253. addn :
  254. if (lt <> pointerconstn) then
  255. t := genintconstnode(lv+rv)
  256. else
  257. t := cpointerconstnode.create(lv+rv,left.resulttype);
  258. subn :
  259. if (lt <> pointerconstn) or (rt = pointerconstn) then
  260. t := genintconstnode(lv-rv)
  261. else
  262. t := cpointerconstnode.create(lv-rv,left.resulttype);
  263. muln :
  264. t:=genintconstnode(lv*rv);
  265. xorn :
  266. t:=cordconstnode.create(lv xor rv,left.resulttype,true);
  267. orn :
  268. t:=cordconstnode.create(lv or rv,left.resulttype,true);
  269. andn :
  270. t:=cordconstnode.create(lv and rv,left.resulttype,true);
  271. ltn :
  272. t:=cordconstnode.create(ord(lv<rv),booltype,true);
  273. lten :
  274. t:=cordconstnode.create(ord(lv<=rv),booltype,true);
  275. gtn :
  276. t:=cordconstnode.create(ord(lv>rv),booltype,true);
  277. gten :
  278. t:=cordconstnode.create(ord(lv>=rv),booltype,true);
  279. equaln :
  280. t:=cordconstnode.create(ord(lv=rv),booltype,true);
  281. unequaln :
  282. t:=cordconstnode.create(ord(lv<>rv),booltype,true);
  283. slashn :
  284. begin
  285. { int/int becomes a real }
  286. rvd:=rv;
  287. lvd:=lv;
  288. t:=crealconstnode.create(lvd/rvd,pbestrealtype^);
  289. end;
  290. else
  291. CGMessage(type_e_mismatch);
  292. end;
  293. result:=t;
  294. exit;
  295. end;
  296. { both real constants ? }
  297. if (lt=realconstn) and (rt=realconstn) then
  298. begin
  299. lvd:=trealconstnode(left).value_real;
  300. rvd:=trealconstnode(right).value_real;
  301. case nodetype of
  302. addn :
  303. t:=crealconstnode.create(lvd+rvd,pbestrealtype^);
  304. subn :
  305. t:=crealconstnode.create(lvd-rvd,pbestrealtype^);
  306. muln :
  307. t:=crealconstnode.create(lvd*rvd,pbestrealtype^);
  308. starstarn,
  309. caretn :
  310. begin
  311. if lvd<0 then
  312. begin
  313. Message(parser_e_invalid_float_operation);
  314. t:=crealconstnode.create(0,pbestrealtype^);
  315. end
  316. else if lvd=0 then
  317. t:=crealconstnode.create(1.0,pbestrealtype^)
  318. else
  319. t:=crealconstnode.create(exp(ln(lvd)*rvd),pbestrealtype^);
  320. end;
  321. slashn :
  322. begin
  323. t:=crealconstnode.create(lvd/rvd,pbestrealtype^);
  324. end;
  325. ltn :
  326. t:=cordconstnode.create(ord(lvd<rvd),booltype,true);
  327. lten :
  328. t:=cordconstnode.create(ord(lvd<=rvd),booltype,true);
  329. gtn :
  330. t:=cordconstnode.create(ord(lvd>rvd),booltype,true);
  331. gten :
  332. t:=cordconstnode.create(ord(lvd>=rvd),booltype,true);
  333. equaln :
  334. t:=cordconstnode.create(ord(lvd=rvd),booltype,true);
  335. unequaln :
  336. t:=cordconstnode.create(ord(lvd<>rvd),booltype,true);
  337. else
  338. CGMessage(type_e_mismatch);
  339. end;
  340. result:=t;
  341. exit;
  342. end;
  343. { first, we handle widestrings, so we can check later for }
  344. { stringconstn only }
  345. { widechars are converted above to widestrings too }
  346. { this isn't veryy efficient, but I don't think }
  347. { that it does matter that much (FK) }
  348. if (lt=stringconstn) and (rt=stringconstn) and
  349. (tstringconstnode(left).st_type=st_widestring) and
  350. (tstringconstnode(right).st_type=st_widestring) then
  351. begin
  352. initwidestring(ws1);
  353. initwidestring(ws2);
  354. copywidestring(pcompilerwidestring(tstringconstnode(left).value_str),ws1);
  355. copywidestring(pcompilerwidestring(tstringconstnode(right).value_str),ws2);
  356. case nodetype of
  357. addn :
  358. begin
  359. concatwidestrings(ws1,ws2);
  360. t:=cstringconstnode.createwstr(ws1);
  361. end;
  362. ltn :
  363. t:=cordconstnode.create(byte(comparewidestrings(ws1,ws2)<0),booltype,true);
  364. lten :
  365. t:=cordconstnode.create(byte(comparewidestrings(ws1,ws2)<=0),booltype,true);
  366. gtn :
  367. t:=cordconstnode.create(byte(comparewidestrings(ws1,ws2)>0),booltype,true);
  368. gten :
  369. t:=cordconstnode.create(byte(comparewidestrings(ws1,ws2)>=0),booltype,true);
  370. equaln :
  371. t:=cordconstnode.create(byte(comparewidestrings(ws1,ws2)=0),booltype,true);
  372. unequaln :
  373. t:=cordconstnode.create(byte(comparewidestrings(ws1,ws2)<>0),booltype,true);
  374. end;
  375. donewidestring(ws1);
  376. donewidestring(ws2);
  377. result:=t;
  378. exit;
  379. end;
  380. { concating strings ? }
  381. concatstrings:=false;
  382. s1:=nil;
  383. s2:=nil;
  384. if (lt=ordconstn) and (rt=ordconstn) and
  385. is_char(ld) and is_char(rd) then
  386. begin
  387. s1:=strpnew(char(byte(tordconstnode(left).value)));
  388. s2:=strpnew(char(byte(tordconstnode(right).value)));
  389. l1:=1;
  390. l2:=1;
  391. concatstrings:=true;
  392. end
  393. else
  394. if (lt=stringconstn) and (rt=ordconstn) and is_char(rd) then
  395. begin
  396. s1:=tstringconstnode(left).getpcharcopy;
  397. l1:=tstringconstnode(left).len;
  398. s2:=strpnew(char(byte(tordconstnode(right).value)));
  399. l2:=1;
  400. concatstrings:=true;
  401. end
  402. else
  403. if (lt=ordconstn) and (rt=stringconstn) and is_char(ld) then
  404. begin
  405. s1:=strpnew(char(byte(tordconstnode(left).value)));
  406. l1:=1;
  407. s2:=tstringconstnode(right).getpcharcopy;
  408. l2:=tstringconstnode(right).len;
  409. concatstrings:=true;
  410. end
  411. else if (lt=stringconstn) and (rt=stringconstn) then
  412. begin
  413. s1:=tstringconstnode(left).getpcharcopy;
  414. l1:=tstringconstnode(left).len;
  415. s2:=tstringconstnode(right).getpcharcopy;
  416. l2:=tstringconstnode(right).len;
  417. concatstrings:=true;
  418. end;
  419. if concatstrings then
  420. begin
  421. case nodetype of
  422. addn :
  423. t:=cstringconstnode.createpchar(concatansistrings(s1,s2,l1,l2),l1+l2);
  424. ltn :
  425. t:=cordconstnode.create(byte(compareansistrings(s1,s2,l1,l2)<0),booltype,true);
  426. lten :
  427. t:=cordconstnode.create(byte(compareansistrings(s1,s2,l1,l2)<=0),booltype,true);
  428. gtn :
  429. t:=cordconstnode.create(byte(compareansistrings(s1,s2,l1,l2)>0),booltype,true);
  430. gten :
  431. t:=cordconstnode.create(byte(compareansistrings(s1,s2,l1,l2)>=0),booltype,true);
  432. equaln :
  433. t:=cordconstnode.create(byte(compareansistrings(s1,s2,l1,l2)=0),booltype,true);
  434. unequaln :
  435. t:=cordconstnode.create(byte(compareansistrings(s1,s2,l1,l2)<>0),booltype,true);
  436. end;
  437. ansistringdispose(s1,l1);
  438. ansistringdispose(s2,l2);
  439. result:=t;
  440. exit;
  441. end;
  442. { set constant evaluation }
  443. if (right.nodetype=setconstn) and
  444. not assigned(tsetconstnode(right).left) and
  445. (left.nodetype=setconstn) and
  446. not assigned(tsetconstnode(left).left) then
  447. begin
  448. { check if size adjusting is needed, only for left
  449. to right as the other way is checked in the typeconv }
  450. if (tsetdef(right.resulttype.def).settype=smallset) and
  451. (tsetdef(left.resulttype.def).settype<>smallset) then
  452. tsetdef(right.resulttype.def).changesettype(normset);
  453. { check base types }
  454. inserttypeconv(left,right.resulttype);
  455. if codegenerror then
  456. begin
  457. { recover by only returning the left part }
  458. result:=left;
  459. left:=nil;
  460. exit;
  461. end;
  462. {$ifdef oldset}
  463. case nodetype of
  464. addn :
  465. begin
  466. for i:=0 to 31 do
  467. resultset[i]:=tsetconstnode(right).value_set^[i] or tsetconstnode(left).value_set^[i];
  468. t:=csetconstnode.create(@resultset,left.resulttype);
  469. end;
  470. muln :
  471. begin
  472. for i:=0 to 31 do
  473. resultset[i]:=tsetconstnode(right).value_set^[i] and tsetconstnode(left).value_set^[i];
  474. t:=csetconstnode.create(@resultset,left.resulttype);
  475. end;
  476. subn :
  477. begin
  478. for i:=0 to 31 do
  479. resultset[i]:=tsetconstnode(left).value_set^[i] and not(tsetconstnode(right).value_set^[i]);
  480. t:=csetconstnode.create(@resultset,left.resulttype);
  481. end;
  482. symdifn :
  483. begin
  484. for i:=0 to 31 do
  485. resultset[i]:=tsetconstnode(left).value_set^[i] xor tsetconstnode(right).value_set^[i];
  486. t:=csetconstnode.create(@resultset,left.resulttype);
  487. end;
  488. unequaln :
  489. begin
  490. b:=true;
  491. for i:=0 to 31 do
  492. if tsetconstnode(right).value_set^[i]=tsetconstnode(left).value_set^[i] then
  493. begin
  494. b:=false;
  495. break;
  496. end;
  497. t:=cordconstnode.create(ord(b),booltype,true);
  498. end;
  499. equaln :
  500. begin
  501. b:=true;
  502. for i:=0 to 31 do
  503. if tsetconstnode(right).value_set^[i]<>tsetconstnode(left).value_set^[i] then
  504. begin
  505. b:=false;
  506. break;
  507. end;
  508. t:=cordconstnode.create(ord(b),booltype,true);
  509. end;
  510. lten :
  511. begin
  512. b := true;
  513. for i := 0 to 31 Do
  514. if (tsetconstnode(right).value_set^[i] And tsetconstnode(left).value_set^[i]) <>
  515. tsetconstnode(left).value_set^[i] Then
  516. begin
  517. b := false;
  518. break
  519. end;
  520. t := cordconstnode.create(ord(b),booltype,true);
  521. end;
  522. gten :
  523. begin
  524. b := true;
  525. for i := 0 to 31 Do
  526. If (tsetconstnode(left).value_set^[i] And tsetconstnode(right).value_set^[i]) <>
  527. tsetconstnode(right).value_set^[i] Then
  528. begin
  529. b := false;
  530. break
  531. end;
  532. t := cordconstnode.create(ord(b),booltype,true);
  533. end;
  534. end;
  535. {$else}
  536. case nodetype of
  537. addn :
  538. begin
  539. resultset:=tsetconstnode(right).value_set^ + tsetconstnode(left).value_set^;
  540. t:=csetconstnode.create(@resultset,left.resulttype);
  541. end;
  542. muln :
  543. begin
  544. resultset:=tsetconstnode(right).value_set^ * tsetconstnode(left).value_set^;
  545. t:=csetconstnode.create(@resultset,left.resulttype);
  546. end;
  547. subn :
  548. begin
  549. resultset:=tsetconstnode(left).value_set^ - tsetconstnode(right).value_set^;
  550. t:=csetconstnode.create(@resultset,left.resulttype);
  551. end;
  552. symdifn :
  553. begin
  554. resultset:=tsetconstnode(right).value_set^ >< tsetconstnode(left).value_set^;
  555. t:=csetconstnode.create(@resultset,left.resulttype);
  556. end;
  557. unequaln :
  558. begin
  559. b:=tsetconstnode(right).value_set^ <> tsetconstnode(left).value_set^;
  560. t:=cordconstnode.create(byte(b),booltype,true);
  561. end;
  562. equaln :
  563. begin
  564. b:=tsetconstnode(right).value_set^ = tsetconstnode(left).value_set^;
  565. t:=cordconstnode.create(byte(b),booltype,true);
  566. end;
  567. lten :
  568. begin
  569. b:=tsetconstnode(left).value_set^ <= tsetconstnode(right).value_set^;
  570. t:=cordconstnode.create(byte(b),booltype,true);
  571. end;
  572. gten :
  573. begin
  574. b:=tsetconstnode(left).value_set^ >= tsetconstnode(right).value_set^;
  575. t:=cordconstnode.create(byte(b),booltype,true);
  576. end;
  577. end;
  578. {$endif}
  579. result:=t;
  580. exit;
  581. end;
  582. { but an int/int gives real/real! }
  583. if nodetype=slashn then
  584. begin
  585. CGMessage(type_h_use_div_for_int);
  586. inserttypeconv(right,pbestrealtype^);
  587. inserttypeconv(left,pbestrealtype^);
  588. end
  589. { if both are orddefs then check sub types }
  590. else if (ld.deftype=orddef) and (rd.deftype=orddef) then
  591. begin
  592. { optimize multiplacation by a power of 2 }
  593. if not(cs_check_overflow in aktlocalswitches) and
  594. (nodetype = muln) and
  595. (((left.nodetype = ordconstn) and
  596. ispowerof2(tordconstnode(left).value,i)) or
  597. ((right.nodetype = ordconstn) and
  598. ispowerof2(tordconstnode(right).value,i))) then
  599. begin
  600. if left.nodetype = ordconstn then
  601. begin
  602. tordconstnode(left).value := i;
  603. result := cshlshrnode.create(shln,right,left);
  604. end
  605. else
  606. begin
  607. tordconstnode(right).value := i;
  608. result := cshlshrnode.create(shln,left,right);
  609. end;
  610. left := nil;
  611. right := nil;
  612. exit;
  613. end;
  614. { 2 booleans? Make them equal to the largest boolean }
  615. if is_boolean(ld) and is_boolean(rd) then
  616. begin
  617. if torddef(left.resulttype.def).size>torddef(right.resulttype.def).size then
  618. begin
  619. right:=ctypeconvnode.create(right,left.resulttype);
  620. ttypeconvnode(right).convtype:=tc_bool_2_int;
  621. right.toggleflag(nf_explizit);
  622. resulttypepass(right);
  623. end
  624. else if torddef(left.resulttype.def).size<torddef(right.resulttype.def).size then
  625. begin
  626. left:=ctypeconvnode.create(left,right.resulttype);
  627. ttypeconvnode(left).convtype:=tc_bool_2_int;
  628. left.toggleflag(nf_explizit);
  629. resulttypepass(left);
  630. end;
  631. case nodetype of
  632. xorn,
  633. ltn,
  634. lten,
  635. gtn,
  636. gten,
  637. andn,
  638. orn:
  639. begin
  640. end;
  641. unequaln,
  642. equaln:
  643. begin
  644. if not(cs_full_boolean_eval in aktlocalswitches) then
  645. begin
  646. { Remove any compares with constants }
  647. if (left.nodetype=ordconstn) then
  648. begin
  649. hp:=right;
  650. b:=(tordconstnode(left).value<>0);
  651. ot:=nodetype;
  652. left.free;
  653. left:=nil;
  654. right:=nil;
  655. if (not(b) and (ot=equaln)) or
  656. (b and (ot=unequaln)) then
  657. begin
  658. hp:=cnotnode.create(hp);
  659. end;
  660. result:=hp;
  661. exit;
  662. end;
  663. if (right.nodetype=ordconstn) then
  664. begin
  665. hp:=left;
  666. b:=(tordconstnode(right).value<>0);
  667. ot:=nodetype;
  668. right.free;
  669. right:=nil;
  670. left:=nil;
  671. if (not(b) and (ot=equaln)) or
  672. (b and (ot=unequaln)) then
  673. begin
  674. hp:=cnotnode.create(hp);
  675. end;
  676. result:=hp;
  677. exit;
  678. end;
  679. end;
  680. end;
  681. else
  682. CGMessage(type_e_mismatch);
  683. end;
  684. end
  685. { Both are chars? }
  686. else if is_char(rd) and is_char(ld) then
  687. begin
  688. if nodetype=addn then
  689. begin
  690. resulttype:=cshortstringtype;
  691. if not(is_constcharnode(left) and is_constcharnode(right)) then
  692. begin
  693. inserttypeconv(left,cshortstringtype);
  694. hp := genaddsstringcharoptnode(self);
  695. result := hp;
  696. exit;
  697. end;
  698. end;
  699. end
  700. { is there a signed 64 bit type ? }
  701. else if ((torddef(rd).typ=s64bit) or (torddef(ld).typ=s64bit)) then
  702. begin
  703. if (torddef(ld).typ<>s64bit) then
  704. inserttypeconv(left,cs64bittype);
  705. if (torddef(rd).typ<>s64bit) then
  706. inserttypeconv(right,cs64bittype);
  707. end
  708. { is there a unsigned 64 bit type ? }
  709. else if ((torddef(rd).typ=u64bit) or (torddef(ld).typ=u64bit)) then
  710. begin
  711. if (torddef(ld).typ<>u64bit) then
  712. inserttypeconv(left,cu64bittype);
  713. if (torddef(rd).typ<>u64bit) then
  714. inserttypeconv(right,cu64bittype);
  715. end
  716. { is there a cardinal? }
  717. else if ((torddef(rd).typ=u32bit) or (torddef(ld).typ=u32bit)) then
  718. begin
  719. if is_signed(ld) and
  720. { then rd = u32bit }
  721. { convert positive constants to u32bit }
  722. not(is_constintnode(left) and
  723. (tordconstnode(left).value >= 0)) and
  724. { range/overflow checking on mixed signed/cardinal expressions }
  725. { is only possible if you convert everything to 64bit (JM) }
  726. ((aktlocalswitches * [cs_check_overflow,cs_check_range] <> []) and
  727. (nodetype in [addn,subn,muln])) then
  728. begin
  729. { perform the operation in 64bit }
  730. CGMessage(type_w_mixed_signed_unsigned);
  731. inserttypeconv(left,cs64bittype);
  732. inserttypeconv(right,cs64bittype);
  733. end
  734. else
  735. begin
  736. { and,or,xor work on bit patterns and don't care
  737. about the sign }
  738. if nodetype in [andn,orn,xorn] then
  739. inserttypeconv_explicit(left,u32bittype)
  740. else
  741. begin
  742. if is_signed(ld) and
  743. not(is_constintnode(left) and
  744. (tordconstnode(left).value >= 0)) and
  745. (cs_check_range in aktlocalswitches) then
  746. CGMessage(type_w_mixed_signed_unsigned2);
  747. inserttypeconv(left,u32bittype);
  748. end;
  749. if is_signed(rd) and
  750. { then ld = u32bit }
  751. { convert positive constants to u32bit }
  752. not(is_constintnode(right) and
  753. (tordconstnode(right).value >= 0)) and
  754. ((aktlocalswitches * [cs_check_overflow,cs_check_range] <> []) and
  755. (nodetype in [addn,subn,muln])) then
  756. begin
  757. { perform the operation in 64bit }
  758. CGMessage(type_w_mixed_signed_unsigned);
  759. inserttypeconv(left,cs64bittype);
  760. inserttypeconv(right,cs64bittype);
  761. end
  762. else
  763. begin
  764. { and,or,xor work on bit patterns and don't care
  765. about the sign }
  766. if nodetype in [andn,orn,xorn] then
  767. inserttypeconv_explicit(left,u32bittype)
  768. else
  769. begin
  770. if is_signed(rd) and
  771. not(is_constintnode(right) and
  772. (tordconstnode(right).value >= 0)) and
  773. (cs_check_range in aktlocalswitches) then
  774. CGMessage(type_w_mixed_signed_unsigned2);
  775. inserttypeconv(right,u32bittype);
  776. end;
  777. end;
  778. end;
  779. end
  780. { generic ord conversion is s32bit }
  781. else
  782. begin
  783. inserttypeconv(right,s32bittype);
  784. inserttypeconv(left,s32bittype);
  785. end;
  786. end
  787. { if both are floatdefs, conversion is already done before constant folding }
  788. else if (ld.deftype=floatdef) then
  789. begin
  790. { already converted }
  791. end
  792. { left side a setdef, must be before string processing,
  793. else array constructor can be seen as array of char (PFV) }
  794. else if (ld.deftype=setdef) then
  795. begin
  796. { trying to add a set element? }
  797. if (nodetype=addn) and (rd.deftype<>setdef) then
  798. begin
  799. if (rt=setelementn) then
  800. begin
  801. if not(is_equal(tsetdef(ld).elementtype.def,rd)) then
  802. CGMessage(type_e_set_element_are_not_comp);
  803. end
  804. else
  805. CGMessage(type_e_mismatch)
  806. end
  807. else
  808. begin
  809. if not(nodetype in [addn,subn,symdifn,muln,equaln,unequaln,lten,gten]) then
  810. CGMessage(type_e_set_operation_unknown);
  811. { right def must be a also be set }
  812. if (rd.deftype<>setdef) or not(is_equal(rd,ld)) then
  813. CGMessage(type_e_set_element_are_not_comp);
  814. end;
  815. { ranges require normsets }
  816. if (tsetdef(ld).settype=smallset) and
  817. (rt=setelementn) and
  818. assigned(tsetelementnode(right).right) then
  819. begin
  820. { generate a temporary normset def, it'll be destroyed
  821. when the symtable is unloaded }
  822. htype.setdef(tsetdef.create(tsetdef(ld).elementtype,255));
  823. inserttypeconv(left,htype);
  824. end;
  825. { if the right side is also a setdef then the settype must
  826. be the same as the left setdef }
  827. if (rd.deftype=setdef) and
  828. (tsetdef(ld).settype<>tsetdef(rd).settype) then
  829. inserttypeconv(right,left.resulttype);
  830. end
  831. { compare pchar to char arrays by addresses like BP/Delphi }
  832. else if (is_pchar(ld) and is_chararray(rd)) or
  833. (is_pchar(rd) and is_chararray(ld)) then
  834. begin
  835. if is_chararray(rd) then
  836. inserttypeconv(right,left.resulttype)
  837. else
  838. inserttypeconv(left,right.resulttype);
  839. end
  840. { is one of the operands a string?,
  841. chararrays are also handled as strings (after conversion), also take
  842. care of chararray+chararray and chararray+char }
  843. else if (rd.deftype=stringdef) or (ld.deftype=stringdef) or
  844. ((is_chararray(rd) or is_char(rd)) and
  845. (is_chararray(ld) or is_char(ld))) then
  846. begin
  847. if is_widestring(rd) or is_widestring(ld) then
  848. begin
  849. if not(is_widestring(rd)) then
  850. inserttypeconv(right,cwidestringtype);
  851. if not(is_widestring(ld)) then
  852. inserttypeconv(left,cwidestringtype);
  853. end
  854. else if is_ansistring(rd) or is_ansistring(ld) then
  855. begin
  856. if not(is_ansistring(rd)) then
  857. inserttypeconv(right,cansistringtype);
  858. if not(is_ansistring(ld)) then
  859. inserttypeconv(left,cansistringtype);
  860. end
  861. else if is_longstring(rd) or is_longstring(ld) then
  862. begin
  863. if not(is_longstring(rd)) then
  864. inserttypeconv(right,clongstringtype);
  865. if not(is_longstring(ld)) then
  866. inserttypeconv(left,clongstringtype);
  867. location.loc:=LOC_CREFERENCE;
  868. end
  869. else
  870. begin
  871. if not(is_shortstring(ld)) then
  872. inserttypeconv(left,cshortstringtype);
  873. { don't convert char, that can be handled by the optimized node }
  874. if not(is_shortstring(rd) or is_char(rd)) then
  875. inserttypeconv(right,cshortstringtype);
  876. end;
  877. end
  878. { pointer comparision and subtraction }
  879. else if (rd.deftype=pointerdef) and (ld.deftype=pointerdef) then
  880. begin
  881. case nodetype of
  882. equaln,unequaln :
  883. begin
  884. if is_voidpointer(right.resulttype.def) then
  885. inserttypeconv(right,left.resulttype)
  886. else if is_voidpointer(left.resulttype.def) then
  887. inserttypeconv(left,right.resulttype)
  888. else if not(is_equal(ld,rd)) then
  889. CGMessage(type_e_mismatch);
  890. end;
  891. ltn,lten,gtn,gten:
  892. begin
  893. if (cs_extsyntax in aktmoduleswitches) then
  894. begin
  895. if is_voidpointer(right.resulttype.def) then
  896. inserttypeconv(right,left.resulttype)
  897. else if is_voidpointer(left.resulttype.def) then
  898. inserttypeconv(left,right.resulttype)
  899. else if not(is_equal(ld,rd)) then
  900. CGMessage(type_e_mismatch);
  901. end
  902. else
  903. CGMessage(type_e_mismatch);
  904. end;
  905. subn:
  906. begin
  907. if (cs_extsyntax in aktmoduleswitches) then
  908. begin
  909. if is_voidpointer(right.resulttype.def) then
  910. inserttypeconv(right,left.resulttype)
  911. else if is_voidpointer(left.resulttype.def) then
  912. inserttypeconv(left,right.resulttype)
  913. else if not(is_equal(ld,rd)) then
  914. CGMessage(type_e_mismatch);
  915. end
  916. else
  917. CGMessage(type_e_mismatch);
  918. resulttype:=s32bittype;
  919. exit;
  920. end;
  921. addn:
  922. begin
  923. if (cs_extsyntax in aktmoduleswitches) then
  924. begin
  925. if is_voidpointer(right.resulttype.def) then
  926. inserttypeconv(right,left.resulttype)
  927. else if is_voidpointer(left.resulttype.def) then
  928. inserttypeconv(left,right.resulttype)
  929. else if not(is_equal(ld,rd)) then
  930. CGMessage(type_e_mismatch);
  931. end
  932. else
  933. CGMessage(type_e_mismatch);
  934. resulttype:=s32bittype;
  935. exit;
  936. end;
  937. else
  938. CGMessage(type_e_mismatch);
  939. end;
  940. end
  941. { class or interface equation }
  942. else if is_class_or_interface(rd) or is_class_or_interface(ld) then
  943. begin
  944. if is_class_or_interface(rd) and is_class_or_interface(ld) then
  945. begin
  946. if tobjectdef(rd).is_related(tobjectdef(ld)) then
  947. inserttypeconv(right,left.resulttype)
  948. else
  949. inserttypeconv(left,right.resulttype);
  950. end
  951. else if is_class_or_interface(rd) then
  952. inserttypeconv(left,right.resulttype)
  953. else
  954. inserttypeconv(right,left.resulttype);
  955. if not(nodetype in [equaln,unequaln]) then
  956. CGMessage(type_e_mismatch);
  957. end
  958. else if (rd.deftype=classrefdef) and (ld.deftype=classrefdef) then
  959. begin
  960. if tobjectdef(tclassrefdef(rd).pointertype.def).is_related(
  961. tobjectdef(tclassrefdef(ld).pointertype.def)) then
  962. inserttypeconv(right,left.resulttype)
  963. else
  964. inserttypeconv(left,right.resulttype);
  965. if not(nodetype in [equaln,unequaln]) then
  966. CGMessage(type_e_mismatch);
  967. end
  968. { allows comperasion with nil pointer }
  969. else if is_class_or_interface(rd) or (rd.deftype=classrefdef) then
  970. begin
  971. inserttypeconv(left,right.resulttype);
  972. if not(nodetype in [equaln,unequaln]) then
  973. CGMessage(type_e_mismatch);
  974. end
  975. else if is_class_or_interface(ld) or (ld.deftype=classrefdef) then
  976. begin
  977. inserttypeconv(right,left.resulttype);
  978. if not(nodetype in [equaln,unequaln]) then
  979. CGMessage(type_e_mismatch);
  980. end
  981. { support procvar=nil,procvar<>nil }
  982. else if ((ld.deftype=procvardef) and (rt=niln)) or
  983. ((rd.deftype=procvardef) and (lt=niln)) then
  984. begin
  985. if not(nodetype in [equaln,unequaln]) then
  986. CGMessage(type_e_mismatch);
  987. end
  988. { support dynamicarray=nil,dynamicarray<>nil }
  989. else if (is_dynamic_array(ld) and (rt=niln)) or
  990. (is_dynamic_array(rd) and (lt=niln)) then
  991. begin
  992. if not(nodetype in [equaln,unequaln]) then
  993. CGMessage(type_e_mismatch);
  994. end
  995. {$ifdef SUPPORT_MMX}
  996. { mmx support, this must be before the zero based array
  997. check }
  998. else if (cs_mmx in aktlocalswitches) and
  999. is_mmx_able_array(ld) and
  1000. is_mmx_able_array(rd) and
  1001. is_equal(ld,rd) then
  1002. begin
  1003. case nodetype of
  1004. addn,subn,xorn,orn,andn:
  1005. ;
  1006. { mul is a little bit restricted }
  1007. muln:
  1008. if not(mmx_type(ld) in [mmxu16bit,mmxs16bit,mmxfixed16]) then
  1009. CGMessage(type_e_mismatch);
  1010. else
  1011. CGMessage(type_e_mismatch);
  1012. end;
  1013. end
  1014. {$endif SUPPORT_MMX}
  1015. { this is a little bit dangerous, also the left type }
  1016. { pointer to should be checked! This broke the mmx support }
  1017. else if (rd.deftype=pointerdef) or is_zero_based_array(rd) then
  1018. begin
  1019. if is_zero_based_array(rd) then
  1020. begin
  1021. resulttype.setdef(tpointerdef.create(tarraydef(rd).elementtype));
  1022. inserttypeconv(right,resulttype);
  1023. end;
  1024. inserttypeconv(left,s32bittype);
  1025. if nodetype=addn then
  1026. begin
  1027. if not(cs_extsyntax in aktmoduleswitches) or
  1028. (not(is_pchar(ld)) and not(m_add_pointer in aktmodeswitches)) then
  1029. CGMessage(type_e_mismatch);
  1030. if (rd.deftype=pointerdef) and
  1031. (tpointerdef(rd).pointertype.def.size>1) then
  1032. left:=caddnode.create(muln,left,
  1033. cordconstnode.create(tpointerdef(rd).pointertype.def.size,s32bittype,true));
  1034. end
  1035. else
  1036. CGMessage(type_e_mismatch);
  1037. end
  1038. else if (ld.deftype=pointerdef) or is_zero_based_array(ld) then
  1039. begin
  1040. if is_zero_based_array(ld) then
  1041. begin
  1042. resulttype.setdef(tpointerdef.create(tarraydef(ld).elementtype));
  1043. inserttypeconv(left,resulttype);
  1044. end;
  1045. inserttypeconv(right,s32bittype);
  1046. if nodetype in [addn,subn] then
  1047. begin
  1048. if not(cs_extsyntax in aktmoduleswitches) or
  1049. (not(is_pchar(ld)) and not(m_add_pointer in aktmodeswitches)) then
  1050. CGMessage(type_e_mismatch);
  1051. if (ld.deftype=pointerdef) and
  1052. (tpointerdef(ld).pointertype.def.size>1) then
  1053. right:=caddnode.create(muln,right,
  1054. cordconstnode.create(tpointerdef(ld).pointertype.def.size,s32bittype,true));
  1055. end
  1056. else
  1057. CGMessage(type_e_mismatch);
  1058. end
  1059. else if (rd.deftype=procvardef) and (ld.deftype=procvardef) and is_equal(rd,ld) then
  1060. begin
  1061. if not (nodetype in [equaln,unequaln]) then
  1062. CGMessage(type_e_mismatch);
  1063. end
  1064. { enums }
  1065. else if (ld.deftype=enumdef) and (rd.deftype=enumdef) then
  1066. begin
  1067. if not(is_equal(ld,rd)) then
  1068. inserttypeconv(right,left.resulttype);
  1069. if not(nodetype in [equaln,unequaln,ltn,lten,gtn,gten]) then
  1070. CGMessage(type_e_mismatch);
  1071. end
  1072. { generic conversion, this is for error recovery }
  1073. else
  1074. begin
  1075. inserttypeconv(left,s32bittype);
  1076. inserttypeconv(right,s32bittype);
  1077. end;
  1078. { set resulttype if not already done }
  1079. if not assigned(resulttype.def) then
  1080. begin
  1081. case nodetype of
  1082. ltn,lten,gtn,gten,equaln,unequaln :
  1083. resulttype:=booltype;
  1084. slashn :
  1085. resulttype:=pbestrealtype^;
  1086. addn:
  1087. begin
  1088. { for strings, return is always a 255 char string }
  1089. if is_shortstring(left.resulttype.def) then
  1090. resulttype:=cshortstringtype
  1091. else
  1092. resulttype:=left.resulttype;
  1093. end;
  1094. else
  1095. resulttype:=left.resulttype;
  1096. end;
  1097. end;
  1098. end;
  1099. function taddnode.first_addstring: tnode;
  1100. var
  1101. p: tnode;
  1102. begin
  1103. { when we get here, we are sure that both the left and the right }
  1104. { node are both strings of the same stringtype (JM) }
  1105. case nodetype of
  1106. addn:
  1107. begin
  1108. { note: if you implemented an fpc_shortstr_concat similar to the }
  1109. { one in i386.inc, you have to override first_addstring like in }
  1110. { ti386addnode.first_string and implement the shortstring concat }
  1111. { manually! The generic routine is different from the i386 one (JM) }
  1112. { create the call to the concat routine both strings as arguments }
  1113. result := ccallnode.createintern('fpc_'+
  1114. tstringdef(resulttype.def).stringtypname+'_concat',
  1115. ccallparanode.create(right,ccallparanode.create(left,nil)));
  1116. { we reused the arguments }
  1117. left := nil;
  1118. right := nil;
  1119. firstpass(result);
  1120. end;
  1121. ltn,lten,gtn,gten,equaln,unequaln :
  1122. begin
  1123. { generate better code for s='' and s<>'' }
  1124. if (nodetype in [equaln,unequaln]) and
  1125. (((left.nodetype=stringconstn) and (str_length(left)=0)) or
  1126. ((right.nodetype=stringconstn) and (str_length(right)=0))) then
  1127. begin
  1128. { switch so that the constant is always on the right }
  1129. if left.nodetype = stringconstn then
  1130. begin
  1131. p := left;
  1132. left := right;
  1133. right := p;
  1134. end;
  1135. if is_shortstring(left.resulttype.def) then
  1136. { compare the length with 0 }
  1137. result := caddnode.create(nodetype,
  1138. cinlinenode.create(in_length_x,false,left),
  1139. cordconstnode.create(0,s32bittype,false))
  1140. else
  1141. begin
  1142. { compare the pointer with nil (for ansistrings etc), }
  1143. { faster than getting the length (JM) }
  1144. result:= caddnode.create(nodetype,
  1145. ctypeconvnode.create(left,voidpointertype),
  1146. cpointerconstnode.create(0,voidpointertype));
  1147. taddnode(result).left.toggleflag(nf_explizit);
  1148. end;
  1149. { left is reused }
  1150. left := nil;
  1151. { right isn't }
  1152. right.free;
  1153. right := nil;
  1154. firstpass(result);
  1155. exit;
  1156. end;
  1157. { no string constant -> call compare routine }
  1158. result := ccallnode.createintern('fpc_'+
  1159. tstringdef(left.resulttype.def).stringtypname+'_compare',
  1160. ccallparanode.create(right,ccallparanode.create(left,nil)));
  1161. { and compare its result with 0 according to the original operator }
  1162. result := caddnode.create(nodetype,result,
  1163. cordconstnode.create(0,s32bittype,false));
  1164. left := nil;
  1165. right := nil;
  1166. firstpass(result);
  1167. end;
  1168. end;
  1169. end;
  1170. function taddnode.first_addset: tnode;
  1171. var
  1172. procname: string[31];
  1173. tempn: tnode;
  1174. paras: tcallparanode;
  1175. srsym: ttypesym;
  1176. begin
  1177. { get the sym that represents the fpc_normal_set type }
  1178. if not searchsystype('FPC_NORMAL_SET',srsym) then
  1179. internalerror(200108313);
  1180. case nodetype of
  1181. equaln,unequaln,lten,gten:
  1182. begin
  1183. case nodetype of
  1184. equaln,unequaln:
  1185. procname := 'fpc_set_comp_sets';
  1186. lten,gten:
  1187. begin
  1188. procname := 'fpc_set_contains_sets';
  1189. { (left >= right) = (right <= left) }
  1190. if nodetype = gten then
  1191. begin
  1192. tempn := left;
  1193. left := right;
  1194. right := tempn;
  1195. end;
  1196. end;
  1197. end;
  1198. { convert the arguments (explicitely) to fpc_normal_set's }
  1199. left := ctypeconvnode.create_explicit(left,srsym.restype);
  1200. right := ctypeconvnode.create_explicit(right,srsym.restype);
  1201. result := ccallnode.createintern(procname,ccallparanode.create(right,
  1202. ccallparanode.create(left,nil)));
  1203. { left and right are reused as parameters }
  1204. left := nil;
  1205. right := nil;
  1206. { for an unequaln, we have to negate the result of comp_sets }
  1207. if nodetype = unequaln then
  1208. result := cnotnode.create(result);
  1209. end;
  1210. addn:
  1211. begin
  1212. { optimize first loading of a set }
  1213. if (right.nodetype=setelementn) and
  1214. not(assigned(tsetelementnode(right).right)) and
  1215. is_emptyset(left) then
  1216. begin
  1217. { type cast the value to pass as argument to a byte, }
  1218. { since that's what the helper expects }
  1219. tsetelementnode(right).left :=
  1220. ctypeconvnode.create(tsetelementnode(right).left,u8bittype);
  1221. tsetelementnode(right).left.toggleflag(nf_explizit);
  1222. { set the resulttype to the actual one (otherwise it's }
  1223. { "fpc_normal_set") }
  1224. result := ccallnode.createinternres('fpc_set_create_element',
  1225. ccallparanode.create(tsetelementnode(right).left,nil),
  1226. resulttype);
  1227. { reused }
  1228. tsetelementnode(right).left := nil;
  1229. end
  1230. else
  1231. begin
  1232. if right.nodetype=setelementn then
  1233. begin
  1234. { convert the arguments to bytes, since that's what }
  1235. { the helper expects }
  1236. tsetelementnode(right).left :=
  1237. ctypeconvnode.create(tsetelementnode(right).left,
  1238. u8bittype);
  1239. tsetelementnode(right).left.toggleflag(nf_explizit);
  1240. { convert the original set (explicitely) to an }
  1241. { fpc_normal_set so we can pass it to the helper }
  1242. left := ctypeconvnode.create(left,srsym.restype);
  1243. left.toggleflag(nf_explizit);
  1244. { add a range or a single element? }
  1245. if assigned(tsetelementnode(right).right) then
  1246. begin
  1247. tsetelementnode(right).right :=
  1248. ctypeconvnode.create(tsetelementnode(right).right,
  1249. u8bittype);
  1250. tsetelementnode(right).right.toggleflag(nf_explizit);
  1251. { create the call }
  1252. result := ccallnode.createinternres('fpc_set_set_range',
  1253. ccallparanode.create(tsetelementnode(right).right,
  1254. ccallparanode.create(tsetelementnode(right).left,
  1255. ccallparanode.create(left,nil))),resulttype);
  1256. end
  1257. else
  1258. begin
  1259. result := ccallnode.createinternres('fpc_set_set_byte',
  1260. ccallparanode.create(tsetelementnode(right).left,
  1261. ccallparanode.create(left,nil)),resulttype);
  1262. end;
  1263. { remove reused parts from original node }
  1264. tsetelementnode(right).right := nil;
  1265. tsetelementnode(right).left := nil;
  1266. left := nil;
  1267. end
  1268. else
  1269. begin
  1270. { add two sets }
  1271. { convert the sets to fpc_normal_set's }
  1272. left := ctypeconvnode.create(left,srsym.restype);
  1273. left.toggleflag(nf_explizit);
  1274. right := ctypeconvnode.create(right,srsym.restype);
  1275. right.toggleflag(nf_explizit);
  1276. result := ccallnode.createinternres('fpc_set_add_sets',
  1277. ccallparanode.create(right,
  1278. ccallparanode.create(left,nil)),resulttype);
  1279. { remove reused parts from original node }
  1280. left := nil;
  1281. right := nil;
  1282. end;
  1283. end
  1284. end;
  1285. subn,symdifn,muln:
  1286. begin
  1287. { convert the sets to fpc_normal_set's }
  1288. left := ctypeconvnode.create(left,srsym.restype);
  1289. left.toggleflag(nf_explizit);
  1290. right := ctypeconvnode.create(right,srsym.restype);
  1291. right.toggleflag(nf_explizit);
  1292. paras := ccallparanode.create(right,
  1293. ccallparanode.create(left,nil));
  1294. case nodetype of
  1295. subn:
  1296. result := ccallnode.createinternres('fpc_set_sub_sets',
  1297. paras,resulttype);
  1298. symdifn:
  1299. result := ccallnode.createinternres('fpc_set_symdif_sets',
  1300. paras,resulttype);
  1301. muln:
  1302. result := ccallnode.createinternres('fpc_set_mul_sets',
  1303. paras,resulttype);
  1304. end;
  1305. { remove reused parts from original node }
  1306. left := nil;
  1307. right := nil;
  1308. end;
  1309. else
  1310. internalerror(200108311);
  1311. end;
  1312. firstpass(result);
  1313. end;
  1314. function taddnode.first_add64bitint: tnode;
  1315. var
  1316. procname: string[31];
  1317. temp: tnode;
  1318. power: longint;
  1319. begin
  1320. result := nil;
  1321. { create helper calls mul }
  1322. if nodetype <> muln then
  1323. exit;
  1324. { make sure that if there is a constant, that it's on the right }
  1325. if left.nodetype = ordconstn then
  1326. begin
  1327. temp := right;
  1328. right := left;
  1329. left := temp;
  1330. end;
  1331. { can we use a shift instead of a mul? }
  1332. if (right.nodetype = ordconstn) and
  1333. ispowerof2(tordconstnode(right).value,power) then
  1334. begin
  1335. tordconstnode(right).value := power;
  1336. result := cshlshrnode.create(shln,left,right);
  1337. { left and right are reused }
  1338. left := nil;
  1339. right := nil;
  1340. { return firstpassed new node }
  1341. firstpass(result);
  1342. exit;
  1343. end;
  1344. { otherwise, create the parameters for the helper }
  1345. right := ccallparanode.create(
  1346. cordconstnode.create(ord(cs_check_overflow in aktlocalswitches),booltype,true),
  1347. ccallparanode.create(right,ccallparanode.create(left,nil)));
  1348. left := nil;
  1349. if torddef(resulttype.def).typ = s64bit then
  1350. procname := 'fpc_mul_int64'
  1351. else
  1352. procname := 'fpc_mul_qword';
  1353. result := ccallnode.createintern(procname,right);
  1354. right := nil;
  1355. firstpass(result);
  1356. end;
  1357. function taddnode.first_addfloat: tnode;
  1358. var
  1359. procname: string[31];
  1360. temp: tnode;
  1361. power: longint;
  1362. { do we need to reverse the result ? }
  1363. notnode : boolean;
  1364. begin
  1365. result := nil;
  1366. notnode := false;
  1367. { In non-emulation mode, real opcodes are
  1368. emitted for floating point values.
  1369. }
  1370. if not (cs_fp_emulation in aktmoduleswitches) then
  1371. exit;
  1372. procname := 'FPC_REAL_';
  1373. case nodetype of
  1374. addn : procname := procname + 'ADD';
  1375. muln : procname := procname + 'MUL';
  1376. subn : procname := procname + 'SUB';
  1377. slashn : procname := procname + 'DIV';
  1378. ltn : procname := procname + 'LESS_THAN';
  1379. lten: procname := procname + 'LESS_EQUAL_THAN';
  1380. gtn:
  1381. begin
  1382. procname := procname + 'LESS_EQUAL_THAN';
  1383. notnode := true;
  1384. end;
  1385. gten:
  1386. begin
  1387. procname := procname + 'LESS_THAN';
  1388. notnode := true;
  1389. end;
  1390. equaln: procname := procname + 'EQUAL';
  1391. unequaln :
  1392. begin
  1393. procname := procname + 'EQUAL';
  1394. notnode := true;
  1395. end;
  1396. else
  1397. CGMessage(type_e_mismatch);
  1398. end;
  1399. { otherwise, create the parameters for the helper }
  1400. right := ccallparanode.create(right,ccallparanode.create(left,nil));
  1401. left := nil;
  1402. { do we need to reverse the result }
  1403. if notnode then
  1404. result := cnotnode.create(ccallnode.createintern(procname,right))
  1405. else
  1406. result := ccallnode.createintern(procname,right);
  1407. right := nil;
  1408. firstpass(result);
  1409. end;
  1410. function taddnode.pass_1 : tnode;
  1411. var
  1412. hp : tnode;
  1413. lt,rt : tnodetype;
  1414. rd,ld : tdef;
  1415. begin
  1416. result:=nil;
  1417. { first do the two subtrees }
  1418. firstpass(left);
  1419. firstpass(right);
  1420. if codegenerror then
  1421. exit;
  1422. { load easier access variables }
  1423. rd:=right.resulttype.def;
  1424. ld:=left.resulttype.def;
  1425. rt:=right.nodetype;
  1426. lt:=left.nodetype;
  1427. { int/int gives real/real! }
  1428. if nodetype=slashn then
  1429. begin
  1430. result := first_addfloat;
  1431. if assigned(result) then
  1432. exit;
  1433. location.loc:=LOC_FPUREGISTER;
  1434. { maybe we need an integer register to save }
  1435. { a reference }
  1436. if ((left.location.loc<>LOC_FPUREGISTER) or
  1437. (right.location.loc<>LOC_FPUREGISTER)) and
  1438. (left.registers32=right.registers32) then
  1439. calcregisters(self,1,1,0)
  1440. else
  1441. calcregisters(self,0,1,0);
  1442. { an add node always first loads both the left and the }
  1443. { right in the fpu before doing the calculation. However, }
  1444. { calcregisters(0,2,0) will overestimate the number of }
  1445. { necessary registers (it will make it 3 in case one of }
  1446. { the operands is already in the fpu) (JM) }
  1447. if ((left.location.loc <> LOC_FPUREGISTER) or
  1448. (right.location.loc <> LOC_FPUREGISTER)) and
  1449. (registersfpu < 2) then
  1450. inc(registersfpu);
  1451. end
  1452. { if both are orddefs then check sub types }
  1453. else if (ld.deftype=orddef) and (rd.deftype=orddef) then
  1454. begin
  1455. { 2 booleans ? }
  1456. if is_boolean(ld) and is_boolean(rd) then
  1457. begin
  1458. if not(cs_full_boolean_eval in aktlocalswitches) and
  1459. (nodetype in [andn,orn]) then
  1460. begin
  1461. location.loc:=LOC_JUMP;
  1462. calcregisters(self,0,0,0);
  1463. end
  1464. else
  1465. begin
  1466. location.loc := LOC_FLAGS;
  1467. if (left.location.loc in [LOC_JUMP,LOC_FLAGS]) and
  1468. (left.location.loc in [LOC_JUMP,LOC_FLAGS]) then
  1469. calcregisters(self,2,0,0)
  1470. else
  1471. calcregisters(self,1,0,0);
  1472. end;
  1473. end
  1474. else
  1475. { Both are chars? only convert to shortstrings for addn }
  1476. if is_char(ld) then
  1477. begin
  1478. if nodetype=addn then
  1479. internalerror(200103291);
  1480. location.loc := LOC_FLAGS;
  1481. calcregisters(self,1,0,0);
  1482. end
  1483. { is there a 64 bit type ? }
  1484. else if (torddef(ld).typ in [s64bit,u64bit]) then
  1485. begin
  1486. result := first_add64bitint;
  1487. if assigned(result) then
  1488. exit;
  1489. if nodetype in [addn,subn,muln,andn,orn,xorn] then
  1490. location.loc := LOC_REGISTER
  1491. else
  1492. location.loc := LOC_JUMP;
  1493. calcregisters(self,2,0,0)
  1494. end
  1495. { is there a cardinal? }
  1496. else if (torddef(ld).typ=u32bit) then
  1497. begin
  1498. if nodetype in [addn,subn,muln,andn,orn,xorn] then
  1499. location.loc := LOC_REGISTER
  1500. else
  1501. location.loc := LOC_FLAGS;
  1502. calcregisters(self,1,0,0);
  1503. { for unsigned mul we need an extra register }
  1504. if nodetype=muln then
  1505. inc(registers32);
  1506. end
  1507. { generic s32bit conversion }
  1508. else
  1509. begin
  1510. if nodetype in [addn,subn,muln,andn,orn,xorn] then
  1511. location.loc := LOC_REGISTER
  1512. else
  1513. location.loc := LOC_FLAGS;
  1514. calcregisters(self,1,0,0);
  1515. end;
  1516. end
  1517. { left side a setdef, must be before string processing,
  1518. else array constructor can be seen as array of char (PFV) }
  1519. else if (ld.deftype=setdef) then
  1520. begin
  1521. if tsetdef(ld).settype=smallset then
  1522. begin
  1523. location.loc:=LOC_REGISTER;
  1524. { are we adding set elements ? }
  1525. if right.nodetype=setelementn then
  1526. calcregisters(self,2,0,0)
  1527. else
  1528. calcregisters(self,1,0,0);
  1529. end
  1530. else
  1531. begin
  1532. result := first_addset;
  1533. if assigned(result) then
  1534. exit;
  1535. location.loc:=LOC_CREFERENCE;
  1536. calcregisters(self,0,0,0);
  1537. { here we call SET... }
  1538. if assigned(procinfo) then
  1539. procinfo.flags:=procinfo.flags or pi_do_call;
  1540. end;
  1541. end
  1542. { compare pchar by addresses like BP/Delphi }
  1543. else if is_pchar(ld) then
  1544. begin
  1545. location.loc:=LOC_REGISTER;
  1546. calcregisters(self,1,0,0);
  1547. end
  1548. { is one of the operands a string }
  1549. else if (ld.deftype=stringdef) then
  1550. begin
  1551. if is_widestring(ld) then
  1552. begin
  1553. { we use reference counted widestrings so no fast exit here }
  1554. if assigned(procinfo) then
  1555. procinfo.no_fast_exit:=true;
  1556. { this is only for add, the comparisaion is handled later }
  1557. location.loc:=LOC_REGISTER;
  1558. end
  1559. else if is_ansistring(ld) then
  1560. begin
  1561. { we use ansistrings so no fast exit here }
  1562. if assigned(procinfo) then
  1563. procinfo.no_fast_exit:=true;
  1564. { this is only for add, the comparisaion is handled later }
  1565. location.loc:=LOC_REGISTER;
  1566. end
  1567. else if is_longstring(ld) then
  1568. begin
  1569. { this is only for add, the comparisaion is handled later }
  1570. location.loc:=LOC_CREFERENCE;
  1571. end
  1572. else
  1573. begin
  1574. if canbeaddsstringcharoptnode(self) then
  1575. begin
  1576. hp := genaddsstringcharoptnode(self);
  1577. firstpass(hp);
  1578. pass_1 := hp;
  1579. exit;
  1580. end
  1581. else
  1582. begin
  1583. { Fix right to be shortstring }
  1584. if is_char(right.resulttype.def) then
  1585. begin
  1586. inserttypeconv(right,cshortstringtype);
  1587. firstpass(right);
  1588. end;
  1589. end;
  1590. if canbeaddsstringcsstringoptnode(self) then
  1591. begin
  1592. hp := genaddsstringcsstringoptnode(self);
  1593. firstpass(hp);
  1594. pass_1 := hp;
  1595. exit;
  1596. end;
  1597. end;
  1598. { otherwise, let addstring convert everything }
  1599. result := first_addstring;
  1600. exit;
  1601. end
  1602. { is one a real float ? }
  1603. else if (rd.deftype=floatdef) or (ld.deftype=floatdef) then
  1604. begin
  1605. result := first_addfloat;
  1606. if assigned(result) then
  1607. exit;
  1608. location.loc:=LOC_FPUREGISTER;
  1609. calcregisters(self,0,1,0);
  1610. { an add node always first loads both the left and the }
  1611. { right in the fpu before doing the calculation. However, }
  1612. { calcregisters(0,2,0) will overestimate the number of }
  1613. { necessary registers (it will make it 3 in case one of }
  1614. { the operands is already in the fpu) (JM) }
  1615. if ((left.location.loc <> LOC_FPUREGISTER) or
  1616. (right.location.loc <> LOC_FPUREGISTER)) and
  1617. (registersfpu < 2) then
  1618. inc(registersfpu);
  1619. end
  1620. { pointer comperation and subtraction }
  1621. else if (ld.deftype=pointerdef) then
  1622. begin
  1623. location.loc:=LOC_REGISTER;
  1624. calcregisters(self,1,0,0);
  1625. end
  1626. else if is_class_or_interface(ld) then
  1627. begin
  1628. location.loc:=LOC_REGISTER;
  1629. calcregisters(self,1,0,0);
  1630. end
  1631. else if (ld.deftype=classrefdef) then
  1632. begin
  1633. location.loc:=LOC_REGISTER;
  1634. calcregisters(self,1,0,0);
  1635. end
  1636. { support procvar=nil,procvar<>nil }
  1637. else if ((ld.deftype=procvardef) and (rt=niln)) or
  1638. ((rd.deftype=procvardef) and (lt=niln)) then
  1639. begin
  1640. location.loc:=LOC_REGISTER;
  1641. calcregisters(self,1,0,0);
  1642. end
  1643. {$ifdef SUPPORT_MMX}
  1644. { mmx support, this must be before the zero based array
  1645. check }
  1646. else if (cs_mmx in aktlocalswitches) and is_mmx_able_array(ld) and
  1647. is_mmx_able_array(rd) then
  1648. begin
  1649. location.loc:=LOC_MMXREGISTER;
  1650. calcregisters(self,0,0,1);
  1651. end
  1652. {$endif SUPPORT_MMX}
  1653. else if (rd.deftype=pointerdef) or (ld.deftype=pointerdef) then
  1654. begin
  1655. location.loc:=LOC_REGISTER;
  1656. calcregisters(self,1,0,0);
  1657. end
  1658. else if (rd.deftype=procvardef) and (ld.deftype=procvardef) and is_equal(rd,ld) then
  1659. begin
  1660. location.loc:=LOC_REGISTER;
  1661. calcregisters(self,1,0,0);
  1662. end
  1663. else if (ld.deftype=enumdef) then
  1664. begin
  1665. location.loc := LOC_FLAGS;
  1666. calcregisters(self,1,0,0);
  1667. end
  1668. {$ifdef SUPPORT_MMX}
  1669. else if (cs_mmx in aktlocalswitches) and
  1670. is_mmx_able_array(ld) and
  1671. is_mmx_able_array(rd) then
  1672. begin
  1673. location.loc:=LOC_MMXREGISTER;
  1674. calcregisters(self,0,0,1);
  1675. end
  1676. {$endif SUPPORT_MMX}
  1677. { the general solution is to convert to 32 bit int }
  1678. else
  1679. begin
  1680. location.loc:=LOC_REGISTER;
  1681. calcregisters(self,1,0,0);
  1682. end;
  1683. end;
  1684. {$ifdef state_tracking}
  1685. function Taddnode.track_state_pass(exec_known:boolean):boolean;
  1686. var factval:Tnode;
  1687. begin
  1688. track_state_pass:=false;
  1689. if left.track_state_pass(exec_known) then
  1690. begin
  1691. track_state_pass:=true;
  1692. left.resulttype.def:=nil;
  1693. do_resulttypepass(left);
  1694. end;
  1695. factval:=aktstate.find_fact(left);
  1696. if factval<>nil then
  1697. begin
  1698. track_state_pass:=true;
  1699. left.destroy;
  1700. left:=factval.getcopy;
  1701. end;
  1702. if right.track_state_pass(exec_known) then
  1703. begin
  1704. track_state_pass:=true;
  1705. right.resulttype.def:=nil;
  1706. do_resulttypepass(right);
  1707. end;
  1708. factval:=aktstate.find_fact(right);
  1709. if factval<>nil then
  1710. begin
  1711. track_state_pass:=true;
  1712. right.destroy;
  1713. right:=factval.getcopy;
  1714. end;
  1715. end;
  1716. {$endif}
  1717. begin
  1718. caddnode:=taddnode;
  1719. end.
  1720. {
  1721. $Log$
  1722. Revision 1.67 2002-10-05 00:47:03 peter
  1723. * support dynamicarray<>nil
  1724. Revision 1.66 2002/10/04 21:19:28 jonas
  1725. * fixed web bug 2139: checking for division by zero fixed
  1726. Revision 1.65 2002/09/07 15:25:02 peter
  1727. * old logs removed and tabs fixed
  1728. Revision 1.64 2002/09/07 12:16:05 carl
  1729. * second part bug report 1996 fix, testrange in cordconstnode
  1730. only called if option is set (also make parsing a tiny faster)
  1731. Revision 1.63 2002/09/04 19:32:56 jonas
  1732. * changed some ctypeconvnode/toggleflag(nf_explizit) combo's to
  1733. ctypeconvnode.create_explicit() statements
  1734. Revision 1.62 2002/08/17 09:23:34 florian
  1735. * first part of procinfo rewrite
  1736. Revision 1.61 2002/08/15 15:15:55 carl
  1737. * jmpbuf size allocation for exceptions is now cpu specific (as it should)
  1738. * more generic nodes for maths
  1739. * several fixes for better m68k support
  1740. Revision 1.60 2002/08/12 15:08:39 carl
  1741. + stab register indexes for powerpc (moved from gdb to cpubase)
  1742. + tprocessor enumeration moved to cpuinfo
  1743. + linker in target_info is now a class
  1744. * many many updates for m68k (will soon start to compile)
  1745. - removed some ifdef or correct them for correct cpu
  1746. Revision 1.59 2002/08/02 07:44:30 jonas
  1747. * made assigned() handling generic
  1748. * add nodes now can also evaluate constant expressions at compile time
  1749. that contain nil nodes
  1750. Revision 1.58 2002/07/26 11:17:52 jonas
  1751. * the optimization of converting a multiplication with a power of two to
  1752. a shl is moved from n386add/secondpass to nadd/resulttypepass
  1753. Revision 1.57 2002/07/23 13:08:16 jonas
  1754. * fixed constant set evaluation of new set handling for non-commutative
  1755. operators
  1756. Revision 1.56 2002/07/23 12:34:29 daniel
  1757. * Readded old set code. To use it define 'oldset'. Activated by default
  1758. for ppc.
  1759. Revision 1.55 2002/07/22 11:48:04 daniel
  1760. * Sets are now internally sets.
  1761. Revision 1.54 2002/07/20 11:57:53 florian
  1762. * types.pas renamed to defbase.pas because D6 contains a types
  1763. unit so this would conflicts if D6 programms are compiled
  1764. + Willamette/SSE2 instructions to assembler added
  1765. Revision 1.53 2002/07/19 11:41:34 daniel
  1766. * State tracker work
  1767. * The whilen and repeatn are now completely unified into whilerepeatn. This
  1768. allows the state tracker to change while nodes automatically into
  1769. repeat nodes.
  1770. * Resulttypepass improvements to the notn. 'not not a' is optimized away and
  1771. 'not(a>b)' is optimized into 'a<=b'.
  1772. * Resulttypepass improvements to the whilerepeatn. 'while not a' is optimized
  1773. by removing the notn and later switchting the true and falselabels. The
  1774. same is done with 'repeat until not a'.
  1775. Revision 1.52 2002/07/14 18:00:43 daniel
  1776. + Added the beginning of a state tracker. This will track the values of
  1777. variables through procedures and optimize things away.
  1778. Revision 1.51 2002/05/18 13:34:08 peter
  1779. * readded missing revisions
  1780. Revision 1.50 2002/05/16 19:46:37 carl
  1781. + defines.inc -> fpcdefs.inc to avoid conflicts if compiling by hand
  1782. + try to fix temp allocation (still in ifdef)
  1783. + generic constructor calls
  1784. + start of tassembler / tmodulebase class cleanup
  1785. Revision 1.48 2002/05/13 19:54:36 peter
  1786. * removed n386ld and n386util units
  1787. * maybe_save/maybe_restore added instead of the old maybe_push
  1788. Revision 1.47 2002/05/12 16:53:06 peter
  1789. * moved entry and exitcode to ncgutil and cgobj
  1790. * foreach gets extra argument for passing local data to the
  1791. iterator function
  1792. * -CR checks also class typecasts at runtime by changing them
  1793. into as
  1794. * fixed compiler to cycle with the -CR option
  1795. * fixed stabs with elf writer, finally the global variables can
  1796. be watched
  1797. * removed a lot of routines from cga unit and replaced them by
  1798. calls to cgobj
  1799. * u32bit-s32bit updates for and,or,xor nodes. When one element is
  1800. u32bit then the other is typecasted also to u32bit without giving
  1801. a rangecheck warning/error.
  1802. * fixed pascal calling method with reversing also the high tree in
  1803. the parast, detected by tcalcst3 test
  1804. Revision 1.46 2002/04/23 19:16:34 peter
  1805. * add pinline unit that inserts compiler supported functions using
  1806. one or more statements
  1807. * moved finalize and setlength from ninl to pinline
  1808. Revision 1.45 2002/04/04 19:05:56 peter
  1809. * removed unused units
  1810. * use tlocation.size in cg.a_*loc*() routines
  1811. Revision 1.44 2002/04/02 17:11:28 peter
  1812. * tlocation,treference update
  1813. * LOC_CONSTANT added for better constant handling
  1814. * secondadd splitted in multiple routines
  1815. * location_force_reg added for loading a location to a register
  1816. of a specified size
  1817. * secondassignment parses now first the right and then the left node
  1818. (this is compatible with Kylix). This saves a lot of push/pop especially
  1819. with string operations
  1820. * adapted some routines to use the new cg methods
  1821. }