aasmtai.pas 100 KB

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