aasmtai.pas 106 KB

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