aasmtai.pas 93 KB

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