aasmtai.pas 81 KB

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