aasmtai.pas 103 KB

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