aasmtai.pas 83 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856
  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. cgbase,cgutils,
  30. symtype,
  31. aasmbase,aasmdata,ogbase
  32. {$ifdef jvm}
  33. ,widestr
  34. {$endif jvm}
  35. ;
  36. type
  37. { keep the number of elements in this enumeration less or equal than 32 as long
  38. as FPC knows only 4 byte and 32 byte sets (FK) }
  39. taitype = (
  40. ait_none,
  41. ait_align,
  42. ait_section,
  43. ait_comment,
  44. ait_string,
  45. ait_instruction,
  46. ait_datablock,
  47. ait_symbol,
  48. { needed to calc the size of a symbol }
  49. ait_symbol_end,
  50. ait_directive,
  51. ait_label,
  52. ait_const,
  53. ait_real_32bit,
  54. ait_real_64bit,
  55. ait_real_80bit,
  56. ait_comp_64bit,
  57. ait_real_128bit,
  58. ait_stab,
  59. ait_force_line,
  60. ait_function_name,
  61. { Used for .ent .end pair used for .dpr section in MIPS
  62. and probably also for Alpha }
  63. ait_ent,
  64. ait_ent_end,
  65. {$ifdef alpha}
  66. { the follow is for the DEC Alpha }
  67. ait_frame,
  68. {$endif alpha}
  69. {$ifdef ia64}
  70. ait_bundle,
  71. ait_stop,
  72. {$endif ia64}
  73. {$ifdef m68k}
  74. ait_labeled_instruction,
  75. {$endif m68k}
  76. {$ifdef arm}
  77. ait_thumb_func,
  78. {$endif arm}
  79. { used to split into tiny assembler files }
  80. ait_cutobject,
  81. ait_regalloc,
  82. ait_tempalloc,
  83. { used to mark assembler blocks and inlined functions }
  84. ait_marker,
  85. { used to describe a new location of a variable }
  86. ait_varloc,
  87. { SEH directives used in ARM,MIPS and x86_64 COFF targets }
  88. ait_seh_directive,
  89. { JVM only }
  90. ait_jvar, { debug information for a local variable }
  91. ait_jcatch { exception catch clause }
  92. );
  93. taiconst_type = (
  94. aitconst_128bit,
  95. aitconst_64bit,
  96. aitconst_32bit,
  97. aitconst_16bit,
  98. aitconst_8bit,
  99. aitconst_sleb128bit,
  100. aitconst_uleb128bit,
  101. { win32 only }
  102. aitconst_rva_symbol,
  103. aitconst_secrel32_symbol,
  104. { darwin only }
  105. { From gcc/config/darwin.c (darwin_asm_output_dwarf_delta):
  106. ***
  107. Output a difference of two labels that will be an assembly time
  108. constant if the two labels are local. (.long lab1-lab2 will be
  109. very different if lab1 is at the boundary between two sections; it
  110. will be relocated according to the second section, not the first,
  111. so one ends up with a difference between labels in different
  112. sections, which is bad in the dwarf2 eh context for instance.)
  113. ***
  114. We cannot use this everywhere, because older versions of the
  115. darwin assembler don't support the construct used for these
  116. relsyms (nor do they support dwarf, for that matter)
  117. }
  118. aitconst_darwin_dwarf_delta64,
  119. aitconst_darwin_dwarf_delta32,
  120. { ARM Thumb-2 only }
  121. aitconst_half16bit { used for table jumps. The actual value is the 16bit value shifted left once }
  122. );
  123. const
  124. {$ifdef cpu64bitaddr}
  125. aitconst_ptr = aitconst_64bit;
  126. {$else cpu64bitaddr}
  127. aitconst_ptr = aitconst_32bit;
  128. {$endif cpu64bitaddr}
  129. {$ifdef cpu64bitalu}
  130. aitconst_aint = aitconst_64bit;
  131. {$else cpu64bitaddr}
  132. aitconst_aint = aitconst_32bit;
  133. {$endif cpu64bitaddr}
  134. taitypestr : array[taitype] of string[24] = (
  135. '<none>',
  136. 'align',
  137. 'section',
  138. 'comment',
  139. 'string',
  140. 'instruction',
  141. 'datablock',
  142. 'symbol',
  143. 'symbol_end',
  144. 'symbol_directive',
  145. 'label',
  146. 'const',
  147. 'real_32bit',
  148. 'real_64bit',
  149. 'real_80bit',
  150. 'comp_64bit',
  151. 'real_128bit',
  152. 'stab',
  153. 'force_line',
  154. 'function_name',
  155. 'ent',
  156. 'ent_end',
  157. {$ifdef alpha}
  158. { the follow is for the DEC Alpha }
  159. 'frame',
  160. {$endif alpha}
  161. {$ifdef ia64}
  162. 'bundle',
  163. 'stop',
  164. {$endif ia64}
  165. {$ifdef m68k}
  166. 'labeled_instr',
  167. {$endif m68k}
  168. {$ifdef arm}
  169. 'thumb_func',
  170. {$endif arm}
  171. 'cut',
  172. 'regalloc',
  173. 'tempalloc',
  174. 'marker',
  175. 'varloc',
  176. 'seh_directive',
  177. 'jvar',
  178. 'jcatch'
  179. );
  180. type
  181. { Types of operand }
  182. toptype=(top_none,top_reg,top_ref,top_const,top_bool,top_local
  183. {$ifdef arm}
  184. { ARM only }
  185. ,top_regset
  186. ,top_shifterop
  187. ,top_conditioncode
  188. ,top_modeflags
  189. {$endif arm}
  190. {$ifdef m68k}
  191. { m68k only }
  192. ,top_regset
  193. {$endif m68k}
  194. {$ifdef jvm}
  195. { jvm only}
  196. ,top_single
  197. ,top_double
  198. ,top_string
  199. ,top_wstring
  200. {$endif jvm}
  201. );
  202. { kinds of operations that an instruction can perform on an operand }
  203. topertype = (operand_read,operand_write,operand_readwrite);
  204. tlocaloper = record
  205. localsym : pointer;
  206. localsymderef : tderef;
  207. localsymofs : longint;
  208. localindexreg : tregister;
  209. localscale : byte;
  210. localgetoffset,
  211. localforceref : boolean
  212. end;
  213. plocaloper = ^tlocaloper;
  214. { please keep the size of this record <=12 bytes and keep it properly aligned }
  215. toper = record
  216. ot : longint;
  217. case typ : toptype of
  218. top_none : ();
  219. top_reg : (reg:tregister);
  220. top_ref : (ref:preference);
  221. top_const : (val:tcgint);
  222. top_bool : (b:boolean);
  223. { local varsym that will be inserted in pass_generate_code }
  224. top_local : (localoper:plocaloper);
  225. {$ifdef arm}
  226. top_regset : (regset:^tcpuregisterset; regtyp: tregistertype; subreg: tsubregister);
  227. top_shifterop : (shifterop : pshifterop);
  228. top_conditioncode : (cc : TAsmCond);
  229. top_modeflags : (modeflags : tcpumodeflags);
  230. {$endif arm}
  231. {$ifdef m68k}
  232. top_regset : (regset:^tcpuregisterset);
  233. {$endif m68k}
  234. {$ifdef jvm}
  235. top_single : (sval:single);
  236. top_double : (dval:double);
  237. top_string : (pcvallen: aint; pcval: pchar);
  238. top_wstring : (pwstrval: pcompilerwidestring);
  239. {$endif jvm}
  240. end;
  241. poper=^toper;
  242. const
  243. { ait_* types which don't result in executable code or which don't influence
  244. the way the program runs/behaves, but which may be encountered by the
  245. optimizer (= if it's sometimes added to the exprasm list). Update if you add
  246. a new ait type! }
  247. SkipInstr = [ait_comment, ait_symbol,ait_section
  248. ,ait_stab, ait_function_name, ait_force_line
  249. ,ait_regalloc, ait_tempalloc, ait_symbol_end
  250. ,ait_ent, ait_ent_end, ait_directive
  251. ,ait_varloc,ait_seh_directive
  252. ,ait_jvar, ait_jcatch];
  253. { ait_* types which do not have line information (and hence which are of type
  254. tai, otherwise, they are of type tailineinfo }
  255. SkipLineInfo =[ait_label,
  256. ait_regalloc,ait_tempalloc,
  257. ait_stab,ait_function_name,
  258. ait_cutobject,ait_marker,ait_varloc,ait_align,ait_section,ait_comment,
  259. ait_const,ait_directive,
  260. ait_ent, ait_ent_end,
  261. {$ifdef arm}
  262. ait_thumb_func,
  263. {$endif arm}
  264. ait_real_32bit,ait_real_64bit,ait_real_80bit,ait_comp_64bit,ait_real_128bit,
  265. ait_symbol,
  266. ait_seh_directive,
  267. ait_jvar,ait_jcatch
  268. ];
  269. type
  270. { cut type, required for alphanumeric ordering of the assembler filenames }
  271. TCutPlace=(cut_normal,cut_begin,cut_end);
  272. TAsmMarker = (
  273. mark_NoPropInfoStart,mark_NoPropInfoEnd,
  274. mark_AsmBlockStart,mark_AsmBlockEnd,
  275. mark_NoLineInfoStart,mark_NoLineInfoEnd,mark_BlockStart,
  276. mark_Position
  277. );
  278. TRegAllocType = (ra_alloc,ra_dealloc,ra_sync,ra_resize);
  279. TStabType = (stab_stabs,stab_stabn,stab_stabd,
  280. { AIX/XCOFF stab types }
  281. stab_stabx,
  282. { begin/end include file }
  283. stabx_bi,stabx_ei,
  284. { begin/end function }
  285. stabx_bf, stabx_ef,
  286. { begin/end static data block }
  287. stabx_bs, stabx_es,
  288. { line spec, function start/end label }
  289. stabx_line, stabx_function);
  290. TAsmDirective=(
  291. asd_indirect_symbol,
  292. asd_extern,asd_nasm_import, asd_toc_entry,
  293. asd_reference,asd_no_dead_strip,asd_weak_reference,asd_lazy_reference,
  294. asd_weak_definition,
  295. { for Jasmin }
  296. asd_jclass,asd_jinterface,asd_jsuper,asd_jfield,asd_jlimit,asd_jline
  297. );
  298. TAsmSehDirective=(
  299. ash_proc,ash_endproc,
  300. ash_endprologue,ash_handler,ash_handlerdata,
  301. ash_eh,ash_32,ash_no32,
  302. ash_setframe,ash_stackalloc,ash_pushreg,
  303. ash_savereg,ash_savexmm,ash_pushframe
  304. );
  305. const
  306. regallocstr : array[tregalloctype] of string[10]=('allocated','released','sync','resized');
  307. tempallocstr : array[boolean] of string[10]=('released','allocated');
  308. stabtypestr : array[TStabType] of string[8]=(
  309. 'stabs','stabn','stabd',
  310. 'stabx',
  311. 'bi','ei',
  312. 'bf','ef',
  313. 'bs','es',
  314. 'line','function');
  315. directivestr : array[TAsmDirective] of string[23]=(
  316. 'indirect_symbol',
  317. 'extern','nasm_import', 'tc', 'reference',
  318. 'no_dead_strip','weak_reference','lazy_reference','weak_definition',
  319. { for Jasmin }
  320. 'class','interface','super','field','limit','line'
  321. );
  322. sehdirectivestr : array[TAsmSehDirective] of string[16]=(
  323. '.seh_proc','.seh_endproc',
  324. '.seh_endprologue','.seh_handler','.seh_handlerdata',
  325. '.seh_eh','.seh_32','seh_no32',
  326. '.seh_setframe','.seh_stackalloc','.seh_pushreg',
  327. '.seh_savereg','.seh_savexmm','.seh_pushframe'
  328. );
  329. type
  330. { abstract assembler item }
  331. tai = class(TLinkedListItem)
  332. {$ifndef NOOPT}
  333. { pointer to record with optimizer info about this tai object }
  334. optinfo : pointer;
  335. {$endif NOOPT}
  336. typ : taitype;
  337. constructor Create;
  338. constructor ppuload(t:taitype;ppufile:tcompilerppufile);virtual;
  339. procedure ppuwrite(ppufile:tcompilerppufile);virtual;
  340. procedure buildderefimpl;virtual;
  341. procedure derefimpl;virtual;
  342. end;
  343. { abstract assembler item with line information }
  344. tailineinfo = class(tai)
  345. fileinfo : tfileposinfo;
  346. constructor Create;
  347. constructor ppuload(t:taitype;ppufile:tcompilerppufile);override;
  348. procedure ppuwrite(ppufile:tcompilerppufile);override;
  349. end;
  350. tai_simple = class(tai)
  351. constructor create(_typ : taitype);
  352. end;
  353. taiclass = class of tai;
  354. taiclassarray = array[taitype] of taiclass;
  355. { Generates an assembler string }
  356. tai_string = class(tailineinfo)
  357. str : pchar;
  358. { extra len so the string can contain an \0 }
  359. len : longint;
  360. constructor Create(const _str : string);
  361. constructor Create_pchar(_str : pchar;length : longint);
  362. destructor Destroy;override;
  363. constructor ppuload(t:taitype;ppufile:tcompilerppufile);override;
  364. procedure ppuwrite(ppufile:tcompilerppufile);override;
  365. function getcopy:tlinkedlistitem;override;
  366. end;
  367. { Generates a common label }
  368. tai_symbol = class(tai)
  369. sym : tasmsymbol;
  370. value : puint;
  371. size : longint;
  372. is_global,
  373. has_value : boolean;
  374. constructor Create(_sym:tasmsymbol;siz:longint);
  375. constructor Create_Global(_sym:tasmsymbol;siz:longint);
  376. constructor Createname(const _name : string;_symtyp:Tasmsymtype;siz:longint);
  377. constructor Createname_global(const _name : string;_symtyp:Tasmsymtype;siz:longint);
  378. constructor Createname_global_value(const _name : string;_symtyp:Tasmsymtype;siz:longint;val:ptruint);
  379. constructor ppuload(t:taitype;ppufile:tcompilerppufile);override;
  380. procedure ppuwrite(ppufile:tcompilerppufile);override;
  381. procedure derefimpl;override;
  382. end;
  383. tai_symbol_end = class(tailineinfo)
  384. sym : tasmsymbol;
  385. constructor Create(_sym:tasmsymbol);
  386. constructor Createname(const _name : string);
  387. constructor ppuload(t:taitype;ppufile:tcompilerppufile);override;
  388. procedure ppuwrite(ppufile:tcompilerppufile);override;
  389. procedure derefimpl;override;
  390. end;
  391. tai_ent = class(tai)
  392. Name : string;
  393. Constructor Create (const ProcName : String);
  394. end;
  395. tai_ent_end = class(tai)
  396. Name : string;
  397. Constructor Create (const ProcName : String);
  398. end;
  399. tai_directive = class(tailineinfo)
  400. name : ansistring;
  401. directive : TAsmDirective;
  402. constructor Create(_directive:TAsmDirective;const _name:ansistring);
  403. constructor ppuload(t:taitype;ppufile:tcompilerppufile);override;
  404. procedure ppuwrite(ppufile:tcompilerppufile);override;
  405. end;
  406. { Generates an assembler label }
  407. tai_label = class(tai)
  408. is_global : boolean;
  409. labsym : tasmlabel;
  410. constructor Create(_labsym : tasmlabel);
  411. constructor ppuload(t:taitype;ppufile:tcompilerppufile);override;
  412. procedure ppuwrite(ppufile:tcompilerppufile);override;
  413. procedure derefimpl;override;
  414. end;
  415. { Generates an assembler comment }
  416. tai_comment = class(tai)
  417. str : pchar;
  418. constructor Create(_str : pchar);
  419. destructor Destroy; override;
  420. constructor ppuload(t:taitype;ppufile:tcompilerppufile);override;
  421. procedure ppuwrite(ppufile:tcompilerppufile);override;
  422. function getcopy:tlinkedlistitem;override;
  423. end;
  424. { Generates a section / segment directive }
  425. tai_section = class(tai)
  426. sectype : TAsmSectiontype;
  427. secorder : TasmSectionorder;
  428. secalign : byte;
  429. name : pshortstring;
  430. sec : TObjSection; { used in binary writer }
  431. destructor Destroy;override;
  432. constructor ppuload(t:taitype;ppufile:tcompilerppufile);override;
  433. procedure ppuwrite(ppufile:tcompilerppufile);override;
  434. {$push}{$warnings off}
  435. private
  436. { this constructor is made private on purpose }
  437. { because sections should be created via new_section() }
  438. constructor Create(Asectype:TAsmSectiontype;const Aname:string;Aalign:byte;Asecorder:TasmSectionorder=secorder_default);
  439. {$pop}
  440. end;
  441. { Generates an uninitializised data block }
  442. tai_datablock = class(tailineinfo)
  443. is_global : boolean;
  444. sym : tasmsymbol;
  445. size : asizeint;
  446. constructor Create(const _name : string;_size : aint);
  447. constructor Create_global(const _name : string;_size : asizeint);
  448. constructor ppuload(t:taitype;ppufile:tcompilerppufile);override;
  449. procedure ppuwrite(ppufile:tcompilerppufile);override;
  450. procedure derefimpl;override;
  451. end;
  452. { Generates an integer const }
  453. tai_const = class(tai)
  454. sym,
  455. endsym : tasmsymbol;
  456. { if symbols and offset are provided the symofs is used,
  457. the value is calculated during assembling }
  458. symofs,
  459. value : int64;
  460. consttype : taiconst_type;
  461. { we use for the 128bit int64/qword for now because I can't imagine a
  462. case where we need 128 bit now (FK) }
  463. constructor Create(_typ:taiconst_type;_value : int64);
  464. constructor Create_128bit(_value : int64);
  465. constructor Create_64bit(_value : int64);
  466. constructor Create_32bit(_value : longint);
  467. constructor Create_16bit(_value : word);
  468. constructor Create_8bit(_value : byte);
  469. constructor Create_char(size: integer; _value: dword);
  470. constructor Create_sleb128bit(_value : int64);
  471. constructor Create_uleb128bit(_value : qword);
  472. constructor Create_aint(_value : aint);
  473. constructor Create_pint(_value : pint);
  474. constructor Create_sym(_sym:tasmsymbol);
  475. constructor Create_type_sym(_typ:taiconst_type;_sym:tasmsymbol);
  476. constructor Create_sym_offset(_sym:tasmsymbol;ofs:aint);
  477. constructor Create_rel_sym(_typ:taiconst_type;_sym,_endsym:tasmsymbol);
  478. constructor Create_rva_sym(_sym:tasmsymbol);
  479. constructor Createname(const name:string;ofs:aint);
  480. constructor ppuload(t:taitype;ppufile:tcompilerppufile);override;
  481. procedure ppuwrite(ppufile:tcompilerppufile);override;
  482. procedure derefimpl;override;
  483. function getcopy:tlinkedlistitem;override;
  484. function size:longint;
  485. end;
  486. { Generates a single float (32 bit real) }
  487. tai_real_32bit = class(tai)
  488. value : ts32real;
  489. constructor Create(_value : ts32real);
  490. constructor ppuload(t:taitype;ppufile:tcompilerppufile);override;
  491. procedure ppuwrite(ppufile:tcompilerppufile);override;
  492. end;
  493. tformatoptions = (fo_none,fo_hiloswapped);
  494. { Generates a double float (64 bit real) }
  495. tai_real_64bit = class(tai)
  496. value : ts64real;
  497. {$ifdef ARM}
  498. formatoptions : tformatoptions;
  499. constructor Create_hiloswapped(_value : ts64real);
  500. {$endif ARM}
  501. constructor Create(_value : ts64real);
  502. constructor ppuload(t:taitype;ppufile:tcompilerppufile);override;
  503. procedure ppuwrite(ppufile:tcompilerppufile);override;
  504. end;
  505. { Generates an extended float (80 bit real) }
  506. tai_real_80bit = class(tai)
  507. value : ts80real;
  508. savesize : byte;
  509. constructor Create(_value : ts80real; _savesize: byte);
  510. constructor ppuload(t:taitype;ppufile:tcompilerppufile);override;
  511. procedure ppuwrite(ppufile:tcompilerppufile);override;
  512. end;
  513. { Generates an float128 (128 bit real) }
  514. tai_real_128bit = class(tai)
  515. value : ts128real;
  516. constructor Create(_value : ts128real);
  517. constructor ppuload(t:taitype;ppufile:tcompilerppufile);override;
  518. procedure ppuwrite(ppufile:tcompilerppufile);override;
  519. end;
  520. { Generates a comp int (integer over 64 bits)
  521. This is Intel 80x86 specific, and is not
  522. really supported on other processors.
  523. }
  524. tai_comp_64bit = class(tai)
  525. value : ts64comp;
  526. constructor Create(_value : ts64comp);
  527. constructor ppuload(t:taitype;ppufile:tcompilerppufile);override;
  528. procedure ppuwrite(ppufile:tcompilerppufile);override;
  529. end;
  530. { tai_stab }
  531. tai_stab = class(tai)
  532. str : pchar;
  533. stabtype : TStabType;
  534. constructor Create(_stabtype:TStabType;_str : pchar);
  535. constructor Create_str(_stabtype:TStabType;const s:string);
  536. constructor create_ansistr(_stabtype: TStabType; const s: ansistring);
  537. destructor Destroy;override;
  538. end;
  539. tai_force_line = class(tailineinfo)
  540. constructor Create;
  541. end;
  542. tai_function_name = class(tai)
  543. funcname : pshortstring;
  544. constructor create(const s:string);
  545. destructor destroy;override;
  546. end;
  547. { Insert a cut to split assembler into several smaller files }
  548. tai_cutobject = class(tai)
  549. place : tcutplace;
  550. constructor Create;
  551. constructor Create_begin;
  552. constructor Create_end;
  553. constructor ppuload(t:taitype;ppufile:tcompilerppufile);override;
  554. procedure ppuwrite(ppufile:tcompilerppufile);override;
  555. end;
  556. { Insert a marker for assembler and inline blocks }
  557. tai_marker = class(tai)
  558. Kind: TAsmMarker;
  559. Constructor Create(_Kind: TAsmMarker);
  560. constructor ppuload(t:taitype;ppufile:tcompilerppufile);override;
  561. procedure ppuwrite(ppufile:tcompilerppufile);override;
  562. end;
  563. tai_tempalloc = class(tai)
  564. allocation : boolean;
  565. {$ifdef EXTDEBUG}
  566. problem : pshortstring;
  567. {$endif EXTDEBUG}
  568. temppos,
  569. tempsize : longint;
  570. constructor alloc(pos,size:longint);
  571. constructor dealloc(pos,size:longint);
  572. {$ifdef EXTDEBUG}
  573. constructor allocinfo(pos,size:longint;const st:string);
  574. {$endif EXTDEBUG}
  575. constructor ppuload(t:taitype;ppufile:tcompilerppufile);override;
  576. destructor destroy;override;
  577. procedure ppuwrite(ppufile:tcompilerppufile);override;
  578. end;
  579. tai_regalloc = class(tai)
  580. reg : tregister;
  581. ratype : TRegAllocType;
  582. { tells BuildLabelTableAndFixRegAlloc that the deallocation should be kept }
  583. keep : boolean;
  584. { reg(de)alloc belongs to this instruction, this
  585. is only used for automatic inserted (de)alloc for
  586. imaginary register and required for spilling code }
  587. instr : tai;
  588. constructor alloc(r : tregister;ainstr:tai);
  589. constructor dealloc(r : tregister;ainstr:tai);
  590. constructor sync(r : tregister);
  591. constructor resize(r : tregister);
  592. constructor ppuload(t:taitype;ppufile:tcompilerppufile);override;
  593. procedure ppuwrite(ppufile:tcompilerppufile);override;
  594. end;
  595. tadd_reg_instruction_proc=procedure(instr:Tai;r:tregister) of object;
  596. { Class template for assembler instructions
  597. }
  598. tai_cpu_abstract = class(tailineinfo)
  599. protected
  600. procedure ppuloadoper(ppufile:tcompilerppufile;var o:toper);virtual;
  601. procedure ppuwriteoper(ppufile:tcompilerppufile;const o:toper);virtual;
  602. procedure ppubuildderefimploper(var o:toper);virtual;abstract;
  603. procedure ppuderefoper(var o:toper);virtual;abstract;
  604. public
  605. { Condition flags for instruction }
  606. condition : TAsmCond;
  607. { Number of operands to instruction }
  608. ops : byte;
  609. { Number of allocate oper structures }
  610. opercnt : byte;
  611. { Operands of instruction }
  612. oper : array[0..max_operands-1] of poper;
  613. { Actual opcode of instruction }
  614. opcode : tasmop;
  615. {$ifdef x86}
  616. segprefix : tregister;
  617. {$endif x86}
  618. { true if instruction is a jmp }
  619. is_jmp : boolean; { is this instruction a jump? (needed for optimizer) }
  620. Constructor Create(op : tasmop);virtual;
  621. Destructor Destroy;override;
  622. function getcopy:TLinkedListItem;override;
  623. constructor ppuload(t:taitype;ppufile:tcompilerppufile);override;
  624. procedure ppuwrite(ppufile:tcompilerppufile);override;
  625. procedure buildderefimpl;override;
  626. procedure derefimpl;override;
  627. procedure SetCondition(const c:TAsmCond);
  628. procedure allocate_oper(opers:longint);
  629. procedure loadconst(opidx:longint;l:aint);
  630. procedure loadsymbol(opidx:longint;s:tasmsymbol;sofs:longint);
  631. procedure loadlocal(opidx:longint;s:pointer;sofs:longint;indexreg:tregister;scale:byte;getoffset,forceref:boolean);
  632. procedure loadref(opidx:longint;const r:treference);
  633. procedure loadreg(opidx:longint;r:tregister);
  634. procedure loadoper(opidx:longint;o:toper);
  635. procedure clearop(opidx:longint);
  636. procedure freeop(opidx:longint);
  637. { register allocator }
  638. function is_same_reg_move(regtype: Tregistertype):boolean;virtual;
  639. function spilling_get_operation_type(opnr: longint): topertype;virtual;
  640. function spilling_get_operation_type_ref(opnr: longint; reg: tregister): topertype;virtual;
  641. function Pass1(objdata:TObjData):longint;virtual;
  642. procedure Pass2(objdata:TObjData);virtual;
  643. procedure resetpass1; virtual;
  644. procedure resetpass2; virtual;
  645. end;
  646. tai_cpu_class = class of tai_cpu_abstract;
  647. { Buffer type used for alignment }
  648. tfillbuffer = array[0..63] of char;
  649. { alignment for operator }
  650. tai_align_abstract = class(tai)
  651. aligntype : byte; { 1 = no align, 2 = word align, 4 = dword align }
  652. fillsize : byte; { real size to fill }
  653. fillop : byte; { value to fill with - optional }
  654. use_op : boolean;
  655. constructor Create(b:byte);virtual;
  656. constructor Create_op(b: byte; _op: byte);virtual;
  657. constructor Create_zeros(b:byte);
  658. constructor ppuload(t:taitype;ppufile:tcompilerppufile);override;
  659. procedure ppuwrite(ppufile:tcompilerppufile);override;
  660. function calculatefillbuf(var buf : tfillbuffer;executable : boolean):pchar;virtual;
  661. end;
  662. tai_align_class = class of tai_align_abstract;
  663. tai_varloc = class(tai)
  664. newlocation,
  665. newlocationhi : tregister;
  666. varsym : tsym;
  667. constructor create(sym : tsym;loc : tregister);
  668. constructor create64(sym : tsym;loc,lochi : tregister);
  669. constructor ppuload(t:taitype;ppufile:tcompilerppufile);override;
  670. procedure ppuwrite(ppufile:tcompilerppufile);override;
  671. procedure buildderefimpl;override;
  672. procedure derefimpl;override;
  673. end;
  674. TSehDirectiveDatatype=(sd_none,sd_string,sd_reg,sd_offset,sd_regoffset);
  675. TSehDirectiveData=record
  676. case typ: TSehDirectiveDatatype of
  677. sd_none: ();
  678. sd_string: (name:pshortstring;flags:byte);
  679. sd_reg,sd_offset,sd_regoffset: (reg:TRegister;offset:dword);
  680. end;
  681. tai_seh_directive = class(tai)
  682. kind: TAsmSehDirective;
  683. data: TSehDirectiveData;
  684. constructor create(_kind:TAsmSehDirective);
  685. constructor create_name(_kind:TAsmSehDirective;const _name: string);
  686. constructor create_reg(_kind:TAsmSehDirective;r:TRegister);
  687. constructor create_offset(_kind:TAsmSehDirective;ofs:dword);
  688. constructor create_reg_offset(_kind:TAsmSehDirective;r:TRegister;ofs:dword);
  689. constructor ppuload(t:taitype;ppufile:tcompilerppufile);override;
  690. destructor destroy;override;
  691. procedure ppuwrite(ppufile:tcompilerppufile);override;
  692. procedure generate_code(objdata:TObjData);virtual;
  693. property datatype: TSehDirectiveDatatype read data.typ;
  694. end;
  695. tai_seh_directive_class=class of tai_seh_directive;
  696. { JVM variable live range description }
  697. tai_jvar = class(tai)
  698. stackslot: longint;
  699. desc: pshortstring;
  700. startlab,stoplab: tasmsymbol;
  701. constructor Create(_stackslot: longint; const _desc: shortstring; _startlab, _stoplab: TAsmSymbol);
  702. constructor ppuload(t:taitype;ppufile:tcompilerppufile);override;
  703. procedure ppuwrite(ppufile:tcompilerppufile);override;
  704. destructor destroy;override;
  705. end;
  706. tai_jvar_class = class of tai_jvar;
  707. { JVM exception catch description }
  708. tai_jcatch = class(tai)
  709. name: pshortstring;
  710. startlab,stoplab,handlerlab: tasmsymbol;
  711. constructor Create(const _name: shortstring; _startlab, _stoplab, _handlerlab: TAsmSymbol);
  712. destructor destroy;override;
  713. constructor ppuload(t:taitype;ppufile:tcompilerppufile);override;
  714. procedure ppuwrite(ppufile:tcompilerppufile);override;
  715. end;
  716. tai_jcatch_class = class of tai_jcatch;
  717. var
  718. { array with all class types for tais }
  719. aiclass : taiclassarray;
  720. { target specific tais, possibly overwritten in target specific aasmcpu }
  721. cai_align : tai_align_class = tai_align_abstract;
  722. cai_cpu : tai_cpu_class = tai_cpu_abstract;
  723. cai_seh_directive: tai_seh_directive_class = tai_seh_directive;
  724. { hook to notify uses of registers }
  725. add_reg_instruction_hook : tadd_reg_instruction_proc;
  726. procedure maybe_new_object_file(list:TAsmList);
  727. procedure new_section(list:TAsmList;Asectype:TAsmSectiontype;const Aname:string;Aalign:byte;Asecorder:TasmSectionorder=secorder_default);
  728. procedure section_symbol_start(list:TAsmList;const Aname:string;Asymtyp:Tasmsymtype;
  729. Aglobal:boolean;Asectype:TAsmSectiontype;Aalign:byte);
  730. procedure section_symbol_end(list:TAsmList;const Aname:string);
  731. function ppuloadai(ppufile:tcompilerppufile):tai;
  732. procedure ppuwriteai(ppufile:tcompilerppufile;n:tai);
  733. implementation
  734. uses
  735. SysUtils,
  736. verbose,
  737. globals,
  738. fmodule;
  739. const
  740. pputaimarker = 254;
  741. {****************************************************************************
  742. Helpers
  743. ****************************************************************************}
  744. procedure maybe_new_object_file(list:TAsmList);
  745. begin
  746. if create_smartlink_library then
  747. list.concat(tai_cutobject.create);
  748. end;
  749. procedure new_section(list:TAsmList;Asectype:TAsmSectiontype;const Aname:string;Aalign:byte;Asecorder:TasmSectionorder=secorder_default);
  750. begin
  751. list.concat(tai_section.create(Asectype,Aname,Aalign,Asecorder));
  752. list.concat(cai_align.create(Aalign));
  753. end;
  754. procedure section_symbol_start(list:TAsmList;const Aname:string;Asymtyp:Tasmsymtype;
  755. Aglobal:boolean;Asectype:TAsmSectiontype;Aalign:byte);
  756. begin
  757. maybe_new_object_file(list);
  758. new_section(list,Asectype,Aname,Aalign);
  759. if Aglobal or
  760. create_smartlink then
  761. list.concat(tai_symbol.createname_global(Aname,Asymtyp,0))
  762. else
  763. list.concat(tai_symbol.createname(Aname,Asymtyp,0));
  764. end;
  765. procedure section_symbol_end(list:TAsmList;const Aname:string);
  766. begin
  767. list.concat(tai_symbol_end.createname(Aname));
  768. end;
  769. function ppuloadai(ppufile:tcompilerppufile):tai;
  770. var
  771. b : byte;
  772. t : taitype;
  773. begin
  774. { marker }
  775. b:=ppufile.getbyte;
  776. if b<>pputaimarker then
  777. internalerror(200208181);
  778. { load nodetype }
  779. t:=taitype(ppufile.getbyte);
  780. if t<>ait_none then
  781. begin
  782. if t>high(taitype) then
  783. internalerror(200208182);
  784. if not assigned(aiclass[t]) then
  785. internalerror(200208183);
  786. {writeln('taiload: ',taitypestr[t]);}
  787. { generate tai of the correct class }
  788. ppuloadai:=aiclass[t].ppuload(t,ppufile);
  789. end
  790. else
  791. ppuloadai:=nil;
  792. end;
  793. procedure ppuwriteai(ppufile:tcompilerppufile;n:tai);
  794. begin
  795. { marker, read by ppuloadnode }
  796. ppufile.putbyte(pputaimarker);
  797. if assigned(n) then
  798. begin
  799. { type, read by ppuloadnode }
  800. ppufile.putbyte(byte(n.typ));
  801. {writeln('taiwrite: ',taitypestr[n.typ]);}
  802. n.ppuwrite(ppufile);
  803. end
  804. else
  805. ppufile.putbyte(byte(ait_none));
  806. end;
  807. constructor tai_varloc.create(sym: tsym; loc: tregister);
  808. begin
  809. inherited Create;
  810. typ:=ait_varloc;
  811. newlocation:=loc;
  812. newlocationhi:=NR_NO;
  813. varsym:=sym;
  814. end;
  815. constructor tai_varloc.create64(sym: tsym; loc: tregister;lochi : tregister);
  816. begin
  817. inherited Create;
  818. typ:=ait_varloc;
  819. newlocation:=loc;
  820. newlocationhi:=lochi;
  821. varsym:=sym;
  822. end;
  823. constructor tai_varloc.ppuload(t: taitype; ppufile: tcompilerppufile);
  824. begin
  825. inherited ppuload(t, ppufile);
  826. end;
  827. procedure tai_varloc.ppuwrite(ppufile: tcompilerppufile);
  828. begin
  829. inherited ppuwrite(ppufile);
  830. end;
  831. procedure tai_varloc.buildderefimpl;
  832. begin
  833. inherited buildderefimpl;
  834. end;
  835. procedure tai_varloc.derefimpl;
  836. begin
  837. inherited derefimpl;
  838. end;
  839. {****************************************************************************
  840. TAI
  841. ****************************************************************************}
  842. constructor tai.Create;
  843. begin
  844. {$ifndef NOOPT}
  845. optinfo:=nil;
  846. {$endif NOOPT}
  847. end;
  848. constructor tai.ppuload(t:taitype;ppufile:tcompilerppufile);
  849. begin
  850. typ:=t;
  851. {$ifndef NOOPT}
  852. optinfo:=nil;
  853. {$endif}
  854. end;
  855. procedure tai.ppuwrite(ppufile:tcompilerppufile);
  856. begin
  857. end;
  858. procedure tai.buildderefimpl;
  859. begin
  860. end;
  861. procedure tai.derefimpl;
  862. begin
  863. end;
  864. {****************************************************************************
  865. TAILINEINFO
  866. ****************************************************************************}
  867. constructor tailineinfo.create;
  868. begin
  869. inherited create;
  870. fileinfo:=current_filepos;
  871. end;
  872. constructor tailineinfo.ppuload(t:taitype;ppufile:tcompilerppufile);
  873. begin
  874. inherited ppuload(t,ppufile);
  875. ppufile.getposinfo(fileinfo);
  876. end;
  877. procedure tailineinfo.ppuwrite(ppufile:tcompilerppufile);
  878. begin
  879. inherited ppuwrite(ppufile);
  880. ppufile.putposinfo(fileinfo);
  881. end;
  882. {****************************************************************************
  883. TAI_SIMPLE
  884. ****************************************************************************}
  885. constructor tai_simple.create(_typ : taitype);
  886. begin
  887. inherited create;
  888. typ:=_typ;
  889. end;
  890. {****************************************************************************
  891. TAI_SECTION
  892. ****************************************************************************}
  893. constructor tai_section.Create(Asectype:TAsmSectiontype;const Aname:string;Aalign:byte;Asecorder:TasmSectionorder=secorder_default);
  894. begin
  895. inherited Create;
  896. typ:=ait_section;
  897. sectype:=asectype;
  898. secalign:=Aalign;
  899. secorder:=Asecorder;
  900. name:=stringdup(Aname);
  901. sec:=nil;
  902. end;
  903. constructor tai_section.ppuload(t:taitype;ppufile:tcompilerppufile);
  904. begin
  905. inherited ppuload(t,ppufile);
  906. sectype:=TAsmSectiontype(ppufile.getbyte);
  907. secalign:=ppufile.getbyte;
  908. name:=stringdup(ppufile.getstring);
  909. sec:=nil;
  910. end;
  911. destructor tai_section.Destroy;
  912. begin
  913. stringdispose(name);
  914. end;
  915. procedure tai_section.ppuwrite(ppufile:tcompilerppufile);
  916. begin
  917. inherited ppuwrite(ppufile);
  918. ppufile.putbyte(byte(sectype));
  919. ppufile.putbyte(secalign);
  920. ppufile.putstring(name^);
  921. end;
  922. {****************************************************************************
  923. TAI_DATABLOCK
  924. ****************************************************************************}
  925. constructor tai_datablock.Create(const _name : string;_size : aint);
  926. begin
  927. inherited Create;
  928. typ:=ait_datablock;
  929. sym:=current_asmdata.DefineAsmSymbol(_name,AB_LOCAL,AT_DATA);
  930. { keep things aligned }
  931. if _size<=0 then
  932. _size:=sizeof(aint);
  933. size:=_size;
  934. is_global:=false;
  935. end;
  936. constructor tai_datablock.Create_global(const _name : string;_size : asizeint);
  937. begin
  938. inherited Create;
  939. typ:=ait_datablock;
  940. sym:=current_asmdata.DefineAsmSymbol(_name,AB_GLOBAL,AT_DATA);
  941. { keep things aligned }
  942. if _size<=0 then
  943. _size:=sizeof(aint);
  944. size:=_size;
  945. is_global:=true;
  946. end;
  947. constructor tai_datablock.ppuload(t:taitype;ppufile:tcompilerppufile);
  948. begin
  949. inherited Create;
  950. sym:=ppufile.getasmsymbol;
  951. size:=ppufile.getaint;
  952. is_global:=boolean(ppufile.getbyte);
  953. end;
  954. procedure tai_datablock.ppuwrite(ppufile:tcompilerppufile);
  955. begin
  956. inherited ppuwrite(ppufile);
  957. ppufile.putasmsymbol(sym);
  958. ppufile.putaint(size);
  959. ppufile.putbyte(byte(is_global));
  960. end;
  961. procedure tai_datablock.derefimpl;
  962. begin
  963. end;
  964. {****************************************************************************
  965. TAI_SYMBOL
  966. ****************************************************************************}
  967. constructor tai_symbol.Create(_sym:tasmsymbol;siz:longint);
  968. begin
  969. inherited Create;
  970. typ:=ait_symbol;
  971. sym:=_sym;
  972. size:=siz;
  973. sym.bind:=AB_LOCAL;
  974. is_global:=false;
  975. end;
  976. constructor tai_symbol.Create_global(_sym:tasmsymbol;siz:longint);
  977. begin
  978. inherited Create;
  979. typ:=ait_symbol;
  980. sym:=_sym;
  981. size:=siz;
  982. { don't override PRIVATE_EXTERN with GLOBAL }
  983. if not(sym.bind in [AB_GLOBAL,AB_PRIVATE_EXTERN]) then
  984. sym.bind:=AB_GLOBAL;
  985. is_global:=true;
  986. end;
  987. constructor tai_symbol.Createname(const _name : string;_symtyp:Tasmsymtype;siz:longint);
  988. begin
  989. inherited Create;
  990. typ:=ait_symbol;
  991. sym:=current_asmdata.DefineAsmSymbol(_name,AB_LOCAL,_symtyp);
  992. size:=siz;
  993. is_global:=false;
  994. end;
  995. constructor tai_symbol.Createname_global(const _name : string;_symtyp:Tasmsymtype;siz:longint);
  996. begin
  997. inherited Create;
  998. typ:=ait_symbol;
  999. sym:=current_asmdata.DefineAsmSymbol(_name,AB_GLOBAL,_symtyp);
  1000. size:=siz;
  1001. is_global:=true;
  1002. end;
  1003. constructor tai_symbol.createname_global_value(const _name: string;_symtyp: tasmsymtype; siz: longint; val: ptruint);
  1004. begin
  1005. Createname_global(_name,_symtyp,siz);
  1006. value:=val;
  1007. has_value:=true;
  1008. end;
  1009. constructor tai_symbol.ppuload(t:taitype;ppufile:tcompilerppufile);
  1010. begin
  1011. inherited ppuload(t,ppufile);
  1012. sym:=ppufile.getasmsymbol;
  1013. size:=ppufile.getlongint;
  1014. is_global:=boolean(ppufile.getbyte);
  1015. end;
  1016. procedure tai_symbol.ppuwrite(ppufile:tcompilerppufile);
  1017. begin
  1018. inherited ppuwrite(ppufile);
  1019. ppufile.putasmsymbol(sym);
  1020. ppufile.putlongint(size);
  1021. ppufile.putbyte(byte(is_global));
  1022. end;
  1023. procedure tai_symbol.derefimpl;
  1024. begin
  1025. end;
  1026. {****************************************************************************
  1027. TAI_SYMBOL_END
  1028. ****************************************************************************}
  1029. constructor tai_symbol_end.Create(_sym:tasmsymbol);
  1030. begin
  1031. inherited Create;
  1032. typ:=ait_symbol_end;
  1033. sym:=_sym;
  1034. end;
  1035. constructor tai_symbol_end.Createname(const _name : string);
  1036. begin
  1037. inherited Create;
  1038. typ:=ait_symbol_end;
  1039. sym:=current_asmdata.RefAsmSymbol(_name);
  1040. end;
  1041. constructor tai_symbol_end.ppuload(t:taitype;ppufile:tcompilerppufile);
  1042. begin
  1043. inherited ppuload(t,ppufile);
  1044. sym:=ppufile.getasmsymbol;
  1045. end;
  1046. procedure tai_symbol_end.ppuwrite(ppufile:tcompilerppufile);
  1047. begin
  1048. inherited ppuwrite(ppufile);
  1049. ppufile.putasmsymbol(sym);
  1050. end;
  1051. procedure tai_symbol_end.derefimpl;
  1052. begin
  1053. end;
  1054. {****************************************************************************
  1055. TAI_SYMBOL_END
  1056. ****************************************************************************}
  1057. constructor tai_directive.Create(_directive:TAsmDirective;const _name:ansistring);
  1058. begin
  1059. inherited Create;
  1060. typ:=ait_directive;
  1061. name:=_name;
  1062. directive:=_directive;
  1063. end;
  1064. constructor tai_directive.ppuload(t:taitype;ppufile:tcompilerppufile);
  1065. begin
  1066. inherited ppuload(t,ppufile);
  1067. name:=ppufile.getansistring;
  1068. directive:=TAsmDirective(ppufile.getbyte);
  1069. end;
  1070. procedure tai_directive.ppuwrite(ppufile:tcompilerppufile);
  1071. begin
  1072. inherited ppuwrite(ppufile);
  1073. ppufile.putansistring(name);
  1074. ppufile.putbyte(byte(directive));
  1075. end;
  1076. {****************************************************************************
  1077. TAI_ENT / TAI_ENT_END
  1078. ****************************************************************************}
  1079. Constructor tai_ent.Create (const ProcName : String);
  1080. begin
  1081. Inherited Create;
  1082. Name:=ProcName;
  1083. typ:=ait_ent;
  1084. end;
  1085. Constructor tai_ent_end.Create (const ProcName : String);
  1086. begin
  1087. Inherited Create;
  1088. Name:=ProcName;
  1089. typ:=ait_ent_end;
  1090. end;
  1091. {****************************************************************************
  1092. TAI_CONST
  1093. ****************************************************************************}
  1094. constructor tai_const.Create(_typ:taiconst_type;_value : int64);
  1095. begin
  1096. inherited Create;
  1097. typ:=ait_const;
  1098. consttype:=_typ;
  1099. value:=_value;
  1100. sym:=nil;
  1101. endsym:=nil;
  1102. end;
  1103. constructor tai_const.Create_128bit(_value : int64);
  1104. begin
  1105. inherited Create;
  1106. typ:=ait_const;
  1107. consttype:=aitconst_128bit;
  1108. value:=_value;
  1109. sym:=nil;
  1110. endsym:=nil;
  1111. end;
  1112. constructor tai_const.Create_64bit(_value : int64);
  1113. begin
  1114. inherited Create;
  1115. typ:=ait_const;
  1116. consttype:=aitconst_64bit;
  1117. value:=_value;
  1118. sym:=nil;
  1119. endsym:=nil;
  1120. end;
  1121. constructor tai_const.Create_32bit(_value : longint);
  1122. begin
  1123. inherited Create;
  1124. typ:=ait_const;
  1125. consttype:=aitconst_32bit;
  1126. value:=_value;
  1127. sym:=nil;
  1128. endsym:=nil;
  1129. end;
  1130. constructor tai_const.Create_16bit(_value : word);
  1131. begin
  1132. inherited Create;
  1133. typ:=ait_const;
  1134. consttype:=aitconst_16bit;
  1135. value:=_value;
  1136. sym:=nil;
  1137. endsym:=nil;
  1138. end;
  1139. constructor tai_const.Create_8bit(_value : byte);
  1140. begin
  1141. inherited Create;
  1142. typ:=ait_const;
  1143. consttype:=aitconst_8bit;
  1144. value:=_value;
  1145. sym:=nil;
  1146. endsym:=nil;
  1147. end;
  1148. constructor tai_const.Create_char(size: integer; _value: dword);
  1149. begin
  1150. inherited Create;
  1151. typ:=ait_const;
  1152. case size of
  1153. 1:
  1154. begin
  1155. consttype:=aitconst_8bit;
  1156. value:=byte(_value)
  1157. end;
  1158. 2:
  1159. begin
  1160. consttype:=aitconst_16bit;
  1161. value:=word(_value)
  1162. end
  1163. else
  1164. InternalError(2010030701)
  1165. end
  1166. end;
  1167. constructor tai_const.Create_sleb128bit(_value : int64);
  1168. begin
  1169. inherited Create;
  1170. typ:=ait_const;
  1171. consttype:=aitconst_sleb128bit;
  1172. value:=_value;
  1173. sym:=nil;
  1174. endsym:=nil;
  1175. end;
  1176. constructor tai_const.Create_uleb128bit(_value : qword);
  1177. begin
  1178. inherited Create;
  1179. typ:=ait_const;
  1180. consttype:=aitconst_uleb128bit;
  1181. value:=int64(_value);
  1182. sym:=nil;
  1183. endsym:=nil;
  1184. end;
  1185. constructor tai_const.Create_aint(_value : aint);
  1186. begin
  1187. inherited Create;
  1188. typ:=ait_const;
  1189. consttype:=aitconst_aint;
  1190. value:=_value;
  1191. sym:=nil;
  1192. endsym:=nil;
  1193. end;
  1194. constructor tai_const.Create_pint(_value : pint);
  1195. begin
  1196. inherited Create;
  1197. typ:=ait_const;
  1198. consttype:=aitconst_ptr;
  1199. value:=_value;
  1200. sym:=nil;
  1201. endsym:=nil;
  1202. end;
  1203. constructor tai_const.Create_type_sym(_typ:taiconst_type;_sym:tasmsymbol);
  1204. begin
  1205. inherited Create;
  1206. typ:=ait_const;
  1207. consttype:=_typ;
  1208. sym:=_sym;
  1209. endsym:=nil;
  1210. value:=0;
  1211. { update sym info }
  1212. if assigned(sym) then
  1213. sym.increfs;
  1214. end;
  1215. constructor tai_const.Create_sym(_sym:tasmsymbol);
  1216. begin
  1217. self.create_sym_offset(_sym,0);
  1218. end;
  1219. constructor tai_const.Create_sym_offset(_sym:tasmsymbol;ofs:aint);
  1220. begin
  1221. inherited Create;
  1222. typ:=ait_const;
  1223. consttype:=aitconst_ptr;
  1224. { sym is allowed to be nil, this is used to write nil pointers }
  1225. sym:=_sym;
  1226. endsym:=nil;
  1227. { store the original offset in symofs so that we can recalculate the
  1228. value field in the assembler }
  1229. symofs:=ofs;
  1230. value:=ofs;
  1231. { update sym info }
  1232. if assigned(sym) then
  1233. sym.increfs;
  1234. end;
  1235. constructor tai_const.Create_rel_sym(_typ:taiconst_type;_sym,_endsym:tasmsymbol);
  1236. begin
  1237. self.create_sym_offset(_sym,0);
  1238. consttype:=_typ;
  1239. endsym:=_endsym;
  1240. endsym.increfs;
  1241. end;
  1242. constructor tai_const.Create_rva_sym(_sym:tasmsymbol);
  1243. begin
  1244. self.create_sym_offset(_sym,0);
  1245. consttype:=aitconst_rva_symbol;
  1246. end;
  1247. constructor tai_const.Createname(const name:string;ofs:aint);
  1248. begin
  1249. self.create_sym_offset(current_asmdata.RefAsmSymbol(name),ofs);
  1250. end;
  1251. constructor tai_const.ppuload(t:taitype;ppufile:tcompilerppufile);
  1252. begin
  1253. inherited ppuload(t,ppufile);
  1254. consttype:=taiconst_type(ppufile.getbyte);
  1255. sym:=ppufile.getasmsymbol;
  1256. endsym:=ppufile.getasmsymbol;
  1257. value:=ppufile.getint64;
  1258. end;
  1259. procedure tai_const.ppuwrite(ppufile:tcompilerppufile);
  1260. begin
  1261. inherited ppuwrite(ppufile);
  1262. ppufile.putbyte(byte(consttype));
  1263. ppufile.putasmsymbol(sym);
  1264. ppufile.putasmsymbol(endsym);
  1265. ppufile.putint64(value);
  1266. end;
  1267. procedure tai_const.derefimpl;
  1268. begin
  1269. end;
  1270. function tai_const.getcopy:tlinkedlistitem;
  1271. begin
  1272. getcopy:=inherited getcopy;
  1273. { we need to increase the reference number }
  1274. sym.increfs;
  1275. if assigned(endsym) then
  1276. endsym.increfs;
  1277. end;
  1278. function tai_const.size:longint;
  1279. begin
  1280. case consttype of
  1281. aitconst_8bit :
  1282. result:=1;
  1283. aitconst_16bit :
  1284. result:=2;
  1285. aitconst_32bit,aitconst_darwin_dwarf_delta32:
  1286. result:=4;
  1287. aitconst_64bit,aitconst_darwin_dwarf_delta64:
  1288. result:=8;
  1289. aitconst_secrel32_symbol,
  1290. aitconst_rva_symbol :
  1291. if target_info.system=system_x86_64_win64 then
  1292. result:=sizeof(longint)
  1293. else
  1294. result:=sizeof(pint);
  1295. aitconst_uleb128bit :
  1296. result:=LengthUleb128(qword(value));
  1297. aitconst_sleb128bit :
  1298. result:=LengthSleb128(value);
  1299. aitconst_half16bit:
  1300. result:=2;
  1301. else
  1302. internalerror(200603253);
  1303. end;
  1304. end;
  1305. {****************************************************************************
  1306. TAI_real_32bit
  1307. ****************************************************************************}
  1308. constructor tai_real_32bit.Create(_value : ts32real);
  1309. begin
  1310. inherited Create;
  1311. typ:=ait_real_32bit;
  1312. value:=_value;
  1313. end;
  1314. constructor tai_real_32bit.ppuload(t:taitype;ppufile:tcompilerppufile);
  1315. begin
  1316. inherited ppuload(t,ppufile);
  1317. value:=ppufile.getreal;
  1318. end;
  1319. procedure tai_real_32bit.ppuwrite(ppufile:tcompilerppufile);
  1320. begin
  1321. inherited ppuwrite(ppufile);
  1322. ppufile.putreal(value);
  1323. end;
  1324. {****************************************************************************
  1325. TAI_real_64bit
  1326. ****************************************************************************}
  1327. constructor tai_real_64bit.Create(_value : ts64real);
  1328. begin
  1329. inherited Create;
  1330. typ:=ait_real_64bit;
  1331. value:=_value;
  1332. end;
  1333. {$ifdef ARM}
  1334. constructor tai_real_64bit.Create_hiloswapped(_value : ts64real);
  1335. begin
  1336. inherited Create;
  1337. typ:=ait_real_64bit;
  1338. value:=_value;
  1339. formatoptions:=fo_hiloswapped;
  1340. end;
  1341. {$endif ARM}
  1342. constructor tai_real_64bit.ppuload(t:taitype;ppufile:tcompilerppufile);
  1343. begin
  1344. inherited ppuload(t,ppufile);
  1345. value:=ppufile.getreal;
  1346. {$ifdef ARM}
  1347. formatoptions:=tformatoptions(ppufile.getbyte);
  1348. {$endif ARM}
  1349. end;
  1350. procedure tai_real_64bit.ppuwrite(ppufile:tcompilerppufile);
  1351. begin
  1352. inherited ppuwrite(ppufile);
  1353. ppufile.putreal(value);
  1354. {$ifdef ARM}
  1355. ppufile.putbyte(byte(formatoptions));
  1356. {$endif ARM}
  1357. end;
  1358. {****************************************************************************
  1359. TAI_real_80bit
  1360. ****************************************************************************}
  1361. constructor tai_real_80bit.Create(_value : ts80real; _savesize: byte);
  1362. begin
  1363. inherited Create;
  1364. typ:=ait_real_80bit;
  1365. value:=_value;
  1366. savesize:=_savesize;
  1367. end;
  1368. constructor tai_real_80bit.ppuload(t:taitype;ppufile:tcompilerppufile);
  1369. begin
  1370. inherited ppuload(t,ppufile);
  1371. value:=ppufile.getreal;
  1372. savesize:=ppufile.getbyte;
  1373. end;
  1374. procedure tai_real_80bit.ppuwrite(ppufile:tcompilerppufile);
  1375. begin
  1376. inherited ppuwrite(ppufile);
  1377. ppufile.putreal(value);
  1378. ppufile.putbyte(savesize);
  1379. end;
  1380. {****************************************************************************
  1381. TAI_real_80bit
  1382. ****************************************************************************}
  1383. constructor tai_real_128bit.Create(_value : ts128real);
  1384. begin
  1385. inherited Create;
  1386. typ:=ait_real_128bit;
  1387. value:=_value;
  1388. end;
  1389. constructor tai_real_128bit.ppuload(t:taitype;ppufile:tcompilerppufile);
  1390. begin
  1391. inherited ppuload(t,ppufile);
  1392. value:=ppufile.getreal;
  1393. end;
  1394. procedure tai_real_128bit.ppuwrite(ppufile:tcompilerppufile);
  1395. begin
  1396. inherited ppuwrite(ppufile);
  1397. ppufile.putreal(value);
  1398. end;
  1399. {****************************************************************************
  1400. Tai_comp_64bit
  1401. ****************************************************************************}
  1402. constructor tai_comp_64bit.Create(_value : ts64comp);
  1403. begin
  1404. inherited Create;
  1405. typ:=ait_comp_64bit;
  1406. value:=_value;
  1407. end;
  1408. constructor tai_comp_64bit.ppuload(t:taitype;ppufile:tcompilerppufile);
  1409. begin
  1410. inherited ppuload(t,ppufile);
  1411. ppufile.putdata(value,sizeof(value));
  1412. end;
  1413. procedure tai_comp_64bit.ppuwrite(ppufile:tcompilerppufile);
  1414. begin
  1415. inherited ppuwrite(ppufile);
  1416. ppufile.getdata(value,sizeof(value));
  1417. end;
  1418. {****************************************************************************
  1419. TAI_STRING
  1420. ****************************************************************************}
  1421. constructor tai_string.Create(const _str : string);
  1422. begin
  1423. inherited Create;
  1424. typ:=ait_string;
  1425. len:=length(_str);
  1426. getmem(str,len+1);
  1427. strpcopy(str,_str);
  1428. end;
  1429. constructor tai_string.Create_pchar(_str : pchar;length : longint);
  1430. begin
  1431. inherited Create;
  1432. typ:=ait_string;
  1433. str:=_str;
  1434. len:=length;
  1435. end;
  1436. destructor tai_string.destroy;
  1437. begin
  1438. if str<>nil then
  1439. freemem(str);
  1440. inherited Destroy;
  1441. end;
  1442. constructor tai_string.ppuload(t:taitype;ppufile:tcompilerppufile);
  1443. begin
  1444. inherited ppuload(t,ppufile);
  1445. len:=ppufile.getlongint;
  1446. getmem(str,len);
  1447. ppufile.getdata(str^,len);
  1448. end;
  1449. procedure tai_string.ppuwrite(ppufile:tcompilerppufile);
  1450. begin
  1451. inherited ppuwrite(ppufile);
  1452. ppufile.putlongint(len);
  1453. ppufile.putdata(str^,len);
  1454. end;
  1455. function tai_string.getcopy : tlinkedlistitem;
  1456. var
  1457. p : tlinkedlistitem;
  1458. begin
  1459. p:=inherited getcopy;
  1460. getmem(tai_string(p).str,len);
  1461. move(str^,tai_string(p).str^,len);
  1462. getcopy:=p;
  1463. end;
  1464. {****************************************************************************
  1465. TAI_LABEL
  1466. ****************************************************************************}
  1467. constructor tai_label.create(_labsym : tasmlabel);
  1468. begin
  1469. inherited Create;
  1470. typ:=ait_label;
  1471. labsym:=_labsym;
  1472. labsym.is_set:=true;
  1473. is_global:=(labsym.bind in [AB_GLOBAL,AB_PRIVATE_EXTERN]);
  1474. end;
  1475. constructor tai_label.ppuload(t:taitype;ppufile:tcompilerppufile);
  1476. begin
  1477. inherited ppuload(t,ppufile);
  1478. labsym:=tasmlabel(ppufile.getasmsymbol);
  1479. is_global:=boolean(ppufile.getbyte);
  1480. end;
  1481. procedure tai_label.ppuwrite(ppufile:tcompilerppufile);
  1482. begin
  1483. inherited ppuwrite(ppufile);
  1484. ppufile.putasmsymbol(labsym);
  1485. ppufile.putbyte(byte(is_global));
  1486. end;
  1487. procedure tai_label.derefimpl;
  1488. begin
  1489. labsym.is_set:=true;
  1490. end;
  1491. {****************************************************************************
  1492. tai_comment comment to be inserted in the assembler file
  1493. ****************************************************************************}
  1494. constructor tai_comment.Create(_str : pchar);
  1495. begin
  1496. inherited Create;
  1497. typ:=ait_comment;
  1498. str:=_str;
  1499. end;
  1500. destructor tai_comment.destroy;
  1501. begin
  1502. freemem(str);
  1503. inherited Destroy;
  1504. end;
  1505. constructor tai_comment.ppuload(t:taitype;ppufile:tcompilerppufile);
  1506. var
  1507. len : longint;
  1508. begin
  1509. inherited ppuload(t,ppufile);
  1510. len:=ppufile.getlongint;
  1511. getmem(str,len+1);
  1512. ppufile.getdata(str^,len);
  1513. str[len]:=#0;
  1514. end;
  1515. procedure tai_comment.ppuwrite(ppufile:tcompilerppufile);
  1516. var
  1517. len : longint;
  1518. begin
  1519. inherited ppuwrite(ppufile);
  1520. len:=strlen(str);
  1521. ppufile.putlongint(len);
  1522. ppufile.putdata(str^,len);
  1523. end;
  1524. function tai_comment.getcopy : tlinkedlistitem;
  1525. var
  1526. p : tlinkedlistitem;
  1527. begin
  1528. p:=inherited getcopy;
  1529. getmem(tai_comment(p).str,strlen(str)+1);
  1530. move(str^,tai_comment(p).str^,strlen(str)+1);
  1531. getcopy:=p;
  1532. end;
  1533. {****************************************************************************
  1534. TAI_STABS
  1535. ****************************************************************************}
  1536. constructor tai_stab.create(_stabtype:TStabType;_str : pchar);
  1537. begin
  1538. inherited create;
  1539. typ:=ait_stab;
  1540. str:=_str;
  1541. stabtype:=_stabtype;
  1542. end;
  1543. constructor tai_stab.create_str(_stabtype:TStabType;const s:string);
  1544. begin
  1545. self.create(_stabtype,strpnew(s));
  1546. end;
  1547. constructor tai_stab.create_ansistr(_stabtype:TStabType;const s:ansistring);
  1548. begin
  1549. inherited create;
  1550. typ:=ait_stab;
  1551. stabtype:=_stabtype;
  1552. getmem(str,length(s)+1);
  1553. move(s[1],str^,length(s)+1);
  1554. end;
  1555. destructor tai_stab.destroy;
  1556. begin
  1557. freemem(str);
  1558. inherited destroy;
  1559. end;
  1560. {****************************************************************************
  1561. TAI_FORCE_LINE
  1562. ****************************************************************************}
  1563. constructor tai_force_line.create;
  1564. begin
  1565. inherited create;
  1566. typ:=ait_force_line;
  1567. end;
  1568. {****************************************************************************
  1569. TAI_FUNCTION_NAME
  1570. ****************************************************************************}
  1571. constructor tai_function_name.create(const s:string);
  1572. begin
  1573. inherited create;
  1574. typ:=ait_function_name;
  1575. funcname:=stringdup(s);
  1576. end;
  1577. destructor tai_function_name.destroy;
  1578. begin
  1579. stringdispose(funcname);
  1580. inherited destroy;
  1581. end;
  1582. {****************************************************************************
  1583. TAI_CUTOBJECT
  1584. ****************************************************************************}
  1585. constructor tai_cutobject.Create;
  1586. begin
  1587. inherited Create;
  1588. typ:=ait_cutobject;
  1589. place:=cut_normal;
  1590. end;
  1591. constructor tai_cutobject.Create_begin;
  1592. begin
  1593. inherited Create;
  1594. typ:=ait_cutobject;
  1595. place:=cut_begin;
  1596. end;
  1597. constructor tai_cutobject.Create_end;
  1598. begin
  1599. inherited Create;
  1600. typ:=ait_cutobject;
  1601. place:=cut_end;
  1602. end;
  1603. constructor tai_cutobject.ppuload(t:taitype;ppufile:tcompilerppufile);
  1604. begin
  1605. inherited ppuload(t,ppufile);
  1606. place:=TCutPlace(ppufile.getbyte);
  1607. end;
  1608. procedure tai_cutobject.ppuwrite(ppufile:tcompilerppufile);
  1609. begin
  1610. inherited ppuwrite(ppufile);
  1611. ppufile.putbyte(byte(place));
  1612. end;
  1613. {****************************************************************************
  1614. Tai_Marker
  1615. ****************************************************************************}
  1616. constructor Tai_Marker.Create(_Kind: TAsmMarker);
  1617. begin
  1618. Inherited Create;
  1619. typ := ait_marker;
  1620. Kind := _Kind;
  1621. end;
  1622. constructor Tai_Marker.ppuload(t:taitype;ppufile:tcompilerppufile);
  1623. begin
  1624. inherited ppuload(t,ppufile);
  1625. kind:=TAsmMarker(ppufile.getbyte);
  1626. end;
  1627. procedure Tai_Marker.ppuwrite(ppufile:tcompilerppufile);
  1628. begin
  1629. inherited ppuwrite(ppufile);
  1630. ppufile.putbyte(byte(kind));
  1631. end;
  1632. {*****************************************************************************
  1633. tai_tempalloc
  1634. *****************************************************************************}
  1635. constructor tai_tempalloc.alloc(pos,size:longint);
  1636. begin
  1637. inherited Create;
  1638. typ:=ait_tempalloc;
  1639. allocation:=true;
  1640. temppos:=pos;
  1641. tempsize:=size;
  1642. {$ifdef EXTDEBUG}
  1643. problem:=nil;
  1644. {$endif EXTDEBUG}
  1645. end;
  1646. destructor tai_tempalloc.destroy;
  1647. begin
  1648. {$ifdef EXTDEBUG}
  1649. stringdispose(problem);
  1650. {$endif EXTDEBUG}
  1651. inherited destroy;
  1652. end;
  1653. constructor tai_tempalloc.dealloc(pos,size:longint);
  1654. begin
  1655. inherited Create;
  1656. typ:=ait_tempalloc;
  1657. allocation:=false;
  1658. temppos:=pos;
  1659. tempsize:=size;
  1660. {$ifdef EXTDEBUG}
  1661. problem:=nil;
  1662. {$endif EXTDEBUG}
  1663. end;
  1664. {$ifdef EXTDEBUG}
  1665. constructor tai_tempalloc.allocinfo(pos,size:longint;const st:string);
  1666. begin
  1667. inherited Create;
  1668. typ:=ait_tempalloc;
  1669. allocation:=false;
  1670. temppos:=pos;
  1671. tempsize:=size;
  1672. problem:=stringdup(st);
  1673. end;
  1674. {$endif EXTDEBUG}
  1675. constructor tai_tempalloc.ppuload(t:taitype;ppufile:tcompilerppufile);
  1676. begin
  1677. inherited ppuload(t,ppufile);
  1678. temppos:=ppufile.getlongint;
  1679. tempsize:=ppufile.getlongint;
  1680. allocation:=boolean(ppufile.getbyte);
  1681. {$ifdef EXTDEBUG}
  1682. problem:=nil;
  1683. {$endif EXTDEBUG}
  1684. end;
  1685. procedure tai_tempalloc.ppuwrite(ppufile:tcompilerppufile);
  1686. begin
  1687. inherited ppuwrite(ppufile);
  1688. ppufile.putlongint(temppos);
  1689. ppufile.putlongint(tempsize);
  1690. ppufile.putbyte(byte(allocation));
  1691. end;
  1692. {*****************************************************************************
  1693. tai_regalloc
  1694. *****************************************************************************}
  1695. constructor tai_regalloc.alloc(r : tregister;ainstr:tai);
  1696. begin
  1697. inherited create;
  1698. typ:=ait_regalloc;
  1699. ratype:=ra_alloc;
  1700. reg:=r;
  1701. { ainstr must be an instruction }
  1702. if assigned(ainstr) and
  1703. (ainstr.typ<>ait_instruction) then
  1704. internalerror(200411011);
  1705. instr:=ainstr;
  1706. end;
  1707. constructor tai_regalloc.dealloc(r : tregister;ainstr:tai);
  1708. begin
  1709. inherited create;
  1710. typ:=ait_regalloc;
  1711. ratype:=ra_dealloc;
  1712. reg:=r;
  1713. { ainstr must be an instruction }
  1714. if assigned(ainstr) and
  1715. (ainstr.typ<>ait_instruction) then
  1716. internalerror(200411012);
  1717. instr:=ainstr;
  1718. end;
  1719. constructor tai_regalloc.sync(r : tregister);
  1720. begin
  1721. inherited create;
  1722. typ:=ait_regalloc;
  1723. ratype:=ra_sync;
  1724. reg:=r;
  1725. end;
  1726. constructor tai_regalloc.resize(r : tregister);
  1727. begin
  1728. inherited create;
  1729. typ:=ait_regalloc;
  1730. ratype:=ra_resize;
  1731. reg:=r;
  1732. end;
  1733. constructor tai_regalloc.ppuload(t:taitype;ppufile:tcompilerppufile);
  1734. begin
  1735. inherited ppuload(t,ppufile);
  1736. ppufile.getdata(reg,sizeof(Tregister));
  1737. ratype:=tregalloctype(ppufile.getbyte);
  1738. keep:=boolean(ppufile.getbyte);
  1739. end;
  1740. procedure tai_regalloc.ppuwrite(ppufile:tcompilerppufile);
  1741. begin
  1742. inherited ppuwrite(ppufile);
  1743. ppufile.putdata(reg,sizeof(Tregister));
  1744. ppufile.putbyte(byte(ratype));
  1745. ppufile.putbyte(byte(keep));
  1746. end;
  1747. {*****************************************************************************
  1748. TaiInstruction
  1749. *****************************************************************************}
  1750. constructor tai_cpu_abstract.Create(op : tasmop);
  1751. begin
  1752. inherited create;
  1753. typ:=ait_instruction;
  1754. is_jmp:=false;
  1755. opcode:=op;
  1756. ops:=0;
  1757. end;
  1758. destructor tai_cpu_abstract.Destroy;
  1759. var
  1760. i : integer;
  1761. begin
  1762. for i:=0 to opercnt-1 do
  1763. freeop(i);
  1764. inherited destroy;
  1765. end;
  1766. { ---------------------------------------------------------------------
  1767. Loading of operands.
  1768. ---------------------------------------------------------------------}
  1769. procedure tai_cpu_abstract.allocate_oper(opers:longint);
  1770. begin
  1771. while (opers>opercnt) do
  1772. begin
  1773. new(oper[opercnt]);
  1774. fillchar(oper[opercnt]^,sizeof(toper),0);
  1775. inc(opercnt);
  1776. end;
  1777. end;
  1778. procedure tai_cpu_abstract.loadconst(opidx:longint;l:aint);
  1779. begin
  1780. allocate_oper(opidx+1);
  1781. with oper[opidx]^ do
  1782. begin
  1783. if typ<>top_const then
  1784. clearop(opidx);
  1785. val:=l;
  1786. typ:=top_const;
  1787. end;
  1788. end;
  1789. procedure tai_cpu_abstract.loadsymbol(opidx:longint;s:tasmsymbol;sofs:longint);
  1790. var
  1791. r : treference;
  1792. begin
  1793. reference_reset_symbol(r,s,sofs,1);
  1794. r.refaddr:=addr_full;
  1795. loadref(opidx,r);
  1796. end;
  1797. procedure tai_cpu_abstract.loadlocal(opidx:longint;s:pointer;sofs:longint;indexreg:tregister;scale:byte;getoffset,forceref:boolean);
  1798. begin
  1799. if not assigned(s) then
  1800. internalerror(200204251);
  1801. allocate_oper(opidx+1);
  1802. with oper[opidx]^ do
  1803. begin
  1804. if typ<>top_local then
  1805. begin
  1806. clearop(opidx);
  1807. new(localoper);
  1808. end;
  1809. with oper[opidx]^.localoper^ do
  1810. begin
  1811. localsym:=s;
  1812. localsymofs:=sofs;
  1813. localindexreg:=indexreg;
  1814. localscale:=scale;
  1815. localgetoffset:=getoffset;
  1816. localforceref:=forceref;
  1817. end;
  1818. typ:=top_local;
  1819. end;
  1820. end;
  1821. procedure tai_cpu_abstract.loadref(opidx:longint;const r:treference);
  1822. begin
  1823. allocate_oper(opidx+1);
  1824. with oper[opidx]^ do
  1825. begin
  1826. if typ<>top_ref then
  1827. begin
  1828. clearop(opidx);
  1829. new(ref);
  1830. end;
  1831. ref^:=r;
  1832. {$ifdef x86}
  1833. { We allow this exception for x86, since overloading this would be
  1834. too much of a a speed penalty}
  1835. if (ref^.segment<>NR_NO) and (ref^.segment<>NR_DS) then
  1836. segprefix:=ref^.segment;
  1837. {$endif}
  1838. if (cs_create_pic in current_settings.moduleswitches) and
  1839. assigned(r.symbol) and
  1840. not assigned(r.relsymbol) and
  1841. (r.refaddr=addr_no)
  1842. {$ifdef ARM}
  1843. and not(r.base=NR_R15)
  1844. {$endif ARM}
  1845. then
  1846. internalerror(200502052);
  1847. typ:=top_ref;
  1848. if assigned(add_reg_instruction_hook) then
  1849. begin
  1850. add_reg_instruction_hook(self,ref^.base);
  1851. add_reg_instruction_hook(self,ref^.index);
  1852. end;
  1853. { mark symbol as used }
  1854. if assigned(ref^.symbol) then
  1855. ref^.symbol.increfs;
  1856. if assigned(ref^.relsymbol) then
  1857. ref^.relsymbol.increfs;
  1858. end;
  1859. end;
  1860. procedure tai_cpu_abstract.loadreg(opidx:longint;r:tregister);
  1861. begin
  1862. allocate_oper(opidx+1);
  1863. with oper[opidx]^ do
  1864. begin
  1865. if typ<>top_reg then
  1866. clearop(opidx);
  1867. reg:=r;
  1868. typ:=top_reg;
  1869. end;
  1870. if assigned(add_reg_instruction_hook) then
  1871. add_reg_instruction_hook(self,r);
  1872. {$ifdef ARM}
  1873. { R15 is the PC on the ARM thus moves to R15 are jumps.
  1874. Due to speed considerations we don't use a virtual overridden method here.
  1875. Because the pc/r15 isn't handled by the reg. allocator this should never cause
  1876. problems with iregs getting r15.
  1877. }
  1878. is_jmp:=(opcode=A_MOV) and (opidx=0) and (r=NR_R15);
  1879. {$endif ARM}
  1880. end;
  1881. procedure tai_cpu_abstract.loadoper(opidx:longint;o:toper);
  1882. begin
  1883. allocate_oper(opidx+1);
  1884. clearop(opidx);
  1885. oper[opidx]^:=o;
  1886. { copy also the reference }
  1887. with oper[opidx]^ do
  1888. begin
  1889. case typ of
  1890. top_reg:
  1891. begin
  1892. if assigned(add_reg_instruction_hook) then
  1893. add_reg_instruction_hook(self,reg);
  1894. end;
  1895. top_ref:
  1896. begin
  1897. new(ref);
  1898. ref^:=o.ref^;
  1899. {$ifdef x86}
  1900. if (ref^.segment<>NR_NO) and (ref^.segment<>NR_DS) then
  1901. segprefix:=ref^.segment;
  1902. {$endif x86}
  1903. if assigned(add_reg_instruction_hook) then
  1904. begin
  1905. add_reg_instruction_hook(self,ref^.base);
  1906. add_reg_instruction_hook(self,ref^.index);
  1907. end;
  1908. end;
  1909. {$ifdef ARM}
  1910. top_shifterop:
  1911. begin
  1912. new(shifterop);
  1913. shifterop^:=o.shifterop^;
  1914. if assigned(add_reg_instruction_hook) then
  1915. add_reg_instruction_hook(self,shifterop^.rs);
  1916. end;
  1917. {$endif ARM}
  1918. end;
  1919. end;
  1920. end;
  1921. procedure tai_cpu_abstract.clearop(opidx:longint);
  1922. begin
  1923. with oper[opidx]^ do
  1924. begin
  1925. case typ of
  1926. top_ref:
  1927. dispose(ref);
  1928. top_local:
  1929. dispose(localoper);
  1930. {$ifdef ARM}
  1931. top_shifterop:
  1932. dispose(shifterop);
  1933. top_regset:
  1934. dispose(regset);
  1935. {$endif ARM}
  1936. {$ifdef jvm}
  1937. top_string:
  1938. freemem(pcval);
  1939. top_wstring:
  1940. donewidestring(pwstrval);
  1941. {$endif jvm}
  1942. end;
  1943. typ:=top_none;
  1944. end;
  1945. end;
  1946. procedure tai_cpu_abstract.freeop(opidx:longint);
  1947. begin
  1948. clearop(opidx);
  1949. dispose(oper[opidx]);
  1950. end;
  1951. { ---------------------------------------------------------------------
  1952. Miscellaneous methods.
  1953. ---------------------------------------------------------------------}
  1954. procedure tai_cpu_abstract.SetCondition(const c:TAsmCond);
  1955. begin
  1956. condition:=c;
  1957. end;
  1958. Function tai_cpu_abstract.getcopy:TLinkedListItem;
  1959. var
  1960. i : longint;
  1961. p : tai_cpu_abstract;
  1962. begin
  1963. p:=tai_cpu_abstract(inherited getcopy);
  1964. { make a copy of the references }
  1965. p.opercnt:=0;
  1966. p.allocate_oper(ops);
  1967. for i:=0 to ops-1 do
  1968. begin
  1969. p.oper[i]^:=oper[i]^;
  1970. case oper[i]^.typ of
  1971. top_local :
  1972. begin
  1973. new(p.oper[i]^.localoper);
  1974. p.oper[i]^.localoper^:=oper[i]^.localoper^;
  1975. end;
  1976. top_ref :
  1977. begin
  1978. new(p.oper[i]^.ref);
  1979. p.oper[i]^.ref^:=oper[i]^.ref^;
  1980. end;
  1981. {$ifdef ARM}
  1982. top_shifterop:
  1983. begin
  1984. new(p.oper[i]^.shifterop);
  1985. p.oper[i]^.shifterop^:=oper[i]^.shifterop^;
  1986. end;
  1987. {$endif ARM}
  1988. end;
  1989. end;
  1990. getcopy:=p;
  1991. end;
  1992. function tai_cpu_abstract.is_same_reg_move(regtype: Tregistertype):boolean;
  1993. begin
  1994. { When the generic RA is used this needs to be overridden, we don't use
  1995. virtual;abstract; to prevent a lot of warnings of unimplemented abstract methods
  1996. when tai_cpu is created (PFV) }
  1997. internalerror(200404091);
  1998. result:=false;
  1999. end;
  2000. function tai_cpu_abstract.spilling_get_operation_type(opnr: longint): topertype;
  2001. begin
  2002. internalerror(200404091);
  2003. result:=operand_readwrite;
  2004. end;
  2005. function tai_cpu_abstract.spilling_get_operation_type_ref(opnr: longint; reg: tregister): topertype;
  2006. begin
  2007. result := operand_read;
  2008. end;
  2009. constructor tai_cpu_abstract.ppuload(t:taitype;ppufile:tcompilerppufile);
  2010. var
  2011. i : integer;
  2012. begin
  2013. inherited ppuload(t,ppufile);
  2014. { hopefully, we don't get problems with big/litte endian here when cross compiling :/ }
  2015. ppufile.getdata(condition,sizeof(tasmcond));
  2016. allocate_oper(ppufile.getbyte);
  2017. for i:=0 to ops-1 do
  2018. ppuloadoper(ppufile,oper[i]^);
  2019. opcode:=tasmop(ppufile.getword);
  2020. {$ifdef x86}
  2021. ppufile.getdata(segprefix,sizeof(Tregister));
  2022. {$endif x86}
  2023. is_jmp:=boolean(ppufile.getbyte);
  2024. end;
  2025. procedure tai_cpu_abstract.ppuwrite(ppufile:tcompilerppufile);
  2026. var
  2027. i : integer;
  2028. begin
  2029. inherited ppuwrite(ppufile);
  2030. ppufile.putdata(condition,sizeof(tasmcond));
  2031. ppufile.putbyte(ops);
  2032. for i:=0 to ops-1 do
  2033. ppuwriteoper(ppufile,oper[i]^);
  2034. ppufile.putword(word(opcode));
  2035. {$ifdef x86}
  2036. ppufile.putdata(segprefix,sizeof(Tregister));
  2037. {$endif x86}
  2038. ppufile.putbyte(byte(is_jmp));
  2039. end;
  2040. procedure tai_cpu_abstract.buildderefimpl;
  2041. var
  2042. i : integer;
  2043. begin
  2044. for i:=0 to ops-1 do
  2045. ppubuildderefimploper(oper[i]^);
  2046. end;
  2047. procedure tai_cpu_abstract.derefimpl;
  2048. var
  2049. i : integer;
  2050. begin
  2051. for i:=0 to ops-1 do
  2052. ppuderefoper(oper[i]^);
  2053. end;
  2054. procedure tai_cpu_abstract.resetpass1;
  2055. begin
  2056. end;
  2057. procedure tai_cpu_abstract.resetpass2;
  2058. begin
  2059. end;
  2060. function tai_cpu_abstract.Pass1(objdata:TObjData):longint;
  2061. begin
  2062. result:=0;
  2063. end;
  2064. procedure tai_cpu_abstract.Pass2(objdata:TObjData);
  2065. begin
  2066. end;
  2067. procedure tai_cpu_abstract.ppuloadoper(ppufile:tcompilerppufile;var o:toper);
  2068. begin
  2069. o.typ:=toptype(ppufile.getbyte);
  2070. o.ot:=ppufile.getlongint;
  2071. case o.typ of
  2072. top_reg :
  2073. ppufile.getdata(o.reg,sizeof(Tregister));
  2074. top_ref :
  2075. begin
  2076. new(o.ref);
  2077. {$ifdef x86}
  2078. ppufile.getdata(o.ref^.segment,sizeof(Tregister));
  2079. {$endif x86}
  2080. ppufile.getdata(o.ref^.base,sizeof(Tregister));
  2081. ppufile.getdata(o.ref^.index,sizeof(Tregister));
  2082. ppufile.getdata(o.ref^.refaddr,sizeof(o.ref^.refaddr));
  2083. o.ref^.scalefactor:=ppufile.getbyte;
  2084. o.ref^.offset:=ppufile.getaint;
  2085. o.ref^.symbol:=ppufile.getasmsymbol;
  2086. o.ref^.relsymbol:=ppufile.getasmsymbol;
  2087. end;
  2088. top_const :
  2089. o.val:=ppufile.getaint;
  2090. top_local :
  2091. begin
  2092. new(o.localoper);
  2093. with o.localoper^ do
  2094. begin
  2095. ppufile.getderef(localsymderef);
  2096. localsymofs:=ppufile.getaint;
  2097. localindexreg:=tregister(ppufile.getlongint);
  2098. localscale:=ppufile.getbyte;
  2099. localgetoffset:=(ppufile.getbyte<>0);
  2100. end;
  2101. end;
  2102. else
  2103. internalerror(2007010210);
  2104. end;
  2105. end;
  2106. procedure tai_cpu_abstract.ppuwriteoper(ppufile:tcompilerppufile;const o:toper);
  2107. begin
  2108. ppufile.putbyte(byte(o.typ));
  2109. ppufile.putlongint(o.ot);
  2110. case o.typ of
  2111. top_reg :
  2112. ppufile.putdata(o.reg,sizeof(Tregister));
  2113. top_ref :
  2114. begin
  2115. {$ifdef x86}
  2116. ppufile.putdata(o.ref^.segment,sizeof(Tregister));
  2117. {$endif x86}
  2118. ppufile.putdata(o.ref^.base,sizeof(Tregister));
  2119. ppufile.putdata(o.ref^.index,sizeof(Tregister));
  2120. ppufile.putdata(o.ref^.refaddr,sizeof(o.ref^.refaddr));
  2121. ppufile.putbyte(o.ref^.scalefactor);
  2122. ppufile.putaint(o.ref^.offset);
  2123. ppufile.putasmsymbol(o.ref^.symbol);
  2124. ppufile.putasmsymbol(o.ref^.relsymbol);
  2125. end;
  2126. top_const :
  2127. ppufile.putaint(o.val);
  2128. top_local :
  2129. begin
  2130. with o.localoper^ do
  2131. begin
  2132. ppufile.putderef(localsymderef);
  2133. ppufile.putaint(localsymofs);
  2134. ppufile.putlongint(longint(localindexreg));
  2135. ppufile.putbyte(localscale);
  2136. ppufile.putbyte(byte(localgetoffset));
  2137. end;
  2138. end;
  2139. else
  2140. internalerror(2007010211);
  2141. end;
  2142. end;
  2143. {****************************************************************************
  2144. tai_align_abstract
  2145. ****************************************************************************}
  2146. constructor tai_align_abstract.Create(b: byte);
  2147. begin
  2148. inherited Create;
  2149. typ:=ait_align;
  2150. {$ifdef EXTDEBUG}
  2151. if upper(classname)='TAI_ALIGN_ABSTRACT' then
  2152. internalerror(200709191);
  2153. {$endif EXTDEBUG}
  2154. if b in [1,2,4,8,16,32] then
  2155. aligntype := b
  2156. else
  2157. aligntype := 1;
  2158. fillsize:=0;
  2159. fillop:=0;
  2160. use_op:=false;
  2161. end;
  2162. constructor tai_align_abstract.Create_op(b: byte; _op: byte);
  2163. begin
  2164. inherited Create;
  2165. typ:=ait_align;
  2166. if b in [1,2,4,8,16,32] then
  2167. aligntype := b
  2168. else
  2169. aligntype := 1;
  2170. fillsize:=0;
  2171. fillop:=_op;
  2172. use_op:=true;
  2173. end;
  2174. constructor tai_align_abstract.Create_zeros(b: byte);
  2175. begin
  2176. inherited Create;
  2177. typ:=ait_align;
  2178. if b in [1,2,4,8,16,32] then
  2179. aligntype := b
  2180. else
  2181. aligntype := 1;
  2182. use_op:=true;
  2183. fillsize:=0;
  2184. fillop:=0;
  2185. end;
  2186. function tai_align_abstract.calculatefillbuf(var buf : tfillbuffer;executable : boolean):pchar;
  2187. begin
  2188. if fillsize>sizeof(buf) then
  2189. internalerror(200404293);
  2190. fillchar(buf,high(buf),fillop);
  2191. calculatefillbuf:=pchar(@buf);
  2192. end;
  2193. constructor tai_align_abstract.ppuload(t:taitype;ppufile:tcompilerppufile);
  2194. begin
  2195. inherited ppuload(t,ppufile);
  2196. aligntype:=ppufile.getbyte;
  2197. fillsize:=0;
  2198. fillop:=ppufile.getbyte;
  2199. use_op:=boolean(ppufile.getbyte);
  2200. end;
  2201. procedure tai_align_abstract.ppuwrite(ppufile:tcompilerppufile);
  2202. begin
  2203. inherited ppuwrite(ppufile);
  2204. ppufile.putbyte(aligntype);
  2205. ppufile.putbyte(fillop);
  2206. ppufile.putbyte(byte(use_op));
  2207. end;
  2208. {****************************************************************************
  2209. tai_seh_directive
  2210. ****************************************************************************}
  2211. const
  2212. datatypemap: array[TAsmSehDirective] of TSehDirectiveDatatype=(
  2213. sd_string, { proc }
  2214. sd_none, { endproc }
  2215. sd_none, { endprologue }
  2216. sd_string, { handler }
  2217. sd_none, { handlerdata }
  2218. sd_none,sd_none,sd_none, { eh, 32, no32 }
  2219. sd_regoffset, { setframe }
  2220. sd_offset, { stackalloc }
  2221. sd_reg, { pushreg }
  2222. sd_regoffset, { savereg }
  2223. sd_regoffset, { savexmm }
  2224. sd_none { pushframe }
  2225. );
  2226. constructor tai_seh_directive.create(_kind:TAsmSehDirective);
  2227. begin
  2228. inherited Create;
  2229. typ:=ait_seh_directive;
  2230. kind:=_kind;
  2231. data.typ:=datatypemap[_kind];
  2232. end;
  2233. constructor tai_seh_directive.create_name(_kind:TAsmSehDirective;const _name:string);
  2234. begin
  2235. create(_kind);
  2236. data.name:=stringdup(_name);
  2237. end;
  2238. constructor tai_seh_directive.create_reg(_kind:TAsmSehDirective;r:TRegister);
  2239. begin
  2240. create(_kind);
  2241. data.reg:=r;
  2242. end;
  2243. constructor tai_seh_directive.create_offset(_kind:TAsmSehDirective;ofs:dword);
  2244. begin
  2245. create(_kind);
  2246. data.offset:=ofs;
  2247. end;
  2248. constructor tai_seh_directive.create_reg_offset(_kind:TAsmSehDirective;
  2249. r:TRegister;ofs:dword);
  2250. begin
  2251. create(_kind);
  2252. data.offset:=ofs;
  2253. data.reg:=r;
  2254. end;
  2255. constructor tai_seh_directive.ppuload(t:taitype;ppufile:tcompilerppufile);
  2256. begin
  2257. inherited ppuload(t, ppufile);
  2258. kind:=TAsmSehDirective(ppufile.getbyte);
  2259. data.typ:=datatypemap[kind];
  2260. case data.typ of
  2261. sd_none: ;
  2262. sd_string:
  2263. begin
  2264. data.name:=stringdup(ppufile.getstring);
  2265. data.flags:=ppufile.getbyte;
  2266. end;
  2267. sd_reg,sd_offset,sd_regoffset:
  2268. begin
  2269. ppufile.getdata(data.reg,sizeof(TRegister));
  2270. data.offset:=ppufile.getdword;
  2271. end;
  2272. else
  2273. InternalError(2011091201);
  2274. end;
  2275. end;
  2276. destructor tai_seh_directive.destroy;
  2277. begin
  2278. if data.typ=sd_string then
  2279. stringdispose(data.name);
  2280. inherited destroy;
  2281. end;
  2282. procedure tai_seh_directive.ppuwrite(ppufile:tcompilerppufile);
  2283. begin
  2284. inherited ppuwrite(ppufile);
  2285. ppufile.putbyte(ord(kind));
  2286. case data.typ of
  2287. sd_none: ;
  2288. sd_string:
  2289. begin
  2290. ppufile.putstring(data.name^);
  2291. ppufile.putbyte(data.flags);
  2292. end;
  2293. sd_reg,sd_offset,sd_regoffset:
  2294. begin
  2295. ppufile.putdata(data.reg,sizeof(TRegister));
  2296. ppufile.putdword(data.offset);
  2297. end;
  2298. else
  2299. InternalError(2011091202);
  2300. end;
  2301. end;
  2302. procedure tai_seh_directive.generate_code(objdata:TObjData);
  2303. begin
  2304. end;
  2305. {****************************************************************************
  2306. tai_jvar
  2307. ****************************************************************************}
  2308. constructor tai_jvar.Create(_stackslot: longint; const _desc: shortstring; _startlab, _stoplab: TAsmSymbol);
  2309. begin
  2310. Inherited create;
  2311. typ:=ait_jvar;
  2312. stackslot:=_stackslot;
  2313. desc:=stringdup(_desc);
  2314. startlab:=_startlab;
  2315. stoplab:=_stoplab;
  2316. end;
  2317. constructor tai_jvar.ppuload(t: taitype; ppufile: tcompilerppufile);
  2318. begin
  2319. inherited ppuload(t, ppufile);
  2320. stackslot:=ppufile.getlongint;
  2321. desc:=stringdup(ppufile.getstring);
  2322. startlab:=ppufile.getasmsymbol;
  2323. stoplab:=ppufile.getasmsymbol;
  2324. end;
  2325. procedure tai_jvar.ppuwrite(ppufile: tcompilerppufile);
  2326. begin
  2327. inherited ppuwrite(ppufile);
  2328. ppufile.putlongint(stackslot);
  2329. ppufile.putstring(desc^);
  2330. ppufile.putasmsymbol(startlab);
  2331. ppufile.putasmsymbol(stoplab);
  2332. end;
  2333. destructor tai_jvar.destroy;
  2334. begin
  2335. stringdispose(desc);
  2336. inherited destroy;
  2337. end;
  2338. {****************************************************************************
  2339. tai_jcatch
  2340. ****************************************************************************}
  2341. constructor tai_jcatch.Create(const _name: shortstring; _startlab, _stoplab, _handlerlab: TAsmSymbol);
  2342. begin
  2343. Inherited create;
  2344. typ:=ait_jcatch;
  2345. name:=stringdup(_name);
  2346. startlab:=_startlab;
  2347. startlab.increfs;
  2348. stoplab:=_stoplab;
  2349. stoplab.increfs;
  2350. handlerlab:=_handlerlab;
  2351. handlerlab.increfs;
  2352. end;
  2353. destructor tai_jcatch.destroy;
  2354. begin
  2355. stringdispose(name);
  2356. inherited destroy;
  2357. end;
  2358. constructor tai_jcatch.ppuload(t: taitype; ppufile: tcompilerppufile);
  2359. begin
  2360. inherited ppuload(t, ppufile);
  2361. name:=stringdup(ppufile.getstring);
  2362. startlab:=ppufile.getasmsymbol;
  2363. startlab.increfs;
  2364. stoplab:=ppufile.getasmsymbol;
  2365. stoplab.increfs;
  2366. handlerlab:=ppufile.getasmsymbol;
  2367. handlerlab.increfs;
  2368. end;
  2369. procedure tai_jcatch.ppuwrite(ppufile: tcompilerppufile);
  2370. begin
  2371. inherited ppuwrite(ppufile);
  2372. ppufile.putstring(name^);
  2373. ppufile.putasmsymbol(startlab);
  2374. ppufile.putasmsymbol(stoplab);
  2375. ppufile.putasmsymbol(handlerlab);
  2376. end;
  2377. begin
  2378. {$push}{$warnings off}
  2379. { taitype should fit into a 4 byte set for speed reasons }
  2380. if ord(high(taitype))>31 then
  2381. internalerror(201108181);
  2382. {$pop}
  2383. end.