aasmtai.pas 98 KB

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