2
0

aasmtai.pas 106 KB

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