aasmtai.pas 92 KB

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