aasmtai.pas 98 KB

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