aasmtai.pas 100 KB

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