2
0

aasmtai.pas 100 KB

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