aasmtai.pas 99 KB

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