aasmtai.pas 107 KB

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