ncgcon.pas 33 KB

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