aasmtai.pas 107 KB

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