aasmtai.pas 107 KB

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