aasmtai.pas 103 KB

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