aasmtai.pas 102 KB

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