ncgcon.pas 34 KB

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