aasmtai.pas 82 KB

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