aasmtai.pas 98 KB

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