aasmtai.pas 99 KB

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