aasmtai.pas 107 KB

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