aasmtai.pas 88 KB

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