aasmtai.pas 99 KB

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