aasmtai.pas 98 KB

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