aasmtai.pas 83 KB

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