aasmtai.pas 99 KB

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