aasmtai.pas 105 KB

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