aasmtai.pas 93 KB

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