ncgcon.pas 32 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696
  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. tcgdataconstnode = class(tdataconstnode)
  25. procedure pass_generate_code;override;
  26. end;
  27. tcgrealconstnode = class(trealconstnode)
  28. procedure pass_generate_code;override;
  29. end;
  30. tcgordconstnode = class(tordconstnode)
  31. procedure pass_generate_code;override;
  32. end;
  33. tcgpointerconstnode = class(tpointerconstnode)
  34. procedure pass_generate_code;override;
  35. end;
  36. tcgstringconstnode = class(tstringconstnode)
  37. procedure pass_generate_code;override;
  38. end;
  39. tcgsetconstnode = class(tsetconstnode)
  40. procedure pass_generate_code;override;
  41. end;
  42. tcgnilnode = class(tnilnode)
  43. procedure pass_generate_code;override;
  44. end;
  45. tcgguidconstnode = class(tguidconstnode)
  46. procedure pass_generate_code;override;
  47. end;
  48. implementation
  49. uses
  50. globtype,widestr,systems,
  51. verbose,globals,cutils,
  52. symconst,symdef,aasmbase,aasmtai,aasmdata,aasmcpu,defutil,
  53. cpuinfo,cpubase,
  54. cgbase,cgobj,cgutils,
  55. ncgutil
  56. ;
  57. {*****************************************************************************
  58. TCGREALCONSTNODE
  59. *****************************************************************************}
  60. procedure tcgdataconstnode.pass_generate_code;
  61. var
  62. l : tasmlabel;
  63. i : longint;
  64. b : byte;
  65. begin
  66. location_reset(location,LOC_CREFERENCE,OS_NO);
  67. current_asmdata.getdatalabel(l);
  68. maybe_new_object_file(current_asmdata.asmlists[al_typedconsts]);
  69. new_section(current_asmdata.asmlists[al_typedconsts],sec_rodata,l.name,const_align(maxalign));
  70. current_asmdata.asmlists[al_typedconsts].concat(Tai_label.Create(l));
  71. data.seek(0);
  72. for i:=0 to data.size-1 do
  73. begin
  74. data.read(b,1);
  75. current_asmdata.asmlists[al_typedconsts].concat(Tai_const.Create_8bit(b));
  76. end;
  77. location.reference.symbol:=l;
  78. end;
  79. {*****************************************************************************
  80. TCGREALCONSTNODE
  81. *****************************************************************************}
  82. procedure tcgrealconstnode.pass_generate_code;
  83. { I suppose the parser/pass_1 must make sure the generated real }
  84. { constants are actually supported by the target processor? (JM) }
  85. const
  86. floattype2ait:array[tfloattype] of taitype=
  87. (ait_real_32bit,ait_real_64bit,ait_real_80bit,ait_comp_64bit,ait_comp_64bit,ait_real_128bit);
  88. var
  89. hp1 : tai;
  90. lastlabel : tasmlabel;
  91. realait : taitype;
  92. {$ifdef ARM}
  93. hiloswapped : boolean;
  94. {$endif ARM}
  95. begin
  96. location_reset(location,LOC_CREFERENCE,def_cgsize(resultdef));
  97. lastlabel:=nil;
  98. realait:=floattype2ait[tfloatdef(resultdef).floattype];
  99. {$ifdef ARM}
  100. hiloswapped:=is_double_hilo_swapped;
  101. {$endif ARM}
  102. { const already used ? }
  103. if not assigned(lab_real) then
  104. begin
  105. { tries to find an old entry }
  106. hp1:=tai(current_asmdata.asmlists[al_typedconsts].first);
  107. while assigned(hp1) do
  108. begin
  109. if hp1.typ=ait_label then
  110. lastlabel:=tai_label(hp1).labsym
  111. else
  112. begin
  113. if (hp1.typ=realait) and (lastlabel<>nil) then
  114. begin
  115. if is_number_float(value_real) and
  116. (
  117. ((realait=ait_real_32bit) and (tai_real_32bit(hp1).value=value_real) and is_number_float(tai_real_32bit(hp1).value) and (get_real_sign(value_real) = get_real_sign(tai_real_32bit(hp1).value))) or
  118. ((realait=ait_real_64bit) and
  119. {$ifdef ARM}
  120. ((tai_real_64bit(hp1).formatoptions=fo_hiloswapped)=hiloswapped) and
  121. {$endif ARM}
  122. (tai_real_64bit(hp1).value=value_real) and is_number_float(tai_real_64bit(hp1).value) and (get_real_sign(value_real) = get_real_sign(tai_real_64bit(hp1).value))) or
  123. ((realait=ait_real_80bit) and (tai_real_80bit(hp1).value=value_real) and is_number_float(tai_real_80bit(hp1).value) and (get_real_sign(value_real) = get_real_sign(tai_real_80bit(hp1).value))) or
  124. {$ifdef cpufloat128}
  125. ((realait=ait_real_128bit) and (tai_real_128bit(hp1).value=value_real) and is_number_float(tai_real_128bit(hp1).value) and (get_real_sign(value_real) = get_real_sign(tai_real_128bit(hp1).value))) or
  126. {$endif cpufloat128}
  127. ((realait=ait_comp_64bit) and (tai_comp_64bit(hp1).value=value_real) and is_number_float(tai_comp_64bit(hp1).value) and (get_real_sign(value_real) = get_real_sign(tai_comp_64bit(hp1).value)))
  128. ) then
  129. begin
  130. { found! }
  131. lab_real:=lastlabel;
  132. break;
  133. end;
  134. end;
  135. lastlabel:=nil;
  136. end;
  137. hp1:=tai(hp1.next);
  138. end;
  139. { :-(, we must generate a new entry }
  140. if not assigned(lab_real) then
  141. begin
  142. current_asmdata.getdatalabel(lastlabel);
  143. lab_real:=lastlabel;
  144. maybe_new_object_file(current_asmdata.asmlists[al_typedconsts]);
  145. new_section(current_asmdata.asmlists[al_typedconsts],sec_rodata_norel,lastlabel.name,const_align(resultdef.size));
  146. current_asmdata.asmlists[al_typedconsts].concat(Tai_label.Create(lastlabel));
  147. case realait of
  148. ait_real_32bit :
  149. begin
  150. current_asmdata.asmlists[al_typedconsts].concat(Tai_real_32bit.Create(ts32real(value_real)));
  151. { range checking? }
  152. if floating_point_range_check_error and
  153. (tai_real_32bit(current_asmdata.asmlists[al_typedconsts].last).value=MathInf.Value) then
  154. Message(parser_e_range_check_error);
  155. end;
  156. ait_real_64bit :
  157. begin
  158. {$ifdef ARM}
  159. if hiloswapped then
  160. current_asmdata.asmlists[al_typedconsts].concat(Tai_real_64bit.Create_hiloswapped(ts64real(value_real)))
  161. else
  162. {$endif ARM}
  163. current_asmdata.asmlists[al_typedconsts].concat(Tai_real_64bit.Create(ts64real(value_real)));
  164. { range checking? }
  165. if floating_point_range_check_error and
  166. (tai_real_64bit(current_asmdata.asmlists[al_typedconsts].last).value=MathInf.Value) then
  167. Message(parser_e_range_check_error);
  168. end;
  169. ait_real_80bit :
  170. begin
  171. current_asmdata.asmlists[al_typedconsts].concat(Tai_real_80bit.Create(value_real));
  172. { range checking? }
  173. if floating_point_range_check_error and
  174. (tai_real_80bit(current_asmdata.asmlists[al_typedconsts].last).value=MathInf.Value) then
  175. Message(parser_e_range_check_error);
  176. end;
  177. {$ifdef cpufloat128}
  178. ait_real_128bit :
  179. begin
  180. current_asmdata.asmlists[al_typedconsts].concat(Tai_real_128bit.Create(value_real));
  181. { range checking? }
  182. if floating_point_range_check_error and
  183. (tai_real_128bit(current_asmdata.asmlists[al_typedconsts].last).value=MathInf.Value) then
  184. Message(parser_e_range_check_error);
  185. end;
  186. {$endif cpufloat128}
  187. { the round is necessary for native compilers where comp isn't a float }
  188. ait_comp_64bit :
  189. if (value_real>9223372036854775807.0) or (value_real<-9223372036854775808.0) then
  190. message(parser_e_range_check_error)
  191. else
  192. current_asmdata.asmlists[al_typedconsts].concat(Tai_comp_64bit.Create(round(value_real)));
  193. else
  194. internalerror(10120);
  195. end;
  196. end;
  197. end;
  198. location.reference.symbol:=lab_real;
  199. end;
  200. {*****************************************************************************
  201. TCGORDCONSTNODE
  202. *****************************************************************************}
  203. procedure tcgordconstnode.pass_generate_code;
  204. begin
  205. location_reset(location,LOC_CONSTANT,def_cgsize(resultdef));
  206. {$ifdef cpu64bitalu}
  207. location.value:=value.svalue;
  208. {$else cpu64bitalu}
  209. location.value64:=value.svalue;
  210. {$endif cpu64bitalu}
  211. end;
  212. {*****************************************************************************
  213. TCGPOINTERCONSTNODE
  214. *****************************************************************************}
  215. procedure tcgpointerconstnode.pass_generate_code;
  216. begin
  217. { an integer const. behaves as a memory reference }
  218. location_reset(location,LOC_CONSTANT,OS_ADDR);
  219. location.value:=aint(value);
  220. end;
  221. {*****************************************************************************
  222. TCGSTRINGCONSTNODE
  223. *****************************************************************************}
  224. procedure tcgstringconstnode.pass_generate_code;
  225. var
  226. hp1,hp2 : tai;
  227. l1,
  228. lastlabel : tasmlabel;
  229. lastlabelhp : tai;
  230. pc : pchar;
  231. same_string : boolean;
  232. l,j,
  233. i,mylength : longint;
  234. begin
  235. { for empty ansistrings we could return a constant 0 }
  236. if (cst_type in [cst_ansistring,cst_widestring]) and (len=0) then
  237. begin
  238. location_reset(location,LOC_CONSTANT,OS_ADDR);
  239. location.value:=0;
  240. exit;
  241. end;
  242. { return a constant reference in memory }
  243. location_reset(location,LOC_CREFERENCE,def_cgsize(resultdef));
  244. { const already used ? }
  245. lastlabel:=nil;
  246. lastlabelhp:=nil;
  247. if not assigned(lab_str) then
  248. begin
  249. if is_shortstring(resultdef) then
  250. mylength:=len+2
  251. else
  252. mylength:=len+1;
  253. { widestrings can't be reused yet }
  254. if not(is_widestring(resultdef)) then
  255. begin
  256. { tries to find an old entry }
  257. hp1:=tai(current_asmdata.asmlists[al_typedconsts].first);
  258. while assigned(hp1) do
  259. begin
  260. if hp1.typ=ait_label then
  261. begin
  262. lastlabel:=tai_label(hp1).labsym;
  263. lastlabelhp:=hp1;
  264. end
  265. else
  266. begin
  267. same_string:=false;
  268. if (hp1.typ=ait_string) and
  269. (lastlabel<>nil) and
  270. (tai_string(hp1).len=mylength) then
  271. begin
  272. case cst_type of
  273. cst_conststring:
  274. begin
  275. j:=0;
  276. same_string:=true;
  277. if len>0 then
  278. begin
  279. for i:=0 to len-1 do
  280. begin
  281. if tai_string(hp1).str[j]<>value_str[i] then
  282. begin
  283. same_string:=false;
  284. break;
  285. end;
  286. inc(j);
  287. end;
  288. end;
  289. end;
  290. cst_shortstring:
  291. begin
  292. { if shortstring then check the length byte first and
  293. set the start index to 1 }
  294. if len=ord(tai_string(hp1).str[0]) then
  295. begin
  296. j:=1;
  297. same_string:=true;
  298. if len>0 then
  299. begin
  300. for i:=0 to len-1 do
  301. begin
  302. if tai_string(hp1).str[j]<>value_str[i] then
  303. begin
  304. same_string:=false;
  305. break;
  306. end;
  307. inc(j);
  308. end;
  309. end;
  310. end;
  311. end;
  312. cst_ansistring,
  313. cst_widestring :
  314. begin
  315. { before the string the following sequence must be found:
  316. <label>
  317. constsymbol <datalabel>
  318. constint -1
  319. constint <len>
  320. we must then return <label> to reuse
  321. }
  322. hp2:=tai(lastlabelhp.previous);
  323. if assigned(hp2) and
  324. (hp2.typ=ait_const) and
  325. (tai_const(hp2).consttype=aitconst_aint) and
  326. (tai_const(hp2).value=len) and
  327. assigned(hp2.previous) and
  328. (tai(hp2.previous).typ=ait_const) and
  329. (tai_const(hp2.previous).consttype=aitconst_aint) and
  330. (tai_const(hp2.previous).value=-1) and
  331. assigned(hp2.previous.previous) and
  332. (tai(hp2.previous.previous).typ=ait_const) and
  333. (tai_const(hp2.previous.previous).consttype=aitconst_ptr) and
  334. assigned(hp2.previous.previous.previous) and
  335. (tai(hp2.previous.previous.previous).typ=ait_label) then
  336. begin
  337. lastlabel:=tai_label(hp2.previous.previous.previous).labsym;
  338. same_string:=true;
  339. j:=0;
  340. if len>0 then
  341. begin
  342. for i:=0 to len-1 do
  343. begin
  344. if tai_string(hp1).str[j]<>value_str[i] then
  345. begin
  346. same_string:=false;
  347. break;
  348. end;
  349. inc(j);
  350. end;
  351. end;
  352. end;
  353. end;
  354. end;
  355. { found ? }
  356. if same_string then
  357. begin
  358. lab_str:=lastlabel;
  359. break;
  360. end;
  361. end;
  362. lastlabel:=nil;
  363. end;
  364. hp1:=tai(hp1.next);
  365. end;
  366. end;
  367. { :-(, we must generate a new entry }
  368. if not assigned(lab_str) then
  369. begin
  370. current_asmdata.getdatalabel(lastlabel);
  371. lab_str:=lastlabel;
  372. maybe_new_object_file(current_asmdata.asmlists[al_typedconsts]);
  373. if (len=0) or
  374. not(cst_type in [cst_ansistring,cst_widestring]) then
  375. new_section(current_asmdata.asmlists[al_typedconsts],sec_rodata_norel,lastlabel.name,const_align(sizeof(pint)))
  376. else
  377. new_section(current_asmdata.asmlists[al_typedconsts],sec_rodata,lastlabel.name,const_align(sizeof(pint)));
  378. current_asmdata.asmlists[al_typedconsts].concat(Tai_label.Create(lastlabel));
  379. { generate an ansi string ? }
  380. case cst_type of
  381. cst_ansistring:
  382. begin
  383. { an empty ansi string is nil! }
  384. if len=0 then
  385. current_asmdata.asmlists[al_typedconsts].concat(Tai_const.Create_sym(nil))
  386. else
  387. begin
  388. current_asmdata.getdatalabel(l1);
  389. current_asmdata.asmlists[al_typedconsts].concat(Tai_const.Create_sym(l1));
  390. current_asmdata.asmlists[al_typedconsts].concat(Tai_const.Create_pint(-1));
  391. current_asmdata.asmlists[al_typedconsts].concat(Tai_const.Create_pint(len));
  392. { make sure the string doesn't get dead stripped if the header is referenced }
  393. if (target_info.system in systems_darwin) then
  394. current_asmdata.asmlists[al_typedconsts].concat(tai_directive.create(asd_reference,l1.name));
  395. current_asmdata.asmlists[al_typedconsts].concat(Tai_label.Create(l1));
  396. { ... and vice versa }
  397. if (target_info.system in systems_darwin) then
  398. current_asmdata.asmlists[al_typedconsts].concat(tai_directive.create(asd_reference,lab_str.name));
  399. { include also terminating zero }
  400. getmem(pc,len+1);
  401. move(value_str^,pc^,len);
  402. pc[len]:=#0;
  403. current_asmdata.asmlists[al_typedconsts].concat(Tai_string.Create_pchar(pc,len+1));
  404. end;
  405. end;
  406. cst_widestring:
  407. begin
  408. { an empty wide string is nil! }
  409. if len=0 then
  410. current_asmdata.asmlists[al_typedconsts].concat(Tai_const.Create_sym(nil))
  411. else
  412. begin
  413. current_asmdata.getdatalabel(l1);
  414. current_asmdata.asmlists[al_typedconsts].concat(Tai_const.Create_sym(l1));
  415. { we use always UTF-16 coding for constants }
  416. { at least for now }
  417. { Consts.concat(Tai_const.Create_8bit(2)); }
  418. if tf_winlikewidestring in target_info.flags then
  419. current_asmdata.asmlists[al_typedconsts].concat(Tai_const.Create_32bit(len*cwidechartype.size))
  420. else
  421. begin
  422. current_asmdata.asmlists[al_typedconsts].concat(Tai_const.Create_pint(-1));
  423. current_asmdata.asmlists[al_typedconsts].concat(Tai_const.Create_pint(len*cwidechartype.size));
  424. end;
  425. { make sure the string doesn't get dead stripped if the header is referenced }
  426. if (target_info.system in systems_darwin) then
  427. current_asmdata.asmlists[al_typedconsts].concat(tai_directive.create(asd_reference,l1.name));
  428. current_asmdata.asmlists[al_typedconsts].concat(Tai_label.Create(l1));
  429. { ... and vice versa }
  430. if (target_info.system in systems_darwin) then
  431. current_asmdata.asmlists[al_typedconsts].concat(tai_directive.create(asd_reference,lab_str.name));
  432. for i:=0 to len-1 do
  433. current_asmdata.asmlists[al_typedconsts].concat(Tai_const.Create_16bit(pcompilerwidestring(value_str)^.data[i]));
  434. { terminating zero }
  435. current_asmdata.asmlists[al_typedconsts].concat(Tai_const.Create_16bit(0));
  436. end;
  437. end;
  438. cst_shortstring:
  439. begin
  440. { truncate strings larger than 255 chars }
  441. if len>255 then
  442. l:=255
  443. else
  444. l:=len;
  445. { include length and terminating zero for quick conversion to pchar }
  446. getmem(pc,l+2);
  447. move(value_str^,pc[1],l);
  448. pc[0]:=chr(l);
  449. pc[l+1]:=#0;
  450. current_asmdata.asmlists[al_typedconsts].concat(Tai_string.Create_pchar(pc,l+2));
  451. end;
  452. cst_conststring:
  453. begin
  454. { include terminating zero }
  455. getmem(pc,len+1);
  456. move(value_str^,pc[0],len);
  457. pc[len]:=#0;
  458. current_asmdata.asmlists[al_typedconsts].concat(Tai_string.Create_pchar(pc,len+1));
  459. end;
  460. end;
  461. end;
  462. end;
  463. location.reference.symbol:=lab_str;
  464. end;
  465. {*****************************************************************************
  466. TCGSETCONSTNODE
  467. *****************************************************************************}
  468. procedure tcgsetconstnode.pass_generate_code;
  469. type
  470. setbytes=array[0..31] of byte;
  471. Psetbytes=^setbytes;
  472. procedure smallsetconst;
  473. begin
  474. location_reset(location,LOC_CONSTANT,int_cgsize(resultdef.size));
  475. if (source_info.endian=target_info.endian) then
  476. begin
  477. {$if defined(FPC_NEW_BIGENDIAN_SETS) or defined(FPC_LITTLE_ENDIAN)}
  478. { not plongint, because that will "sign extend" the set on 64 bit platforms }
  479. { if changed to "paword", please also modify "32-resultdef.size*8" and }
  480. { cross-endian code below }
  481. { Extra aint type cast to avoid range errors }
  482. location.value:=aint(pCardinal(value_set)^)
  483. {$else}
  484. location.value:=reverse_byte(Psetbytes(value_set)^[0]);
  485. location.value:=location.value or (reverse_byte(Psetbytes(value_set)^[1]) shl 8);
  486. location.value:=location.value or (reverse_byte(Psetbytes(value_set)^[2]) shl 16);
  487. location.value:=location.value or (reverse_byte(Psetbytes(value_set)^[3]) shl 24);
  488. {$endif}
  489. end
  490. else
  491. begin
  492. location.value:=swapendian(Pcardinal(value_set)^);
  493. location.value:= reverse_byte (location.value and $ff) or
  494. (reverse_byte((location.value shr 8) and $ff) shl 8) or
  495. (reverse_byte((location.value shr 16) and $ff) shl 16) or
  496. (reverse_byte((location.value shr 24) and $ff) shl 24);
  497. end;
  498. if (target_info.endian=endian_big) then
  499. location.value:=location.value shr (32-resultdef.size*8);
  500. end;
  501. procedure varsetconst;
  502. var
  503. hp1 : tai;
  504. lastlabel : tasmlabel;
  505. i, diff : longint;
  506. neededtyp : taiconst_type;
  507. begin
  508. location_reset(location,LOC_CREFERENCE,OS_NO);
  509. neededtyp:=aitconst_8bit;
  510. lastlabel:=nil;
  511. { const already used ? }
  512. if not assigned(lab_set) then
  513. begin
  514. { tries to found an old entry }
  515. hp1:=tai(current_asmdata.asmlists[al_typedconsts].first);
  516. while assigned(hp1) do
  517. begin
  518. if hp1.typ=ait_label then
  519. lastlabel:=tai_label(hp1).labsym
  520. else
  521. begin
  522. if (lastlabel<>nil) and
  523. (hp1.typ=ait_const) and
  524. (tai_const(hp1).consttype=neededtyp) then
  525. begin
  526. if (tai_const(hp1).consttype=aitconst_8bit) then
  527. begin
  528. { compare normal set }
  529. i:=0;
  530. while assigned(hp1) and (i<32) do
  531. begin
  532. if (source_info.endian=target_info.endian) then
  533. begin
  534. {$if defined(FPC_NEW_BIGENDIAN_SETS) or defined(FPC_LITTLE_ENDIAN)}
  535. if tai_const(hp1).value<>Psetbytes(value_set)^[i ] then
  536. {$else}
  537. if tai_const(hp1).value<>reverse_byte(Psetbytes(value_set)^[i xor 3]) then
  538. {$endif}
  539. break
  540. end
  541. else if tai_const(hp1).value<>reverse_byte(Psetbytes(value_set)^[i]) then
  542. break;
  543. inc(i);
  544. hp1:=tai(hp1.next);
  545. end;
  546. if i=32 then
  547. begin
  548. { found! }
  549. lab_set:=lastlabel;
  550. break;
  551. end;
  552. { leave when the end of consts is reached, so no
  553. hp1.next is done }
  554. if not assigned(hp1) then
  555. break;
  556. end
  557. else
  558. begin
  559. { compare small set }
  560. if paint(value_set)^=tai_const(hp1).value then
  561. begin
  562. { found! }
  563. lab_set:=lastlabel;
  564. break;
  565. end;
  566. end;
  567. end;
  568. lastlabel:=nil;
  569. end;
  570. hp1:=tai(hp1.next);
  571. end;
  572. { :-(, we must generate a new entry }
  573. if not assigned(lab_set) then
  574. begin
  575. current_asmdata.getdatalabel(lastlabel);
  576. lab_set:=lastlabel;
  577. maybe_new_object_file(current_asmdata.asmlists[al_typedconsts]);
  578. new_section(current_asmdata.asmlists[al_typedconsts],sec_rodata_norel,lastlabel.name,const_align(sizeof(pint)));
  579. current_asmdata.asmlists[al_typedconsts].concat(Tai_label.Create(lastlabel));
  580. if (source_info.endian=target_info.endian) then
  581. {$if defined(FPC_NEW_BIGENDIAN_SETS) or defined(FPC_LITTLE_ENDIAN)}
  582. for i:=0 to 31 do
  583. current_asmdata.asmlists[al_typedconsts].concat(Tai_const.Create_8bit(Psetbytes(value_set)^[i]))
  584. {$else}
  585. for i:=0 to 31 do
  586. current_asmdata.asmlists[al_typedconsts].concat(Tai_const.Create_8bit(reverse_byte(Psetbytes(value_set)^[i xor 3])))
  587. {$endif}
  588. else
  589. for i:=0 to 31 do
  590. current_asmdata.asmlists[al_typedconsts].concat(Tai_const.Create_8bit(reverse_byte(Psetbytes(value_set)^[i])));
  591. end;
  592. end;
  593. location.reference.symbol:=lab_set;
  594. end;
  595. begin
  596. adjustforsetbase;
  597. { small sets are loaded as constants }
  598. if is_smallset(resultdef) then
  599. smallsetconst
  600. else
  601. varsetconst;
  602. end;
  603. {*****************************************************************************
  604. TCGNILNODE
  605. *****************************************************************************}
  606. procedure tcgnilnode.pass_generate_code;
  607. begin
  608. location_reset(location,LOC_CONSTANT,OS_ADDR);
  609. location.value:=0;
  610. end;
  611. {*****************************************************************************
  612. TCGPOINTERCONSTNODE
  613. *****************************************************************************}
  614. procedure tcgguidconstnode.pass_generate_code;
  615. var
  616. tmplabel : TAsmLabel;
  617. i : integer;
  618. begin
  619. location_reset(location,LOC_CREFERENCE,OS_NO);
  620. { label for GUID }
  621. current_asmdata.getdatalabel(tmplabel);
  622. current_asmdata.asmlists[al_typedconsts].concat(tai_align.create(const_align(16)));
  623. current_asmdata.asmlists[al_typedconsts].concat(Tai_label.Create(tmplabel));
  624. current_asmdata.asmlists[al_typedconsts].concat(Tai_const.Create_32bit(longint(value.D1)));
  625. current_asmdata.asmlists[al_typedconsts].concat(Tai_const.Create_16bit(value.D2));
  626. current_asmdata.asmlists[al_typedconsts].concat(Tai_const.Create_16bit(value.D3));
  627. for i:=low(value.D4) to high(value.D4) do
  628. current_asmdata.asmlists[al_typedconsts].concat(Tai_const.Create_8bit(value.D4[i]));
  629. location.reference.symbol:=tmplabel;
  630. end;
  631. begin
  632. cdataconstnode:=tcgdataconstnode;
  633. crealconstnode:=tcgrealconstnode;
  634. cordconstnode:=tcgordconstnode;
  635. cpointerconstnode:=tcgpointerconstnode;
  636. cstringconstnode:=tcgstringconstnode;
  637. csetconstnode:=tcgsetconstnode;
  638. cnilnode:=tcgnilnode;
  639. cguidconstnode:=tcgguidconstnode;
  640. end.