aasmtai.pas 88 KB

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