aasmtai.pas 85 KB

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