aasmtai.pas 105 KB

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