aasmtai.pas 88 KB

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