ncgcon.pas 32 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694
  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:=(current_settings.fputype in [fpu_fpa,fpu_fpa10,fpu_fpa11]) and
  101. not(cs_fp_emulation in current_settings.moduleswitches);
  102. {$ifdef FPC_DOUBLE_HILO_SWAPPED}
  103. hiloswapped:=not hiloswapped;
  104. {$endif FPC_DOUBLE_HILO_SWAPPED}
  105. {$endif ARM}
  106. { const already used ? }
  107. if not assigned(lab_real) then
  108. begin
  109. { tries to find an old entry }
  110. hp1:=tai(current_asmdata.asmlists[al_typedconsts].first);
  111. while assigned(hp1) do
  112. begin
  113. if hp1.typ=ait_label then
  114. lastlabel:=tai_label(hp1).labsym
  115. else
  116. begin
  117. if (hp1.typ=realait) and (lastlabel<>nil) then
  118. begin
  119. if is_number_float(value_real) and
  120. (
  121. ((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
  122. ((realait=ait_real_64bit) and
  123. {$ifdef ARM}
  124. ((tai_real_64bit(hp1).formatoptions=fo_hiloswapped)=hiloswapped) and
  125. {$endif ARM}
  126. (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
  127. ((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
  128. {$ifdef cpufloat128}
  129. ((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
  130. {$endif cpufloat128}
  131. ((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)))
  132. ) then
  133. begin
  134. { found! }
  135. lab_real:=lastlabel;
  136. break;
  137. end;
  138. end;
  139. lastlabel:=nil;
  140. end;
  141. hp1:=tai(hp1.next);
  142. end;
  143. { :-(, we must generate a new entry }
  144. if not assigned(lab_real) then
  145. begin
  146. current_asmdata.getdatalabel(lastlabel);
  147. lab_real:=lastlabel;
  148. maybe_new_object_file(current_asmdata.asmlists[al_typedconsts]);
  149. new_section(current_asmdata.asmlists[al_typedconsts],sec_rodata,lastlabel.name,const_align(resultdef.size));
  150. current_asmdata.asmlists[al_typedconsts].concat(Tai_label.Create(lastlabel));
  151. case realait of
  152. ait_real_32bit :
  153. begin
  154. current_asmdata.asmlists[al_typedconsts].concat(Tai_real_32bit.Create(ts32real(value_real)));
  155. { range checking? }
  156. if ((cs_check_range in current_settings.localswitches) or
  157. (cs_check_overflow in current_settings.localswitches)) and
  158. (tai_real_32bit(current_asmdata.asmlists[al_typedconsts].last).value=MathInf.Value) then
  159. Message(parser_e_range_check_error);
  160. end;
  161. ait_real_64bit :
  162. begin
  163. {$ifdef ARM}
  164. if hiloswapped then
  165. current_asmdata.asmlists[al_typedconsts].concat(Tai_real_64bit.Create_hiloswapped(ts64real(value_real)))
  166. else
  167. {$endif ARM}
  168. current_asmdata.asmlists[al_typedconsts].concat(Tai_real_64bit.Create(ts64real(value_real)));
  169. { range checking? }
  170. if ((cs_check_range in current_settings.localswitches) or
  171. (cs_check_overflow in current_settings.localswitches)) and
  172. (tai_real_64bit(current_asmdata.asmlists[al_typedconsts].last).value=MathInf.Value) then
  173. Message(parser_e_range_check_error);
  174. end;
  175. ait_real_80bit :
  176. begin
  177. current_asmdata.asmlists[al_typedconsts].concat(Tai_real_80bit.Create(value_real));
  178. { range checking? }
  179. if ((cs_check_range in current_settings.localswitches) or
  180. (cs_check_overflow in current_settings.localswitches)) and
  181. (tai_real_80bit(current_asmdata.asmlists[al_typedconsts].last).value=MathInf.Value) then
  182. Message(parser_e_range_check_error);
  183. end;
  184. {$ifdef cpufloat128}
  185. ait_real_128bit :
  186. begin
  187. current_asmdata.asmlists[al_typedconsts].concat(Tai_real_128bit.Create(value_real));
  188. { range checking? }
  189. if ((cs_check_range in current_settings.localswitches) or
  190. (cs_check_overflow in current_settings.localswitches)) and
  191. (tai_real_128bit(current_asmdata.asmlists[al_typedconsts].last).value=MathInf.Value) then
  192. Message(parser_e_range_check_error);
  193. end;
  194. {$endif cpufloat128}
  195. { the round is necessary for native compilers where comp isn't a float }
  196. ait_comp_64bit :
  197. if (value_real>9223372036854775807.0) or (value_real<-9223372036854775808.0) then
  198. message(parser_e_range_check_error)
  199. else
  200. current_asmdata.asmlists[al_typedconsts].concat(Tai_comp_64bit.Create(round(value_real)));
  201. else
  202. internalerror(10120);
  203. end;
  204. end;
  205. end;
  206. location.reference.symbol:=lab_real;
  207. end;
  208. {*****************************************************************************
  209. TCGORDCONSTNODE
  210. *****************************************************************************}
  211. procedure tcgordconstnode.pass_generate_code;
  212. begin
  213. location_reset(location,LOC_CONSTANT,def_cgsize(resultdef));
  214. {$ifdef cpu64bit}
  215. location.value:=value.svalue;
  216. {$else cpu64bit}
  217. location.value64:=value.svalue;
  218. {$endif cpu64bit}
  219. end;
  220. {*****************************************************************************
  221. TCGPOINTERCONSTNODE
  222. *****************************************************************************}
  223. procedure tcgpointerconstnode.pass_generate_code;
  224. begin
  225. { an integer const. behaves as a memory reference }
  226. location_reset(location,LOC_CONSTANT,OS_ADDR);
  227. location.value:=aint(value);
  228. end;
  229. {*****************************************************************************
  230. TCGSTRINGCONSTNODE
  231. *****************************************************************************}
  232. procedure tcgstringconstnode.pass_generate_code;
  233. var
  234. hp1,hp2 : tai;
  235. l1,l2,
  236. lastlabel : tasmlabel;
  237. lastlabelhp : tai;
  238. pc : pchar;
  239. same_string : boolean;
  240. l,j,
  241. i,mylength : longint;
  242. begin
  243. { for empty ansistrings we could return a constant 0 }
  244. if (cst_type in [cst_ansistring,cst_widestring]) and (len=0) then
  245. begin
  246. location_reset(location,LOC_CONSTANT,OS_ADDR);
  247. location.value:=0;
  248. exit;
  249. end;
  250. { return a constant reference in memory }
  251. location_reset(location,LOC_CREFERENCE,def_cgsize(resultdef));
  252. { const already used ? }
  253. lastlabel:=nil;
  254. lastlabelhp:=nil;
  255. if not assigned(lab_str) then
  256. begin
  257. if is_shortstring(resultdef) then
  258. mylength:=len+2
  259. else
  260. mylength:=len+1;
  261. { widestrings can't be reused yet }
  262. if not(is_widestring(resultdef)) then
  263. begin
  264. { tries to find an old entry }
  265. hp1:=tai(current_asmdata.asmlists[al_typedconsts].first);
  266. while assigned(hp1) do
  267. begin
  268. if hp1.typ=ait_label then
  269. begin
  270. lastlabel:=tai_label(hp1).labsym;
  271. lastlabelhp:=hp1;
  272. end
  273. else
  274. begin
  275. same_string:=false;
  276. if (hp1.typ=ait_string) and
  277. (lastlabel<>nil) and
  278. (tai_string(hp1).len=mylength) then
  279. begin
  280. case cst_type of
  281. cst_conststring:
  282. begin
  283. j:=0;
  284. same_string:=true;
  285. if len>0 then
  286. begin
  287. for i:=0 to len-1 do
  288. begin
  289. if tai_string(hp1).str[j]<>value_str[i] then
  290. begin
  291. same_string:=false;
  292. break;
  293. end;
  294. inc(j);
  295. end;
  296. end;
  297. end;
  298. cst_shortstring:
  299. begin
  300. { if shortstring then check the length byte first and
  301. set the start index to 1 }
  302. if len=ord(tai_string(hp1).str[0]) then
  303. begin
  304. j:=1;
  305. same_string:=true;
  306. if len>0 then
  307. begin
  308. for i:=0 to len-1 do
  309. begin
  310. if tai_string(hp1).str[j]<>value_str[i] then
  311. begin
  312. same_string:=false;
  313. break;
  314. end;
  315. inc(j);
  316. end;
  317. end;
  318. end;
  319. end;
  320. cst_ansistring,
  321. cst_widestring :
  322. begin
  323. { before the string the following sequence must be found:
  324. <label>
  325. constsymbol <datalabel>
  326. constint -1
  327. constint <len>
  328. we must then return <label> to reuse
  329. }
  330. hp2:=tai(lastlabelhp.previous);
  331. if assigned(hp2) and
  332. (hp2.typ=ait_const) and
  333. (tai_const(hp2).consttype=aitconst_aint) and
  334. (tai_const(hp2).value=len) and
  335. assigned(hp2.previous) and
  336. (tai(hp2.previous).typ=ait_const) and
  337. (tai_const(hp2.previous).consttype=aitconst_aint) and
  338. (tai_const(hp2.previous).value=-1) and
  339. assigned(hp2.previous.previous) and
  340. (tai(hp2.previous.previous).typ=ait_const) and
  341. (tai_const(hp2.previous.previous).consttype=aitconst_ptr) and
  342. assigned(hp2.previous.previous.previous) and
  343. (tai(hp2.previous.previous.previous).typ=ait_label) then
  344. begin
  345. lastlabel:=tai_label(hp2.previous.previous.previous).labsym;
  346. same_string:=true;
  347. j:=0;
  348. if len>0 then
  349. begin
  350. for i:=0 to len-1 do
  351. begin
  352. if tai_string(hp1).str[j]<>value_str[i] then
  353. begin
  354. same_string:=false;
  355. break;
  356. end;
  357. inc(j);
  358. end;
  359. end;
  360. end;
  361. end;
  362. end;
  363. { found ? }
  364. if same_string then
  365. begin
  366. lab_str:=lastlabel;
  367. break;
  368. end;
  369. end;
  370. lastlabel:=nil;
  371. end;
  372. hp1:=tai(hp1.next);
  373. end;
  374. end;
  375. { :-(, we must generate a new entry }
  376. if not assigned(lab_str) then
  377. begin
  378. current_asmdata.getdatalabel(lastlabel);
  379. lab_str:=lastlabel;
  380. maybe_new_object_file(current_asmdata.asmlists[al_typedconsts]);
  381. new_section(current_asmdata.asmlists[al_typedconsts],sec_rodata,lastlabel.name,const_align(sizeof(aint)));
  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.getdatalabel(l2);
  394. current_asmdata.asmlists[al_typedconsts].concat(Tai_label.Create(l2));
  395. current_asmdata.asmlists[al_typedconsts].concat(Tai_const.Create_sym(l1));
  396. current_asmdata.asmlists[al_typedconsts].concat(Tai_const.Create_aint(-1));
  397. current_asmdata.asmlists[al_typedconsts].concat(Tai_const.Create_aint(len));
  398. current_asmdata.asmlists[al_typedconsts].concat(Tai_label.Create(l1));
  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. { return the offset of the real string }
  405. lab_str:=l2;
  406. end;
  407. end;
  408. cst_widestring:
  409. begin
  410. { an empty wide string is nil! }
  411. if len=0 then
  412. current_asmdata.asmlists[al_typedconsts].concat(Tai_const.Create_sym(nil))
  413. else
  414. begin
  415. current_asmdata.getdatalabel(l1);
  416. current_asmdata.getdatalabel(l2);
  417. current_asmdata.asmlists[al_typedconsts].concat(Tai_label.Create(l2));
  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_aint(-1));
  427. current_asmdata.asmlists[al_typedconsts].concat(Tai_const.Create_aint(len*cwidechartype.size));
  428. end;
  429. current_asmdata.asmlists[al_typedconsts].concat(Tai_label.Create(l1));
  430. for i:=0 to len-1 do
  431. current_asmdata.asmlists[al_typedconsts].concat(Tai_const.Create_16bit(pcompilerwidestring(value_str)^.data[i]));
  432. { terminating zero }
  433. current_asmdata.asmlists[al_typedconsts].concat(Tai_const.Create_16bit(0));
  434. { return the offset of the real string }
  435. lab_str:=l2;
  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. var
  470. hp1 : tai;
  471. lastlabel : tasmlabel;
  472. i : longint;
  473. neededtyp : taiconst_type;
  474. type
  475. setbytes=array[0..31] of byte;
  476. Psetbytes=^setbytes;
  477. begin
  478. { small sets are loaded as constants }
  479. if not(is_varset(resultdef)) then
  480. begin
  481. location_reset(location,LOC_CONSTANT,int_cgsize(resultdef.size));
  482. if (source_info.endian=target_info.endian) then
  483. begin
  484. {$if defined(FPC_NEW_BIGENDIAN_SETS) or defined(FPC_LITTLE_ENDIAN)}
  485. { not plongint, because that will "sign extend" the set on 64 bit platforms }
  486. { if changed to "paword", please also modify "32-resultdef.size*8" and }
  487. { cross-endian code below }
  488. { Extra aint type cast to avoid range errors }
  489. location.value:=aint(pCardinal(value_set)^)
  490. {$else}
  491. location.value:=reverse_byte(Psetbytes(value_set)^[0]);
  492. location.value:=location.value or (reverse_byte(Psetbytes(value_set)^[1]) shl 8);
  493. location.value:=location.value or (reverse_byte(Psetbytes(value_set)^[2]) shl 16);
  494. location.value:=location.value or (reverse_byte(Psetbytes(value_set)^[3]) shl 24);
  495. {$endif}
  496. end
  497. else
  498. begin
  499. location.value:=swapendian(Pcardinal(value_set)^);
  500. location.value:= reverse_byte (location.value and $ff) or
  501. (reverse_byte((location.value shr 8) and $ff) shl 8) or
  502. (reverse_byte((location.value shr 16) and $ff) shl 16) or
  503. (reverse_byte((location.value shr 24) and $ff) shl 24);
  504. end;
  505. if (target_info.endian=endian_big) then
  506. location.value:=location.value shr (32-resultdef.size*8);
  507. exit;
  508. end;
  509. location_reset(location,LOC_CREFERENCE,OS_NO);
  510. neededtyp:=aitconst_8bit;
  511. lastlabel:=nil;
  512. { const already used ? }
  513. if not assigned(lab_set) then
  514. begin
  515. { tries to found an old entry }
  516. hp1:=tai(current_asmdata.asmlists[al_typedconsts].first);
  517. while assigned(hp1) do
  518. begin
  519. if hp1.typ=ait_label then
  520. lastlabel:=tai_label(hp1).labsym
  521. else
  522. begin
  523. if (lastlabel<>nil) and
  524. (hp1.typ=ait_const) and
  525. (tai_const(hp1).consttype=neededtyp) then
  526. begin
  527. if (tai_const(hp1).consttype=aitconst_8bit) then
  528. begin
  529. { compare normal set }
  530. i:=0;
  531. while assigned(hp1) and (i<32) do
  532. begin
  533. if (source_info.endian=target_info.endian) then
  534. begin
  535. {$if defined(FPC_NEW_BIGENDIAN_SETS) or defined(FPC_LITTLE_ENDIAN)}
  536. if tai_const(hp1).value<>Psetbytes(value_set)^[i ] then
  537. {$else}
  538. if tai_const(hp1).value<>reverse_byte(Psetbytes(value_set)^[i xor 3]) then
  539. {$endif}
  540. break
  541. end
  542. else if tai_const(hp1).value<>reverse_byte(Psetbytes(value_set)^[i]) then
  543. break;
  544. inc(i);
  545. hp1:=tai(hp1.next);
  546. end;
  547. if i=32 then
  548. begin
  549. { found! }
  550. lab_set:=lastlabel;
  551. break;
  552. end;
  553. { leave when the end of consts is reached, so no
  554. hp1.next is done }
  555. if not assigned(hp1) then
  556. break;
  557. end
  558. else
  559. begin
  560. { compare small set }
  561. if paint(value_set)^=tai_const(hp1).value then
  562. begin
  563. { found! }
  564. lab_set:=lastlabel;
  565. break;
  566. end;
  567. end;
  568. end;
  569. lastlabel:=nil;
  570. end;
  571. hp1:=tai(hp1.next);
  572. end;
  573. { :-(, we must generate a new entry }
  574. if not assigned(lab_set) then
  575. begin
  576. current_asmdata.getdatalabel(lastlabel);
  577. lab_set:=lastlabel;
  578. maybe_new_object_file(current_asmdata.asmlists[al_typedconsts]);
  579. new_section(current_asmdata.asmlists[al_typedconsts],sec_rodata,lastlabel.name,const_align(sizeof(aint)));
  580. current_asmdata.asmlists[al_typedconsts].concat(Tai_label.Create(lastlabel));
  581. { already handled at the start of this method?? (JM)
  582. if tsetdef(resultdef).settype=smallset then
  583. begin
  584. move(value_set^,i,sizeof(longint));
  585. Consts.concat(Tai_const.Create_32bit(i));
  586. end
  587. else
  588. }
  589. begin
  590. if (source_info.endian=target_info.endian) then
  591. {$if defined(FPC_NEW_BIGENDIAN_SETS) or defined(FPC_LITTLE_ENDIAN)}
  592. for i:=0 to 31 do
  593. current_asmdata.asmlists[al_typedconsts].concat(Tai_const.Create_8bit(Psetbytes(value_set)^[i]))
  594. {$else}
  595. for i:=0 to 31 do
  596. current_asmdata.asmlists[al_typedconsts].concat(Tai_const.Create_8bit(reverse_byte(Psetbytes(value_set)^[i xor 3])))
  597. {$endif}
  598. else
  599. for i:=0 to 31 do
  600. current_asmdata.asmlists[al_typedconsts].concat(Tai_const.Create_8bit(reverse_byte(Psetbytes(value_set)^[i])));
  601. end;
  602. end;
  603. end;
  604. location.reference.symbol:=lab_set;
  605. end;
  606. {*****************************************************************************
  607. TCGNILNODE
  608. *****************************************************************************}
  609. procedure tcgnilnode.pass_generate_code;
  610. begin
  611. location_reset(location,LOC_CONSTANT,OS_ADDR);
  612. location.value:=0;
  613. end;
  614. {*****************************************************************************
  615. TCGPOINTERCONSTNODE
  616. *****************************************************************************}
  617. procedure tcgguidconstnode.pass_generate_code;
  618. var
  619. tmplabel : TAsmLabel;
  620. i : integer;
  621. begin
  622. location_reset(location,LOC_CREFERENCE,OS_NO);
  623. { label for GUID }
  624. current_asmdata.getdatalabel(tmplabel);
  625. current_asmdata.asmlists[al_typedconsts].concat(tai_align.create(const_align(16)));
  626. current_asmdata.asmlists[al_typedconsts].concat(Tai_label.Create(tmplabel));
  627. current_asmdata.asmlists[al_typedconsts].concat(Tai_const.Create_32bit(longint(value.D1)));
  628. current_asmdata.asmlists[al_typedconsts].concat(Tai_const.Create_16bit(value.D2));
  629. current_asmdata.asmlists[al_typedconsts].concat(Tai_const.Create_16bit(value.D3));
  630. for i:=low(value.D4) to high(value.D4) do
  631. current_asmdata.asmlists[al_typedconsts].concat(Tai_const.Create_8bit(value.D4[i]));
  632. location.reference.symbol:=tmplabel;
  633. end;
  634. begin
  635. cdataconstnode:=tcgdataconstnode;
  636. crealconstnode:=tcgrealconstnode;
  637. cordconstnode:=tcgordconstnode;
  638. cpointerconstnode:=tcgpointerconstnode;
  639. cstringconstnode:=tcgstringconstnode;
  640. csetconstnode:=tcgsetconstnode;
  641. cnilnode:=tcgnilnode;
  642. cguidconstnode:=tcgguidconstnode;
  643. end.