aasmtai.pas 93 KB

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