aasmtai.pas 93 KB

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