aasmtai.pas 68 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394
  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 overriden 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,globals,systems,
  28. cpuinfo,cpubase,
  29. cgbase,cgutils,
  30. symtype,
  31. aasmbase,aasmdata,ogbase;
  32. type
  33. { keep the number of elements in this enumeration less or equal than 32 as long
  34. as FPC knows only 4 byte and 32 byte sets (FK) }
  35. taitype = (
  36. ait_none,
  37. ait_align,
  38. ait_section,
  39. ait_comment,
  40. ait_string,
  41. ait_instruction,
  42. ait_datablock,
  43. ait_symbol,
  44. { needed to calc the size of a symbol }
  45. ait_symbol_end,
  46. ait_directive,
  47. ait_label,
  48. ait_const,
  49. ait_real_32bit,
  50. ait_real_64bit,
  51. ait_real_80bit,
  52. ait_comp_64bit,
  53. ait_real_128bit,
  54. ait_stab,
  55. ait_force_line,
  56. ait_function_name,
  57. {$ifdef alpha}
  58. { the follow is for the DEC Alpha }
  59. ait_frame,
  60. ait_ent,
  61. {$endif alpha}
  62. {$ifdef ia64}
  63. ait_bundle,
  64. ait_stop,
  65. {$endif ia64}
  66. {$ifdef m68k}
  67. ait_labeled_instruction,
  68. {$endif m68k}
  69. { used to split into tiny assembler files }
  70. ait_cutobject,
  71. ait_regalloc,
  72. ait_tempalloc,
  73. { used to mark assembler blocks and inlined functions }
  74. ait_marker,
  75. { new source file (dwarf) }
  76. ait_file,
  77. { new line/loc in source file (dwarf) }
  78. ait_loc
  79. );
  80. taiconst_type = (
  81. aitconst_128bit,
  82. aitconst_64bit,
  83. aitconst_32bit,
  84. aitconst_16bit,
  85. aitconst_8bit,
  86. aitconst_sleb128bit,
  87. aitconst_uleb128bit,
  88. { win32 only }
  89. aitconst_rva_symbol,
  90. { darwin only }
  91. aitconst_indirect_symbol
  92. );
  93. const
  94. {$ifdef cpu64bit}
  95. aitconst_aint = aitconst_64bit;
  96. aitconst_ptr = aitconst_64bit;
  97. {$else cpu64bit}
  98. aitconst_aint = aitconst_32bit;
  99. aitconst_ptr = aitconst_32bit;
  100. {$endif cpu64bit}
  101. taitypestr : array[taitype] of string[24] = (
  102. '<none>',
  103. 'align',
  104. 'section',
  105. 'comment',
  106. 'string',
  107. 'instruction',
  108. 'datablock',
  109. 'symbol',
  110. 'symbol_end',
  111. 'symbol_directive',
  112. 'label',
  113. 'const',
  114. 'real_32bit',
  115. 'real_64bit',
  116. 'real_80bit',
  117. 'comp_64bit',
  118. 'real_128bit',
  119. 'stab',
  120. 'force_line',
  121. 'function_name',
  122. {$ifdef alpha}
  123. { the follow is for the DEC Alpha }
  124. 'frame',
  125. 'ent',
  126. {$endif alpha}
  127. {$ifdef ia64}
  128. 'bundle',
  129. 'stop',
  130. {$endif ia64}
  131. {$ifdef m68k}
  132. 'labeled_instr',
  133. {$endif m68k}
  134. 'cut',
  135. 'regalloc',
  136. 'tempalloc',
  137. 'marker',
  138. 'file',
  139. 'line'
  140. );
  141. type
  142. { Types of operand }
  143. toptype=(top_none,top_reg,top_ref,top_const,top_bool,top_local
  144. {$ifdef arm}
  145. { ARM only }
  146. ,top_regset
  147. ,top_shifterop
  148. {$endif arm}
  149. {$ifdef m68k}
  150. { m68k only }
  151. ,top_regset
  152. {$endif m68k}
  153. { i386 only});
  154. { kinds of operations that an instruction can perform on an operand }
  155. topertype = (operand_read,operand_write,operand_readwrite);
  156. tlocaloper = record
  157. localsym : pointer;
  158. localsymderef : tderef;
  159. localsymofs : longint;
  160. localindexreg : tregister;
  161. localscale : byte;
  162. localgetoffset,
  163. localforceref : boolean
  164. end;
  165. plocaloper = ^tlocaloper;
  166. { please keep the size of this record <=12 bytes and keep it properly aligned }
  167. toper = record
  168. ot : longint;
  169. case typ : toptype of
  170. top_none : ();
  171. top_reg : (reg:tregister);
  172. top_ref : (ref:preference);
  173. top_const : (val:aint);
  174. top_bool : (b:boolean);
  175. { local varsym that will be inserted in pass_generate_code }
  176. top_local : (localoper:plocaloper);
  177. {$ifdef arm}
  178. top_regset : (regset:^tcpuregisterset);
  179. top_shifterop : (shifterop : pshifterop);
  180. {$endif arm}
  181. {$ifdef m68k}
  182. top_regset : (regset:^tcpuregisterset);
  183. {$endif m68k}
  184. end;
  185. poper=^toper;
  186. const
  187. { ait_* types which don't result in executable code or which don't influence
  188. the way the program runs/behaves, but which may be encountered by the
  189. optimizer (= if it's sometimes added to the exprasm list). Update if you add
  190. a new ait type! }
  191. SkipInstr = [ait_comment, ait_symbol,ait_section
  192. ,ait_stab, ait_function_name, ait_force_line
  193. ,ait_regalloc, ait_tempalloc, ait_symbol_end, ait_directive
  194. ,ait_file,ait_loc];
  195. { ait_* types which do not have line information (and hence which are of type
  196. tai, otherwise, they are of type tailineinfo }
  197. SkipLineInfo =[ait_label,
  198. ait_regalloc,ait_tempalloc,
  199. ait_stab,ait_function_name,
  200. ait_cutobject,ait_marker,ait_align,ait_section,ait_comment,
  201. ait_const,
  202. ait_real_32bit,ait_real_64bit,ait_real_80bit,ait_comp_64bit,ait_real_128bit,
  203. ait_file,ait_loc,ait_symbol
  204. ];
  205. type
  206. { cut type, required for alphanumeric ordering of the assembler filenames }
  207. TCutPlace=(cut_normal,cut_begin,cut_end);
  208. TAsmMarker = (
  209. mark_NoPropInfoStart,mark_NoPropInfoEnd,
  210. mark_AsmBlockStart,mark_AsmBlockEnd,
  211. mark_InlineStart,mark_InlineEnd,mark_BlockStart,
  212. mark_Position
  213. );
  214. TRegAllocType = (ra_alloc,ra_dealloc,ra_sync,ra_resize);
  215. TStabType = (stab_stabs,stab_stabn,stab_stabd);
  216. TAsmDirective=(
  217. asd_non_lazy_symbol_pointer,asd_indirect_symbol,asd_lazy_symbol_pointer,
  218. asd_extern,asd_nasm_import, asd_toc_entry, asd_mod_init_func, asd_mod_term_func,
  219. asd_reference,asd_no_dead_strip
  220. );
  221. const
  222. regallocstr : array[tregalloctype] of string[10]=('allocated','released','sync','resized');
  223. tempallocstr : array[boolean] of string[10]=('released','allocated');
  224. stabtypestr : array[TStabType] of string[5]=('stabs','stabn','stabd');
  225. directivestr : array[TAsmDirective] of string[23]=(
  226. 'non_lazy_symbol_pointer','indirect_symbol','lazy_symbol_pointer',
  227. 'extern','nasm_import', 'tc', 'mod_init_func', 'mod_term_func', 'reference',
  228. 'no_dead_strip'
  229. );
  230. type
  231. { abstract assembler item }
  232. tai = class(TLinkedListItem)
  233. {$ifndef NOOPT}
  234. { pointer to record with optimizer info about this tai object }
  235. optinfo : pointer;
  236. {$endif NOOPT}
  237. typ : taitype;
  238. constructor Create;
  239. constructor ppuload(t:taitype;ppufile:tcompilerppufile);virtual;
  240. procedure ppuwrite(ppufile:tcompilerppufile);virtual;
  241. procedure buildderefimpl;virtual;
  242. procedure derefimpl;virtual;
  243. end;
  244. { abstract assembler item with line information }
  245. tailineinfo = class(tai)
  246. fileinfo : tfileposinfo;
  247. constructor Create;
  248. constructor ppuload(t:taitype;ppufile:tcompilerppufile);override;
  249. procedure ppuwrite(ppufile:tcompilerppufile);override;
  250. end;
  251. tai_simple = class(tai)
  252. constructor create(_typ : taitype);
  253. end;
  254. taiclass = class of tai;
  255. taiclassarray = array[taitype] of taiclass;
  256. { Generates an assembler string }
  257. tai_string = class(tailineinfo)
  258. str : pchar;
  259. { extra len so the string can contain an \0 }
  260. len : longint;
  261. constructor Create(const _str : string);
  262. constructor Create_pchar(_str : pchar;length : longint);
  263. destructor Destroy;override;
  264. constructor ppuload(t:taitype;ppufile:tcompilerppufile);override;
  265. procedure ppuwrite(ppufile:tcompilerppufile);override;
  266. function getcopy:tlinkedlistitem;override;
  267. end;
  268. { Generates a common label }
  269. tai_symbol = class(tai)
  270. is_global : boolean;
  271. sym : tasmsymbol;
  272. size : longint;
  273. constructor Create(_sym:tasmsymbol;siz:longint);
  274. constructor Create_Global(_sym:tasmsymbol;siz:longint);
  275. constructor Createname(const _name : string;_symtyp:Tasmsymtype;siz:longint);
  276. constructor Createname_global(const _name : string;_symtyp:Tasmsymtype;siz:longint);
  277. constructor ppuload(t:taitype;ppufile:tcompilerppufile);override;
  278. procedure ppuwrite(ppufile:tcompilerppufile);override;
  279. procedure derefimpl;override;
  280. end;
  281. tai_symbol_end = class(tailineinfo)
  282. sym : tasmsymbol;
  283. constructor Create(_sym:tasmsymbol);
  284. constructor Createname(const _name : string);
  285. constructor ppuload(t:taitype;ppufile:tcompilerppufile);override;
  286. procedure ppuwrite(ppufile:tcompilerppufile);override;
  287. procedure derefimpl;override;
  288. end;
  289. tai_directive = class(tailineinfo)
  290. name : pshortstring;
  291. directive : TAsmDirective;
  292. constructor Create(_directive:TAsmDirective;const _name:string);
  293. destructor Destroy;override;
  294. constructor ppuload(t:taitype;ppufile:tcompilerppufile);override;
  295. procedure ppuwrite(ppufile:tcompilerppufile);override;
  296. end;
  297. { Generates an assembler label }
  298. tai_label = class(tai)
  299. is_global : boolean;
  300. labsym : tasmlabel;
  301. constructor Create(_labsym : tasmlabel);
  302. constructor ppuload(t:taitype;ppufile:tcompilerppufile);override;
  303. procedure ppuwrite(ppufile:tcompilerppufile);override;
  304. procedure derefimpl;override;
  305. end;
  306. { Generates an assembler comment }
  307. tai_comment = class(tai)
  308. str : pchar;
  309. constructor Create(_str : pchar);
  310. destructor Destroy; override;
  311. constructor ppuload(t:taitype;ppufile:tcompilerppufile);override;
  312. procedure ppuwrite(ppufile:tcompilerppufile);override;
  313. function getcopy:tlinkedlistitem;override;
  314. end;
  315. { Generates a section / segment directive }
  316. tai_section = class(tai)
  317. sectype : TAsmSectiontype;
  318. secorder : TasmSectionorder;
  319. secalign : byte;
  320. name : pshortstring;
  321. sec : TObjSection; { used in binary writer }
  322. constructor Create(Asectype:TAsmSectiontype;Aname:string;Aalign:byte;Asecorder:TasmSectionorder=secorder_default);
  323. destructor Destroy;override;
  324. constructor ppuload(t:taitype;ppufile:tcompilerppufile);override;
  325. procedure ppuwrite(ppufile:tcompilerppufile);override;
  326. end;
  327. { Generates an uninitializised data block }
  328. tai_datablock = class(tailineinfo)
  329. is_global : boolean;
  330. sym : tasmsymbol;
  331. size : longint;
  332. constructor Create(const _name : string;_size : longint);
  333. constructor Create_global(const _name : string;_size : longint);
  334. constructor ppuload(t:taitype;ppufile:tcompilerppufile);override;
  335. procedure ppuwrite(ppufile:tcompilerppufile);override;
  336. procedure derefimpl;override;
  337. end;
  338. { Generates an integer const }
  339. tai_const = class(tai)
  340. sym,
  341. endsym : tasmsymbol;
  342. value : int64;
  343. consttype : taiconst_type;
  344. { we use for the 128bit int64/qword for now because I can't imagine a
  345. case where we need 128 bit now (FK) }
  346. constructor Create(_typ:taiconst_type;_value : int64);
  347. constructor Create_128bit(_value : int64);
  348. constructor Create_64bit(_value : int64);
  349. constructor Create_32bit(_value : longint);
  350. constructor Create_16bit(_value : word);
  351. constructor Create_8bit(_value : byte);
  352. constructor Create_sleb128bit(_value : int64);
  353. constructor Create_uleb128bit(_value : qword);
  354. constructor Create_aint(_value : aint);
  355. constructor Create_sym(_sym:tasmsymbol);
  356. constructor Create_type_sym(_typ:taiconst_type;_sym:tasmsymbol);
  357. constructor Create_sym_offset(_sym:tasmsymbol;ofs:aint);
  358. constructor Create_rel_sym(_typ:taiconst_type;_sym,_endsym:tasmsymbol);
  359. constructor Create_rva_sym(_sym:tasmsymbol);
  360. constructor Create_indirect_sym(_sym:tasmsymbol);
  361. constructor Createname(const name:string;ofs:aint);
  362. constructor Createname_rva(const name:string);
  363. constructor ppuload(t:taitype;ppufile:tcompilerppufile);override;
  364. procedure ppuwrite(ppufile:tcompilerppufile);override;
  365. procedure derefimpl;override;
  366. function getcopy:tlinkedlistitem;override;
  367. function size:longint;
  368. end;
  369. { Generates a single float (32 bit real) }
  370. tai_real_32bit = class(tai)
  371. value : ts32real;
  372. constructor Create(_value : ts32real);
  373. constructor ppuload(t:taitype;ppufile:tcompilerppufile);override;
  374. procedure ppuwrite(ppufile:tcompilerppufile);override;
  375. end;
  376. tformatoptions = (fo_none,fo_hiloswapped);
  377. { Generates a double float (64 bit real) }
  378. tai_real_64bit = class(tai)
  379. value : ts64real;
  380. {$ifdef ARM}
  381. formatoptions : tformatoptions;
  382. constructor Create_hiloswapped(_value : ts64real);
  383. {$endif ARM}
  384. constructor Create(_value : ts64real);
  385. constructor ppuload(t:taitype;ppufile:tcompilerppufile);override;
  386. procedure ppuwrite(ppufile:tcompilerppufile);override;
  387. end;
  388. { Generates an extended float (80 bit real) }
  389. tai_real_80bit = class(tai)
  390. value : ts80real;
  391. constructor Create(_value : ts80real);
  392. constructor ppuload(t:taitype;ppufile:tcompilerppufile);override;
  393. procedure ppuwrite(ppufile:tcompilerppufile);override;
  394. end;
  395. { Generates an float128 (128 bit real) }
  396. tai_real_128bit = class(tai)
  397. value : ts128real;
  398. constructor Create(_value : ts128real);
  399. constructor ppuload(t:taitype;ppufile:tcompilerppufile);override;
  400. procedure ppuwrite(ppufile:tcompilerppufile);override;
  401. end;
  402. { Generates a comp int (integer over 64 bits)
  403. This is Intel 80x86 specific, and is not
  404. really supported on other processors.
  405. }
  406. tai_comp_64bit = class(tai)
  407. value : ts64comp;
  408. constructor Create(_value : ts64comp);
  409. constructor ppuload(t:taitype;ppufile:tcompilerppufile);override;
  410. procedure ppuwrite(ppufile:tcompilerppufile);override;
  411. end;
  412. tai_stab = class(tai)
  413. str : pchar;
  414. stabtype : TStabType;
  415. constructor Create(_stabtype:TStabType;_str : pchar);
  416. constructor Create_str(_stabtype:TStabType;const s:string);
  417. destructor Destroy;override;
  418. end;
  419. tai_force_line = class(tailineinfo)
  420. constructor Create;
  421. end;
  422. tai_function_name = class(tai)
  423. funcname : pshortstring;
  424. constructor create(const s:string);
  425. destructor destroy;override;
  426. end;
  427. { Insert a cut to split assembler into several smaller files }
  428. tai_cutobject = class(tai)
  429. place : tcutplace;
  430. constructor Create;
  431. constructor Create_begin;
  432. constructor Create_end;
  433. constructor ppuload(t:taitype;ppufile:tcompilerppufile);override;
  434. procedure ppuwrite(ppufile:tcompilerppufile);override;
  435. end;
  436. { Insert a marker for assembler and inline blocks }
  437. tai_marker = class(tai)
  438. Kind: TAsmMarker;
  439. Constructor Create(_Kind: TAsmMarker);
  440. constructor ppuload(t:taitype;ppufile:tcompilerppufile);override;
  441. procedure ppuwrite(ppufile:tcompilerppufile);override;
  442. end;
  443. tai_tempalloc = class(tai)
  444. allocation : boolean;
  445. {$ifdef EXTDEBUG}
  446. problem : pshortstring;
  447. {$endif EXTDEBUG}
  448. temppos,
  449. tempsize : longint;
  450. constructor alloc(pos,size:longint);
  451. constructor dealloc(pos,size:longint);
  452. {$ifdef EXTDEBUG}
  453. constructor allocinfo(pos,size:longint;const st:string);
  454. {$endif EXTDEBUG}
  455. constructor ppuload(t:taitype;ppufile:tcompilerppufile);override;
  456. destructor destroy;override;
  457. procedure ppuwrite(ppufile:tcompilerppufile);override;
  458. end;
  459. tai_regalloc = class(tai)
  460. reg : tregister;
  461. ratype : TRegAllocType;
  462. { reg(de)alloc belongs to this instruction, this
  463. is only used for automatic inserted (de)alloc for
  464. imaginary register and required for spilling code }
  465. instr : tai;
  466. constructor alloc(r : tregister;ainstr:tai);
  467. constructor dealloc(r : tregister;ainstr:tai);
  468. constructor sync(r : tregister);
  469. constructor resize(r : tregister);
  470. constructor ppuload(t:taitype;ppufile:tcompilerppufile);override;
  471. procedure ppuwrite(ppufile:tcompilerppufile);override;
  472. end;
  473. { Generates a dwarf file location }
  474. tai_file = class(tai)
  475. str : pchar;
  476. idx : longint;
  477. constructor Create(_str : string);
  478. destructor Destroy; override;
  479. constructor ppuload(t:taitype;ppufile:tcompilerppufile);override;
  480. procedure ppuwrite(ppufile:tcompilerppufile);override;
  481. function getcopy:tlinkedlistitem;override;
  482. end;
  483. { Generates a dwarf line location }
  484. tai_loc = class(tai)
  485. fileentry : tai_file;
  486. line,
  487. column : longint;
  488. constructor Create(_fileidx : tai_file;_line,_column : longint);
  489. constructor ppuload(t:taitype;ppufile:tcompilerppufile);override;
  490. procedure ppuwrite(ppufile:tcompilerppufile);override;
  491. end;
  492. tadd_reg_instruction_proc=procedure(instr:Tai;r:tregister) of object;
  493. { Class template for assembler instructions
  494. }
  495. tai_cpu_abstract = class(tailineinfo)
  496. protected
  497. procedure ppuloadoper(ppufile:tcompilerppufile;var o:toper);virtual;abstract;
  498. procedure ppuwriteoper(ppufile:tcompilerppufile;const o:toper);virtual;abstract;
  499. procedure ppubuildderefimploper(var o:toper);virtual;abstract;
  500. procedure ppuderefoper(var o:toper);virtual;abstract;
  501. public
  502. { Condition flags for instruction }
  503. condition : TAsmCond;
  504. { Number of operands to instruction }
  505. ops : byte;
  506. { Number of allocate oper structures }
  507. opercnt : byte;
  508. { Operands of instruction }
  509. oper : array[0..max_operands-1] of poper;
  510. { Actual opcode of instruction }
  511. opcode : tasmop;
  512. {$ifdef x86}
  513. segprefix : tregister;
  514. {$endif x86}
  515. { true if instruction is a jmp }
  516. is_jmp : boolean; { is this instruction a jump? (needed for optimizer) }
  517. Constructor Create(op : tasmop);virtual;
  518. Destructor Destroy;override;
  519. function getcopy:TLinkedListItem;override;
  520. constructor ppuload(t:taitype;ppufile:tcompilerppufile);override;
  521. procedure ppuwrite(ppufile:tcompilerppufile);override;
  522. procedure buildderefimpl;override;
  523. procedure derefimpl;override;
  524. procedure SetCondition(const c:TAsmCond);
  525. procedure allocate_oper(opers:longint);
  526. procedure loadconst(opidx:longint;l:aint);
  527. procedure loadsymbol(opidx:longint;s:tasmsymbol;sofs:longint);
  528. procedure loadlocal(opidx:longint;s:pointer;sofs:longint;indexreg:tregister;scale:byte;getoffset,forceref:boolean);
  529. procedure loadref(opidx:longint;const r:treference);
  530. procedure loadreg(opidx:longint;r:tregister);
  531. procedure loadoper(opidx:longint;o:toper);
  532. procedure clearop(opidx:longint);
  533. { register allocator }
  534. function is_same_reg_move(regtype: Tregistertype):boolean;virtual;
  535. function spilling_get_operation_type(opnr: longint): topertype;virtual;
  536. function spilling_get_operation_type_ref(opnr: longint; reg: tregister): topertype;virtual;
  537. function Pass1(objdata:TObjData):longint;virtual;abstract;
  538. procedure Pass2(objdata:TObjData);virtual;abstract;
  539. procedure resetpass1; virtual;
  540. procedure resetpass2; virtual;
  541. end;
  542. tai_cpu_class = class of tai_cpu_abstract;
  543. { Buffer type used for alignment }
  544. tfillbuffer = array[0..63] of char;
  545. { alignment for operator }
  546. tai_align_abstract = class(tai)
  547. aligntype : byte; { 1 = no align, 2 = word align, 4 = dword align }
  548. fillsize : byte; { real size to fill }
  549. fillop : byte; { value to fill with - optional }
  550. use_op : boolean;
  551. constructor Create(b:byte);virtual;
  552. constructor Create_op(b: byte; _op: byte);virtual;
  553. constructor Create_zeros(b:byte);
  554. constructor ppuload(t:taitype;ppufile:tcompilerppufile);override;
  555. procedure ppuwrite(ppufile:tcompilerppufile);override;
  556. function calculatefillbuf(var buf : tfillbuffer):pchar;virtual;
  557. end;
  558. tai_align_class = class of tai_align_abstract;
  559. var
  560. { array with all class types for tais }
  561. aiclass : taiclassarray;
  562. { target specific tais }
  563. cai_align : tai_align_class;
  564. cai_cpu : tai_cpu_class;
  565. { hook to notify uses of registers }
  566. add_reg_instruction_hook : tadd_reg_instruction_proc;
  567. procedure maybe_new_object_file(list:TAsmList);
  568. procedure new_section(list:TAsmList;Asectype:TAsmSectiontype;Aname:string;Aalign:byte;Asecorder:TasmSectionorder=secorder_default);
  569. procedure section_symbol_start(list:TAsmList;const Aname:string;Asymtyp:Tasmsymtype;
  570. Aglobal:boolean;Asectype:TAsmSectiontype;Aalign:byte);
  571. procedure section_symbol_end(list:TAsmList;const Aname:string);
  572. function ppuloadai(ppufile:tcompilerppufile):tai;
  573. procedure ppuwriteai(ppufile:tcompilerppufile;n:tai);
  574. implementation
  575. uses
  576. SysUtils,
  577. verbose;
  578. const
  579. pputaimarker = 254;
  580. {****************************************************************************
  581. Helpers
  582. ****************************************************************************}
  583. procedure maybe_new_object_file(list:TAsmList);
  584. begin
  585. if (cs_create_smart in current_settings.moduleswitches) and
  586. (not use_smartlink_section) then
  587. list.concat(tai_cutobject.create);
  588. end;
  589. procedure new_section(list:TAsmList;Asectype:TAsmSectiontype;Aname:string;Aalign:byte;Asecorder:TasmSectionorder=secorder_default);
  590. begin
  591. list.concat(tai_section.create(Asectype,Aname,Aalign,Asecorder));
  592. list.concat(cai_align.create(Aalign));
  593. end;
  594. procedure section_symbol_start(list:TAsmList;const Aname:string;Asymtyp:Tasmsymtype;
  595. Aglobal:boolean;Asectype:TAsmSectiontype;Aalign:byte);
  596. begin
  597. maybe_new_object_file(list);
  598. list.concat(tai_section.create(Asectype,Aname,Aalign));
  599. list.concat(cai_align.create(Aalign));
  600. if Aglobal or
  601. maybe_smartlink_symbol then
  602. list.concat(tai_symbol.createname_global(Aname,Asymtyp,0))
  603. else
  604. list.concat(tai_symbol.createname(Aname,Asymtyp,0));
  605. end;
  606. procedure section_symbol_end(list:TAsmList;const Aname:string);
  607. begin
  608. list.concat(tai_symbol_end.createname(Aname));
  609. end;
  610. function ppuloadai(ppufile:tcompilerppufile):tai;
  611. var
  612. b : byte;
  613. t : taitype;
  614. begin
  615. { marker }
  616. b:=ppufile.getbyte;
  617. if b<>pputaimarker then
  618. internalerror(200208181);
  619. { load nodetype }
  620. t:=taitype(ppufile.getbyte);
  621. if t<>ait_none then
  622. begin
  623. if t>high(taitype) then
  624. internalerror(200208182);
  625. if not assigned(aiclass[t]) then
  626. internalerror(200208183);
  627. {writeln('taiload: ',taitypestr[t]);}
  628. { generate tai of the correct class }
  629. ppuloadai:=aiclass[t].ppuload(t,ppufile);
  630. end
  631. else
  632. ppuloadai:=nil;
  633. end;
  634. procedure ppuwriteai(ppufile:tcompilerppufile;n:tai);
  635. begin
  636. { marker, read by ppuloadnode }
  637. ppufile.putbyte(pputaimarker);
  638. if assigned(n) then
  639. begin
  640. { type, read by ppuloadnode }
  641. ppufile.putbyte(byte(n.typ));
  642. {writeln('taiwrite: ',taitypestr[n.typ]);}
  643. n.ppuwrite(ppufile);
  644. end
  645. else
  646. ppufile.putbyte(byte(ait_none));
  647. end;
  648. {****************************************************************************
  649. TAI
  650. ****************************************************************************}
  651. constructor tai.Create;
  652. begin
  653. {$ifndef NOOPT}
  654. optinfo:=nil;
  655. {$endif NOOPT}
  656. end;
  657. constructor tai.ppuload(t:taitype;ppufile:tcompilerppufile);
  658. begin
  659. typ:=t;
  660. {$ifndef NOOPT}
  661. optinfo:=nil;
  662. {$endif}
  663. end;
  664. procedure tai.ppuwrite(ppufile:tcompilerppufile);
  665. begin
  666. end;
  667. procedure tai.buildderefimpl;
  668. begin
  669. end;
  670. procedure tai.derefimpl;
  671. begin
  672. end;
  673. {****************************************************************************
  674. TAILINEINFO
  675. ****************************************************************************}
  676. constructor tailineinfo.create;
  677. begin
  678. inherited create;
  679. if not(inlining_procedure and
  680. (cs_gdb_valgrind in current_settings.globalswitches)) then
  681. fileinfo:=current_filepos;
  682. end;
  683. constructor tailineinfo.ppuload(t:taitype;ppufile:tcompilerppufile);
  684. begin
  685. inherited ppuload(t,ppufile);
  686. ppufile.getposinfo(fileinfo);
  687. end;
  688. procedure tailineinfo.ppuwrite(ppufile:tcompilerppufile);
  689. begin
  690. inherited ppuwrite(ppufile);
  691. ppufile.putposinfo(fileinfo);
  692. end;
  693. {****************************************************************************
  694. TAI_SIMPLE
  695. ****************************************************************************}
  696. constructor tai_simple.create(_typ : taitype);
  697. begin
  698. inherited create;
  699. typ:=_typ;
  700. end;
  701. {****************************************************************************
  702. TAI_SECTION
  703. ****************************************************************************}
  704. constructor tai_section.Create(Asectype:TAsmSectiontype;Aname:string;Aalign:byte;Asecorder:TasmSectionorder=secorder_default);
  705. begin
  706. inherited Create;
  707. typ:=ait_section;
  708. sectype:=asectype;
  709. secalign:=Aalign;
  710. secorder:=Asecorder;
  711. name:=stringdup(Aname);
  712. sec:=nil;
  713. end;
  714. constructor tai_section.ppuload(t:taitype;ppufile:tcompilerppufile);
  715. begin
  716. inherited ppuload(t,ppufile);
  717. sectype:=TAsmSectiontype(ppufile.getbyte);
  718. secalign:=ppufile.getbyte;
  719. name:=stringdup(ppufile.getstring);
  720. sec:=nil;
  721. end;
  722. destructor tai_section.Destroy;
  723. begin
  724. stringdispose(name);
  725. end;
  726. procedure tai_section.ppuwrite(ppufile:tcompilerppufile);
  727. begin
  728. inherited ppuwrite(ppufile);
  729. ppufile.putbyte(byte(sectype));
  730. ppufile.putbyte(secalign);
  731. ppufile.putstring(name^);
  732. end;
  733. {****************************************************************************
  734. TAI_DATABLOCK
  735. ****************************************************************************}
  736. constructor tai_datablock.Create(const _name : string;_size : longint);
  737. begin
  738. inherited Create;
  739. typ:=ait_datablock;
  740. sym:=current_asmdata.DefineAsmSymbol(_name,AB_LOCAL,AT_DATA);
  741. { keep things aligned }
  742. if _size<=0 then
  743. _size:=4;
  744. size:=_size;
  745. is_global:=false;
  746. end;
  747. constructor tai_datablock.Create_global(const _name : string;_size : longint);
  748. begin
  749. inherited Create;
  750. typ:=ait_datablock;
  751. sym:=current_asmdata.DefineAsmSymbol(_name,AB_GLOBAL,AT_DATA);
  752. { keep things aligned }
  753. if _size<=0 then
  754. _size:=4;
  755. size:=_size;
  756. is_global:=true;
  757. end;
  758. constructor tai_datablock.ppuload(t:taitype;ppufile:tcompilerppufile);
  759. begin
  760. inherited Create;
  761. sym:=ppufile.getasmsymbol;
  762. size:=ppufile.getlongint;
  763. is_global:=boolean(ppufile.getbyte);
  764. end;
  765. procedure tai_datablock.ppuwrite(ppufile:tcompilerppufile);
  766. begin
  767. inherited ppuwrite(ppufile);
  768. ppufile.putasmsymbol(sym);
  769. ppufile.putlongint(size);
  770. ppufile.putbyte(byte(is_global));
  771. end;
  772. procedure tai_datablock.derefimpl;
  773. begin
  774. end;
  775. {****************************************************************************
  776. TAI_SYMBOL
  777. ****************************************************************************}
  778. constructor tai_symbol.Create(_sym:tasmsymbol;siz:longint);
  779. begin
  780. inherited Create;
  781. typ:=ait_symbol;
  782. sym:=_sym;
  783. size:=siz;
  784. sym.bind:=AB_LOCAL;
  785. is_global:=false;
  786. end;
  787. constructor tai_symbol.Create_global(_sym:tasmsymbol;siz:longint);
  788. begin
  789. inherited Create;
  790. typ:=ait_symbol;
  791. sym:=_sym;
  792. size:=siz;
  793. sym.bind:=AB_GLOBAL;
  794. is_global:=true;
  795. end;
  796. constructor tai_symbol.Createname(const _name : string;_symtyp:Tasmsymtype;siz:longint);
  797. begin
  798. inherited Create;
  799. typ:=ait_symbol;
  800. sym:=current_asmdata.DefineAsmSymbol(_name,AB_LOCAL,_symtyp);
  801. size:=siz;
  802. is_global:=false;
  803. end;
  804. constructor tai_symbol.Createname_global(const _name : string;_symtyp:Tasmsymtype;siz:longint);
  805. begin
  806. inherited Create;
  807. typ:=ait_symbol;
  808. sym:=current_asmdata.DefineAsmSymbol(_name,AB_GLOBAL,_symtyp);
  809. size:=siz;
  810. is_global:=true;
  811. end;
  812. constructor tai_symbol.ppuload(t:taitype;ppufile:tcompilerppufile);
  813. begin
  814. inherited ppuload(t,ppufile);
  815. sym:=ppufile.getasmsymbol;
  816. size:=ppufile.getlongint;
  817. is_global:=boolean(ppufile.getbyte);
  818. end;
  819. procedure tai_symbol.ppuwrite(ppufile:tcompilerppufile);
  820. begin
  821. inherited ppuwrite(ppufile);
  822. ppufile.putasmsymbol(sym);
  823. ppufile.putlongint(size);
  824. ppufile.putbyte(byte(is_global));
  825. end;
  826. procedure tai_symbol.derefimpl;
  827. begin
  828. end;
  829. {****************************************************************************
  830. TAI_SYMBOL_END
  831. ****************************************************************************}
  832. constructor tai_symbol_end.Create(_sym:tasmsymbol);
  833. begin
  834. inherited Create;
  835. typ:=ait_symbol_end;
  836. sym:=_sym;
  837. end;
  838. constructor tai_symbol_end.Createname(const _name : string);
  839. begin
  840. inherited Create;
  841. typ:=ait_symbol_end;
  842. sym:=current_asmdata.RefAsmSymbol(_name);
  843. end;
  844. constructor tai_symbol_end.ppuload(t:taitype;ppufile:tcompilerppufile);
  845. begin
  846. inherited ppuload(t,ppufile);
  847. sym:=ppufile.getasmsymbol;
  848. end;
  849. procedure tai_symbol_end.ppuwrite(ppufile:tcompilerppufile);
  850. begin
  851. inherited ppuwrite(ppufile);
  852. ppufile.putasmsymbol(sym);
  853. end;
  854. procedure tai_symbol_end.derefimpl;
  855. begin
  856. end;
  857. {****************************************************************************
  858. TAI_SYMBOL_END
  859. ****************************************************************************}
  860. constructor tai_directive.Create(_directive:TAsmDirective;const _name:string);
  861. begin
  862. inherited Create;
  863. typ:=ait_directive;
  864. name:=stringdup(_name);
  865. directive:=_directive;
  866. end;
  867. destructor tai_directive.Destroy;
  868. begin
  869. stringdispose(name);
  870. end;
  871. constructor tai_directive.ppuload(t:taitype;ppufile:tcompilerppufile);
  872. begin
  873. inherited ppuload(t,ppufile);
  874. name:=stringdup(ppufile.getstring);
  875. directive:=TAsmDirective(ppufile.getbyte);
  876. end;
  877. procedure tai_directive.ppuwrite(ppufile:tcompilerppufile);
  878. begin
  879. inherited ppuwrite(ppufile);
  880. ppufile.putstring(name^);
  881. ppufile.putbyte(byte(directive));
  882. end;
  883. {****************************************************************************
  884. TAI_CONST
  885. ****************************************************************************}
  886. constructor tai_const.Create(_typ:taiconst_type;_value : int64);
  887. begin
  888. inherited Create;
  889. typ:=ait_const;
  890. consttype:=_typ;
  891. value:=_value;
  892. sym:=nil;
  893. endsym:=nil;
  894. end;
  895. constructor tai_const.Create_128bit(_value : int64);
  896. begin
  897. inherited Create;
  898. typ:=ait_const;
  899. consttype:=aitconst_128bit;
  900. value:=_value;
  901. sym:=nil;
  902. endsym:=nil;
  903. end;
  904. constructor tai_const.Create_64bit(_value : int64);
  905. begin
  906. inherited Create;
  907. typ:=ait_const;
  908. consttype:=aitconst_64bit;
  909. value:=_value;
  910. sym:=nil;
  911. endsym:=nil;
  912. end;
  913. constructor tai_const.Create_32bit(_value : longint);
  914. begin
  915. inherited Create;
  916. typ:=ait_const;
  917. consttype:=aitconst_32bit;
  918. value:=_value;
  919. sym:=nil;
  920. endsym:=nil;
  921. end;
  922. constructor tai_const.Create_16bit(_value : word);
  923. begin
  924. inherited Create;
  925. typ:=ait_const;
  926. consttype:=aitconst_16bit;
  927. value:=_value;
  928. sym:=nil;
  929. endsym:=nil;
  930. end;
  931. constructor tai_const.Create_8bit(_value : byte);
  932. begin
  933. inherited Create;
  934. typ:=ait_const;
  935. consttype:=aitconst_8bit;
  936. value:=_value;
  937. sym:=nil;
  938. endsym:=nil;
  939. end;
  940. constructor tai_const.Create_sleb128bit(_value : int64);
  941. begin
  942. inherited Create;
  943. typ:=ait_const;
  944. consttype:=aitconst_sleb128bit;
  945. value:=_value;
  946. sym:=nil;
  947. endsym:=nil;
  948. end;
  949. constructor tai_const.Create_uleb128bit(_value : qword);
  950. begin
  951. inherited Create;
  952. typ:=ait_const;
  953. consttype:=aitconst_uleb128bit;
  954. value:=int64(_value);
  955. sym:=nil;
  956. endsym:=nil;
  957. end;
  958. constructor tai_const.Create_aint(_value : aint);
  959. begin
  960. inherited Create;
  961. typ:=ait_const;
  962. consttype:=aitconst_aint;
  963. value:=_value;
  964. sym:=nil;
  965. endsym:=nil;
  966. end;
  967. constructor tai_const.Create_type_sym(_typ:taiconst_type;_sym:tasmsymbol);
  968. begin
  969. inherited Create;
  970. typ:=ait_const;
  971. consttype:=_typ;
  972. sym:=_sym;
  973. endsym:=nil;
  974. value:=0;
  975. { update sym info }
  976. if assigned(sym) then
  977. sym.increfs;
  978. end;
  979. constructor tai_const.Create_sym(_sym:tasmsymbol);
  980. begin
  981. inherited Create;
  982. typ:=ait_const;
  983. consttype:=aitconst_ptr;
  984. { sym is allowed to be nil, this is used to write nil pointers }
  985. sym:=_sym;
  986. endsym:=nil;
  987. value:=0;
  988. { update sym info }
  989. if assigned(sym) then
  990. sym.increfs;
  991. end;
  992. constructor tai_const.Create_sym_offset(_sym:tasmsymbol;ofs:aint);
  993. begin
  994. inherited Create;
  995. typ:=ait_const;
  996. consttype:=aitconst_ptr;
  997. if not assigned(_sym) then
  998. internalerror(200404121);
  999. sym:=_sym;
  1000. endsym:=nil;
  1001. value:=ofs;
  1002. { update sym info }
  1003. sym.increfs;
  1004. end;
  1005. constructor tai_const.Create_rel_sym(_typ:taiconst_type;_sym,_endsym:tasmsymbol);
  1006. begin
  1007. inherited Create;
  1008. typ:=ait_const;
  1009. consttype:=_typ;
  1010. sym:=_sym;
  1011. endsym:=_endsym;
  1012. value:=0;
  1013. { update sym info }
  1014. sym.increfs;
  1015. endsym.increfs;
  1016. end;
  1017. constructor tai_const.Create_rva_sym(_sym:tasmsymbol);
  1018. begin
  1019. inherited Create;
  1020. typ:=ait_const;
  1021. consttype:=aitconst_rva_symbol;
  1022. sym:=_sym;
  1023. endsym:=nil;
  1024. value:=0;
  1025. { update sym info }
  1026. sym.increfs;
  1027. end;
  1028. constructor tai_const.Create_indirect_sym(_sym:tasmsymbol);
  1029. begin
  1030. inherited Create;
  1031. typ:=ait_const;
  1032. consttype:=aitconst_indirect_symbol;
  1033. sym:=_sym;
  1034. endsym:=nil;
  1035. value:=0;
  1036. { update sym info }
  1037. sym.increfs;
  1038. end;
  1039. constructor tai_const.Createname(const name:string;ofs:aint);
  1040. begin
  1041. inherited Create;
  1042. typ:=ait_const;
  1043. consttype:=aitconst_ptr;
  1044. sym:=current_asmdata.RefAsmSymbol(name);
  1045. endsym:=nil;
  1046. value:=ofs;
  1047. { update sym info }
  1048. sym.increfs;
  1049. end;
  1050. constructor tai_const.Createname_rva(const name:string);
  1051. begin
  1052. inherited Create;
  1053. typ:=ait_const;
  1054. consttype:=aitconst_rva_symbol;
  1055. sym:=current_asmdata.RefAsmSymbol(name);
  1056. endsym:=nil;
  1057. value:=0;
  1058. { update sym info }
  1059. sym.increfs;
  1060. end;
  1061. constructor tai_const.ppuload(t:taitype;ppufile:tcompilerppufile);
  1062. begin
  1063. inherited ppuload(t,ppufile);
  1064. consttype:=taiconst_type(ppufile.getbyte);
  1065. sym:=ppufile.getasmsymbol;
  1066. endsym:=ppufile.getasmsymbol;
  1067. value:=ppufile.getint64;
  1068. end;
  1069. procedure tai_const.ppuwrite(ppufile:tcompilerppufile);
  1070. begin
  1071. inherited ppuwrite(ppufile);
  1072. ppufile.putbyte(byte(consttype));
  1073. ppufile.putasmsymbol(sym);
  1074. ppufile.putasmsymbol(endsym);
  1075. ppufile.putint64(value);
  1076. end;
  1077. procedure tai_const.derefimpl;
  1078. begin
  1079. end;
  1080. function tai_const.getcopy:tlinkedlistitem;
  1081. begin
  1082. getcopy:=inherited getcopy;
  1083. { we need to increase the reference number }
  1084. sym.increfs;
  1085. if assigned(endsym) then
  1086. endsym.increfs;
  1087. end;
  1088. function tai_const.size:longint;
  1089. begin
  1090. case consttype of
  1091. aitconst_8bit :
  1092. result:=1;
  1093. aitconst_16bit :
  1094. result:=2;
  1095. aitconst_32bit :
  1096. result:=4;
  1097. aitconst_64bit :
  1098. result:=8;
  1099. aitconst_indirect_symbol,
  1100. aitconst_rva_symbol :
  1101. if target_info.system=system_x86_64_win64 then
  1102. result:=sizeof(longint)
  1103. else
  1104. result:=sizeof(aint);
  1105. aitconst_uleb128bit :
  1106. result:=LengthUleb128(value);
  1107. aitconst_sleb128bit :
  1108. result:=LengthSleb128(value);
  1109. else
  1110. internalerror(200603253);
  1111. end;
  1112. end;
  1113. {****************************************************************************
  1114. TAI_real_32bit
  1115. ****************************************************************************}
  1116. constructor tai_real_32bit.Create(_value : ts32real);
  1117. begin
  1118. inherited Create;
  1119. typ:=ait_real_32bit;
  1120. value:=_value;
  1121. end;
  1122. constructor tai_real_32bit.ppuload(t:taitype;ppufile:tcompilerppufile);
  1123. begin
  1124. inherited ppuload(t,ppufile);
  1125. value:=ppufile.getreal;
  1126. end;
  1127. procedure tai_real_32bit.ppuwrite(ppufile:tcompilerppufile);
  1128. begin
  1129. inherited ppuwrite(ppufile);
  1130. ppufile.putreal(value);
  1131. end;
  1132. {****************************************************************************
  1133. TAI_real_64bit
  1134. ****************************************************************************}
  1135. constructor tai_real_64bit.Create(_value : ts64real);
  1136. begin
  1137. inherited Create;
  1138. typ:=ait_real_64bit;
  1139. value:=_value;
  1140. end;
  1141. {$ifdef ARM}
  1142. constructor tai_real_64bit.Create_hiloswapped(_value : ts64real);
  1143. begin
  1144. inherited Create;
  1145. typ:=ait_real_64bit;
  1146. value:=_value;
  1147. formatoptions:=fo_hiloswapped;
  1148. end;
  1149. {$endif ARM}
  1150. constructor tai_real_64bit.ppuload(t:taitype;ppufile:tcompilerppufile);
  1151. begin
  1152. inherited ppuload(t,ppufile);
  1153. value:=ppufile.getreal;
  1154. {$ifdef ARM}
  1155. formatoptions:=tformatoptions(ppufile.getbyte);
  1156. {$endif ARM}
  1157. end;
  1158. procedure tai_real_64bit.ppuwrite(ppufile:tcompilerppufile);
  1159. begin
  1160. inherited ppuwrite(ppufile);
  1161. ppufile.putreal(value);
  1162. {$ifdef ARM}
  1163. ppufile.putbyte(byte(formatoptions));
  1164. {$endif ARM}
  1165. end;
  1166. {****************************************************************************
  1167. TAI_real_80bit
  1168. ****************************************************************************}
  1169. constructor tai_real_80bit.Create(_value : ts80real);
  1170. begin
  1171. inherited Create;
  1172. typ:=ait_real_80bit;
  1173. value:=_value;
  1174. end;
  1175. constructor tai_real_80bit.ppuload(t:taitype;ppufile:tcompilerppufile);
  1176. begin
  1177. inherited ppuload(t,ppufile);
  1178. value:=ppufile.getreal;
  1179. end;
  1180. procedure tai_real_80bit.ppuwrite(ppufile:tcompilerppufile);
  1181. begin
  1182. inherited ppuwrite(ppufile);
  1183. ppufile.putreal(value);
  1184. end;
  1185. {****************************************************************************
  1186. TAI_real_80bit
  1187. ****************************************************************************}
  1188. constructor tai_real_128bit.Create(_value : ts128real);
  1189. begin
  1190. inherited Create;
  1191. typ:=ait_real_128bit;
  1192. value:=_value;
  1193. end;
  1194. constructor tai_real_128bit.ppuload(t:taitype;ppufile:tcompilerppufile);
  1195. begin
  1196. inherited ppuload(t,ppufile);
  1197. value:=ppufile.getreal;
  1198. end;
  1199. procedure tai_real_128bit.ppuwrite(ppufile:tcompilerppufile);
  1200. begin
  1201. inherited ppuwrite(ppufile);
  1202. ppufile.putreal(value);
  1203. end;
  1204. {****************************************************************************
  1205. Tai_comp_64bit
  1206. ****************************************************************************}
  1207. constructor tai_comp_64bit.Create(_value : ts64comp);
  1208. begin
  1209. inherited Create;
  1210. typ:=ait_comp_64bit;
  1211. value:=_value;
  1212. end;
  1213. constructor tai_comp_64bit.ppuload(t:taitype;ppufile:tcompilerppufile);
  1214. begin
  1215. inherited ppuload(t,ppufile);
  1216. ppufile.putdata(value,sizeof(value));
  1217. end;
  1218. procedure tai_comp_64bit.ppuwrite(ppufile:tcompilerppufile);
  1219. begin
  1220. inherited ppuwrite(ppufile);
  1221. ppufile.getdata(value,sizeof(value));
  1222. end;
  1223. {****************************************************************************
  1224. TAI_STRING
  1225. ****************************************************************************}
  1226. constructor tai_string.Create(const _str : string);
  1227. begin
  1228. inherited Create;
  1229. typ:=ait_string;
  1230. len:=length(_str);
  1231. getmem(str,len+1);
  1232. strpcopy(str,_str);
  1233. end;
  1234. constructor tai_string.Create_pchar(_str : pchar;length : longint);
  1235. begin
  1236. inherited Create;
  1237. typ:=ait_string;
  1238. str:=_str;
  1239. len:=length;
  1240. end;
  1241. destructor tai_string.destroy;
  1242. begin
  1243. if str<>nil then
  1244. freemem(str);
  1245. inherited Destroy;
  1246. end;
  1247. constructor tai_string.ppuload(t:taitype;ppufile:tcompilerppufile);
  1248. begin
  1249. inherited ppuload(t,ppufile);
  1250. len:=ppufile.getlongint;
  1251. getmem(str,len);
  1252. ppufile.getdata(str^,len);
  1253. end;
  1254. procedure tai_string.ppuwrite(ppufile:tcompilerppufile);
  1255. begin
  1256. inherited ppuwrite(ppufile);
  1257. ppufile.putlongint(len);
  1258. ppufile.putdata(str^,len);
  1259. end;
  1260. function tai_string.getcopy : tlinkedlistitem;
  1261. var
  1262. p : tlinkedlistitem;
  1263. begin
  1264. p:=inherited getcopy;
  1265. getmem(tai_string(p).str,len);
  1266. move(str^,tai_string(p).str^,len);
  1267. getcopy:=p;
  1268. end;
  1269. {****************************************************************************
  1270. TAI_LABEL
  1271. ****************************************************************************}
  1272. constructor tai_label.create(_labsym : tasmlabel);
  1273. begin
  1274. inherited Create;
  1275. typ:=ait_label;
  1276. labsym:=_labsym;
  1277. labsym.is_set:=true;
  1278. is_global:=(labsym.bind=AB_GLOBAL);
  1279. end;
  1280. constructor tai_label.ppuload(t:taitype;ppufile:tcompilerppufile);
  1281. begin
  1282. inherited ppuload(t,ppufile);
  1283. labsym:=tasmlabel(ppufile.getasmsymbol);
  1284. is_global:=boolean(ppufile.getbyte);
  1285. end;
  1286. procedure tai_label.ppuwrite(ppufile:tcompilerppufile);
  1287. begin
  1288. inherited ppuwrite(ppufile);
  1289. ppufile.putasmsymbol(labsym);
  1290. ppufile.putbyte(byte(is_global));
  1291. end;
  1292. procedure tai_label.derefimpl;
  1293. begin
  1294. labsym.is_set:=true;
  1295. end;
  1296. {****************************************************************************
  1297. tai_comment comment to be inserted in the assembler file
  1298. ****************************************************************************}
  1299. constructor tai_comment.Create(_str : pchar);
  1300. begin
  1301. inherited Create;
  1302. typ:=ait_comment;
  1303. str:=_str;
  1304. end;
  1305. destructor tai_comment.destroy;
  1306. begin
  1307. freemem(str);
  1308. inherited Destroy;
  1309. end;
  1310. constructor tai_comment.ppuload(t:taitype;ppufile:tcompilerppufile);
  1311. var
  1312. len : longint;
  1313. begin
  1314. inherited ppuload(t,ppufile);
  1315. len:=ppufile.getlongint;
  1316. getmem(str,len+1);
  1317. ppufile.getdata(str^,len);
  1318. str[len]:=#0;
  1319. end;
  1320. procedure tai_comment.ppuwrite(ppufile:tcompilerppufile);
  1321. var
  1322. len : longint;
  1323. begin
  1324. inherited ppuwrite(ppufile);
  1325. len:=strlen(str);
  1326. ppufile.putlongint(len);
  1327. ppufile.putdata(str^,len);
  1328. end;
  1329. function tai_comment.getcopy : tlinkedlistitem;
  1330. var
  1331. p : tlinkedlistitem;
  1332. begin
  1333. p:=inherited getcopy;
  1334. getmem(tai_comment(p).str,strlen(str)+1);
  1335. move(str^,tai_comment(p).str^,strlen(str)+1);
  1336. getcopy:=p;
  1337. end;
  1338. {****************************************************************************
  1339. TAI_STABS
  1340. ****************************************************************************}
  1341. constructor tai_stab.create(_stabtype:TStabType;_str : pchar);
  1342. begin
  1343. inherited create;
  1344. typ:=ait_stab;
  1345. str:=_str;
  1346. stabtype:=_stabtype;
  1347. end;
  1348. constructor tai_stab.create_str(_stabtype:TStabType;const s:string);
  1349. begin
  1350. self.create(_stabtype,strpnew(s));
  1351. end;
  1352. destructor tai_stab.destroy;
  1353. begin
  1354. freemem(str);
  1355. inherited destroy;
  1356. end;
  1357. {****************************************************************************
  1358. TAI_FORCE_LINE
  1359. ****************************************************************************}
  1360. constructor tai_force_line.create;
  1361. begin
  1362. inherited create;
  1363. typ:=ait_force_line;
  1364. end;
  1365. {****************************************************************************
  1366. TAI_FUNCTION_NAME
  1367. ****************************************************************************}
  1368. constructor tai_function_name.create(const s:string);
  1369. begin
  1370. inherited create;
  1371. typ:=ait_function_name;
  1372. funcname:=stringdup(s);
  1373. end;
  1374. destructor tai_function_name.destroy;
  1375. begin
  1376. stringdispose(funcname);
  1377. inherited destroy;
  1378. end;
  1379. {****************************************************************************
  1380. TAI_CUTOBJECT
  1381. ****************************************************************************}
  1382. constructor tai_cutobject.Create;
  1383. begin
  1384. inherited Create;
  1385. typ:=ait_cutobject;
  1386. place:=cut_normal;
  1387. end;
  1388. constructor tai_cutobject.Create_begin;
  1389. begin
  1390. inherited Create;
  1391. typ:=ait_cutobject;
  1392. place:=cut_begin;
  1393. end;
  1394. constructor tai_cutobject.Create_end;
  1395. begin
  1396. inherited Create;
  1397. typ:=ait_cutobject;
  1398. place:=cut_end;
  1399. end;
  1400. constructor tai_cutobject.ppuload(t:taitype;ppufile:tcompilerppufile);
  1401. begin
  1402. inherited ppuload(t,ppufile);
  1403. place:=TCutPlace(ppufile.getbyte);
  1404. end;
  1405. procedure tai_cutobject.ppuwrite(ppufile:tcompilerppufile);
  1406. begin
  1407. inherited ppuwrite(ppufile);
  1408. ppufile.putbyte(byte(place));
  1409. end;
  1410. {****************************************************************************
  1411. Tai_Marker
  1412. ****************************************************************************}
  1413. constructor Tai_Marker.Create(_Kind: TAsmMarker);
  1414. begin
  1415. Inherited Create;
  1416. typ := ait_marker;
  1417. Kind := _Kind;
  1418. end;
  1419. constructor Tai_Marker.ppuload(t:taitype;ppufile:tcompilerppufile);
  1420. begin
  1421. inherited ppuload(t,ppufile);
  1422. kind:=TAsmMarker(ppufile.getbyte);
  1423. end;
  1424. procedure Tai_Marker.ppuwrite(ppufile:tcompilerppufile);
  1425. begin
  1426. inherited ppuwrite(ppufile);
  1427. ppufile.putbyte(byte(kind));
  1428. end;
  1429. {*****************************************************************************
  1430. tai_tempalloc
  1431. *****************************************************************************}
  1432. constructor tai_tempalloc.alloc(pos,size:longint);
  1433. begin
  1434. inherited Create;
  1435. typ:=ait_tempalloc;
  1436. allocation:=true;
  1437. temppos:=pos;
  1438. tempsize:=size;
  1439. {$ifdef EXTDEBUG}
  1440. problem:=nil;
  1441. {$endif EXTDEBUG}
  1442. end;
  1443. destructor tai_tempalloc.destroy;
  1444. begin
  1445. {$ifdef EXTDEBUG}
  1446. stringdispose(problem);
  1447. {$endif EXTDEBUG}
  1448. inherited destroy;
  1449. end;
  1450. constructor tai_tempalloc.dealloc(pos,size:longint);
  1451. begin
  1452. inherited Create;
  1453. typ:=ait_tempalloc;
  1454. allocation:=false;
  1455. temppos:=pos;
  1456. tempsize:=size;
  1457. {$ifdef EXTDEBUG}
  1458. problem:=nil;
  1459. {$endif EXTDEBUG}
  1460. end;
  1461. {$ifdef EXTDEBUG}
  1462. constructor tai_tempalloc.allocinfo(pos,size:longint;const st:string);
  1463. begin
  1464. inherited Create;
  1465. typ:=ait_tempalloc;
  1466. allocation:=false;
  1467. temppos:=pos;
  1468. tempsize:=size;
  1469. problem:=stringdup(st);
  1470. end;
  1471. {$endif EXTDEBUG}
  1472. constructor tai_tempalloc.ppuload(t:taitype;ppufile:tcompilerppufile);
  1473. begin
  1474. inherited ppuload(t,ppufile);
  1475. temppos:=ppufile.getlongint;
  1476. tempsize:=ppufile.getlongint;
  1477. allocation:=boolean(ppufile.getbyte);
  1478. {$ifdef EXTDEBUG}
  1479. problem:=nil;
  1480. {$endif EXTDEBUG}
  1481. end;
  1482. procedure tai_tempalloc.ppuwrite(ppufile:tcompilerppufile);
  1483. begin
  1484. inherited ppuwrite(ppufile);
  1485. ppufile.putlongint(temppos);
  1486. ppufile.putlongint(tempsize);
  1487. ppufile.putbyte(byte(allocation));
  1488. end;
  1489. {*****************************************************************************
  1490. tai_regalloc
  1491. *****************************************************************************}
  1492. constructor tai_regalloc.alloc(r : tregister;ainstr:tai);
  1493. begin
  1494. inherited create;
  1495. typ:=ait_regalloc;
  1496. ratype:=ra_alloc;
  1497. reg:=r;
  1498. { ainstr must be an instruction }
  1499. if assigned(ainstr) and
  1500. (ainstr.typ<>ait_instruction) then
  1501. internalerror(200411011);
  1502. instr:=ainstr;
  1503. end;
  1504. constructor tai_regalloc.dealloc(r : tregister;ainstr:tai);
  1505. begin
  1506. inherited create;
  1507. typ:=ait_regalloc;
  1508. ratype:=ra_dealloc;
  1509. reg:=r;
  1510. { ainstr must be an instruction }
  1511. if assigned(ainstr) and
  1512. (ainstr.typ<>ait_instruction) then
  1513. internalerror(200411012);
  1514. instr:=ainstr;
  1515. end;
  1516. constructor tai_regalloc.sync(r : tregister);
  1517. begin
  1518. inherited create;
  1519. typ:=ait_regalloc;
  1520. ratype:=ra_sync;
  1521. reg:=r;
  1522. end;
  1523. constructor tai_regalloc.resize(r : tregister);
  1524. begin
  1525. inherited create;
  1526. typ:=ait_regalloc;
  1527. ratype:=ra_resize;
  1528. reg:=r;
  1529. end;
  1530. constructor tai_regalloc.ppuload(t:taitype;ppufile:tcompilerppufile);
  1531. begin
  1532. inherited ppuload(t,ppufile);
  1533. ppufile.getdata(reg,sizeof(Tregister));
  1534. ratype:=tregalloctype(ppufile.getbyte);
  1535. end;
  1536. procedure tai_regalloc.ppuwrite(ppufile:tcompilerppufile);
  1537. begin
  1538. inherited ppuwrite(ppufile);
  1539. ppufile.putdata(reg,sizeof(Tregister));
  1540. ppufile.putbyte(byte(ratype));
  1541. end;
  1542. {****************************************************************************
  1543. tai_file
  1544. ****************************************************************************}
  1545. constructor tai_file.Create(_str : string);
  1546. begin
  1547. inherited Create;
  1548. typ:=ait_file;
  1549. getmem(str,length(_str)+1);
  1550. move(_str[1],str^,length(_str));
  1551. str[length(_str)]:=#0;
  1552. end;
  1553. destructor tai_file.destroy;
  1554. begin
  1555. freemem(str);
  1556. inherited Destroy;
  1557. end;
  1558. constructor tai_file.ppuload(t:taitype;ppufile:tcompilerppufile);
  1559. var
  1560. len : longint;
  1561. begin
  1562. inherited ppuload(t,ppufile);
  1563. len:=ppufile.getlongint;
  1564. getmem(str,len+1);
  1565. ppufile.getdata(str^,len);
  1566. str[len]:=#0;
  1567. idx:=ppufile.getlongint;
  1568. end;
  1569. procedure tai_file.ppuwrite(ppufile:tcompilerppufile);
  1570. var
  1571. len : longint;
  1572. begin
  1573. inherited ppuwrite(ppufile);
  1574. len:=strlen(str);
  1575. ppufile.putlongint(len);
  1576. ppufile.putdata(str^,len);
  1577. ppufile.putlongint(idx);
  1578. end;
  1579. function tai_file.getcopy : tlinkedlistitem;
  1580. var
  1581. p : tlinkedlistitem;
  1582. begin
  1583. p:=inherited getcopy;
  1584. getmem(tai_comment(p).str,strlen(str)+1);
  1585. move(str^,tai_comment(p).str^,strlen(str)+1);
  1586. getcopy:=p;
  1587. end;
  1588. {****************************************************************************
  1589. tai_loc
  1590. ****************************************************************************}
  1591. constructor tai_loc.Create(_fileidx : tai_file;_line,_column : longint);
  1592. begin
  1593. inherited Create;
  1594. typ:=ait_loc;
  1595. fileentry:=_fileidx;
  1596. line:=_line;
  1597. column:=_column;
  1598. end;
  1599. constructor tai_loc.ppuload(t:taitype;ppufile:tcompilerppufile);
  1600. begin
  1601. inherited ppuload(t,ppufile);
  1602. {!!!! fileidx:=ppufile.getlongint; }
  1603. line:=ppufile.getlongint;
  1604. column:=ppufile.getlongint;
  1605. end;
  1606. procedure tai_loc.ppuwrite(ppufile:tcompilerppufile);
  1607. begin
  1608. inherited ppuwrite(ppufile);
  1609. {!!!!! ppufile.putlongint(fileidx); }
  1610. ppufile.putlongint(line);
  1611. ppufile.putlongint(column);
  1612. end;
  1613. {*****************************************************************************
  1614. TaiInstruction
  1615. *****************************************************************************}
  1616. constructor tai_cpu_abstract.Create(op : tasmop);
  1617. begin
  1618. inherited create;
  1619. typ:=ait_instruction;
  1620. is_jmp:=false;
  1621. opcode:=op;
  1622. ops:=0;
  1623. fillchar(condition,sizeof(condition),0);
  1624. fillchar(oper,sizeof(oper),0);
  1625. end;
  1626. destructor tai_cpu_abstract.Destroy;
  1627. var
  1628. i : integer;
  1629. begin
  1630. for i:=0 to opercnt-1 do
  1631. begin
  1632. clearop(i);
  1633. dispose(oper[i]);
  1634. end;
  1635. inherited destroy;
  1636. end;
  1637. { ---------------------------------------------------------------------
  1638. Loading of operands.
  1639. ---------------------------------------------------------------------}
  1640. procedure tai_cpu_abstract.allocate_oper(opers:longint);
  1641. begin
  1642. while (opers>opercnt) do
  1643. begin
  1644. new(oper[opercnt]);
  1645. fillchar(oper[opercnt]^,sizeof(toper),0);
  1646. inc(opercnt);
  1647. end;
  1648. end;
  1649. procedure tai_cpu_abstract.loadconst(opidx:longint;l:aint);
  1650. begin
  1651. allocate_oper(opidx+1);
  1652. with oper[opidx]^ do
  1653. begin
  1654. if typ<>top_const then
  1655. clearop(opidx);
  1656. val:=l;
  1657. typ:=top_const;
  1658. end;
  1659. end;
  1660. procedure tai_cpu_abstract.loadsymbol(opidx:longint;s:tasmsymbol;sofs:longint);
  1661. var
  1662. r : treference;
  1663. begin
  1664. reference_reset_symbol(r,s,sofs);
  1665. r.refaddr:=addr_full;
  1666. loadref(opidx,r);
  1667. end;
  1668. procedure tai_cpu_abstract.loadlocal(opidx:longint;s:pointer;sofs:longint;indexreg:tregister;scale:byte;getoffset,forceref:boolean);
  1669. begin
  1670. if not assigned(s) then
  1671. internalerror(200204251);
  1672. allocate_oper(opidx+1);
  1673. with oper[opidx]^ do
  1674. begin
  1675. if typ<>top_local then
  1676. begin
  1677. clearop(opidx);
  1678. new(localoper);
  1679. end;
  1680. with oper[opidx]^.localoper^ do
  1681. begin
  1682. localsym:=s;
  1683. localsymofs:=sofs;
  1684. localindexreg:=indexreg;
  1685. localscale:=scale;
  1686. localgetoffset:=getoffset;
  1687. localforceref:=forceref;
  1688. end;
  1689. typ:=top_local;
  1690. end;
  1691. end;
  1692. procedure tai_cpu_abstract.loadref(opidx:longint;const r:treference);
  1693. begin
  1694. allocate_oper(opidx+1);
  1695. with oper[opidx]^ do
  1696. begin
  1697. if typ<>top_ref then
  1698. begin
  1699. clearop(opidx);
  1700. new(ref);
  1701. end;
  1702. ref^:=r;
  1703. {$ifdef x86}
  1704. { We allow this exception for x86, since overloading this would be
  1705. too much of a a speed penalty}
  1706. if (ref^.segment<>NR_NO) and (ref^.segment<>NR_DS) then
  1707. segprefix:=ref^.segment;
  1708. {$endif}
  1709. {$ifdef extdebug}
  1710. if (cs_create_pic in current_settings.moduleswitches) and
  1711. assigned(r.symbol) and
  1712. (r.refaddr=addr_no) then
  1713. internalerror(200502052);
  1714. {$endif}
  1715. typ:=top_ref;
  1716. if assigned(add_reg_instruction_hook) then
  1717. begin
  1718. add_reg_instruction_hook(self,ref^.base);
  1719. add_reg_instruction_hook(self,ref^.index);
  1720. end;
  1721. { mark symbol as used }
  1722. if assigned(ref^.symbol) then
  1723. ref^.symbol.increfs;
  1724. end;
  1725. end;
  1726. procedure tai_cpu_abstract.loadreg(opidx:longint;r:tregister);
  1727. begin
  1728. allocate_oper(opidx+1);
  1729. with oper[opidx]^ do
  1730. begin
  1731. if typ<>top_reg then
  1732. clearop(opidx);
  1733. reg:=r;
  1734. typ:=top_reg;
  1735. end;
  1736. if assigned(add_reg_instruction_hook) then
  1737. add_reg_instruction_hook(self,r);
  1738. {$ifdef ARM}
  1739. { R15 is the PC on the ARM thus moves to R15 are jumps.
  1740. Due to speed considerations we don't use a virtual overridden method here.
  1741. Because the pc/r15 isn't handled by the reg. allocator this should never cause
  1742. problems with iregs getting r15.
  1743. }
  1744. is_jmp:=(opcode=A_MOV) and (opidx=0) and (r=NR_R15);
  1745. {$endif ARM}
  1746. end;
  1747. procedure tai_cpu_abstract.loadoper(opidx:longint;o:toper);
  1748. begin
  1749. allocate_oper(opidx+1);
  1750. clearop(opidx);
  1751. oper[opidx]^:=o;
  1752. { copy also the reference }
  1753. with oper[opidx]^ do
  1754. begin
  1755. case typ of
  1756. top_reg:
  1757. begin
  1758. if assigned(add_reg_instruction_hook) then
  1759. add_reg_instruction_hook(self,reg);
  1760. end;
  1761. top_ref:
  1762. begin
  1763. new(ref);
  1764. ref^:=o.ref^;
  1765. if assigned(add_reg_instruction_hook) then
  1766. begin
  1767. add_reg_instruction_hook(self,ref^.base);
  1768. add_reg_instruction_hook(self,ref^.index);
  1769. end;
  1770. end;
  1771. {$ifdef ARM}
  1772. top_shifterop:
  1773. begin
  1774. new(shifterop);
  1775. shifterop^:=o.shifterop^;
  1776. if assigned(add_reg_instruction_hook) then
  1777. add_reg_instruction_hook(self,shifterop^.rs);
  1778. end;
  1779. {$endif ARM}
  1780. end;
  1781. end;
  1782. end;
  1783. procedure tai_cpu_abstract.clearop(opidx:longint);
  1784. begin
  1785. with oper[opidx]^ do
  1786. begin
  1787. case typ of
  1788. top_ref:
  1789. dispose(ref);
  1790. top_local:
  1791. dispose(localoper);
  1792. {$ifdef ARM}
  1793. top_shifterop:
  1794. dispose(shifterop);
  1795. top_regset:
  1796. dispose(regset);
  1797. {$endif ARM}
  1798. end;
  1799. typ:=top_none;
  1800. end;
  1801. end;
  1802. { ---------------------------------------------------------------------
  1803. Miscellaneous methods.
  1804. ---------------------------------------------------------------------}
  1805. procedure tai_cpu_abstract.SetCondition(const c:TAsmCond);
  1806. begin
  1807. condition:=c;
  1808. end;
  1809. Function tai_cpu_abstract.getcopy:TLinkedListItem;
  1810. var
  1811. i : longint;
  1812. p : tai_cpu_abstract;
  1813. begin
  1814. p:=tai_cpu_abstract(inherited getcopy);
  1815. { make a copy of the references }
  1816. p.opercnt:=0;
  1817. p.allocate_oper(ops);
  1818. for i:=0 to ops-1 do
  1819. begin
  1820. p.oper[i]^:=oper[i]^;
  1821. case oper[i]^.typ of
  1822. top_local :
  1823. begin
  1824. new(p.oper[i]^.localoper);
  1825. p.oper[i]^.localoper^:=oper[i]^.localoper^;
  1826. end;
  1827. top_ref :
  1828. begin
  1829. new(p.oper[i]^.ref);
  1830. p.oper[i]^.ref^:=oper[i]^.ref^;
  1831. end;
  1832. {$ifdef ARM}
  1833. top_shifterop:
  1834. begin
  1835. new(p.oper[i]^.shifterop);
  1836. p.oper[i]^.shifterop^:=oper[i]^.shifterop^;
  1837. end;
  1838. {$endif ARM}
  1839. end;
  1840. end;
  1841. getcopy:=p;
  1842. end;
  1843. function tai_cpu_abstract.is_same_reg_move(regtype: Tregistertype):boolean;
  1844. begin
  1845. { When the generic RA is used this needs to be overriden, we don't use
  1846. virtual;abstract; to prevent a lot of warnings of unimplemented abstract methods
  1847. when tai_cpu is created (PFV) }
  1848. internalerror(200404091);
  1849. result:=false;
  1850. end;
  1851. function tai_cpu_abstract.spilling_get_operation_type(opnr: longint): topertype;
  1852. begin
  1853. internalerror(200404091);
  1854. result:=operand_readwrite;
  1855. end;
  1856. function tai_cpu_abstract.spilling_get_operation_type_ref(opnr: longint; reg: tregister): topertype;
  1857. begin
  1858. result := operand_read;
  1859. end;
  1860. constructor tai_cpu_abstract.ppuload(t:taitype;ppufile:tcompilerppufile);
  1861. var
  1862. i : integer;
  1863. begin
  1864. inherited ppuload(t,ppufile);
  1865. { hopefully, we don't get problems with big/litte endian here when cross compiling :/ }
  1866. ppufile.getdata(condition,sizeof(tasmcond));
  1867. allocate_oper(ppufile.getbyte);
  1868. for i:=0 to ops-1 do
  1869. ppuloadoper(ppufile,oper[i]^);
  1870. opcode:=tasmop(ppufile.getword);
  1871. {$ifdef x86}
  1872. ppufile.getdata(segprefix,sizeof(Tregister));
  1873. {$endif x86}
  1874. is_jmp:=boolean(ppufile.getbyte);
  1875. end;
  1876. procedure tai_cpu_abstract.ppuwrite(ppufile:tcompilerppufile);
  1877. var
  1878. i : integer;
  1879. begin
  1880. inherited ppuwrite(ppufile);
  1881. ppufile.putdata(condition,sizeof(tasmcond));
  1882. ppufile.putbyte(ops);
  1883. for i:=0 to ops-1 do
  1884. ppuwriteoper(ppufile,oper[i]^);
  1885. ppufile.putword(word(opcode));
  1886. {$ifdef x86}
  1887. ppufile.putdata(segprefix,sizeof(Tregister));
  1888. {$endif x86}
  1889. ppufile.putbyte(byte(is_jmp));
  1890. end;
  1891. procedure tai_cpu_abstract.buildderefimpl;
  1892. var
  1893. i : integer;
  1894. begin
  1895. for i:=0 to ops-1 do
  1896. ppubuildderefimploper(oper[i]^);
  1897. end;
  1898. procedure tai_cpu_abstract.derefimpl;
  1899. var
  1900. i : integer;
  1901. begin
  1902. for i:=0 to ops-1 do
  1903. ppuderefoper(oper[i]^);
  1904. end;
  1905. procedure tai_cpu_abstract.resetpass1;
  1906. begin
  1907. end;
  1908. procedure tai_cpu_abstract.resetpass2;
  1909. begin
  1910. end;
  1911. {****************************************************************************
  1912. tai_align_abstract
  1913. ****************************************************************************}
  1914. constructor tai_align_abstract.Create(b: byte);
  1915. begin
  1916. inherited Create;
  1917. typ:=ait_align;
  1918. if b in [1,2,4,8,16,32] then
  1919. aligntype := b
  1920. else
  1921. aligntype := 1;
  1922. fillsize:=0;
  1923. fillop:=0;
  1924. use_op:=false;
  1925. end;
  1926. constructor tai_align_abstract.Create_op(b: byte; _op: byte);
  1927. begin
  1928. inherited Create;
  1929. typ:=ait_align;
  1930. if b in [1,2,4,8,16,32] then
  1931. aligntype := b
  1932. else
  1933. aligntype := 1;
  1934. fillsize:=0;
  1935. fillop:=_op;
  1936. use_op:=true;
  1937. end;
  1938. constructor tai_align_abstract.Create_zeros(b: byte);
  1939. begin
  1940. inherited Create;
  1941. typ:=ait_align;
  1942. if b in [1,2,4,8,16,32] then
  1943. aligntype := b
  1944. else
  1945. aligntype := 1;
  1946. use_op:=true;
  1947. fillsize:=0;
  1948. fillop:=0;
  1949. end;
  1950. function tai_align_abstract.calculatefillbuf(var buf : tfillbuffer):pchar;
  1951. begin
  1952. if fillsize>sizeof(buf) then
  1953. internalerror(200404293);
  1954. fillchar(buf,high(buf),fillop);
  1955. calculatefillbuf:=pchar(@buf);
  1956. end;
  1957. constructor tai_align_abstract.ppuload(t:taitype;ppufile:tcompilerppufile);
  1958. begin
  1959. inherited ppuload(t,ppufile);
  1960. aligntype:=ppufile.getbyte;
  1961. fillsize:=0;
  1962. fillop:=ppufile.getbyte;
  1963. use_op:=boolean(ppufile.getbyte);
  1964. end;
  1965. procedure tai_align_abstract.ppuwrite(ppufile:tcompilerppufile);
  1966. begin
  1967. inherited ppuwrite(ppufile);
  1968. ppufile.putbyte(aligntype);
  1969. ppufile.putbyte(fillop);
  1970. ppufile.putbyte(byte(use_op));
  1971. end;
  1972. begin
  1973. cai_cpu:=tai_cpu_abstract;
  1974. cai_align:=tai_align_abstract;
  1975. end.