aasmcnst.pas 86 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281
  1. {
  2. Copyright (c) 2014 by Jonas Maebe, member of the Free Pascal development
  3. team
  4. This unit implements typed constant data elements at the assembler level
  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 aasmcnst;
  19. {$i fpcdefs.inc}
  20. interface
  21. uses
  22. cclasses,globtype,constexp,
  23. aasmbase,aasmdata,aasmtai,
  24. symconst,symbase,symtype,symdef,symsym;
  25. type
  26. { typed const: integer/floating point/string/pointer/... const along with
  27. tdef info }
  28. ttypedconstkind = (tck_simple, tck_array, tck_record);
  29. { the type of the element and its def }
  30. tai_abstracttypedconst = class abstract (tai)
  31. private
  32. procedure setdef(def: tdef);
  33. protected
  34. fadetyp: ttypedconstkind;
  35. { the def of this element }
  36. fdef: tdef;
  37. public
  38. constructor create(_adetyp: ttypedconstkind; _def: tdef);
  39. property adetyp: ttypedconstkind read fadetyp;
  40. property def: tdef read fdef write setdef;
  41. end;
  42. { a simple data element; the value is stored as a tai }
  43. tai_simpletypedconst = class(tai_abstracttypedconst)
  44. private
  45. procedure setval(AValue: tai);
  46. protected
  47. fval: tai;
  48. public
  49. constructor create(_def: tdef; _val: tai);
  50. destructor destroy; override;
  51. property val: tai read fval write setval;
  52. end;
  53. { an aggregate data element (record or array). Values are stored as an
  54. array of tsimpledataelement. }
  55. tai_aggregatetypedconst = class(tai_abstracttypedconst)
  56. public type
  57. { iterator to walk over all individual items in the aggregate }
  58. tadeenumerator = class(tobject)
  59. private
  60. fvalues: tfpobjectlist;
  61. fvaluespos: longint;
  62. function getcurrent: tai_abstracttypedconst;
  63. public
  64. constructor create(data: tai_aggregatetypedconst);
  65. function movenext: boolean;
  66. procedure reset;
  67. property current: tai_abstracttypedconst read getcurrent;
  68. end;
  69. protected
  70. fvalues: tfpobjectlist;
  71. fisstring: boolean;
  72. { converts the existing data to a single tai_string }
  73. procedure convert_to_string;
  74. procedure add_to_string(strtai: tai_string; othertai: tai);
  75. public
  76. constructor create(_adetyp: ttypedconstkind; _fdef: tdef);
  77. function getenumerator: tadeenumerator;
  78. procedure addvalue(val: tai_abstracttypedconst); virtual;
  79. function valuecount: longint;
  80. procedure insertvaluebeforepos(val: tai_abstracttypedconst; pos: longint);
  81. procedure replacevalueatpos(val: tai_abstracttypedconst; pos: longint);
  82. { change the type to a record, regardless of how the aggregate was created;
  83. the size of the original type and the record must match }
  84. procedure changetorecord(_def: trecorddef);
  85. procedure finish;
  86. destructor destroy; override;
  87. end;
  88. tasmlabofs = record
  89. lab: tasmlabel;
  90. ofs: asizeint;
  91. end;
  92. { flags for the finalisation of the typed const builder asmlist }
  93. ttcasmlistoption = (
  94. { the tasmsymbol is a tasmlabel }
  95. tcalo_is_lab,
  96. { start a new section (e.g., because we don't know the current section
  97. type) }
  98. tcalo_new_section,
  99. { this symbol is the start of a block of data that should be
  100. dead-stripable/smartlinkable; may imply starting a new section, but
  101. not necessarily (depends on what the platform requirements are) }
  102. tcalo_make_dead_strippable,
  103. { this symbol should never be removed by the linker }
  104. tcalo_no_dead_strip,
  105. { start of a vectorized but individually dead strippable list of elements,
  106. like the resource strings of a unit: they have to stay in this order,
  107. but individual elements can be removed }
  108. tcalo_vectorized_dead_strip_start,
  109. { item in the above list }
  110. tcalo_vectorized_dead_strip_item,
  111. { end of the above list }
  112. tcalo_vectorized_dead_strip_end,
  113. { symbol should be weakly defined }
  114. tcalo_weak,
  115. { symbol should be registered with the unit's public assembler symbols }
  116. tcalo_is_public_asm,
  117. { symbol should be declared with AT_DATA_FORCEINDIRECT }
  118. tcalo_data_force_indirect,
  119. { apply const_align() to the alignment, for user-defined data }
  120. tcalo_apply_constalign
  121. );
  122. ttcasmlistoptions = set of ttcasmlistoption;
  123. ttcdeadstripsectionsymboloption = (
  124. { define the symbol }
  125. tcdssso_define,
  126. { register the assembler symbol either with the public or extern assembler
  127. symbols of the unit }
  128. tcdssso_register_asmsym,
  129. { use the indirect symbol }
  130. tcdssso_use_indirect
  131. );
  132. ttcdeadstripsectionsymboloptions = set of ttcdeadstripsectionsymboloption;
  133. { information about aggregates we are parsing }
  134. taggregateinformation = class
  135. private
  136. fnextfieldname: TIDString;
  137. function getcuroffset: asizeint;
  138. procedure setnextfieldname(AValue: TIDString);
  139. protected
  140. { type of the aggregate }
  141. fdef: tdef;
  142. { type of the aggregate }
  143. ftyp: ttypedconstkind;
  144. { symtable entry of the previously emitted field in case of a
  145. record/object (nil if none emitted yet), used to insert alignment bytes
  146. if necessary for variant records and objects }
  147. fcurfield,
  148. { field corresponding to the data that will be emitted next in case of a
  149. record/object (nil if not set), used to handle variant records and
  150. objects }
  151. fnextfield: tfieldvarsym;
  152. { similar as the fcurfield/fnextfield above, but instead of fieldvarsyms
  153. these are indices in the symlist of a recorddef that correspond to
  154. fieldvarsyms. These are used only for non-variant records, simply
  155. traversing the fields in order. We could use the above method here as
  156. well, but to find the next field we'd always have to use
  157. symlist.indexof(fcurfield), which would be quite slow. These have -1 as
  158. value if they're not set }
  159. fcurindex,
  160. fnextindex: longint;
  161. { anonymous record that is being built as we add constant data }
  162. fanonrecord: boolean;
  163. property curindex: longint read fcurindex write fcurindex;
  164. property nextindex: longint read fnextindex write fnextindex;
  165. public
  166. constructor create(_def: tdef; _typ: ttypedconstkind); virtual;
  167. { calculated padding bytes for alignment if needed, and add the def of the
  168. next field in case we are constructing an anonymous record }
  169. function prepare_next_field(nextfielddef: tdef): asizeint; virtual;
  170. property def: tdef read fdef;
  171. property typ: ttypedconstkind read ftyp;
  172. property curfield: tfieldvarsym read fcurfield write fcurfield;
  173. property nextfield: tfieldvarsym read fnextfield write fnextfield;
  174. property nextfieldname: TIDString write setnextfieldname;
  175. property curoffset: asizeint read getcuroffset;
  176. property anonrecord: boolean read fanonrecord write fanonrecord;
  177. end;
  178. taggregateinformationclass = class of taggregateinformation;
  179. { information about a placeholder element that has been added, and which has
  180. to be replaced later with a real data element }
  181. ttypedconstplaceholder = class abstract
  182. def: tdef;
  183. constructor create(d: tdef);
  184. { same usage as ttai_typedconstbuilder.emit_tai }
  185. procedure replace(ai: tai; d: tdef); virtual; abstract;
  186. end;
  187. { Warning: never directly create a ttai_typedconstbuilder instance,
  188. instead create a cai_typedconstbuilder (this class can be overridden) }
  189. ttai_typedconstbuilder = class abstract
  190. { class type to use when creating new aggregate information instances }
  191. protected class var
  192. caggregateinformation: taggregateinformationclass;
  193. private
  194. function getcurragginfo: taggregateinformation;
  195. procedure set_next_field(AValue: tfieldvarsym);
  196. procedure set_next_field_name(AValue: TIDString);
  197. protected
  198. { temporary list in which all data is collected }
  199. fasmlist: tasmlist;
  200. { options for the final asmlist }
  201. foptions: ttcasmlistoptions;
  202. { while queueing elements of a compound expression, this is the current
  203. offset in the top-level array/record }
  204. fqueue_offset: asizeint;
  205. fqueued_def: tdef;
  206. { array of caggregateinformation instances }
  207. faggregateinformation: tfpobjectlist;
  208. { Support for generating data that is only referenced from the typed
  209. constant data that we are currently generated. Such data can all be put
  210. in the same dead-strippable unit, as it's either all included or none of
  211. it is included. This data can be spread over multiple kinds of sections
  212. though (e.g. rodata and rodata_no_rel), so per section keep track whether
  213. we already started a dead-strippable unit and if so, what the section
  214. name was (so that on platforms that perform the dead stripping based on
  215. sections, we put all data for one typed constant into a single section
  216. with the same name) }
  217. protected type
  218. tinternal_data_section_info = record
  219. secname: TSymStr;
  220. sectype: TAsmSectiontype;
  221. end;
  222. protected var
  223. { all internally generated data must be stored in the same list, as it must
  224. be consecutive (if it's spread over multiple lists, we don't know in
  225. which order they'll be concatenated) -> keep track of this list }
  226. finternal_data_asmlist: tasmlist;
  227. { kind of the last section we started in the finternal_data_asmlist, to
  228. avoid creating unnecessary section statements }
  229. finternal_data_current_section: TAsmSectiontype;
  230. { info about in which kinds of sections we have already emitted internal
  231. data, and what their names were }
  232. finternal_data_section_info: array of tinternal_data_section_info;
  233. { ensure that finalize_asmlist is called only once }
  234. fasmlist_finalized: boolean;
  235. { ensure that if it's vectorized dead strippable data, we called
  236. finalize_vectorized_dead_strip_asmlist instead of finalize_asmlist }
  237. fvectorized_finalize_called: boolean;
  238. { returns whether def must be handled as an aggregate on the current
  239. platform }
  240. function aggregate_kind(def: tdef): ttypedconstkind; virtual;
  241. { finalize the asmlist: add the necessary symbols etc }
  242. procedure finalize_asmlist(sym: tasmsymbol; def: tdef; section: TAsmSectiontype; const secname: TSymStr; alignment: shortint; const options: ttcasmlistoptions); virtual;
  243. procedure finalize_asmlist_add_indirect_sym(sym: tasmsymbol; def: tdef; section: TAsmSectiontype; const secname: TSymStr; alignment: shortint; const options: ttcasmlistoptions); virtual;
  244. { prepare finalization (common for the default and overridden versions }
  245. procedure finalize_asmlist_prepare(const options: ttcasmlistoptions; var alignment: shortint);
  246. { functionality of the above for vectorized dead strippable sections }
  247. procedure finalize_vectorized_dead_strip_asmlist(def: tdef; const basename, itemname: TSymStr; st: tsymtable; alignment: shortint; options: ttcasmlistoptions); virtual;
  248. { called by the public emit_tai() routines to actually add the typed
  249. constant data; the public ones also take care of adding extra padding
  250. bytes etc (by calling this one) }
  251. procedure do_emit_tai(p: tai; def: tdef); virtual;
  252. { calls prepare_next_field() and adds the padding bytes in the current
  253. location }
  254. procedure pad_next_field(nextfielddef: tdef);
  255. { returns the index in finternal_data_section_info of the info for the
  256. section of type typ. Returns -1 if there is no such info yet }
  257. function get_internal_data_section_index(typ: TAsmSectiontype): longint;
  258. { get a start label for an internal data section (at the start of a
  259. potentially dead-strippable part) }
  260. function get_internal_data_section_start_label: tasmlabel; virtual;
  261. { get a label in the middle of an internal data section (no dead
  262. stripping) }
  263. function get_internal_data_section_internal_label: tasmlabel; virtual;
  264. { easy access to the top level aggregate information instance }
  265. property curagginfo: taggregateinformation read getcurragginfo;
  266. public
  267. constructor create(const options: ttcasmlistoptions); virtual;
  268. destructor destroy; override;
  269. public
  270. { returns a builder for generating data that is only referrenced by the
  271. typed constant date we are currently generating (e.g. string data for a
  272. pchar constant). Also returns the label that will be placed at the start
  273. of that data. list is the tasmlist to which the data will be added.
  274. secname can be empty to use a default }
  275. procedure start_internal_data_builder(list: tasmlist; sectype: TAsmSectiontype; const secname: TSymStr; out tcb: ttai_typedconstbuilder; out l: tasmlabel);
  276. { finish a previously started internal data builder, including
  277. concatenating all generated data to the provided list and freeing the
  278. builder }
  279. procedure finish_internal_data_builder(var tcb: ttai_typedconstbuilder; l: tasmlabel; def: tdef; alignment: longint);
  280. { add a simple constant data element (p) to the typed constant.
  281. def is the type of the added value }
  282. procedure emit_tai(p: tai; def: tdef); virtual;
  283. { same as above, for a special case: when the def is a procvardef and we
  284. want to use it explicitly as a procdef (i.e., not as a record with a
  285. code and data pointer in case of a complex procvardef) }
  286. procedure emit_tai_procvar2procdef(p: tai; pvdef: tprocvardef); virtual;
  287. protected
  288. procedure maybe_emit_tail_padding(def: tdef); virtual;
  289. function emit_string_const_common(stringtype: tstringtype; len: asizeint; encoding: tstringencoding; var startlab: tasmlabel):tasmlabofs;
  290. function get_dynstring_def_for_type(stringtype: tstringtype; winlikewidestring: boolean): tstringdef;
  291. procedure begin_aggregate_internal(def: tdef; anonymous: boolean); virtual;
  292. procedure end_aggregate_internal(def: tdef; anonymous: boolean); virtual;
  293. { when building an anonymous record, we cannot immediately insert the
  294. alignment before it in case it's nested, since we only know the required
  295. alignment once all fields have been inserted -> mark the location before
  296. the anonymous record, and insert the alignment once it's finished }
  297. procedure mark_anon_aggregate_alignment; virtual; abstract;
  298. procedure insert_marked_aggregate_alignment(def: tdef); virtual; abstract;
  299. class function get_vectorized_dead_strip_section_symbol(const basename: string; st: tsymtable; options: ttcdeadstripsectionsymboloptions; start: boolean): tasmsymbol; virtual;
  300. public
  301. class function get_vectorized_dead_strip_custom_section_name(const basename: TSymStr; st: tsymtable; out secname: TSymStr): boolean; virtual;
  302. { get the start/end symbol for a dead stripable vectorized section, such
  303. as the resourcestring data of a unit }
  304. class function get_vectorized_dead_strip_section_symbol_start(const basename: string; st: tsymtable; options: ttcdeadstripsectionsymboloptions): tasmsymbol; virtual;
  305. class function get_vectorized_dead_strip_section_symbol_end(const basename: string; st: tsymtable; options: ttcdeadstripsectionsymboloptions): tasmsymbol; virtual;
  306. class function get_dynstring_rec_name(typ: tstringtype; winlike: boolean; len: asizeint): TSymStr;
  307. class function get_dynstring_rec(typ: tstringtype; winlike: boolean; len: asizeint): trecorddef;
  308. { the datalist parameter specifies where the data for the string constant
  309. will be emitted (via an internal data builder) }
  310. function emit_ansistring_const(datalist: TAsmList; data: pchar; len: asizeint; encoding: tstringencoding): tasmlabofs;
  311. function emit_unicodestring_const(datalist: TAsmList; data: pointer; encoding: tstringencoding; winlike: boolean):tasmlabofs;
  312. { emits a tasmlabofs as returned by emit_*string_const }
  313. procedure emit_string_offset(const ll: tasmlabofs; const strlength: longint; const st: tstringtype; const winlikewidestring: boolean; const charptrdef: tdef);virtual;
  314. { emits a tasmlabofs as returned by begin_dynarray_const }
  315. procedure emit_dynarray_offset(const ll:tasmlabofs;const arrlength:asizeint;const arrdef:tarraydef; const arrconstdatadef: trecorddef);virtual;
  316. { starts a dynamic array constant so that its data can be emitted directly afterwards }
  317. function begin_dynarray_const(arrdef:tdef;var startlab:tasmlabel;out arrlengthloc:ttypedconstplaceholder):tasmlabofs;virtual;
  318. function end_dynarray_const(arrdef:tdef;arrlength:asizeint;arrlengthloc:ttypedconstplaceholder):tdef;virtual;
  319. { emit a shortstring constant, and return its def }
  320. function emit_shortstring_const(const str: shortstring): tdef;
  321. { emit a pchar string constant (the characters, not a pointer to them), and return its def }
  322. function emit_pchar_const(str: pchar; len: pint; copypchar: boolean): tdef;
  323. { emit a guid constant }
  324. procedure emit_guid_const(const guid: tguid);
  325. { emit a procdef constant }
  326. procedure emit_procdef_const(pd: tprocdef);
  327. { emit an ordinal constant }
  328. procedure emit_ord_const(value: int64; def: tdef);
  329. { emit a reference to a pooled shortstring constant }
  330. procedure emit_pooled_shortstring_const_ref(const str:shortstring);
  331. { begin a potential aggregate type. Must be called for any type
  332. that consists of multiple tai constant data entries, or that
  333. represents an aggregate at the Pascal level (a record, a non-dynamic
  334. array, ... }
  335. procedure maybe_begin_aggregate(def: tdef);
  336. { end a potential aggregate type. Must be paired with every
  337. maybe_begin_aggregate }
  338. procedure maybe_end_aggregate(def: tdef);
  339. { similar as above, but in case
  340. a) it's definitely a record
  341. b) the def of the record should be automatically constructed based on
  342. the types of the emitted fields
  343. packrecords: same as "pacrecords x"
  344. recordalign: specify the (minimum) alignment of the start of the record
  345. (no equivalent in source code), used as an alternative for explicit
  346. align statements. Use "1" if it should be calculated based on the
  347. fields
  348. recordalignmin: same as "codealign recordmin=x"
  349. maxcrecordalign: specify maximum C record alignment (no equivalent in
  350. source code)
  351. }
  352. function begin_anonymous_record(const optionalname: string; packrecords, recordalign, recordalignmin: shortint): trecorddef; virtual;
  353. function end_anonymous_record: trecorddef; virtual;
  354. { add a placeholder element at the current position that later can be
  355. filled in with the actual data (via ttypedconstplaceholder.replace)
  356. useful in case you have table preceded by the number of elements, and
  357. you count the elements while building the table }
  358. function emit_placeholder(def: tdef): ttypedconstplaceholder; virtual; abstract;
  359. protected
  360. { common code to check whether a placeholder can be added at the current
  361. position }
  362. procedure check_add_placeholder(def: tdef);
  363. public
  364. { The next group of routines are for constructing complex expressions.
  365. While parsing a typed constant these operators are encountered from
  366. outer to inner, so that is also the order in which they should be
  367. added to the queue. Only one queue can be active at a time. }
  368. { Init the queue. Gives an internalerror if a queue was already active }
  369. procedure queue_init(todef: tdef); virtual;
  370. { queue an array/string indexing operation (performs all range checking,
  371. so it doesn't have to be duplicated in all descendents). }
  372. procedure queue_vecn(def: tdef; const index: tconstexprint); virtual;
  373. { queue a subscripting operation }
  374. procedure queue_subscriptn(def: tabstractrecorddef; vs: tfieldvarsym); virtual;
  375. { queue indexing a record recursively via several field names. The fields
  376. are specified in the inner to outer order (i.e., def.field1.field2) }
  377. function queue_subscriptn_multiple_by_name(def: tabstractrecorddef; const fields: array of TIDString): tdef;
  378. { queue a type conversion operation }
  379. procedure queue_typeconvn(fromdef, todef: tdef); virtual;
  380. { finalise the queue (so a new one can be created) and flush the
  381. previously queued operations, applying them in reverse order on a...}
  382. { ... procdef }
  383. procedure queue_emit_proc(pd: tprocdef); virtual;
  384. { ... staticvarsym }
  385. procedure queue_emit_staticvar(vs: tstaticvarsym); virtual;
  386. { ... labelsym }
  387. procedure queue_emit_label(l: tlabelsym); virtual;
  388. { ... constsym }
  389. procedure queue_emit_const(cs: tconstsym); virtual;
  390. { ... asmsym/asmlabel }
  391. procedure queue_emit_asmsym(sym: tasmsymbol; def: tdef); virtual;
  392. { ... an ordinal constant }
  393. procedure queue_emit_ordconst(value: int64; def: tdef); virtual;
  394. protected
  395. { returns whether queue_init has been called without a corresponding
  396. queue_emit_* to finish it }
  397. function queue_is_active: boolean;
  398. public
  399. { finalize the internal asmlist (if necessary) and return it.
  400. This asmlist will be freed when the builder is destroyed, so add its
  401. contents to another list first. This property should only be accessed
  402. once all data has been added. }
  403. function get_final_asmlist(sym: tasmsymbol; def: tdef; section: TAsmSectiontype; const secname: TSymStr; alignment: longint): tasmlist;
  404. function get_final_asmlist_vectorized_dead_strip(def: tdef; const basename, itemname: TSymStr; st: TSymtable; alignment: longint): tasmlist;
  405. { returns the offset of the string data relative to ansi/unicode/widestring
  406. constant labels. On most platforms, this is 0 (with the header at a
  407. negative offset), but on some platforms such negative offsets are not
  408. supported this is equal to the header size }
  409. class function get_string_symofs(typ: tstringtype; winlikewidestring: boolean): pint; virtual;
  410. { returns the offset of the array data relatve to dynamic array constant
  411. labels. On most platforms, this is 0 (with the header at a negative
  412. offset), but on some platforms such negative offsets are not supported
  413. and thus this is equal to the header size }
  414. class function get_dynarray_symofs:pint;virtual;
  415. { set the fieldvarsym whose data we will emit next; needed
  416. in case of variant records, so we know which part of the variant gets
  417. initialised. Also in case of objects, because the fieldvarsyms are spread
  418. over the symtables of the entire inheritance tree }
  419. property next_field: tfieldvarsym write set_next_field;
  420. { set the name of the next field that will be emitted for an anonymous
  421. record (also if that field is a nested anonymous record) }
  422. property next_field_name: TIDString write set_next_field_name;
  423. protected
  424. { these ones always return the actual offset, called by the above (and
  425. overridden versions) }
  426. class function get_string_header_size(typ: tstringtype; winlikewidestring: boolean): pint;
  427. class function get_dynarray_header_size:pint;
  428. end;
  429. ttai_typedconstbuilderclass = class of ttai_typedconstbuilder;
  430. tlowlevelaggregateinformation = class(taggregateinformation)
  431. protected
  432. fanonrecmarker: tai;
  433. public
  434. property anonrecmarker: tai read fanonrecmarker write fanonrecmarker;
  435. end;
  436. tlowleveltypedconstplaceholder = class(ttypedconstplaceholder)
  437. list: tasmlist;
  438. insertpos: tai;
  439. constructor create(l: tasmlist; pos: tai; d: tdef);
  440. procedure replace(ai: tai; d: tdef); override;
  441. end;
  442. ttai_lowleveltypedconstbuilder = class(ttai_typedconstbuilder)
  443. protected
  444. procedure mark_anon_aggregate_alignment; override;
  445. procedure insert_marked_aggregate_alignment(def: tdef); override;
  446. procedure finalize_asmlist(sym: tasmsymbol; def: tdef; section: TAsmSectiontype; const secname: TSymStr; alignment: shortint; const options: ttcasmlistoptions); override;
  447. public
  448. { set the default value for caggregateinformation (= tlowlevelaggregateinformation) }
  449. class constructor classcreate;
  450. function emit_placeholder(def: tdef): ttypedconstplaceholder; override;
  451. end;
  452. var
  453. ctai_typedconstbuilder: ttai_typedconstbuilderclass;
  454. implementation
  455. uses
  456. cutils,
  457. verbose,globals,systems,widestr,
  458. fmodule,
  459. symtable,symutil,defutil;
  460. {****************************************************************************
  461. taggregateinformation
  462. ****************************************************************************}
  463. function taggregateinformation.getcuroffset: asizeint;
  464. var
  465. field: tfieldvarsym;
  466. begin
  467. if assigned(curfield) then
  468. result:=curfield.fieldoffset+curfield.vardef.size
  469. else if curindex<>-1 then
  470. begin
  471. field:=tfieldvarsym(tabstractrecorddef(def).symtable.symlist[curindex]);
  472. result:=field.fieldoffset+field.vardef.size
  473. end
  474. else
  475. result:=0
  476. end;
  477. procedure taggregateinformation.setnextfieldname(AValue: TIDString);
  478. begin
  479. if (fnextfieldname<>'') or
  480. not anonrecord then
  481. internalerror(2015071503);
  482. fnextfieldname:=AValue;
  483. end;
  484. constructor taggregateinformation.create(_def: tdef; _typ: ttypedconstkind);
  485. begin
  486. fdef:=_def;
  487. ftyp:=_typ;
  488. fcurindex:=-1;
  489. fnextindex:=-1;
  490. end;
  491. function taggregateinformation.prepare_next_field(nextfielddef: tdef): asizeint;
  492. var
  493. sym: tsym;
  494. currentoffset,nextoffset: asizeint;
  495. i: longint;
  496. begin
  497. { get the next field and its offset, and make that next field the current
  498. one }
  499. if assigned(nextfield) then
  500. begin
  501. nextoffset:=nextfield.fieldoffset;
  502. currentoffset:=curoffset;
  503. curfield:=nextfield;
  504. end
  505. else
  506. begin
  507. { must set nextfield for unions and objects, as we cannot
  508. automatically detect the "next" field in that case }
  509. if ((def.typ=recorddef) and
  510. trecorddef(def).isunion) or
  511. is_object(def) then
  512. internalerror(2014091202);
  513. { if we are constructing this record as data gets emitted, add a field
  514. for this data }
  515. if anonrecord then
  516. begin
  517. trecorddef(def).add_field_by_def(fnextfieldname,nextfielddef);
  518. fnextfieldname:='';
  519. end
  520. else if fnextfieldname<>'' then
  521. internalerror(2015071501);
  522. currentoffset:=curoffset;
  523. { find next field }
  524. i:=curindex;
  525. repeat
  526. inc(i);
  527. sym:=tsym(tabstractrecorddef(def).symtable.symlist[i]);
  528. until is_normal_fieldvarsym(sym);
  529. curfield:=tfieldvarsym(sym);
  530. nextoffset:=curfield.fieldoffset;
  531. curindex:=i;
  532. end;
  533. { need padding? }
  534. result:=nextoffset-currentoffset;
  535. end;
  536. {****************************************************************************
  537. ttypedconstplaceholder
  538. ****************************************************************************}
  539. constructor ttypedconstplaceholder.create(d: tdef);
  540. begin
  541. def:=d;
  542. end;
  543. {****************************************************************************
  544. tai_abstracttypedconst
  545. ****************************************************************************}
  546. procedure tai_abstracttypedconst.setdef(def: tdef);
  547. begin
  548. { should not be changed, rewrite the calling code if this happens }
  549. if assigned(fdef) then
  550. Internalerror(2014080203);
  551. fdef:=def;
  552. end;
  553. constructor tai_abstracttypedconst.create(_adetyp: ttypedconstkind; _def: tdef);
  554. begin
  555. inherited create;
  556. typ:=ait_typedconst;
  557. fadetyp:=_adetyp;
  558. fdef:=_def;
  559. end;
  560. {****************************************************************************
  561. tai_simpletypedconst
  562. ****************************************************************************}
  563. procedure tai_simpletypedconst.setval(AValue: tai);
  564. begin
  565. fval:=AValue;
  566. end;
  567. constructor tai_simpletypedconst.create(_def: tdef; _val: tai);
  568. begin
  569. inherited create(tck_simple,_def);
  570. fval:=_val;
  571. end;
  572. destructor tai_simpletypedconst.destroy;
  573. begin
  574. fval.free;
  575. inherited destroy;
  576. end;
  577. {****************************************************************************
  578. tai_aggregatetypedconst.tadeenumerator
  579. ****************************************************************************}
  580. constructor tai_aggregatetypedconst.tadeenumerator.create(data: tai_aggregatetypedconst);
  581. begin
  582. fvalues:=data.fvalues;
  583. fvaluespos:=-1;
  584. end;
  585. function tai_aggregatetypedconst.tadeenumerator.getcurrent: tai_abstracttypedconst;
  586. begin
  587. result:=tai_abstracttypedconst(fvalues[fvaluespos]);
  588. end;
  589. function tai_aggregatetypedconst.tadeenumerator.movenext: boolean;
  590. begin
  591. if fvaluespos<pred(fvalues.count) then
  592. begin
  593. inc(fvaluespos);
  594. result:=true
  595. end
  596. else
  597. result:=false;
  598. end;
  599. procedure tai_aggregatetypedconst.tadeenumerator.reset;
  600. begin
  601. fvaluespos:=0
  602. end;
  603. {****************************************************************************
  604. tai_aggregatetypedconst
  605. ****************************************************************************}
  606. procedure tai_aggregatetypedconst.convert_to_string;
  607. var
  608. ai: tai_abstracttypedconst;
  609. newstr: tai_string;
  610. begin
  611. newstr:=tai_string.Create('');
  612. for ai in self do
  613. begin
  614. if ai.adetyp<>tck_simple then
  615. internalerror(2014070103);
  616. add_to_string(newstr,tai_simpletypedconst(ai).val);
  617. ai.free;
  618. end;
  619. fvalues.count:=0;
  620. { the "nil" def will be replaced with an array def of the appropriate
  621. size once we're finished adding data, so we don't create intermediate
  622. arraydefs all the time }
  623. fvalues.add(tai_simpletypedconst.create(nil,newstr));
  624. end;
  625. procedure tai_aggregatetypedconst.add_to_string(strtai: tai_string; othertai: tai);
  626. begin
  627. case othertai.typ of
  628. ait_string:
  629. begin
  630. strtai.str:=reallocmem(strtai.str,strtai.len+tai_string(othertai).len+1);
  631. { also copy null terminator }
  632. move(tai_string(othertai).str[0],strtai.str[strtai.len],tai_string(othertai).len+1);
  633. { the null terminator is not part of the string data }
  634. strtai.len:=strtai.len+tai_string(othertai).len;
  635. end;
  636. ait_const:
  637. begin
  638. if tai_const(othertai).size<>1 then
  639. internalerror(2014070101);
  640. { it was already len+1 to hold the #0 -> realloc to len+2 }
  641. strtai.str:=reallocmem(strtai.str,strtai.len+2);
  642. strtai.str[strtai.len]:=ansichar(tai_const(othertai).value);
  643. strtai.str[strtai.len+1]:=#0;
  644. inc(strtai.len);
  645. end;
  646. else
  647. internalerror(2014070102);
  648. end;
  649. end;
  650. constructor tai_aggregatetypedconst.create(_adetyp: ttypedconstkind; _fdef: tdef);
  651. begin
  652. inherited;
  653. fisstring:=false;
  654. fvalues:=tfpobjectlist.create(true);
  655. end;
  656. function tai_aggregatetypedconst.getenumerator: tadeenumerator;
  657. begin
  658. result:=tadeenumerator.create(self);
  659. end;
  660. procedure tai_aggregatetypedconst.addvalue(val: tai_abstracttypedconst);
  661. begin
  662. { merge string constants and ordinal constants added in an array of
  663. char, to unify the length and the string data }
  664. if fisstring or
  665. ((val.adetyp=tck_simple) and
  666. (tai_simpletypedconst(val).val.typ=ait_string)) then
  667. begin
  668. if not fisstring and
  669. (fvalues.count>0) then
  670. convert_to_string;
  671. fisstring:=true;
  672. case fvalues.count of
  673. 0: fvalues.add(val);
  674. 1:
  675. begin
  676. add_to_string(tai_string(tai_simpletypedconst(fvalues[0]).val),tai_simpletypedconst(val).val);
  677. val.free
  678. end
  679. else
  680. internalerror(2014070104);
  681. end;
  682. end
  683. else
  684. fvalues.add(val);
  685. end;
  686. function tai_aggregatetypedconst.valuecount: longint;
  687. begin
  688. result:=fvalues.count;
  689. end;
  690. procedure tai_aggregatetypedconst.insertvaluebeforepos(val: tai_abstracttypedconst; pos: longint);
  691. begin
  692. fvalues.insert(pos,val);
  693. end;
  694. procedure tai_aggregatetypedconst.replacevalueatpos(val: tai_abstracttypedconst; pos: longint);
  695. begin
  696. { since fvalues owns its elements, it will automatically free the old value }
  697. fvalues[pos]:=val;
  698. end;
  699. procedure tai_aggregatetypedconst.changetorecord(_def: trecorddef);
  700. begin
  701. { must be a record of the same size as the current data }
  702. if assigned(fdef) and
  703. (fdef.size<>_def.size) then
  704. internalerror(2015122402);
  705. fdef:=_def;
  706. fadetyp:=tck_record;
  707. end;
  708. procedure tai_aggregatetypedconst.finish;
  709. begin
  710. if fisstring then
  711. begin
  712. { set the def: an array of char with the same length as the string
  713. data }
  714. if fvalues.count<>1 then
  715. internalerror(2014070105);
  716. tai_simpletypedconst(fvalues[0]).fdef:=
  717. carraydef.getreusable(cansichartype,
  718. tai_string(tai_simpletypedconst(fvalues[0]).val).len);
  719. end;
  720. end;
  721. destructor tai_aggregatetypedconst.destroy;
  722. begin
  723. fvalues.free;
  724. inherited destroy;
  725. end;
  726. {*****************************************************************************
  727. ttai_typedconstbuilder
  728. *****************************************************************************}
  729. function ttai_typedconstbuilder.getcurragginfo: taggregateinformation;
  730. begin
  731. if assigned(faggregateinformation) and
  732. (faggregateinformation.count>0) then
  733. result:=taggregateinformation(faggregateinformation[faggregateinformation.count-1])
  734. else
  735. result:=nil;
  736. end;
  737. procedure ttai_typedconstbuilder.set_next_field(AValue: tfieldvarsym);
  738. var
  739. info: taggregateinformation;
  740. begin
  741. info:=curagginfo;
  742. if not assigned(info) then
  743. internalerror(2014091206);
  744. info.nextfield:=AValue;
  745. end;
  746. procedure ttai_typedconstbuilder.set_next_field_name(AValue: TIDString);
  747. var
  748. info: taggregateinformation;
  749. begin
  750. info:=curagginfo;
  751. if not assigned(info) then
  752. internalerror(2015071502);
  753. info.nextfieldname:='$'+AValue;
  754. end;
  755. procedure ttai_typedconstbuilder.pad_next_field(nextfielddef: tdef);
  756. var
  757. fillbytes: asizeint;
  758. begin
  759. fillbytes:=curagginfo.prepare_next_field(nextfielddef);
  760. while fillbytes>0 do
  761. begin
  762. do_emit_tai(tai_const.create_8bit(0),u8inttype);
  763. dec(fillbytes);
  764. end;
  765. end;
  766. function ttai_typedconstbuilder.get_internal_data_section_index(typ: TAsmSectiontype): longint;
  767. begin
  768. { avoid wrong warning by -Oodfa }
  769. result:=-1;
  770. for result:=low(finternal_data_section_info) to high(finternal_data_section_info) do
  771. if finternal_data_section_info[result].sectype=typ then
  772. exit;
  773. result:=-1;
  774. end;
  775. function ttai_typedconstbuilder.get_internal_data_section_start_label: tasmlabel;
  776. begin
  777. { on Darwin, dead code/data stripping happens based on non-temporary
  778. labels (any label that doesn't start with "L" -- it doesn't have
  779. to be global) }
  780. if target_info.system in systems_darwin then
  781. current_asmdata.getstaticdatalabel(result)
  782. else if create_smartlink_library then
  783. current_asmdata.getglobaldatalabel(result)
  784. else
  785. current_asmdata.getlocaldatalabel(result);
  786. end;
  787. function ttai_typedconstbuilder.get_internal_data_section_internal_label: tasmlabel;
  788. begin
  789. if create_smartlink_library then
  790. { all labels need to be global in case they're in another object }
  791. current_asmdata.getglobaldatalabel(result)
  792. else
  793. { no special requirement for the label -> just get a local one }
  794. current_asmdata.getlocaldatalabel(result);
  795. end;
  796. function ttai_typedconstbuilder.aggregate_kind(def: tdef): ttypedconstkind;
  797. begin
  798. if (def.typ in [recorddef,filedef,variantdef]) or
  799. is_object(def) or
  800. ((def.typ=procvardef) and
  801. not tprocvardef(def).is_addressonly and
  802. not is_block(def)) then
  803. result:=tck_record
  804. else if ((def.typ=arraydef) and
  805. not is_dynamic_array(def)) or
  806. ((def.typ=setdef) and
  807. not is_smallset(def)) or
  808. is_shortstring(def) then
  809. result:=tck_array
  810. else
  811. result:=tck_simple;
  812. end;
  813. procedure ttai_typedconstbuilder.finalize_asmlist_prepare(const options: ttcasmlistoptions; var alignment: shortint);
  814. begin
  815. if tcalo_apply_constalign in options then
  816. alignment:=const_align(alignment);
  817. { have we finished all aggregates? }
  818. if (getcurragginfo<>nil) and
  819. { in case of syntax errors, the aggregate may not have been finished }
  820. (ErrorCount=0) then
  821. internalerror(2015072301);
  822. { must call finalize_vectorized_dead_strip_asmlist() instead }
  823. if (([tcalo_vectorized_dead_strip_start,
  824. tcalo_vectorized_dead_strip_item,
  825. tcalo_vectorized_dead_strip_end]*options)<>[]) and
  826. not fvectorized_finalize_called then
  827. internalerror(2015110602);
  828. end;
  829. procedure ttai_typedconstbuilder.finalize_asmlist(sym: tasmsymbol; def: tdef; section: TAsmSectiontype; const secname: TSymStr; alignment: shortint; const options: ttcasmlistoptions);
  830. var
  831. prelist: tasmlist;
  832. begin
  833. finalize_asmlist_prepare(options, alignment);
  834. prelist:=tasmlist.create;
  835. { only now add items based on the symbolname, because it may be
  836. modified by the "section" specifier in case of a typed constant }
  837. { both in case the data should be dead strippable and never dead
  838. stripped, it should be in a separate section (so this property doesn't
  839. affect other data) }
  840. if ([tcalo_no_dead_strip,tcalo_make_dead_strippable]*options)<>[] then
  841. begin
  842. maybe_new_object_file(prelist);
  843. { we always need a new section here, since if we started a new
  844. object file then we have to say what the section is, and otherwise
  845. we need a new section because that's how the dead stripping works }
  846. new_section(prelist,section,secname,alignment);
  847. end
  848. else if tcalo_new_section in options then
  849. begin
  850. { insert ait_cutobject for smart-linking on targets
  851. that do not support smarlinking based on sections,
  852. like msdos }
  853. if not (tf_smartlink_sections in target_info.flags) then
  854. maybe_new_object_file(prelist);
  855. new_section(prelist,section,secname,alignment);
  856. end
  857. else
  858. prelist.concat(cai_align.Create(alignment));
  859. { On Darwin, use .reference to ensure the data doesn't get dead stripped.
  860. On other platforms, the data must be in the .fpc section (which is
  861. kept via the linker script) }
  862. if tcalo_no_dead_strip in options then
  863. begin
  864. if (target_info.system in systems_darwin) then
  865. begin
  866. { Objective-C section declarations contain "no_dead_strip"
  867. attributes if none of their symbols need to be stripped -> don't
  868. add extra ".reference" statement for their symbols (gcc/clang
  869. don't either) }
  870. if not(section in [low(TObjCAsmSectionType)..high(TObjCAsmSectionType)]) then
  871. prelist.concat(tai_directive.Create(asd_reference,sym.name))
  872. end
  873. else if section<>sec_fpc then
  874. internalerror(2015101402);
  875. end;
  876. if not(tcalo_is_lab in options) then
  877. if sym.bind=AB_LOCAL then
  878. prelist.concat(tai_symbol.Create(sym,0))
  879. else
  880. prelist.concat(tai_symbol.Create_Global(sym,0))
  881. else
  882. prelist.concat(tai_label.Create(tasmlabel(sym)));
  883. if tcalo_weak in options then
  884. prelist.concat(tai_directive.Create(asd_weak_definition,sym.name));
  885. { insert the symbol information before the data }
  886. fasmlist.insertlist(prelist);
  887. { end of the symbol }
  888. fasmlist.concat(tai_symbol_end.Createname(sym.name));
  889. { free the temporary list }
  890. prelist.free;
  891. end;
  892. procedure ttai_typedconstbuilder.finalize_asmlist_add_indirect_sym(sym: tasmsymbol; def: tdef; section: TAsmSectiontype; const secname: TSymStr; alignment: shortint; const options: ttcasmlistoptions);
  893. var
  894. ptrdef : tdef;
  895. symind : tasmsymbol;
  896. indtcb : ttai_typedconstbuilder;
  897. indsecname : tsymstr;
  898. begin
  899. if (tcalo_data_force_indirect in options) and
  900. (sym.bind in [AB_GLOBAL,AB_COMMON]) and
  901. (sym.typ=AT_DATA) then
  902. begin
  903. ptrdef:=cpointerdef.getreusable(def);
  904. symind:=current_asmdata.DefineAsmSymbol(sym.name,AB_INDIRECT,AT_DATA,ptrdef);
  905. { reuse the section if possible }
  906. if section=sec_rodata then
  907. indsecname:=secname
  908. else
  909. indsecname:=lower(symind.name);
  910. indtcb:=ctai_typedconstbuilder.create([tcalo_new_section]);
  911. indtcb.emit_tai(tai_const.create_sym_offset(sym,0),ptrdef);
  912. current_asmdata.asmlists[al_indirectglobals].concatlist(indtcb.get_final_asmlist(
  913. symind,
  914. ptrdef,
  915. sec_rodata,
  916. indsecname,
  917. ptrdef.alignment));
  918. indtcb.free;
  919. if not (target_info.system in systems_indirect_var_imports) then
  920. current_module.add_public_asmsym(symind.name,AB_INDIRECT,AT_DATA);
  921. end;
  922. end;
  923. procedure ttai_typedconstbuilder.finalize_vectorized_dead_strip_asmlist(def: tdef; const basename, itemname: TSymStr; st: tsymtable; alignment: shortint; options: ttcasmlistoptions);
  924. var
  925. sym: tasmsymbol;
  926. secname: TSymStr;
  927. sectype: TAsmSectiontype;
  928. asmtype : TAsmsymtype;
  929. customsecname: boolean;
  930. dsopts : ttcdeadstripsectionsymboloptions;
  931. begin
  932. fvectorized_finalize_called:=true;
  933. sym:=nil;
  934. customsecname:=get_vectorized_dead_strip_custom_section_name(basename,st,secname);
  935. if customsecname then
  936. sectype:=sec_user
  937. else
  938. sectype:=sec_data;
  939. dsopts:=[tcdssso_define];
  940. if tcalo_is_public_asm in options then
  941. include(dsopts,tcdssso_register_asmsym);
  942. if tcalo_data_force_indirect in options then
  943. include(dsopts,tcdssso_use_indirect);
  944. if tcalo_vectorized_dead_strip_start in options then
  945. begin
  946. { the start and end names are predefined }
  947. if itemname<>'' then
  948. internalerror(2015110801);
  949. sym:=get_vectorized_dead_strip_section_symbol_start(basename,st,dsopts);
  950. if not customsecname then
  951. secname:=make_mangledname(basename,st,'1_START');
  952. end
  953. else if tcalo_vectorized_dead_strip_end in options then
  954. begin
  955. { the start and end names are predefined }
  956. if itemname<>'' then
  957. internalerror(2015110802);
  958. sym:=get_vectorized_dead_strip_section_symbol_end(basename,st,dsopts);
  959. if not customsecname then
  960. secname:=make_mangledname(basename,st,'3_END');
  961. end
  962. else if tcalo_vectorized_dead_strip_item in options then
  963. begin
  964. if tcalo_data_force_indirect in options then
  965. asmtype:=AT_DATA_FORCEINDIRECT
  966. else
  967. asmtype:=AT_DATA;
  968. sym:=current_asmdata.DefineAsmSymbol(make_mangledname(basename,st,itemname),AB_GLOBAL,asmtype,def);
  969. if tcalo_is_public_asm in options then
  970. current_module.add_public_asmsym(sym);
  971. if not customsecname then
  972. secname:=make_mangledname(basename,st,'2_'+itemname);
  973. exclude(options,tcalo_vectorized_dead_strip_item);
  974. end;
  975. current_module.linkorderedsymbols.concat(sym.Name);
  976. finalize_asmlist(sym,def,sectype,secname,alignment,options);
  977. end;
  978. procedure ttai_typedconstbuilder.do_emit_tai(p: tai; def: tdef);
  979. begin
  980. { by default we don't care about the type }
  981. fasmlist.concat(p);
  982. end;
  983. function ttai_typedconstbuilder.get_final_asmlist(sym: tasmsymbol; def: tdef; section: TAsmSectiontype; const secname: TSymStr; alignment: longint): tasmlist;
  984. begin
  985. if not fasmlist_finalized then
  986. begin
  987. finalize_asmlist(sym,def,section,secname,alignment,foptions);
  988. finalize_asmlist_add_indirect_sym(sym,def,section,secname,alignment,foptions);
  989. fasmlist_finalized:=true;
  990. end;
  991. result:=fasmlist;
  992. end;
  993. function ttai_typedconstbuilder.get_final_asmlist_vectorized_dead_strip(def: tdef; const basename, itemname: TSymStr; st: TSymtable; alignment: longint): tasmlist;
  994. begin
  995. if not fasmlist_finalized then
  996. begin
  997. finalize_vectorized_dead_strip_asmlist(def,basename,itemname,st,alignment,foptions);
  998. fasmlist_finalized:=true;
  999. end;
  1000. result:=fasmlist;
  1001. end;
  1002. class function ttai_typedconstbuilder.get_string_symofs(typ: tstringtype; winlikewidestring: boolean): pint;
  1003. begin
  1004. { darwin's linker does not support negative offsets }
  1005. if not(target_info.system in systems_darwin) then
  1006. result:=0
  1007. else
  1008. result:=get_string_header_size(typ,winlikewidestring);
  1009. end;
  1010. class function ttai_typedconstbuilder.get_dynarray_symofs:pint;
  1011. begin
  1012. { darwin's linker does not support negative offsets }
  1013. if not (target_info.system in systems_darwin) then
  1014. result:=0
  1015. else
  1016. result:=get_dynarray_header_size;
  1017. end;
  1018. class function ttai_typedconstbuilder.get_string_header_size(typ: tstringtype; winlikewidestring: boolean): pint;
  1019. var
  1020. ansistring_header_size: pint;
  1021. unicodestring_header_size: pint;
  1022. begin
  1023. ansistring_header_size:=
  1024. { encoding }
  1025. 2 +
  1026. { elesize }
  1027. 2 +
  1028. {$ifdef cpu64bitaddr}
  1029. { alignment }
  1030. 4 +
  1031. {$endif cpu64bitaddr}
  1032. { reference count }
  1033. sizesinttype.size +
  1034. { length }
  1035. sizesinttype.size;
  1036. unicodestring_header_size:=ansistring_header_size;
  1037. case typ of
  1038. st_ansistring:
  1039. result:=ansistring_header_size;
  1040. st_unicodestring:
  1041. result:=unicodestring_header_size;
  1042. st_widestring:
  1043. if winlikewidestring then
  1044. result:=0
  1045. else
  1046. result:=unicodestring_header_size;
  1047. else
  1048. result:=0;
  1049. end;
  1050. end;
  1051. class function ttai_typedconstbuilder.get_dynarray_header_size:pint;
  1052. begin
  1053. result:=
  1054. { reference count }
  1055. ptrsinttype.size +
  1056. { high value }
  1057. sizesinttype.size;
  1058. end;
  1059. constructor ttai_typedconstbuilder.create(const options: ttcasmlistoptions);
  1060. begin
  1061. inherited create;
  1062. fasmlist:=tasmlist.create;
  1063. foptions:=options;
  1064. { queue is empty }
  1065. fqueue_offset:=low(fqueue_offset);
  1066. finternal_data_current_section:=sec_none;
  1067. end;
  1068. destructor ttai_typedconstbuilder.destroy;
  1069. begin
  1070. { the queue should have been flushed if it was used }
  1071. if fqueue_offset<>low(fqueue_offset) then
  1072. internalerror(2014062901);
  1073. faggregateinformation.free;
  1074. fasmlist.free;
  1075. inherited destroy;
  1076. end;
  1077. procedure ttai_typedconstbuilder.start_internal_data_builder(list: tasmlist; sectype: TAsmSectiontype; const secname: TSymStr; out tcb: ttai_typedconstbuilder; out l: tasmlabel);
  1078. var
  1079. options: ttcasmlistoptions;
  1080. foundsec: longint;
  1081. begin
  1082. { you can't start multiple concurrent internal data builders for the
  1083. same tcb, finish the first before starting another }
  1084. if finternal_data_current_section<>sec_none then
  1085. internalerror(2016082801);
  1086. { we don't know what was previously added to this list, so always add
  1087. a section header. We'll use the same section name in case multiple
  1088. items are added to the same kind of section (rodata, rodata_no_rel,
  1089. ...), so that everything will still end up in the same section even if
  1090. there are multiple section headers }
  1091. options:=[tcalo_is_lab,tcalo_new_section];
  1092. finternal_data_current_section:=sectype;
  1093. l:=nil;
  1094. { did we already create a section of this type for the internal data of
  1095. this builder? }
  1096. foundsec:=get_internal_data_section_index(sectype);
  1097. if foundsec=-1 then
  1098. begin
  1099. { we only need to start a dead-strippable section of data at the
  1100. start of the first subsection of this kind for this block.
  1101. exception: if dead stripping happens based on objects/libraries,
  1102. then we only have to create a new object file for the first
  1103. internal data section of any kind (all the rest will simply be put
  1104. in the same object file) }
  1105. if create_smartlink then
  1106. begin
  1107. if not create_smartlink_library or
  1108. (length(finternal_data_section_info)=0) then
  1109. include(options,tcalo_make_dead_strippable);
  1110. { on Darwin, dead code/data stripping happens based on non-
  1111. temporary labels (any label that doesn't start with "L" -- it
  1112. doesn't have to be global) -> add a non-temporary lobel at the
  1113. start of every kind of subsection created in this builder }
  1114. if target_info.system in systems_darwin then
  1115. l:=get_internal_data_section_start_label;
  1116. end;
  1117. foundsec:=length(finternal_data_section_info);
  1118. setlength(finternal_data_section_info,foundsec+1);
  1119. finternal_data_section_info[foundsec].sectype:=sectype;
  1120. end;
  1121. if not assigned(finternal_data_asmlist) and
  1122. (cs_create_smart in current_settings.moduleswitches) then
  1123. begin
  1124. l:=get_internal_data_section_start_label;
  1125. { the internal data list should only be assigned by this routine,
  1126. the first time that an internal data block is started }
  1127. if not assigned(list) or
  1128. assigned(finternal_data_asmlist) then
  1129. internalerror(2015032101);
  1130. finternal_data_asmlist:=list;
  1131. end
  1132. { all internal data for this tcb must go to the same list (otherwise all
  1133. data we want to add to the dead-strippable block is not guaranteed to
  1134. be sequential and e.g. in the same object file in case of library-based
  1135. dead stripping) }
  1136. else if (assigned(finternal_data_asmlist) and
  1137. (list<>finternal_data_asmlist)) or
  1138. not assigned(list) then
  1139. internalerror(2015032101);
  1140. finternal_data_asmlist:=list;
  1141. if not assigned(l) then
  1142. l:=get_internal_data_section_internal_label;
  1143. { first section of this kind -> set name }
  1144. if finternal_data_section_info[foundsec].secname='' then
  1145. if secname='' then
  1146. finternal_data_section_info[foundsec].secname:=l.Name
  1147. else
  1148. finternal_data_section_info[foundsec].secname:=secname
  1149. { if the name is specified multiple times, it must match }
  1150. else if (secname<>'') and
  1151. (finternal_data_section_info[foundsec].secname<>secname) then
  1152. internalerror(2015032401);
  1153. tcb:=ttai_typedconstbuilderclass(classtype).create(options);
  1154. end;
  1155. procedure ttai_typedconstbuilder.finish_internal_data_builder(var tcb: ttai_typedconstbuilder; l: tasmlabel; def: tdef; alignment: longint);
  1156. begin
  1157. finternal_data_asmlist.concatList(tcb.get_final_asmlist(l,def,
  1158. finternal_data_current_section,
  1159. finternal_data_section_info[get_internal_data_section_index(finternal_data_current_section)].secname,
  1160. alignment));
  1161. tcb.free;
  1162. tcb:=nil;
  1163. finternal_data_current_section:=sec_none;
  1164. end;
  1165. procedure ttai_typedconstbuilder.emit_tai(p: tai; def: tdef);
  1166. var
  1167. kind: ttypedconstkind;
  1168. info: taggregateinformation;
  1169. begin
  1170. { these elements can be aggregates themselves, e.g. a shortstring can
  1171. be emitted as a series of bytes and char arrays }
  1172. kind:=aggregate_kind(def);
  1173. info:=curagginfo;
  1174. if (kind<>tck_simple) and
  1175. (not assigned(info) or
  1176. (info.typ<>kind)) then
  1177. internalerror(2014091001);
  1178. { if we're emitting a record, handle the padding bytes, and in case of
  1179. an anonymous record also add the next field }
  1180. if assigned(info) then
  1181. begin
  1182. { queue_init already adds padding }
  1183. if not queue_is_active and
  1184. (is_record(info.def) or
  1185. is_object(info.def)) and
  1186. { may add support for these later }
  1187. not is_packed_record_or_object(info.def) then
  1188. pad_next_field(def);
  1189. end;
  1190. { emit the data }
  1191. do_emit_tai(p,def);
  1192. end;
  1193. procedure ttai_typedconstbuilder.emit_tai_procvar2procdef(p: tai; pvdef: tprocvardef);
  1194. begin
  1195. { nothing special by default, since we don't care about the type }
  1196. emit_tai(p,pvdef);
  1197. end;
  1198. procedure ttai_typedconstbuilder.maybe_emit_tail_padding(def: tdef);
  1199. var
  1200. info: taggregateinformation;
  1201. fillbytes: asizeint;
  1202. begin
  1203. info:=curagginfo;
  1204. if not assigned(info) then
  1205. internalerror(2014091002);
  1206. if def<>info.def then
  1207. internalerror(2014091205);
  1208. if (is_record(def) or
  1209. is_object(def)) and
  1210. not is_packed_record_or_object(def) then
  1211. begin
  1212. fillbytes:=def.size-info.curoffset;
  1213. while fillbytes>0 do
  1214. begin
  1215. do_emit_tai(Tai_const.Create_8bit(0),u8inttype);
  1216. dec(fillbytes)
  1217. end;
  1218. end;
  1219. end;
  1220. function ttai_typedconstbuilder.emit_string_const_common(stringtype: tstringtype; len: asizeint; encoding: tstringencoding; var startlab: tasmlabel): tasmlabofs;
  1221. var
  1222. string_symofs: asizeint;
  1223. charptrdef: tdef;
  1224. elesize: word;
  1225. begin
  1226. result.lab:=startlab;
  1227. result.ofs:=0;
  1228. { pack the data, so that we don't add unnecessary null bytes after the
  1229. constant string }
  1230. begin_anonymous_record('$'+get_dynstring_rec_name(stringtype,false,len),1,sizeof(TConstPtrUInt),1);
  1231. string_symofs:=get_string_symofs(stringtype,false);
  1232. { encoding }
  1233. emit_tai(tai_const.create_16bit(encoding),u16inttype);
  1234. inc(result.ofs,2);
  1235. { element size }
  1236. case stringtype of
  1237. st_ansistring:
  1238. begin
  1239. elesize:=1;
  1240. charptrdef:=charpointertype;
  1241. end;
  1242. st_unicodestring:
  1243. begin
  1244. elesize:=2;
  1245. charptrdef:=widecharpointertype;
  1246. end
  1247. else
  1248. internalerror(2014080401);
  1249. end;
  1250. emit_tai(tai_const.create_16bit(elesize),u16inttype);
  1251. inc(result.ofs,2);
  1252. {$ifdef cpu64bitaddr}
  1253. { dummy for alignment }
  1254. emit_tai(tai_const.create_32bit(0),u32inttype);
  1255. inc(result.ofs,4);
  1256. {$endif cpu64bitaddr}
  1257. emit_tai(tai_const.create_sizeint(-1),sizesinttype);
  1258. inc(result.ofs,sizesinttype.size);
  1259. emit_tai(tai_const.create_sizeint(len),sizesinttype);
  1260. inc(result.ofs,sizesinttype.size);
  1261. if string_symofs=0 then
  1262. begin
  1263. { results in slightly more efficient code }
  1264. emit_tai(tai_label.create(result.lab),charptrdef);
  1265. result.ofs:=0;
  1266. { create new label of the same kind (including whether or not the
  1267. name starts with target_asm.labelprefix in case it's AB_LOCAL,
  1268. so we keep the difference depending on whether the original was
  1269. allocated via getstatic/getlocal/getglobal datalabel) }
  1270. startlab:=tasmlabel.create(current_asmdata.AsmSymbolDict,startlab.name+'$strlab',startlab.bind,startlab.typ);
  1271. end;
  1272. { sanity check }
  1273. if result.ofs<>string_symofs then
  1274. internalerror(2012051701);
  1275. end;
  1276. function ttai_typedconstbuilder.get_dynstring_def_for_type(stringtype: tstringtype; winlikewidestring: boolean): tstringdef;
  1277. begin
  1278. if stringtype=st_ansistring then
  1279. result:=tstringdef(cansistringtype)
  1280. else if (stringtype=st_unicodestring) or
  1281. ((stringtype=st_widestring) and
  1282. not winlikewidestring) then
  1283. result:=tstringdef(cunicodestringtype)
  1284. else if stringtype=st_widestring then
  1285. result:=tstringdef(cwidestringtype)
  1286. else
  1287. internalerror(2015122101);
  1288. end;
  1289. procedure ttai_typedconstbuilder.begin_aggregate_internal(def: tdef; anonymous: boolean);
  1290. var
  1291. info: taggregateinformation;
  1292. tck: ttypedconstkind;
  1293. begin
  1294. tck:=aggregate_kind(def);
  1295. if tck=tck_simple then
  1296. exit;
  1297. if not assigned(faggregateinformation) then
  1298. faggregateinformation:=tfpobjectlist.create
  1299. { if we're starting an anonymous record, we can't align it yet because
  1300. the alignment depends on the fields that will be added -> we'll do
  1301. it at the end }
  1302. else if not anonymous or
  1303. ((def.typ<>recorddef) and
  1304. not is_object(def)) then
  1305. begin
  1306. { add padding if necessary, and update the current field/offset }
  1307. info:=curagginfo;
  1308. if (is_record(curagginfo.def) or
  1309. is_object(curagginfo.def)) and
  1310. not is_packed_record_or_object(curagginfo.def) then
  1311. begin
  1312. if queue_is_active then
  1313. internalerror(2015073001);
  1314. pad_next_field(def);
  1315. end;
  1316. end
  1317. { if this is the outer record, no padding is required; the alignment
  1318. has to be specified explicitly in that case via get_final_asmlist() }
  1319. else if assigned(curagginfo) and
  1320. (curagginfo.def.typ=recorddef) then
  1321. { mark where we'll have to insert the padding bytes at the end }
  1322. mark_anon_aggregate_alignment;
  1323. info:=caggregateinformation.create(def,aggregate_kind(def));
  1324. faggregateinformation.add(info);
  1325. end;
  1326. procedure ttai_typedconstbuilder.end_aggregate_internal(def: tdef; anonymous: boolean);
  1327. var
  1328. info: taggregateinformation;
  1329. tck: ttypedconstkind;
  1330. begin
  1331. tck:=aggregate_kind(def);
  1332. if tck=tck_simple then
  1333. exit;
  1334. { add tail padding if necessary }
  1335. maybe_emit_tail_padding(def);
  1336. { pop and free the information }
  1337. info:=curagginfo;
  1338. faggregateinformation.count:=faggregateinformation.count-1;
  1339. info.free;
  1340. end;
  1341. class function ttai_typedconstbuilder.get_vectorized_dead_strip_section_symbol(const basename: string; st: tsymtable; options: ttcdeadstripsectionsymboloptions; start: boolean): tasmsymbol;
  1342. var
  1343. name: TSymStr;
  1344. asmtype : TAsmsymtype;
  1345. begin
  1346. if start then
  1347. name:=make_mangledname(basename,st,'START')
  1348. else
  1349. name:=make_mangledname(basename,st,'END');
  1350. if tcdssso_define in options then
  1351. begin
  1352. if tcdssso_use_indirect in options then
  1353. asmtype:=AT_DATA_FORCEINDIRECT
  1354. else
  1355. asmtype:=AT_DATA;
  1356. result:=current_asmdata.DefineAsmSymbol(name,AB_GLOBAL,asmtype,voidpointertype);
  1357. if tcdssso_register_asmsym in options then
  1358. current_module.add_public_asmsym(result);
  1359. end
  1360. else
  1361. begin
  1362. result:=current_asmdata.RefAsmSymbol(name,AT_DATA,tcdssso_use_indirect in options);
  1363. if tcdssso_register_asmsym in options then
  1364. current_module.add_extern_asmsym(result);
  1365. end;
  1366. end;
  1367. class function ttai_typedconstbuilder.get_vectorized_dead_strip_custom_section_name(const basename: TSymStr; st: tsymtable; out secname: TSymStr): boolean;
  1368. begin
  1369. result:=false;
  1370. end;
  1371. class function ttai_typedconstbuilder.get_vectorized_dead_strip_section_symbol_start(const basename: string; st: tsymtable; options: ttcdeadstripsectionsymboloptions): tasmsymbol;
  1372. begin
  1373. result:=get_vectorized_dead_strip_section_symbol(basename,st,options,true);
  1374. end;
  1375. class function ttai_typedconstbuilder.get_vectorized_dead_strip_section_symbol_end(const basename: string; st: tsymtable; options: ttcdeadstripsectionsymboloptions): tasmsymbol;
  1376. begin
  1377. result:=get_vectorized_dead_strip_section_symbol(basename,st,options,false);
  1378. end;
  1379. class function ttai_typedconstbuilder.get_dynstring_rec_name(typ: tstringtype; winlike: boolean; len: asizeint): TSymStr;
  1380. begin
  1381. case typ of
  1382. st_ansistring:
  1383. result:='ansistrrec';
  1384. st_unicodestring,
  1385. st_widestring:
  1386. if (typ=st_unicodestring) or
  1387. not winlike then
  1388. result:='unicodestrrec'
  1389. else
  1390. result:='widestrrec';
  1391. else
  1392. internalerror(2014080402);
  1393. end;
  1394. result:=result+tostr(len);
  1395. end;
  1396. class function ttai_typedconstbuilder.get_dynstring_rec(typ: tstringtype; winlike: boolean; len: asizeint): trecorddef;
  1397. var
  1398. name: TSymStr;
  1399. streledef: tdef;
  1400. strtypesym: ttypesym;
  1401. srsym: tsym;
  1402. srsymtable: tsymtable;
  1403. begin
  1404. name:=get_dynstring_rec_name(typ,winlike,len);
  1405. { search in the interface of all units for the type to reuse it }
  1406. if searchsym_type(name,srsym,srsymtable) then
  1407. begin
  1408. result:=trecorddef(ttypesym(srsym).typedef);
  1409. exit;
  1410. end
  1411. else
  1412. begin
  1413. { also search the implementation of the current unit }
  1414. strtypesym:=try_search_current_module_type(name);
  1415. if assigned(strtypesym) then
  1416. begin
  1417. result:=trecorddef(strtypesym.typedef);
  1418. exit;
  1419. end;
  1420. end;
  1421. if (typ<>st_widestring) or
  1422. not winlike then
  1423. begin
  1424. result:=crecorddef.create_global_internal('$'+name,1,1);
  1425. { encoding }
  1426. result.add_field_by_def('',u16inttype);
  1427. { element size }
  1428. result.add_field_by_def('',u16inttype);
  1429. { elements }
  1430. case typ of
  1431. st_ansistring:
  1432. streledef:=cansichartype;
  1433. st_unicodestring:
  1434. streledef:=cwidechartype;
  1435. else
  1436. internalerror(2016082301);
  1437. end;
  1438. {$ifdef cpu64bitaddr}
  1439. { dummy for alignment }
  1440. result.add_field_by_def('',u32inttype);
  1441. {$endif cpu64bitaddr}
  1442. { reference count }
  1443. result.add_field_by_def('',sizesinttype);
  1444. { length in elements }
  1445. result.add_field_by_def('',sizesinttype);
  1446. end
  1447. else
  1448. begin
  1449. result:=crecorddef.create_global_internal('$'+name,4,
  1450. targetinfos[target_info.system]^.alignment.recordalignmin);
  1451. { length in bytes }
  1452. result.add_field_by_def('',s32inttype);
  1453. streledef:=cwidechartype;
  1454. end;
  1455. { data (include zero terminator) }
  1456. result.add_field_by_def('',carraydef.getreusable(streledef,len+1));
  1457. trecordsymtable(trecorddef(result).symtable).addalignmentpadding;
  1458. end;
  1459. function ttai_typedconstbuilder.emit_ansistring_const(datalist: TAsmList; data: pchar; len: asizeint; encoding: tstringencoding): tasmlabofs;
  1460. var
  1461. s: PChar;
  1462. startlab: tasmlabel;
  1463. ansistrrecdef: trecorddef;
  1464. datadef: tdef;
  1465. datatcb: ttai_typedconstbuilder;
  1466. begin
  1467. start_internal_data_builder(datalist,sec_rodata_norel,'',datatcb,startlab);
  1468. result:=datatcb.emit_string_const_common(st_ansistring,len,encoding,startlab);
  1469. getmem(s,len+1);
  1470. move(data^,s^,len);
  1471. s[len]:=#0;
  1472. { terminating zero included }
  1473. datadef:=carraydef.getreusable(cansichartype,len+1);
  1474. datatcb.maybe_begin_aggregate(datadef);
  1475. datatcb.emit_tai(tai_string.create_pchar(s,len+1),datadef);
  1476. datatcb.maybe_end_aggregate(datadef);
  1477. ansistrrecdef:=datatcb.end_anonymous_record;
  1478. finish_internal_data_builder(datatcb,startlab,ansistrrecdef,const_align(voidpointertype.alignment));
  1479. end;
  1480. function ttai_typedconstbuilder.emit_unicodestring_const(datalist: TAsmList; data: pointer; encoding: tstringencoding; winlike: boolean):tasmlabofs;
  1481. var
  1482. i, strlength: longint;
  1483. string_symofs: asizeint;
  1484. startlab: tasmlabel;
  1485. datadef: tdef;
  1486. datatcb: ttai_typedconstbuilder;
  1487. unicodestrrecdef: trecorddef;
  1488. begin
  1489. start_internal_data_builder(datalist,sec_rodata_norel,'',datatcb,startlab);
  1490. strlength:=getlengthwidestring(pcompilerwidestring(data));
  1491. if winlike then
  1492. begin
  1493. result.lab:=startlab;
  1494. datatcb.begin_anonymous_record('$'+get_dynstring_rec_name(st_widestring,true,strlength),
  1495. 4,4,
  1496. targetinfos[target_info.system]^.alignment.recordalignmin);
  1497. datatcb.emit_tai(Tai_const.Create_32bit(strlength*cwidechartype.size),s32inttype);
  1498. { can we optimise by placing the string constant label at the
  1499. required offset? }
  1500. string_symofs:=get_string_symofs(st_widestring,true);
  1501. if string_symofs=0 then
  1502. begin
  1503. { yes }
  1504. datatcb.emit_tai(Tai_label.Create(result.lab),widecharpointertype);
  1505. { allocate a separate label for the start of the data (see
  1506. emit_string_const_common() for explanation) }
  1507. startlab:=tasmlabel.create(current_asmdata.AsmSymbolDict,startlab.name+'$strlab',startlab.bind,startlab.typ);
  1508. end
  1509. else
  1510. internalerror(2015031502);
  1511. result.ofs:=string_symofs;
  1512. end
  1513. else
  1514. begin
  1515. result:=datatcb.emit_string_const_common(st_unicodestring,strlength,encoding,startlab);
  1516. end;
  1517. if cwidechartype.size = 2 then
  1518. begin
  1519. datadef:=carraydef.getreusable(cwidechartype,strlength+1);
  1520. datatcb.maybe_begin_aggregate(datadef);
  1521. for i:=0 to strlength-1 do
  1522. datatcb.emit_tai(Tai_const.Create_16bit(pcompilerwidestring(data)^.data[i]),cwidechartype);
  1523. { ending #0 }
  1524. datatcb.emit_tai(Tai_const.Create_16bit(0),cwidechartype);
  1525. datatcb.maybe_end_aggregate(datadef);
  1526. unicodestrrecdef:=datatcb.end_anonymous_record;
  1527. end
  1528. else
  1529. { code generation for other sizes must be written }
  1530. internalerror(200904271);
  1531. finish_internal_data_builder(datatcb,startlab,unicodestrrecdef,const_align(voidpointertype.alignment));
  1532. end;
  1533. procedure ttai_typedconstbuilder.emit_string_offset(const ll: tasmlabofs; const strlength: longint; const st: tstringtype; const winlikewidestring: boolean; const charptrdef: tdef);
  1534. begin
  1535. emit_tai(Tai_const.Create_sym_offset(ll.lab,ll.ofs),get_dynstring_def_for_type(st,winlikewidestring));
  1536. end;
  1537. procedure ttai_typedconstbuilder.emit_dynarray_offset(const ll:tasmlabofs;const arrlength:asizeint;const arrdef:tarraydef; const arrconstdatadef: trecorddef);
  1538. begin
  1539. emit_tai(tai_const.create_sym_offset(ll.lab,ll.ofs),arrdef);
  1540. end;
  1541. function ttai_typedconstbuilder.begin_dynarray_const(arrdef:tdef;var startlab:tasmlabel;out arrlengthloc:ttypedconstplaceholder):tasmlabofs;
  1542. var
  1543. dynarray_symofs: asizeint;
  1544. begin
  1545. result.lab:=startlab;
  1546. result.ofs:=0;
  1547. { pack the data, so that we don't add unnecessary null bytes after the
  1548. constant string }
  1549. begin_anonymous_record('',1,sizeof(TConstPtrUInt),1);
  1550. dynarray_symofs:=get_dynarray_symofs;
  1551. { what to do if ptrsinttype <> sizesinttype??? }
  1552. emit_tai(tai_const.create_sizeint(-1),ptrsinttype);
  1553. inc(result.ofs,ptrsinttype.size);
  1554. arrlengthloc:=emit_placeholder(sizesinttype);
  1555. inc(result.ofs,sizesinttype.size);
  1556. if dynarray_symofs=0 then
  1557. begin
  1558. { results in slightly more efficient code }
  1559. emit_tai(tai_label.create(result.lab),arrdef);
  1560. result.ofs:=0;
  1561. { create new label of the same kind (including whether or not the
  1562. name starts with target_asm.labelprefix in case it's AB_LOCAL,
  1563. so we keep the difference depending on whether the original was
  1564. allocated via getstatic/getlocal/getglobal datalabel) }
  1565. startlab:=tasmlabel.create(current_asmdata.AsmSymbolDict,startlab.name+'$dynarrlab',startlab.bind,startlab.typ);
  1566. end;
  1567. { sanity check }
  1568. if result.ofs<>dynarray_symofs then
  1569. internalerror(2018020601);
  1570. end;
  1571. function ttai_typedconstbuilder.end_dynarray_const(arrdef:tdef;arrlength:asizeint;arrlengthloc:ttypedconstplaceholder):tdef;
  1572. begin
  1573. { we emit the high value, not the count }
  1574. arrlengthloc.replace(tai_const.Create_sizeint(arrlength-1),sizesinttype);
  1575. result:=end_anonymous_record;
  1576. end;
  1577. function ttai_typedconstbuilder.emit_shortstring_const(const str: shortstring): tdef;
  1578. begin
  1579. { we use an arraydef instead of a shortstringdef, because we don't have
  1580. functionality in place yet to reuse shortstringdefs of the same length
  1581. and neither the lowlevel nor the llvm typedconst builder cares about
  1582. this difference }
  1583. result:=carraydef.getreusable(cansichartype,length(str)+1);
  1584. maybe_begin_aggregate(result);
  1585. emit_tai(Tai_const.Create_8bit(length(str)),u8inttype);
  1586. if str<>'' then
  1587. emit_tai(Tai_string.Create(str),carraydef.getreusable(cansichartype,length(str)));
  1588. maybe_end_aggregate(result);
  1589. end;
  1590. function ttai_typedconstbuilder.emit_pchar_const(str: pchar; len: pint; copypchar: boolean): tdef;
  1591. var
  1592. newstr: pchar;
  1593. begin
  1594. result:=carraydef.getreusable(cansichartype,len+1);
  1595. maybe_begin_aggregate(result);
  1596. if (len=0) and
  1597. (not assigned(str) or
  1598. copypchar) then
  1599. emit_tai(Tai_const.Create_8bit(0),cansichartype)
  1600. else
  1601. begin
  1602. if copypchar then
  1603. begin
  1604. getmem(newstr,len+1);
  1605. move(str^,newstr^,len+1);
  1606. str:=newstr;
  1607. end;
  1608. emit_tai(Tai_string.Create_pchar(str,len+1),result);
  1609. end;
  1610. maybe_end_aggregate(result);
  1611. end;
  1612. procedure ttai_typedconstbuilder.emit_guid_const(const guid: tguid);
  1613. var
  1614. i: longint;
  1615. field: tfieldvarsym;
  1616. begin
  1617. maybe_begin_aggregate(rec_tguid);
  1618. { variant record -> must specify which fields get initialised }
  1619. next_field:=tfieldvarsym(rec_tguid.symtable.Find('DATA1'));
  1620. emit_tai(Tai_const.Create_32bit(longint(guid.D1)),u32inttype);
  1621. next_field:=tfieldvarsym(rec_tguid.symtable.Find('DATA2'));
  1622. emit_tai(Tai_const.Create_16bit(guid.D2),u16inttype);
  1623. next_field:=tfieldvarsym(rec_tguid.symtable.Find('DATA3'));
  1624. emit_tai(Tai_const.Create_16bit(guid.D3),u16inttype);
  1625. field:=tfieldvarsym(rec_tguid.symtable.Find('DATA4'));
  1626. next_field:=field;
  1627. { the array }
  1628. maybe_begin_aggregate(field.vardef);
  1629. for i:=Low(guid.D4) to High(guid.D4) do
  1630. emit_tai(Tai_const.Create_8bit(guid.D4[i]),u8inttype);
  1631. maybe_end_aggregate(field.vardef);
  1632. maybe_end_aggregate(rec_tguid);
  1633. end;
  1634. procedure ttai_typedconstbuilder.emit_procdef_const(pd: tprocdef);
  1635. begin
  1636. emit_tai(Tai_const.Createname(pd.mangledname,AT_FUNCTION,0),cprocvardef.getreusableprocaddr(pd));
  1637. end;
  1638. procedure ttai_typedconstbuilder.emit_ord_const(value: int64; def: tdef);
  1639. begin
  1640. case def.size of
  1641. 1:
  1642. emit_tai(Tai_const.Create_8bit(byte(value)),def);
  1643. 2:
  1644. emit_tai(Tai_const.Create_16bit(word(value)),def);
  1645. 4:
  1646. emit_tai(Tai_const.Create_32bit(longint(value)),def);
  1647. 8:
  1648. emit_tai(Tai_const.Create_64bit(value),def);
  1649. else
  1650. internalerror(2014100501);
  1651. end;
  1652. end;
  1653. procedure ttai_typedconstbuilder.emit_pooled_shortstring_const_ref(const str:shortstring);
  1654. var
  1655. pool : thashset;
  1656. entry : phashsetitem;
  1657. strlab : tasmlabel;
  1658. l : longint;
  1659. pc : pansichar;
  1660. datadef : tdef;
  1661. strtcb : ttai_typedconstbuilder;
  1662. begin
  1663. pool:=current_asmdata.ConstPools[sp_shortstr];
  1664. entry:=pool.FindOrAdd(@str[1],length(str));
  1665. { :-(, we must generate a new entry }
  1666. if not assigned(entry^.Data) then
  1667. begin
  1668. current_asmdata.getglobaldatalabel(strlab);
  1669. { include length and terminating zero for quick conversion to pchar }
  1670. l:=length(str);
  1671. getmem(pc,l+2);
  1672. move(str[1],pc[1],l);
  1673. pc[0]:=chr(l);
  1674. pc[l+1]:=#0;
  1675. datadef:=carraydef.getreusable(cansichartype,l+2);
  1676. { we start a new constbuilder as we don't know whether we're called
  1677. from inside an internal constbuilder }
  1678. strtcb:=ctai_typedconstbuilder.create([tcalo_is_lab,tcalo_make_dead_strippable,tcalo_apply_constalign]);
  1679. strtcb.maybe_begin_aggregate(datadef);
  1680. strtcb.emit_tai(Tai_string.Create_pchar(pc,l+2),datadef);
  1681. strtcb.maybe_end_aggregate(datadef);
  1682. current_asmdata.asmlists[al_typedconsts].concatList(
  1683. strtcb.get_final_asmlist(strlab,datadef,sec_rodata_norel,strlab.name,const_align(sizeof(pint)))
  1684. );
  1685. strtcb.free;
  1686. entry^.Data:=strlab;
  1687. end
  1688. else
  1689. strlab:=tasmlabel(entry^.Data);
  1690. emit_tai(tai_const.Create_sym(strlab),charpointertype);
  1691. end;
  1692. procedure ttai_typedconstbuilder.maybe_begin_aggregate(def: tdef);
  1693. begin
  1694. begin_aggregate_internal(def,false);
  1695. end;
  1696. procedure ttai_typedconstbuilder.maybe_end_aggregate(def: tdef);
  1697. begin
  1698. end_aggregate_internal(def,false);
  1699. end;
  1700. function ttai_typedconstbuilder.begin_anonymous_record(const optionalname: string; packrecords, recordalign, recordalignmin: shortint): trecorddef;
  1701. var
  1702. anonrecorddef: trecorddef;
  1703. typesym: ttypesym;
  1704. begin
  1705. { if the name is specified, we create a typesym with that name in order
  1706. to ensure we can find it again later with that name -> reuse here as
  1707. well if possible (and that also avoids duplicate type name issues) }
  1708. if optionalname<>'' then
  1709. begin
  1710. typesym:=try_search_current_module_type(optionalname);
  1711. if assigned(typesym) then
  1712. begin
  1713. if typesym.typedef.typ<>recorddef then
  1714. internalerror(2015071401);
  1715. result:=trecorddef(typesym.typedef);
  1716. maybe_begin_aggregate(result);
  1717. exit;
  1718. end;
  1719. end;
  1720. { create skeleton def }
  1721. anonrecorddef:=crecorddef.create_global_internal(optionalname,packrecords,recordalignmin);
  1722. trecordsymtable(anonrecorddef.symtable).recordalignment:=recordalign;
  1723. { generic aggregate housekeeping }
  1724. begin_aggregate_internal(anonrecorddef,true);
  1725. { mark as anonymous record }
  1726. curagginfo.anonrecord:=true;
  1727. { in case a descendent wants to do something with the anonrecorddef too }
  1728. result:=anonrecorddef;
  1729. end;
  1730. function ttai_typedconstbuilder.end_anonymous_record: trecorddef;
  1731. var
  1732. info: taggregateinformation;
  1733. anonrecord: boolean;
  1734. begin
  1735. info:=curagginfo;
  1736. if not assigned(info) or
  1737. (info.def.typ<>recorddef) then
  1738. internalerror(2014080201);
  1739. result:=trecorddef(info.def);
  1740. { make a copy, as we need it after info has been freed by
  1741. maybe_end_aggregate(result) }
  1742. anonrecord:=info.anonrecord;
  1743. { finalise the record skeleton (all fields have been added already by
  1744. emit_tai()) -- anonrecord may not be set in case we reused an earlier
  1745. constructed def }
  1746. if anonrecord then
  1747. trecordsymtable(result.symtable).addalignmentpadding;
  1748. end_aggregate_internal(result,true);
  1749. if anonrecord and
  1750. assigned(curagginfo) and
  1751. (curagginfo.def.typ=recorddef) then
  1752. insert_marked_aggregate_alignment(result);
  1753. end;
  1754. procedure ttai_typedconstbuilder.check_add_placeholder(def: tdef);
  1755. begin
  1756. { it only makes sense to add a placeholder inside an aggregate
  1757. (otherwise there can be but one element)
  1758. we cannot add a placeholder in the middle of a queued expression
  1759. either
  1760. the placeholder cannot be an aggregate }
  1761. if not assigned(curagginfo) or
  1762. queue_is_active or
  1763. (aggregate_kind(def)<>tck_simple) then
  1764. internalerror(2015091001);
  1765. end;
  1766. procedure ttai_typedconstbuilder.queue_init(todef: tdef);
  1767. var
  1768. info: taggregateinformation;
  1769. begin
  1770. { nested call to init? }
  1771. if fqueue_offset<>low(fqueue_offset) then
  1772. internalerror(2014062101);
  1773. { insert padding bytes before starting the queue, so that the first
  1774. padding byte won't be interpreted as the emitted value for this queue }
  1775. info:=curagginfo;
  1776. if assigned(info) then
  1777. begin
  1778. if ((info.def.typ=recorddef) or
  1779. is_object(info.def)) and
  1780. { may add support for these later }
  1781. not is_packed_record_or_object(info.def) then
  1782. pad_next_field(todef);
  1783. end;
  1784. fqueue_offset:=0;
  1785. fqueued_def:=todef;
  1786. end;
  1787. procedure ttai_typedconstbuilder.queue_vecn(def: tdef; const index: tconstexprint);
  1788. var
  1789. elelen,
  1790. vecbase: asizeint;
  1791. v: tconstexprint;
  1792. begin
  1793. elelen:=1;
  1794. vecbase:=0;
  1795. case def.typ of
  1796. stringdef :
  1797. ;
  1798. arraydef :
  1799. begin
  1800. if not is_packed_array(def) then
  1801. begin
  1802. elelen:=tarraydef(def).elesize;
  1803. vecbase:=tarraydef(def).lowrange;
  1804. end
  1805. else
  1806. Message(parser_e_packed_dynamic_open_array);
  1807. end;
  1808. else
  1809. Message(parser_e_illegal_expression);
  1810. end;
  1811. { Prevent overflow }
  1812. v:=index-vecbase;
  1813. if (v<int64(low(fqueue_offset))) or (v>int64(high(fqueue_offset))) then
  1814. message3(type_e_range_check_error_bounds,tostr(v),tostr(low(fqueue_offset)),tostr(high(fqueue_offset)));
  1815. if high(fqueue_offset)-fqueue_offset div elelen>v then
  1816. inc(fqueue_offset,elelen*v.svalue)
  1817. else
  1818. message3(type_e_range_check_error_bounds,tostr(index),tostr(vecbase),tostr(high(fqueue_offset)-fqueue_offset div elelen+vecbase))
  1819. end;
  1820. procedure ttai_typedconstbuilder.queue_subscriptn(def: tabstractrecorddef; vs: tfieldvarsym);
  1821. begin
  1822. inc(fqueue_offset,vs.fieldoffset);
  1823. end;
  1824. function ttai_typedconstbuilder.queue_subscriptn_multiple_by_name(def: tabstractrecorddef; const fields: array of TIDString): tdef;
  1825. var
  1826. syms,
  1827. parentdefs: tfplist;
  1828. sym: tsym;
  1829. curdef: tdef;
  1830. i: longint;
  1831. begin
  1832. result:=nil;
  1833. if length(fields)=0 then
  1834. internalerror(2015071601);
  1835. syms:=tfplist.Create;
  1836. syms.count:=length(fields);
  1837. parentdefs:=tfplist.create;
  1838. parentdefs.Count:=length(fields);
  1839. curdef:=def;
  1840. for i:=low(fields) to high(fields) do
  1841. begin
  1842. sym:=search_struct_member_no_helper(tabstractrecorddef(curdef),fields[i]);
  1843. if not assigned(sym) or
  1844. not is_normal_fieldvarsym(sym) or
  1845. ((i<>high(fields)) and
  1846. not(tfieldvarsym(sym).vardef.typ in [objectdef,recorddef])) then
  1847. internalerror(2015071505);
  1848. syms[i]:=sym;
  1849. parentdefs[i]:=curdef;
  1850. curdef:=tfieldvarsym(sym).vardef;
  1851. result:=curdef;
  1852. end;
  1853. for i:=high(fields) downto low(fields) do
  1854. queue_subscriptn(tabstractrecorddef(parentdefs[i]),tfieldvarsym(syms[i]));
  1855. syms.free;
  1856. parentdefs.free;
  1857. end;
  1858. procedure ttai_typedconstbuilder.queue_typeconvn(fromdef, todef: tdef);
  1859. begin
  1860. { do nothing }
  1861. end;
  1862. procedure ttai_typedconstbuilder.queue_emit_proc(pd: tprocdef);
  1863. begin
  1864. if fqueue_offset<>0 then
  1865. internalerror(2014092101);
  1866. emit_procdef_const(pd);
  1867. fqueue_offset:=low(fqueue_offset);
  1868. end;
  1869. procedure ttai_typedconstbuilder.queue_emit_staticvar(vs: tstaticvarsym);
  1870. begin
  1871. { pointerdef because we are emitting a pointer to the staticvarsym
  1872. data, not the data itself }
  1873. emit_tai(Tai_const.Createname(vs.mangledname,AT_DATA,fqueue_offset),cpointerdef.getreusable(vs.vardef));
  1874. fqueue_offset:=low(fqueue_offset);
  1875. end;
  1876. procedure ttai_typedconstbuilder.queue_emit_label(l: tlabelsym);
  1877. begin
  1878. emit_tai(Tai_const.Createname(l.mangledname,fqueue_offset),voidcodepointertype);
  1879. fqueue_offset:=low(fqueue_offset);
  1880. end;
  1881. procedure ttai_typedconstbuilder.queue_emit_const(cs: tconstsym);
  1882. var
  1883. resourcestrrec: trecorddef;
  1884. begin
  1885. if cs.consttyp<>constresourcestring then
  1886. internalerror(2014062102);
  1887. if fqueue_offset<>0 then
  1888. internalerror(2014062103);
  1889. { warning: update if/when the type of resource strings changes }
  1890. case cs.consttyp of
  1891. constresourcestring:
  1892. begin
  1893. resourcestrrec:=trecorddef(search_system_type('TRESOURCESTRINGRECORD').typedef);
  1894. queue_subscriptn_multiple_by_name(resourcestrrec,['CURRENTVALUE']);
  1895. queue_emit_asmsym(current_asmdata.RefAsmSymbol(
  1896. make_mangledname('RESSTR',cs.owner,cs.name),AT_DATA),resourcestrrec
  1897. );
  1898. end;
  1899. { can these occur? }
  1900. constord,
  1901. conststring,constreal,
  1902. constset,constpointer,constnil,
  1903. constwstring,constguid:
  1904. internalerror(2015090903);
  1905. else
  1906. internalerror(2015090904);
  1907. end;
  1908. fqueue_offset:=low(fqueue_offset);
  1909. end;
  1910. procedure ttai_typedconstbuilder.queue_emit_asmsym(sym: tasmsymbol; def: tdef);
  1911. begin
  1912. { pointerdef, because "sym" represents the address of whatever the
  1913. data is }
  1914. def:=cpointerdef.getreusable(def);
  1915. emit_tai(Tai_const.Create_sym_offset(sym,fqueue_offset),def);
  1916. fqueue_offset:=low(fqueue_offset);
  1917. end;
  1918. procedure ttai_typedconstbuilder.queue_emit_ordconst(value: int64; def: tdef);
  1919. begin
  1920. emit_ord_const(value,def);
  1921. fqueue_offset:=low(fqueue_offset);
  1922. end;
  1923. function ttai_typedconstbuilder.queue_is_active: boolean;
  1924. begin
  1925. result:=fqueue_offset<>low(fqueue_offset)
  1926. end;
  1927. {****************************************************************************
  1928. tlowleveltypedconstplaceholder
  1929. ****************************************************************************}
  1930. constructor tlowleveltypedconstplaceholder.create(l: tasmlist; pos: tai; d: tdef);
  1931. begin
  1932. inherited create(d);
  1933. list:=l;
  1934. insertpos:=pos;
  1935. end;
  1936. procedure tlowleveltypedconstplaceholder.replace(ai: tai; d: tdef);
  1937. begin
  1938. if d<>def then
  1939. internalerror(2015091007);
  1940. list.insertafter(ai,insertpos);
  1941. list.remove(insertpos);
  1942. insertpos.free;
  1943. end;
  1944. {****************************************************************************
  1945. tai_abstracttypedconst
  1946. ****************************************************************************}
  1947. class constructor ttai_lowleveltypedconstbuilder.classcreate;
  1948. begin
  1949. caggregateinformation:=tlowlevelaggregateinformation;
  1950. end;
  1951. function ttai_lowleveltypedconstbuilder.emit_placeholder(def: tdef): ttypedconstplaceholder;
  1952. var
  1953. p: tai;
  1954. begin
  1955. check_add_placeholder(def);
  1956. p:=tai_marker.Create(mark_position);
  1957. emit_tai(p,def);
  1958. result:=tlowleveltypedconstplaceholder.create(fasmlist,p,def);
  1959. end;
  1960. procedure ttai_lowleveltypedconstbuilder.mark_anon_aggregate_alignment;
  1961. var
  1962. marker: tai_marker;
  1963. begin
  1964. marker:=tai_marker.Create(mark_position);
  1965. fasmlist.concat(marker);
  1966. tlowlevelaggregateinformation(curagginfo).anonrecmarker:=marker;
  1967. end;
  1968. procedure ttai_lowleveltypedconstbuilder.insert_marked_aggregate_alignment(def: tdef);
  1969. var
  1970. info: tlowlevelaggregateinformation;
  1971. fillbytes: asizeint;
  1972. begin
  1973. info:=tlowlevelaggregateinformation(curagginfo);
  1974. if not assigned(info.anonrecmarker) then
  1975. internalerror(2014091401);
  1976. fillbytes:=info.prepare_next_field(def);
  1977. while fillbytes>0 do
  1978. begin
  1979. fasmlist.insertafter(tai_const.create_8bit(0),info.anonrecmarker);
  1980. dec(fillbytes);
  1981. end;
  1982. fasmlist.remove(info.anonrecmarker);
  1983. info.anonrecmarker.free;
  1984. info.anonrecmarker:=nil;
  1985. end;
  1986. procedure ttai_lowleveltypedconstbuilder.finalize_asmlist(sym: tasmsymbol; def: tdef; section: TAsmSectiontype; const secname: TSymStr; alignment: shortint; const options: ttcasmlistoptions);
  1987. begin
  1988. inherited;
  1989. { The darwin/ppc64 assembler or linker seems to have trouble }
  1990. { if a section ends with a global label without any data after it. }
  1991. { So for safety, just put a dummy value here. }
  1992. { Further, the regular linker also kills this symbol when turning }
  1993. { on smart linking in case no value appears after it, so put the }
  1994. { dummy byte there always }
  1995. { Update: the Mac OS X 10.6 linker orders data that needs to be }
  1996. { relocated before all other data, so make this data relocatable, }
  1997. { otherwise the end label won't be moved with the rest }
  1998. if (tcalo_vectorized_dead_strip_end in options) and
  1999. (target_info.system in (systems_darwin+systems_aix)) then
  2000. fasmlist.concat(Tai_const.create_sym(sym));
  2001. end;
  2002. begin
  2003. ctai_typedconstbuilder:=ttai_lowleveltypedconstbuilder;
  2004. end.