aasmtai.pas 107 KB

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