aasmtai.pas 107 KB

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