aasmtai.pas 103 KB

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