aasmtai.pas 100 KB

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