ninl.pas 104 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738
  1. {
  2. $Id$
  3. Copyright (c) 1998-2002 by Florian Klaempfl
  4. Type checking and register allocation for inline 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 ninl;
  19. {$i fpcdefs.inc}
  20. interface
  21. uses
  22. node,htypechk,cpuinfo,symtype;
  23. {$i compinnr.inc}
  24. type
  25. tinlinenode = class(tunarynode)
  26. inlinenumber : byte;
  27. constructor create(number : byte;is_const:boolean;l : tnode);virtual;
  28. constructor ppuload(t:tnodetype;ppufile:tcompilerppufile);override;
  29. procedure ppuwrite(ppufile:tcompilerppufile);override;
  30. function getcopy : tnode;override;
  31. function pass_1 : tnode;override;
  32. function det_resulttype:tnode;override;
  33. function docompare(p: tnode): boolean; override;
  34. { All the following routines currently
  35. call compilerproc's, unless they are
  36. overriden in which case, the code
  37. generator handles them.
  38. }
  39. function first_pi: tnode ; virtual;
  40. function first_arctan_real: tnode; virtual;
  41. function first_abs_real: tnode; virtual;
  42. function first_sqr_real: tnode; virtual;
  43. function first_sqrt_real: tnode; virtual;
  44. function first_ln_real: tnode; virtual;
  45. function first_cos_real: tnode; virtual;
  46. function first_sin_real: tnode; virtual;
  47. private
  48. function handle_str: tnode;
  49. function handle_reset_rewrite_typed: tnode;
  50. function handle_read_write: tnode;
  51. function handle_val: tnode;
  52. end;
  53. tinlinenodeclass = class of tinlinenode;
  54. var
  55. cinlinenode : tinlinenodeclass;
  56. function geninlinenode(number : byte;is_const:boolean;l : tnode) : tinlinenode;
  57. implementation
  58. uses
  59. verbose,globals,systems,
  60. globtype, cutils,
  61. symbase,symconst,symdef,symsym,symtable,paramgr,defutil,defcmp,
  62. pass_1,
  63. ncal,ncon,ncnv,nadd,nld,nbas,nflw,nmem,nmat,nutils,
  64. cgbase,procinfo
  65. ;
  66. function geninlinenode(number : byte;is_const:boolean;l : tnode) : tinlinenode;
  67. begin
  68. geninlinenode:=cinlinenode.create(number,is_const,l);
  69. end;
  70. {*****************************************************************************
  71. TINLINENODE
  72. *****************************************************************************}
  73. constructor tinlinenode.create(number : byte;is_const:boolean;l : tnode);
  74. begin
  75. inherited create(inlinen,l);
  76. if is_const then
  77. include(flags,nf_inlineconst);
  78. inlinenumber:=number;
  79. end;
  80. constructor tinlinenode.ppuload(t:tnodetype;ppufile:tcompilerppufile);
  81. begin
  82. inherited ppuload(t,ppufile);
  83. inlinenumber:=ppufile.getbyte;
  84. end;
  85. procedure tinlinenode.ppuwrite(ppufile:tcompilerppufile);
  86. begin
  87. inherited ppuwrite(ppufile);
  88. ppufile.putbyte(inlinenumber);
  89. end;
  90. function tinlinenode.getcopy : tnode;
  91. var
  92. n : tinlinenode;
  93. begin
  94. n:=tinlinenode(inherited getcopy);
  95. n.inlinenumber:=inlinenumber;
  96. result:=n;
  97. end;
  98. function tinlinenode.handle_str : tnode;
  99. var
  100. lenpara,
  101. fracpara,
  102. newparas,
  103. dest,
  104. source : tcallparanode;
  105. procname: string;
  106. is_real : boolean;
  107. begin
  108. result := cerrornode.create;
  109. { make sure we got at least two parameters (if we got only one, }
  110. { this parameter may not be encapsulated in a callparan) }
  111. if not assigned(left) or
  112. (left.nodetype <> callparan) then
  113. begin
  114. CGMessage(parser_e_wrong_parameter_size);
  115. exit;
  116. end;
  117. { get destination string }
  118. dest := tcallparanode(left);
  119. { get source para (number) }
  120. source := dest;
  121. while assigned(source.right) do
  122. source := tcallparanode(source.right);
  123. is_real := source.resulttype.def.deftype = floatdef;
  124. if not assigned(dest) or
  125. ((dest.left.resulttype.def.deftype<>stringdef) and
  126. not(is_chararray(dest.left.resulttype.def))) or
  127. not(is_real or
  128. (source.left.resulttype.def.deftype = orddef)) then
  129. begin
  130. { the parser will give this message already because we }
  131. { return an errornode (JM) }
  132. { CGMessagePos(fileinfo,parser_e_illegal_expression); }
  133. exit;
  134. end;
  135. { get len/frac parameters }
  136. lenpara := nil;
  137. fracpara := nil;
  138. if (cpf_is_colon_para in tcallparanode(dest.right).callparaflags) then
  139. begin
  140. lenpara := tcallparanode(dest.right);
  141. { we can let the callnode do the type checking of these parameters too, }
  142. { but then the error messages aren't as nice }
  143. if not is_integer(lenpara.resulttype.def) then
  144. begin
  145. CGMessagePos1(lenpara.fileinfo,
  146. type_e_integer_expr_expected,lenpara.resulttype.def.typename);
  147. exit;
  148. end;
  149. if (cpf_is_colon_para in tcallparanode(lenpara.right).callparaflags) then
  150. begin
  151. { parameters are in reverse order! }
  152. fracpara := lenpara;
  153. lenpara := tcallparanode(lenpara.right);
  154. if not is_real then
  155. begin
  156. CGMessagePos(lenpara.fileinfo,parser_e_illegal_colon_qualifier);
  157. exit
  158. end;
  159. if not is_integer(lenpara.resulttype.def) then
  160. begin
  161. CGMessagePos1(lenpara.fileinfo,
  162. type_e_integer_expr_expected,lenpara.resulttype.def.typename);
  163. exit;
  164. end;
  165. end;
  166. end;
  167. { generate the parameter list for the compilerproc }
  168. newparas := dest;
  169. { if we have a float parameter, insert the realtype, len and fracpara parameters }
  170. if is_real then
  171. begin
  172. { insert realtype parameter }
  173. newparas.right := ccallparanode.create(cordconstnode.create(
  174. ord(tfloatdef(source.left.resulttype.def).typ),s32inttype,true),
  175. newparas.right);
  176. { if necessary, insert a fraction parameter }
  177. if not assigned(fracpara) then
  178. begin
  179. tcallparanode(newparas.right).right := ccallparanode.create(
  180. cordconstnode.create(-1,s32inttype,false),
  181. tcallparanode(newparas.right).right);
  182. fracpara := tcallparanode(tcallparanode(newparas.right).right);
  183. end;
  184. { if necessary, insert a length para }
  185. if not assigned(lenpara) then
  186. fracpara.right := ccallparanode.create(
  187. cordconstnode.create(-32767,s32inttype,false),
  188. fracpara.right);
  189. end
  190. else
  191. { for a normal parameter, insert a only length parameter if one is missing }
  192. if not assigned(lenpara) then
  193. newparas.right := ccallparanode.create(cordconstnode.create(-1,s32inttype,false),
  194. newparas.right);
  195. { remove the parameters from the original node so they won't get disposed, }
  196. { since they're reused }
  197. left := nil;
  198. { create procedure name }
  199. if is_chararray(dest.resulttype.def) then
  200. procname:='fpc_chararray_'
  201. else
  202. procname := 'fpc_' + tstringdef(dest.resulttype.def).stringtypname+'_';
  203. if is_real then
  204. procname := procname + 'float'
  205. else
  206. case torddef(source.resulttype.def).typ of
  207. {$ifdef cpu64bit}
  208. u64bit:
  209. procname := procname + 'uint';
  210. {$else}
  211. u32bit:
  212. procname := procname + 'uint';
  213. u64bit:
  214. procname := procname + 'qword';
  215. scurrency,
  216. s64bit:
  217. procname := procname + 'int64';
  218. {$endif}
  219. else
  220. procname := procname + 'sint';
  221. end;
  222. { free the errornode we generated in the beginning }
  223. result.free;
  224. { create the call node, }
  225. result := ccallnode.createintern(procname,newparas);
  226. end;
  227. function tinlinenode.handle_reset_rewrite_typed: tnode;
  228. begin
  229. { since this is a "in_xxxx_typedfile" node, we can be sure we have }
  230. { a typed file as argument and we don't have to check it again (JM) }
  231. { add the recsize parameter }
  232. { note: for some reason, the parameter of intern procedures with only one }
  233. { parameter is gets lifted out of its original tcallparanode (see round }
  234. { line 1306 of ncal.pas), so recreate a tcallparanode here (JM) }
  235. left := ccallparanode.create(cordconstnode.create(
  236. tfiledef(left.resulttype.def).typedfiletype.def.size,s32inttype,true),
  237. ccallparanode.create(left,nil));
  238. { create the correct call }
  239. if inlinenumber=in_reset_typedfile then
  240. result := ccallnode.createintern('fpc_reset_typed',left)
  241. else
  242. result := ccallnode.createintern('fpc_rewrite_typed',left);
  243. { make sure left doesn't get disposed, since we use it in the new call }
  244. left := nil;
  245. end;
  246. function tinlinenode.handle_read_write: tnode;
  247. const
  248. {$ifdef cpu64bit}
  249. hasownreadfunc = [uchar,uwidechar,bool8bit,bool16bit,bool32bit];
  250. {$else cpu64bit}
  251. hasownreadfunc = [uchar,uwidechar,bool8bit,bool16bit,bool32bit,s64bit,u64bit];
  252. {$endif cpu64bit}
  253. procnames: array[boolean,boolean] of string[11] =
  254. (('write_text_','read_text_'),('typed_write','typed_read'));
  255. var
  256. filepara,
  257. lenpara,
  258. fracpara,
  259. nextpara,
  260. para : tcallparanode;
  261. newstatement : tstatementnode;
  262. newblock : tblocknode;
  263. p1 : tnode;
  264. filetemp,
  265. temp : ttempcreatenode;
  266. procprefix,
  267. name : string[31];
  268. srsym : tvarsym;
  269. tempowner : tsymtable;
  270. restype : ^ttype;
  271. is_typed,
  272. do_read,
  273. is_real,
  274. error_para,
  275. found_error,
  276. is_ordinal : boolean;
  277. begin
  278. filepara := nil;
  279. is_typed := false;
  280. filetemp := nil;
  281. do_read := inlinenumber in [in_read_x,in_readln_x];
  282. { if we fail, we can quickly exit this way. We must generate something }
  283. { instead of the inline node, because firstpass will bomb with an }
  284. { internalerror if it encounters a read/write }
  285. result := cerrornode.create;
  286. { reverse the parameters (needed to get the colon parameters in the }
  287. { correct order when processing write(ln) }
  288. left := reverseparameters(tcallparanode(left));
  289. if assigned(left) then
  290. begin
  291. { check if we have a file parameter and if yes, what kind it is }
  292. filepara := tcallparanode(left);
  293. if (filepara.resulttype.def.deftype=filedef) then
  294. begin
  295. if (tfiledef(filepara.resulttype.def).filetyp=ft_untyped) then
  296. begin
  297. CGMessagePos(fileinfo,type_e_no_read_write_for_untyped_file);
  298. exit;
  299. end
  300. else
  301. begin
  302. if (tfiledef(filepara.resulttype.def).filetyp=ft_typed) then
  303. begin
  304. if (inlinenumber in [in_readln_x,in_writeln_x]) then
  305. begin
  306. CGMessagePos(fileinfo,type_e_no_readln_writeln_for_typed_file);
  307. exit;
  308. end;
  309. is_typed := true;
  310. end
  311. end;
  312. end
  313. else
  314. filepara := nil;
  315. end;
  316. { create a blocknode in which the successive write/read statements will be }
  317. { put, since they belong together. Also create a dummy statement already to }
  318. { make inserting of additional statements easier }
  319. newblock:=internalstatements(newstatement);
  320. { if we don't have a filepara, create one containing the default }
  321. if not assigned(filepara) then
  322. begin
  323. { retrieve the symbols for standard input/output handle }
  324. if do_read then
  325. name := 'INPUT'
  326. else
  327. name := 'OUTPUT';
  328. if not searchsysvar(name,srsym,tempowner) then
  329. internalerror(200108141);
  330. { since the input/output variables are threadvars loading them into
  331. a temp once is faster. Create a temp which will hold a pointer to the file }
  332. filetemp := ctempcreatenode.create_reg(voidpointertype,voidpointertype.def.size,tt_persistent);
  333. addstatement(newstatement,filetemp);
  334. { make sure the resulttype of the temp (and as such of the }
  335. { temprefs coming after it) is set (necessary because the }
  336. { temprefs will be part of the filepara, of which we need }
  337. { the resulttype later on and temprefs can only be }
  338. { resulttypepassed if the resulttype of the temp is known) }
  339. resulttypepass(tnode(filetemp));
  340. { assign the address of the file to the temp }
  341. addstatement(newstatement,
  342. cassignmentnode.create(ctemprefnode.create(filetemp),
  343. caddrnode.create(cloadnode.create(srsym,tempowner))));
  344. { create a new fileparameter as follows: file_type(temp^) }
  345. { (so that we pass the value and not the address of the temp }
  346. { to the read/write routine) }
  347. filepara := ccallparanode.create(ctypeconvnode.create_explicit(
  348. cderefnode.create(ctemprefnode.create(filetemp)),srsym.vartype),nil);
  349. end
  350. else
  351. { remove filepara from the parameter chain }
  352. begin
  353. left := filepara.right;
  354. filepara.right := nil;
  355. { the file para is a var parameter, but it must be valid already }
  356. set_varstate(filepara.left,vs_used,true);
  357. { check if we should make a temp to store the result of a complex }
  358. { expression (better heuristics, anyone?) (JM) }
  359. if (filepara.left.nodetype <> loadn) then
  360. begin
  361. { create a temp which will hold a pointer to the file }
  362. filetemp := ctempcreatenode.create_reg(voidpointertype,voidpointertype.def.size,tt_persistent);
  363. { add it to the statements }
  364. addstatement(newstatement,filetemp);
  365. { make sure the resulttype of the temp (and as such of the }
  366. { temprefs coming after it) is set (necessary because the }
  367. { temprefs will be part of the filepara, of which we need }
  368. { the resulttype later on and temprefs can only be }
  369. { resulttypepassed if the resulttype of the temp is known) }
  370. resulttypepass(tnode(filetemp));
  371. { assign the address of the file to the temp }
  372. addstatement(newstatement,
  373. cassignmentnode.create(ctemprefnode.create(filetemp),
  374. caddrnode.create(filepara.left)));
  375. resulttypepass(newstatement.left);
  376. { create a new fileparameter as follows: file_type(temp^) }
  377. { (so that we pass the value and not the address of the temp }
  378. { to the read/write routine) }
  379. nextpara := ccallparanode.create(ctypeconvnode.create_explicit(
  380. cderefnode.create(ctemprefnode.create(filetemp)),filepara.left.resulttype),nil);
  381. { replace the old file para with the new one }
  382. filepara.left := nil;
  383. filepara.free;
  384. filepara := nextpara;
  385. end;
  386. end;
  387. { the resulttype of the filepara must be set since it's }
  388. { used below }
  389. filepara.get_paratype;
  390. { now, filepara is nowhere referenced anymore, so we can safely dispose it }
  391. { if something goes wrong or at the end of the procedure }
  392. { choose the correct procedure prefix }
  393. procprefix := 'fpc_'+procnames[is_typed,do_read];
  394. { we're going to reuse the paranodes, so make sure they don't get freed }
  395. { twice }
  396. para := tcallparanode(left);
  397. left := nil;
  398. { no errors found yet... }
  399. found_error := false;
  400. if is_typed then
  401. begin
  402. { add the typesize to the filepara }
  403. filepara.right := ccallparanode.create(cordconstnode.create(
  404. tfiledef(filepara.resulttype.def).typedfiletype.def.size,s32inttype,true),nil);
  405. { check for "no parameters" (you need at least one extra para for typed files) }
  406. if not assigned(para) then
  407. begin
  408. CGMessage(parser_e_wrong_parameter_size);
  409. found_error := true;
  410. end;
  411. { process all parameters }
  412. while assigned(para) do
  413. begin
  414. { check if valid parameter }
  415. if para.left.nodetype=typen then
  416. begin
  417. CGMessagePos(para.left.fileinfo,type_e_cant_read_write_type);
  418. found_error := true;
  419. end;
  420. { support writeln(procvar) }
  421. if (para.left.resulttype.def.deftype=procvardef) then
  422. begin
  423. p1:=ccallnode.create_procvar(nil,para.left);
  424. resulttypepass(p1);
  425. para.left:=p1;
  426. end;
  427. inserttypeconv(para.left,tfiledef(filepara.resulttype.def).typedfiletype);
  428. if assigned(para.right) and
  429. (cpf_is_colon_para in tcallparanode(para.right).callparaflags) then
  430. begin
  431. CGMessagePos(para.right.fileinfo,parser_e_illegal_colon_qualifier);
  432. { skip all colon para's }
  433. nextpara := tcallparanode(tcallparanode(para.right).right);
  434. while assigned(nextpara) and
  435. (cpf_is_colon_para in nextpara.callparaflags) do
  436. nextpara := tcallparanode(nextpara.right);
  437. found_error := true;
  438. end
  439. else
  440. { get next parameter }
  441. nextpara := tcallparanode(para.right);
  442. { When we have a call, we have a problem: you can't pass the }
  443. { result of a call as a formal const parameter. Solution: }
  444. { assign the result to a temp and pass this temp as parameter }
  445. { This is not very efficient, but write(typedfile,x) is }
  446. { already slow by itself anyway (no buffering) (JM) }
  447. { Actually, thge same goes for every non-simple expression }
  448. { (such as an addition, ...) -> put everything but load nodes }
  449. { into temps (JM) }
  450. { of course, this must only be allowed for writes!!! (JM) }
  451. if not(do_read) and
  452. (para.left.nodetype <> loadn) then
  453. begin
  454. { create temp for result }
  455. temp := ctempcreatenode.create(para.left.resulttype,
  456. para.left.resulttype.def.size,tt_persistent);
  457. addstatement(newstatement,temp);
  458. { assign result to temp }
  459. addstatement(newstatement,
  460. cassignmentnode.create(ctemprefnode.create(temp),
  461. para.left));
  462. { replace (reused) paranode with temp }
  463. para.left := ctemprefnode.create(temp);
  464. end;
  465. { add fileparameter }
  466. para.right := filepara.getcopy;
  467. { create call statment }
  468. { since the parameters are in the correct order, we have to insert }
  469. { the statements always at the end of the current block }
  470. addstatement(newstatement,ccallnode.createintern(procprefix,para));
  471. { if we used a temp, free it }
  472. if para.left.nodetype = temprefn then
  473. addstatement(newstatement,ctempdeletenode.create(temp));
  474. { process next parameter }
  475. para := nextpara;
  476. end;
  477. { free the file parameter }
  478. filepara.free;
  479. end
  480. else
  481. { text read/write }
  482. begin
  483. while assigned(para) do
  484. begin
  485. { is this parameter faulty? }
  486. error_para := false;
  487. { is this parameter an ordinal? }
  488. is_ordinal := false;
  489. { is this parameter a real? }
  490. is_real:=false;
  491. { can't read/write types }
  492. if para.left.nodetype=typen then
  493. begin
  494. CGMessagePos(para.fileinfo,type_e_cant_read_write_type);
  495. error_para := true;
  496. end;
  497. { support writeln(procvar) }
  498. if (para.left.resulttype.def.deftype=procvardef) then
  499. begin
  500. p1:=ccallnode.create_procvar(nil,para.left);
  501. resulttypepass(p1);
  502. para.left:=p1;
  503. end;
  504. { Currency will be written using the bestreal }
  505. if is_currency(para.left.resulttype.def) then
  506. inserttypeconv(para.left,pbestrealtype^);
  507. case para.left.resulttype.def.deftype of
  508. stringdef :
  509. begin
  510. name := procprefix+tstringdef(para.left.resulttype.def).stringtypname;
  511. end;
  512. pointerdef :
  513. begin
  514. if not is_pchar(para.left.resulttype.def) then
  515. begin
  516. CGMessagePos(para.fileinfo,type_e_cant_read_write_type);
  517. error_para := true;
  518. end
  519. else
  520. name := procprefix+'pchar_as_pointer';
  521. end;
  522. floatdef :
  523. begin
  524. is_real:=true;
  525. name := procprefix+'float';
  526. end;
  527. orddef :
  528. begin
  529. is_ordinal := true;
  530. case torddef(para.left.resulttype.def).typ of
  531. {$ifdef cpu64bit}
  532. s64bit,
  533. {$endif cpu64bit}
  534. s8bit,
  535. s16bit,
  536. s32bit :
  537. name := procprefix+'sint';
  538. {$ifdef cpu64bit}
  539. u64bit,
  540. {$endif cpu64bit}
  541. u8bit,
  542. u16bit,
  543. u32bit :
  544. name := procprefix+'uint';
  545. uchar :
  546. name := procprefix+'char';
  547. uwidechar :
  548. name := procprefix+'widechar';
  549. {$ifndef cpu64bit}
  550. s64bit :
  551. name := procprefix+'int64';
  552. u64bit :
  553. name := procprefix+'qword';
  554. {$endif cpu64bit}
  555. bool8bit,
  556. bool16bit,
  557. bool32bit :
  558. begin
  559. if do_read then
  560. begin
  561. CGMessagePos(para.fileinfo,type_e_cant_read_write_type);
  562. error_para := true;
  563. end
  564. else
  565. name := procprefix+'boolean'
  566. end
  567. else
  568. begin
  569. CGMessagePos(para.fileinfo,type_e_cant_read_write_type);
  570. error_para := true;
  571. end;
  572. end;
  573. end;
  574. variantdef :
  575. name:=procprefix+'variant';
  576. arraydef :
  577. begin
  578. if is_chararray(para.left.resulttype.def) then
  579. name := procprefix+'pchar_as_array'
  580. else
  581. begin
  582. CGMessagePos(para.fileinfo,type_e_cant_read_write_type);
  583. error_para := true;
  584. end
  585. end
  586. else
  587. begin
  588. CGMessagePos(para.fileinfo,type_e_cant_read_write_type);
  589. error_para := true;
  590. end
  591. end;
  592. { check for length/fractional colon para's }
  593. fracpara := nil;
  594. lenpara := nil;
  595. if assigned(para.right) and
  596. (cpf_is_colon_para in tcallparanode(para.right).callparaflags) then
  597. begin
  598. lenpara := tcallparanode(para.right);
  599. if assigned(lenpara.right) and
  600. (cpf_is_colon_para in tcallparanode(lenpara.right).callparaflags) then
  601. fracpara:=tcallparanode(lenpara.right);
  602. end;
  603. { get the next parameter now already, because we're going }
  604. { to muck around with the pointers }
  605. if assigned(fracpara) then
  606. nextpara := tcallparanode(fracpara.right)
  607. else if assigned(lenpara) then
  608. nextpara := tcallparanode(lenpara.right)
  609. else
  610. nextpara := tcallparanode(para.right);
  611. { check if a fracpara is allowed }
  612. if assigned(fracpara) and not is_real then
  613. begin
  614. CGMessagePos(fracpara.fileinfo,parser_e_illegal_colon_qualifier);
  615. error_para := true;
  616. end
  617. else if assigned(lenpara) and do_read then
  618. begin
  619. { I think this is already filtered out by parsing, but I'm not sure (JM) }
  620. CGMessagePos(lenpara.fileinfo,parser_e_illegal_colon_qualifier);
  621. error_para := true;
  622. end;
  623. { adjust found_error }
  624. found_error := found_error or error_para;
  625. if not error_para then
  626. begin
  627. { create dummy frac/len para's if necessary }
  628. if not do_read then
  629. begin
  630. { difference in default value for floats and the rest :( }
  631. if not is_real then
  632. begin
  633. if not assigned(lenpara) then
  634. lenpara := ccallparanode.create(
  635. cordconstnode.create(0,sinttype,false),nil)
  636. else
  637. { make sure we don't pass the successive }
  638. { parameters too. We also already have a }
  639. { reference to the next parameter in }
  640. { nextpara }
  641. lenpara.right := nil;
  642. end
  643. else
  644. begin
  645. if not assigned(lenpara) then
  646. lenpara := ccallparanode.create(
  647. cordconstnode.create(-32767,sinttype,false),nil);
  648. { also create a default fracpara if necessary }
  649. if not assigned(fracpara) then
  650. fracpara := ccallparanode.create(
  651. cordconstnode.create(-1,sinttype,false),nil);
  652. { add it to the lenpara }
  653. lenpara.right := fracpara;
  654. { and add the realtype para (this also removes the link }
  655. { to any parameters coming after it) }
  656. fracpara.right := ccallparanode.create(
  657. cordconstnode.create(ord(tfloatdef(para.left.resulttype.def).typ),
  658. sinttype,true),nil);
  659. end;
  660. end;
  661. if do_read and
  662. ((is_ordinal and
  663. not(torddef(para.left.resulttype.def).typ in hasownreadfunc) and
  664. (para.left.resulttype.def.size<>sinttype.def.size)
  665. ) or
  666. (is_real and
  667. not equal_defs(para.left.resulttype.def,pbestrealtype^.def)
  668. )
  669. ) then
  670. { special handling of reading small numbers, because the helpers }
  671. { expect a longint/card/bestreal var parameter. Use a temp. can't }
  672. { use functions because then the call to FPC_IOCHECK destroys }
  673. { their result before we can store it }
  674. begin
  675. { get the resulttype of the var parameter of the helper }
  676. if is_real then
  677. restype := pbestrealtype
  678. else if is_signed(para.left.resulttype.def) then
  679. restype := @sinttype
  680. else
  681. restype := @uinttype;
  682. { create the parameter list: the temp ... }
  683. temp := ctempcreatenode.create(restype^,restype^.def.size,tt_persistent);
  684. addstatement(newstatement,temp);
  685. { ... and the file }
  686. p1 := ccallparanode.create(ctemprefnode.create(temp),
  687. filepara.getcopy);
  688. { create the call to the helper }
  689. addstatement(newstatement,
  690. ccallnode.createintern(name,tcallparanode(p1)));
  691. { assign the result to the original var (this automatically }
  692. { takes care of range checking) }
  693. addstatement(newstatement,
  694. cassignmentnode.create(para.left,
  695. ctemprefnode.create(temp)));
  696. { release the temp location }
  697. addstatement(newstatement,ctempdeletenode.create(temp));
  698. { statement of para is used }
  699. para.left := nil;
  700. { free the enclosing tcallparanode, but not the }
  701. { parameters coming after it }
  702. para.right := nil;
  703. para.free;
  704. end
  705. else
  706. { read of non s/u-8/16bit, or a write }
  707. begin
  708. { add the filepara to the current parameter }
  709. para.right := filepara.getcopy;
  710. { add the lenpara (fracpara and realtype are already linked }
  711. { with it if necessary) }
  712. tcallparanode(para.right).right := lenpara;
  713. { create the call statement }
  714. addstatement(newstatement,
  715. ccallnode.createintern(name,para));
  716. end
  717. end
  718. else
  719. { error_para = true }
  720. begin
  721. { free the parameter, since it isn't referenced anywhere anymore }
  722. para.right := nil;
  723. para.free;
  724. if assigned(lenpara) then
  725. begin
  726. lenpara.right := nil;
  727. lenpara.free;
  728. end;
  729. if assigned(fracpara) then
  730. begin
  731. fracpara.right := nil;
  732. fracpara.free;
  733. end;
  734. end;
  735. { process next parameter }
  736. para := nextpara;
  737. end;
  738. { if no error, add the write(ln)/read(ln) end calls }
  739. if not found_error then
  740. begin
  741. case inlinenumber of
  742. in_read_x:
  743. name:='fpc_read_end';
  744. in_write_x:
  745. name:='fpc_write_end';
  746. in_readln_x:
  747. name:='fpc_readln_end';
  748. in_writeln_x:
  749. name:='fpc_writeln_end';
  750. end;
  751. addstatement(newstatement,ccallnode.createintern(name,filepara));
  752. end;
  753. end;
  754. { if we found an error, simply delete the generated blocknode }
  755. if found_error then
  756. newblock.free
  757. else
  758. begin
  759. { deallocate the temp for the file para if we used one }
  760. if assigned(filetemp) then
  761. addstatement(newstatement,ctempdeletenode.create(filetemp));
  762. { otherwise return the newly generated block of instructions, }
  763. { but first free the errornode we generated at the beginning }
  764. result.free;
  765. result := newblock
  766. end;
  767. end;
  768. function tinlinenode.handle_val: tnode;
  769. var
  770. procname,
  771. suffix : string[31];
  772. sourcepara,
  773. destpara,
  774. codepara,
  775. sizepara,
  776. newparas : tcallparanode;
  777. orgcode : tnode;
  778. newstatement : tstatementnode;
  779. newblock : tblocknode;
  780. tempcode : ttempcreatenode;
  781. begin
  782. { for easy exiting if something goes wrong }
  783. result := cerrornode.create;
  784. { check the amount of parameters }
  785. if not(assigned(left)) or
  786. not(assigned(tcallparanode(left).right)) then
  787. begin
  788. CGMessage(parser_e_wrong_parameter_size);
  789. exit;
  790. end;
  791. { reverse parameters for easier processing }
  792. left := reverseparameters(tcallparanode(left));
  793. { get the parameters }
  794. tempcode := nil;
  795. orgcode := nil;
  796. sizepara := nil;
  797. sourcepara := tcallparanode(left);
  798. destpara := tcallparanode(sourcepara.right);
  799. codepara := tcallparanode(destpara.right);
  800. { check if codepara is valid }
  801. if assigned(codepara) and
  802. (
  803. (codepara.resulttype.def.deftype <> orddef)
  804. {$ifndef cpu64bit}
  805. or is_64bitint(codepara.resulttype.def)
  806. {$endif cpu64bit}
  807. ) then
  808. begin
  809. CGMessagePos1(codepara.fileinfo,type_e_integer_expr_expected,codepara.resulttype.def.typename);
  810. exit;
  811. end;
  812. { check if dest para is valid }
  813. if not(destpara.resulttype.def.deftype in [orddef,floatdef]) then
  814. begin
  815. CGMessagePos(destpara.fileinfo,type_e_integer_or_real_expr_expected);
  816. exit;
  817. end;
  818. { we're going to reuse the exisiting para's, so make sure they }
  819. { won't be disposed }
  820. left := nil;
  821. { create the blocknode which will hold the generated statements + }
  822. { an initial dummy statement }
  823. newblock:=internalstatements(newstatement);
  824. { do we need a temp for code? Yes, if no code specified, or if }
  825. { code is not a 32bit parameter (we already checked whether the }
  826. { the code para, if specified, was an orddef) }
  827. if not assigned(codepara) or
  828. (codepara.resulttype.def.size<>sinttype.def.size) then
  829. begin
  830. tempcode := ctempcreatenode.create(sinttype,sinttype.def.size,tt_persistent);
  831. addstatement(newstatement,tempcode);
  832. { set the resulttype of the temp (needed to be able to get }
  833. { the resulttype of the tempref used in the new code para) }
  834. resulttypepass(tnode(tempcode));
  835. { create a temp codepara, but save the original code para to }
  836. { assign the result to later on }
  837. if assigned(codepara) then
  838. begin
  839. orgcode := codepara.left;
  840. codepara.left := ctemprefnode.create(tempcode);
  841. end
  842. else
  843. codepara := ccallparanode.create(ctemprefnode.create(tempcode),nil);
  844. { we need its resulttype later on }
  845. codepara.get_paratype;
  846. end
  847. else if (torddef(codepara.resulttype.def).typ = torddef(sinttype.def).typ) then
  848. { because code is a var parameter, it must match types exactly }
  849. { however, since it will return values in [0..255], both longints }
  850. { and cardinals are fine. Since the formal code para type is }
  851. { longint, insert a typecoversion to longint for cardinal para's }
  852. begin
  853. codepara.left := ctypeconvnode.create_explicit(codepara.left,sinttype);
  854. { make it explicit, oterwise you may get a nonsense range }
  855. { check error if the cardinal already contained a value }
  856. { > $7fffffff }
  857. codepara.get_paratype;
  858. end;
  859. { create the procedure name }
  860. procname := 'fpc_val_';
  861. case destpara.resulttype.def.deftype of
  862. orddef:
  863. begin
  864. case torddef(destpara.resulttype.def).typ of
  865. {$ifdef cpu64bit}
  866. scurrency,
  867. s64bit,
  868. {$endif cpu64bit}
  869. s8bit,
  870. s16bit,
  871. s32bit:
  872. begin
  873. suffix := 'sint_';
  874. { we also need a destsize para in this case }
  875. sizepara := ccallparanode.create(cordconstnode.create
  876. (destpara.resulttype.def.size,s32inttype,true),nil);
  877. end;
  878. {$ifdef cpu64bit}
  879. u64bit,
  880. {$endif cpu64bit}
  881. u8bit,
  882. u16bit,
  883. u32bit:
  884. suffix := 'uint_';
  885. {$ifndef cpu64bit}
  886. scurrency,
  887. s64bit: suffix := 'int64_';
  888. u64bit: suffix := 'qword_';
  889. {$endif cpu64bit}
  890. else
  891. internalerror(200304225);
  892. end;
  893. end;
  894. floatdef:
  895. begin
  896. suffix := 'real_';
  897. end;
  898. end;
  899. procname := procname + suffix;
  900. { play a trick to have tcallnode handle invalid source parameters: }
  901. { the shortstring-longint val routine by default }
  902. if (sourcepara.resulttype.def.deftype = stringdef) then
  903. procname := procname + tstringdef(sourcepara.resulttype.def).stringtypname
  904. else
  905. procname := procname + 'shortstr';
  906. { set up the correct parameters for the call: the code para... }
  907. newparas := codepara;
  908. { and the source para }
  909. codepara.right := sourcepara;
  910. { sizepara either contains nil if none is needed (which is ok, since }
  911. { then the next statement severes any possible links with other paras }
  912. { that sourcepara may have) or it contains the necessary size para and }
  913. { its right field is nil }
  914. sourcepara.right := sizepara;
  915. { create the call and assign the result to dest }
  916. { (val helpers are functions) }
  917. { the assignment will take care of rangechecking }
  918. addstatement(newstatement,cassignmentnode.create(
  919. destpara.left,ccallnode.createintern(procname,newparas)));
  920. { dispose of the enclosing paranode of the destination }
  921. destpara.left := nil;
  922. destpara.right := nil;
  923. destpara.free;
  924. { check if we used a temp for code and whether we have to store }
  925. { it to the real code parameter }
  926. if assigned(orgcode) then
  927. addstatement(newstatement,cassignmentnode.create(
  928. orgcode,
  929. ctemprefnode.create(tempcode)));
  930. { release the temp if we allocated one }
  931. if assigned(tempcode) then
  932. addstatement(newstatement,ctempdeletenode.create(tempcode));
  933. { free the errornode }
  934. result.free;
  935. { and return it }
  936. result := newblock;
  937. end;
  938. {$ifdef fpc}
  939. {$maxfpuregisters 0}
  940. {$endif fpc}
  941. function tinlinenode.det_resulttype:tnode;
  942. function do_lowhigh(const t:ttype) : tnode;
  943. var
  944. v : tconstexprint;
  945. enum : tenumsym;
  946. hp : tnode;
  947. begin
  948. case t.def.deftype of
  949. orddef:
  950. begin
  951. if inlinenumber=in_low_x then
  952. v:=torddef(t.def).low
  953. else
  954. v:=torddef(t.def).high;
  955. { low/high of torddef are longints, so we need special }
  956. { handling for cardinal and 64bit types (JM) }
  957. { 1.0.x doesn't support int64($ffffffff) correct, it'll expand
  958. to -1 instead of staying $ffffffff. Therefor we use $ffff with
  959. shl twice (PFV) }
  960. case torddef(t.def).typ of
  961. s64bit,scurrency :
  962. begin
  963. if (inlinenumber=in_low_x) then
  964. v := int64($80000000) shl 32
  965. else
  966. v := (int64($7fffffff) shl 32) or int64($ffff) shl 16 or int64($ffff)
  967. end;
  968. u64bit :
  969. begin
  970. { we have to use a dirty trick for high(qword), }
  971. { because it's bigger than high(tconstexprint) (JM) }
  972. v := 0
  973. end
  974. else
  975. begin
  976. if not is_signed(t.def) then
  977. v := cardinal(v);
  978. end;
  979. end;
  980. hp:=cordconstnode.create(v,t,true);
  981. resulttypepass(hp);
  982. { fix high(qword) }
  983. if (torddef(t.def).typ=u64bit) and
  984. (inlinenumber = in_high_x) then
  985. tordconstnode(hp).value := -1; { is the same as qword($ffffffffffffffff) }
  986. do_lowhigh:=hp;
  987. end;
  988. enumdef:
  989. begin
  990. enum:=tenumsym(tenumdef(t.def).firstenum);
  991. v:=tenumdef(t.def).maxval;
  992. if inlinenumber=in_high_x then
  993. while assigned(enum) and (enum.value <> v) do
  994. enum:=enum.nextenum;
  995. if not assigned(enum) then
  996. internalerror(309993)
  997. else
  998. hp:=genenumnode(enum);
  999. do_lowhigh:=hp;
  1000. end;
  1001. else
  1002. internalerror(87);
  1003. end;
  1004. end;
  1005. function getconstrealvalue : bestreal;
  1006. begin
  1007. case left.nodetype of
  1008. ordconstn:
  1009. getconstrealvalue:=tordconstnode(left).value;
  1010. realconstn:
  1011. getconstrealvalue:=trealconstnode(left).value_real;
  1012. else
  1013. internalerror(309992);
  1014. end;
  1015. end;
  1016. procedure setconstrealvalue(r : bestreal);
  1017. begin
  1018. result:=crealconstnode.create(r,pbestrealtype^);
  1019. end;
  1020. function handle_ln_const(r : bestreal) : tnode;
  1021. begin
  1022. if r<=0.0 then
  1023. if (cs_check_range in aktlocalswitches) or
  1024. (cs_check_overflow in aktlocalswitches) then
  1025. begin
  1026. result:=crealconstnode.create(0,pbestrealtype^);
  1027. CGMessage(type_e_wrong_math_argument)
  1028. end
  1029. else
  1030. begin
  1031. if r=0.0 then
  1032. result:=crealconstnode.create(double(MathQNaN),pbestrealtype^)
  1033. else
  1034. result:=crealconstnode.create(double(MathNegInf),pbestrealtype^)
  1035. end
  1036. else
  1037. result:=crealconstnode.create(ln(r),pbestrealtype^)
  1038. end;
  1039. function handle_sqrt_const(r : bestreal) : tnode;
  1040. begin
  1041. if r<0.0 then
  1042. if (cs_check_range in aktlocalswitches) or
  1043. (cs_check_overflow in aktlocalswitches) then
  1044. begin
  1045. result:=crealconstnode.create(0,pbestrealtype^);
  1046. CGMessage(type_e_wrong_math_argument)
  1047. end
  1048. else
  1049. result:=crealconstnode.create(double(MathQNaN),pbestrealtype^)
  1050. else
  1051. result:=crealconstnode.create(sqrt(r),pbestrealtype^)
  1052. end;
  1053. var
  1054. vl,vl2 : TConstExprInt;
  1055. vr : bestreal;
  1056. hightree,
  1057. hp : tnode;
  1058. srsym : tsym;
  1059. isreal : boolean;
  1060. checkrange : boolean;
  1061. label
  1062. myexit;
  1063. begin
  1064. result:=nil;
  1065. { if we handle writeln; left contains no valid address }
  1066. if assigned(left) then
  1067. begin
  1068. if left.nodetype=callparan then
  1069. tcallparanode(left).get_paratype
  1070. else
  1071. resulttypepass(left);
  1072. end;
  1073. inc(parsing_para_level);
  1074. { handle intern constant functions in separate case }
  1075. if nf_inlineconst in flags then
  1076. begin
  1077. { no parameters? }
  1078. if not assigned(left) then
  1079. begin
  1080. case inlinenumber of
  1081. in_const_pi :
  1082. hp:=crealconstnode.create(pi,pbestrealtype^);
  1083. else
  1084. internalerror(89);
  1085. end;
  1086. end
  1087. else
  1088. begin
  1089. vl:=0;
  1090. vl2:=0; { second parameter Ex: ptr(vl,vl2) }
  1091. vr:=0;
  1092. isreal:=false;
  1093. case left.nodetype of
  1094. realconstn :
  1095. begin
  1096. isreal:=true;
  1097. vr:=trealconstnode(left).value_real;
  1098. end;
  1099. ordconstn :
  1100. vl:=tordconstnode(left).value;
  1101. callparan :
  1102. begin
  1103. { both exists, else it was not generated }
  1104. vl:=tordconstnode(tcallparanode(left).left).value;
  1105. vl2:=tordconstnode(tcallparanode(tcallparanode(left).right).left).value;
  1106. end;
  1107. else
  1108. CGMessage(parser_e_illegal_expression);
  1109. end;
  1110. case inlinenumber of
  1111. in_const_trunc :
  1112. begin
  1113. if isreal then
  1114. begin
  1115. if (vr>=9223372036854775808.0) or (vr<=-9223372036854775809.0) then
  1116. begin
  1117. CGMessage(parser_e_range_check_error);
  1118. hp:=cordconstnode.create(1,s64inttype,false)
  1119. end
  1120. else
  1121. hp:=cordconstnode.create(trunc(vr),s64inttype,true)
  1122. end
  1123. else
  1124. hp:=cordconstnode.create(trunc(vl),s64inttype,true);
  1125. end;
  1126. in_const_round :
  1127. begin
  1128. if isreal then
  1129. begin
  1130. if (vr>=9223372036854775807.5) or (vr<=-9223372036854775808.5) then
  1131. begin
  1132. CGMessage(parser_e_range_check_error);
  1133. hp:=cordconstnode.create(1,s64inttype,false)
  1134. end
  1135. else
  1136. hp:=cordconstnode.create(round(vr),s64inttype,true)
  1137. end
  1138. else
  1139. hp:=cordconstnode.create(round(vl),s64inttype,true);
  1140. end;
  1141. in_const_frac :
  1142. begin
  1143. if isreal then
  1144. hp:=crealconstnode.create(frac(vr),pbestrealtype^)
  1145. else
  1146. hp:=crealconstnode.create(frac(vl),pbestrealtype^);
  1147. end;
  1148. in_const_int :
  1149. begin
  1150. if isreal then
  1151. hp:=crealconstnode.create(int(vr),pbestrealtype^)
  1152. else
  1153. hp:=crealconstnode.create(int(vl),pbestrealtype^);
  1154. end;
  1155. in_const_abs :
  1156. begin
  1157. if isreal then
  1158. hp:=crealconstnode.create(abs(vr),pbestrealtype^)
  1159. else
  1160. hp:=cordconstnode.create(abs(vl),left.resulttype,true);
  1161. end;
  1162. in_const_sqr :
  1163. begin
  1164. if isreal then
  1165. hp:=crealconstnode.create(sqr(vr),pbestrealtype^)
  1166. else
  1167. hp:=cordconstnode.create(sqr(vl),left.resulttype,true);
  1168. end;
  1169. in_const_odd :
  1170. begin
  1171. if isreal then
  1172. CGMessage1(type_e_integer_expr_expected,left.resulttype.def.typename)
  1173. else
  1174. hp:=cordconstnode.create(byte(odd(vl)),booltype,true);
  1175. end;
  1176. in_const_swap_word :
  1177. begin
  1178. if isreal then
  1179. CGMessage1(type_e_integer_expr_expected,left.resulttype.def.typename)
  1180. else
  1181. hp:=cordconstnode.create((vl and $ff) shl 8+(vl shr 8),left.resulttype,true);
  1182. end;
  1183. in_const_swap_long :
  1184. begin
  1185. if isreal then
  1186. CGMessage1(type_e_integer_expr_expected,left.resulttype.def.typename)
  1187. else
  1188. hp:=cordconstnode.create((vl and $ffff) shl 16+(vl shr 16),left.resulttype,true);
  1189. end;
  1190. in_const_swap_qword :
  1191. begin
  1192. if isreal then
  1193. CGMessage1(type_e_integer_expr_expected,left.resulttype.def.typename)
  1194. else
  1195. hp:=cordconstnode.create((vl and $ffff) shl 32+(vl shr 32),left.resulttype,true);
  1196. end;
  1197. in_const_ptr :
  1198. begin
  1199. if isreal then
  1200. CGMessage1(type_e_integer_expr_expected,left.resulttype.def.typename)
  1201. else
  1202. hp:=cpointerconstnode.create((vl2 shl 4)+vl,voidfarpointertype);
  1203. end;
  1204. in_const_sqrt :
  1205. begin
  1206. if isreal then
  1207. hp:=handle_sqrt_const(vr)
  1208. else
  1209. hp:=handle_sqrt_const(vl)
  1210. end;
  1211. in_const_arctan :
  1212. begin
  1213. if isreal then
  1214. hp:=crealconstnode.create(arctan(vr),pbestrealtype^)
  1215. else
  1216. hp:=crealconstnode.create(arctan(vl),pbestrealtype^);
  1217. end;
  1218. in_const_cos :
  1219. begin
  1220. if isreal then
  1221. hp:=crealconstnode.create(cos(vr),pbestrealtype^)
  1222. else
  1223. hp:=crealconstnode.create(cos(vl),pbestrealtype^);
  1224. end;
  1225. in_const_sin :
  1226. begin
  1227. if isreal then
  1228. hp:=crealconstnode.create(sin(vr),pbestrealtype^)
  1229. else
  1230. hp:=crealconstnode.create(sin(vl),pbestrealtype^);
  1231. end;
  1232. in_const_exp :
  1233. begin
  1234. if isreal then
  1235. hp:=crealconstnode.create(exp(vr),pbestrealtype^)
  1236. else
  1237. hp:=crealconstnode.create(exp(vl),pbestrealtype^);
  1238. end;
  1239. in_const_ln :
  1240. begin
  1241. if isreal then
  1242. hp:=handle_ln_const(vr)
  1243. else
  1244. hp:=handle_ln_const(vl)
  1245. end;
  1246. else
  1247. internalerror(88);
  1248. end;
  1249. end;
  1250. if hp=nil then
  1251. hp:=tnode.create(errorn);
  1252. result:=hp;
  1253. goto myexit;
  1254. end
  1255. else
  1256. begin
  1257. case inlinenumber of
  1258. in_lo_long,
  1259. in_hi_long,
  1260. in_lo_qword,
  1261. in_hi_qword,
  1262. in_lo_word,
  1263. in_hi_word :
  1264. begin
  1265. { give warning for incompatibility with tp and delphi }
  1266. if (inlinenumber in [in_lo_long,in_hi_long,in_lo_qword,in_hi_qword]) and
  1267. ((m_tp7 in aktmodeswitches) or
  1268. (m_delphi in aktmodeswitches)) then
  1269. CGMessage(type_w_maybe_wrong_hi_lo);
  1270. { constant folding }
  1271. if left.nodetype=ordconstn then
  1272. begin
  1273. case inlinenumber of
  1274. in_lo_word :
  1275. hp:=cordconstnode.create(tordconstnode(left).value and $ff,left.resulttype,true);
  1276. in_hi_word :
  1277. hp:=cordconstnode.create(tordconstnode(left).value shr 8,left.resulttype,true);
  1278. in_lo_long :
  1279. hp:=cordconstnode.create(tordconstnode(left).value and $ffff,left.resulttype,true);
  1280. in_hi_long :
  1281. hp:=cordconstnode.create(tordconstnode(left).value shr 16,left.resulttype,true);
  1282. in_lo_qword :
  1283. hp:=cordconstnode.create(tordconstnode(left).value and $ffffffff,left.resulttype,true);
  1284. in_hi_qword :
  1285. hp:=cordconstnode.create(tordconstnode(left).value shr 32,left.resulttype,true);
  1286. end;
  1287. result:=hp;
  1288. goto myexit;
  1289. end;
  1290. set_varstate(left,vs_used,true);
  1291. if not is_integer(left.resulttype.def) then
  1292. CGMessage1(type_e_integer_expr_expected,left.resulttype.def.typename);
  1293. case inlinenumber of
  1294. in_lo_word,
  1295. in_hi_word :
  1296. resulttype:=u8inttype;
  1297. in_lo_long,
  1298. in_hi_long :
  1299. resulttype:=u16inttype;
  1300. in_lo_qword,
  1301. in_hi_qword :
  1302. resulttype:=u32inttype;
  1303. end;
  1304. end;
  1305. in_sizeof_x:
  1306. begin
  1307. set_varstate(left,vs_used,false);
  1308. if paramanager.push_high_param(vs_value,left.resulttype.def,current_procinfo.procdef.proccalloption) then
  1309. begin
  1310. hightree:=load_high_value_node(tvarsym(tloadnode(left).symtableentry));
  1311. if assigned(hightree) then
  1312. begin
  1313. hp:=caddnode.create(addn,hightree,
  1314. cordconstnode.create(1,sinttype,false));
  1315. if (left.resulttype.def.deftype=arraydef) and
  1316. (tarraydef(left.resulttype.def).elesize<>1) then
  1317. hp:=caddnode.create(muln,hp,cordconstnode.create(tarraydef(
  1318. left.resulttype.def).elesize,sinttype,true));
  1319. result:=hp;
  1320. end;
  1321. end
  1322. else
  1323. resulttype:=sinttype;
  1324. end;
  1325. in_typeof_x:
  1326. begin
  1327. set_varstate(left,vs_used,false);
  1328. resulttype:=voidpointertype;
  1329. end;
  1330. in_ord_x:
  1331. begin
  1332. if (left.nodetype=ordconstn) then
  1333. begin
  1334. hp:=cordconstnode.create(
  1335. tordconstnode(left).value,sinttype,true);
  1336. result:=hp;
  1337. goto myexit;
  1338. end;
  1339. set_varstate(left,vs_used,true);
  1340. case left.resulttype.def.deftype of
  1341. orddef :
  1342. begin
  1343. case torddef(left.resulttype.def).typ of
  1344. bool8bit,
  1345. uchar:
  1346. begin
  1347. { change to byte() }
  1348. hp:=ctypeconvnode.create_explicit(left,u8inttype);
  1349. left:=nil;
  1350. result:=hp;
  1351. end;
  1352. bool16bit,
  1353. uwidechar :
  1354. begin
  1355. { change to word() }
  1356. hp:=ctypeconvnode.create_explicit(left,u16inttype);
  1357. left:=nil;
  1358. result:=hp;
  1359. end;
  1360. bool32bit :
  1361. begin
  1362. { change to dword() }
  1363. hp:=ctypeconvnode.create_explicit(left,u32inttype);
  1364. left:=nil;
  1365. result:=hp;
  1366. end;
  1367. uvoid :
  1368. CGMessage1(type_e_ordinal_expr_expected,left.resulttype.def.typename);
  1369. else
  1370. begin
  1371. { all other orddef need no transformation }
  1372. hp:=left;
  1373. left:=nil;
  1374. result:=hp;
  1375. end;
  1376. end;
  1377. end;
  1378. enumdef :
  1379. begin
  1380. hp:=ctypeconvnode.create_explicit(left,s32inttype);
  1381. left:=nil;
  1382. result:=hp;
  1383. end;
  1384. else
  1385. CGMessage1(type_e_ordinal_expr_expected,left.resulttype.def.typename);
  1386. end;
  1387. end;
  1388. in_chr_byte:
  1389. begin
  1390. { convert to explicit char() }
  1391. set_varstate(left,vs_used,true);
  1392. hp:=ctypeconvnode.create_explicit(left,cchartype);
  1393. left:=nil;
  1394. result:=hp;
  1395. end;
  1396. in_length_x:
  1397. begin
  1398. set_varstate(left,vs_used,true);
  1399. case left.resulttype.def.deftype of
  1400. stringdef :
  1401. begin
  1402. { we don't need string convertions here }
  1403. if (left.nodetype=typeconvn) and
  1404. (ttypeconvnode(left).left.resulttype.def.deftype=stringdef) then
  1405. begin
  1406. hp:=ttypeconvnode(left).left;
  1407. ttypeconvnode(left).left:=nil;
  1408. left.free;
  1409. left:=hp;
  1410. end;
  1411. { evaluates length of constant strings direct }
  1412. if (left.nodetype=stringconstn) then
  1413. begin
  1414. hp:=cordconstnode.create(
  1415. tstringconstnode(left).len,s32inttype,true);
  1416. result:=hp;
  1417. goto myexit;
  1418. end;
  1419. end;
  1420. orddef :
  1421. begin
  1422. { length of char is one allways }
  1423. if is_char(left.resulttype.def) or
  1424. is_widechar(left.resulttype.def) then
  1425. begin
  1426. hp:=cordconstnode.create(1,s32inttype,false);
  1427. result:=hp;
  1428. goto myexit;
  1429. end
  1430. else
  1431. CGMessage(type_e_mismatch);
  1432. end;
  1433. pointerdef :
  1434. begin
  1435. if is_pchar(left.resulttype.def) then
  1436. begin
  1437. hp := ccallparanode.create(left,nil);
  1438. result := ccallnode.createintern('fpc_pchar_length',hp);
  1439. { make sure the left node doesn't get disposed, since it's }
  1440. { reused in the new node (JM) }
  1441. left:=nil;
  1442. goto myexit;
  1443. end
  1444. else if is_pwidechar(left.resulttype.def) then
  1445. begin
  1446. hp := ccallparanode.create(left,nil);
  1447. result := ccallnode.createintern('fpc_pwidechar_length',hp);
  1448. { make sure the left node doesn't get disposed, since it's }
  1449. { reused in the new node (JM) }
  1450. left:=nil;
  1451. goto myexit;
  1452. end
  1453. else
  1454. CGMessage(type_e_mismatch);
  1455. end;
  1456. arraydef :
  1457. begin
  1458. if is_open_array(left.resulttype.def) or
  1459. is_array_of_const(left.resulttype.def) then
  1460. begin
  1461. hightree:=load_high_value_node(tvarsym(tloadnode(left).symtableentry));
  1462. if assigned(hightree) then
  1463. begin
  1464. hp:=caddnode.create(addn,hightree,
  1465. cordconstnode.create(1,s32inttype,false));
  1466. result:=hp;
  1467. end;
  1468. goto myexit;
  1469. end
  1470. else
  1471. if not is_dynamic_array(left.resulttype.def) then
  1472. begin
  1473. hp:=cordconstnode.create(tarraydef(left.resulttype.def).highrange-
  1474. tarraydef(left.resulttype.def).lowrange+1,
  1475. s32inttype,true);
  1476. result:=hp;
  1477. goto myexit;
  1478. end
  1479. else
  1480. begin
  1481. hp := ccallparanode.create(ctypeconvnode.create_explicit(left,voidpointertype),nil);
  1482. result := ccallnode.createintern('fpc_dynarray_length',hp);
  1483. { make sure the left node doesn't get disposed, since it's }
  1484. { reused in the new node (JM) }
  1485. left:=nil;
  1486. goto myexit;
  1487. end;
  1488. end;
  1489. else
  1490. CGMessage(type_e_mismatch);
  1491. end;
  1492. { shortstring return an 8 bit value as the length
  1493. is the first byte of the string }
  1494. if is_shortstring(left.resulttype.def) then
  1495. resulttype:=u8inttype
  1496. else
  1497. resulttype:=sinttype;
  1498. end;
  1499. in_typeinfo_x:
  1500. begin
  1501. set_varstate(left,vs_used,true);
  1502. resulttype:=voidpointertype;
  1503. end;
  1504. in_assigned_x:
  1505. begin
  1506. { the parser has already made sure the expression is valid }
  1507. { handle constant expressions }
  1508. if is_constnode(tcallparanode(left).left) or
  1509. (tcallparanode(left).left.nodetype = pointerconstn) then
  1510. begin
  1511. { let an add node figure it out }
  1512. result := caddnode.create(unequaln,tcallparanode(left).left,cnilnode.create);
  1513. tcallparanode(left).left := nil;
  1514. { free left, because otherwise some code at 'myexit' tries }
  1515. { to run get_paratype for it, which crashes since left.left }
  1516. { is now nil }
  1517. left.free;
  1518. left := nil;
  1519. goto myexit;
  1520. end;
  1521. { otherwise handle separately, because there could be a procvar, which }
  1522. { is 2*sizeof(pointer), while we must only check the first pointer }
  1523. set_varstate(tcallparanode(left).left,vs_used,true);
  1524. resulttype:=booltype;
  1525. end;
  1526. in_ofs_x :
  1527. internalerror(2000101001);
  1528. in_seg_x :
  1529. begin
  1530. set_varstate(left,vs_used,false);
  1531. hp:=cordconstnode.create(0,s32inttype,false);
  1532. result:=hp;
  1533. goto myexit;
  1534. end;
  1535. in_pred_x,
  1536. in_succ_x:
  1537. begin
  1538. set_varstate(left,vs_used,true);
  1539. resulttype:=left.resulttype;
  1540. if not is_ordinal(resulttype.def) then
  1541. CGMessage(type_e_ordinal_expr_expected)
  1542. else
  1543. begin
  1544. if (resulttype.def.deftype=enumdef) and
  1545. (tenumdef(resulttype.def).has_jumps) then
  1546. CGMessage(type_e_succ_and_pred_enums_with_assign_not_possible);
  1547. end;
  1548. { only if the result is an enum do we do range checking }
  1549. if (resulttype.def.deftype=enumdef) then
  1550. checkrange := true
  1551. else
  1552. checkrange := false;
  1553. { do constant folding after check for jumps }
  1554. if left.nodetype=ordconstn then
  1555. begin
  1556. if inlinenumber=in_succ_x then
  1557. hp:=cordconstnode.create(tordconstnode(left).value+1,left.resulttype,checkrange)
  1558. else
  1559. hp:=cordconstnode.create(tordconstnode(left).value-1,left.resulttype,checkrange);
  1560. result:=hp;
  1561. end;
  1562. end;
  1563. in_initialize_x,
  1564. in_finalize_x,
  1565. in_setlength_x:
  1566. begin
  1567. { inlined from pinline }
  1568. internalerror(200204231);
  1569. end;
  1570. in_inc_x,
  1571. in_dec_x:
  1572. begin
  1573. resulttype:=voidtype;
  1574. if assigned(left) then
  1575. begin
  1576. { first param must be var }
  1577. valid_for_var(tcallparanode(left).left);
  1578. set_varstate(tcallparanode(left).left,vs_used,true);
  1579. if (left.resulttype.def.deftype in [enumdef,pointerdef]) or
  1580. is_ordinal(left.resulttype.def) or
  1581. is_currency(left.resulttype.def) then
  1582. begin
  1583. { value of left gets changed -> must be unique }
  1584. set_unique(tcallparanode(left).left);
  1585. { two paras ? }
  1586. if assigned(tcallparanode(left).right) then
  1587. begin
  1588. set_varstate(tcallparanode(tcallparanode(left).right).left,vs_used,true);
  1589. inserttypeconv_explicit(tcallparanode(tcallparanode(left).right).left,tcallparanode(left).left.resulttype);
  1590. if assigned(tcallparanode(tcallparanode(left).right).right) then
  1591. CGMessage(parser_e_illegal_expression);
  1592. end;
  1593. end
  1594. else
  1595. CGMessage(type_e_ordinal_expr_expected);
  1596. end
  1597. else
  1598. CGMessage(type_e_mismatch);
  1599. end;
  1600. in_read_x,
  1601. in_readln_x,
  1602. in_write_x,
  1603. in_writeln_x :
  1604. begin
  1605. result := handle_read_write;
  1606. end;
  1607. in_settextbuf_file_x :
  1608. begin
  1609. resulttype:=voidtype;
  1610. { now we know the type of buffer }
  1611. srsym:=searchsymonlyin(systemunit,'SETTEXTBUF');
  1612. hp:=ccallparanode.create(cordconstnode.create(
  1613. tcallparanode(left).left.resulttype.def.size,s32inttype,true),left);
  1614. hp:=ccallnode.create(hp,tprocsym(srsym),systemunit,nil,[]);
  1615. left:=nil;
  1616. result:=hp;
  1617. end;
  1618. { the firstpass of the arg has been done in firstcalln ? }
  1619. in_reset_typedfile,
  1620. in_rewrite_typedfile :
  1621. begin
  1622. result := handle_reset_rewrite_typed;
  1623. end;
  1624. in_str_x_string :
  1625. begin
  1626. result := handle_str;
  1627. end;
  1628. in_val_x :
  1629. begin
  1630. result := handle_val;
  1631. end;
  1632. in_include_x_y,
  1633. in_exclude_x_y:
  1634. begin
  1635. resulttype:=voidtype;
  1636. { the parser already checks whether we have two (and exectly two) }
  1637. { parameters (JM) }
  1638. { first param must be var }
  1639. valid_for_var(tcallparanode(left).left);
  1640. set_varstate(tcallparanode(left).left,vs_used,true);
  1641. { check type }
  1642. if (left.resulttype.def.deftype=setdef) then
  1643. begin
  1644. { insert a type conversion }
  1645. { to the type of the set elements }
  1646. set_varstate(tcallparanode(tcallparanode(left).right).left,vs_used,true);
  1647. inserttypeconv(tcallparanode(tcallparanode(left).right).left,
  1648. tsetdef(left.resulttype.def).elementtype);
  1649. end
  1650. else
  1651. CGMessage(type_e_mismatch);
  1652. end;
  1653. in_low_x,
  1654. in_high_x:
  1655. begin
  1656. set_varstate(left,vs_used,false);
  1657. case left.resulttype.def.deftype of
  1658. orddef,
  1659. enumdef:
  1660. begin
  1661. result:=do_lowhigh(left.resulttype);
  1662. end;
  1663. setdef:
  1664. begin
  1665. result:=do_lowhigh(tsetdef(left.resulttype.def).elementtype);
  1666. end;
  1667. arraydef:
  1668. begin
  1669. if inlinenumber=in_low_x then
  1670. begin
  1671. result:=cordconstnode.create(tarraydef(
  1672. left.resulttype.def).lowrange,tarraydef(left.resulttype.def).rangetype,true);
  1673. end
  1674. else
  1675. begin
  1676. if is_open_array(left.resulttype.def) or
  1677. is_array_of_const(left.resulttype.def) then
  1678. begin
  1679. result:=load_high_value_node(tvarsym(tloadnode(left).symtableentry));
  1680. end
  1681. else
  1682. if is_dynamic_array(left.resulttype.def) then
  1683. begin
  1684. { can't use inserttypeconv because we need }
  1685. { an explicit type conversion (JM) }
  1686. hp := ccallparanode.create(ctypeconvnode.create_explicit(left,voidpointertype),nil);
  1687. result := ccallnode.createintern('fpc_dynarray_high',hp);
  1688. { make sure the left node doesn't get disposed, since it's }
  1689. { reused in the new node (JM) }
  1690. left:=nil;
  1691. end
  1692. else
  1693. begin
  1694. result:=cordconstnode.create(tarraydef(
  1695. left.resulttype.def).highrange,tarraydef(left.resulttype.def).rangetype,true);
  1696. end;
  1697. end;
  1698. end;
  1699. stringdef:
  1700. begin
  1701. if inlinenumber=in_low_x then
  1702. begin
  1703. result:=cordconstnode.create(0,u8inttype,false);
  1704. end
  1705. else
  1706. begin
  1707. if is_open_string(left.resulttype.def) then
  1708. result:=load_high_value_node(tvarsym(tloadnode(left).symtableentry))
  1709. else
  1710. result:=cordconstnode.create(tstringdef(left.resulttype.def).len,u8inttype,true);
  1711. end;
  1712. end;
  1713. else
  1714. CGMessage(type_e_mismatch);
  1715. end;
  1716. end;
  1717. in_pi:
  1718. begin
  1719. if block_type=bt_const then
  1720. setconstrealvalue(pi)
  1721. else
  1722. resulttype:=pbestrealtype^;
  1723. end;
  1724. in_cos_extended :
  1725. begin
  1726. if left.nodetype in [ordconstn,realconstn] then
  1727. setconstrealvalue(cos(getconstrealvalue))
  1728. else
  1729. begin
  1730. set_varstate(left,vs_used,true);
  1731. inserttypeconv(left,pbestrealtype^);
  1732. resulttype:=pbestrealtype^;
  1733. end;
  1734. end;
  1735. in_sin_extended :
  1736. begin
  1737. if left.nodetype in [ordconstn,realconstn] then
  1738. setconstrealvalue(sin(getconstrealvalue))
  1739. else
  1740. begin
  1741. set_varstate(left,vs_used,true);
  1742. inserttypeconv(left,pbestrealtype^);
  1743. resulttype:=pbestrealtype^;
  1744. end;
  1745. end;
  1746. in_arctan_extended :
  1747. begin
  1748. if left.nodetype in [ordconstn,realconstn] then
  1749. setconstrealvalue(arctan(getconstrealvalue))
  1750. else
  1751. begin
  1752. set_varstate(left,vs_used,true);
  1753. inserttypeconv(left,pbestrealtype^);
  1754. resulttype:=pbestrealtype^;
  1755. end;
  1756. end;
  1757. in_abs_extended :
  1758. begin
  1759. if left.nodetype in [ordconstn,realconstn] then
  1760. setconstrealvalue(abs(getconstrealvalue))
  1761. else
  1762. begin
  1763. set_varstate(left,vs_used,true);
  1764. inserttypeconv(left,pbestrealtype^);
  1765. resulttype:=pbestrealtype^;
  1766. end;
  1767. end;
  1768. in_sqr_extended :
  1769. begin
  1770. if left.nodetype in [ordconstn,realconstn] then
  1771. setconstrealvalue(sqr(getconstrealvalue))
  1772. else
  1773. begin
  1774. set_varstate(left,vs_used,true);
  1775. inserttypeconv(left,pbestrealtype^);
  1776. resulttype:=pbestrealtype^;
  1777. end;
  1778. end;
  1779. in_sqrt_extended :
  1780. begin
  1781. if left.nodetype in [ordconstn,realconstn] then
  1782. begin
  1783. vr:=getconstrealvalue;
  1784. if vr<0.0 then
  1785. result:=handle_sqrt_const(vr)
  1786. else
  1787. setconstrealvalue(sqrt(vr));
  1788. end
  1789. else
  1790. begin
  1791. set_varstate(left,vs_used,true);
  1792. inserttypeconv(left,pbestrealtype^);
  1793. resulttype:=pbestrealtype^;
  1794. end;
  1795. end;
  1796. in_ln_extended :
  1797. begin
  1798. if left.nodetype in [ordconstn,realconstn] then
  1799. begin
  1800. vr:=getconstrealvalue;
  1801. if vr<=0.0 then
  1802. result:=handle_ln_const(vr)
  1803. else
  1804. setconstrealvalue(ln(vr));
  1805. end
  1806. else
  1807. begin
  1808. set_varstate(left,vs_used,true);
  1809. inserttypeconv(left,pbestrealtype^);
  1810. resulttype:=pbestrealtype^;
  1811. end;
  1812. end;
  1813. {$ifdef SUPPORT_MMX}
  1814. in_mmx_pcmpeqb..in_mmx_pcmpgtw:
  1815. begin
  1816. end;
  1817. {$endif SUPPORT_MMX}
  1818. in_prefetch_var:
  1819. begin
  1820. resulttype:=voidtype;
  1821. end;
  1822. in_assert_x_y :
  1823. begin
  1824. resulttype:=voidtype;
  1825. if assigned(left) then
  1826. begin
  1827. set_varstate(tcallparanode(left).left,vs_used,true);
  1828. { check type }
  1829. if is_boolean(left.resulttype.def) then
  1830. begin
  1831. set_varstate(tcallparanode(tcallparanode(left).right).left,vs_used,true);
  1832. { must always be a string }
  1833. inserttypeconv(tcallparanode(tcallparanode(left).right).left,cshortstringtype);
  1834. end
  1835. else
  1836. CGMessage1(type_e_boolean_expr_expected,left.resulttype.def.typename);
  1837. end
  1838. else
  1839. CGMessage(type_e_mismatch);
  1840. { We've checked the whole statement for correctness, now we
  1841. can remove it if assertions are off }
  1842. if not(cs_do_assertion in aktlocalswitches) then
  1843. begin
  1844. { we need a valid node, so insert a nothingn }
  1845. result:=cnothingnode.create;
  1846. end
  1847. else
  1848. include(current_procinfo.flags,pi_do_call);
  1849. end;
  1850. else
  1851. internalerror(8);
  1852. end;
  1853. end;
  1854. myexit:
  1855. { Run get_paratype again to update maybe inserted typeconvs }
  1856. if not codegenerror then
  1857. begin
  1858. if assigned(left) and
  1859. (left.nodetype=callparan) then
  1860. tcallparanode(left).get_paratype;
  1861. end;
  1862. dec(parsing_para_level);
  1863. end;
  1864. function tinlinenode.pass_1 : tnode;
  1865. var
  1866. hp,hpp : tnode;
  1867. shiftconst: longint;
  1868. begin
  1869. result:=nil;
  1870. { if we handle writeln; left contains no valid address }
  1871. if assigned(left) then
  1872. begin
  1873. if left.nodetype=callparan then
  1874. tcallparanode(left).firstcallparan
  1875. else
  1876. firstpass(left);
  1877. left_max;
  1878. end;
  1879. inc(parsing_para_level);
  1880. { intern const should already be handled }
  1881. if nf_inlineconst in flags then
  1882. internalerror(200104044);
  1883. case inlinenumber of
  1884. in_lo_qword,
  1885. in_hi_qword,
  1886. in_lo_long,
  1887. in_hi_long,
  1888. in_lo_word,
  1889. in_hi_word:
  1890. begin
  1891. shiftconst := 0;
  1892. case inlinenumber of
  1893. in_hi_qword:
  1894. shiftconst := 32;
  1895. in_hi_long:
  1896. shiftconst := 16;
  1897. in_hi_word:
  1898. shiftconst := 8;
  1899. end;
  1900. if shiftconst <> 0 then
  1901. result := ctypeconvnode.create_explicit(cshlshrnode.create(shrn,left,
  1902. cordconstnode.create(shiftconst,u32inttype,false)),resulttype)
  1903. else
  1904. result := ctypeconvnode.create_explicit(left,resulttype);
  1905. left := nil;
  1906. firstpass(result);
  1907. end;
  1908. in_sizeof_x:
  1909. begin
  1910. if registersint<1 then
  1911. registersint:=1;
  1912. expectloc:=LOC_REGISTER;
  1913. end;
  1914. in_typeof_x:
  1915. begin
  1916. if registersint<1 then
  1917. registersint:=1;
  1918. expectloc:=LOC_REGISTER;
  1919. end;
  1920. in_length_x:
  1921. begin
  1922. if is_shortstring(left.resulttype.def) then
  1923. expectloc:=left.expectloc
  1924. else
  1925. begin
  1926. { ansi/wide string }
  1927. if registersint<1 then
  1928. registersint:=1;
  1929. expectloc:=LOC_REGISTER;
  1930. end;
  1931. end;
  1932. in_typeinfo_x:
  1933. begin
  1934. expectloc:=LOC_REGISTER;
  1935. registersint:=1;
  1936. end;
  1937. in_assigned_x:
  1938. begin
  1939. expectloc := LOC_JUMP;
  1940. registersint:=1;
  1941. end;
  1942. in_pred_x,
  1943. in_succ_x:
  1944. begin
  1945. if is_64bit(resulttype.def) then
  1946. begin
  1947. if (registersint<2) then
  1948. registersint:=2
  1949. end
  1950. else
  1951. begin
  1952. if (registersint<1) then
  1953. registersint:=1;
  1954. end;
  1955. expectloc:=LOC_REGISTER;
  1956. end;
  1957. in_setlength_x,
  1958. in_initialize_x,
  1959. in_finalize_x:
  1960. begin
  1961. expectloc:=LOC_VOID;
  1962. end;
  1963. in_inc_x,
  1964. in_dec_x:
  1965. begin
  1966. expectloc:=LOC_VOID;
  1967. { check type }
  1968. if
  1969. {$ifndef cpu64bit}
  1970. is_64bit(left.resulttype.def) or
  1971. {$endif cpu64bit}
  1972. { range/overflow checking doesn't work properly }
  1973. { with the inc/dec code that's generated (JM) }
  1974. (
  1975. (left.resulttype.def.deftype = orddef) and
  1976. not(is_char(left.resulttype.def)) and
  1977. not(is_boolean(left.resulttype.def)) and
  1978. (aktlocalswitches * [cs_check_overflow,cs_check_range] <> [])
  1979. ) then
  1980. { convert to simple add (JM) }
  1981. begin
  1982. { extra parameter? }
  1983. if assigned(tcallparanode(left).right) then
  1984. begin
  1985. { Yes, use for add node }
  1986. hpp := tcallparanode(tcallparanode(left).right).left;
  1987. tcallparanode(tcallparanode(left).right).left := nil;
  1988. if assigned(tcallparanode(tcallparanode(left).right).right) then
  1989. CGMessage(parser_e_illegal_expression);
  1990. end
  1991. else
  1992. { no, create constant 1 }
  1993. hpp := cordconstnode.create(1,tcallparanode(left).left.resulttype,false);
  1994. { addition/substraction depending on inc/dec }
  1995. if inlinenumber = in_inc_x then
  1996. hp := caddnode.create(addn,tcallparanode(left).left.getcopy,hpp)
  1997. else
  1998. hp := caddnode.create(subn,tcallparanode(left).left.getcopy,hpp);
  1999. { assign result of addition }
  2000. hpp := cassignmentnode.create(tcallparanode(left).left,hp);
  2001. tcallparanode(left).left := nil;
  2002. { firstpass it }
  2003. firstpass(hpp);
  2004. { return new node }
  2005. result := hpp;
  2006. end
  2007. else if (left.resulttype.def.deftype in [enumdef,pointerdef]) or
  2008. is_ordinal(left.resulttype.def) then
  2009. begin
  2010. { two paras ? }
  2011. if assigned(tcallparanode(left).right) then
  2012. begin
  2013. { need we an additional register ? }
  2014. if not(is_constintnode(tcallparanode(tcallparanode(left).right).left)) and
  2015. (tcallparanode(tcallparanode(left).right).left.expectloc in [LOC_CREFERENCE,LOC_REFERENCE]) and
  2016. (tcallparanode(tcallparanode(left).right).left.registersint<=1) then
  2017. inc(registersint);
  2018. { do we need an additional register to restore the first parameter? }
  2019. if tcallparanode(tcallparanode(left).right).left.registersint>=registersint then
  2020. inc(registersint);
  2021. end;
  2022. end;
  2023. end;
  2024. in_include_x_y,
  2025. in_exclude_x_y:
  2026. begin
  2027. expectloc:=LOC_VOID;
  2028. registersint:=left.registersint;
  2029. registersfpu:=left.registersfpu;
  2030. {$ifdef SUPPORT_MMX}
  2031. registersmmx:=left.registersmmx;
  2032. {$endif SUPPORT_MMX}
  2033. end;
  2034. in_cos_extended:
  2035. begin
  2036. result:= first_cos_real;
  2037. end;
  2038. in_sin_extended:
  2039. begin
  2040. result := first_sin_real;
  2041. end;
  2042. in_arctan_extended:
  2043. begin
  2044. result := first_arctan_real;
  2045. end;
  2046. in_pi:
  2047. begin
  2048. result := first_pi;
  2049. end;
  2050. in_abs_extended:
  2051. begin
  2052. result := first_abs_real;
  2053. end;
  2054. in_sqr_extended:
  2055. begin
  2056. result := first_sqr_real;
  2057. end;
  2058. in_sqrt_extended:
  2059. begin
  2060. result := first_sqrt_real;
  2061. end;
  2062. in_ln_extended:
  2063. begin
  2064. result := first_ln_real;
  2065. end;
  2066. {$ifdef SUPPORT_MMX}
  2067. in_mmx_pcmpeqb..in_mmx_pcmpgtw:
  2068. begin
  2069. end;
  2070. {$endif SUPPORT_MMX}
  2071. in_assert_x_y :
  2072. begin
  2073. expectloc:=LOC_VOID;
  2074. registersint:=left.registersint;
  2075. registersfpu:=left.registersfpu;
  2076. {$ifdef SUPPORT_MMX}
  2077. registersmmx:=left.registersmmx;
  2078. {$endif SUPPORT_MMX}
  2079. end;
  2080. in_low_x,
  2081. in_high_x:
  2082. internalerror(200104047);
  2083. in_ord_x,
  2084. in_chr_byte:
  2085. begin
  2086. { should not happend as it's converted to typeconv }
  2087. internalerror(200104045);
  2088. end;
  2089. in_ofs_x :
  2090. internalerror(2000101001);
  2091. in_seg_x :
  2092. internalerror(200104046);
  2093. in_settextbuf_file_x,
  2094. in_reset_typedfile,
  2095. in_rewrite_typedfile,
  2096. in_str_x_string,
  2097. in_val_x,
  2098. in_read_x,
  2099. in_readln_x,
  2100. in_write_x,
  2101. in_writeln_x :
  2102. begin
  2103. { should be handled by det_resulttype }
  2104. internalerror(200108234);
  2105. end;
  2106. in_prefetch_var:
  2107. begin
  2108. expectloc:=LOC_VOID;
  2109. end;
  2110. else
  2111. internalerror(8);
  2112. end;
  2113. dec(parsing_para_level);
  2114. end;
  2115. {$ifdef fpc}
  2116. {$maxfpuregisters default}
  2117. {$endif fpc}
  2118. function tinlinenode.docompare(p: tnode): boolean;
  2119. begin
  2120. docompare :=
  2121. inherited docompare(p) and
  2122. (inlinenumber = tinlinenode(p).inlinenumber);
  2123. end;
  2124. function tinlinenode.first_pi : tnode;
  2125. begin
  2126. result := crealconstnode.create(pi,pbestrealtype^);
  2127. end;
  2128. function tinlinenode.first_arctan_real : tnode;
  2129. begin
  2130. { create the call to the helper }
  2131. { on entry left node contains the parameter }
  2132. first_arctan_real := ccallnode.createintern('fpc_arctan_real',
  2133. ccallparanode.create(left,nil));
  2134. left := nil;
  2135. end;
  2136. function tinlinenode.first_abs_real : tnode;
  2137. begin
  2138. { create the call to the helper }
  2139. { on entry left node contains the parameter }
  2140. first_abs_real := ccallnode.createintern('fpc_abs_real',
  2141. ccallparanode.create(left,nil));
  2142. left := nil;
  2143. end;
  2144. function tinlinenode.first_sqr_real : tnode;
  2145. begin
  2146. { create the call to the helper }
  2147. { on entry left node contains the parameter }
  2148. first_sqr_real := ccallnode.createintern('fpc_sqr_real',
  2149. ccallparanode.create(left,nil));
  2150. left := nil;
  2151. end;
  2152. function tinlinenode.first_sqrt_real : tnode;
  2153. begin
  2154. { create the call to the helper }
  2155. { on entry left node contains the parameter }
  2156. first_sqrt_real := ccallnode.createintern('fpc_sqrt_real',
  2157. ccallparanode.create(left,nil));
  2158. left := nil;
  2159. end;
  2160. function tinlinenode.first_ln_real : tnode;
  2161. begin
  2162. { create the call to the helper }
  2163. { on entry left node contains the parameter }
  2164. first_ln_real := ccallnode.createintern('fpc_ln_real',
  2165. ccallparanode.create(left,nil));
  2166. left := nil;
  2167. end;
  2168. function tinlinenode.first_cos_real : tnode;
  2169. begin
  2170. { create the call to the helper }
  2171. { on entry left node contains the parameter }
  2172. first_cos_real := ccallnode.createintern('fpc_cos_real',
  2173. ccallparanode.create(left,nil));
  2174. left := nil;
  2175. end;
  2176. function tinlinenode.first_sin_real : tnode;
  2177. begin
  2178. { create the call to the helper }
  2179. { on entry left node contains the parameter }
  2180. first_sin_real := ccallnode.createintern('fpc_sin_real',
  2181. ccallparanode.create(left,nil));
  2182. left := nil;
  2183. end;
  2184. begin
  2185. cinlinenode:=tinlinenode;
  2186. end.
  2187. {
  2188. $Log$
  2189. Revision 1.137 2004-06-18 15:16:46 peter
  2190. * remove obsolete cardinal() typecasts
  2191. Revision 1.136 2004/06/16 20:07:08 florian
  2192. * dwarf branch merged
  2193. Revision 1.135 2004/05/28 21:15:20 peter
  2194. * inc(x,y) makes y always of type x to prevent 64bit operations
  2195. when x is a u32bit and y is signed
  2196. Revision 1.134 2004/05/23 18:28:41 peter
  2197. * methodpointer is loaded into a temp when it was a calln
  2198. Revision 1.133.2.9 2004/05/03 16:49:00 peter
  2199. * sizeof fixed
  2200. Revision 1.133.2.8 2004/05/02 11:26:05 peter
  2201. * fixed i386 readln(qword)
  2202. Revision 1.133.2.7 2004/05/01 21:30:17 peter
  2203. * fixed read for int64/qword
  2204. Revision 1.133.2.6 2004/05/01 20:51:19 peter
  2205. * fix val code parameter
  2206. Revision 1.133.2.5 2004/05/01 16:35:51 florian
  2207. * fixed length(<ansi/widestring>) for 64 Bit CPUs
  2208. Revision 1.133.2.4 2004/04/29 19:50:36 peter
  2209. * fixed val for 64bit
  2210. Revision 1.133.2.3 2004/04/29 19:07:22 peter
  2211. * compile fixes
  2212. Revision 1.133.2.2 2004/04/28 19:55:51 peter
  2213. * new warning for ordinal-pointer when size is different
  2214. * fixed some cg_e_ messages to the correct section type_e_ or parser_e_
  2215. Revision 1.133.2.1 2004/04/26 21:05:09 peter
  2216. * size of classes is now stored as aint
  2217. Revision 1.133 2004/03/18 16:19:03 peter
  2218. * fixed operator overload allowing for pointer-string
  2219. * replaced some type_e_mismatch with more informational messages
  2220. Revision 1.132 2004/02/20 21:55:59 peter
  2221. * procvar cleanup
  2222. Revision 1.131 2004/02/04 18:45:29 jonas
  2223. + some more usage of register temps
  2224. Revision 1.130 2004/02/03 22:32:54 peter
  2225. * renamed xNNbittype to xNNinttype
  2226. * renamed registers32 to registersint
  2227. * replace some s32bit,u32bit with torddef([su]inttype).def.typ
  2228. Revision 1.129 2004/02/03 16:46:51 jonas
  2229. + support to store ttempcreate/ref/deletenodes in registers
  2230. * put temps for withnodes and some newnodes in registers
  2231. Note: this currently only works because calling ungetregister()
  2232. multiple times for the same register doesn't matter. We need again
  2233. a way to specify that a register is currently a regvar and as such
  2234. should not be freed when you call ungetregister() on it.
  2235. Revision 1.128 2004/02/02 20:41:59 florian
  2236. + added prefetch(const mem) support
  2237. Revision 1.127 2004/01/26 16:12:28 daniel
  2238. * reginfo now also only allocated during register allocation
  2239. * third round of gdb cleanups: kick out most of concatstabto
  2240. Revision 1.126 2003/12/31 20:47:02 jonas
  2241. * properly fixed assigned() mess (by handling it separately in ncginl)
  2242. -> all assigned()-related tests in the test suite work again
  2243. Revision 1.125 2003/12/27 22:27:55 peter
  2244. * support type convs for write typed
  2245. Revision 1.124 2003/12/08 21:17:12 jonas
  2246. * if there are assertions, include pi_do_call in procinfo.flags
  2247. Revision 1.123 2003/11/29 16:19:54 peter
  2248. * Initialize() added
  2249. Revision 1.122 2003/11/10 22:02:52 peter
  2250. * cross unit inlining fixed
  2251. Revision 1.121 2003/10/21 15:15:36 peter
  2252. * taicpu_abstract.oper[] changed to pointers
  2253. Revision 1.120 2003/10/08 19:19:45 peter
  2254. * set_varstate cleanup
  2255. Revision 1.119 2003/10/01 20:34:48 peter
  2256. * procinfo unit contains tprocinfo
  2257. * cginfo renamed to cgbase
  2258. * moved cgmessage to verbose
  2259. * fixed ppc and sparc compiles
  2260. Revision 1.118 2003/09/23 21:10:11 peter
  2261. * don't call firstpass in resulttypepass
  2262. Revision 1.117 2003/09/23 17:56:05 peter
  2263. * locals and paras are allocated in the code generation
  2264. * tvarsym.localloc contains the location of para/local when
  2265. generating code for the current procedure
  2266. Revision 1.116 2003/09/16 16:17:01 peter
  2267. * varspez in calls to push_addr_param
  2268. Revision 1.115 2003/09/06 16:47:24 florian
  2269. + support of NaN and Inf in the compiler as values of real constants
  2270. Revision 1.114 2003/06/13 21:19:30 peter
  2271. * current_procdef removed, use current_procinfo.procdef instead
  2272. Revision 1.113 2003/05/31 21:29:04 jonas
  2273. * constant evaluation of trunc() and round() now also gives 64 bit
  2274. results
  2275. Revision 1.112 2003/05/17 13:30:08 jonas
  2276. * changed tt_persistant to tt_persistent :)
  2277. * tempcreatenode now doesn't accept a boolean anymore for persistent
  2278. temps, but a ttemptype, so you can also create ansistring temps etc
  2279. Revision 1.111 2003/05/11 21:37:03 peter
  2280. * moved implicit exception frame from ncgutil to psub
  2281. * constructor/destructor helpers moved from cobj/ncgutil to psub
  2282. Revision 1.110 2003/05/09 17:47:02 peter
  2283. * self moved to hidden parameter
  2284. * removed hdisposen,hnewn,selfn
  2285. Revision 1.109 2003/04/27 11:21:33 peter
  2286. * aktprocdef renamed to current_procinfo.procdef
  2287. * procinfo renamed to current_procinfo
  2288. * procinfo will now be stored in current_module so it can be
  2289. cleaned up properly
  2290. * gen_main_procsym changed to create_main_proc and release_main_proc
  2291. to also generate a tprocinfo structure
  2292. * fixed unit implicit initfinal
  2293. Revision 1.108 2002/04/25 20:15:39 florian
  2294. * block nodes within expressions shouldn't release the used registers,
  2295. fixed using a flag till the new rg is ready
  2296. Revision 1.107 2003/04/23 20:16:04 peter
  2297. + added currency support based on int64
  2298. + is_64bit for use in cg units instead of is_64bitint
  2299. * removed cgmessage from n386add, replace with internalerrors
  2300. Revision 1.106 2003/04/22 23:50:23 peter
  2301. * firstpass uses expectloc
  2302. * checks if there are differences between the expectloc and
  2303. location.loc from secondpass in EXTDEBUG
  2304. Revision 1.105 2002/12/30 12:54:45 jonas
  2305. * don't allow erroneuos read(typedfile,...) statements
  2306. Revision 1.104 2002/12/30 12:48:07 jonas
  2307. * fixed web bug 2296
  2308. Revision 1.103 2002/12/17 22:19:33 peter
  2309. * fixed pushing of records>8 bytes with stdcall
  2310. * simplified hightree loading
  2311. Revision 1.102 2002/12/15 21:30:12 florian
  2312. * tcallnode.paraitem introduced, all references to defcoll removed
  2313. Revision 1.101 2002/11/27 20:04:39 peter
  2314. * cdecl array of const fixes
  2315. Revision 1.100 2002/11/27 15:33:47 peter
  2316. * the never ending story of tp procvar hacks
  2317. Revision 1.99 2002/11/27 02:37:13 peter
  2318. * case statement inlining added
  2319. * fixed inlining of write()
  2320. * switched statementnode left and right parts so the statements are
  2321. processed in the correct order when getcopy is used. This is
  2322. required for tempnodes
  2323. Revision 1.98 2002/11/25 17:43:19 peter
  2324. * splitted defbase in defutil,symutil,defcmp
  2325. * merged isconvertable and is_equal into compare_defs(_ext)
  2326. * made operator search faster by walking the list only once
  2327. Revision 1.97 2002/11/18 18:35:01 peter
  2328. * Swap(QWord) constant support
  2329. Revision 1.96 2002/11/18 17:31:57 peter
  2330. * pass proccalloption to ret_in_xxx and push_xxx functions
  2331. Revision 1.95 2002/11/16 17:59:31 peter
  2332. * load threadvar input/output variable in temp
  2333. Revision 1.94 2002/11/15 01:58:52 peter
  2334. * merged changes from 1.0.7 up to 04-11
  2335. - -V option for generating bug report tracing
  2336. - more tracing for option parsing
  2337. - errors for cdecl and high()
  2338. - win32 import stabs
  2339. - win32 records<=8 are returned in eax:edx (turned off by default)
  2340. - heaptrc update
  2341. - more info for temp management in .s file with EXTDEBUG
  2342. Revision 1.93 2002/10/10 19:24:58 florian
  2343. + write(ln) support for variants added
  2344. Revision 1.92 2002/10/10 16:07:57 florian
  2345. + several widestring/pwidechar related stuff added
  2346. Revision 1.91 2002/10/05 14:21:08 peter
  2347. * Length(PChar) supported
  2348. Revision 1.90 2002/09/13 19:12:09 carl
  2349. * only enumerations have range checking for succ/pred in const section
  2350. Revision 1.89 2002/09/09 19:41:01 peter
  2351. * check ranges for pred() and succ()
  2352. Revision 1.88 2002/09/08 13:01:25 jonas
  2353. * first_pi now just generates a constant, added missing calls to firstpass()
  2354. Revision 1.87 2002/09/07 20:42:16 carl
  2355. * cardinal -> longword
  2356. Revision 1.86 2002/09/07 12:16:04 carl
  2357. * second part bug report 1996 fix, testrange in cordconstnode
  2358. only called if option is set (also make parsing a tiny faster)
  2359. Revision 1.85 2002/09/02 19:24:42 peter
  2360. * array of char support for Str()
  2361. Revision 1.84 2002/08/19 19:36:43 peter
  2362. * More fixes for cross unit inlining, all tnodes are now implemented
  2363. * Moved pocall_internconst to po_internconst because it is not a
  2364. calling type at all and it conflicted when inlining of these small
  2365. functions was requested
  2366. Revision 1.83 2002/08/02 07:44:31 jonas
  2367. * made assigned() handling generic
  2368. * add nodes now can also evaluate constant expressions at compile time
  2369. that contain nil nodes
  2370. Revision 1.82 2002/07/29 21:23:43 florian
  2371. * more fixes for the ppc
  2372. + wrappers for the tcnvnode.first_* stuff introduced
  2373. Revision 1.81 2002/07/26 12:28:50 jonas
  2374. * don't always convert the second argument of inc/dec to a longint, but
  2375. to a type based on the first argument
  2376. Revision 1.80 2002/07/25 18:00:19 carl
  2377. + Resulttype for floats is now CPU independent (bestrealytype)
  2378. + Generic version of some routines (call to RTL routines)
  2379. : still untested.
  2380. Revision 1.79 2002/07/20 11:57:54 florian
  2381. * types.pas renamed to defbase.pas because D6 contains a types
  2382. unit so this would conflicts if D6 programms are compiled
  2383. + Willamette/SSE2 instructions to assembler added
  2384. Revision 1.78 2002/07/11 14:41:28 florian
  2385. * start of the new generic parameter handling
  2386. Revision 1.77 2002/06/06 18:53:53 jonas
  2387. * fixed fpu stack overflow in compiler when compiled with -Or
  2388. Revision 1.76 2002/05/18 13:34:10 peter
  2389. * readded missing revisions
  2390. Revision 1.75 2002/05/16 19:46:38 carl
  2391. + defines.inc -> fpcdefs.inc to avoid conflicts if compiling by hand
  2392. + try to fix temp allocation (still in ifdef)
  2393. + generic constructor calls
  2394. + start of tassembler / tmodulebase class cleanup
  2395. Revision 1.73 2002/05/12 16:53:07 peter
  2396. * moved entry and exitcode to ncgutil and cgobj
  2397. * foreach gets extra argument for passing local data to the
  2398. iterator function
  2399. * -CR checks also class typecasts at runtime by changing them
  2400. into as
  2401. * fixed compiler to cycle with the -CR option
  2402. * fixed stabs with elf writer, finally the global variables can
  2403. be watched
  2404. * removed a lot of routines from cga unit and replaced them by
  2405. calls to cgobj
  2406. * u32bit-s32bit updates for and,or,xor nodes. When one element is
  2407. u32bit then the other is typecasted also to u32bit without giving
  2408. a rangecheck warning/error.
  2409. * fixed pascal calling method with reversing also the high tree in
  2410. the parast, detected by tcalcst3 test
  2411. Revision 1.72 2002/04/23 19:16:34 peter
  2412. * add pinline unit that inserts compiler supported functions using
  2413. one or more statements
  2414. * moved finalize and setlength from ninl to pinline
  2415. Revision 1.71 2002/04/02 17:11:29 peter
  2416. * tlocation,treference update
  2417. * LOC_CONSTANT added for better constant handling
  2418. * secondadd splitted in multiple routines
  2419. * location_force_reg added for loading a location to a register
  2420. of a specified size
  2421. * secondassignment parses now first the right and then the left node
  2422. (this is compatible with Kylix). This saves a lot of push/pop especially
  2423. with string operations
  2424. * adapted some routines to use the new cg methods
  2425. Revision 1.70 2002/03/31 20:26:34 jonas
  2426. + a_loadfpu_* and a_loadmm_* methods in tcg
  2427. * register allocation is now handled by a class and is mostly processor
  2428. independent (+rgobj.pas and i386/rgcpu.pas)
  2429. * temp allocation is now handled by a class (+tgobj.pas, -i386\tgcpu.pas)
  2430. * some small improvements and fixes to the optimizer
  2431. * some register allocation fixes
  2432. * some fpuvaroffset fixes in the unary minus node
  2433. * push/popusedregisters is now called rg.save/restoreusedregisters and
  2434. (for i386) uses temps instead of push/pop's when using -Op3 (that code is
  2435. also better optimizable)
  2436. * fixed and optimized register saving/restoring for new/dispose nodes
  2437. * LOC_FPU locations now also require their "register" field to be set to
  2438. R_ST, not R_ST0 (the latter is used for LOC_CFPUREGISTER locations only)
  2439. - list field removed of the tnode class because it's not used currently
  2440. and can cause hard-to-find bugs
  2441. Revision 1.69 2002/01/24 18:25:48 peter
  2442. * implicit result variable generation for assembler routines
  2443. * removed m_tp modeswitch, use m_tp7 or not(m_fpc) instead
  2444. Revision 1.68 2002/01/19 11:53:56 peter
  2445. * constant evaluation for assinged added
  2446. }