ncgcon.pas 35 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743
  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(asmlist[al_typedconsts].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(asmlist[al_typedconsts]);
  120. new_section(asmlist[al_typedconsts],sec_rodata,lastlabel.name,const_align(resulttype.def.size));
  121. asmlist[al_typedconsts].concat(Tai_label.Create(lastlabel));
  122. case realait of
  123. ait_real_32bit :
  124. begin
  125. asmlist[al_typedconsts].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(asmlist[al_typedconsts].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. asmlist[al_typedconsts].concat(Tai_real_64bit.Create_hiloswapped(ts64real(value_real)))
  137. else
  138. {$endif ARM}
  139. asmlist[al_typedconsts].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(asmlist[al_typedconsts].last).value=double(MathInf)) then
  144. Message(parser_e_range_check_error);
  145. end;
  146. ait_real_80bit :
  147. begin
  148. asmlist[al_typedconsts].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(asmlist[al_typedconsts].last).value=double(MathInf)) then
  153. Message(parser_e_range_check_error);
  154. end;
  155. {$ifdef cpufloat128}
  156. ait_real_128bit :
  157. begin
  158. asmlist[al_typedconsts].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(asmlist[al_typedconsts].last).value=double(MathInf)) then
  163. Message(parser_e_range_check_error);
  164. end;
  165. {$endif cpufloat128}
  166. { the round is necessary for native compilers where comp isn't a float }
  167. ait_comp_64bit :
  168. if (value_real>9223372036854775807.0) or (value_real<-9223372036854775808.0) then
  169. message(parser_e_range_check_error)
  170. else
  171. asmlist[al_typedconsts].concat(Tai_comp_64bit.Create(round(value_real)));
  172. else
  173. internalerror(10120);
  174. end;
  175. end;
  176. end;
  177. location.reference.symbol:=lab_real;
  178. end;
  179. {*****************************************************************************
  180. TCGORDCONSTNODE
  181. *****************************************************************************}
  182. procedure tcgordconstnode.pass_2;
  183. begin
  184. location_reset(location,LOC_CONSTANT,def_cgsize(resulttype.def));
  185. {$ifdef cpu64bit}
  186. location.value:=value;
  187. {$else cpu64bit}
  188. location.value64:=int64(value);
  189. {$endif cpu64bit}
  190. end;
  191. {*****************************************************************************
  192. TCGPOINTERCONSTNODE
  193. *****************************************************************************}
  194. procedure tcgpointerconstnode.pass_2;
  195. begin
  196. { an integer const. behaves as a memory reference }
  197. location_reset(location,LOC_CONSTANT,OS_ADDR);
  198. location.value:=aint(value);
  199. end;
  200. {*****************************************************************************
  201. TCGSTRINGCONSTNODE
  202. *****************************************************************************}
  203. procedure tcgstringconstnode.pass_2;
  204. var
  205. hp1,hp2 : tai;
  206. l1,l2,
  207. lastlabel : tasmlabel;
  208. lastlabelhp : tai;
  209. pc : pchar;
  210. same_string : boolean;
  211. l,j,
  212. i,mylength : longint;
  213. begin
  214. { for empty ansistrings we could return a constant 0 }
  215. {$ifdef ansistring_bits}
  216. if (st_type in [st_ansistring16,st_ansistring32,st_ansistring64,st_widestring]) and (len=0) then
  217. {$else}
  218. if (st_type in [st_ansistring,st_widestring]) and (len=0) then
  219. {$endif}
  220. begin
  221. location_reset(location,LOC_CONSTANT,OS_ADDR);
  222. location.value:=0;
  223. exit;
  224. end;
  225. { return a constant reference in memory }
  226. location_reset(location,LOC_CREFERENCE,def_cgsize(resulttype.def));
  227. { const already used ? }
  228. lastlabel:=nil;
  229. lastlabelhp:=nil;
  230. if not assigned(lab_str) then
  231. begin
  232. if is_shortstring(resulttype.def) then
  233. mylength:=len+2
  234. else
  235. mylength:=len+1;
  236. { widestrings can't be reused yet }
  237. if not(is_widestring(resulttype.def)) then
  238. begin
  239. { tries to find an old entry }
  240. hp1:=tai(asmlist[al_typedconsts].first);
  241. while assigned(hp1) do
  242. begin
  243. if hp1.typ=ait_label then
  244. begin
  245. lastlabel:=tai_label(hp1).l;
  246. lastlabelhp:=hp1;
  247. end
  248. else
  249. begin
  250. same_string:=false;
  251. if (hp1.typ=ait_string) and
  252. (lastlabel<>nil) and
  253. (tai_string(hp1).len=mylength) then
  254. begin
  255. { if shortstring then check the length byte first and
  256. set the start index to 1 }
  257. case st_type of
  258. st_shortstring:
  259. begin
  260. if len=ord(tai_string(hp1).str[0]) then
  261. begin
  262. j:=1;
  263. same_string:=true;
  264. if len>0 then
  265. begin
  266. for i:=0 to len-1 do
  267. begin
  268. if tai_string(hp1).str[j]<>value_str[i] then
  269. begin
  270. same_string:=false;
  271. break;
  272. end;
  273. inc(j);
  274. end;
  275. end;
  276. end;
  277. end;
  278. {$ifdef ansistring_bits}
  279. st_ansistring16:
  280. begin
  281. { before the string the following sequence must be found:
  282. <label>
  283. constsymbol <datalabel>
  284. const32 <len>
  285. const32 <len>
  286. const32 -1
  287. we must then return <label> to reuse
  288. }
  289. hp2:=tai(lastlabelhp.previous);
  290. if assigned(hp2) and
  291. (hp2.typ=ait_const_16bit) and
  292. (tai_const(hp2).value=aword(-1)) and
  293. assigned(hp2.previous) and
  294. (tai(hp2.previous).typ=ait_const_16bit) and
  295. (tai_const(hp2.previous).value=len) and
  296. assigned(hp2.previous.previous) and
  297. (tai(hp2.previous.previous).typ=ait_const_16bit) and
  298. (tai_const(hp2.previous.previous).value=len) and
  299. assigned(hp2.previous.previous.previous) and
  300. (tai(hp2.previous.previous.previous).typ=ait_const_symbol) and
  301. assigned(hp2.previous.previous.previous.previous) and
  302. (tai(hp2.previous.previous.previous.previous).typ=ait_label) then
  303. begin
  304. lastlabel:=tai_label(hp2.previous.previous.previous.previous).l;
  305. same_string:=true;
  306. j:=0;
  307. if len>0 then
  308. begin
  309. for i:=0 to len-1 do
  310. begin
  311. if tai_string(hp1).str[j]<>value_str[i] then
  312. begin
  313. same_string:=false;
  314. break;
  315. end;
  316. inc(j);
  317. end;
  318. end;
  319. end;
  320. end;
  321. {$endif}
  322. {$ifdef ansistring_bits}
  323. st_ansistring32,
  324. {$else}
  325. st_ansistring,
  326. {$endif}
  327. st_widestring :
  328. begin
  329. { before the string the following sequence must be found:
  330. <label>
  331. constsymbol <datalabel>
  332. constint -1
  333. constint <len>
  334. we must then return <label> to reuse
  335. }
  336. hp2:=tai(lastlabelhp.previous);
  337. if assigned(hp2) and
  338. (hp2.typ=ait_const_aint) and
  339. (tai_const(hp2).value=-1) and
  340. assigned(hp2.previous) and
  341. (tai(hp2.previous).typ=ait_const_aint) and
  342. (tai_const(hp2.previous).value=len) and
  343. assigned(hp2.previous.previous) and
  344. (tai(hp2.previous.previous).typ=ait_const_ptr) and
  345. assigned(hp2.previous.previous.previous) and
  346. (tai(hp2.previous.previous.previous).typ=ait_label) then
  347. begin
  348. lastlabel:=tai_label(hp2.previous.previous.previous).l;
  349. same_string:=true;
  350. j:=0;
  351. if len>0 then
  352. begin
  353. for i:=0 to len-1 do
  354. begin
  355. if tai_string(hp1).str[j]<>value_str[i] then
  356. begin
  357. same_string:=false;
  358. break;
  359. end;
  360. inc(j);
  361. end;
  362. end;
  363. end;
  364. end;
  365. {$ifdef ansistring_bits}
  366. st_ansistring64:
  367. begin
  368. { before the string the following sequence must be found:
  369. <label>
  370. constsymbol <datalabel>
  371. const32 <len>
  372. const32 <len>
  373. const32 -1
  374. we must then return <label> to reuse
  375. }
  376. hp2:=tai(lastlabelhp.previous);
  377. if assigned(hp2) and
  378. (hp2.typ=ait_const_64bit) and
  379. (tai_const(hp2).value=aword(-1)) and
  380. assigned(hp2.previous) and
  381. (tai(hp2.previous).typ=ait_const_64bit) and
  382. (tai_const(hp2.previous).value=len) and
  383. assigned(hp2.previous.previous) and
  384. (tai(hp2.previous.previous).typ=ait_const_64bit) and
  385. (tai_const(hp2.previous.previous).value=len) and
  386. assigned(hp2.previous.previous.previous) and
  387. (tai(hp2.previous.previous.previous).typ=ait_const_symbol) and
  388. assigned(hp2.previous.previous.previous.previous) and
  389. (tai(hp2.previous.previous.previous.previous).typ=ait_label) then
  390. begin
  391. lastlabel:=tai_label(hp2.previous.previous.previous.previous).l;
  392. same_string:=true;
  393. j:=0;
  394. if len>0 then
  395. begin
  396. for i:=0 to len-1 do
  397. begin
  398. if tai_string(hp1).str[j]<>value_str[i] then
  399. begin
  400. same_string:=false;
  401. break;
  402. end;
  403. inc(j);
  404. end;
  405. end;
  406. end;
  407. end;
  408. {$endif}
  409. end;
  410. { found ? }
  411. if same_string then
  412. begin
  413. lab_str:=lastlabel;
  414. break;
  415. end;
  416. end;
  417. lastlabel:=nil;
  418. end;
  419. hp1:=tai(hp1.next);
  420. end;
  421. end;
  422. { :-(, we must generate a new entry }
  423. if not assigned(lab_str) then
  424. begin
  425. objectlibrary.getdatalabel(lastlabel);
  426. lab_str:=lastlabel;
  427. maybe_new_object_file(asmlist[al_typedconsts]);
  428. new_section(asmlist[al_typedconsts],sec_rodata,lastlabel.name,const_align(sizeof(aint)));
  429. asmlist[al_typedconsts].concat(Tai_label.Create(lastlabel));
  430. { generate an ansi string ? }
  431. case st_type of
  432. {$ifdef ansistring_bits}
  433. st_ansistring16:
  434. begin
  435. { an empty ansi string is nil! }
  436. if len=0 then
  437. asmlist[al_typedconsts].concat(Tai_const.Create_ptr(0))
  438. else
  439. begin
  440. objectlibrary.getdatalabel(l1);
  441. objectlibrary.getdatalabel(l2);
  442. Consts.concat(Tai_label.Create(l2));
  443. Consts.concat(Tai_const_symbol.Create(l1));
  444. Consts.concat(Tai_const.Create_32bit(-1));
  445. Consts.concat(Tai_const.Create_32bit(len));
  446. Consts.concat(Tai_label.Create(l1));
  447. getmem(pc,len+2);
  448. move(value_str^,pc^,len);
  449. pc[len]:=#0;
  450. { to overcome this problem we set the length explicitly }
  451. { with the ending null char }
  452. asmlist[al_typedconsts].concat(Tai_string.Create_length_pchar(pc,len+1));
  453. { return the offset of the real string }
  454. lab_str:=l2;
  455. end;
  456. end;
  457. {$endif}
  458. {$ifdef ansistring_bits}st_ansistring32:{$else}st_ansistring:{$endif}
  459. begin
  460. { an empty ansi string is nil! }
  461. if len=0 then
  462. asmlist[al_typedconsts].concat(Tai_const.Create_sym(nil))
  463. else
  464. begin
  465. objectlibrary.getdatalabel(l1);
  466. objectlibrary.getdatalabel(l2);
  467. asmlist[al_typedconsts].concat(Tai_label.Create(l2));
  468. asmlist[al_typedconsts].concat(Tai_const.Create_sym(l1));
  469. asmlist[al_typedconsts].concat(Tai_const.Create_aint(-1));
  470. asmlist[al_typedconsts].concat(Tai_const.Create_aint(len));
  471. asmlist[al_typedconsts].concat(Tai_label.Create(l1));
  472. getmem(pc,len+2);
  473. move(value_str^,pc^,len);
  474. pc[len]:=#0;
  475. { to overcome this problem we set the length explicitly }
  476. { with the ending null char }
  477. asmlist[al_typedconsts].concat(Tai_string.Create_length_pchar(pc,len+1));
  478. { return the offset of the real string }
  479. lab_str:=l2;
  480. end;
  481. end;
  482. {$ifdef ansistring_bits}
  483. st_ansistring64:
  484. begin
  485. { an empty ansi string is nil! }
  486. if len=0 then
  487. Consts.concat(Tai_const.Create_ptr(0))
  488. else
  489. begin
  490. objectlibrary.getdatalabel(l1);
  491. objectlibrary.getdatalabel(l2);
  492. asmlist[al_typedconsts].concat(Tai_label.Create(l2));
  493. asmlist[al_typedconsts].concat(Tai_const_symbol.Create(l1));
  494. asmlist[al_typedconsts].concat(Tai_const.Create_32bit(-1));
  495. asmlist[al_typedconsts].concat(Tai_const.Create_32bit(len));
  496. asmlist[al_typedconsts].concat(Tai_label.Create(l1));
  497. getmem(pc,len+2);
  498. move(value_str^,pc^,len);
  499. pc[len]:=#0;
  500. { to overcome this problem we set the length explicitly }
  501. { with the ending null char }
  502. asmlist[al_typedconsts].concat(Tai_string.Create_length_pchar(pc,len+1));
  503. { return the offset of the real string }
  504. lab_str:=l2;
  505. end;
  506. end;
  507. {$endif}
  508. st_widestring:
  509. begin
  510. { an empty wide string is nil! }
  511. if len=0 then
  512. asmlist[al_typedconsts].concat(Tai_const.Create_sym(nil))
  513. else
  514. begin
  515. objectlibrary.getdatalabel(l1);
  516. objectlibrary.getdatalabel(l2);
  517. asmlist[al_typedconsts].concat(Tai_label.Create(l2));
  518. asmlist[al_typedconsts].concat(Tai_const.Create_sym(l1));
  519. { we use always UTF-16 coding for constants }
  520. { at least for now }
  521. { Consts.concat(Tai_const.Create_8bit(2)); }
  522. asmlist[al_typedconsts].concat(Tai_const.Create_aint(-1));
  523. asmlist[al_typedconsts].concat(Tai_const.Create_aint(len));
  524. asmlist[al_typedconsts].concat(Tai_label.Create(l1));
  525. for i:=0 to len-1 do
  526. asmlist[al_typedconsts].concat(Tai_const.Create_16bit(pcompilerwidestring(value_str)^.data[i]));
  527. { terminating zero }
  528. asmlist[al_typedconsts].concat(Tai_const.Create_16bit(0));
  529. { return the offset of the real string }
  530. lab_str:=l2;
  531. end;
  532. end;
  533. st_shortstring:
  534. begin
  535. { truncate strings larger than 255 chars }
  536. if len>255 then
  537. l:=255
  538. else
  539. l:=len;
  540. { also length and terminating zero }
  541. getmem(pc,l+3);
  542. move(value_str^,pc[1],l+1);
  543. pc[0]:=chr(l);
  544. { to overcome this problem we set the length explicitly }
  545. { with the ending null char }
  546. pc[l+1]:=#0;
  547. asmlist[al_typedconsts].concat(Tai_string.Create_length_pchar(pc,l+2));
  548. end;
  549. end;
  550. end;
  551. end;
  552. location.reference.symbol:=lab_str;
  553. end;
  554. {*****************************************************************************
  555. TCGSETCONSTNODE
  556. *****************************************************************************}
  557. procedure tcgsetconstnode.pass_2;
  558. var
  559. hp1 : tai;
  560. lastlabel : tasmlabel;
  561. i : longint;
  562. neededtyp : taitype;
  563. indexadjust : longint;
  564. type
  565. setbytes=array[0..31] of byte;
  566. Psetbytes=^setbytes;
  567. begin
  568. { xor indexadjust with indexes in a set typecasted to an array of }
  569. { bytes to get the correct locations, also when endianess of source }
  570. { and destiantion differs (JM) }
  571. if (source_info.endian = target_info.endian) then
  572. indexadjust := 0
  573. else
  574. indexadjust := 3;
  575. { small sets are loaded as constants }
  576. if tsetdef(resulttype.def).settype=smallset then
  577. begin
  578. location_reset(location,LOC_CONSTANT,OS_32);
  579. location.value:=pLongint(value_set)^;
  580. exit;
  581. end;
  582. location_reset(location,LOC_CREFERENCE,OS_NO);
  583. neededtyp:=ait_const_8bit;
  584. lastlabel:=nil;
  585. { const already used ? }
  586. if not assigned(lab_set) then
  587. begin
  588. { tries to found an old entry }
  589. hp1:=tai(asmlist[al_typedconsts].first);
  590. while assigned(hp1) do
  591. begin
  592. if hp1.typ=ait_label then
  593. lastlabel:=tai_label(hp1).l
  594. else
  595. begin
  596. if (lastlabel<>nil) and (hp1.typ=neededtyp) then
  597. begin
  598. if (hp1.typ=ait_const_8bit) then
  599. begin
  600. { compare normal set }
  601. i:=0;
  602. while assigned(hp1) and (i<32) do
  603. begin
  604. if tai_const(hp1).value<>Psetbytes(value_set)^[i xor indexadjust] then
  605. break;
  606. inc(i);
  607. hp1:=tai(hp1.next);
  608. end;
  609. if i=32 then
  610. begin
  611. { found! }
  612. lab_set:=lastlabel;
  613. break;
  614. end;
  615. { leave when the end of consts is reached, so no
  616. hp1.next is done }
  617. if not assigned(hp1) then
  618. break;
  619. end
  620. else
  621. begin
  622. { compare small set }
  623. if paint(value_set)^=tai_const(hp1).value then
  624. begin
  625. { found! }
  626. lab_set:=lastlabel;
  627. break;
  628. end;
  629. end;
  630. end;
  631. lastlabel:=nil;
  632. end;
  633. hp1:=tai(hp1.next);
  634. end;
  635. { :-(, we must generate a new entry }
  636. if not assigned(lab_set) then
  637. begin
  638. objectlibrary.getdatalabel(lastlabel);
  639. lab_set:=lastlabel;
  640. maybe_new_object_file(asmlist[al_typedconsts]);
  641. new_section(asmlist[al_typedconsts],sec_rodata,lastlabel.name,const_align(sizeof(aint)));
  642. asmlist[al_typedconsts].concat(Tai_label.Create(lastlabel));
  643. { already handled at the start of this method?? (JM)
  644. if tsetdef(resulttype.def).settype=smallset then
  645. begin
  646. move(value_set^,i,sizeof(longint));
  647. Consts.concat(Tai_const.Create_32bit(i));
  648. end
  649. else
  650. }
  651. begin
  652. for i:=0 to 31 do
  653. asmlist[al_typedconsts].concat(Tai_const.Create_8bit(Psetbytes(value_set)^[i xor indexadjust]));
  654. end;
  655. end;
  656. end;
  657. location.reference.symbol:=lab_set;
  658. end;
  659. {*****************************************************************************
  660. TCGNILNODE
  661. *****************************************************************************}
  662. procedure tcgnilnode.pass_2;
  663. begin
  664. location_reset(location,LOC_CONSTANT,OS_ADDR);
  665. location.value:=0;
  666. end;
  667. {*****************************************************************************
  668. TCGPOINTERCONSTNODE
  669. *****************************************************************************}
  670. procedure tcgguidconstnode.pass_2;
  671. var
  672. tmplabel : TAsmLabel;
  673. i : integer;
  674. begin
  675. location_reset(location,LOC_CREFERENCE,OS_NO);
  676. { label for GUID }
  677. objectlibrary.getdatalabel(tmplabel);
  678. asmlist[al_typedconsts].concat(tai_align.create(const_align(16)));
  679. asmlist[al_typedconsts].concat(Tai_label.Create(tmplabel));
  680. asmlist[al_typedconsts].concat(Tai_const.Create_32bit(longint(value.D1)));
  681. asmlist[al_typedconsts].concat(Tai_const.Create_16bit(value.D2));
  682. asmlist[al_typedconsts].concat(Tai_const.Create_16bit(value.D3));
  683. for i:=low(value.D4) to high(value.D4) do
  684. asmlist[al_typedconsts].concat(Tai_const.Create_8bit(value.D4[i]));
  685. location.reference.symbol:=tmplabel;
  686. end;
  687. begin
  688. crealconstnode:=tcgrealconstnode;
  689. cordconstnode:=tcgordconstnode;
  690. cpointerconstnode:=tcgpointerconstnode;
  691. cstringconstnode:=tcgstringconstnode;
  692. csetconstnode:=tcgsetconstnode;
  693. cnilnode:=tcgnilnode;
  694. cguidconstnode:=tcgguidconstnode;
  695. end.