aasmtai.pas 63 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256
  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. constructor alloc(r : tregister);
  437. constructor dealloc(r : tregister);
  438. constructor sync(r : tregister);
  439. constructor resize(r : tregister);
  440. constructor ppuload(t:taitype;ppufile:tcompilerppufile);override;
  441. procedure ppuwrite(ppufile:tcompilerppufile);override;
  442. end;
  443. Taasmoutput=class;
  444. tadd_reg_instruction_proc=procedure(instr:Tai;r:tregister) of object;
  445. Trggetproc=procedure(list:Taasmoutput;position:Tai;subreg:Tsubregister;var result:Tregister) of object;
  446. Trgungetproc=procedure(list:Taasmoutput;position:Tai;r:Tregister) of object;
  447. { Class template for assembler instructions
  448. }
  449. tai_cpu_abstract = class(tailineinfo)
  450. protected
  451. procedure ppuloadoper(ppufile:tcompilerppufile;var o:toper);virtual;abstract;
  452. procedure ppuwriteoper(ppufile:tcompilerppufile;const o:toper);virtual;abstract;
  453. procedure ppubuildderefimploper(var o:toper);virtual;abstract;
  454. procedure ppuderefoper(var o:toper);virtual;abstract;
  455. public
  456. { Condition flags for instruction }
  457. condition : TAsmCond;
  458. { Number of operands to instruction }
  459. ops : byte;
  460. { Number of allocate oper structures }
  461. opercnt : byte;
  462. { Operands of instruction }
  463. oper : array[0..max_operands-1] of poper;
  464. { Actual opcode of instruction }
  465. opcode : tasmop;
  466. {$ifdef x86}
  467. segprefix : tregister;
  468. {$endif x86}
  469. { true if instruction is a jmp }
  470. is_jmp : boolean; { is this instruction a jump? (needed for optimizer) }
  471. Constructor Create(op : tasmop);virtual;
  472. Destructor Destroy;override;
  473. function getcopy:TLinkedListItem;override;
  474. constructor ppuload(t:taitype;ppufile:tcompilerppufile);override;
  475. procedure ppuwrite(ppufile:tcompilerppufile);override;
  476. procedure buildderefimpl;override;
  477. procedure derefimpl;override;
  478. procedure SetCondition(const c:TAsmCond);
  479. procedure allocate_oper(opers:longint);
  480. procedure loadconst(opidx:longint;l:aint);
  481. procedure loadsymbol(opidx:longint;s:tasmsymbol;sofs:longint);
  482. procedure loadlocal(opidx:longint;s:pointer;sofs:longint;indexreg:tregister;scale:byte;getoffset:boolean);
  483. procedure loadref(opidx:longint;const r:treference);
  484. procedure loadreg(opidx:longint;r:tregister);
  485. procedure loadoper(opidx:longint;o:toper);
  486. procedure clearop(opidx:longint);
  487. { register allocator }
  488. function is_same_reg_move(regtype: Tregistertype):boolean;virtual;
  489. function spilling_get_operation_type(opnr: longint): topertype;virtual;
  490. end;
  491. tai_cpu_class = class of tai_cpu_abstract;
  492. { alignment for operator }
  493. tai_align_abstract = class(tai)
  494. aligntype : byte; { 1 = no align, 2 = word align, 4 = dword align }
  495. fillsize : byte; { real size to fill }
  496. fillop : byte; { value to fill with - optional }
  497. use_op : boolean;
  498. constructor Create(b:byte);virtual;
  499. constructor Create_op(b: byte; _op: byte);virtual;
  500. constructor Create_zeros(b:byte);
  501. constructor ppuload(t:taitype;ppufile:tcompilerppufile);override;
  502. procedure ppuwrite(ppufile:tcompilerppufile);override;
  503. function calculatefillbuf(var buf : tfillbuffer):pchar;virtual;
  504. end;
  505. tai_align_class = class of tai_align_abstract;
  506. taasmoutput = class(tlinkedlist)
  507. constructor create;
  508. function empty : boolean;
  509. function getlasttaifilepos : pfileposinfo;
  510. procedure InsertAfter(Item,Loc : TLinkedListItem);override;
  511. end;
  512. var
  513. { array with all class types for tais }
  514. aiclass : taiclassarray;
  515. { Current expression list }
  516. exprasmlist : taasmoutput;
  517. { labels for BREAK and CONTINUE }
  518. aktbreaklabel,aktcontinuelabel : tasmlabel;
  519. { label when the result is true or false }
  520. truelabel,falselabel : tasmlabel;
  521. { hook to notify uses of registers }
  522. add_reg_instruction_hook : tadd_reg_instruction_proc;
  523. { default lists }
  524. datasegment,codesegment,bsssegment,
  525. debuglist,withdebuglist,consts,
  526. importssection,exportssection,
  527. resourcesection,rttilist,
  528. dwarflist,
  529. { data used by pic code }
  530. picdata,
  531. resourcestringlist : taasmoutput;
  532. cai_align : tai_align_class;
  533. cai_cpu : tai_cpu_class;
  534. function use_smartlink_section:boolean;
  535. function maybe_smartlink_symbol:boolean;
  536. procedure maybe_new_object_file(list:taasmoutput);
  537. procedure new_section(list:taasmoutput;Asectype:TAsmSectionType;Aname:string;Aalign:byte);
  538. function ppuloadai(ppufile:tcompilerppufile):tai;
  539. procedure ppuwriteai(ppufile:tcompilerppufile;n:tai);
  540. implementation
  541. uses
  542. {$ifdef delphi}
  543. sysutils,
  544. {$else}
  545. strings,
  546. {$endif}
  547. verbose;
  548. const
  549. pputaimarker = 254;
  550. {****************************************************************************
  551. Helpers
  552. ****************************************************************************}
  553. function ppuloadai(ppufile:tcompilerppufile):tai;
  554. var
  555. b : byte;
  556. t : taitype;
  557. begin
  558. { marker }
  559. b:=ppufile.getbyte;
  560. if b<>pputaimarker then
  561. internalerror(200208181);
  562. { load nodetype }
  563. t:=taitype(ppufile.getbyte);
  564. if t<>ait_none then
  565. begin
  566. if t>high(taitype) then
  567. internalerror(200208182);
  568. if not assigned(aiclass[t]) then
  569. internalerror(200208183);
  570. {writeln('taiload: ',taitypestr[t]);}
  571. { generate tai of the correct class }
  572. ppuloadai:=aiclass[t].ppuload(t,ppufile);
  573. end
  574. else
  575. ppuloadai:=nil;
  576. end;
  577. procedure ppuwriteai(ppufile:tcompilerppufile;n:tai);
  578. begin
  579. { marker, read by ppuloadnode }
  580. ppufile.putbyte(pputaimarker);
  581. if assigned(n) then
  582. begin
  583. { type, read by ppuloadnode }
  584. ppufile.putbyte(byte(n.typ));
  585. {writeln('taiwrite: ',taitypestr[n.typ]);}
  586. n.ppuwrite(ppufile);
  587. end
  588. else
  589. ppufile.putbyte(byte(ait_none));
  590. end;
  591. function use_smartlink_section:boolean;
  592. begin
  593. result:=(af_smartlink_sections in target_asm.flags) and
  594. (tf_smartlink_sections in target_info.flags) and
  595. not(cs_debuginfo in aktmoduleswitches);
  596. end;
  597. function maybe_smartlink_symbol:boolean;
  598. begin
  599. result:=(cs_create_smart in aktmoduleswitches) or
  600. use_smartlink_section;
  601. end;
  602. procedure maybe_new_object_file(list:taasmoutput);
  603. begin
  604. if (cs_create_smart in aktmoduleswitches) and
  605. (not use_smartlink_section) then
  606. list.concat(tai_cutobject.create);
  607. end;
  608. procedure new_section(list:taasmoutput;Asectype:TAsmSectionType;Aname:string;Aalign:byte);
  609. begin
  610. list.concat(tai_section.create(Asectype,Aname,Aalign));
  611. list.concat(cai_align.create(Aalign));
  612. end;
  613. {****************************************************************************
  614. TAI
  615. ****************************************************************************}
  616. constructor tai.Create;
  617. begin
  618. {$ifndef NOOPT}
  619. optinfo:=nil;
  620. {$endif NOOPT}
  621. end;
  622. constructor tai.ppuload(t:taitype;ppufile:tcompilerppufile);
  623. begin
  624. typ:=t;
  625. {$ifndef NOOPT}
  626. optinfo:=nil;
  627. {$endif}
  628. end;
  629. procedure tai.ppuwrite(ppufile:tcompilerppufile);
  630. begin
  631. end;
  632. procedure tai.buildderefimpl;
  633. begin
  634. end;
  635. procedure tai.derefimpl;
  636. begin
  637. end;
  638. {****************************************************************************
  639. TAILINEINFO
  640. ****************************************************************************}
  641. constructor tailineinfo.create;
  642. begin
  643. inherited create;
  644. if not(inlining_procedure and
  645. (cs_gdb_valgrind in aktglobalswitches)) then
  646. fileinfo:=aktfilepos;
  647. end;
  648. constructor tailineinfo.ppuload(t:taitype;ppufile:tcompilerppufile);
  649. begin
  650. inherited ppuload(t,ppufile);
  651. ppufile.getposinfo(fileinfo);
  652. end;
  653. procedure tailineinfo.ppuwrite(ppufile:tcompilerppufile);
  654. begin
  655. inherited ppuwrite(ppufile);
  656. ppufile.putposinfo(fileinfo);
  657. end;
  658. {****************************************************************************
  659. TAI_SIMPLE
  660. ****************************************************************************}
  661. constructor tai_simple.create(_typ : taitype);
  662. begin
  663. inherited create;
  664. typ:=_typ;
  665. end;
  666. {****************************************************************************
  667. TAI_SECTION
  668. ****************************************************************************}
  669. constructor tai_section.Create(Asectype:TAsmSectionType;Aname:string;Aalign:byte);
  670. begin
  671. inherited Create;
  672. typ:=ait_section;
  673. sectype:=asectype;
  674. secalign:=Aalign;
  675. name:=stringdup(Aname);
  676. sec:=nil;
  677. end;
  678. constructor tai_section.ppuload(t:taitype;ppufile:tcompilerppufile);
  679. begin
  680. inherited ppuload(t,ppufile);
  681. sectype:=tasmsectiontype(ppufile.getbyte);
  682. secalign:=ppufile.getbyte;
  683. name:=stringdup(ppufile.getstring);
  684. sec:=nil;
  685. end;
  686. destructor tai_section.Destroy;
  687. begin
  688. stringdispose(name);
  689. end;
  690. procedure tai_section.ppuwrite(ppufile:tcompilerppufile);
  691. begin
  692. inherited ppuwrite(ppufile);
  693. ppufile.putbyte(byte(sectype));
  694. ppufile.putbyte(secalign);
  695. ppufile.putstring(name^);
  696. end;
  697. {****************************************************************************
  698. TAI_DATABLOCK
  699. ****************************************************************************}
  700. constructor tai_datablock.Create(const _name : string;_size : longint);
  701. begin
  702. inherited Create;
  703. typ:=ait_datablock;
  704. sym:=objectlibrary.newasmsymbol(_name,AB_LOCAL,AT_DATA);
  705. { keep things aligned }
  706. if _size<=0 then
  707. _size:=4;
  708. size:=_size;
  709. is_global:=false;
  710. end;
  711. constructor tai_datablock.Create_global(const _name : string;_size : longint);
  712. begin
  713. inherited Create;
  714. typ:=ait_datablock;
  715. sym:=objectlibrary.newasmsymbol(_name,AB_GLOBAL,AT_DATA);
  716. { keep things aligned }
  717. if _size<=0 then
  718. _size:=4;
  719. size:=_size;
  720. is_global:=true;
  721. end;
  722. constructor tai_datablock.ppuload(t:taitype;ppufile:tcompilerppufile);
  723. begin
  724. inherited Create;
  725. sym:=ppufile.getasmsymbol;
  726. size:=ppufile.getlongint;
  727. is_global:=boolean(ppufile.getbyte);
  728. end;
  729. procedure tai_datablock.ppuwrite(ppufile:tcompilerppufile);
  730. begin
  731. inherited ppuwrite(ppufile);
  732. ppufile.putasmsymbol(sym);
  733. ppufile.putlongint(size);
  734. ppufile.putbyte(byte(is_global));
  735. end;
  736. procedure tai_datablock.derefimpl;
  737. begin
  738. objectlibrary.DerefAsmsymbol(sym);
  739. end;
  740. {****************************************************************************
  741. TAI_SYMBOL
  742. ****************************************************************************}
  743. constructor tai_symbol.Create(_sym:tasmsymbol;siz:longint);
  744. begin
  745. inherited Create;
  746. typ:=ait_symbol;
  747. sym:=_sym;
  748. size:=siz;
  749. sym.defbind:=AB_LOCAL;
  750. is_global:=false;
  751. end;
  752. constructor tai_symbol.Create_global(_sym:tasmsymbol;siz:longint);
  753. begin
  754. inherited Create;
  755. typ:=ait_symbol;
  756. sym:=_sym;
  757. size:=siz;
  758. sym.defbind:=AB_GLOBAL;
  759. is_global:=true;
  760. end;
  761. constructor tai_symbol.Createname(const _name : string;_symtyp:Tasmsymtype;siz:longint);
  762. begin
  763. inherited Create;
  764. typ:=ait_symbol;
  765. sym:=objectlibrary.newasmsymbol(_name,AB_LOCAL,_symtyp);
  766. size:=siz;
  767. is_global:=false;
  768. end;
  769. constructor tai_symbol.Createname_global(const _name : string;_symtyp:Tasmsymtype;siz:longint);
  770. begin
  771. inherited Create;
  772. typ:=ait_symbol;
  773. sym:=objectlibrary.newasmsymbol(_name,AB_GLOBAL,_symtyp);
  774. size:=siz;
  775. is_global:=true;
  776. end;
  777. constructor tai_symbol.ppuload(t:taitype;ppufile:tcompilerppufile);
  778. begin
  779. inherited ppuload(t,ppufile);
  780. sym:=ppufile.getasmsymbol;
  781. size:=ppufile.getlongint;
  782. is_global:=boolean(ppufile.getbyte);
  783. end;
  784. procedure tai_symbol.ppuwrite(ppufile:tcompilerppufile);
  785. begin
  786. inherited ppuwrite(ppufile);
  787. ppufile.putasmsymbol(sym);
  788. ppufile.putlongint(size);
  789. ppufile.putbyte(byte(is_global));
  790. end;
  791. procedure tai_symbol.derefimpl;
  792. begin
  793. objectlibrary.DerefAsmsymbol(sym);
  794. end;
  795. {****************************************************************************
  796. TAI_SYMBOL_END
  797. ****************************************************************************}
  798. constructor tai_symbol_end.Create(_sym:tasmsymbol);
  799. begin
  800. inherited Create;
  801. typ:=ait_symbol_end;
  802. sym:=_sym;
  803. end;
  804. constructor tai_symbol_end.Createname(const _name : string);
  805. begin
  806. inherited Create;
  807. typ:=ait_symbol_end;
  808. sym:=objectlibrary.newasmsymbol(_name,AB_GLOBAL,AT_NONE);
  809. end;
  810. constructor tai_symbol_end.ppuload(t:taitype;ppufile:tcompilerppufile);
  811. begin
  812. inherited ppuload(t,ppufile);
  813. sym:=ppufile.getasmsymbol;
  814. end;
  815. procedure tai_symbol_end.ppuwrite(ppufile:tcompilerppufile);
  816. begin
  817. inherited ppuwrite(ppufile);
  818. ppufile.putasmsymbol(sym);
  819. end;
  820. procedure tai_symbol_end.derefimpl;
  821. begin
  822. objectlibrary.DerefAsmsymbol(sym);
  823. end;
  824. {****************************************************************************
  825. TAI_CONST
  826. ****************************************************************************}
  827. constructor tai_const.Create(_typ:taitype;_value : int64);
  828. begin
  829. inherited Create;
  830. typ:=_typ;
  831. value:=_value;
  832. sym:=nil;
  833. endsym:=nil;
  834. end;
  835. constructor tai_const.Create_128bit(_value : int64);
  836. begin
  837. inherited Create;
  838. typ:=ait_const_128bit;
  839. value:=_value;
  840. sym:=nil;
  841. endsym:=nil;
  842. end;
  843. constructor tai_const.Create_64bit(_value : int64);
  844. begin
  845. inherited Create;
  846. typ:=ait_const_64bit;
  847. value:=_value;
  848. sym:=nil;
  849. endsym:=nil;
  850. end;
  851. constructor tai_const.Create_32bit(_value : longint);
  852. begin
  853. inherited Create;
  854. typ:=ait_const_32bit;
  855. value:=_value;
  856. sym:=nil;
  857. endsym:=nil;
  858. end;
  859. constructor tai_const.Create_16bit(_value : word);
  860. begin
  861. inherited Create;
  862. typ:=ait_const_16bit;
  863. value:=_value;
  864. sym:=nil;
  865. endsym:=nil;
  866. end;
  867. constructor tai_const.Create_8bit(_value : byte);
  868. begin
  869. inherited Create;
  870. typ:=ait_const_8bit;
  871. value:=_value;
  872. sym:=nil;
  873. endsym:=nil;
  874. end;
  875. constructor tai_const.Create_sleb128bit(_value : int64);
  876. begin
  877. inherited Create;
  878. typ:=ait_const_sleb128bit;
  879. value:=_value;
  880. sym:=nil;
  881. endsym:=nil;
  882. end;
  883. constructor tai_const.Create_uleb128bit(_value : qword);
  884. begin
  885. inherited Create;
  886. typ:=ait_const_uleb128bit;
  887. value:=int64(_value);
  888. sym:=nil;
  889. endsym:=nil;
  890. end;
  891. constructor tai_const.Create_aint(_value : aint);
  892. begin
  893. inherited Create;
  894. typ:=ait_const_aint;
  895. value:=_value;
  896. sym:=nil;
  897. endsym:=nil;
  898. end;
  899. constructor tai_const.Create_sym(_sym:tasmsymbol);
  900. begin
  901. inherited Create;
  902. typ:=ait_const_ptr;
  903. { sym is allowed to be nil, this is used to write nil pointers }
  904. sym:=_sym;
  905. endsym:=nil;
  906. value:=0;
  907. { update sym info }
  908. if assigned(sym) then
  909. sym.increfs;
  910. end;
  911. constructor tai_const.Create_sym_offset(_sym:tasmsymbol;ofs:aint);
  912. begin
  913. inherited Create;
  914. typ:=ait_const_ptr;
  915. if not assigned(_sym) then
  916. internalerror(200404121);
  917. sym:=_sym;
  918. endsym:=nil;
  919. value:=ofs;
  920. { update sym info }
  921. sym.increfs;
  922. end;
  923. constructor tai_const.Create_rel_sym(_typ:taitype;_sym,_endsym:tasmsymbol);
  924. begin
  925. inherited Create;
  926. typ:=_typ;
  927. sym:=_sym;
  928. endsym:=_endsym;
  929. value:=0;
  930. { update sym info }
  931. sym.increfs;
  932. endsym.increfs;
  933. end;
  934. constructor tai_const.Create_rva_sym(_sym:tasmsymbol);
  935. begin
  936. inherited Create;
  937. typ:=ait_const_rva_symbol;
  938. sym:=_sym;
  939. endsym:=nil;
  940. value:=0;
  941. { update sym info }
  942. sym.increfs;
  943. end;
  944. constructor tai_const.Create_indirect_sym(_sym:tasmsymbol);
  945. begin
  946. inherited Create;
  947. typ:=ait_const_indirect_symbol;
  948. sym:=_sym;
  949. endsym:=nil;
  950. value:=0;
  951. { update sym info }
  952. sym.increfs;
  953. end;
  954. constructor tai_const.Createname(const name:string;_symtyp:Tasmsymtype;ofs:aint);
  955. begin
  956. inherited Create;
  957. typ:=ait_const_ptr;
  958. sym:=objectlibrary.newasmsymbol(name,AB_EXTERNAL,_symtyp);
  959. endsym:=nil;
  960. value:=ofs;
  961. { update sym info }
  962. sym.increfs;
  963. end;
  964. constructor tai_const.Createname_rva(const name:string);
  965. begin
  966. inherited Create;
  967. typ:=ait_const_rva_symbol;
  968. sym:=objectlibrary.newasmsymbol(name,AB_EXTERNAL,AT_FUNCTION);
  969. endsym:=nil;
  970. value:=0;
  971. { update sym info }
  972. sym.increfs;
  973. end;
  974. constructor tai_const.ppuload(t:taitype;ppufile:tcompilerppufile);
  975. begin
  976. inherited ppuload(t,ppufile);
  977. sym:=ppufile.getasmsymbol;
  978. endsym:=ppufile.getasmsymbol;
  979. value:=ppufile.getint64;
  980. end;
  981. procedure tai_const.ppuwrite(ppufile:tcompilerppufile);
  982. begin
  983. inherited ppuwrite(ppufile);
  984. ppufile.putasmsymbol(sym);
  985. ppufile.putasmsymbol(endsym);
  986. ppufile.putint64(value);
  987. end;
  988. procedure tai_const.derefimpl;
  989. begin
  990. objectlibrary.DerefAsmsymbol(sym);
  991. objectlibrary.DerefAsmsymbol(endsym);
  992. end;
  993. function tai_const.getcopy:tlinkedlistitem;
  994. begin
  995. getcopy:=inherited getcopy;
  996. { we need to increase the reference number }
  997. sym.increfs;
  998. if assigned(endsym) then
  999. endsym.increfs;
  1000. end;
  1001. function tai_const.size:longint;
  1002. begin
  1003. case typ of
  1004. ait_const_8bit :
  1005. result:=1;
  1006. ait_const_16bit :
  1007. result:=2;
  1008. ait_const_32bit :
  1009. result:=4;
  1010. ait_const_64bit :
  1011. result:=8;
  1012. ait_const_indirect_symbol,
  1013. ait_const_rva_symbol :
  1014. result:=sizeof(aint);
  1015. end;
  1016. end;
  1017. {****************************************************************************
  1018. TAI_real_32bit
  1019. ****************************************************************************}
  1020. constructor tai_real_32bit.Create(_value : ts32real);
  1021. begin
  1022. inherited Create;
  1023. typ:=ait_real_32bit;
  1024. value:=_value;
  1025. end;
  1026. constructor tai_real_32bit.ppuload(t:taitype;ppufile:tcompilerppufile);
  1027. begin
  1028. inherited ppuload(t,ppufile);
  1029. value:=ppufile.getreal;
  1030. end;
  1031. procedure tai_real_32bit.ppuwrite(ppufile:tcompilerppufile);
  1032. begin
  1033. inherited ppuwrite(ppufile);
  1034. ppufile.putreal(value);
  1035. end;
  1036. {****************************************************************************
  1037. TAI_real_64bit
  1038. ****************************************************************************}
  1039. constructor tai_real_64bit.Create(_value : ts64real);
  1040. begin
  1041. inherited Create;
  1042. typ:=ait_real_64bit;
  1043. value:=_value;
  1044. end;
  1045. {$ifdef ARM}
  1046. constructor tai_real_64bit.Create_hiloswapped(_value : ts64real);
  1047. begin
  1048. inherited Create;
  1049. typ:=ait_real_64bit;
  1050. value:=_value;
  1051. formatoptions:=fo_hiloswapped;
  1052. end;
  1053. {$endif ARM}
  1054. constructor tai_real_64bit.ppuload(t:taitype;ppufile:tcompilerppufile);
  1055. begin
  1056. inherited ppuload(t,ppufile);
  1057. value:=ppufile.getreal;
  1058. {$ifdef ARM}
  1059. formatoptions:=tformatoptions(ppufile.getbyte);
  1060. {$endif ARM}
  1061. end;
  1062. procedure tai_real_64bit.ppuwrite(ppufile:tcompilerppufile);
  1063. begin
  1064. inherited ppuwrite(ppufile);
  1065. ppufile.putreal(value);
  1066. {$ifdef ARM}
  1067. ppufile.putbyte(byte(formatoptions));
  1068. {$endif ARM}
  1069. end;
  1070. {****************************************************************************
  1071. TAI_real_80bit
  1072. ****************************************************************************}
  1073. constructor tai_real_80bit.Create(_value : ts80real);
  1074. begin
  1075. inherited Create;
  1076. typ:=ait_real_80bit;
  1077. value:=_value;
  1078. end;
  1079. constructor tai_real_80bit.ppuload(t:taitype;ppufile:tcompilerppufile);
  1080. begin
  1081. inherited ppuload(t,ppufile);
  1082. value:=ppufile.getreal;
  1083. end;
  1084. procedure tai_real_80bit.ppuwrite(ppufile:tcompilerppufile);
  1085. begin
  1086. inherited ppuwrite(ppufile);
  1087. ppufile.putreal(value);
  1088. end;
  1089. {****************************************************************************
  1090. TAI_real_80bit
  1091. ****************************************************************************}
  1092. constructor tai_real_128bit.Create(_value : ts128real);
  1093. begin
  1094. inherited Create;
  1095. typ:=ait_real_128bit;
  1096. value:=_value;
  1097. end;
  1098. constructor tai_real_128bit.ppuload(t:taitype;ppufile:tcompilerppufile);
  1099. begin
  1100. inherited ppuload(t,ppufile);
  1101. value:=ppufile.getreal;
  1102. end;
  1103. procedure tai_real_128bit.ppuwrite(ppufile:tcompilerppufile);
  1104. begin
  1105. inherited ppuwrite(ppufile);
  1106. ppufile.putreal(value);
  1107. end;
  1108. {****************************************************************************
  1109. Tai_comp_64bit
  1110. ****************************************************************************}
  1111. constructor tai_comp_64bit.Create(_value : ts64comp);
  1112. begin
  1113. inherited Create;
  1114. typ:=ait_comp_64bit;
  1115. value:=_value;
  1116. end;
  1117. constructor tai_comp_64bit.ppuload(t:taitype;ppufile:tcompilerppufile);
  1118. begin
  1119. inherited ppuload(t,ppufile);
  1120. ppufile.putdata(value,sizeof(value));
  1121. end;
  1122. procedure tai_comp_64bit.ppuwrite(ppufile:tcompilerppufile);
  1123. begin
  1124. inherited ppuwrite(ppufile);
  1125. ppufile.getdata(value,sizeof(value));
  1126. end;
  1127. {****************************************************************************
  1128. TAI_STRING
  1129. ****************************************************************************}
  1130. constructor tai_string.Create(const _str : string);
  1131. begin
  1132. inherited Create;
  1133. typ:=ait_string;
  1134. len:=length(_str);
  1135. getmem(str,len+1);
  1136. strpcopy(str,_str);
  1137. end;
  1138. constructor tai_string.Create_pchar(_str : pchar);
  1139. begin
  1140. inherited Create;
  1141. typ:=ait_string;
  1142. str:=_str;
  1143. len:=strlen(_str);
  1144. end;
  1145. constructor tai_string.Create_length_pchar(_str : pchar;length : longint);
  1146. begin
  1147. inherited Create;
  1148. typ:=ait_string;
  1149. str:=_str;
  1150. len:=length;
  1151. end;
  1152. destructor tai_string.destroy;
  1153. begin
  1154. { you can have #0 inside the strings so }
  1155. if str<>nil then
  1156. freemem(str,len+1);
  1157. inherited Destroy;
  1158. end;
  1159. constructor tai_string.ppuload(t:taitype;ppufile:tcompilerppufile);
  1160. begin
  1161. inherited ppuload(t,ppufile);
  1162. len:=ppufile.getlongint;
  1163. getmem(str,len+1);
  1164. ppufile.getdata(str^,len);
  1165. str[len]:=#0;
  1166. end;
  1167. procedure tai_string.ppuwrite(ppufile:tcompilerppufile);
  1168. begin
  1169. inherited ppuwrite(ppufile);
  1170. ppufile.putlongint(len);
  1171. ppufile.putdata(str^,len);
  1172. end;
  1173. function tai_string.getcopy : tlinkedlistitem;
  1174. var
  1175. p : tlinkedlistitem;
  1176. begin
  1177. p:=inherited getcopy;
  1178. getmem(tai_string(p).str,len+1);
  1179. move(str^,tai_string(p).str^,len+1);
  1180. getcopy:=p;
  1181. end;
  1182. {****************************************************************************
  1183. TAI_LABEL
  1184. ****************************************************************************}
  1185. constructor tai_label.create(_l : tasmlabel);
  1186. begin
  1187. inherited Create;
  1188. typ:=ait_label;
  1189. l:=_l;
  1190. l.is_set:=true;
  1191. is_global:=(l.defbind=AB_GLOBAL);
  1192. end;
  1193. constructor tai_label.ppuload(t:taitype;ppufile:tcompilerppufile);
  1194. begin
  1195. inherited ppuload(t,ppufile);
  1196. l:=tasmlabel(ppufile.getasmsymbol);
  1197. is_global:=boolean(ppufile.getbyte);
  1198. end;
  1199. procedure tai_label.ppuwrite(ppufile:tcompilerppufile);
  1200. begin
  1201. inherited ppuwrite(ppufile);
  1202. ppufile.putasmsymbol(l);
  1203. ppufile.putbyte(byte(is_global));
  1204. end;
  1205. procedure tai_label.derefimpl;
  1206. begin
  1207. objectlibrary.DerefAsmsymbol(tasmsymbol(l));
  1208. l.is_set:=true;
  1209. end;
  1210. {****************************************************************************
  1211. TAI_DIRECT
  1212. ****************************************************************************}
  1213. constructor tai_direct.Create(_str : pchar);
  1214. begin
  1215. inherited Create;
  1216. typ:=ait_direct;
  1217. str:=_str;
  1218. end;
  1219. destructor tai_direct.destroy;
  1220. begin
  1221. strdispose(str);
  1222. inherited Destroy;
  1223. end;
  1224. constructor tai_direct.ppuload(t:taitype;ppufile:tcompilerppufile);
  1225. var
  1226. len : longint;
  1227. begin
  1228. inherited ppuload(t,ppufile);
  1229. len:=ppufile.getlongint;
  1230. getmem(str,len+1);
  1231. ppufile.getdata(str^,len);
  1232. str[len]:=#0;
  1233. end;
  1234. procedure tai_direct.ppuwrite(ppufile:tcompilerppufile);
  1235. var
  1236. len : longint;
  1237. begin
  1238. inherited ppuwrite(ppufile);
  1239. len:=strlen(str);
  1240. ppufile.putlongint(len);
  1241. ppufile.putdata(str^,len);
  1242. end;
  1243. function tai_direct.getcopy : tlinkedlistitem;
  1244. var
  1245. p : tlinkedlistitem;
  1246. begin
  1247. p:=inherited getcopy;
  1248. getmem(tai_direct(p).str,strlen(str)+1);
  1249. move(str^,tai_direct(p).str^,strlen(str)+1);
  1250. getcopy:=p;
  1251. end;
  1252. {****************************************************************************
  1253. tai_comment comment to be inserted in the assembler file
  1254. ****************************************************************************}
  1255. constructor tai_comment.Create(_str : pchar);
  1256. begin
  1257. inherited Create;
  1258. typ:=ait_comment;
  1259. str:=_str;
  1260. end;
  1261. destructor tai_comment.destroy;
  1262. begin
  1263. strdispose(str);
  1264. inherited Destroy;
  1265. end;
  1266. constructor tai_comment.ppuload(t:taitype;ppufile:tcompilerppufile);
  1267. var
  1268. len : longint;
  1269. begin
  1270. inherited ppuload(t,ppufile);
  1271. len:=ppufile.getlongint;
  1272. getmem(str,len+1);
  1273. ppufile.getdata(str^,len);
  1274. str[len]:=#0;
  1275. end;
  1276. procedure tai_comment.ppuwrite(ppufile:tcompilerppufile);
  1277. var
  1278. len : longint;
  1279. begin
  1280. inherited ppuwrite(ppufile);
  1281. len:=strlen(str);
  1282. ppufile.putlongint(len);
  1283. ppufile.putdata(str^,len);
  1284. end;
  1285. function tai_comment.getcopy : tlinkedlistitem;
  1286. var
  1287. p : tlinkedlistitem;
  1288. begin
  1289. p:=inherited getcopy;
  1290. getmem(tai_comment(p).str,strlen(str)+1);
  1291. move(str^,tai_comment(p).str^,strlen(str)+1);
  1292. getcopy:=p;
  1293. end;
  1294. {****************************************************************************
  1295. TAI_CUTOBJECT
  1296. ****************************************************************************}
  1297. constructor tai_cutobject.Create;
  1298. begin
  1299. inherited Create;
  1300. typ:=ait_cutobject;
  1301. place:=cut_normal;
  1302. end;
  1303. constructor tai_cutobject.Create_begin;
  1304. begin
  1305. inherited Create;
  1306. typ:=ait_cutobject;
  1307. place:=cut_begin;
  1308. end;
  1309. constructor tai_cutobject.Create_end;
  1310. begin
  1311. inherited Create;
  1312. typ:=ait_cutobject;
  1313. place:=cut_end;
  1314. end;
  1315. constructor tai_cutobject.ppuload(t:taitype;ppufile:tcompilerppufile);
  1316. begin
  1317. inherited ppuload(t,ppufile);
  1318. place:=TCutPlace(ppufile.getbyte);
  1319. end;
  1320. procedure tai_cutobject.ppuwrite(ppufile:tcompilerppufile);
  1321. begin
  1322. inherited ppuwrite(ppufile);
  1323. ppufile.putbyte(byte(place));
  1324. end;
  1325. {****************************************************************************
  1326. Tai_Marker
  1327. ****************************************************************************}
  1328. constructor Tai_Marker.Create(_Kind: TMarker);
  1329. begin
  1330. Inherited Create;
  1331. typ := ait_marker;
  1332. Kind := _Kind;
  1333. end;
  1334. constructor Tai_Marker.ppuload(t:taitype;ppufile:tcompilerppufile);
  1335. begin
  1336. inherited ppuload(t,ppufile);
  1337. kind:=TMarker(ppufile.getbyte);
  1338. end;
  1339. procedure Tai_Marker.ppuwrite(ppufile:tcompilerppufile);
  1340. begin
  1341. inherited ppuwrite(ppufile);
  1342. ppufile.putbyte(byte(kind));
  1343. end;
  1344. {*****************************************************************************
  1345. tai_tempalloc
  1346. *****************************************************************************}
  1347. constructor tai_tempalloc.alloc(pos,size:longint);
  1348. begin
  1349. inherited Create;
  1350. typ:=ait_tempalloc;
  1351. allocation:=true;
  1352. temppos:=pos;
  1353. tempsize:=size;
  1354. {$ifdef EXTDEBUG}
  1355. problem:=nil;
  1356. {$endif EXTDEBUG}
  1357. end;
  1358. destructor tai_tempalloc.destroy;
  1359. begin
  1360. {$ifdef EXTDEBUG}
  1361. stringdispose(problem);
  1362. {$endif EXTDEBUG}
  1363. inherited destroy;
  1364. end;
  1365. constructor tai_tempalloc.dealloc(pos,size:longint);
  1366. begin
  1367. inherited Create;
  1368. typ:=ait_tempalloc;
  1369. allocation:=false;
  1370. temppos:=pos;
  1371. tempsize:=size;
  1372. {$ifdef EXTDEBUG}
  1373. problem:=nil;
  1374. {$endif EXTDEBUG}
  1375. end;
  1376. {$ifdef EXTDEBUG}
  1377. constructor tai_tempalloc.allocinfo(pos,size:longint;const st:string);
  1378. begin
  1379. inherited Create;
  1380. typ:=ait_tempalloc;
  1381. allocation:=false;
  1382. temppos:=pos;
  1383. tempsize:=size;
  1384. problem:=stringdup(st);
  1385. end;
  1386. {$endif EXTDEBUG}
  1387. constructor tai_tempalloc.ppuload(t:taitype;ppufile:tcompilerppufile);
  1388. begin
  1389. inherited ppuload(t,ppufile);
  1390. temppos:=ppufile.getlongint;
  1391. tempsize:=ppufile.getlongint;
  1392. allocation:=boolean(ppufile.getbyte);
  1393. {$ifdef EXTDEBUG}
  1394. problem:=nil;
  1395. {$endif EXTDEBUG}
  1396. end;
  1397. procedure tai_tempalloc.ppuwrite(ppufile:tcompilerppufile);
  1398. begin
  1399. inherited ppuwrite(ppufile);
  1400. ppufile.putlongint(temppos);
  1401. ppufile.putlongint(tempsize);
  1402. ppufile.putbyte(byte(allocation));
  1403. end;
  1404. {*****************************************************************************
  1405. tai_regalloc
  1406. *****************************************************************************}
  1407. constructor tai_regalloc.alloc(r : tregister);
  1408. begin
  1409. inherited create;
  1410. typ:=ait_regalloc;
  1411. ratype:=ra_alloc;
  1412. reg:=r;
  1413. end;
  1414. constructor tai_regalloc.dealloc(r : tregister);
  1415. begin
  1416. inherited create;
  1417. typ:=ait_regalloc;
  1418. ratype:=ra_dealloc;
  1419. reg:=r;
  1420. end;
  1421. constructor tai_regalloc.sync(r : tregister);
  1422. begin
  1423. inherited create;
  1424. typ:=ait_regalloc;
  1425. ratype:=ra_sync;
  1426. reg:=r;
  1427. end;
  1428. constructor tai_regalloc.resize(r : tregister);
  1429. begin
  1430. inherited create;
  1431. typ:=ait_regalloc;
  1432. ratype:=ra_resize;
  1433. reg:=r;
  1434. end;
  1435. constructor tai_regalloc.ppuload(t:taitype;ppufile:tcompilerppufile);
  1436. begin
  1437. inherited ppuload(t,ppufile);
  1438. ppufile.getdata(reg,sizeof(Tregister));
  1439. ratype:=tregalloctype(ppufile.getbyte);
  1440. end;
  1441. procedure tai_regalloc.ppuwrite(ppufile:tcompilerppufile);
  1442. begin
  1443. inherited ppuwrite(ppufile);
  1444. ppufile.putdata(reg,sizeof(Tregister));
  1445. ppufile.putbyte(byte(ratype));
  1446. end;
  1447. {*****************************************************************************
  1448. TaiInstruction
  1449. *****************************************************************************}
  1450. constructor tai_cpu_abstract.Create(op : tasmop);
  1451. begin
  1452. inherited create;
  1453. typ:=ait_instruction;
  1454. is_jmp:=false;
  1455. opcode:=op;
  1456. ops:=0;
  1457. fillchar(condition,sizeof(condition),0);
  1458. fillchar(oper,sizeof(oper),0);
  1459. end;
  1460. destructor tai_cpu_abstract.Destroy;
  1461. var
  1462. i : integer;
  1463. begin
  1464. for i:=0 to opercnt-1 do
  1465. begin
  1466. clearop(i);
  1467. dispose(oper[i]);
  1468. end;
  1469. inherited destroy;
  1470. end;
  1471. { ---------------------------------------------------------------------
  1472. Loading of operands.
  1473. ---------------------------------------------------------------------}
  1474. procedure tai_cpu_abstract.allocate_oper(opers:longint);
  1475. begin
  1476. while (opers>opercnt) do
  1477. begin
  1478. new(oper[opercnt]);
  1479. fillchar(oper[opercnt]^,sizeof(toper),0);
  1480. inc(opercnt);
  1481. end;
  1482. end;
  1483. procedure tai_cpu_abstract.loadconst(opidx:longint;l:aint);
  1484. begin
  1485. allocate_oper(opidx+1);
  1486. with oper[opidx]^ do
  1487. begin
  1488. if typ<>top_const then
  1489. clearop(opidx);
  1490. val:=l;
  1491. typ:=top_const;
  1492. end;
  1493. end;
  1494. procedure tai_cpu_abstract.loadsymbol(opidx:longint;s:tasmsymbol;sofs:longint);
  1495. var
  1496. r : treference;
  1497. begin
  1498. reference_reset_symbol(r,s,sofs);
  1499. r.refaddr:=addr_full;
  1500. loadref(opidx,r);
  1501. end;
  1502. procedure tai_cpu_abstract.loadlocal(opidx:longint;s:pointer;sofs:longint;indexreg:tregister;scale:byte;getoffset:boolean);
  1503. begin
  1504. if not assigned(s) then
  1505. internalerror(200204251);
  1506. allocate_oper(opidx+1);
  1507. with oper[opidx]^ do
  1508. begin
  1509. if typ<>top_local then
  1510. begin
  1511. clearop(opidx);
  1512. new(localoper);
  1513. end;
  1514. with oper[opidx]^.localoper^ do
  1515. begin
  1516. localsym:=s;
  1517. localsymofs:=sofs;
  1518. localindexreg:=indexreg;
  1519. localscale:=scale;
  1520. localgetoffset:=getoffset;
  1521. end;
  1522. typ:=top_local;
  1523. end;
  1524. end;
  1525. procedure tai_cpu_abstract.loadref(opidx:longint;const r:treference);
  1526. begin
  1527. allocate_oper(opidx+1);
  1528. with oper[opidx]^ do
  1529. begin
  1530. if typ<>top_ref then
  1531. begin
  1532. clearop(opidx);
  1533. new(ref);
  1534. end;
  1535. ref^:=r;
  1536. {$ifdef x86}
  1537. { We allow this exception for x86, since overloading this would be
  1538. too much of a a speed penalty}
  1539. if (ref^.segment<>NR_NO) and (ref^.segment<>NR_DS) then
  1540. segprefix:=ref^.segment;
  1541. {$endif}
  1542. typ:=top_ref;
  1543. if assigned(add_reg_instruction_hook) then
  1544. begin
  1545. add_reg_instruction_hook(self,ref^.base);
  1546. add_reg_instruction_hook(self,ref^.index);
  1547. end;
  1548. { mark symbol as used }
  1549. if assigned(ref^.symbol) then
  1550. ref^.symbol.increfs;
  1551. end;
  1552. end;
  1553. procedure tai_cpu_abstract.loadreg(opidx:longint;r:tregister);
  1554. begin
  1555. allocate_oper(opidx+1);
  1556. with oper[opidx]^ do
  1557. begin
  1558. if typ<>top_reg then
  1559. clearop(opidx);
  1560. reg:=r;
  1561. typ:=top_reg;
  1562. end;
  1563. if assigned(add_reg_instruction_hook) then
  1564. add_reg_instruction_hook(self,r);
  1565. {$ifdef ARM}
  1566. { R15 is the PC on the ARM thus moves to R15 are jumps.
  1567. Due to speed considerations we don't use a virtual overridden method here.
  1568. Because the pc/r15 isn't handled by the reg. allocator this should never cause
  1569. problems with iregs getting r15.
  1570. }
  1571. is_jmp:=(opcode=A_MOV) and (opidx=0) and (r=NR_R15);
  1572. {$endif ARM}
  1573. end;
  1574. procedure tai_cpu_abstract.loadoper(opidx:longint;o:toper);
  1575. begin
  1576. allocate_oper(opidx+1);
  1577. clearop(opidx);
  1578. oper[opidx]^:=o;
  1579. { copy also the reference }
  1580. with oper[opidx]^ do
  1581. begin
  1582. case typ of
  1583. top_reg:
  1584. begin
  1585. if assigned(add_reg_instruction_hook) then
  1586. add_reg_instruction_hook(self,reg);
  1587. end;
  1588. top_ref:
  1589. begin
  1590. new(ref);
  1591. ref^:=o.ref^;
  1592. if assigned(add_reg_instruction_hook) then
  1593. begin
  1594. add_reg_instruction_hook(self,ref^.base);
  1595. add_reg_instruction_hook(self,ref^.index);
  1596. end;
  1597. end;
  1598. {$ifdef ARM}
  1599. top_shifterop:
  1600. begin
  1601. new(shifterop);
  1602. shifterop^:=o.shifterop^;
  1603. if assigned(add_reg_instruction_hook) then
  1604. add_reg_instruction_hook(self,shifterop^.rs);
  1605. end;
  1606. {$endif ARM}
  1607. end;
  1608. end;
  1609. end;
  1610. procedure tai_cpu_abstract.clearop(opidx:longint);
  1611. begin
  1612. with oper[opidx]^ do
  1613. begin
  1614. case typ of
  1615. top_ref:
  1616. dispose(ref);
  1617. top_local:
  1618. dispose(localoper);
  1619. {$ifdef ARM}
  1620. top_shifterop:
  1621. dispose(shifterop);
  1622. top_regset:
  1623. dispose(regset);
  1624. {$endif ARM}
  1625. end;
  1626. typ:=top_none;
  1627. end;
  1628. end;
  1629. { ---------------------------------------------------------------------
  1630. Miscellaneous methods.
  1631. ---------------------------------------------------------------------}
  1632. procedure tai_cpu_abstract.SetCondition(const c:TAsmCond);
  1633. begin
  1634. condition:=c;
  1635. end;
  1636. Function tai_cpu_abstract.getcopy:TLinkedListItem;
  1637. var
  1638. i : longint;
  1639. p : tai_cpu_abstract;
  1640. begin
  1641. p:=tai_cpu_abstract(inherited getcopy);
  1642. { make a copy of the references }
  1643. p.opercnt:=0;
  1644. p.allocate_oper(ops);
  1645. for i:=0 to ops-1 do
  1646. begin
  1647. p.oper[i]^:=oper[i]^;
  1648. case oper[i]^.typ of
  1649. top_local :
  1650. begin
  1651. new(p.oper[i]^.localoper);
  1652. p.oper[i]^.localoper^:=oper[i]^.localoper^;
  1653. end;
  1654. top_ref :
  1655. begin
  1656. new(p.oper[i]^.ref);
  1657. p.oper[i]^.ref^:=oper[i]^.ref^;
  1658. end;
  1659. {$ifdef ARM}
  1660. top_shifterop:
  1661. begin
  1662. new(p.oper[i]^.shifterop);
  1663. p.oper[i]^.shifterop^:=oper[i]^.shifterop^;
  1664. end;
  1665. {$endif ARM}
  1666. end;
  1667. end;
  1668. getcopy:=p;
  1669. end;
  1670. function tai_cpu_abstract.is_same_reg_move(regtype: Tregistertype):boolean;
  1671. begin
  1672. { When the generic RA is used this needs to be overriden, we don't use
  1673. virtual;abstract; to prevent a lot of warnings of unimplemented abstract methods
  1674. when tai_cpu is created (PFV) }
  1675. internalerror(200404091);
  1676. end;
  1677. function tai_cpu_abstract.spilling_get_operation_type(opnr: longint): topertype;
  1678. begin
  1679. internalerror(200404091);
  1680. end;
  1681. constructor tai_cpu_abstract.ppuload(t:taitype;ppufile:tcompilerppufile);
  1682. var
  1683. i : integer;
  1684. begin
  1685. inherited ppuload(t,ppufile);
  1686. { hopefully, we don't get problems with big/litte endian here when cross compiling :/ }
  1687. ppufile.getdata(condition,sizeof(tasmcond));
  1688. allocate_oper(ppufile.getbyte);
  1689. for i:=0 to ops-1 do
  1690. ppuloadoper(ppufile,oper[i]^);
  1691. opcode:=tasmop(ppufile.getword);
  1692. {$ifdef x86}
  1693. ppufile.getdata(segprefix,sizeof(Tregister));
  1694. {$endif x86}
  1695. is_jmp:=boolean(ppufile.getbyte);
  1696. end;
  1697. procedure tai_cpu_abstract.ppuwrite(ppufile:tcompilerppufile);
  1698. var
  1699. i : integer;
  1700. begin
  1701. inherited ppuwrite(ppufile);
  1702. ppufile.putdata(condition,sizeof(tasmcond));
  1703. ppufile.putbyte(ops);
  1704. for i:=0 to ops-1 do
  1705. ppuwriteoper(ppufile,oper[i]^);
  1706. ppufile.putword(word(opcode));
  1707. {$ifdef x86}
  1708. ppufile.putdata(segprefix,sizeof(Tregister));
  1709. {$endif x86}
  1710. ppufile.putbyte(byte(is_jmp));
  1711. end;
  1712. procedure tai_cpu_abstract.buildderefimpl;
  1713. var
  1714. i : integer;
  1715. begin
  1716. for i:=0 to ops-1 do
  1717. ppubuildderefimploper(oper[i]^);
  1718. end;
  1719. procedure tai_cpu_abstract.derefimpl;
  1720. var
  1721. i : integer;
  1722. begin
  1723. for i:=0 to ops-1 do
  1724. ppuderefoper(oper[i]^);
  1725. end;
  1726. {****************************************************************************
  1727. tai_align_abstract
  1728. ****************************************************************************}
  1729. constructor tai_align_abstract.Create(b: byte);
  1730. begin
  1731. inherited Create;
  1732. typ:=ait_align;
  1733. if b in [1,2,4,8,16,32] then
  1734. aligntype := b
  1735. else
  1736. aligntype := 1;
  1737. fillsize:=0;
  1738. fillop:=0;
  1739. use_op:=false;
  1740. end;
  1741. constructor tai_align_abstract.Create_op(b: byte; _op: byte);
  1742. begin
  1743. inherited Create;
  1744. typ:=ait_align;
  1745. if b in [1,2,4,8,16,32] then
  1746. aligntype := b
  1747. else
  1748. aligntype := 1;
  1749. fillsize:=0;
  1750. fillop:=_op;
  1751. use_op:=true;
  1752. end;
  1753. constructor tai_align_abstract.Create_zeros(b: byte);
  1754. begin
  1755. inherited Create;
  1756. typ:=ait_align;
  1757. if b in [1,2,4,8,16,32] then
  1758. aligntype := b
  1759. else
  1760. aligntype := 1;
  1761. use_op:=true;
  1762. fillsize:=0;
  1763. fillop:=0;
  1764. end;
  1765. function tai_align_abstract.calculatefillbuf(var buf : tfillbuffer):pchar;
  1766. begin
  1767. if fillsize>sizeof(buf) then
  1768. internalerror(200404293);
  1769. fillchar(buf,high(buf),fillop);
  1770. calculatefillbuf:=pchar(@buf);
  1771. end;
  1772. constructor tai_align_abstract.ppuload(t:taitype;ppufile:tcompilerppufile);
  1773. begin
  1774. inherited ppuload(t,ppufile);
  1775. aligntype:=ppufile.getbyte;
  1776. fillsize:=0;
  1777. fillop:=ppufile.getbyte;
  1778. use_op:=boolean(ppufile.getbyte);
  1779. end;
  1780. procedure tai_align_abstract.ppuwrite(ppufile:tcompilerppufile);
  1781. begin
  1782. inherited ppuwrite(ppufile);
  1783. ppufile.putbyte(aligntype);
  1784. ppufile.putbyte(fillop);
  1785. ppufile.putbyte(byte(use_op));
  1786. end;
  1787. {*****************************************************************************
  1788. TAAsmOutput
  1789. *****************************************************************************}
  1790. constructor taasmoutput.create;
  1791. begin
  1792. inherited create;
  1793. { make sure the optimizer won't remove the first tai of this list}
  1794. insert(tai_marker.create(marker_blockstart));
  1795. end;
  1796. function taasmoutput.empty : boolean;
  1797. begin
  1798. { there is always a marker_blockstart available,
  1799. see taasmoutput.create }
  1800. result:=(count<=1);
  1801. end;
  1802. function taasmoutput.getlasttaifilepos : pfileposinfo;
  1803. var
  1804. hp : tlinkedlistitem;
  1805. begin
  1806. getlasttaifilepos := nil;
  1807. if assigned(last) then
  1808. begin
  1809. { find the last file information record }
  1810. if not (tai(last).typ in SkipLineInfo) then
  1811. getlasttaifilepos:=@tailineinfo(last).fileinfo
  1812. else
  1813. { go through list backwards to find the first entry
  1814. with line information
  1815. }
  1816. begin
  1817. hp:=tai(last);
  1818. while assigned(hp) and (tai(hp).typ in SkipLineInfo) do
  1819. hp:=hp.Previous;
  1820. { found entry }
  1821. if assigned(hp) then
  1822. getlasttaifilepos:=@tailineinfo(hp).fileinfo
  1823. end;
  1824. end;
  1825. end;
  1826. procedure Taasmoutput.InsertAfter(Item,Loc : TLinkedListItem);
  1827. begin
  1828. { This is not possible because it is not sure that the
  1829. tai at Loc has taifileinfo as parent }
  1830. {if assigned(Loc) then
  1831. tailineinfo(Item).fileinfo:=tailineinfo(Loc).fileinfo;}
  1832. inherited InsertAfter(Item,Loc);
  1833. end;
  1834. begin
  1835. cai_cpu:=tai_cpu_abstract;
  1836. cai_align:=tai_align_abstract;
  1837. end.
  1838. {
  1839. $Log$
  1840. Revision 1.89 2004-09-26 17:45:29 peter
  1841. * simple regvar support, not yet finished
  1842. Revision 1.88 2004/08/15 13:30:18 florian
  1843. * fixed alignment of variant records
  1844. * more alignment problems fixed
  1845. Revision 1.87 2004/08/14 14:50:42 florian
  1846. * fixed several sparc alignment issues
  1847. + Jonas' inline node patch; non functional yet
  1848. Revision 1.86 2004/06/20 08:55:28 florian
  1849. * logs truncated
  1850. Revision 1.85 2004/06/16 20:07:06 florian
  1851. * dwarf branch merged
  1852. Revision 1.84 2004/05/23 14:31:05 peter
  1853. * ignore marker block when checking for empty list
  1854. Revision 1.83 2004/05/22 23:34:27 peter
  1855. tai_regalloc.allocation changed to ratype to notify rgobj of register size changes
  1856. Revision 1.82 2004/04/12 18:59:32 florian
  1857. * small x86_64 fixes
  1858. Revision 1.81.2.14 2004/06/13 10:51:16 florian
  1859. * fixed several register allocator problems (sparc/arm)
  1860. }