aasmtai.pas 104 KB

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