aasmtai.pas 100 KB

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