aasmtai.pas 107 KB

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