aasmtai.pas 83 KB

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