aasmtai.pas 100 KB

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