aasmtai.pas 88 KB

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