aasmtai.pas 104 KB

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