aasmtai.pas 105 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571
  1. {
  2. Copyright (c) 1998-2006 by Florian Klaempfl
  3. This unit implements an abstract asmoutput class for all processor types
  4. This program is free software; you can redistribute it and/or modify
  5. it under the terms of the GNU General Public License as published by
  6. the Free Software Foundation; either version 2 of the License, or
  7. (at your option) any later version.
  8. This program is distributed in the hope that it will be useful,
  9. but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. GNU General Public License for more details.
  12. You should have received a copy of the GNU General Public License
  13. along with this program; if not, write to the Free Software
  14. Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  15. ****************************************************************************
  16. }
  17. { @abstract(This unit implements an abstract asm output class for all processor types)
  18. This unit implements an abstract assembler output class for all processors, these
  19. are then overridden for each assembler writer to actually write the data in these
  20. classes to an assembler file.
  21. }
  22. unit aasmtai;
  23. {$i fpcdefs.inc}
  24. interface
  25. uses
  26. cutils,cclasses,
  27. globtype,systems,
  28. cpuinfo,cpubase,
  29. {$ifdef llvm}
  30. { overrides max_operands }
  31. llvmbase,
  32. {$endif llvm}
  33. cgbase,cgutils,
  34. symtype,
  35. aasmbase,aasmdata,ogbase
  36. {$ifdef jvm}
  37. ,widestr
  38. {$endif jvm}
  39. ;
  40. type
  41. { keep the number of elements in this enumeration less or equal than 32 as long
  42. as FPC knows only 4 byte and 32 byte sets (FK) }
  43. taitype = (
  44. ait_none,
  45. ait_align,
  46. ait_section,
  47. ait_comment,
  48. ait_string,
  49. ait_instruction,
  50. ait_datablock,
  51. ait_symbol,
  52. { needed to calc the size of a symbol }
  53. ait_symbol_end,
  54. ait_directive,
  55. ait_label,
  56. ait_const,
  57. ait_realconst,
  58. ait_typedconst,
  59. ait_stab,
  60. ait_force_line,
  61. ait_function_name,
  62. ait_symbolpair,
  63. { used to split into tiny assembler files }
  64. ait_cutobject,
  65. ait_regalloc,
  66. ait_tempalloc,
  67. { used to mark assembler blocks and inlined functions }
  68. ait_marker,
  69. { used to describe a new location of a variable }
  70. ait_varloc,
  71. {$ifdef JVM}
  72. { JVM only }
  73. ait_jvar, { debug information for a local variable }
  74. ait_jcatch, { exception catch clause }
  75. {$endif JVM}
  76. {$ifdef llvm}
  77. ait_llvmins, { llvm instruction }
  78. ait_llvmalias, { alias for a symbol }
  79. ait_llvmdecl, { llvm symbol declaration (global/external variable, external procdef) }
  80. ait_llvmmetadatanode, (* llvm metadata node: !id = !{type value, ...} *)
  81. ait_llvmmetadatareftypedconst, { reference to metadata inside a metadata constant }
  82. ait_llvmmetadatarefoperand, { llvm metadata referece: !metadataname !id }
  83. {$endif}
  84. { SEH directives used in ARM,MIPS and x86_64 COFF targets }
  85. ait_seh_directive,
  86. { Dwarf CFI directive }
  87. ait_cfi,
  88. ait_eabi_attribute
  89. );
  90. taiconst_type = (
  91. aitconst_128bit,
  92. aitconst_64bit,
  93. aitconst_32bit,
  94. aitconst_16bit,
  95. aitconst_8bit,
  96. aitconst_sleb128bit,
  97. aitconst_uleb128bit,
  98. { win32 only }
  99. aitconst_rva_symbol,
  100. aitconst_secrel32_symbol,
  101. { darwin only }
  102. { From gcc/config/darwin.c (darwin_asm_output_dwarf_delta):
  103. ***
  104. Output a difference of two labels that will be an assembly time
  105. constant if the two labels are local. (.long lab1-lab2 will be
  106. very different if lab1 is at the boundary between two sections; it
  107. will be relocated according to the second section, not the first,
  108. so one ends up with a difference between labels in different
  109. sections, which is bad in the dwarf2 eh context for instance.)
  110. ***
  111. We cannot use this everywhere, because older versions of the
  112. darwin assembler don't support the construct used for these
  113. relsyms (nor do they support dwarf, for that matter)
  114. }
  115. aitconst_darwin_dwarf_delta64,
  116. aitconst_darwin_dwarf_delta32,
  117. { ARM Thumb-2 only }
  118. aitconst_half16bit, { used for table jumps. The actual value is the 16bit value shifted left once }
  119. { AVR }
  120. aitconst_gs, { Upper 16-bit of 17-bit constant }
  121. { for use by dwarf debugger information }
  122. aitconst_16bit_unaligned,
  123. aitconst_32bit_unaligned,
  124. aitconst_64bit_unaligned,
  125. { i8086 far pointer; emits: 'DW symbol, SEG symbol' }
  126. aitconst_farptr,
  127. { i8086 segment of symbol; emits: 'DW SEG symbol' }
  128. aitconst_seg,
  129. { i8086 data segment group; emits: 'DW dgroup'
  130. generated by the this inline asm:
  131. DW SEG @DATA
  132. in all memory models, except huge }
  133. aitconst_dgroup,
  134. { i8086 far data segment of the current pascal module (unit or program);
  135. emits: 'DW CURRENTMODULENAME_DATA'
  136. generated by the this inline asm:
  137. DW SEG @DATA
  138. in the huge memory model }
  139. aitconst_fardataseg,
  140. { offset of symbol's GOT slot in GOT }
  141. aitconst_got,
  142. { offset of symbol itself from GOT }
  143. aitconst_gotoff_symbol,
  144. { offset in TLS block }
  145. aitconst_dtpoff,
  146. { ARM TLS code }
  147. aitconst_gottpoff,
  148. aitconst_tpoff,
  149. aitconst_tlsgd,
  150. aitconst_tlsdesc
  151. );
  152. tairealconsttype = (
  153. aitrealconst_s32bit,
  154. aitrealconst_s64bit,
  155. aitrealconst_s80bit,
  156. aitrealconst_s128bit,
  157. aitrealconst_s64comp
  158. );
  159. const
  160. {$if defined(cpu64bitaddr)}
  161. aitconst_ptr = aitconst_64bit;
  162. aitconst_ptr_unaligned = aitconst_64bit_unaligned;
  163. aitconst_sizeint = aitconst_64bit;
  164. aitconst_sizeint_unaligned = aitconst_64bit_unaligned;
  165. {$elseif defined(cpu32bitaddr)}
  166. aitconst_ptr = aitconst_32bit;
  167. aitconst_ptr_unaligned = aitconst_32bit_unaligned;
  168. aitconst_sizeint = aitconst_32bit;
  169. aitconst_sizeint_unaligned = aitconst_32bit_unaligned;
  170. {$elseif defined(cpu16bitaddr)}
  171. aitconst_ptr = aitconst_16bit;
  172. aitconst_ptr_unaligned = aitconst_16bit_unaligned;
  173. aitconst_sizeint = aitconst_16bit;
  174. aitconst_sizeint_unaligned = aitconst_16bit_unaligned;
  175. {$endif}
  176. {$if defined(cpu64bitalu)}
  177. aitconst_aint = aitconst_64bit;
  178. {$elseif defined(cpu32bitalu)}
  179. aitconst_aint = aitconst_32bit;
  180. {$elseif defined(cpu16bitalu)}
  181. aitconst_aint = aitconst_16bit;
  182. {$elseif defined(cpu8bitalu)}
  183. aitconst_aint = aitconst_8bit;
  184. {$endif}
  185. taitypestr : array[taitype] of string[24] = (
  186. '<none>',
  187. 'align',
  188. 'section',
  189. 'comment',
  190. 'string',
  191. 'instruction',
  192. 'datablock',
  193. 'symbol',
  194. 'symbol_end',
  195. 'symbol_directive',
  196. 'label',
  197. 'const',
  198. 'realconst',
  199. 'typedconst',
  200. 'stab',
  201. 'force_line',
  202. 'function_name',
  203. 'symbolpair',
  204. 'cut',
  205. 'regalloc',
  206. 'tempalloc',
  207. 'marker',
  208. 'varloc',
  209. {$ifdef JVM}
  210. 'jvar',
  211. 'jcatch',
  212. {$endif JVM}
  213. {$ifdef llvm}
  214. 'llvmins',
  215. 'llvmalias',
  216. 'llvmdecl',
  217. 'llvmmetadata',
  218. 'llvmmetadatareftc',
  219. 'llvmmetadatarefop',
  220. {$endif}
  221. 'cfi',
  222. 'seh_directive',
  223. 'eabi_attribute'
  224. );
  225. type
  226. { Types of operand }
  227. toptype=(top_none,top_reg,top_ref,top_const,top_bool,top_local
  228. {$ifdef arm}
  229. { ARM only }
  230. ,top_regset
  231. ,top_modeflags
  232. ,top_specialreg
  233. {$endif arm}
  234. {$if defined(arm) or defined(aarch64)}
  235. ,top_conditioncode
  236. ,top_shifterop
  237. ,top_realconst
  238. {$endif defined(arm) or defined(aarch64)}
  239. {$ifdef m68k}
  240. { m68k only }
  241. ,top_regset
  242. ,top_regpair
  243. ,top_realconst
  244. {$endif m68k}
  245. {$ifdef jvm}
  246. { jvm only}
  247. ,top_single
  248. ,top_double
  249. ,top_string
  250. ,top_wstring
  251. {$endif jvm}
  252. {$ifdef llvm}
  253. { llvm only }
  254. ,top_single
  255. ,top_double
  256. ,top_undef
  257. {$ifdef cpuextended}
  258. ,top_extended80
  259. {$endif cpuextended}
  260. ,top_tai
  261. ,top_def
  262. ,top_fpcond
  263. ,top_cond
  264. ,top_para
  265. ,top_asmlist
  266. ,top_callingconvention
  267. {$endif llvm}
  268. {$if defined(riscv32) or defined(riscv64)}
  269. ,top_fenceflags
  270. ,top_roundingmode
  271. {$endif defined(riscv32) or defined(riscv64)}
  272. );
  273. { kinds of operations that an instruction can perform on an operand }
  274. topertype = (operand_read,operand_write,operand_readwrite);
  275. tlocaloper = record
  276. localsym : pointer;
  277. localsymderef : tderef;
  278. localsymofs : longint;
  279. {$ifdef x86}
  280. localsegment,
  281. {$endif x86}
  282. localindexreg : tregister;
  283. localscale : byte;
  284. localgetoffset,
  285. localforceref : boolean
  286. end;
  287. plocaloper = ^tlocaloper;
  288. const
  289. { ait_* types which don't result in executable code or which don't influence
  290. the way the program runs/behaves, but which may be encountered by the
  291. optimizer (= if it's sometimes added to the exprasm list). Update if you add
  292. a new ait type! }
  293. SkipInstr = [ait_comment, ait_symbol,ait_section
  294. ,ait_stab, ait_function_name, ait_force_line
  295. ,ait_regalloc, ait_tempalloc, ait_symbol_end
  296. ,ait_directive
  297. ,ait_varloc,
  298. {$ifdef JVM}
  299. ait_jvar,
  300. {$endif JVM}
  301. ait_seh_directive];
  302. { ait_* types which do not have line information (and hence which are of type
  303. tai, otherwise, they are of type tailineinfo }
  304. SkipLineInfo =[ait_label,
  305. ait_regalloc,ait_tempalloc,
  306. ait_stab,ait_function_name,
  307. ait_cutobject,ait_marker,ait_varloc,ait_align,ait_section,ait_comment,
  308. ait_const,ait_directive,
  309. ait_symbolpair,
  310. ait_realconst,
  311. ait_symbol,
  312. {$ifdef JVM}
  313. ait_jvar, ait_jcatch,
  314. {$endif JVM}
  315. {$ifdef llvm}
  316. ait_llvmdecl,
  317. ait_llvmmetadatanode,
  318. ait_llvmmetadatareftypedconst,
  319. ait_llvmmetadatarefoperand,
  320. {$endif llvm}
  321. ait_seh_directive,
  322. ait_cfi,
  323. ait_eabi_attribute
  324. ];
  325. type
  326. { cut type, required for alphanumeric ordering of the assembler filenames }
  327. TCutPlace=(cut_normal,cut_begin,cut_end);
  328. TAsmMarker = (
  329. mark_NoPropInfoStart,mark_NoPropInfoEnd,
  330. mark_AsmBlockStart,mark_AsmBlockEnd,
  331. mark_NoLineInfoStart,mark_NoLineInfoEnd,mark_BlockStart,
  332. mark_Position
  333. );
  334. TRegAllocType = (ra_alloc,ra_dealloc,ra_sync,ra_resize,ra_markused);
  335. TStabType = (stab_stabs,stab_stabn,stab_stabd,
  336. { AIX/XCOFF stab types }
  337. stab_stabx,
  338. { begin/end include file }
  339. stabx_bi,stabx_ei,
  340. { begin/end function }
  341. stabx_bf, stabx_ef,
  342. { begin/end static data block }
  343. stabx_bs, stabx_es,
  344. { line spec, function start/end label }
  345. stabx_line, stabx_function);
  346. TAsmDirective=(
  347. asd_indirect_symbol,
  348. asd_extern,asd_nasm_import, asd_toc_entry,
  349. asd_reference,asd_no_dead_strip,asd_weak_reference,asd_lazy_reference,
  350. asd_weak_definition,
  351. { for Jasmin }
  352. asd_jclass,asd_jinterface,asd_jsuper,asd_jfield,asd_jlimit,asd_jline,
  353. { .ent/.end for MIPS }
  354. asd_ent,asd_ent_end,
  355. { supported by recent clang-based assemblers for data-in-code }
  356. asd_data_region, asd_end_data_region,
  357. { ARM }
  358. asd_thumb_func,asd_code,
  359. { restricts the assembler only to those instructions, which are
  360. available on the specified CPU; this represents directives such as
  361. NASM's 'CPU 686' or MASM/TASM's '.686p'. Might not be supported by
  362. all assemblers. }
  363. asd_cpu,
  364. { for the OMF object format }
  365. asd_omf_linnum_line,
  366. { RISC-V }
  367. asd_option
  368. );
  369. TAsmSehDirective=(
  370. ash_proc,ash_endproc,
  371. ash_endprologue,ash_handler,ash_handlerdata,
  372. ash_eh,ash_32,ash_no32,
  373. ash_setframe,ash_stackalloc,ash_pushreg,
  374. ash_savereg,ash_savexmm,ash_pushframe,
  375. ash_pushnv,ash_savenv
  376. );
  377. TSymbolPairKind = (spk_set, spk_set_global, spk_thumb_set, spk_localentry);
  378. const
  379. regallocstr : array[tregalloctype] of string[10]=('allocated','released','sync','resized','used');
  380. tempallocstr : array[boolean] of string[10]=('released','allocated');
  381. stabtypestr : array[TStabType] of string[8]=(
  382. 'stabs','stabn','stabd',
  383. 'stabx',
  384. 'bi','ei',
  385. 'bf','ef',
  386. 'bs','es',
  387. 'line','function');
  388. directivestr : array[TAsmDirective] of string[23]=(
  389. 'indirect_symbol',
  390. 'extern','nasm_import', 'tc', 'reference',
  391. 'no_dead_strip','weak','lazy_reference','weak',
  392. { for Jasmin }
  393. 'class','interface','super','field','limit','line',
  394. { .ent/.end for MIPS }
  395. 'ent','end',
  396. { supported by recent clang-based assemblers for data-in-code }
  397. 'data_region','end_data_region',
  398. { ARM }
  399. 'thumb_func',
  400. 'code',
  401. 'cpu',
  402. { for the OMF object format }
  403. 'omf_line',
  404. { RISC-V }
  405. 'option'
  406. );
  407. sehdirectivestr : array[TAsmSehDirective] of string[16]=(
  408. '.seh_proc','.seh_endproc',
  409. '.seh_endprologue','.seh_handler','.seh_handlerdata',
  410. '.seh_eh','.seh_32','seh_no32',
  411. '.seh_setframe','.seh_stackalloc','.seh_pushreg',
  412. '.seh_savereg','.seh_savexmm','.seh_pushframe',
  413. '.pushnv','.savenv'
  414. );
  415. symbolpairkindstr: array[TSymbolPairKind] of string[11]=(
  416. '.set', '.set', '.thumb_set', '.localentry'
  417. );
  418. type
  419. tai = class;
  420. { please keep the size of this record <=12 bytes and keep it properly aligned }
  421. toper = record
  422. ot : longint;
  423. {$ifdef x86}
  424. vopext: smallint;
  425. {$ENDIF}
  426. case typ : toptype of
  427. top_none : ();
  428. top_reg : (reg:tregister);
  429. top_ref : (ref:preference);
  430. top_const : (val:tcgint);
  431. top_bool : (b:boolean);
  432. { local varsym that will be inserted in pass_generate_code }
  433. top_local : (localoper:plocaloper);
  434. {$ifdef arm}
  435. top_regset : (regset:^tcpuregisterset; regtyp: tregistertype; subreg: tsubregister; usermode: boolean);
  436. top_modeflags : (modeflags : tcpumodeflags);
  437. top_specialreg : (specialreg:tregister; specialflags:tspecialregflags);
  438. {$endif arm}
  439. {$if defined(arm) or defined(aarch64)}
  440. top_shifterop : (shifterop : pshifterop);
  441. top_conditioncode : (cc : TAsmCond);
  442. top_realconst : (val_real:bestreal);
  443. {$endif defined(arm) or defined(aarch64)}
  444. {$ifdef m68k}
  445. top_regset : (dataregset,addrregset,fpuregset: tcpuregisterset);
  446. top_regpair : (reghi,reglo: tregister);
  447. top_realconst : (val_real:bestreal);
  448. {$endif m68k}
  449. {$ifdef jvm}
  450. top_single : (sval:single);
  451. top_double : (dval:double);
  452. top_string : (pcvallen: aint; pcval: pchar);
  453. top_wstring : (pwstrval: pcompilerwidestring);
  454. {$endif jvm}
  455. {$ifdef llvm}
  456. top_single : (sval:single);
  457. top_double : (dval:double);
  458. top_undef : ();
  459. {$ifdef cpuextended}
  460. top_extended80 : (eval:extended);
  461. {$endif cpuextended}
  462. top_tai : (ai: tai);
  463. top_def : (def: tdef);
  464. top_cond : (cond: topcmp);
  465. top_fpcond : (fpcond: tllvmfpcmp);
  466. top_para : (paras: tfplist);
  467. top_asmlist : (asmlist: tasmlist);
  468. top_callingconvention: (callingconvention: tproccalloption);
  469. {$endif llvm}
  470. {$if defined(riscv32) or defined(riscv64)}
  471. top_fenceflags : (fenceflags : TFenceFlags);
  472. top_roundingmode : (roundingmode : TRoundingMode);
  473. {$endif defined(riscv32) or defined(riscv64)}
  474. end;
  475. poper=^toper;
  476. { abstract assembler item }
  477. tai = class(TLinkedListItem)
  478. {$ifndef NOOPT}
  479. { pointer to record with optimizer info about this tai object }
  480. optinfo : pointer;
  481. {$endif NOOPT}
  482. typ : taitype;
  483. constructor Create;
  484. constructor ppuload(t:taitype;ppufile:tcompilerppufile);virtual;
  485. procedure ppuwrite(ppufile:tcompilerppufile);virtual;
  486. procedure buildderefimpl;virtual;
  487. procedure derefimpl;virtual;
  488. end;
  489. { abstract assembler item with line information }
  490. tailineinfo = class(tai)
  491. fileinfo : tfileposinfo;
  492. constructor Create;
  493. constructor ppuload(t:taitype;ppufile:tcompilerppufile);override;
  494. procedure ppuwrite(ppufile:tcompilerppufile);override;
  495. end;
  496. tai_simple = class(tai)
  497. constructor create(_typ : taitype);
  498. end;
  499. taiclass = class of tai;
  500. taiclassarray = array[taitype] of taiclass;
  501. { Generates an assembler string }
  502. tai_string = class(tailineinfo)
  503. str : pchar;
  504. { extra len so the string can contain an \0 }
  505. len : longint;
  506. constructor Create(const _str : string);
  507. constructor Create_pchar(_str : pchar;length : longint);
  508. destructor Destroy;override;
  509. constructor ppuload(t:taitype;ppufile:tcompilerppufile);override;
  510. procedure ppuwrite(ppufile:tcompilerppufile);override;
  511. function getcopy:tlinkedlistitem;override;
  512. end;
  513. { Generates a common label }
  514. tai_symbol = class(tai)
  515. sym : tasmsymbol;
  516. value : puint;
  517. size : longint;
  518. is_global,
  519. has_value : boolean;
  520. constructor Create(_sym:tasmsymbol;siz:longint);
  521. constructor Create_Global(_sym:tasmsymbol;siz:longint);
  522. constructor Createname(const _name : string;_symtyp:Tasmsymtype;siz:longint;def:tdef);
  523. constructor Createname_global(const _name : string;_symtyp:Tasmsymtype;siz:longint;def:tdef);
  524. constructor Createname_hidden(const _name : string;_symtyp:Tasmsymtype;siz:longint;def:tdef);
  525. constructor Createname_global_value(const _name : string;_symtyp:Tasmsymtype;siz:longint;val:ptruint;def:tdef);
  526. constructor ppuload(t:taitype;ppufile:tcompilerppufile);override;
  527. procedure ppuwrite(ppufile:tcompilerppufile);override;
  528. procedure derefimpl;override;
  529. end;
  530. tai_symbol_end = class(tailineinfo)
  531. sym : tasmsymbol;
  532. constructor Create(_sym:tasmsymbol);
  533. constructor Createname(const _name : string);
  534. constructor ppuload(t:taitype;ppufile:tcompilerppufile);override;
  535. procedure ppuwrite(ppufile:tcompilerppufile);override;
  536. procedure derefimpl;override;
  537. end;
  538. tai_directive = class(tailineinfo)
  539. name : ansistring;
  540. directive : TAsmDirective;
  541. constructor Create(_directive:TAsmDirective;const _name:ansistring);
  542. constructor ppuload(t:taitype;ppufile:tcompilerppufile);override;
  543. procedure ppuwrite(ppufile:tcompilerppufile);override;
  544. end;
  545. { Generates an assembler label }
  546. tai_label = class(tai)
  547. labsym : tasmlabel;
  548. {$ifdef arm}
  549. { set to true when the label has been moved by insertpcrelativedata to the correct location
  550. so one label can be used multiple times }
  551. moved : boolean;
  552. { true, if a label has been already inserted, this is important for arm thumb where no negative
  553. pc relative offsets are allowed }
  554. inserted : boolean;
  555. {$endif arm}
  556. constructor Create(_labsym : tasmlabel);
  557. constructor ppuload(t:taitype;ppufile:tcompilerppufile);override;
  558. procedure ppuwrite(ppufile:tcompilerppufile);override;
  559. procedure derefimpl;override;
  560. end;
  561. { Generates an assembler comment }
  562. tai_comment = class(tai)
  563. str : pchar;
  564. constructor Create(_str : pchar);
  565. destructor Destroy; override;
  566. constructor ppuload(t:taitype;ppufile:tcompilerppufile);override;
  567. procedure ppuwrite(ppufile:tcompilerppufile);override;
  568. function getcopy:tlinkedlistitem;override;
  569. end;
  570. { Generates a section / segment directive }
  571. tai_section = class(tai)
  572. sectype : TAsmSectiontype;
  573. secorder : TasmSectionorder;
  574. secalign : longint;
  575. name : pshortstring;
  576. { used in binary writer }
  577. sec : TObjSection;
  578. { used only by ELF so far }
  579. secflags : TSectionFlags;
  580. secprogbits : TSectionProgbits;
  581. destructor Destroy;override;
  582. constructor ppuload(t:taitype;ppufile:tcompilerppufile);override;
  583. procedure ppuwrite(ppufile:tcompilerppufile);override;
  584. {$push}{$warnings off}
  585. private
  586. { this constructor is made private on purpose }
  587. { because sections should be created via new_section() }
  588. constructor Create(Asectype:TAsmSectiontype;const Aname:string;Aalign:longint;Asecorder:TasmSectionorder=secorder_default);
  589. {$pop}
  590. end;
  591. { Generates an uninitializised data block }
  592. tai_datablock = class(tailineinfo)
  593. is_global : boolean;
  594. sym : tasmsymbol;
  595. size : asizeint;
  596. constructor Create(const _name: string; _size: asizeint; def: tdef; _typ: Tasmsymtype);
  597. constructor Create_hidden(const _name: string; _size: asizeint; def: tdef; _typ: Tasmsymtype);
  598. constructor Create_global(const _name: string; _size: asizeint; def: tdef; _typ: Tasmsymtype);
  599. constructor ppuload(t:taitype;ppufile:tcompilerppufile);override;
  600. procedure ppuwrite(ppufile:tcompilerppufile);override;
  601. procedure derefimpl;override;
  602. end;
  603. { Generates an integer const }
  604. { tai_const }
  605. tai_const = class(tai)
  606. sym,
  607. endsym : tasmsymbol;
  608. { if symbols and offset are provided the symofs is used,
  609. the value is calculated during assembling }
  610. symofs,
  611. value : int64;
  612. consttype : taiconst_type;
  613. { sleb128 and uleb128 values have a varying length, by calling FixSize their size can be fixed
  614. to avoid that other offsets need to be changed. The value to write is stored in fixed_size }
  615. fixed_size : byte;
  616. { we use for the 128bit int64/qword for now because I can't imagine a
  617. case where we need 128 bit now (FK) }
  618. constructor Create(_typ:taiconst_type;_value : int64);
  619. constructor Create_128bit(_value : int64);
  620. constructor Create_64bit(_value : int64);
  621. constructor Create_32bit(_value : longint);
  622. constructor Create_16bit(_value : word);
  623. constructor Create_64bit_unaligned(_value : int64);
  624. constructor Create_32bit_unaligned(_value : longint);
  625. constructor Create_16bit_unaligned(_value : word);
  626. constructor Create_8bit(_value : byte);
  627. constructor Create_char(size: integer; _value: dword);
  628. constructor Create_sleb128bit(_value : int64);
  629. constructor Create_uleb128bit(_value : qword);
  630. constructor Create_aint(_value : aint);
  631. constructor Create_sizeint(_value : asizeint);
  632. constructor Create_sizeint_unaligned(_value : asizeint);
  633. constructor Create_sym(_sym:tasmsymbol);
  634. {$ifdef i8086}
  635. constructor Create_sym_near(_sym:tasmsymbol);
  636. constructor Create_sym_far(_sym:tasmsymbol);
  637. constructor Createname_near(const name:string;ofs:asizeint);
  638. constructor Createname_far(const name:string;ofs:asizeint);
  639. constructor Createname_near(const name:string;_symtyp:Tasmsymtype;ofs:asizeint);
  640. constructor Createname_far(const name:string;_symtyp:Tasmsymtype;ofs:asizeint);
  641. {$endif i8086}
  642. constructor Create_type_sym(_typ:taiconst_type;_sym:tasmsymbol);
  643. constructor Create_sym_offset(_sym:tasmsymbol;ofs:asizeint);
  644. constructor Create_type_sym_offset(_typ:taiconst_type;_sym:tasmsymbol;ofs:asizeint);
  645. constructor Create_rel_sym(_typ:taiconst_type;_sym,_endsym:tasmsymbol);
  646. constructor Create_rel_sym_offset(_typ : taiconst_type; _sym,_endsym : tasmsymbol; _ofs : int64);
  647. constructor Create_rva_sym(_sym:tasmsymbol);
  648. constructor Createname(const name:string;ofs:asizeint);
  649. constructor Createname(const name:string;_symtyp:Tasmsymtype;ofs:asizeint);
  650. constructor Create_type_name(_typ:taiconst_type;const name:string;ofs:asizeint);
  651. constructor Create_type_name(_typ:taiconst_type;const name:string;_symtyp:Tasmsymtype;ofs:asizeint);
  652. constructor Create_nil_codeptr;
  653. constructor Create_nil_codeptr_unaligned;
  654. constructor Create_nil_dataptr;
  655. constructor Create_nil_dataptr_unaligned;
  656. constructor Create_int_codeptr(_value: int64);
  657. constructor Create_int_codeptr_unaligned(_value: int64);
  658. constructor Create_int_dataptr(_value: int64);
  659. constructor Create_int_dataptr_unaligned(_value: int64);
  660. {$ifdef avr}
  661. constructor Create_int_dataptr_unaligned(_value: int64; size: taiconst_type);
  662. {$endif}
  663. {$ifdef i8086}
  664. constructor Create_seg_name(const name:string);
  665. constructor Create_dgroup;
  666. constructor Create_fardataseg;
  667. {$endif i8086}
  668. constructor ppuload(t:taitype;ppufile:tcompilerppufile);override;
  669. procedure ppuwrite(ppufile:tcompilerppufile);override;
  670. procedure derefimpl;override;
  671. function getcopy:tlinkedlistitem;override;
  672. function size:longint;
  673. { sleb128 and uleb128 values have a varying length, by calling FixSize their size can be fixed
  674. to avoid that other offsets need to be changed. The value to write is stored in fixed_size }
  675. Procedure FixSize;
  676. end;
  677. { floating point const }
  678. tformatoptions = (fo_none,fo_hiloswapped);
  679. tai_realconst = class(tai)
  680. realtyp: tairealconsttype;
  681. savesize: byte;
  682. value: record
  683. case tairealconsttype of
  684. aitrealconst_s32bit: (s32val: ts32real);
  685. aitrealconst_s64bit: (s64val: ts64real);
  686. aitrealconst_s80bit: (s80val: ts80real);
  687. aitrealconst_s128bit: (s128val: ts128real);
  688. aitrealconst_s64comp: (s64compval: ts64comp);
  689. end;
  690. {$ifdef ARM}
  691. formatoptions : tformatoptions;
  692. {$endif ARM}
  693. constructor create_s32real(val: ts32real);
  694. constructor create_s64real(val: ts64real);
  695. {$ifdef ARM}
  696. constructor create_s64real_hiloswapped(val : ts64real);
  697. {$endif ARM}
  698. constructor create_s80real(val: ts80real; _savesize: byte);
  699. constructor create_s128real(val: ts128real);
  700. constructor create_s64compreal(val: ts64comp);
  701. constructor ppuload(t: taitype;ppufile: tcompilerppufile); override;
  702. procedure ppuwrite(ppufile: tcompilerppufile); override;
  703. function getcopy:tlinkedlistitem;override;
  704. function datasize: word;
  705. end;
  706. { tai_stab }
  707. tai_stab = class(tai)
  708. str : pchar;
  709. stabtype : TStabType;
  710. constructor Create(_stabtype:TStabType;_str : pchar);
  711. constructor Create_str(_stabtype:TStabType;const s:string);
  712. constructor create_ansistr(_stabtype: TStabType; const s: ansistring);
  713. destructor Destroy;override;
  714. end;
  715. tai_force_line = class(tailineinfo)
  716. constructor Create;
  717. end;
  718. tai_function_name = class(tai)
  719. funcname : pshortstring;
  720. constructor create(const s:string);
  721. destructor destroy;override;
  722. end;
  723. { Insert a cut to split assembler into several smaller files }
  724. tai_cutobject = class(tai)
  725. place : tcutplace;
  726. constructor Create;
  727. constructor Create_begin;
  728. constructor Create_end;
  729. constructor ppuload(t:taitype;ppufile:tcompilerppufile);override;
  730. procedure ppuwrite(ppufile:tcompilerppufile);override;
  731. end;
  732. { Insert a marker for assembler and inline blocks }
  733. tai_marker = class(tai)
  734. Kind: TAsmMarker;
  735. Constructor Create(_Kind: TAsmMarker);
  736. constructor ppuload(t:taitype;ppufile:tcompilerppufile);override;
  737. procedure ppuwrite(ppufile:tcompilerppufile);override;
  738. end;
  739. tai_tempalloc = class(tai)
  740. allocation : boolean;
  741. {$ifdef EXTDEBUG}
  742. problem : pshortstring;
  743. {$endif EXTDEBUG}
  744. temppos,
  745. tempsize : longint;
  746. constructor alloc(pos,size:longint);
  747. constructor dealloc(pos,size:longint);
  748. {$ifdef EXTDEBUG}
  749. constructor allocinfo(pos,size:longint;const st:string);
  750. {$endif EXTDEBUG}
  751. constructor ppuload(t:taitype;ppufile:tcompilerppufile);override;
  752. destructor destroy;override;
  753. procedure ppuwrite(ppufile:tcompilerppufile);override;
  754. end;
  755. tai_regalloc = class(tai)
  756. reg : tregister;
  757. ratype : TRegAllocType;
  758. { tells BuildLabelTableAndFixRegAlloc that the deallocation should be kept }
  759. keep : boolean;
  760. { reg(de)alloc belongs to this instruction, this
  761. is only used for automatic inserted (de)alloc for
  762. imaginary register and required for spilling code }
  763. instr : tai;
  764. constructor alloc(r : tregister;ainstr:tai);
  765. constructor dealloc(r : tregister;ainstr:tai);
  766. constructor sync(r : tregister);
  767. constructor resize(r : tregister);
  768. constructor markused(r : tregister);
  769. constructor ppuload(t:taitype;ppufile:tcompilerppufile);override;
  770. procedure ppuwrite(ppufile:tcompilerppufile);override;
  771. end;
  772. tadd_reg_instruction_proc=procedure(instr:Tai;r:tregister) of object;
  773. { Class template for assembler instructions
  774. }
  775. tai_cpu_abstract = class(tailineinfo)
  776. protected
  777. procedure ppuloadoper(ppufile:tcompilerppufile;var o:toper);virtual;
  778. procedure ppuwriteoper(ppufile:tcompilerppufile;const o:toper);virtual;
  779. procedure ppubuildderefimploper(var o:toper);virtual;abstract;
  780. procedure ppuderefoper(var o:toper);virtual;abstract;
  781. public
  782. { Condition flags for instruction }
  783. condition : TAsmCond;
  784. { Number of operands to instruction }
  785. ops : byte;
  786. { Number of allocate oper structures }
  787. opercnt : byte;
  788. { Operands of instruction }
  789. oper : array[0..max_operands-1] of poper;
  790. { Actual opcode of instruction }
  791. opcode : tasmop;
  792. {$ifdef x86}
  793. segprefix : tregister;
  794. {$endif x86}
  795. { true if instruction is a jmp }
  796. is_jmp : boolean; { is this instruction a jump? (needed for optimizer) }
  797. Constructor Create(op : tasmop);virtual;
  798. Destructor Destroy;override;
  799. function getcopy:TLinkedListItem;override;
  800. constructor ppuload(t:taitype;ppufile:tcompilerppufile);override;
  801. procedure ppuwrite(ppufile:tcompilerppufile);override;
  802. procedure buildderefimpl;override;
  803. procedure derefimpl;override;
  804. procedure SetCondition(const c:TAsmCond);
  805. procedure allocate_oper(opers:longint);
  806. procedure loadconst(opidx:longint;l:tcgint);
  807. procedure loadsymbol(opidx:longint;s:tasmsymbol;sofs:longint);
  808. procedure loadlocal(opidx:longint;s:pointer;sofs:longint;indexreg:tregister;scale:byte;getoffset,forceref:boolean);
  809. procedure loadref(opidx:longint;const r:treference);
  810. procedure loadreg(opidx:longint;r:tregister);
  811. procedure loadoper(opidx:longint;o:toper); virtual;
  812. procedure clearop(opidx:longint); virtual;
  813. procedure freeop(opidx:longint);
  814. { register allocator }
  815. function is_same_reg_move(regtype: Tregistertype):boolean;virtual;
  816. function spilling_get_operation_type(opnr: longint): topertype;virtual;
  817. function spilling_get_operation_type_ref(opnr: longint; reg: tregister): topertype;virtual;
  818. function Pass1(objdata:TObjData):longint;virtual;
  819. procedure Pass2(objdata:TObjData);virtual;
  820. procedure resetpass1; virtual;
  821. procedure resetpass2; virtual;
  822. end;
  823. tai_cpu_class = class of tai_cpu_abstract;
  824. { Buffer type used for alignment }
  825. tfillbuffer = array[0..63] of char;
  826. { alignment for operator }
  827. tai_align_abstract = class(tai)
  828. aligntype : byte; { 1 = no align, 2 = word align, 4 = dword align }
  829. maxbytes : byte; { if needed bytes would be larger than maxbyes, alignment is ignored }
  830. fillsize : byte; { real size to fill }
  831. fillop : byte; { value to fill with - optional }
  832. use_op : boolean;
  833. constructor Create(b:byte);virtual;
  834. constructor Create_op(b: byte; _op: byte);virtual;
  835. constructor create_max(b: byte; max: byte);virtual;
  836. constructor Create_zeros(b:byte);
  837. constructor ppuload(t:taitype;ppufile:tcompilerppufile);override;
  838. procedure ppuwrite(ppufile:tcompilerppufile);override;
  839. function calculatefillbuf(var buf : tfillbuffer;executable : boolean):pchar;virtual;
  840. end;
  841. tai_align_class = class of tai_align_abstract;
  842. tai_varloc = class(tai)
  843. newlocation,
  844. newlocationhi : tregister;
  845. varsym : tsym;
  846. constructor create(sym : tsym;loc : tregister);
  847. constructor create64(sym : tsym;loc,lochi : tregister);
  848. {$ifdef cpu64bitalu}
  849. constructor create128(sym : tsym;loc,lochi : tregister);
  850. {$endif cpu64bitalu}
  851. constructor ppuload(t:taitype;ppufile:tcompilerppufile);override;
  852. procedure ppuwrite(ppufile:tcompilerppufile);override;
  853. procedure buildderefimpl;override;
  854. procedure derefimpl;override;
  855. end;
  856. TSehDirectiveDatatype=(sd_none,sd_string,sd_reg,sd_offset,sd_regoffset);
  857. TSehDirectiveData=record
  858. case typ: TSehDirectiveDatatype of
  859. sd_none: ();
  860. sd_string: (name:pshortstring;flags:byte);
  861. sd_reg,sd_offset,sd_regoffset: (reg:TRegister;offset:dword);
  862. end;
  863. tai_seh_directive = class(tai)
  864. kind: TAsmSehDirective;
  865. data: TSehDirectiveData;
  866. constructor create(_kind:TAsmSehDirective);
  867. constructor create_name(_kind:TAsmSehDirective;const _name: string);
  868. constructor create_reg(_kind:TAsmSehDirective;r:TRegister);
  869. constructor create_offset(_kind:TAsmSehDirective;ofs:dword);
  870. constructor create_reg_offset(_kind:TAsmSehDirective;r:TRegister;ofs:dword);
  871. constructor ppuload(t:taitype;ppufile:tcompilerppufile);override;
  872. destructor destroy;override;
  873. procedure ppuwrite(ppufile:tcompilerppufile);override;
  874. procedure generate_code(objdata:TObjData);virtual;
  875. property datatype: TSehDirectiveDatatype read data.typ;
  876. end;
  877. tai_seh_directive_class=class of tai_seh_directive;
  878. {$ifdef JVM}
  879. { JVM variable live range description }
  880. tai_jvar = class(tai)
  881. stackslot: longint;
  882. desc: pshortstring;
  883. startlab,stoplab: tasmsymbol;
  884. constructor Create(_stackslot: longint; const _desc: shortstring; _startlab, _stoplab: TAsmSymbol);
  885. constructor ppuload(t:taitype;ppufile:tcompilerppufile);override;
  886. procedure ppuwrite(ppufile:tcompilerppufile);override;
  887. destructor destroy;override;
  888. end;
  889. tai_jvar_class = class of tai_jvar;
  890. { JVM exception catch description }
  891. tai_jcatch = class(tai)
  892. name: pshortstring;
  893. startlab,stoplab,handlerlab: tasmsymbol;
  894. constructor Create(const _name: shortstring; _startlab, _stoplab, _handlerlab: TAsmSymbol);
  895. destructor destroy;override;
  896. constructor ppuload(t:taitype;ppufile:tcompilerppufile);override;
  897. procedure ppuwrite(ppufile:tcompilerppufile);override;
  898. end;
  899. tai_jcatch_class = class of tai_jcatch;
  900. {$endif JVM}
  901. tai_symbolpair = class(tai)
  902. kind: TSymbolPairKind;
  903. sym,
  904. value: pshortstring;
  905. constructor create(akind: TSymbolPairKind; const asym, avalue: string);
  906. destructor destroy;override;
  907. constructor ppuload(t:taitype;ppufile:tcompilerppufile);override;
  908. procedure ppuwrite(ppufile:tcompilerppufile);override;
  909. end;
  910. teattrtyp = (eattrtype_none,eattrtype_dword,eattrtype_ntbs);
  911. tai_eabi_attribute = class(tai)
  912. eattr_typ : teattrtyp;
  913. tag,value : dword;
  914. valuestr : pstring;
  915. constructor create(atag,avalue : dword);
  916. constructor create(atag : dword;const avalue : string);
  917. destructor destroy;override;
  918. constructor ppuload(t:taitype;ppufile:tcompilerppufile);override;
  919. procedure ppuwrite(ppufile:tcompilerppufile);override;
  920. end;
  921. var
  922. { array with all class types for tais }
  923. aiclass : taiclassarray;
  924. { target specific tais, possibly overwritten in target specific aasmcpu }
  925. cai_align : tai_align_class = tai_align_abstract;
  926. cai_cpu : tai_cpu_class = tai_cpu_abstract;
  927. cai_seh_directive: tai_seh_directive_class = tai_seh_directive;
  928. { hook to notify uses of registers }
  929. add_reg_instruction_hook : tadd_reg_instruction_proc;
  930. procedure maybe_new_object_file(list:TAsmList);
  931. function new_section(list:TAsmList;Asectype:TAsmSectiontype;const Aname:string;Aalign:byte;Asecorder:TasmSectionorder=secorder_default) : tai_section;
  932. function ppuloadai(ppufile:tcompilerppufile):tai;
  933. procedure ppuwriteai(ppufile:tcompilerppufile;n:tai);
  934. implementation
  935. uses
  936. {$ifdef x86}
  937. aasmcpu,
  938. {$endif x86}
  939. SysUtils,
  940. verbose,
  941. globals;
  942. const
  943. pputaimarker = 254;
  944. {****************************************************************************
  945. Helpers
  946. ****************************************************************************}
  947. procedure maybe_new_object_file(list:TAsmList);
  948. begin
  949. if create_smartlink_library then
  950. list.concat(tai_cutobject.create);
  951. end;
  952. function new_section(list:TAsmList;Asectype:TAsmSectiontype;const Aname:string;Aalign:byte;Asecorder:TasmSectionorder=secorder_default) : tai_section;
  953. begin
  954. Result:=tai_section.create(Asectype,Aname,Aalign,Asecorder);
  955. list.concat(Result);
  956. inc(list.section_count);
  957. list.concat(cai_align.create(Aalign));
  958. end;
  959. function ppuloadai(ppufile:tcompilerppufile):tai;
  960. var
  961. b : byte;
  962. t : taitype;
  963. begin
  964. { marker }
  965. b:=ppufile.getbyte;
  966. if b<>pputaimarker then
  967. internalerror(200208181);
  968. { load nodetype }
  969. t:=taitype(ppufile.getbyte);
  970. if t<>ait_none then
  971. begin
  972. if t>high(taitype) then
  973. internalerror(200208182);
  974. if not assigned(aiclass[t]) then
  975. internalerror(200208183);
  976. {writeln('taiload: ',taitypestr[t]);}
  977. { generate tai of the correct class }
  978. ppuloadai:=aiclass[t].ppuload(t,ppufile);
  979. end
  980. else
  981. ppuloadai:=nil;
  982. end;
  983. procedure ppuwriteai(ppufile:tcompilerppufile;n:tai);
  984. begin
  985. { marker, read by ppuloadnode }
  986. ppufile.putbyte(pputaimarker);
  987. if assigned(n) then
  988. begin
  989. { type, read by ppuloadnode }
  990. ppufile.putbyte(byte(n.typ));
  991. {writeln('taiwrite: ',taitypestr[n.typ]);}
  992. n.ppuwrite(ppufile);
  993. end
  994. else
  995. ppufile.putbyte(byte(ait_none));
  996. end;
  997. constructor tai_symbolpair.create(akind: TSymbolPairKind; const asym, avalue: string);
  998. begin
  999. inherited create;
  1000. kind:=akind;
  1001. typ:=ait_symbolpair;
  1002. sym:=stringdup(asym);
  1003. value:=stringdup(avalue);
  1004. end;
  1005. destructor tai_symbolpair.destroy;
  1006. begin
  1007. stringdispose(sym);
  1008. stringdispose(value);
  1009. inherited destroy;
  1010. end;
  1011. constructor tai_symbolpair.ppuload(t: taitype; ppufile: tcompilerppufile);
  1012. begin
  1013. inherited ppuload(t,ppufile);
  1014. kind:=TSymbolPairKind(ppufile.getbyte);;
  1015. sym:=ppufile.getpshortstring;
  1016. value:=ppufile.getpshortstring;
  1017. end;
  1018. procedure tai_symbolpair.ppuwrite(ppufile: tcompilerppufile);
  1019. begin
  1020. inherited ppuwrite(ppufile);
  1021. ppufile.putbyte(byte(kind));
  1022. ppufile.putstring(sym^);
  1023. ppufile.putstring(value^);
  1024. end;
  1025. constructor tai_varloc.create(sym: tsym; loc: tregister);
  1026. begin
  1027. inherited Create;
  1028. typ:=ait_varloc;
  1029. newlocation:=loc;
  1030. newlocationhi:=NR_NO;
  1031. varsym:=sym;
  1032. end;
  1033. constructor tai_varloc.create64(sym: tsym; loc, lochi: tregister);
  1034. begin
  1035. inherited Create;
  1036. typ:=ait_varloc;
  1037. newlocation:=loc;
  1038. newlocationhi:=lochi;
  1039. varsym:=sym;
  1040. end;
  1041. {$ifdef cpu64bitalu}
  1042. constructor tai_varloc.create128(sym: tsym; loc, lochi: tregister);
  1043. begin
  1044. inherited Create;
  1045. typ:=ait_varloc;
  1046. newlocation:=loc;
  1047. newlocationhi:=lochi;
  1048. varsym:=sym;
  1049. end;
  1050. {$endif cpu64bitalu}
  1051. constructor tai_varloc.ppuload(t: taitype; ppufile: tcompilerppufile);
  1052. begin
  1053. inherited ppuload(t, ppufile);
  1054. end;
  1055. procedure tai_varloc.ppuwrite(ppufile: tcompilerppufile);
  1056. begin
  1057. inherited ppuwrite(ppufile);
  1058. end;
  1059. procedure tai_varloc.buildderefimpl;
  1060. begin
  1061. inherited buildderefimpl;
  1062. end;
  1063. procedure tai_varloc.derefimpl;
  1064. begin
  1065. inherited derefimpl;
  1066. end;
  1067. {****************************************************************************
  1068. TAI
  1069. ****************************************************************************}
  1070. constructor tai.Create;
  1071. begin
  1072. {$ifndef NOOPT}
  1073. optinfo:=nil;
  1074. {$endif NOOPT}
  1075. end;
  1076. constructor tai.ppuload(t:taitype;ppufile:tcompilerppufile);
  1077. begin
  1078. typ:=t;
  1079. {$ifndef NOOPT}
  1080. optinfo:=nil;
  1081. {$endif}
  1082. end;
  1083. procedure tai.ppuwrite(ppufile:tcompilerppufile);
  1084. begin
  1085. end;
  1086. procedure tai.buildderefimpl;
  1087. begin
  1088. end;
  1089. procedure tai.derefimpl;
  1090. begin
  1091. end;
  1092. {****************************************************************************
  1093. TAILINEINFO
  1094. ****************************************************************************}
  1095. constructor tailineinfo.create;
  1096. begin
  1097. inherited create;
  1098. fileinfo:=current_filepos;
  1099. end;
  1100. constructor tailineinfo.ppuload(t:taitype;ppufile:tcompilerppufile);
  1101. begin
  1102. inherited ppuload(t,ppufile);
  1103. ppufile.getposinfo(fileinfo);
  1104. end;
  1105. procedure tailineinfo.ppuwrite(ppufile:tcompilerppufile);
  1106. begin
  1107. inherited ppuwrite(ppufile);
  1108. ppufile.putposinfo(fileinfo);
  1109. end;
  1110. {****************************************************************************
  1111. TAI_SIMPLE
  1112. ****************************************************************************}
  1113. constructor tai_simple.create(_typ : taitype);
  1114. begin
  1115. inherited create;
  1116. typ:=_typ;
  1117. end;
  1118. {****************************************************************************
  1119. TAI_SECTION
  1120. ****************************************************************************}
  1121. constructor tai_section.Create(Asectype:TAsmSectiontype;const Aname:string;Aalign:longint;Asecorder:TasmSectionorder=secorder_default);
  1122. begin
  1123. inherited Create;
  1124. typ:=ait_section;
  1125. sectype:=asectype;
  1126. secalign:=Aalign;
  1127. secorder:=Asecorder;
  1128. TObjData.sectiontype2progbitsandflags(sectype,secprogbits,secflags);
  1129. name:=stringdup(Aname);
  1130. sec:=nil;
  1131. end;
  1132. constructor tai_section.ppuload(t:taitype;ppufile:tcompilerppufile);
  1133. begin
  1134. inherited ppuload(t,ppufile);
  1135. sectype:=TAsmSectiontype(ppufile.getbyte);
  1136. secalign:=ppufile.getlongint;
  1137. name:=ppufile.getpshortstring;
  1138. secflags:=TSectionFlags(ppufile.getdword);
  1139. secprogbits:=TSectionProgbits(ppufile.getbyte);
  1140. sec:=nil;
  1141. end;
  1142. destructor tai_section.Destroy;
  1143. begin
  1144. stringdispose(name);
  1145. end;
  1146. procedure tai_section.ppuwrite(ppufile:tcompilerppufile);
  1147. begin
  1148. inherited ppuwrite(ppufile);
  1149. ppufile.putbyte(byte(sectype));
  1150. ppufile.putlongint(secalign);
  1151. ppufile.putstring(name^);
  1152. ppufile.putbyte(dword(secflags));
  1153. ppufile.putbyte(byte(secprogbits));
  1154. end;
  1155. {****************************************************************************
  1156. TAI_DATABLOCK
  1157. ****************************************************************************}
  1158. constructor tai_datablock.Create(const _name : string;_size : asizeint; def: tdef; _typ:Tasmsymtype);
  1159. begin
  1160. inherited Create;
  1161. typ:=ait_datablock;
  1162. sym:=current_asmdata.DefineAsmSymbol(_name,AB_LOCAL,_typ,def);
  1163. { keep things aligned }
  1164. if _size<=0 then
  1165. _size:=sizeof(aint);
  1166. size:=_size;
  1167. is_global:=false;
  1168. end;
  1169. constructor tai_datablock.Create_hidden(const _name: string; _size: asizeint; def: tdef; _typ:Tasmsymtype);
  1170. begin
  1171. if tf_supports_hidden_symbols in target_info.flags then
  1172. begin
  1173. inherited Create;
  1174. typ:=ait_datablock;
  1175. sym:=current_asmdata.DefineAsmSymbol(_name,AB_PRIVATE_EXTERN,_typ,def);
  1176. { keep things aligned }
  1177. if _size<=0 then
  1178. _size:=sizeof(aint);
  1179. size:=_size;
  1180. is_global:=true;
  1181. end
  1182. else
  1183. Create(_name,_size,def,_typ);
  1184. end;
  1185. constructor tai_datablock.Create_global(const _name : string;_size : asizeint; def: tdef; _typ:Tasmsymtype);
  1186. begin
  1187. inherited Create;
  1188. typ:=ait_datablock;
  1189. sym:=current_asmdata.DefineAsmSymbol(_name,AB_GLOBAL,_typ,def);
  1190. { keep things aligned }
  1191. if _size<=0 then
  1192. _size:=sizeof(aint);
  1193. size:=_size;
  1194. is_global:=true;
  1195. end;
  1196. constructor tai_datablock.ppuload(t:taitype;ppufile:tcompilerppufile);
  1197. begin
  1198. inherited Create;
  1199. sym:=ppufile.getasmsymbol;
  1200. size:=ppufile.getaint;
  1201. is_global:=ppufile.getboolean;
  1202. end;
  1203. procedure tai_datablock.ppuwrite(ppufile:tcompilerppufile);
  1204. begin
  1205. inherited ppuwrite(ppufile);
  1206. ppufile.putasmsymbol(sym);
  1207. ppufile.putaint(size);
  1208. ppufile.putboolean(is_global);
  1209. end;
  1210. procedure tai_datablock.derefimpl;
  1211. begin
  1212. end;
  1213. {****************************************************************************
  1214. TAI_SYMBOL
  1215. ****************************************************************************}
  1216. constructor tai_symbol.Create(_sym:tasmsymbol;siz:longint);
  1217. begin
  1218. inherited Create;
  1219. typ:=ait_symbol;
  1220. sym:=_sym;
  1221. size:=siz;
  1222. { don't redefine global/external symbols as local, as code to access
  1223. such symbols is different on some platforms }
  1224. if not(sym.bind in [AB_NONE,AB_LOCAL]) then
  1225. internalerror(2013081601);
  1226. sym.bind:=AB_LOCAL;
  1227. is_global:=false;
  1228. end;
  1229. constructor tai_symbol.Create_global(_sym:tasmsymbol;siz:longint);
  1230. begin
  1231. inherited Create;
  1232. typ:=ait_symbol;
  1233. sym:=_sym;
  1234. size:=siz;
  1235. { don't override PRIVATE_EXTERN with GLOBAL }
  1236. if not(sym.bind in [AB_GLOBAL,AB_PRIVATE_EXTERN]) then
  1237. sym.bind:=AB_GLOBAL;
  1238. is_global:=true;
  1239. end;
  1240. constructor tai_symbol.Createname(const _name : string;_symtyp:Tasmsymtype;siz:longint;def:tdef);
  1241. begin
  1242. inherited Create;
  1243. typ:=ait_symbol;
  1244. sym:=current_asmdata.DefineAsmSymbol(_name,AB_LOCAL,_symtyp,def);
  1245. size:=siz;
  1246. is_global:=false;
  1247. end;
  1248. constructor tai_symbol.Createname_global(const _name : string;_symtyp:Tasmsymtype;siz:longint;def:tdef);
  1249. begin
  1250. inherited Create;
  1251. typ:=ait_symbol;
  1252. sym:=current_asmdata.DefineAsmSymbol(_name,AB_GLOBAL,_symtyp,def);
  1253. size:=siz;
  1254. is_global:=true;
  1255. end;
  1256. constructor tai_symbol.Createname_hidden(const _name: string; _symtyp: Tasmsymtype; siz: longint; def: tdef);
  1257. begin
  1258. if tf_supports_hidden_symbols in target_info.flags then
  1259. begin
  1260. inherited Create;
  1261. typ:=ait_symbol;
  1262. sym:=current_asmdata.DefineAsmSymbol(_name,AB_PRIVATE_EXTERN,_symtyp,def);
  1263. size:=siz;
  1264. is_global:=true;
  1265. end
  1266. else
  1267. Createname(_name, _symtyp, siz, def);
  1268. end;
  1269. constructor tai_symbol.createname_global_value(const _name: string;_symtyp: tasmsymtype; siz: longint; val: ptruint;def:tdef);
  1270. begin
  1271. Createname_global(_name,_symtyp,siz,def);
  1272. value:=val;
  1273. has_value:=true;
  1274. end;
  1275. constructor tai_symbol.ppuload(t:taitype;ppufile:tcompilerppufile);
  1276. begin
  1277. inherited ppuload(t,ppufile);
  1278. sym:=ppufile.getasmsymbol;
  1279. size:=ppufile.getlongint;
  1280. is_global:=ppufile.getboolean;
  1281. end;
  1282. procedure tai_symbol.ppuwrite(ppufile:tcompilerppufile);
  1283. begin
  1284. inherited ppuwrite(ppufile);
  1285. ppufile.putasmsymbol(sym);
  1286. ppufile.putlongint(size);
  1287. ppufile.putboolean(is_global);
  1288. end;
  1289. procedure tai_symbol.derefimpl;
  1290. begin
  1291. end;
  1292. {****************************************************************************
  1293. TAI_SYMBOL_END
  1294. ****************************************************************************}
  1295. constructor tai_symbol_end.Create(_sym:tasmsymbol);
  1296. begin
  1297. inherited Create;
  1298. typ:=ait_symbol_end;
  1299. sym:=_sym;
  1300. end;
  1301. constructor tai_symbol_end.Createname(const _name : string);
  1302. begin
  1303. inherited Create;
  1304. typ:=ait_symbol_end;
  1305. sym:=current_asmdata.GetAsmSymbol(_name);
  1306. if not assigned(sym) then
  1307. internalerror(2013080301);
  1308. end;
  1309. constructor tai_symbol_end.ppuload(t:taitype;ppufile:tcompilerppufile);
  1310. begin
  1311. inherited ppuload(t,ppufile);
  1312. sym:=ppufile.getasmsymbol;
  1313. end;
  1314. procedure tai_symbol_end.ppuwrite(ppufile:tcompilerppufile);
  1315. begin
  1316. inherited ppuwrite(ppufile);
  1317. ppufile.putasmsymbol(sym);
  1318. end;
  1319. procedure tai_symbol_end.derefimpl;
  1320. begin
  1321. end;
  1322. {****************************************************************************
  1323. TAI_SYMBOL_END
  1324. ****************************************************************************}
  1325. constructor tai_directive.Create(_directive:TAsmDirective;const _name:ansistring);
  1326. begin
  1327. inherited Create;
  1328. typ:=ait_directive;
  1329. name:=_name;
  1330. directive:=_directive;
  1331. end;
  1332. constructor tai_directive.ppuload(t:taitype;ppufile:tcompilerppufile);
  1333. begin
  1334. inherited ppuload(t,ppufile);
  1335. name:=ppufile.getansistring;
  1336. directive:=TAsmDirective(ppufile.getbyte);
  1337. end;
  1338. procedure tai_directive.ppuwrite(ppufile:tcompilerppufile);
  1339. begin
  1340. inherited ppuwrite(ppufile);
  1341. ppufile.putansistring(name);
  1342. ppufile.putbyte(byte(directive));
  1343. end;
  1344. {****************************************************************************
  1345. TAI_CONST
  1346. ****************************************************************************}
  1347. constructor tai_const.Create(_typ:taiconst_type;_value : int64);
  1348. begin
  1349. inherited Create;
  1350. typ:=ait_const;
  1351. consttype:=_typ;
  1352. value:=_value;
  1353. sym:=nil;
  1354. endsym:=nil;
  1355. end;
  1356. constructor tai_const.Create_128bit(_value : int64);
  1357. begin
  1358. inherited Create;
  1359. typ:=ait_const;
  1360. consttype:=aitconst_128bit;
  1361. value:=_value;
  1362. sym:=nil;
  1363. endsym:=nil;
  1364. end;
  1365. constructor tai_const.Create_64bit(_value : int64);
  1366. begin
  1367. inherited Create;
  1368. typ:=ait_const;
  1369. consttype:=aitconst_64bit;
  1370. value:=_value;
  1371. sym:=nil;
  1372. endsym:=nil;
  1373. end;
  1374. constructor tai_const.Create_32bit(_value : longint);
  1375. begin
  1376. inherited Create;
  1377. typ:=ait_const;
  1378. consttype:=aitconst_32bit;
  1379. value:=_value;
  1380. sym:=nil;
  1381. endsym:=nil;
  1382. end;
  1383. constructor tai_const.Create_16bit(_value : word);
  1384. begin
  1385. inherited Create;
  1386. typ:=ait_const;
  1387. consttype:=aitconst_16bit;
  1388. value:=_value;
  1389. sym:=nil;
  1390. endsym:=nil;
  1391. end;
  1392. constructor tai_const.Create_64bit_unaligned(_value : int64);
  1393. begin
  1394. inherited Create;
  1395. typ:=ait_const;
  1396. consttype:=aitconst_64bit_unaligned;
  1397. value:=_value;
  1398. sym:=nil;
  1399. endsym:=nil;
  1400. end;
  1401. constructor tai_const.Create_32bit_unaligned(_value : longint);
  1402. begin
  1403. inherited Create;
  1404. typ:=ait_const;
  1405. consttype:=aitconst_32bit_unaligned;
  1406. value:=_value;
  1407. sym:=nil;
  1408. endsym:=nil;
  1409. end;
  1410. constructor tai_const.Create_16bit_unaligned(_value : word);
  1411. begin
  1412. inherited Create;
  1413. typ:=ait_const;
  1414. consttype:=aitconst_16bit_unaligned;
  1415. value:=_value;
  1416. sym:=nil;
  1417. endsym:=nil;
  1418. end;
  1419. constructor tai_const.Create_8bit(_value : byte);
  1420. begin
  1421. inherited Create;
  1422. typ:=ait_const;
  1423. consttype:=aitconst_8bit;
  1424. value:=_value;
  1425. sym:=nil;
  1426. endsym:=nil;
  1427. end;
  1428. constructor tai_const.Create_char(size: integer; _value: dword);
  1429. begin
  1430. inherited Create;
  1431. typ:=ait_const;
  1432. case size of
  1433. 1:
  1434. begin
  1435. consttype:=aitconst_8bit;
  1436. value:=byte(_value)
  1437. end;
  1438. 2:
  1439. begin
  1440. consttype:=aitconst_16bit;
  1441. value:=word(_value)
  1442. end
  1443. else
  1444. InternalError(2010030701)
  1445. end
  1446. end;
  1447. constructor tai_const.Create_sleb128bit(_value : int64);
  1448. begin
  1449. inherited Create;
  1450. typ:=ait_const;
  1451. consttype:=aitconst_sleb128bit;
  1452. value:=_value;
  1453. sym:=nil;
  1454. endsym:=nil;
  1455. end;
  1456. constructor tai_const.Create_uleb128bit(_value : qword);
  1457. begin
  1458. inherited Create;
  1459. typ:=ait_const;
  1460. consttype:=aitconst_uleb128bit;
  1461. value:=int64(_value);
  1462. sym:=nil;
  1463. endsym:=nil;
  1464. end;
  1465. constructor tai_const.Create_aint(_value : aint);
  1466. begin
  1467. inherited Create;
  1468. typ:=ait_const;
  1469. consttype:=aitconst_aint;
  1470. value:=_value;
  1471. sym:=nil;
  1472. endsym:=nil;
  1473. end;
  1474. constructor tai_const.Create_sizeint(_value : asizeint);
  1475. begin
  1476. inherited Create;
  1477. typ:=ait_const;
  1478. consttype:=aitconst_sizeint;
  1479. value:=_value;
  1480. sym:=nil;
  1481. endsym:=nil;
  1482. end;
  1483. constructor tai_const.Create_sizeint_unaligned(_value : asizeint);
  1484. begin
  1485. inherited Create;
  1486. typ:=ait_const;
  1487. consttype:=aitconst_sizeint_unaligned;
  1488. value:=_value;
  1489. sym:=nil;
  1490. endsym:=nil;
  1491. end;
  1492. constructor tai_const.Create_type_sym(_typ:taiconst_type;_sym:tasmsymbol);
  1493. begin
  1494. inherited Create;
  1495. typ:=ait_const;
  1496. consttype:=_typ;
  1497. sym:=_sym;
  1498. endsym:=nil;
  1499. value:=0;
  1500. { update sym info }
  1501. if assigned(sym) then
  1502. sym.increfs;
  1503. end;
  1504. constructor tai_const.Create_sym(_sym:tasmsymbol);
  1505. begin
  1506. self.create_sym_offset(_sym,0);
  1507. end;
  1508. {$ifdef i8086}
  1509. constructor tai_const.Create_sym_near(_sym: tasmsymbol);
  1510. begin
  1511. self.create_sym(_sym);
  1512. consttype:=aitconst_ptr;
  1513. end;
  1514. constructor tai_const.Create_sym_far(_sym: tasmsymbol);
  1515. begin
  1516. self.create_sym(_sym);
  1517. consttype:=aitconst_farptr;
  1518. end;
  1519. constructor tai_const.Createname_near(const name:string;ofs:asizeint);
  1520. begin
  1521. self.Createname(name,ofs);
  1522. consttype:=aitconst_ptr;
  1523. end;
  1524. constructor tai_const.Createname_far(const name:string;ofs:asizeint);
  1525. begin
  1526. self.Createname(name,ofs);
  1527. consttype:=aitconst_farptr;
  1528. end;
  1529. constructor tai_const.Createname_near(const name:string;_symtyp:Tasmsymtype;ofs:asizeint);
  1530. begin
  1531. self.Createname(name,_symtyp,ofs);
  1532. consttype:=aitconst_ptr;
  1533. end;
  1534. constructor tai_const.Createname_far(const name:string;_symtyp:Tasmsymtype;ofs:asizeint);
  1535. begin
  1536. self.Createname(name,_symtyp,ofs);
  1537. consttype:=aitconst_farptr;
  1538. end;
  1539. {$endif i8086}
  1540. constructor tai_const.Create_sym_offset(_sym:tasmsymbol;ofs:asizeint);
  1541. begin
  1542. inherited Create;
  1543. typ:=ait_const;
  1544. {$ifdef i8086}
  1545. if assigned(_sym) and (_sym.typ=AT_DATA) then
  1546. begin
  1547. if current_settings.x86memorymodel in x86_far_data_models then
  1548. consttype:=aitconst_farptr
  1549. else
  1550. consttype:=aitconst_ptr;
  1551. end
  1552. else
  1553. begin
  1554. if current_settings.x86memorymodel in x86_far_code_models then
  1555. consttype:=aitconst_farptr
  1556. else
  1557. consttype:=aitconst_ptr;
  1558. end;
  1559. {$else i8086}
  1560. {$ifdef avr}
  1561. if assigned(_sym) and (_sym.typ=AT_FUNCTION) then
  1562. consttype:=aitconst_gs
  1563. else
  1564. {$endif avr}
  1565. consttype:=aitconst_ptr;
  1566. {$endif i8086}
  1567. { sym is allowed to be nil, this is used to write nil pointers }
  1568. sym:=_sym;
  1569. endsym:=nil;
  1570. { store the original offset in symofs so that we can recalculate the
  1571. value field in the assembler }
  1572. symofs:=ofs;
  1573. value:=ofs;
  1574. { update sym info }
  1575. if assigned(sym) then
  1576. sym.increfs;
  1577. end;
  1578. constructor tai_const.Create_type_sym_offset(_typ : taiconst_type;_sym : tasmsymbol; ofs : asizeint);
  1579. begin
  1580. inherited Create;
  1581. typ:=ait_const;
  1582. consttype:=_typ;
  1583. { sym is allowed to be nil, this is used to write nil pointers }
  1584. sym:=_sym;
  1585. endsym:=nil;
  1586. { store the original offset in symofs so that we can recalculate the
  1587. value field in the assembler }
  1588. symofs:=ofs;
  1589. value:=ofs;
  1590. { update sym info }
  1591. if assigned(sym) then
  1592. sym.increfs;
  1593. end;
  1594. constructor tai_const.Create_rel_sym(_typ:taiconst_type;_sym,_endsym:tasmsymbol);
  1595. begin
  1596. self.create_sym_offset(_sym,0);
  1597. consttype:=_typ;
  1598. endsym:=_endsym;
  1599. endsym.increfs;
  1600. end;
  1601. constructor tai_const.Create_rel_sym_offset(_typ: taiconst_type; _sym, _endsym: tasmsymbol; _ofs: int64);
  1602. begin
  1603. self.create_sym_offset(_sym,_ofs);
  1604. consttype:=_typ;
  1605. endsym:=_endsym;
  1606. endsym.increfs;
  1607. end;
  1608. constructor tai_const.Create_rva_sym(_sym:tasmsymbol);
  1609. begin
  1610. self.create_sym_offset(_sym,0);
  1611. consttype:=aitconst_rva_symbol;
  1612. end;
  1613. constructor tai_const.Createname(const name:string;ofs:asizeint);
  1614. begin
  1615. self.Createname(name,AT_NONE,ofs);
  1616. end;
  1617. constructor tai_const.Createname(const name:string;_symtyp:Tasmsymtype;ofs:asizeint);
  1618. begin
  1619. self.create_sym_offset(current_asmdata.RefAsmSymbol(name,_symtyp),ofs);
  1620. end;
  1621. constructor tai_const.Create_type_name(_typ:taiconst_type;const name:string;ofs:asizeint);
  1622. begin
  1623. self.Create_type_name(_typ,name,AT_NONE,ofs);
  1624. end;
  1625. constructor tai_const.Create_type_name(_typ:taiconst_type;const name:string;_symtyp:Tasmsymtype;ofs:asizeint);
  1626. begin
  1627. self.create_sym_offset(current_asmdata.RefAsmSymbol(name,_symtyp),ofs);
  1628. consttype:=_typ;
  1629. end;
  1630. constructor tai_const.Create_nil_codeptr;
  1631. begin
  1632. self.Create_int_codeptr(0);
  1633. end;
  1634. constructor tai_const.Create_nil_codeptr_unaligned;
  1635. begin
  1636. self.Create_int_codeptr_unaligned(0);
  1637. end;
  1638. constructor tai_const.Create_nil_dataptr;
  1639. begin
  1640. self.Create_int_dataptr(0);
  1641. end;
  1642. constructor tai_const.Create_nil_dataptr_unaligned;
  1643. begin
  1644. self.Create_int_dataptr_unaligned(0);
  1645. end;
  1646. constructor tai_const.Create_int_codeptr(_value: int64);
  1647. begin
  1648. inherited Create;
  1649. typ:=ait_const;
  1650. {$ifdef i8086}
  1651. if current_settings.x86memorymodel in x86_far_code_models then
  1652. consttype:=aitconst_farptr
  1653. else
  1654. {$endif i8086}
  1655. {$ifdef avr}
  1656. consttype:=aitconst_gs;
  1657. {$else avr}
  1658. consttype:=aitconst_ptr;
  1659. {$endif avr}
  1660. sym:=nil;
  1661. endsym:=nil;
  1662. symofs:=0;
  1663. value:=_value;
  1664. end;
  1665. constructor tai_const.Create_int_codeptr_unaligned(_value: int64);
  1666. begin
  1667. inherited Create;
  1668. typ:=ait_const;
  1669. {$ifdef i8086}
  1670. if current_settings.x86memorymodel in x86_far_code_models then
  1671. consttype:=aitconst_farptr
  1672. else
  1673. {$endif i8086}
  1674. {$ifdef avr}
  1675. consttype:=aitconst_gs;
  1676. {$else avr}
  1677. consttype:=aitconst_ptr_unaligned;
  1678. {$endif avr}
  1679. sym:=nil;
  1680. endsym:=nil;
  1681. symofs:=0;
  1682. value:=_value;
  1683. end;
  1684. constructor tai_const.Create_int_dataptr(_value: int64);
  1685. begin
  1686. inherited Create;
  1687. typ:=ait_const;
  1688. {$ifdef i8086}
  1689. if current_settings.x86memorymodel in x86_far_data_models then
  1690. consttype:=aitconst_farptr
  1691. else
  1692. {$endif i8086}
  1693. consttype:=aitconst_ptr;
  1694. sym:=nil;
  1695. endsym:=nil;
  1696. symofs:=0;
  1697. value:=_value;
  1698. end;
  1699. constructor tai_const.Create_int_dataptr_unaligned(_value: int64);
  1700. begin
  1701. inherited Create;
  1702. typ:=ait_const;
  1703. {$ifdef i8086}
  1704. if current_settings.x86memorymodel in x86_far_data_models then
  1705. consttype:=aitconst_farptr
  1706. else
  1707. {$endif i8086}
  1708. consttype:=aitconst_ptr_unaligned;
  1709. sym:=nil;
  1710. endsym:=nil;
  1711. symofs:=0;
  1712. value:=_value;
  1713. end;
  1714. {$ifdef avr}
  1715. constructor tai_const.Create_int_dataptr_unaligned(_value: int64;
  1716. size: taiconst_type);
  1717. begin
  1718. inherited Create;
  1719. typ:=ait_const;
  1720. consttype:=size;
  1721. sym:=nil;
  1722. endsym:=nil;
  1723. symofs:=0;
  1724. value:=_value;
  1725. end;
  1726. {$endif avr}
  1727. {$ifdef i8086}
  1728. constructor tai_const.Create_seg_name(const name:string);
  1729. begin
  1730. self.Createname(name,0);
  1731. self.consttype:=aitconst_seg;
  1732. end;
  1733. constructor tai_const.Create_dgroup;
  1734. begin
  1735. self.Create_16bit(0);
  1736. self.consttype:=aitconst_dgroup;
  1737. end;
  1738. constructor tai_const.Create_fardataseg;
  1739. begin
  1740. self.Create_16bit(0);
  1741. self.consttype:=aitconst_fardataseg;
  1742. end;
  1743. {$endif i8086}
  1744. constructor tai_const.ppuload(t:taitype;ppufile:tcompilerppufile);
  1745. begin
  1746. inherited ppuload(t,ppufile);
  1747. consttype:=taiconst_type(ppufile.getbyte);
  1748. sym:=ppufile.getasmsymbol;
  1749. endsym:=ppufile.getasmsymbol;
  1750. value:=ppufile.getint64;
  1751. end;
  1752. procedure tai_const.ppuwrite(ppufile:tcompilerppufile);
  1753. begin
  1754. inherited ppuwrite(ppufile);
  1755. ppufile.putbyte(byte(consttype));
  1756. ppufile.putasmsymbol(sym);
  1757. ppufile.putasmsymbol(endsym);
  1758. ppufile.putint64(value);
  1759. end;
  1760. procedure tai_const.derefimpl;
  1761. begin
  1762. end;
  1763. function tai_const.getcopy:tlinkedlistitem;
  1764. begin
  1765. getcopy:=inherited getcopy;
  1766. { we need to increase the reference number }
  1767. if assigned(sym) then
  1768. sym.increfs;
  1769. if assigned(endsym) then
  1770. endsym.increfs;
  1771. end;
  1772. function tai_const.size:longint;
  1773. begin
  1774. case consttype of
  1775. aitconst_8bit :
  1776. result:=1;
  1777. aitconst_16bit,aitconst_16bit_unaligned :
  1778. result:=2;
  1779. aitconst_32bit,aitconst_darwin_dwarf_delta32,
  1780. aitconst_32bit_unaligned:
  1781. result:=4;
  1782. aitconst_64bit,aitconst_darwin_dwarf_delta64,
  1783. aitconst_64bit_unaligned:
  1784. result:=8;
  1785. aitconst_secrel32_symbol,
  1786. aitconst_rva_symbol :
  1787. if target_info.system=system_x86_64_win64 then
  1788. result:=sizeof(longint)
  1789. else
  1790. result:=sizeof(pint);
  1791. aitconst_uleb128bit :
  1792. begin
  1793. if fixed_size>0 then
  1794. result:=fixed_size
  1795. else if sym=nil then
  1796. begin
  1797. FixSize;
  1798. result:=fixed_size;
  1799. end
  1800. else
  1801. { worst case }
  1802. result:=sizeof(pint)+2;
  1803. end;
  1804. aitconst_sleb128bit :
  1805. begin
  1806. if fixed_size>0 then
  1807. result:=fixed_size
  1808. else if sym=nil then
  1809. begin
  1810. FixSize;
  1811. result:=fixed_size;
  1812. end
  1813. else
  1814. { worst case }
  1815. result:=sizeof(pint)+2;
  1816. end;
  1817. aitconst_half16bit,
  1818. aitconst_gs:
  1819. result:=2;
  1820. aitconst_farptr:
  1821. result:=4;
  1822. aitconst_dgroup,
  1823. aitconst_fardataseg,
  1824. aitconst_seg:
  1825. result:=2;
  1826. aitconst_got:
  1827. result:=sizeof(pint);
  1828. aitconst_gotoff_symbol:
  1829. result:=4;
  1830. aitconst_gottpoff:
  1831. result:=4;
  1832. aitconst_tlsgd:
  1833. result:=4;
  1834. aitconst_tpoff:
  1835. result:=4;
  1836. aitconst_tlsdesc:
  1837. result:=4;
  1838. aitconst_dtpoff:
  1839. result:=4;
  1840. else
  1841. internalerror(200603253);
  1842. end;
  1843. end;
  1844. procedure tai_const.FixSize;
  1845. begin
  1846. case consttype of
  1847. aitconst_uleb128bit:
  1848. fixed_size:=LengthUleb128(qword(value));
  1849. aitconst_sleb128bit:
  1850. fixed_size:=LengthSleb128(value);
  1851. else
  1852. Internalerror(2019030301);
  1853. end;
  1854. end;
  1855. {****************************************************************************
  1856. TAI_realconst
  1857. ****************************************************************************}
  1858. constructor tai_realconst.create_s32real(val: ts32real);
  1859. begin
  1860. inherited create;
  1861. typ:=ait_realconst;
  1862. realtyp:=aitrealconst_s32bit;
  1863. savesize:=4;
  1864. value.s32val:=val;
  1865. end;
  1866. constructor tai_realconst.create_s64real(val: ts64real);
  1867. begin
  1868. inherited create;
  1869. typ:=ait_realconst;
  1870. realtyp:=aitrealconst_s64bit;
  1871. savesize:=8;
  1872. value.s64val:=val;
  1873. end;
  1874. {$ifdef ARM}
  1875. constructor tai_realconst.create_s64real_hiloswapped(val : ts64real);
  1876. begin
  1877. inherited create;
  1878. typ:=ait_realconst;
  1879. realtyp:=aitrealconst_s64bit;
  1880. value.s64val:=val;
  1881. savesize:=8;
  1882. formatoptions:=fo_hiloswapped;
  1883. end;
  1884. {$endif ARM}
  1885. constructor tai_realconst.create_s80real(val: ts80real; _savesize: byte);
  1886. begin
  1887. inherited create;
  1888. typ:=ait_realconst;
  1889. realtyp:=aitrealconst_s80bit;
  1890. savesize:=_savesize;
  1891. value.s80val:=val;
  1892. end;
  1893. constructor tai_realconst.create_s128real(val: ts128real);
  1894. begin
  1895. inherited create;
  1896. typ:=ait_realconst;
  1897. realtyp:=aitrealconst_s128bit;
  1898. savesize:=16;
  1899. value.s128val:=val;
  1900. end;
  1901. constructor tai_realconst.create_s64compreal(val: ts64comp);
  1902. begin
  1903. inherited create;
  1904. typ:=ait_realconst;
  1905. realtyp:=aitrealconst_s64comp;
  1906. savesize:=8;
  1907. value.s64compval:=val;
  1908. end;
  1909. constructor tai_realconst.ppuload(t: taitype; ppufile: tcompilerppufile);
  1910. begin
  1911. inherited;
  1912. realtyp:=tairealconsttype(ppufile.getbyte);
  1913. {$ifdef ARM}
  1914. formatoptions:=tformatoptions(ppufile.getbyte);
  1915. {$endif ARM}
  1916. case realtyp of
  1917. aitrealconst_s32bit:
  1918. value.s32val:=ppufile.getreal;
  1919. aitrealconst_s64bit:
  1920. value.s64val:=ppufile.getreal;
  1921. aitrealconst_s80bit:
  1922. value.s80val:=ppufile.getreal;
  1923. aitrealconst_s128bit:
  1924. value.s128val:=ppufile.getreal;
  1925. aitrealconst_s64comp:
  1926. value.s64compval:=comp(ppufile.getint64);
  1927. end;
  1928. end;
  1929. procedure tai_realconst.ppuwrite(ppufile: tcompilerppufile);
  1930. var
  1931. c: comp;
  1932. begin
  1933. inherited ppuwrite(ppufile);
  1934. ppufile.putbyte(byte(realtyp));
  1935. {$ifdef ARM}
  1936. ppufile.putbyte(byte(formatoptions));
  1937. {$endif ARM}
  1938. case realtyp of
  1939. aitrealconst_s32bit:
  1940. ppufile.putreal(value.s32val);
  1941. aitrealconst_s64bit:
  1942. ppufile.putreal(value.s64val);
  1943. aitrealconst_s80bit:
  1944. ppufile.putreal(value.s80val);
  1945. aitrealconst_s128bit:
  1946. ppufile.putreal(value.s128val);
  1947. aitrealconst_s64comp:
  1948. begin
  1949. c:=comp(value.s64compval);
  1950. ppufile.putint64(int64(c));
  1951. end
  1952. end;
  1953. end;
  1954. function tai_realconst.getcopy: tlinkedlistitem;
  1955. begin
  1956. result:=inherited getcopy;
  1957. tai_realconst(result).value:=value;
  1958. tai_realconst(result).realtyp:=realtyp;
  1959. tai_realconst(result).savesize:=savesize;
  1960. {$ifdef ARM}
  1961. tai_realconst(result).formatoptions:=formatoptions;
  1962. {$endif ARM}
  1963. end;
  1964. function tai_realconst.datasize: word;
  1965. begin
  1966. case realtyp of
  1967. aitrealconst_s32bit:
  1968. result:=4;
  1969. aitrealconst_s64bit,
  1970. aitrealconst_s64comp:
  1971. result:=8;
  1972. aitrealconst_s80bit:
  1973. result:=10;
  1974. aitrealconst_s128bit:
  1975. result:=16;
  1976. end;
  1977. end;
  1978. {****************************************************************************
  1979. TAI_STRING
  1980. ****************************************************************************}
  1981. constructor tai_string.Create(const _str : string);
  1982. begin
  1983. inherited Create;
  1984. typ:=ait_string;
  1985. len:=length(_str);
  1986. getmem(str,len+1);
  1987. move(_str[1],str^,len);
  1988. str[len]:=#0;
  1989. end;
  1990. constructor tai_string.Create_pchar(_str : pchar;length : longint);
  1991. begin
  1992. inherited Create;
  1993. typ:=ait_string;
  1994. str:=_str;
  1995. len:=length;
  1996. end;
  1997. destructor tai_string.destroy;
  1998. begin
  1999. if str<>nil then
  2000. freemem(str);
  2001. inherited Destroy;
  2002. end;
  2003. constructor tai_string.ppuload(t:taitype;ppufile:tcompilerppufile);
  2004. begin
  2005. inherited ppuload(t,ppufile);
  2006. len:=ppufile.getlongint;
  2007. getmem(str,len+1);
  2008. ppufile.getdata(str^,len);
  2009. str[len]:=#0
  2010. end;
  2011. procedure tai_string.ppuwrite(ppufile:tcompilerppufile);
  2012. begin
  2013. inherited ppuwrite(ppufile);
  2014. ppufile.putlongint(len);
  2015. ppufile.putdata(str^,len);
  2016. end;
  2017. function tai_string.getcopy : tlinkedlistitem;
  2018. var
  2019. p : tlinkedlistitem;
  2020. begin
  2021. p:=inherited getcopy;
  2022. getmem(tai_string(p).str,len);
  2023. move(str^,tai_string(p).str^,len);
  2024. getcopy:=p;
  2025. end;
  2026. {****************************************************************************
  2027. TAI_LABEL
  2028. ****************************************************************************}
  2029. constructor tai_label.Create(_labsym : tasmlabel);
  2030. begin
  2031. inherited Create;
  2032. typ:=ait_label;
  2033. labsym:=_labsym;
  2034. labsym.is_set:=true;
  2035. end;
  2036. constructor tai_label.ppuload(t:taitype;ppufile:tcompilerppufile);
  2037. begin
  2038. inherited ppuload(t,ppufile);
  2039. labsym:=tasmlabel(ppufile.getasmsymbol);
  2040. ppufile.getbyte; { was is_global flag, now unused }
  2041. end;
  2042. procedure tai_label.ppuwrite(ppufile:tcompilerppufile);
  2043. begin
  2044. inherited ppuwrite(ppufile);
  2045. ppufile.putasmsymbol(labsym);
  2046. ppufile.putbyte(0); { was is_global flag, now unused }
  2047. end;
  2048. procedure tai_label.derefimpl;
  2049. begin
  2050. labsym.is_set:=true;
  2051. end;
  2052. {****************************************************************************
  2053. tai_comment comment to be inserted in the assembler file
  2054. ****************************************************************************}
  2055. constructor tai_comment.Create(_str : pchar);
  2056. begin
  2057. inherited Create;
  2058. typ:=ait_comment;
  2059. str:=_str;
  2060. end;
  2061. destructor tai_comment.destroy;
  2062. begin
  2063. freemem(str);
  2064. inherited Destroy;
  2065. end;
  2066. constructor tai_comment.ppuload(t:taitype;ppufile:tcompilerppufile);
  2067. var
  2068. len : longint;
  2069. begin
  2070. inherited ppuload(t,ppufile);
  2071. len:=ppufile.getlongint;
  2072. getmem(str,len+1);
  2073. ppufile.getdata(str^,len);
  2074. str[len]:=#0;
  2075. end;
  2076. procedure tai_comment.ppuwrite(ppufile:tcompilerppufile);
  2077. var
  2078. len : longint;
  2079. begin
  2080. inherited ppuwrite(ppufile);
  2081. len:=strlen(str);
  2082. ppufile.putlongint(len);
  2083. ppufile.putdata(str^,len);
  2084. end;
  2085. function tai_comment.getcopy : tlinkedlistitem;
  2086. var
  2087. p : tlinkedlistitem;
  2088. begin
  2089. p:=inherited getcopy;
  2090. getmem(tai_comment(p).str,strlen(str)+1);
  2091. move(str^,tai_comment(p).str^,strlen(str)+1);
  2092. getcopy:=p;
  2093. end;
  2094. {****************************************************************************
  2095. TAI_STABS
  2096. ****************************************************************************}
  2097. constructor tai_stab.create(_stabtype:TStabType;_str : pchar);
  2098. begin
  2099. inherited create;
  2100. typ:=ait_stab;
  2101. str:=_str;
  2102. stabtype:=_stabtype;
  2103. end;
  2104. constructor tai_stab.create_str(_stabtype:TStabType;const s:string);
  2105. begin
  2106. self.create(_stabtype,strpnew(s));
  2107. end;
  2108. constructor tai_stab.create_ansistr(_stabtype:TStabType;const s:ansistring);
  2109. begin
  2110. inherited create;
  2111. typ:=ait_stab;
  2112. stabtype:=_stabtype;
  2113. getmem(str,length(s)+1);
  2114. if length(s)>0 then
  2115. move(s[1],str^,length(s)+1)
  2116. else
  2117. str^:=#0;
  2118. end;
  2119. destructor tai_stab.destroy;
  2120. begin
  2121. freemem(str);
  2122. inherited destroy;
  2123. end;
  2124. {****************************************************************************
  2125. TAI_FORCE_LINE
  2126. ****************************************************************************}
  2127. constructor tai_force_line.create;
  2128. begin
  2129. inherited create;
  2130. typ:=ait_force_line;
  2131. end;
  2132. {****************************************************************************
  2133. TAI_FUNCTION_NAME
  2134. ****************************************************************************}
  2135. constructor tai_function_name.create(const s:string);
  2136. begin
  2137. inherited create;
  2138. typ:=ait_function_name;
  2139. funcname:=stringdup(s);
  2140. end;
  2141. destructor tai_function_name.destroy;
  2142. begin
  2143. stringdispose(funcname);
  2144. inherited destroy;
  2145. end;
  2146. {****************************************************************************
  2147. TAI_CUTOBJECT
  2148. ****************************************************************************}
  2149. constructor tai_cutobject.Create;
  2150. begin
  2151. inherited Create;
  2152. typ:=ait_cutobject;
  2153. place:=cut_normal;
  2154. end;
  2155. constructor tai_cutobject.Create_begin;
  2156. begin
  2157. inherited Create;
  2158. typ:=ait_cutobject;
  2159. place:=cut_begin;
  2160. end;
  2161. constructor tai_cutobject.Create_end;
  2162. begin
  2163. inherited Create;
  2164. typ:=ait_cutobject;
  2165. place:=cut_end;
  2166. end;
  2167. constructor tai_cutobject.ppuload(t:taitype;ppufile:tcompilerppufile);
  2168. begin
  2169. inherited ppuload(t,ppufile);
  2170. place:=TCutPlace(ppufile.getbyte);
  2171. end;
  2172. procedure tai_cutobject.ppuwrite(ppufile:tcompilerppufile);
  2173. begin
  2174. inherited ppuwrite(ppufile);
  2175. ppufile.putbyte(byte(place));
  2176. end;
  2177. {****************************************************************************
  2178. Tai_Marker
  2179. ****************************************************************************}
  2180. constructor Tai_Marker.Create(_Kind: TAsmMarker);
  2181. begin
  2182. Inherited Create;
  2183. typ := ait_marker;
  2184. Kind := _Kind;
  2185. end;
  2186. constructor Tai_Marker.ppuload(t:taitype;ppufile:tcompilerppufile);
  2187. begin
  2188. inherited ppuload(t,ppufile);
  2189. kind:=TAsmMarker(ppufile.getbyte);
  2190. end;
  2191. procedure Tai_Marker.ppuwrite(ppufile:tcompilerppufile);
  2192. begin
  2193. inherited ppuwrite(ppufile);
  2194. ppufile.putbyte(byte(kind));
  2195. end;
  2196. {*****************************************************************************
  2197. tai_tempalloc
  2198. *****************************************************************************}
  2199. constructor tai_tempalloc.alloc(pos,size:longint);
  2200. begin
  2201. inherited Create;
  2202. typ:=ait_tempalloc;
  2203. allocation:=true;
  2204. temppos:=pos;
  2205. tempsize:=size;
  2206. {$ifdef EXTDEBUG}
  2207. problem:=nil;
  2208. {$endif EXTDEBUG}
  2209. end;
  2210. destructor tai_tempalloc.destroy;
  2211. begin
  2212. {$ifdef EXTDEBUG}
  2213. stringdispose(problem);
  2214. {$endif EXTDEBUG}
  2215. inherited destroy;
  2216. end;
  2217. constructor tai_tempalloc.dealloc(pos,size:longint);
  2218. begin
  2219. inherited Create;
  2220. typ:=ait_tempalloc;
  2221. allocation:=false;
  2222. temppos:=pos;
  2223. tempsize:=size;
  2224. {$ifdef EXTDEBUG}
  2225. problem:=nil;
  2226. {$endif EXTDEBUG}
  2227. end;
  2228. {$ifdef EXTDEBUG}
  2229. constructor tai_tempalloc.allocinfo(pos,size:longint;const st:string);
  2230. begin
  2231. inherited Create;
  2232. typ:=ait_tempalloc;
  2233. allocation:=false;
  2234. temppos:=pos;
  2235. tempsize:=size;
  2236. problem:=stringdup(st);
  2237. end;
  2238. {$endif EXTDEBUG}
  2239. constructor tai_tempalloc.ppuload(t:taitype;ppufile:tcompilerppufile);
  2240. begin
  2241. inherited ppuload(t,ppufile);
  2242. temppos:=ppufile.getlongint;
  2243. tempsize:=ppufile.getlongint;
  2244. allocation:=ppufile.getboolean;
  2245. {$ifdef EXTDEBUG}
  2246. problem:=nil;
  2247. {$endif EXTDEBUG}
  2248. end;
  2249. procedure tai_tempalloc.ppuwrite(ppufile:tcompilerppufile);
  2250. begin
  2251. inherited ppuwrite(ppufile);
  2252. ppufile.putlongint(temppos);
  2253. ppufile.putlongint(tempsize);
  2254. ppufile.putboolean(allocation);
  2255. end;
  2256. {*****************************************************************************
  2257. tai_regalloc
  2258. *****************************************************************************}
  2259. constructor tai_regalloc.alloc(r : tregister;ainstr:tai);
  2260. begin
  2261. inherited create;
  2262. typ:=ait_regalloc;
  2263. ratype:=ra_alloc;
  2264. reg:=r;
  2265. { ainstr must be an instruction }
  2266. if assigned(ainstr) and
  2267. (ainstr.typ<>ait_instruction) then
  2268. internalerror(200411011);
  2269. instr:=ainstr;
  2270. end;
  2271. constructor tai_regalloc.dealloc(r : tregister;ainstr:tai);
  2272. begin
  2273. inherited create;
  2274. typ:=ait_regalloc;
  2275. ratype:=ra_dealloc;
  2276. reg:=r;
  2277. { ainstr must be an instruction }
  2278. if assigned(ainstr) and
  2279. (ainstr.typ<>ait_instruction) then
  2280. internalerror(200411012);
  2281. instr:=ainstr;
  2282. end;
  2283. constructor tai_regalloc.sync(r : tregister);
  2284. begin
  2285. inherited create;
  2286. typ:=ait_regalloc;
  2287. ratype:=ra_sync;
  2288. reg:=r;
  2289. end;
  2290. constructor tai_regalloc.resize(r : tregister);
  2291. begin
  2292. inherited create;
  2293. typ:=ait_regalloc;
  2294. ratype:=ra_resize;
  2295. reg:=r;
  2296. end;
  2297. constructor tai_regalloc.markused(r : tregister);
  2298. begin
  2299. inherited create;
  2300. typ:=ait_regalloc;
  2301. ratype:=ra_markused;
  2302. reg:=r;
  2303. end;
  2304. constructor tai_regalloc.ppuload(t:taitype;ppufile:tcompilerppufile);
  2305. begin
  2306. inherited ppuload(t,ppufile);
  2307. ppufile.getdata(reg,sizeof(Tregister));
  2308. ratype:=tregalloctype(ppufile.getbyte);
  2309. keep:=ppufile.getboolean;
  2310. end;
  2311. procedure tai_regalloc.ppuwrite(ppufile:tcompilerppufile);
  2312. begin
  2313. inherited ppuwrite(ppufile);
  2314. ppufile.putdata(reg,sizeof(Tregister));
  2315. ppufile.putbyte(byte(ratype));
  2316. ppufile.putboolean(keep);
  2317. end;
  2318. {*****************************************************************************
  2319. TaiInstruction
  2320. *****************************************************************************}
  2321. constructor tai_cpu_abstract.Create(op : tasmop);
  2322. begin
  2323. inherited create;
  2324. typ:=ait_instruction;
  2325. is_jmp:=false;
  2326. opcode:=op;
  2327. ops:=0;
  2328. end;
  2329. destructor tai_cpu_abstract.Destroy;
  2330. var
  2331. i : integer;
  2332. begin
  2333. for i:=0 to opercnt-1 do
  2334. freeop(i);
  2335. inherited destroy;
  2336. end;
  2337. { ---------------------------------------------------------------------
  2338. Loading of operands.
  2339. ---------------------------------------------------------------------}
  2340. procedure tai_cpu_abstract.allocate_oper(opers:longint);
  2341. begin
  2342. while (opers>opercnt) do
  2343. begin
  2344. new(oper[opercnt]);
  2345. fillchar(oper[opercnt]^,sizeof(toper),0);
  2346. inc(opercnt);
  2347. end;
  2348. end;
  2349. procedure tai_cpu_abstract.loadconst(opidx:longint;l:tcgint);
  2350. begin
  2351. allocate_oper(opidx+1);
  2352. with oper[opidx]^ do
  2353. begin
  2354. if typ<>top_const then
  2355. clearop(opidx);
  2356. val:=l;
  2357. typ:=top_const;
  2358. end;
  2359. end;
  2360. procedure tai_cpu_abstract.loadsymbol(opidx:longint;s:tasmsymbol;sofs:longint);
  2361. var
  2362. r : treference;
  2363. begin
  2364. reference_reset_symbol(r,s,sofs,1,[]);
  2365. r.refaddr:=addr_full;
  2366. loadref(opidx,r);
  2367. end;
  2368. procedure tai_cpu_abstract.loadlocal(opidx:longint;s:pointer;sofs:longint;indexreg:tregister;scale:byte;getoffset,forceref:boolean);
  2369. begin
  2370. if not assigned(s) then
  2371. internalerror(200204251);
  2372. allocate_oper(opidx+1);
  2373. with oper[opidx]^ do
  2374. begin
  2375. if typ<>top_local then
  2376. begin
  2377. clearop(opidx);
  2378. new(localoper);
  2379. end;
  2380. with oper[opidx]^.localoper^ do
  2381. begin
  2382. localsym:=s;
  2383. localsymofs:=sofs;
  2384. localindexreg:=indexreg;
  2385. localscale:=scale;
  2386. localgetoffset:=getoffset;
  2387. localforceref:=forceref;
  2388. {$ifdef x86}
  2389. localsegment:=NR_NO;
  2390. {$endif x86}
  2391. end;
  2392. typ:=top_local;
  2393. end;
  2394. end;
  2395. procedure tai_cpu_abstract.loadref(opidx:longint;const r:treference);
  2396. {$ifdef x86}
  2397. var
  2398. si_param: ShortInt;
  2399. {$endif}
  2400. begin
  2401. allocate_oper(opidx+1);
  2402. with oper[opidx]^ do
  2403. begin
  2404. if typ<>top_ref then
  2405. begin
  2406. clearop(opidx);
  2407. new(ref);
  2408. end;
  2409. ref^:=r;
  2410. {$ifdef x86}
  2411. { We allow this exception for x86, since overloading this would be
  2412. too much of a a speed penalty}
  2413. if is_x86_parameterized_string_op(opcode) then
  2414. begin
  2415. si_param:=get_x86_string_op_si_param(opcode);
  2416. if (si_param<>-1) and (taicpu(self).OperandOrder=op_att) then
  2417. si_param:=x86_parameterized_string_op_param_count(opcode)-si_param-1;
  2418. if (si_param=opidx) and (ref^.segment<>NR_NO) and (ref^.segment<>NR_DS) then
  2419. segprefix:=ref^.segment;
  2420. end
  2421. else if (opcode=A_XLAT) and (ref^.segment<>NR_NO) and (ref^.segment<>NR_DS) then
  2422. segprefix:=ref^.segment
  2423. else if (ref^.segment<>NR_NO) and (ref^.segment<>get_default_segment_of_ref(ref^)) then
  2424. segprefix:=ref^.segment;
  2425. {$endif}
  2426. {$ifndef llvm}
  2427. if (cs_create_pic in current_settings.moduleswitches) and
  2428. assigned(r.symbol) and
  2429. not assigned(r.relsymbol) and
  2430. (r.refaddr=addr_no)
  2431. {$ifdef ARM}
  2432. and not(r.base=NR_R15)
  2433. {$endif ARM}
  2434. {$ifdef aarch64}
  2435. and not(r.refaddr in [addr_full,addr_gotpageoffset,addr_gotpage])
  2436. {$endif aarch64}
  2437. then
  2438. internalerror(200502052);
  2439. {$endif not llvm}
  2440. typ:=top_ref;
  2441. if assigned(add_reg_instruction_hook) then
  2442. begin
  2443. add_reg_instruction_hook(self,ref^.base);
  2444. add_reg_instruction_hook(self,ref^.index);
  2445. end;
  2446. { mark symbol as used }
  2447. if assigned(ref^.symbol) then
  2448. ref^.symbol.increfs;
  2449. if assigned(ref^.relsymbol) then
  2450. ref^.relsymbol.increfs;
  2451. end;
  2452. end;
  2453. procedure tai_cpu_abstract.loadreg(opidx:longint;r:tregister);
  2454. begin
  2455. allocate_oper(opidx+1);
  2456. with oper[opidx]^ do
  2457. begin
  2458. if typ<>top_reg then
  2459. clearop(opidx);
  2460. reg:=r;
  2461. typ:=top_reg;
  2462. end;
  2463. if assigned(add_reg_instruction_hook) then
  2464. add_reg_instruction_hook(self,r);
  2465. {$ifdef ARM}
  2466. { R15 is the PC on the ARM thus moves to R15 are jumps.
  2467. Due to speed considerations we don't use a virtual overridden method here.
  2468. Because the pc/r15 isn't handled by the reg. allocator this should never cause
  2469. problems with iregs getting r15.
  2470. }
  2471. is_jmp:=(opcode=A_MOV) and (opidx=0) and (r=NR_R15);
  2472. {$endif ARM}
  2473. end;
  2474. procedure tai_cpu_abstract.loadoper(opidx:longint;o:toper);
  2475. {$ifdef x86}
  2476. var
  2477. si_param: ShortInt;
  2478. {$endif x86}
  2479. begin
  2480. allocate_oper(opidx+1);
  2481. clearop(opidx);
  2482. oper[opidx]^:=o;
  2483. { copy also the reference }
  2484. with oper[opidx]^ do
  2485. begin
  2486. case typ of
  2487. top_reg:
  2488. begin
  2489. if assigned(add_reg_instruction_hook) then
  2490. add_reg_instruction_hook(self,reg);
  2491. end;
  2492. top_ref:
  2493. begin
  2494. new(ref);
  2495. ref^:=o.ref^;
  2496. {$ifdef x86}
  2497. { We allow this exception for x86, since overloading this would be
  2498. too much of a a speed penalty}
  2499. if is_x86_parameterized_string_op(opcode) then
  2500. begin
  2501. si_param:=get_x86_string_op_si_param(opcode);
  2502. if (si_param<>-1) and (taicpu(self).OperandOrder=op_att) then
  2503. si_param:=x86_parameterized_string_op_param_count(opcode)-si_param-1;
  2504. if (si_param=opidx) and (ref^.segment<>NR_NO) and (ref^.segment<>NR_DS) then
  2505. segprefix:=ref^.segment;
  2506. end
  2507. else if (opcode=A_XLAT) and (ref^.segment<>NR_NO) and (ref^.segment<>NR_DS) then
  2508. segprefix:=ref^.segment
  2509. else if (ref^.segment<>NR_NO) and (ref^.segment<>get_default_segment_of_ref(ref^)) then
  2510. segprefix:=ref^.segment;
  2511. {$endif x86}
  2512. if assigned(add_reg_instruction_hook) then
  2513. begin
  2514. add_reg_instruction_hook(self,ref^.base);
  2515. add_reg_instruction_hook(self,ref^.index);
  2516. end;
  2517. end;
  2518. {$ifdef ARM}
  2519. top_shifterop:
  2520. begin
  2521. new(shifterop);
  2522. shifterop^:=o.shifterop^;
  2523. if assigned(add_reg_instruction_hook) then
  2524. add_reg_instruction_hook(self,shifterop^.rs);
  2525. end;
  2526. {$endif ARM}
  2527. else
  2528. ;
  2529. end;
  2530. end;
  2531. end;
  2532. procedure tai_cpu_abstract.clearop(opidx:longint);
  2533. begin
  2534. with oper[opidx]^ do
  2535. begin
  2536. case typ of
  2537. top_ref:
  2538. dispose(ref);
  2539. top_local:
  2540. dispose(localoper);
  2541. {$ifdef ARM}
  2542. top_shifterop:
  2543. dispose(shifterop);
  2544. top_regset:
  2545. dispose(regset);
  2546. {$endif ARM}
  2547. {$ifdef jvm}
  2548. top_string:
  2549. freemem(pcval);
  2550. top_wstring:
  2551. donewidestring(pwstrval);
  2552. {$endif jvm}
  2553. else
  2554. ;
  2555. end;
  2556. typ:=top_none;
  2557. end;
  2558. end;
  2559. procedure tai_cpu_abstract.freeop(opidx:longint);
  2560. begin
  2561. clearop(opidx);
  2562. dispose(oper[opidx]);
  2563. end;
  2564. { ---------------------------------------------------------------------
  2565. Miscellaneous methods.
  2566. ---------------------------------------------------------------------}
  2567. procedure tai_cpu_abstract.SetCondition(const c:TAsmCond);
  2568. begin
  2569. condition:=c;
  2570. end;
  2571. Function tai_cpu_abstract.getcopy:TLinkedListItem;
  2572. var
  2573. i : longint;
  2574. p : tai_cpu_abstract;
  2575. begin
  2576. p:=tai_cpu_abstract(inherited getcopy);
  2577. { make a copy of the references }
  2578. p.opercnt:=0;
  2579. p.allocate_oper(ops);
  2580. for i:=0 to ops-1 do
  2581. begin
  2582. p.oper[i]^:=oper[i]^;
  2583. case oper[i]^.typ of
  2584. top_local :
  2585. begin
  2586. new(p.oper[i]^.localoper);
  2587. p.oper[i]^.localoper^:=oper[i]^.localoper^;
  2588. end;
  2589. top_ref :
  2590. begin
  2591. new(p.oper[i]^.ref);
  2592. p.oper[i]^.ref^:=oper[i]^.ref^;
  2593. end;
  2594. {$ifdef ARM}
  2595. top_shifterop:
  2596. begin
  2597. new(p.oper[i]^.shifterop);
  2598. p.oper[i]^.shifterop^:=oper[i]^.shifterop^;
  2599. end;
  2600. {$endif ARM}
  2601. else
  2602. ;
  2603. end;
  2604. end;
  2605. getcopy:=p;
  2606. end;
  2607. function tai_cpu_abstract.is_same_reg_move(regtype: Tregistertype):boolean;
  2608. begin
  2609. { When the generic RA is used this needs to be overridden, we don't use
  2610. virtual;abstract; to prevent a lot of warnings of unimplemented abstract methods
  2611. when tai_cpu is created (PFV) }
  2612. internalerror(2004040901);
  2613. result:=false;
  2614. end;
  2615. function tai_cpu_abstract.spilling_get_operation_type(opnr: longint): topertype;
  2616. begin
  2617. internalerror(2004040902);
  2618. result:=operand_readwrite;
  2619. end;
  2620. function tai_cpu_abstract.spilling_get_operation_type_ref(opnr: longint; reg: tregister): topertype;
  2621. begin
  2622. result := operand_read;
  2623. end;
  2624. constructor tai_cpu_abstract.ppuload(t:taitype;ppufile:tcompilerppufile);
  2625. var
  2626. i : integer;
  2627. begin
  2628. inherited ppuload(t,ppufile);
  2629. { hopefully, we don't get problems with big/little endian here when cross compiling :/ }
  2630. ppufile.getdata(condition,sizeof(tasmcond));
  2631. ops := ppufile.getbyte;
  2632. allocate_oper(ops);
  2633. for i:=0 to ops-1 do
  2634. ppuloadoper(ppufile,oper[i]^);
  2635. opcode:=tasmop(ppufile.getword);
  2636. {$ifdef x86}
  2637. ppufile.getdata(segprefix,sizeof(Tregister));
  2638. {$endif x86}
  2639. is_jmp:=ppufile.getboolean;
  2640. end;
  2641. procedure tai_cpu_abstract.ppuwrite(ppufile:tcompilerppufile);
  2642. var
  2643. i : integer;
  2644. begin
  2645. inherited ppuwrite(ppufile);
  2646. ppufile.putdata(condition,sizeof(tasmcond));
  2647. ppufile.putbyte(ops);
  2648. for i:=0 to ops-1 do
  2649. ppuwriteoper(ppufile,oper[i]^);
  2650. ppufile.putword(word(opcode));
  2651. {$ifdef x86}
  2652. ppufile.putdata(segprefix,sizeof(Tregister));
  2653. {$endif x86}
  2654. ppufile.putboolean(is_jmp);
  2655. end;
  2656. procedure tai_cpu_abstract.buildderefimpl;
  2657. var
  2658. i : integer;
  2659. begin
  2660. for i:=0 to ops-1 do
  2661. ppubuildderefimploper(oper[i]^);
  2662. end;
  2663. procedure tai_cpu_abstract.derefimpl;
  2664. var
  2665. i : integer;
  2666. begin
  2667. for i:=0 to ops-1 do
  2668. ppuderefoper(oper[i]^);
  2669. end;
  2670. procedure tai_cpu_abstract.resetpass1;
  2671. begin
  2672. end;
  2673. procedure tai_cpu_abstract.resetpass2;
  2674. begin
  2675. end;
  2676. function tai_cpu_abstract.Pass1(objdata:TObjData):longint;
  2677. begin
  2678. result:=0;
  2679. end;
  2680. procedure tai_cpu_abstract.Pass2(objdata:TObjData);
  2681. begin
  2682. end;
  2683. procedure tai_cpu_abstract.ppuloadoper(ppufile:tcompilerppufile;var o:toper);
  2684. begin
  2685. o.typ:=toptype(ppufile.getbyte);
  2686. o.ot:=ppufile.getlongint;
  2687. case o.typ of
  2688. top_reg :
  2689. ppufile.getdata(o.reg,sizeof(Tregister));
  2690. top_ref :
  2691. begin
  2692. new(o.ref);
  2693. {$ifdef x86}
  2694. ppufile.getdata(o.ref^.segment,sizeof(Tregister));
  2695. {$endif x86}
  2696. ppufile.getdata(o.ref^.base,sizeof(Tregister));
  2697. ppufile.getdata(o.ref^.index,sizeof(Tregister));
  2698. ppufile.getdata(o.ref^.refaddr,sizeof(o.ref^.refaddr));
  2699. o.ref^.scalefactor:=ppufile.getbyte;
  2700. o.ref^.offset:=ppufile.getaint;
  2701. o.ref^.symbol:=ppufile.getasmsymbol;
  2702. o.ref^.relsymbol:=ppufile.getasmsymbol;
  2703. end;
  2704. top_const :
  2705. o.val:=ppufile.getaint;
  2706. top_local :
  2707. begin
  2708. new(o.localoper);
  2709. with o.localoper^ do
  2710. begin
  2711. ppufile.getderef(localsymderef);
  2712. localsymofs:=ppufile.getaint;
  2713. {$ifdef x86}
  2714. localsegment:=tregister(ppufile.getlongint);
  2715. {$endif x86}
  2716. localindexreg:=tregister(ppufile.getlongint);
  2717. localscale:=ppufile.getbyte;
  2718. localgetoffset:=(ppufile.getbyte<>0);
  2719. end;
  2720. end;
  2721. else
  2722. internalerror(2007010210);
  2723. end;
  2724. end;
  2725. procedure tai_cpu_abstract.ppuwriteoper(ppufile:tcompilerppufile;const o:toper);
  2726. begin
  2727. ppufile.putbyte(byte(o.typ));
  2728. ppufile.putlongint(o.ot);
  2729. case o.typ of
  2730. top_reg :
  2731. ppufile.putdata(o.reg,sizeof(Tregister));
  2732. top_ref :
  2733. begin
  2734. {$ifdef x86}
  2735. ppufile.putdata(o.ref^.segment,sizeof(Tregister));
  2736. {$endif x86}
  2737. ppufile.putdata(o.ref^.base,sizeof(Tregister));
  2738. ppufile.putdata(o.ref^.index,sizeof(Tregister));
  2739. ppufile.putdata(o.ref^.refaddr,sizeof(o.ref^.refaddr));
  2740. ppufile.putbyte(o.ref^.scalefactor);
  2741. ppufile.putaint(o.ref^.offset);
  2742. ppufile.putasmsymbol(o.ref^.symbol);
  2743. ppufile.putasmsymbol(o.ref^.relsymbol);
  2744. end;
  2745. top_const :
  2746. ppufile.putaint(o.val);
  2747. top_local :
  2748. begin
  2749. with o.localoper^ do
  2750. begin
  2751. ppufile.putderef(localsymderef);
  2752. ppufile.putaint(localsymofs);
  2753. {$ifdef x86}
  2754. ppufile.putlongint(longint(localsegment));
  2755. {$endif x86}
  2756. ppufile.putlongint(longint(localindexreg));
  2757. ppufile.putbyte(localscale);
  2758. ppufile.putbyte(byte(localgetoffset));
  2759. end;
  2760. end;
  2761. else
  2762. internalerror(2007010211);
  2763. end;
  2764. end;
  2765. {****************************************************************************
  2766. tai_align_abstract
  2767. ****************************************************************************}
  2768. constructor tai_align_abstract.Create(b: byte);
  2769. begin
  2770. inherited Create;
  2771. typ:=ait_align;
  2772. {$ifdef EXTDEBUG}
  2773. if upper(classname)='TAI_ALIGN_ABSTRACT' then
  2774. internalerror(200709191);
  2775. {$endif EXTDEBUG}
  2776. if b in [1,2,4,8,16,32,64] then
  2777. aligntype := b
  2778. else
  2779. aligntype := 1;
  2780. fillsize:=0;
  2781. fillop:=0;
  2782. use_op:=false;
  2783. maxbytes:=aligntype;
  2784. end;
  2785. constructor tai_align_abstract.Create_op(b: byte; _op: byte);
  2786. begin
  2787. inherited Create;
  2788. typ:=ait_align;
  2789. if b in [1,2,4,8,16,32] then
  2790. aligntype := b
  2791. else
  2792. aligntype := 1;
  2793. fillsize:=0;
  2794. fillop:=_op;
  2795. use_op:=true;
  2796. maxbytes:=aligntype;
  2797. end;
  2798. constructor tai_align_abstract.create_max(b : byte; max : byte);
  2799. begin
  2800. inherited Create;
  2801. typ:=ait_align;
  2802. if b in [1,2,4,8,16,32] then
  2803. aligntype := b
  2804. else
  2805. aligntype := 1;
  2806. maxbytes:=max;
  2807. fillsize:=0;
  2808. fillop:=0;
  2809. use_op:=false;
  2810. end;
  2811. constructor tai_align_abstract.Create_zeros(b: byte);
  2812. begin
  2813. inherited Create;
  2814. typ:=ait_align;
  2815. if b in [1,2,4,8,16,32] then
  2816. aligntype := b
  2817. else
  2818. aligntype := 1;
  2819. use_op:=true;
  2820. fillsize:=0;
  2821. fillop:=0;
  2822. maxbytes:=aligntype;
  2823. end;
  2824. function tai_align_abstract.calculatefillbuf(var buf : tfillbuffer;executable : boolean):pchar;
  2825. begin
  2826. if fillsize>sizeof(buf) then
  2827. internalerror(200404293);
  2828. fillchar(buf,high(buf),fillop);
  2829. calculatefillbuf:=pchar(@buf);
  2830. end;
  2831. constructor tai_align_abstract.ppuload(t:taitype;ppufile:tcompilerppufile);
  2832. begin
  2833. inherited ppuload(t,ppufile);
  2834. aligntype:=ppufile.getbyte;
  2835. fillsize:=0;
  2836. fillop:=ppufile.getbyte;
  2837. use_op:=ppufile.getboolean;
  2838. maxbytes:=ppufile.getbyte;
  2839. end;
  2840. procedure tai_align_abstract.ppuwrite(ppufile:tcompilerppufile);
  2841. begin
  2842. inherited ppuwrite(ppufile);
  2843. ppufile.putbyte(aligntype);
  2844. ppufile.putbyte(fillop);
  2845. ppufile.putboolean(use_op);
  2846. ppufile.putbyte(maxbytes);
  2847. end;
  2848. {****************************************************************************
  2849. tai_seh_directive
  2850. ****************************************************************************}
  2851. const
  2852. datatypemap: array[TAsmSehDirective] of TSehDirectiveDatatype=(
  2853. sd_string, { proc }
  2854. sd_none, { endproc }
  2855. sd_none, { endprologue }
  2856. sd_string, { handler }
  2857. sd_none, { handlerdata }
  2858. sd_none,sd_none,sd_none, { eh, 32, no32 }
  2859. sd_regoffset, { setframe }
  2860. sd_offset, { stackalloc }
  2861. sd_reg, { pushreg }
  2862. sd_regoffset, { savereg }
  2863. sd_regoffset, { savexmm }
  2864. sd_none, { pushframe }
  2865. sd_reg, { pushnv }
  2866. sd_none { savenv }
  2867. );
  2868. constructor tai_seh_directive.create(_kind:TAsmSehDirective);
  2869. begin
  2870. inherited Create;
  2871. typ:=ait_seh_directive;
  2872. kind:=_kind;
  2873. data.typ:=datatypemap[_kind];
  2874. end;
  2875. constructor tai_seh_directive.create_name(_kind:TAsmSehDirective;const _name:string);
  2876. begin
  2877. create(_kind);
  2878. data.name:=stringdup(_name);
  2879. end;
  2880. constructor tai_seh_directive.create_reg(_kind:TAsmSehDirective;r:TRegister);
  2881. begin
  2882. create(_kind);
  2883. data.reg:=r;
  2884. end;
  2885. constructor tai_seh_directive.create_offset(_kind:TAsmSehDirective;ofs:dword);
  2886. begin
  2887. create(_kind);
  2888. data.offset:=ofs;
  2889. end;
  2890. constructor tai_seh_directive.create_reg_offset(_kind:TAsmSehDirective;
  2891. r:TRegister;ofs:dword);
  2892. begin
  2893. create(_kind);
  2894. data.offset:=ofs;
  2895. data.reg:=r;
  2896. end;
  2897. constructor tai_seh_directive.ppuload(t:taitype;ppufile:tcompilerppufile);
  2898. begin
  2899. inherited ppuload(t, ppufile);
  2900. kind:=TAsmSehDirective(ppufile.getbyte);
  2901. data.typ:=datatypemap[kind];
  2902. case data.typ of
  2903. sd_none: ;
  2904. sd_string:
  2905. begin
  2906. data.name:=ppufile.getpshortstring;
  2907. data.flags:=ppufile.getbyte;
  2908. end;
  2909. sd_reg,sd_offset,sd_regoffset:
  2910. begin
  2911. ppufile.getdata(data.reg,sizeof(TRegister));
  2912. data.offset:=ppufile.getdword;
  2913. end;
  2914. end;
  2915. end;
  2916. destructor tai_seh_directive.destroy;
  2917. begin
  2918. if data.typ=sd_string then
  2919. stringdispose(data.name);
  2920. inherited destroy;
  2921. end;
  2922. procedure tai_seh_directive.ppuwrite(ppufile:tcompilerppufile);
  2923. begin
  2924. inherited ppuwrite(ppufile);
  2925. ppufile.putbyte(ord(kind));
  2926. case data.typ of
  2927. sd_none: ;
  2928. sd_string:
  2929. begin
  2930. ppufile.putstring(data.name^);
  2931. ppufile.putbyte(data.flags);
  2932. end;
  2933. sd_reg,sd_offset,sd_regoffset:
  2934. begin
  2935. ppufile.putdata(data.reg,sizeof(TRegister));
  2936. ppufile.putdword(data.offset);
  2937. end;
  2938. end;
  2939. end;
  2940. procedure tai_seh_directive.generate_code(objdata:TObjData);
  2941. begin
  2942. end;
  2943. {****************************************************************************
  2944. tai_eabi_attribute
  2945. ****************************************************************************}
  2946. constructor tai_eabi_attribute.create(atag,avalue : dword);
  2947. begin
  2948. inherited Create;
  2949. typ:=ait_eabi_attribute;
  2950. eattr_typ:=eattrtype_dword;
  2951. tag:=atag;
  2952. value:=avalue;
  2953. end;
  2954. constructor tai_eabi_attribute.create(atag: dword; const avalue: string);
  2955. begin
  2956. inherited Create;
  2957. typ:=ait_eabi_attribute;
  2958. eattr_typ:=eattrtype_ntbs;
  2959. tag:=atag;
  2960. valuestr:=NewStr(avalue);
  2961. end;
  2962. destructor tai_eabi_attribute.destroy;
  2963. begin
  2964. Inherited Destroy;
  2965. end;
  2966. constructor tai_eabi_attribute.ppuload(t:taitype;ppufile:tcompilerppufile);
  2967. begin
  2968. end;
  2969. procedure tai_eabi_attribute.ppuwrite(ppufile:tcompilerppufile);
  2970. begin
  2971. inherited ppuwrite(ppufile);
  2972. ppufile.putdword(tag);
  2973. ppufile.putdword(value);
  2974. end;
  2975. {$ifdef JVM}
  2976. {****************************************************************************
  2977. tai_jvar
  2978. ****************************************************************************}
  2979. constructor tai_jvar.Create(_stackslot: longint; const _desc: shortstring; _startlab, _stoplab: TAsmSymbol);
  2980. begin
  2981. Inherited create;
  2982. typ:=ait_jvar;
  2983. stackslot:=_stackslot;
  2984. desc:=stringdup(_desc);
  2985. startlab:=_startlab;
  2986. stoplab:=_stoplab;
  2987. end;
  2988. constructor tai_jvar.ppuload(t: taitype; ppufile: tcompilerppufile);
  2989. begin
  2990. inherited ppuload(t, ppufile);
  2991. stackslot:=ppufile.getlongint;
  2992. desc:=ppufile.getpshortstring;
  2993. startlab:=ppufile.getasmsymbol;
  2994. stoplab:=ppufile.getasmsymbol;
  2995. end;
  2996. procedure tai_jvar.ppuwrite(ppufile: tcompilerppufile);
  2997. begin
  2998. inherited ppuwrite(ppufile);
  2999. ppufile.putlongint(stackslot);
  3000. ppufile.putstring(desc^);
  3001. ppufile.putasmsymbol(startlab);
  3002. ppufile.putasmsymbol(stoplab);
  3003. end;
  3004. destructor tai_jvar.destroy;
  3005. begin
  3006. stringdispose(desc);
  3007. inherited destroy;
  3008. end;
  3009. {****************************************************************************
  3010. tai_jcatch
  3011. ****************************************************************************}
  3012. constructor tai_jcatch.Create(const _name: shortstring; _startlab, _stoplab, _handlerlab: TAsmSymbol);
  3013. begin
  3014. Inherited create;
  3015. typ:=ait_jcatch;
  3016. name:=stringdup(_name);
  3017. startlab:=_startlab;
  3018. startlab.increfs;
  3019. stoplab:=_stoplab;
  3020. stoplab.increfs;
  3021. handlerlab:=_handlerlab;
  3022. handlerlab.increfs;
  3023. end;
  3024. destructor tai_jcatch.destroy;
  3025. begin
  3026. stringdispose(name);
  3027. inherited destroy;
  3028. end;
  3029. constructor tai_jcatch.ppuload(t: taitype; ppufile: tcompilerppufile);
  3030. begin
  3031. inherited ppuload(t, ppufile);
  3032. name:=ppufile.getpshortstring;
  3033. startlab:=ppufile.getasmsymbol;
  3034. startlab.increfs;
  3035. stoplab:=ppufile.getasmsymbol;
  3036. stoplab.increfs;
  3037. handlerlab:=ppufile.getasmsymbol;
  3038. handlerlab.increfs;
  3039. end;
  3040. procedure tai_jcatch.ppuwrite(ppufile: tcompilerppufile);
  3041. begin
  3042. inherited ppuwrite(ppufile);
  3043. ppufile.putstring(name^);
  3044. ppufile.putasmsymbol(startlab);
  3045. ppufile.putasmsymbol(stoplab);
  3046. ppufile.putasmsymbol(handlerlab);
  3047. end;
  3048. {$endif JVM}
  3049. begin
  3050. {$push}{$warnings off}
  3051. { taitype should fit into a 4 byte set for speed reasons }
  3052. if ord(high(taitype))>31 then
  3053. internalerror(201108181);
  3054. {$pop}
  3055. end.