aasmtai.pas 107 KB

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