aasmtai.pas 89 KB

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