ncgcon.pas 32 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691
  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. {$endif ARM}
  103. { const already used ? }
  104. if not assigned(lab_real) then
  105. begin
  106. { tries to find an old entry }
  107. hp1:=tai(current_asmdata.asmlists[al_typedconsts].first);
  108. while assigned(hp1) do
  109. begin
  110. if hp1.typ=ait_label then
  111. lastlabel:=tai_label(hp1).labsym
  112. else
  113. begin
  114. if (hp1.typ=realait) and (lastlabel<>nil) then
  115. begin
  116. if is_number_float(value_real) and
  117. (
  118. ((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
  119. ((realait=ait_real_64bit) and
  120. {$ifdef ARM}
  121. ((tai_real_64bit(hp1).formatoptions=fo_hiloswapped)=hiloswapped) and
  122. {$endif ARM}
  123. (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
  124. ((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
  125. {$ifdef cpufloat128}
  126. ((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
  127. {$endif cpufloat128}
  128. ((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)))
  129. ) then
  130. begin
  131. { found! }
  132. lab_real:=lastlabel;
  133. break;
  134. end;
  135. end;
  136. lastlabel:=nil;
  137. end;
  138. hp1:=tai(hp1.next);
  139. end;
  140. { :-(, we must generate a new entry }
  141. if not assigned(lab_real) then
  142. begin
  143. current_asmdata.getdatalabel(lastlabel);
  144. lab_real:=lastlabel;
  145. maybe_new_object_file(current_asmdata.asmlists[al_typedconsts]);
  146. new_section(current_asmdata.asmlists[al_typedconsts],sec_rodata,lastlabel.name,const_align(resultdef.size));
  147. current_asmdata.asmlists[al_typedconsts].concat(Tai_label.Create(lastlabel));
  148. case realait of
  149. ait_real_32bit :
  150. begin
  151. current_asmdata.asmlists[al_typedconsts].concat(Tai_real_32bit.Create(ts32real(value_real)));
  152. { range checking? }
  153. if ((cs_check_range in current_settings.localswitches) or
  154. (cs_check_overflow in current_settings.localswitches)) and
  155. (tai_real_32bit(current_asmdata.asmlists[al_typedconsts].last).value=MathInf.Value) then
  156. Message(parser_e_range_check_error);
  157. end;
  158. ait_real_64bit :
  159. begin
  160. {$ifdef ARM}
  161. if hiloswapped then
  162. current_asmdata.asmlists[al_typedconsts].concat(Tai_real_64bit.Create_hiloswapped(ts64real(value_real)))
  163. else
  164. {$endif ARM}
  165. current_asmdata.asmlists[al_typedconsts].concat(Tai_real_64bit.Create(ts64real(value_real)));
  166. { range checking? }
  167. if ((cs_check_range in current_settings.localswitches) or
  168. (cs_check_overflow in current_settings.localswitches)) and
  169. (tai_real_64bit(current_asmdata.asmlists[al_typedconsts].last).value=MathInf.Value) then
  170. Message(parser_e_range_check_error);
  171. end;
  172. ait_real_80bit :
  173. begin
  174. current_asmdata.asmlists[al_typedconsts].concat(Tai_real_80bit.Create(value_real));
  175. { range checking? }
  176. if ((cs_check_range in current_settings.localswitches) or
  177. (cs_check_overflow in current_settings.localswitches)) and
  178. (tai_real_80bit(current_asmdata.asmlists[al_typedconsts].last).value=MathInf.Value) then
  179. Message(parser_e_range_check_error);
  180. end;
  181. {$ifdef cpufloat128}
  182. ait_real_128bit :
  183. begin
  184. current_asmdata.asmlists[al_typedconsts].concat(Tai_real_128bit.Create(value_real));
  185. { range checking? }
  186. if ((cs_check_range in current_settings.localswitches) or
  187. (cs_check_overflow in current_settings.localswitches)) and
  188. (tai_real_128bit(current_asmdata.asmlists[al_typedconsts].last).value=MathInf.Value) then
  189. Message(parser_e_range_check_error);
  190. end;
  191. {$endif cpufloat128}
  192. { the round is necessary for native compilers where comp isn't a float }
  193. ait_comp_64bit :
  194. if (value_real>9223372036854775807.0) or (value_real<-9223372036854775808.0) then
  195. message(parser_e_range_check_error)
  196. else
  197. current_asmdata.asmlists[al_typedconsts].concat(Tai_comp_64bit.Create(round(value_real)));
  198. else
  199. internalerror(10120);
  200. end;
  201. end;
  202. end;
  203. location.reference.symbol:=lab_real;
  204. end;
  205. {*****************************************************************************
  206. TCGORDCONSTNODE
  207. *****************************************************************************}
  208. procedure tcgordconstnode.pass_generate_code;
  209. begin
  210. location_reset(location,LOC_CONSTANT,def_cgsize(resultdef));
  211. {$ifdef cpu64bit}
  212. location.value:=value.svalue;
  213. {$else cpu64bit}
  214. location.value64:=value.svalue;
  215. {$endif cpu64bit}
  216. end;
  217. {*****************************************************************************
  218. TCGPOINTERCONSTNODE
  219. *****************************************************************************}
  220. procedure tcgpointerconstnode.pass_generate_code;
  221. begin
  222. { an integer const. behaves as a memory reference }
  223. location_reset(location,LOC_CONSTANT,OS_ADDR);
  224. location.value:=aint(value);
  225. end;
  226. {*****************************************************************************
  227. TCGSTRINGCONSTNODE
  228. *****************************************************************************}
  229. procedure tcgstringconstnode.pass_generate_code;
  230. var
  231. hp1,hp2 : tai;
  232. l1,l2,
  233. lastlabel : tasmlabel;
  234. lastlabelhp : tai;
  235. pc : pchar;
  236. same_string : boolean;
  237. l,j,
  238. i,mylength : longint;
  239. begin
  240. { for empty ansistrings we could return a constant 0 }
  241. if (cst_type in [cst_ansistring,cst_widestring]) and (len=0) then
  242. begin
  243. location_reset(location,LOC_CONSTANT,OS_ADDR);
  244. location.value:=0;
  245. exit;
  246. end;
  247. { return a constant reference in memory }
  248. location_reset(location,LOC_CREFERENCE,def_cgsize(resultdef));
  249. { const already used ? }
  250. lastlabel:=nil;
  251. lastlabelhp:=nil;
  252. if not assigned(lab_str) then
  253. begin
  254. if is_shortstring(resultdef) then
  255. mylength:=len+2
  256. else
  257. mylength:=len+1;
  258. { widestrings can't be reused yet }
  259. if not(is_widestring(resultdef)) then
  260. begin
  261. { tries to find an old entry }
  262. hp1:=tai(current_asmdata.asmlists[al_typedconsts].first);
  263. while assigned(hp1) do
  264. begin
  265. if hp1.typ=ait_label then
  266. begin
  267. lastlabel:=tai_label(hp1).labsym;
  268. lastlabelhp:=hp1;
  269. end
  270. else
  271. begin
  272. same_string:=false;
  273. if (hp1.typ=ait_string) and
  274. (lastlabel<>nil) and
  275. (tai_string(hp1).len=mylength) then
  276. begin
  277. case cst_type of
  278. cst_conststring:
  279. begin
  280. j:=0;
  281. same_string:=true;
  282. if len>0 then
  283. begin
  284. for i:=0 to len-1 do
  285. begin
  286. if tai_string(hp1).str[j]<>value_str[i] then
  287. begin
  288. same_string:=false;
  289. break;
  290. end;
  291. inc(j);
  292. end;
  293. end;
  294. end;
  295. cst_shortstring:
  296. begin
  297. { if shortstring then check the length byte first and
  298. set the start index to 1 }
  299. if len=ord(tai_string(hp1).str[0]) then
  300. begin
  301. j:=1;
  302. same_string:=true;
  303. if len>0 then
  304. begin
  305. for i:=0 to len-1 do
  306. begin
  307. if tai_string(hp1).str[j]<>value_str[i] then
  308. begin
  309. same_string:=false;
  310. break;
  311. end;
  312. inc(j);
  313. end;
  314. end;
  315. end;
  316. end;
  317. cst_ansistring,
  318. cst_widestring :
  319. begin
  320. { before the string the following sequence must be found:
  321. <label>
  322. constsymbol <datalabel>
  323. constint -1
  324. constint <len>
  325. we must then return <label> to reuse
  326. }
  327. hp2:=tai(lastlabelhp.previous);
  328. if assigned(hp2) and
  329. (hp2.typ=ait_const) and
  330. (tai_const(hp2).consttype=aitconst_aint) and
  331. (tai_const(hp2).value=len) and
  332. assigned(hp2.previous) and
  333. (tai(hp2.previous).typ=ait_const) and
  334. (tai_const(hp2.previous).consttype=aitconst_aint) and
  335. (tai_const(hp2.previous).value=-1) and
  336. assigned(hp2.previous.previous) and
  337. (tai(hp2.previous.previous).typ=ait_const) and
  338. (tai_const(hp2.previous.previous).consttype=aitconst_ptr) and
  339. assigned(hp2.previous.previous.previous) and
  340. (tai(hp2.previous.previous.previous).typ=ait_label) then
  341. begin
  342. lastlabel:=tai_label(hp2.previous.previous.previous).labsym;
  343. same_string:=true;
  344. j:=0;
  345. if len>0 then
  346. begin
  347. for i:=0 to len-1 do
  348. begin
  349. if tai_string(hp1).str[j]<>value_str[i] then
  350. begin
  351. same_string:=false;
  352. break;
  353. end;
  354. inc(j);
  355. end;
  356. end;
  357. end;
  358. end;
  359. end;
  360. { found ? }
  361. if same_string then
  362. begin
  363. lab_str:=lastlabel;
  364. break;
  365. end;
  366. end;
  367. lastlabel:=nil;
  368. end;
  369. hp1:=tai(hp1.next);
  370. end;
  371. end;
  372. { :-(, we must generate a new entry }
  373. if not assigned(lab_str) then
  374. begin
  375. current_asmdata.getdatalabel(lastlabel);
  376. lab_str:=lastlabel;
  377. maybe_new_object_file(current_asmdata.asmlists[al_typedconsts]);
  378. new_section(current_asmdata.asmlists[al_typedconsts],sec_rodata,lastlabel.name,const_align(sizeof(aint)));
  379. current_asmdata.asmlists[al_typedconsts].concat(Tai_label.Create(lastlabel));
  380. { generate an ansi string ? }
  381. case cst_type of
  382. cst_ansistring:
  383. begin
  384. { an empty ansi string is nil! }
  385. if len=0 then
  386. current_asmdata.asmlists[al_typedconsts].concat(Tai_const.Create_sym(nil))
  387. else
  388. begin
  389. current_asmdata.getdatalabel(l1);
  390. current_asmdata.getdatalabel(l2);
  391. current_asmdata.asmlists[al_typedconsts].concat(Tai_label.Create(l2));
  392. current_asmdata.asmlists[al_typedconsts].concat(Tai_const.Create_sym(l1));
  393. current_asmdata.asmlists[al_typedconsts].concat(Tai_const.Create_aint(-1));
  394. current_asmdata.asmlists[al_typedconsts].concat(Tai_const.Create_aint(len));
  395. current_asmdata.asmlists[al_typedconsts].concat(Tai_label.Create(l1));
  396. { include also terminating zero }
  397. getmem(pc,len+1);
  398. move(value_str^,pc^,len);
  399. pc[len]:=#0;
  400. current_asmdata.asmlists[al_typedconsts].concat(Tai_string.Create_pchar(pc,len+1));
  401. { return the offset of the real string }
  402. lab_str:=l2;
  403. end;
  404. end;
  405. cst_widestring:
  406. begin
  407. { an empty wide string is nil! }
  408. if len=0 then
  409. current_asmdata.asmlists[al_typedconsts].concat(Tai_const.Create_sym(nil))
  410. else
  411. begin
  412. current_asmdata.getdatalabel(l1);
  413. current_asmdata.getdatalabel(l2);
  414. current_asmdata.asmlists[al_typedconsts].concat(Tai_label.Create(l2));
  415. current_asmdata.asmlists[al_typedconsts].concat(Tai_const.Create_sym(l1));
  416. { we use always UTF-16 coding for constants }
  417. { at least for now }
  418. { Consts.concat(Tai_const.Create_8bit(2)); }
  419. if tf_winlikewidestring in target_info.flags then
  420. current_asmdata.asmlists[al_typedconsts].concat(Tai_const.Create_32bit(len*cwidechartype.size))
  421. else
  422. begin
  423. current_asmdata.asmlists[al_typedconsts].concat(Tai_const.Create_aint(-1));
  424. current_asmdata.asmlists[al_typedconsts].concat(Tai_const.Create_aint(len*cwidechartype.size));
  425. end;
  426. current_asmdata.asmlists[al_typedconsts].concat(Tai_label.Create(l1));
  427. for i:=0 to len-1 do
  428. current_asmdata.asmlists[al_typedconsts].concat(Tai_const.Create_16bit(pcompilerwidestring(value_str)^.data[i]));
  429. { terminating zero }
  430. current_asmdata.asmlists[al_typedconsts].concat(Tai_const.Create_16bit(0));
  431. { return the offset of the real string }
  432. lab_str:=l2;
  433. end;
  434. end;
  435. cst_shortstring:
  436. begin
  437. { truncate strings larger than 255 chars }
  438. if len>255 then
  439. l:=255
  440. else
  441. l:=len;
  442. { include length and terminating zero for quick conversion to pchar }
  443. getmem(pc,l+2);
  444. move(value_str^,pc[1],l);
  445. pc[0]:=chr(l);
  446. pc[l+1]:=#0;
  447. current_asmdata.asmlists[al_typedconsts].concat(Tai_string.Create_pchar(pc,l+2));
  448. end;
  449. cst_conststring:
  450. begin
  451. { include terminating zero }
  452. getmem(pc,len+1);
  453. move(value_str^,pc[0],len);
  454. pc[len]:=#0;
  455. current_asmdata.asmlists[al_typedconsts].concat(Tai_string.Create_pchar(pc,len+1));
  456. end;
  457. end;
  458. end;
  459. end;
  460. location.reference.symbol:=lab_str;
  461. end;
  462. {*****************************************************************************
  463. TCGSETCONSTNODE
  464. *****************************************************************************}
  465. procedure tcgsetconstnode.pass_generate_code;
  466. var
  467. hp1 : tai;
  468. lastlabel : tasmlabel;
  469. i : longint;
  470. neededtyp : taiconst_type;
  471. type
  472. setbytes=array[0..31] of byte;
  473. Psetbytes=^setbytes;
  474. begin
  475. { small sets are loaded as constants }
  476. if not(is_varset(resultdef)) then
  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:=cardinal(SwapLong(pLongint(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. exit;
  505. end;
  506. location_reset(location,LOC_CREFERENCE,OS_NO);
  507. neededtyp:=aitconst_8bit;
  508. lastlabel:=nil;
  509. { const already used ? }
  510. if not assigned(lab_set) then
  511. begin
  512. { tries to found an old entry }
  513. hp1:=tai(current_asmdata.asmlists[al_typedconsts].first);
  514. while assigned(hp1) do
  515. begin
  516. if hp1.typ=ait_label then
  517. lastlabel:=tai_label(hp1).labsym
  518. else
  519. begin
  520. if (lastlabel<>nil) and
  521. (hp1.typ=ait_const) and
  522. (tai_const(hp1).consttype=neededtyp) then
  523. begin
  524. if (tai_const(hp1).consttype=aitconst_8bit) then
  525. begin
  526. { compare normal set }
  527. i:=0;
  528. while assigned(hp1) and (i<32) do
  529. begin
  530. if (source_info.endian=target_info.endian) then
  531. begin
  532. {$if defined(FPC_NEW_BIGENDIAN_SETS) or defined(FPC_LITTLE_ENDIAN)}
  533. if tai_const(hp1).value<>Psetbytes(value_set)^[i ] then
  534. {$else}
  535. if tai_const(hp1).value<>reverse_byte(Psetbytes(value_set)^[i xor 3]) then
  536. {$endif}
  537. break
  538. end
  539. else if tai_const(hp1).value<>reverse_byte(Psetbytes(value_set)^[i]) then
  540. break;
  541. inc(i);
  542. hp1:=tai(hp1.next);
  543. end;
  544. if i=32 then
  545. begin
  546. { found! }
  547. lab_set:=lastlabel;
  548. break;
  549. end;
  550. { leave when the end of consts is reached, so no
  551. hp1.next is done }
  552. if not assigned(hp1) then
  553. break;
  554. end
  555. else
  556. begin
  557. { compare small set }
  558. if paint(value_set)^=tai_const(hp1).value then
  559. begin
  560. { found! }
  561. lab_set:=lastlabel;
  562. break;
  563. end;
  564. end;
  565. end;
  566. lastlabel:=nil;
  567. end;
  568. hp1:=tai(hp1.next);
  569. end;
  570. { :-(, we must generate a new entry }
  571. if not assigned(lab_set) then
  572. begin
  573. current_asmdata.getdatalabel(lastlabel);
  574. lab_set:=lastlabel;
  575. maybe_new_object_file(current_asmdata.asmlists[al_typedconsts]);
  576. new_section(current_asmdata.asmlists[al_typedconsts],sec_rodata,lastlabel.name,const_align(sizeof(aint)));
  577. current_asmdata.asmlists[al_typedconsts].concat(Tai_label.Create(lastlabel));
  578. { already handled at the start of this method?? (JM)
  579. if tsetdef(resultdef).settype=smallset then
  580. begin
  581. move(value_set^,i,sizeof(longint));
  582. Consts.concat(Tai_const.Create_32bit(i));
  583. end
  584. else
  585. }
  586. begin
  587. if (source_info.endian=target_info.endian) then
  588. {$if defined(FPC_NEW_BIGENDIAN_SETS) or defined(FPC_LITTLE_ENDIAN)}
  589. for i:=0 to 31 do
  590. current_asmdata.asmlists[al_typedconsts].concat(Tai_const.Create_8bit(Psetbytes(value_set)^[i]))
  591. {$else}
  592. for i:=0 to 31 do
  593. current_asmdata.asmlists[al_typedconsts].concat(Tai_const.Create_8bit(reverse_byte(Psetbytes(value_set)^[i xor 3])))
  594. {$endif}
  595. else
  596. for i:=0 to 31 do
  597. current_asmdata.asmlists[al_typedconsts].concat(Tai_const.Create_8bit(reverse_byte(Psetbytes(value_set)^[i])));
  598. end;
  599. end;
  600. end;
  601. location.reference.symbol:=lab_set;
  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.