aasmtai.pas 104 KB

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