ninl.pas 103 KB

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