aasmtai.pas 99 KB

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