ncgcon.pas 35 KB

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