aasmtai.pas 100 KB

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