aasmtai.pas 63 KB

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