ncgcon.pas 35 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788
  1. {
  2. $Id$
  3. Copyright (c) 1998-2002 by Florian Klaempfl
  4. Generate assembler for constant nodes which are the same for
  5. all (most) processors
  6. This program is free software; you can redistribute it and/or modify
  7. it under the terms of the GNU General Public License as published by
  8. the Free Software Foundation; either version 2 of the License, or
  9. (at your option) any later version.
  10. This program is distributed in the hope that it will be useful,
  11. but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. GNU General Public License for more details.
  14. You should have received a copy of the GNU General Public License
  15. along with this program; if not, write to the Free Software
  16. Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  17. ****************************************************************************
  18. }
  19. unit ncgcon;
  20. {$i fpcdefs.inc}
  21. interface
  22. uses
  23. node,ncon;
  24. type
  25. tcgrealconstnode = class(trealconstnode)
  26. procedure pass_2;override;
  27. end;
  28. tcgordconstnode = class(tordconstnode)
  29. procedure pass_2;override;
  30. end;
  31. tcgpointerconstnode = class(tpointerconstnode)
  32. procedure pass_2;override;
  33. end;
  34. tcgstringconstnode = class(tstringconstnode)
  35. procedure pass_2;override;
  36. end;
  37. tcgsetconstnode = class(tsetconstnode)
  38. procedure pass_2;override;
  39. end;
  40. tcgnilnode = class(tnilnode)
  41. procedure pass_2;override;
  42. end;
  43. tcgguidconstnode = class(tguidconstnode)
  44. procedure pass_2;override;
  45. end;
  46. implementation
  47. uses
  48. globtype,widestr,systems,
  49. verbose,globals,
  50. symconst,symdef,aasmbase,aasmtai,aasmcpu,defutil,
  51. cpuinfo,cpubase,
  52. cgbase,cgobj,
  53. {$ifdef delphi}
  54. ,dmisc
  55. {$endif}
  56. ncgutil
  57. ;
  58. {*****************************************************************************
  59. TCGREALCONSTNODE
  60. *****************************************************************************}
  61. procedure tcgrealconstnode.pass_2;
  62. { I suppose the parser/pass_1 must make sure the generated real }
  63. { constants are actually supported by the target processor? (JM) }
  64. const
  65. floattype2ait:array[tfloattype] of taitype=
  66. (ait_real_32bit,ait_real_64bit,ait_real_80bit,ait_comp_64bit,ait_comp_64bit,ait_real_128bit);
  67. var
  68. hp1 : tai;
  69. lastlabel : tasmlabel;
  70. realait : taitype;
  71. {$ifdef ARM}
  72. hiloswapped : boolean;
  73. {$endif ARM}
  74. begin
  75. location_reset(location,LOC_CREFERENCE,def_cgsize(resulttype.def));
  76. lastlabel:=nil;
  77. realait:=floattype2ait[tfloatdef(resulttype.def).typ];
  78. {$ifdef ARM}
  79. hiloswapped:=aktfputype in [fpu_fpa,fpu_fpa10,fpu_fpa11];
  80. {$endif ARM}
  81. { const already used ? }
  82. if not assigned(lab_real) then
  83. begin
  84. { tries to find an old entry }
  85. hp1:=tai(Consts.first);
  86. while assigned(hp1) do
  87. begin
  88. if hp1.typ=ait_label then
  89. lastlabel:=tai_label(hp1).l
  90. else
  91. begin
  92. if (hp1.typ=realait) and (lastlabel<>nil) then
  93. begin
  94. if is_number_float(value_real) and
  95. (
  96. ((realait=ait_real_32bit) and (tai_real_32bit(hp1).value=value_real) and is_number_float(tai_real_32bit(hp1).value)) or
  97. ((realait=ait_real_64bit) and
  98. {$ifdef ARM}
  99. ((tai_real_64bit(hp1).formatoptions=fo_hiloswapped)=hiloswapped) and
  100. {$endif ARM}
  101. (tai_real_64bit(hp1).value=value_real) and is_number_float(tai_real_64bit(hp1).value)) or
  102. ((realait=ait_real_80bit) and (tai_real_80bit(hp1).value=value_real) and is_number_float(tai_real_80bit(hp1).value)) or
  103. {$ifdef cpufloat128}
  104. ((realait=ait_real_128bit) and (tai_real_128bit(hp1).value=value_real) and is_number_float(tai_real_128bit(hp1).value)) or
  105. {$endif cpufloat128}
  106. ((realait=ait_comp_64bit) and (tai_comp_64bit(hp1).value=value_real) and is_number_float(tai_comp_64bit(hp1).value))
  107. ) then
  108. begin
  109. { found! }
  110. lab_real:=lastlabel;
  111. break;
  112. end;
  113. end;
  114. lastlabel:=nil;
  115. end;
  116. hp1:=tai(hp1.next);
  117. end;
  118. { :-(, we must generate a new entry }
  119. if not assigned(lab_real) then
  120. begin
  121. objectlibrary.getdatalabel(lastlabel);
  122. lab_real:=lastlabel;
  123. maybe_new_object_file(consts);
  124. new_section(consts,sec_rodata,lastlabel.name,const_align(resulttype.def.size));
  125. Consts.concat(Tai_label.Create(lastlabel));
  126. case realait of
  127. ait_real_32bit :
  128. begin
  129. Consts.concat(Tai_real_32bit.Create(ts32real(value_real)));
  130. { range checking? }
  131. if ((cs_check_range in aktlocalswitches) or
  132. (cs_check_overflow in aktlocalswitches)) and
  133. (tai_real_32bit(Consts.Last).value=double(MathInf)) then
  134. Message(parser_e_range_check_error);
  135. end;
  136. ait_real_64bit :
  137. begin
  138. {$ifdef ARM}
  139. if hiloswapped then
  140. Consts.concat(Tai_real_64bit.Create_hiloswapped(ts64real(value_real)))
  141. else
  142. {$endif ARM}
  143. Consts.concat(Tai_real_64bit.Create(ts64real(value_real)));
  144. { range checking? }
  145. if ((cs_check_range in aktlocalswitches) or
  146. (cs_check_overflow in aktlocalswitches)) and
  147. (tai_real_64bit(Consts.Last).value=double(MathInf)) then
  148. Message(parser_e_range_check_error);
  149. end;
  150. ait_real_80bit :
  151. begin
  152. Consts.concat(Tai_real_80bit.Create(value_real));
  153. { range checking? }
  154. if ((cs_check_range in aktlocalswitches) or
  155. (cs_check_overflow in aktlocalswitches)) and
  156. (tai_real_80bit(Consts.Last).value=double(MathInf)) then
  157. Message(parser_e_range_check_error);
  158. end;
  159. {$ifdef cpufloat128}
  160. ait_real_128bit :
  161. begin
  162. Consts.concat(Tai_real_128bit.Create(value_real));
  163. { range checking? }
  164. if ((cs_check_range in aktlocalswitches) or
  165. (cs_check_overflow in aktlocalswitches)) and
  166. (tai_real_128bit(Consts.Last).value=double(MathInf)) then
  167. Message(parser_e_range_check_error);
  168. end;
  169. {$endif cpufloat128}
  170. {$ifdef ver1_0}
  171. ait_comp_64bit :
  172. Consts.concat(Tai_comp_64bit.Create(value_real));
  173. {$else ver1_0}
  174. { the round is necessary for native compilers where comp isn't a float }
  175. ait_comp_64bit :
  176. begin
  177. if (value_real>9223372036854775807.0) or (value_real<-9223372036854775808.0) then
  178. Message(parser_e_range_check_error)
  179. else
  180. Consts.concat(Tai_comp_64bit.Create(round(value_real)));
  181. end;
  182. {$endif ver1_0}
  183. else
  184. internalerror(10120);
  185. end;
  186. end;
  187. end;
  188. location.reference.symbol:=lab_real;
  189. end;
  190. {*****************************************************************************
  191. TCGORDCONSTNODE
  192. *****************************************************************************}
  193. procedure tcgordconstnode.pass_2;
  194. begin
  195. location_reset(location,LOC_CONSTANT,def_cgsize(resulttype.def));
  196. {$ifdef cpu64bit}
  197. location.value:=value;
  198. {$else cpu64bit}
  199. location.value64:=int64(value);
  200. {$endif cpu64bit}
  201. end;
  202. {*****************************************************************************
  203. TCGPOINTERCONSTNODE
  204. *****************************************************************************}
  205. procedure tcgpointerconstnode.pass_2;
  206. begin
  207. { an integer const. behaves as a memory reference }
  208. location_reset(location,LOC_CONSTANT,OS_ADDR);
  209. location.value:=aint(value);
  210. end;
  211. {*****************************************************************************
  212. TCGSTRINGCONSTNODE
  213. *****************************************************************************}
  214. procedure tcgstringconstnode.pass_2;
  215. var
  216. hp1,hp2 : tai;
  217. l1,l2,
  218. lastlabel : tasmlabel;
  219. lastlabelhp : tai;
  220. pc : pchar;
  221. same_string : boolean;
  222. l,j,
  223. i,mylength : longint;
  224. begin
  225. { for empty ansistrings we could return a constant 0 }
  226. {$ifdef ansistring_bits}
  227. if (st_type in [st_ansistring16,st_ansistring32,st_ansistring64,st_widestring]) and (len=0) then
  228. {$else}
  229. if (st_type in [st_ansistring,st_widestring]) and (len=0) then
  230. {$endif}
  231. begin
  232. location_reset(location,LOC_CONSTANT,OS_ADDR);
  233. location.value:=0;
  234. exit;
  235. end;
  236. { return a constant reference in memory }
  237. location_reset(location,LOC_CREFERENCE,def_cgsize(resulttype.def));
  238. { const already used ? }
  239. lastlabel:=nil;
  240. lastlabelhp:=nil;
  241. if not assigned(lab_str) then
  242. begin
  243. if is_shortstring(resulttype.def) then
  244. mylength:=len+2
  245. else
  246. mylength:=len+1;
  247. { widestrings can't be reused yet }
  248. if not(is_widestring(resulttype.def)) then
  249. begin
  250. { tries to found an old entry }
  251. hp1:=tai(Consts.first);
  252. while assigned(hp1) do
  253. begin
  254. if hp1.typ=ait_label then
  255. begin
  256. lastlabel:=tai_label(hp1).l;
  257. lastlabelhp:=hp1;
  258. end
  259. else
  260. begin
  261. same_string:=false;
  262. if (hp1.typ=ait_string) and
  263. (lastlabel<>nil) and
  264. (tai_string(hp1).len=mylength) then
  265. begin
  266. { if shortstring then check the length byte first and
  267. set the start index to 1 }
  268. case st_type of
  269. st_shortstring:
  270. begin
  271. if len=ord(tai_string(hp1).str[0]) then
  272. begin
  273. j:=1;
  274. same_string:=true;
  275. if len>0 then
  276. begin
  277. for i:=0 to len-1 do
  278. begin
  279. if tai_string(hp1).str[j]<>value_str[i] then
  280. begin
  281. same_string:=false;
  282. break;
  283. end;
  284. inc(j);
  285. end;
  286. end;
  287. end;
  288. end;
  289. {$ifdef ansistring_bits}
  290. st_ansistring16:
  291. begin
  292. { before the string the following sequence must be found:
  293. <label>
  294. constsymbol <datalabel>
  295. const32 <len>
  296. const32 <len>
  297. const32 -1
  298. we must then return <label> to reuse
  299. }
  300. hp2:=tai(lastlabelhp.previous);
  301. if assigned(hp2) and
  302. (hp2.typ=ait_const_16bit) and
  303. (tai_const(hp2).value=aword(-1)) and
  304. assigned(hp2.previous) and
  305. (tai(hp2.previous).typ=ait_const_16bit) and
  306. (tai_const(hp2.previous).value=len) and
  307. assigned(hp2.previous.previous) and
  308. (tai(hp2.previous.previous).typ=ait_const_16bit) and
  309. (tai_const(hp2.previous.previous).value=len) and
  310. assigned(hp2.previous.previous.previous) and
  311. (tai(hp2.previous.previous.previous).typ=ait_const_symbol) and
  312. assigned(hp2.previous.previous.previous.previous) and
  313. (tai(hp2.previous.previous.previous.previous).typ=ait_label) then
  314. begin
  315. lastlabel:=tai_label(hp2.previous.previous.previous.previous).l;
  316. same_string:=true;
  317. j:=0;
  318. if len>0 then
  319. begin
  320. for i:=0 to len-1 do
  321. begin
  322. if tai_string(hp1).str[j]<>value_str[i] then
  323. begin
  324. same_string:=false;
  325. break;
  326. end;
  327. inc(j);
  328. end;
  329. end;
  330. end;
  331. end;
  332. {$endif}
  333. {$ifdef ansistring_bits}
  334. st_ansistring32,
  335. {$else}
  336. st_ansistring,
  337. {$endif}
  338. st_widestring :
  339. begin
  340. { before the string the following sequence must be found:
  341. <label>
  342. constsymbol <datalabel>
  343. constint -1
  344. constint <len>
  345. we must then return <label> to reuse
  346. }
  347. hp2:=tai(lastlabelhp.previous);
  348. if assigned(hp2) and
  349. (hp2.typ=ait_const_aint) and
  350. (tai_const(hp2).value=-1) and
  351. assigned(hp2.previous) and
  352. (tai(hp2.previous).typ=ait_const_aint) and
  353. (tai_const(hp2.previous).value=len) and
  354. assigned(hp2.previous.previous) and
  355. (tai(hp2.previous.previous).typ=ait_const_ptr) and
  356. assigned(hp2.previous.previous.previous) and
  357. (tai(hp2.previous.previous.previous).typ=ait_label) then
  358. begin
  359. lastlabel:=tai_label(hp2.previous.previous.previous).l;
  360. same_string:=true;
  361. j:=0;
  362. if len>0 then
  363. begin
  364. for i:=0 to len-1 do
  365. begin
  366. if tai_string(hp1).str[j]<>value_str[i] then
  367. begin
  368. same_string:=false;
  369. break;
  370. end;
  371. inc(j);
  372. end;
  373. end;
  374. end;
  375. end;
  376. {$ifdef ansistring_bits}
  377. st_ansistring64:
  378. begin
  379. { before the string the following sequence must be found:
  380. <label>
  381. constsymbol <datalabel>
  382. const32 <len>
  383. const32 <len>
  384. const32 -1
  385. we must then return <label> to reuse
  386. }
  387. hp2:=tai(lastlabelhp.previous);
  388. if assigned(hp2) and
  389. (hp2.typ=ait_const_64bit) and
  390. (tai_const(hp2).value=aword(-1)) and
  391. assigned(hp2.previous) and
  392. (tai(hp2.previous).typ=ait_const_64bit) and
  393. (tai_const(hp2.previous).value=len) and
  394. assigned(hp2.previous.previous) and
  395. (tai(hp2.previous.previous).typ=ait_const_64bit) and
  396. (tai_const(hp2.previous.previous).value=len) and
  397. assigned(hp2.previous.previous.previous) and
  398. (tai(hp2.previous.previous.previous).typ=ait_const_symbol) and
  399. assigned(hp2.previous.previous.previous.previous) and
  400. (tai(hp2.previous.previous.previous.previous).typ=ait_label) then
  401. begin
  402. lastlabel:=tai_label(hp2.previous.previous.previous.previous).l;
  403. same_string:=true;
  404. j:=0;
  405. if len>0 then
  406. begin
  407. for i:=0 to len-1 do
  408. begin
  409. if tai_string(hp1).str[j]<>value_str[i] then
  410. begin
  411. same_string:=false;
  412. break;
  413. end;
  414. inc(j);
  415. end;
  416. end;
  417. end;
  418. end;
  419. {$endif}
  420. end;
  421. { found ? }
  422. if same_string then
  423. begin
  424. lab_str:=lastlabel;
  425. break;
  426. end;
  427. end;
  428. lastlabel:=nil;
  429. end;
  430. hp1:=tai(hp1.next);
  431. end;
  432. end;
  433. { :-(, we must generate a new entry }
  434. if not assigned(lab_str) then
  435. begin
  436. objectlibrary.getdatalabel(lastlabel);
  437. lab_str:=lastlabel;
  438. maybe_new_object_file(consts);
  439. new_section(consts,sec_rodata,lastlabel.name,const_align(sizeof(aint)));
  440. Consts.concat(Tai_label.Create(lastlabel));
  441. { generate an ansi string ? }
  442. case st_type of
  443. {$ifdef ansistring_bits}
  444. st_ansistring16:
  445. begin
  446. { an empty ansi string is nil! }
  447. if len=0 then
  448. Consts.concat(Tai_const.Create_ptr(0))
  449. else
  450. begin
  451. objectlibrary.getdatalabel(l1);
  452. objectlibrary.getdatalabel(l2);
  453. Consts.concat(Tai_label.Create(l2));
  454. Consts.concat(Tai_const_symbol.Create(l1));
  455. Consts.concat(Tai_const.Create_32bit(-1));
  456. Consts.concat(Tai_const.Create_32bit(len));
  457. Consts.concat(Tai_label.Create(l1));
  458. getmem(pc,len+2);
  459. move(value_str^,pc^,len);
  460. pc[len]:=#0;
  461. { to overcome this problem we set the length explicitly }
  462. { with the ending null char }
  463. Consts.concat(Tai_string.Create_length_pchar(pc,len+1));
  464. { return the offset of the real string }
  465. lab_str:=l2;
  466. end;
  467. end;
  468. {$endif}
  469. {$ifdef ansistring_bits}st_ansistring32:{$else}st_ansistring:{$endif}
  470. begin
  471. { an empty ansi string is nil! }
  472. if len=0 then
  473. Consts.concat(Tai_const.Create_sym(nil))
  474. else
  475. begin
  476. objectlibrary.getdatalabel(l1);
  477. objectlibrary.getdatalabel(l2);
  478. Consts.concat(Tai_label.Create(l2));
  479. Consts.concat(Tai_const.Create_sym(l1));
  480. Consts.concat(Tai_const.Create_aint(-1));
  481. Consts.concat(Tai_const.Create_aint(len));
  482. Consts.concat(Tai_label.Create(l1));
  483. getmem(pc,len+2);
  484. move(value_str^,pc^,len);
  485. pc[len]:=#0;
  486. { to overcome this problem we set the length explicitly }
  487. { with the ending null char }
  488. Consts.concat(Tai_string.Create_length_pchar(pc,len+1));
  489. { return the offset of the real string }
  490. lab_str:=l2;
  491. end;
  492. end;
  493. {$ifdef ansistring_bits}
  494. st_ansistring64:
  495. begin
  496. { an empty ansi string is nil! }
  497. if len=0 then
  498. Consts.concat(Tai_const.Create_ptr(0))
  499. else
  500. begin
  501. objectlibrary.getdatalabel(l1);
  502. objectlibrary.getdatalabel(l2);
  503. Consts.concat(Tai_label.Create(l2));
  504. Consts.concat(Tai_const_symbol.Create(l1));
  505. Consts.concat(Tai_const.Create_32bit(-1));
  506. Consts.concat(Tai_const.Create_32bit(len));
  507. Consts.concat(Tai_label.Create(l1));
  508. getmem(pc,len+2);
  509. move(value_str^,pc^,len);
  510. pc[len]:=#0;
  511. { to overcome this problem we set the length explicitly }
  512. { with the ending null char }
  513. Consts.concat(Tai_string.Create_length_pchar(pc,len+1));
  514. { return the offset of the real string }
  515. lab_str:=l2;
  516. end;
  517. end;
  518. {$endif}
  519. st_widestring:
  520. begin
  521. { an empty wide string is nil! }
  522. if len=0 then
  523. Consts.concat(Tai_const.Create_sym(nil))
  524. else
  525. begin
  526. objectlibrary.getdatalabel(l1);
  527. objectlibrary.getdatalabel(l2);
  528. Consts.concat(Tai_label.Create(l2));
  529. Consts.concat(Tai_const.Create_sym(l1));
  530. { we use always UTF-16 coding for constants }
  531. { at least for now }
  532. { Consts.concat(Tai_const.Create_8bit(2)); }
  533. Consts.concat(Tai_const.Create_aint(-1));
  534. Consts.concat(Tai_const.Create_aint(len));
  535. Consts.concat(Tai_label.Create(l1));
  536. for i:=0 to len-1 do
  537. Consts.concat(Tai_const.Create_16bit(pcompilerwidestring(value_str)^.data[i]));
  538. { terminating zero }
  539. Consts.concat(Tai_const.Create_16bit(0));
  540. { return the offset of the real string }
  541. lab_str:=l2;
  542. end;
  543. end;
  544. st_shortstring:
  545. begin
  546. { truncate strings larger than 255 chars }
  547. if len>255 then
  548. l:=255
  549. else
  550. l:=len;
  551. { also length and terminating zero }
  552. getmem(pc,l+3);
  553. move(value_str^,pc[1],l+1);
  554. pc[0]:=chr(l);
  555. { to overcome this problem we set the length explicitly }
  556. { with the ending null char }
  557. pc[l+1]:=#0;
  558. Consts.concat(Tai_string.Create_length_pchar(pc,l+2));
  559. end;
  560. end;
  561. end;
  562. end;
  563. location.reference.symbol:=lab_str;
  564. end;
  565. {*****************************************************************************
  566. TCGSETCONSTNODE
  567. *****************************************************************************}
  568. procedure tcgsetconstnode.pass_2;
  569. var
  570. hp1 : tai;
  571. lastlabel : tasmlabel;
  572. i : longint;
  573. neededtyp : taitype;
  574. indexadjust : longint;
  575. type
  576. setbytes=array[0..31] of byte;
  577. Psetbytes=^setbytes;
  578. begin
  579. { xor indexadjust with indexes in a set typecasted to an array of }
  580. { bytes to get the correct locations, also when endianess of source }
  581. { and destiantion differs (JM) }
  582. if (source_info.endian = target_info.endian) then
  583. indexadjust := 0
  584. else
  585. indexadjust := 3;
  586. { small sets are loaded as constants }
  587. if tsetdef(resulttype.def).settype=smallset then
  588. begin
  589. location_reset(location,LOC_CONSTANT,OS_32);
  590. location.value:=PAInt(value_set)^;
  591. exit;
  592. end;
  593. location_reset(location,LOC_CREFERENCE,OS_NO);
  594. neededtyp:=ait_const_8bit;
  595. lastlabel:=nil;
  596. { const already used ? }
  597. if not assigned(lab_set) then
  598. begin
  599. { tries to found an old entry }
  600. hp1:=tai(Consts.first);
  601. while assigned(hp1) do
  602. begin
  603. if hp1.typ=ait_label then
  604. lastlabel:=tai_label(hp1).l
  605. else
  606. begin
  607. if (lastlabel<>nil) and (hp1.typ=neededtyp) then
  608. begin
  609. if (hp1.typ=ait_const_8bit) then
  610. begin
  611. { compare normal set }
  612. i:=0;
  613. while assigned(hp1) and (i<32) do
  614. begin
  615. if tai_const(hp1).value<>Psetbytes(value_set)^[i xor indexadjust] then
  616. break;
  617. inc(i);
  618. hp1:=tai(hp1.next);
  619. end;
  620. if i=32 then
  621. begin
  622. { found! }
  623. lab_set:=lastlabel;
  624. break;
  625. end;
  626. { leave when the end of consts is reached, so no
  627. hp1.next is done }
  628. if not assigned(hp1) then
  629. break;
  630. end
  631. else
  632. begin
  633. { compare small set }
  634. if paint(value_set)^=tai_const(hp1).value then
  635. begin
  636. { found! }
  637. lab_set:=lastlabel;
  638. break;
  639. end;
  640. end;
  641. end;
  642. lastlabel:=nil;
  643. end;
  644. hp1:=tai(hp1.next);
  645. end;
  646. { :-(, we must generate a new entry }
  647. if not assigned(lab_set) then
  648. begin
  649. objectlibrary.getdatalabel(lastlabel);
  650. lab_set:=lastlabel;
  651. maybe_new_object_file(consts);
  652. new_section(consts,sec_rodata,lastlabel.name,const_align(sizeof(aint)));
  653. Consts.concat(Tai_label.Create(lastlabel));
  654. { already handled at the start of this method?? (JM)
  655. if tsetdef(resulttype.def).settype=smallset then
  656. begin
  657. move(value_set^,i,sizeof(longint));
  658. Consts.concat(Tai_const.Create_32bit(i));
  659. end
  660. else
  661. }
  662. begin
  663. for i:=0 to 31 do
  664. Consts.concat(Tai_const.Create_8bit(Psetbytes(value_set)^[i xor indexadjust]));
  665. end;
  666. end;
  667. end;
  668. location.reference.symbol:=lab_set;
  669. end;
  670. {*****************************************************************************
  671. TCGNILNODE
  672. *****************************************************************************}
  673. procedure tcgnilnode.pass_2;
  674. begin
  675. location_reset(location,LOC_CONSTANT,OS_ADDR);
  676. location.value:=0;
  677. end;
  678. {*****************************************************************************
  679. TCGPOINTERCONSTNODE
  680. *****************************************************************************}
  681. procedure tcgguidconstnode.pass_2;
  682. var
  683. tmplabel : TAsmLabel;
  684. i : integer;
  685. begin
  686. location_reset(location,LOC_CREFERENCE,OS_NO);
  687. { label for GUID }
  688. objectlibrary.getdatalabel(tmplabel);
  689. consts.concat(tai_align.create(const_align(16)));
  690. consts.concat(Tai_label.Create(tmplabel));
  691. consts.concat(Tai_const.Create_32bit(value.D1));
  692. consts.concat(Tai_const.Create_16bit(value.D2));
  693. consts.concat(Tai_const.Create_16bit(value.D3));
  694. for i:=Low(value.D4) to High(value.D4) do
  695. consts.concat(Tai_const.Create_8bit(value.D4[i]));
  696. location.reference.symbol:=tmplabel;
  697. end;
  698. begin
  699. crealconstnode:=tcgrealconstnode;
  700. cordconstnode:=tcgordconstnode;
  701. cpointerconstnode:=tcgpointerconstnode;
  702. cstringconstnode:=tcgstringconstnode;
  703. csetconstnode:=tcgsetconstnode;
  704. cnilnode:=tcgnilnode;
  705. cguidconstnode:=tcgguidconstnode;
  706. end.
  707. {
  708. $Log$
  709. Revision 1.45 2004-08-08 16:00:56 florian
  710. * constant floating point assignments etc. are now overflow checked
  711. if Q+ or R+ is turned on
  712. Revision 1.44 2004/07/12 17:58:19 peter
  713. * remove maxlen field from ansistring/widestrings
  714. Revision 1.43 2004/06/20 08:55:29 florian
  715. * logs truncated
  716. Revision 1.42 2004/06/18 15:16:46 peter
  717. * remove obsolete cardinal() typecasts
  718. Revision 1.41 2004/06/16 20:07:08 florian
  719. * dwarf branch merged
  720. Revision 1.40 2004/04/29 19:56:37 daniel
  721. * Prepare compiler infrastructure for multiple ansistring types
  722. Revision 1.39.2.9 2004/06/13 10:51:16 florian
  723. * fixed several register allocator problems (sparc/arm)
  724. Revision 1.39.2.8 2004/06/12 17:01:01 florian
  725. * fixed compilation of arm compiler
  726. }