2
0

aasmtai.pas 67 KB

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