aasmtai.pas 100 KB

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