aasmtai.pas 104 KB

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