aasmtai.pas 71 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394
  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,
  31. symppu,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. ait_const_32bit,
  47. ait_const_16bit,
  48. ait_const_8bit,
  49. ait_const_symbol,
  50. { the following is only used by the win32 version of the compiler }
  51. { and only the GNU AS Win32 is able to write it }
  52. ait_const_rva,
  53. ait_real_32bit,
  54. ait_real_64bit,
  55. ait_real_80bit,
  56. ait_comp_64bit,
  57. ait_real_128bit,
  58. {$ifdef GDB}
  59. ait_stabn,
  60. ait_stabs,
  61. ait_force_line,
  62. ait_stab_function_name,
  63. {$endif GDB}
  64. {$ifdef alpha}
  65. { the follow is for the DEC Alpha }
  66. ait_frame,
  67. ait_ent,
  68. {$endif alpha}
  69. {$ifdef ia64}
  70. ait_bundle,
  71. ait_stop,
  72. {$endif ia64}
  73. {$ifdef m68k}
  74. ait_labeled_instruction,
  75. {$endif m68k}
  76. {$ifdef SPARC}
  77. ait_labeled_instruction,
  78. {$endif SPARC}
  79. ait_cut, { used to split into tiny assembler files }
  80. ait_regalloc,
  81. ait_tempalloc,
  82. ait_marker { used to mark assembler blocks and inlined functions }
  83. );
  84. const
  85. taitypestr : array[taitype] of string[14] = (
  86. '<none>',
  87. 'align',
  88. 'section',
  89. 'comment',
  90. 'direct',
  91. 'string',
  92. 'instruction',
  93. 'datablock',
  94. 'symbol',
  95. 'symbol_end',
  96. 'label',
  97. 'const_32bit',
  98. 'const_16bit',
  99. 'const_8bit',
  100. 'const_symbol',
  101. 'const_rva',
  102. 'real_32bit',
  103. 'real_64bit',
  104. 'real_80bit',
  105. 'comp_64bit',
  106. 'real_128bit',
  107. {$ifdef GDB}
  108. 'stabn',
  109. 'stabs',
  110. 'force_line',
  111. 'stab_funcname',
  112. {$endif GDB}
  113. {$ifdef alpha}
  114. { the follow is for the DEC Alpha }
  115. 'frame',
  116. 'ent',
  117. {$endif alpha}
  118. {$ifdef ia64}
  119. 'bundle',
  120. 'stop',
  121. {$endif ia64}
  122. {$ifdef m68k}
  123. 'labeled_instr',
  124. {$endif m68k}
  125. {$ifdef SPARC}
  126. 'labeled_instr',
  127. {$endif SPARC}
  128. 'cut',
  129. 'regalloc',
  130. 'tempalloc',
  131. 'marker'
  132. );
  133. type
  134. { Types of operand }
  135. toptype=(top_none,top_reg,top_ref,top_const,top_symbol,top_bool,top_local);
  136. toper=record
  137. ot : longint;
  138. case typ : toptype of
  139. top_none : ();
  140. top_reg : (reg:tregister);
  141. top_ref : (ref:preference);
  142. top_const : (val:aword);
  143. top_symbol : (sym:tasmsymbol;symofs:longint);
  144. top_bool : (b:boolean);
  145. { local varsym that will be inserted in pass_2 }
  146. top_local : (localsym:pointer;localsymderef:tderef;localsymofs:longint);
  147. end;
  148. poper=^toper;
  149. { ait_* types which don't result in executable code or which don't influence }
  150. { the way the program runs/behaves, but which may be encountered by the }
  151. { optimizer (= if it's sometimes added to the exprasm list). Update if you add }
  152. { a new ait type! }
  153. const
  154. SkipInstr = [ait_comment, ait_symbol,ait_section
  155. {$ifdef GDB}
  156. ,ait_stabs, ait_stabn, ait_stab_function_name, ait_force_line
  157. {$endif GDB}
  158. ,ait_regalloc, ait_tempalloc, ait_symbol_end];
  159. { ait_* types which do not have line information (and hence which are of type
  160. tai, otherwise, they are of type tailineinfo }
  161. { ait_* types which do not have line information (and hence which are of type
  162. tai, otherwise, they are of type tailineinfo }
  163. SkipLineInfo =[ait_label,
  164. ait_regalloc,ait_tempalloc,
  165. {$ifdef GDB}
  166. ait_stabn,ait_stabs,ait_stab_function_name,
  167. {$endif GDB}
  168. ait_cut,ait_marker,ait_align,ait_section,ait_comment,
  169. ait_const_8bit,ait_const_16bit,ait_const_32bit,
  170. ait_real_32bit,ait_real_64bit,ait_real_80bit,ait_comp_64bit
  171. ];
  172. type
  173. { cut type, required for alphanumeric ordering of the assembler filenames }
  174. TCutPlace=(cut_normal,cut_begin,cut_end);
  175. TMarker = (NoPropInfoStart,NoPropInfoEnd,
  176. AsmBlockStart,AsmBlockEnd,
  177. InlineStart,InlineEnd,marker_blockstart,
  178. marker_position);
  179. { Buffer type used for alignment }
  180. tfillbuffer = array[0..63] of char;
  181. Tspill_temp_list=array[tsuperregister] of Treference;
  182. { abstract assembler item }
  183. tai = class(TLinkedListItem)
  184. {$ifndef NOOPT}
  185. { pointer to record with optimizer info about this tai object }
  186. optinfo : pointer;
  187. {$endif NOOPT}
  188. typ : taitype;
  189. constructor Create;
  190. constructor ppuload(t:taitype;ppufile:tcompilerppufile);virtual;
  191. procedure ppuwrite(ppufile:tcompilerppufile);virtual;
  192. procedure buildderefimpl;virtual;
  193. procedure derefimpl;virtual;
  194. end;
  195. { abstract assembler item with line information }
  196. tailineinfo = class(tai)
  197. fileinfo : tfileposinfo;
  198. constructor Create;
  199. constructor ppuload(t:taitype;ppufile:tcompilerppufile);override;
  200. procedure ppuwrite(ppufile:tcompilerppufile);override;
  201. end;
  202. taiclass = class of tai;
  203. taiclassarray = array[taitype] of taiclass;
  204. { Generates an assembler string }
  205. tai_string = class(tailineinfo)
  206. str : pchar;
  207. { extra len so the string can contain an \0 }
  208. len : longint;
  209. constructor Create(const _str : string);
  210. constructor Create_pchar(_str : pchar);
  211. constructor Create_length_pchar(_str : pchar;length : longint);
  212. destructor Destroy;override;
  213. constructor ppuload(t:taitype;ppufile:tcompilerppufile);override;
  214. procedure ppuwrite(ppufile:tcompilerppufile);override;
  215. function getcopy:tlinkedlistitem;override;
  216. end;
  217. { Generates a common label }
  218. tai_symbol = class(tailineinfo)
  219. is_global : boolean;
  220. sym : tasmsymbol;
  221. size : longint;
  222. constructor Create(_sym:tasmsymbol;siz:longint);
  223. constructor Create_Global(_sym:tasmsymbol;siz:longint);
  224. constructor Createname(const _name : string;siz:longint);
  225. constructor Createname_global(const _name : string;siz:longint);
  226. constructor Createdataname(const _name : string;siz:longint);
  227. constructor Createdataname_global(const _name : string;siz:longint);
  228. constructor ppuload(t:taitype;ppufile:tcompilerppufile);override;
  229. procedure ppuwrite(ppufile:tcompilerppufile);override;
  230. procedure derefimpl;override;
  231. end;
  232. tai_symbol_end = class(tailineinfo)
  233. sym : tasmsymbol;
  234. constructor Create(_sym:tasmsymbol);
  235. constructor Createname(const _name : string);
  236. constructor ppuload(t:taitype;ppufile:tcompilerppufile);override;
  237. procedure ppuwrite(ppufile:tcompilerppufile);override;
  238. procedure derefimpl;override;
  239. end;
  240. { Generates an assembler label }
  241. tai_label = class(tai)
  242. is_global : boolean;
  243. l : tasmlabel;
  244. constructor Create(_l : tasmlabel);
  245. constructor ppuload(t:taitype;ppufile:tcompilerppufile);override;
  246. procedure ppuwrite(ppufile:tcompilerppufile);override;
  247. procedure derefimpl;override;
  248. end;
  249. { Directly output data to final assembler file }
  250. tai_direct = class(tailineinfo)
  251. str : pchar;
  252. constructor Create(_str : pchar);
  253. destructor Destroy; override;
  254. constructor ppuload(t:taitype;ppufile:tcompilerppufile);override;
  255. procedure ppuwrite(ppufile:tcompilerppufile);override;
  256. function getcopy:tlinkedlistitem;override;
  257. end;
  258. { Generates an assembler comment }
  259. tai_comment = class(tai)
  260. str : pchar;
  261. constructor Create(_str : pchar);
  262. destructor Destroy; override;
  263. constructor ppuload(t:taitype;ppufile:tcompilerppufile);override;
  264. procedure ppuwrite(ppufile:tcompilerppufile);override;
  265. function getcopy:tlinkedlistitem;override;
  266. end;
  267. { Generates a section / segment directive }
  268. tai_section = class(tai)
  269. sec : TSection;
  270. constructor Create(s : TSection);
  271. constructor ppuload(t:taitype;ppufile:tcompilerppufile);override;
  272. procedure ppuwrite(ppufile:tcompilerppufile);override;
  273. end;
  274. { Generates an uninitializised data block }
  275. tai_datablock = class(tailineinfo)
  276. is_global : boolean;
  277. sym : tasmsymbol;
  278. size : longint;
  279. constructor Create(const _name : string;_size : longint);
  280. constructor Create_global(const _name : string;_size : longint);
  281. constructor ppuload(t:taitype;ppufile:tcompilerppufile);override;
  282. procedure ppuwrite(ppufile:tcompilerppufile);override;
  283. procedure derefimpl;override;
  284. end;
  285. { Generates a long integer (32 bit) }
  286. tai_const = class(tai)
  287. value : longint;
  288. constructor Create_32bit(_value : longint);
  289. constructor Create_16bit(_value : word);
  290. constructor Create_8bit(_value : byte);
  291. constructor ppuload(t:taitype;ppufile:tcompilerppufile);override;
  292. procedure ppuwrite(ppufile:tcompilerppufile);override;
  293. end;
  294. tai_const_symbol = class(tailineinfo)
  295. sym : tasmsymbol;
  296. offset : longint;
  297. constructor Create(_sym:tasmsymbol);
  298. constructor Create_offset(_sym:tasmsymbol;ofs:longint);
  299. constructor Create_rva(_sym:tasmsymbol);
  300. constructor Createname(const name:string);
  301. constructor Createname_offset(const name:string;ofs:longint);
  302. constructor Createname_rva(const name:string);
  303. constructor Createdataname(const name:string);
  304. constructor ppuload(t:taitype;ppufile:tcompilerppufile);override;
  305. procedure ppuwrite(ppufile:tcompilerppufile);override;
  306. procedure derefimpl;override;
  307. function getcopy:tlinkedlistitem;override;
  308. end;
  309. { Generates a single float (32 bit real) }
  310. tai_real_32bit = class(tai)
  311. value : ts32real;
  312. constructor Create(_value : ts32real);
  313. constructor ppuload(t:taitype;ppufile:tcompilerppufile);override;
  314. procedure ppuwrite(ppufile:tcompilerppufile);override;
  315. end;
  316. { Generates a double float (64 bit real) }
  317. tai_real_64bit = class(tai)
  318. value : ts64real;
  319. constructor Create(_value : ts64real);
  320. constructor ppuload(t:taitype;ppufile:tcompilerppufile);override;
  321. procedure ppuwrite(ppufile:tcompilerppufile);override;
  322. end;
  323. { Generates an extended float (80 bit real) }
  324. tai_real_80bit = class(tai)
  325. value : ts80real;
  326. constructor Create(_value : ts80real);
  327. constructor ppuload(t:taitype;ppufile:tcompilerppufile);override;
  328. procedure ppuwrite(ppufile:tcompilerppufile);override;
  329. end;
  330. { Generates a comp int (integer over 64 bits)
  331. This is Intel 80x86 specific, and is not
  332. really supported on other processors.
  333. }
  334. tai_comp_64bit = class(tai)
  335. value : ts64comp;
  336. constructor Create(_value : ts64comp);
  337. constructor ppuload(t:taitype;ppufile:tcompilerppufile);override;
  338. procedure ppuwrite(ppufile:tcompilerppufile);override;
  339. end;
  340. { Insert a cut to split assembler into several smaller files }
  341. tai_cut = class(tai)
  342. place : tcutplace;
  343. constructor Create;
  344. constructor Create_begin;
  345. constructor Create_end;
  346. constructor ppuload(t:taitype;ppufile:tcompilerppufile);override;
  347. procedure ppuwrite(ppufile:tcompilerppufile);override;
  348. end;
  349. { Insert a marker for assembler and inline blocks }
  350. tai_marker = class(tai)
  351. Kind: TMarker;
  352. Constructor Create(_Kind: TMarker);
  353. constructor ppuload(t:taitype;ppufile:tcompilerppufile);override;
  354. procedure ppuwrite(ppufile:tcompilerppufile);override;
  355. end;
  356. tai_tempalloc = class(tai)
  357. allocation : boolean;
  358. {$ifdef EXTDEBUG}
  359. problem : pstring;
  360. {$endif EXTDEBUG}
  361. temppos,
  362. tempsize : longint;
  363. constructor alloc(pos,size:longint);
  364. constructor dealloc(pos,size:longint);
  365. {$ifdef EXTDEBUG}
  366. constructor allocinfo(pos,size:longint;const st:string);
  367. {$endif EXTDEBUG}
  368. constructor ppuload(t:taitype;ppufile:tcompilerppufile);override;
  369. destructor destroy;override;
  370. procedure ppuwrite(ppufile:tcompilerppufile);override;
  371. end;
  372. tai_regalloc = class(tai)
  373. allocation : boolean;
  374. reg : tregister;
  375. constructor alloc(r : tregister);
  376. constructor dealloc(r : tregister);
  377. constructor ppuload(t:taitype;ppufile:tcompilerppufile);override;
  378. procedure ppuwrite(ppufile:tcompilerppufile);override;
  379. end;
  380. Taasmoutput=class;
  381. Trggetproc=procedure(list:Taasmoutput;position:Tai;subreg:Tsubregister;var result:Tregister) of object;
  382. Trgungetproc=procedure(list:Taasmoutput;position:Tai;r:Tregister) of object;
  383. { Class template for assembler instructions
  384. }
  385. taicpu_abstract = class(tailineinfo)
  386. protected
  387. procedure ppuloadoper(ppufile:tcompilerppufile;var o:toper);virtual;abstract;
  388. procedure ppuwriteoper(ppufile:tcompilerppufile;const o:toper);virtual;abstract;
  389. procedure ppubuildderefimploper(var o:toper);virtual;abstract;
  390. procedure ppuderefoper(var o:toper);virtual;abstract;
  391. public
  392. { Condition flags for instruction }
  393. condition : TAsmCond;
  394. { Number of operands to instruction }
  395. ops : byte;
  396. { Number of allocate oper structures }
  397. opercnt : byte;
  398. { Operands of instruction }
  399. oper : array[0..max_operands-1] of poper;
  400. { Actual opcode of instruction }
  401. opcode : tasmop;
  402. {$ifdef x86}
  403. segprefix : tregister;
  404. {$endif x86}
  405. { true if instruction is a jmp }
  406. is_jmp : boolean; { is this instruction a jump? (needed for optimizer) }
  407. Constructor Create(op : tasmop);
  408. Destructor Destroy;override;
  409. function getcopy:TLinkedListItem;override;
  410. constructor ppuload(t:taitype;ppufile:tcompilerppufile);override;
  411. procedure ppuwrite(ppufile:tcompilerppufile);override;
  412. procedure buildderefimpl;override;
  413. procedure derefimpl;override;
  414. procedure SetCondition(const c:TAsmCond);
  415. procedure allocate_oper(opers:longint);
  416. procedure loadconst(opidx:longint;l:aword);
  417. procedure loadsymbol(opidx:longint;s:tasmsymbol;sofs:longint);
  418. procedure loadlocal(opidx:longint;s:pointer;sofs:longint);
  419. procedure loadref(opidx:longint;const r:treference);
  420. procedure loadreg(opidx:longint;r:tregister);
  421. procedure loadoper(opidx:longint;o:toper);
  422. procedure clearop(opidx:longint);
  423. function is_nop:boolean;virtual;abstract;
  424. function is_move:boolean;virtual;abstract;
  425. { register allocator }
  426. function get_insert_pos(p:Tai;huntfor1,huntfor2,huntfor3:Tsuperregister;var unusedregsint:tsuperregisterset):Tai;
  427. procedure forward_allocation(p:Tai;var unusedregsint:tsuperregisterset);
  428. function spill_registers(list:Taasmoutput;
  429. rgget:Trggetproc;
  430. rgunget:Trgungetproc;
  431. const r:tsuperregisterset;
  432. var unusedregsint:tsuperregisterset;
  433. const spilltemplist:Tspill_temp_list):boolean;virtual;
  434. function spilling_decode_loadstore(op: tasmop; var counterpart: tasmop; var wasload: boolean): boolean;virtual;abstract;
  435. function spilling_create_loadstore(op: tasmop; r:tregister; const ref:treference): tai;virtual;abstract;
  436. function spilling_create_load(const ref:treference;r:tregister): tai;virtual;abstract;
  437. function spilling_create_store(r:tregister; const ref:treference): tai;virtual;abstract;
  438. end;
  439. { alignment for operator }
  440. tai_align_abstract = class(tai)
  441. aligntype : byte; { 1 = no align, 2 = word align, 4 = dword align }
  442. fillsize : byte; { real size to fill }
  443. fillop : byte; { value to fill with - optional }
  444. use_op : boolean;
  445. constructor Create(b:byte);
  446. constructor Create_op(b: byte; _op: byte);
  447. constructor ppuload(t:taitype;ppufile:tcompilerppufile);override;
  448. procedure ppuwrite(ppufile:tcompilerppufile);override;
  449. function calculatefillbuf(var buf : tfillbuffer):pchar;virtual;
  450. end;
  451. taasmoutput = class(tlinkedlist)
  452. constructor create;
  453. function getlasttaifilepos : pfileposinfo;
  454. procedure InsertAfter(Item,Loc : TLinkedListItem);
  455. end;
  456. var
  457. { array with all class types for tais }
  458. aiclass : taiclassarray;
  459. { Current expression list }
  460. exprasmlist : taasmoutput;
  461. { labels for BREAK and CONTINUE }
  462. aktbreaklabel,aktcontinuelabel : tasmlabel;
  463. { label when the result is true or false }
  464. truelabel,falselabel : tasmlabel;
  465. { default lists }
  466. datasegment,codesegment,bsssegment,
  467. debuglist,withdebuglist,consts,
  468. importssection,exportssection,
  469. resourcesection,rttilist,
  470. resourcestringlist : taasmoutput;
  471. function ppuloadai(ppufile:tcompilerppufile):tai;
  472. procedure ppuwriteai(ppufile:tcompilerppufile;n:tai);
  473. implementation
  474. uses
  475. {$ifdef delphi}
  476. sysutils,
  477. {$else}
  478. strings,
  479. {$endif}
  480. verbose;
  481. const
  482. pputaimarker = 254;
  483. {****************************************************************************
  484. Helpers
  485. ****************************************************************************}
  486. function ppuloadai(ppufile:tcompilerppufile):tai;
  487. var
  488. b : byte;
  489. t : taitype;
  490. begin
  491. { marker }
  492. b:=ppufile.getbyte;
  493. if b<>pputaimarker then
  494. internalerror(200208181);
  495. { load nodetype }
  496. t:=taitype(ppufile.getbyte);
  497. if t<>ait_none then
  498. begin
  499. if t>high(taitype) then
  500. internalerror(200208182);
  501. if not assigned(aiclass[t]) then
  502. internalerror(200208183);
  503. {writeln('taiload: ',taitypestr[t]);}
  504. { generate tai of the correct class }
  505. ppuloadai:=aiclass[t].ppuload(t,ppufile);
  506. end
  507. else
  508. ppuloadai:=nil;
  509. end;
  510. procedure ppuwriteai(ppufile:tcompilerppufile;n:tai);
  511. begin
  512. { marker, read by ppuloadnode }
  513. ppufile.putbyte(pputaimarker);
  514. if assigned(n) then
  515. begin
  516. { type, read by ppuloadnode }
  517. ppufile.putbyte(byte(n.typ));
  518. {writeln('taiwrite: ',taitypestr[n.typ]);}
  519. n.ppuwrite(ppufile);
  520. end
  521. else
  522. ppufile.putbyte(byte(ait_none));
  523. end;
  524. {****************************************************************************
  525. TAI
  526. ****************************************************************************}
  527. constructor tai.Create;
  528. begin
  529. {$ifndef NOOPT}
  530. optinfo:=nil;
  531. {$endif NOOPT}
  532. end;
  533. constructor tai.ppuload(t:taitype;ppufile:tcompilerppufile);
  534. begin
  535. typ:=t;
  536. {$ifndef NOOPT}
  537. optinfo:=nil;
  538. {$endif}
  539. end;
  540. procedure tai.ppuwrite(ppufile:tcompilerppufile);
  541. begin
  542. end;
  543. procedure tai.buildderefimpl;
  544. begin
  545. end;
  546. procedure tai.derefimpl;
  547. begin
  548. end;
  549. {****************************************************************************
  550. TAILINEINFO
  551. ****************************************************************************}
  552. constructor tailineinfo.create;
  553. begin
  554. inherited create;
  555. fileinfo:=aktfilepos;
  556. end;
  557. constructor tailineinfo.ppuload(t:taitype;ppufile:tcompilerppufile);
  558. begin
  559. inherited ppuload(t,ppufile);
  560. ppufile.getposinfo(fileinfo);
  561. end;
  562. procedure tailineinfo.ppuwrite(ppufile:tcompilerppufile);
  563. begin
  564. inherited ppuwrite(ppufile);
  565. ppufile.putposinfo(fileinfo);
  566. end;
  567. {****************************************************************************
  568. TAI_SECTION
  569. ****************************************************************************}
  570. constructor tai_section.Create(s : TSection);
  571. begin
  572. inherited Create;
  573. typ:=ait_section;
  574. sec:=s;
  575. end;
  576. constructor tai_section.ppuload(t:taitype;ppufile:tcompilerppufile);
  577. begin
  578. inherited ppuload(t,ppufile);
  579. sec:=tsection(ppufile.getbyte);
  580. end;
  581. procedure tai_section.ppuwrite(ppufile:tcompilerppufile);
  582. begin
  583. inherited ppuwrite(ppufile);
  584. ppufile.putbyte(byte(sec));
  585. end;
  586. {****************************************************************************
  587. TAI_DATABLOCK
  588. ****************************************************************************}
  589. constructor tai_datablock.Create(const _name : string;_size : longint);
  590. begin
  591. inherited Create;
  592. typ:=ait_datablock;
  593. sym:=objectlibrary.newasmsymboltype(_name,AB_LOCAL,AT_DATA);
  594. { keep things aligned }
  595. if _size<=0 then
  596. _size:=4;
  597. size:=_size;
  598. is_global:=false;
  599. end;
  600. constructor tai_datablock.Create_global(const _name : string;_size : longint);
  601. begin
  602. inherited Create;
  603. typ:=ait_datablock;
  604. sym:=objectlibrary.newasmsymboltype(_name,AB_GLOBAL,AT_DATA);
  605. { keep things aligned }
  606. if _size<=0 then
  607. _size:=4;
  608. size:=_size;
  609. is_global:=true;
  610. end;
  611. constructor tai_datablock.ppuload(t:taitype;ppufile:tcompilerppufile);
  612. begin
  613. inherited Create;
  614. sym:=ppufile.getasmsymbol;
  615. size:=ppufile.getlongint;
  616. is_global:=boolean(ppufile.getbyte);
  617. end;
  618. procedure tai_datablock.ppuwrite(ppufile:tcompilerppufile);
  619. begin
  620. inherited ppuwrite(ppufile);
  621. ppufile.putasmsymbol(sym);
  622. ppufile.putlongint(size);
  623. ppufile.putbyte(byte(is_global));
  624. end;
  625. procedure tai_datablock.derefimpl;
  626. begin
  627. objectlibrary.DerefAsmsymbol(sym);
  628. end;
  629. {****************************************************************************
  630. TAI_SYMBOL
  631. ****************************************************************************}
  632. constructor tai_symbol.Create(_sym:tasmsymbol;siz:longint);
  633. begin
  634. inherited Create;
  635. typ:=ait_symbol;
  636. sym:=_sym;
  637. size:=siz;
  638. sym.defbind:=AB_LOCAL;
  639. is_global:=false;
  640. end;
  641. constructor tai_symbol.Create_global(_sym:tasmsymbol;siz:longint);
  642. begin
  643. inherited Create;
  644. typ:=ait_symbol;
  645. sym:=_sym;
  646. size:=siz;
  647. sym.defbind:=AB_GLOBAL;
  648. is_global:=true;
  649. end;
  650. constructor tai_symbol.Createname(const _name : string;siz:longint);
  651. begin
  652. inherited Create;
  653. typ:=ait_symbol;
  654. sym:=objectlibrary.newasmsymboltype(_name,AB_LOCAL,AT_FUNCTION);
  655. size:=siz;
  656. is_global:=false;
  657. end;
  658. constructor tai_symbol.Createname_global(const _name : string;siz:longint);
  659. begin
  660. inherited Create;
  661. typ:=ait_symbol;
  662. sym:=objectlibrary.newasmsymboltype(_name,AB_GLOBAL,AT_FUNCTION);
  663. size:=siz;
  664. is_global:=true;
  665. end;
  666. constructor tai_symbol.Createdataname(const _name : string;siz:longint);
  667. begin
  668. inherited Create;
  669. typ:=ait_symbol;
  670. sym:=objectlibrary.newasmsymboltype(_name,AB_LOCAL,AT_DATA);
  671. size:=siz;
  672. is_global:=false;
  673. end;
  674. constructor tai_symbol.Createdataname_global(const _name : string;siz:longint);
  675. begin
  676. inherited Create;
  677. typ:=ait_symbol;
  678. sym:=objectlibrary.newasmsymboltype(_name,AB_GLOBAL,AT_DATA);
  679. size:=siz;
  680. is_global:=true;
  681. end;
  682. constructor tai_symbol.ppuload(t:taitype;ppufile:tcompilerppufile);
  683. begin
  684. inherited ppuload(t,ppufile);
  685. sym:=ppufile.getasmsymbol;
  686. size:=ppufile.getlongint;
  687. is_global:=boolean(ppufile.getbyte);
  688. end;
  689. procedure tai_symbol.ppuwrite(ppufile:tcompilerppufile);
  690. begin
  691. inherited ppuwrite(ppufile);
  692. ppufile.putasmsymbol(sym);
  693. ppufile.putlongint(size);
  694. ppufile.putbyte(byte(is_global));
  695. end;
  696. procedure tai_symbol.derefimpl;
  697. begin
  698. objectlibrary.DerefAsmsymbol(sym);
  699. end;
  700. {****************************************************************************
  701. TAI_SYMBOL
  702. ****************************************************************************}
  703. constructor tai_symbol_end.Create(_sym:tasmsymbol);
  704. begin
  705. inherited Create;
  706. typ:=ait_symbol_end;
  707. sym:=_sym;
  708. end;
  709. constructor tai_symbol_end.Createname(const _name : string);
  710. begin
  711. inherited Create;
  712. typ:=ait_symbol_end;
  713. sym:=objectlibrary.newasmsymboltype(_name,AB_GLOBAL,AT_NONE);
  714. end;
  715. constructor tai_symbol_end.ppuload(t:taitype;ppufile:tcompilerppufile);
  716. begin
  717. inherited ppuload(t,ppufile);
  718. sym:=ppufile.getasmsymbol;
  719. end;
  720. procedure tai_symbol_end.ppuwrite(ppufile:tcompilerppufile);
  721. begin
  722. inherited ppuwrite(ppufile);
  723. ppufile.putasmsymbol(sym);
  724. end;
  725. procedure tai_symbol_end.derefimpl;
  726. begin
  727. objectlibrary.DerefAsmsymbol(sym);
  728. end;
  729. {****************************************************************************
  730. TAI_CONST
  731. ****************************************************************************}
  732. constructor tai_const.Create_32bit(_value : longint);
  733. begin
  734. inherited Create;
  735. typ:=ait_const_32bit;
  736. value:=_value;
  737. end;
  738. constructor tai_const.Create_16bit(_value : word);
  739. begin
  740. inherited Create;
  741. typ:=ait_const_16bit;
  742. value:=_value;
  743. end;
  744. constructor tai_const.Create_8bit(_value : byte);
  745. begin
  746. inherited Create;
  747. typ:=ait_const_8bit;
  748. value:=_value;
  749. end;
  750. constructor tai_const.ppuload(t:taitype;ppufile:tcompilerppufile);
  751. begin
  752. inherited ppuload(t,ppufile);
  753. value:=ppufile.getlongint;
  754. end;
  755. procedure tai_const.ppuwrite(ppufile:tcompilerppufile);
  756. begin
  757. inherited ppuwrite(ppufile);
  758. ppufile.putlongint(value);
  759. end;
  760. {****************************************************************************
  761. TAI_CONST_SYMBOL
  762. ****************************************************************************}
  763. constructor tai_const_symbol.Create(_sym:tasmsymbol);
  764. begin
  765. inherited Create;
  766. typ:=ait_const_symbol;
  767. sym:=_sym;
  768. offset:=0;
  769. { update sym info }
  770. sym.increfs;
  771. end;
  772. constructor tai_const_symbol.Create_offset(_sym:tasmsymbol;ofs:longint);
  773. begin
  774. inherited Create;
  775. typ:=ait_const_symbol;
  776. sym:=_sym;
  777. offset:=ofs;
  778. { update sym info }
  779. sym.increfs;
  780. end;
  781. constructor tai_const_symbol.Create_rva(_sym:tasmsymbol);
  782. begin
  783. inherited Create;
  784. typ:=ait_const_rva;
  785. sym:=_sym;
  786. offset:=0;
  787. { update sym info }
  788. sym.increfs;
  789. end;
  790. constructor tai_const_symbol.Createname(const name:string);
  791. begin
  792. inherited Create;
  793. typ:=ait_const_symbol;
  794. sym:=objectlibrary.newasmsymbol(name);
  795. offset:=0;
  796. { update sym info }
  797. sym.increfs;
  798. end;
  799. constructor tai_const_symbol.Createname_offset(const name:string;ofs:longint);
  800. begin
  801. inherited Create;
  802. typ:=ait_const_symbol;
  803. sym:=objectlibrary.newasmsymbol(name);
  804. offset:=ofs;
  805. { update sym info }
  806. sym.increfs;
  807. end;
  808. constructor tai_const_symbol.Createname_rva(const name:string);
  809. begin
  810. inherited Create;
  811. typ:=ait_const_rva;
  812. sym:=objectlibrary.newasmsymbol(name);
  813. offset:=0;
  814. { update sym info }
  815. sym.increfs;
  816. end;
  817. constructor tai_const_symbol.Createdataname(const name:string);
  818. begin
  819. inherited Create;
  820. typ:=ait_const_symbol;
  821. sym:=objectlibrary.newasmsymboltype(name,AB_EXTERNAL,AT_DATA);
  822. offset:=0;
  823. { update sym info }
  824. sym.increfs;
  825. end;
  826. constructor tai_const_symbol.ppuload(t:taitype;ppufile:tcompilerppufile);
  827. begin
  828. inherited ppuload(t,ppufile);
  829. sym:=ppufile.getasmsymbol;
  830. offset:=ppufile.getlongint;
  831. end;
  832. procedure tai_const_symbol.ppuwrite(ppufile:tcompilerppufile);
  833. begin
  834. inherited ppuwrite(ppufile);
  835. ppufile.putasmsymbol(sym);
  836. ppufile.putlongint(offset);
  837. end;
  838. procedure tai_const_symbol.derefimpl;
  839. begin
  840. objectlibrary.DerefAsmsymbol(sym);
  841. end;
  842. function tai_const_symbol.getcopy:tlinkedlistitem;
  843. begin
  844. getcopy:=inherited getcopy;
  845. { we need to increase the reference number }
  846. sym.increfs;
  847. end;
  848. {****************************************************************************
  849. TAI_real_32bit
  850. ****************************************************************************}
  851. constructor tai_real_32bit.Create(_value : ts32real);
  852. begin
  853. inherited Create;
  854. typ:=ait_real_32bit;
  855. value:=_value;
  856. end;
  857. constructor tai_real_32bit.ppuload(t:taitype;ppufile:tcompilerppufile);
  858. begin
  859. inherited ppuload(t,ppufile);
  860. value:=ppufile.getreal;
  861. end;
  862. procedure tai_real_32bit.ppuwrite(ppufile:tcompilerppufile);
  863. begin
  864. inherited ppuwrite(ppufile);
  865. ppufile.putreal(value);
  866. end;
  867. {****************************************************************************
  868. TAI_real_64bit
  869. ****************************************************************************}
  870. constructor tai_real_64bit.Create(_value : ts64real);
  871. begin
  872. inherited Create;
  873. typ:=ait_real_64bit;
  874. value:=_value;
  875. end;
  876. constructor tai_real_64bit.ppuload(t:taitype;ppufile:tcompilerppufile);
  877. begin
  878. inherited ppuload(t,ppufile);
  879. value:=ppufile.getreal;
  880. end;
  881. procedure tai_real_64bit.ppuwrite(ppufile:tcompilerppufile);
  882. begin
  883. inherited ppuwrite(ppufile);
  884. ppufile.putreal(value);
  885. end;
  886. {****************************************************************************
  887. TAI_real_80bit
  888. ****************************************************************************}
  889. constructor tai_real_80bit.Create(_value : ts80real);
  890. begin
  891. inherited Create;
  892. typ:=ait_real_80bit;
  893. value:=_value;
  894. end;
  895. constructor tai_real_80bit.ppuload(t:taitype;ppufile:tcompilerppufile);
  896. begin
  897. inherited ppuload(t,ppufile);
  898. value:=ppufile.getreal;
  899. end;
  900. procedure tai_real_80bit.ppuwrite(ppufile:tcompilerppufile);
  901. begin
  902. inherited ppuwrite(ppufile);
  903. ppufile.putreal(value);
  904. end;
  905. {****************************************************************************
  906. Tai_comp_64bit
  907. ****************************************************************************}
  908. constructor tai_comp_64bit.Create(_value : ts64comp);
  909. begin
  910. inherited Create;
  911. typ:=ait_comp_64bit;
  912. value:=_value;
  913. end;
  914. constructor tai_comp_64bit.ppuload(t:taitype;ppufile:tcompilerppufile);
  915. begin
  916. inherited ppuload(t,ppufile);
  917. ppufile.putdata(value,sizeof(value));
  918. end;
  919. procedure tai_comp_64bit.ppuwrite(ppufile:tcompilerppufile);
  920. begin
  921. inherited ppuwrite(ppufile);
  922. ppufile.getdata(value,sizeof(value));
  923. end;
  924. {****************************************************************************
  925. TAI_STRING
  926. ****************************************************************************}
  927. constructor tai_string.Create(const _str : string);
  928. begin
  929. inherited Create;
  930. typ:=ait_string;
  931. len:=length(_str);
  932. getmem(str,len+1);
  933. strpcopy(str,_str);
  934. end;
  935. constructor tai_string.Create_pchar(_str : pchar);
  936. begin
  937. inherited Create;
  938. typ:=ait_string;
  939. str:=_str;
  940. len:=strlen(_str);
  941. end;
  942. constructor tai_string.Create_length_pchar(_str : pchar;length : longint);
  943. begin
  944. inherited Create;
  945. typ:=ait_string;
  946. str:=_str;
  947. len:=length;
  948. end;
  949. destructor tai_string.destroy;
  950. begin
  951. { you can have #0 inside the strings so }
  952. if str<>nil then
  953. freemem(str,len+1);
  954. inherited Destroy;
  955. end;
  956. constructor tai_string.ppuload(t:taitype;ppufile:tcompilerppufile);
  957. begin
  958. inherited ppuload(t,ppufile);
  959. len:=ppufile.getlongint;
  960. getmem(str,len+1);
  961. ppufile.getdata(str^,len);
  962. str[len]:=#0;
  963. end;
  964. procedure tai_string.ppuwrite(ppufile:tcompilerppufile);
  965. begin
  966. inherited ppuwrite(ppufile);
  967. ppufile.putlongint(len);
  968. ppufile.putdata(str^,len);
  969. end;
  970. function tai_string.getcopy : tlinkedlistitem;
  971. var
  972. p : tlinkedlistitem;
  973. begin
  974. p:=inherited getcopy;
  975. getmem(tai_string(p).str,len+1);
  976. move(str^,tai_string(p).str^,len+1);
  977. getcopy:=p;
  978. end;
  979. {****************************************************************************
  980. TAI_LABEL
  981. ****************************************************************************}
  982. constructor tai_label.create(_l : tasmlabel);
  983. begin
  984. inherited Create;
  985. typ:=ait_label;
  986. l:=_l;
  987. l.is_set:=true;
  988. is_global:=(l.defbind=AB_GLOBAL);
  989. end;
  990. constructor tai_label.ppuload(t:taitype;ppufile:tcompilerppufile);
  991. begin
  992. inherited ppuload(t,ppufile);
  993. l:=tasmlabel(ppufile.getasmsymbol);
  994. is_global:=boolean(ppufile.getbyte);
  995. end;
  996. procedure tai_label.ppuwrite(ppufile:tcompilerppufile);
  997. begin
  998. inherited ppuwrite(ppufile);
  999. ppufile.putasmsymbol(l);
  1000. ppufile.putbyte(byte(is_global));
  1001. end;
  1002. procedure tai_label.derefimpl;
  1003. begin
  1004. objectlibrary.DerefAsmsymbol(tasmsymbol(l));
  1005. l.is_set:=true;
  1006. end;
  1007. {****************************************************************************
  1008. TAI_DIRECT
  1009. ****************************************************************************}
  1010. constructor tai_direct.Create(_str : pchar);
  1011. begin
  1012. inherited Create;
  1013. typ:=ait_direct;
  1014. str:=_str;
  1015. end;
  1016. destructor tai_direct.destroy;
  1017. begin
  1018. strdispose(str);
  1019. inherited Destroy;
  1020. end;
  1021. constructor tai_direct.ppuload(t:taitype;ppufile:tcompilerppufile);
  1022. var
  1023. len : longint;
  1024. begin
  1025. inherited ppuload(t,ppufile);
  1026. len:=ppufile.getlongint;
  1027. getmem(str,len+1);
  1028. ppufile.getdata(str^,len);
  1029. str[len]:=#0;
  1030. end;
  1031. procedure tai_direct.ppuwrite(ppufile:tcompilerppufile);
  1032. var
  1033. len : longint;
  1034. begin
  1035. inherited ppuwrite(ppufile);
  1036. len:=strlen(str);
  1037. ppufile.putlongint(len);
  1038. ppufile.putdata(str^,len);
  1039. end;
  1040. function tai_direct.getcopy : tlinkedlistitem;
  1041. var
  1042. p : tlinkedlistitem;
  1043. begin
  1044. p:=inherited getcopy;
  1045. getmem(tai_direct(p).str,strlen(str)+1);
  1046. move(str^,tai_direct(p).str^,strlen(str)+1);
  1047. getcopy:=p;
  1048. end;
  1049. {****************************************************************************
  1050. tai_comment comment to be inserted in the assembler file
  1051. ****************************************************************************}
  1052. constructor tai_comment.Create(_str : pchar);
  1053. begin
  1054. inherited Create;
  1055. typ:=ait_comment;
  1056. str:=_str;
  1057. end;
  1058. destructor tai_comment.destroy;
  1059. begin
  1060. strdispose(str);
  1061. inherited Destroy;
  1062. end;
  1063. constructor tai_comment.ppuload(t:taitype;ppufile:tcompilerppufile);
  1064. var
  1065. len : longint;
  1066. begin
  1067. inherited ppuload(t,ppufile);
  1068. len:=ppufile.getlongint;
  1069. getmem(str,len+1);
  1070. ppufile.getdata(str^,len);
  1071. str[len]:=#0;
  1072. end;
  1073. procedure tai_comment.ppuwrite(ppufile:tcompilerppufile);
  1074. var
  1075. len : longint;
  1076. begin
  1077. inherited ppuwrite(ppufile);
  1078. len:=strlen(str);
  1079. ppufile.putlongint(len);
  1080. ppufile.putdata(str^,len);
  1081. end;
  1082. function tai_comment.getcopy : tlinkedlistitem;
  1083. var
  1084. p : tlinkedlistitem;
  1085. begin
  1086. p:=inherited getcopy;
  1087. getmem(tai_comment(p).str,strlen(str)+1);
  1088. move(str^,tai_comment(p).str^,strlen(str)+1);
  1089. getcopy:=p;
  1090. end;
  1091. {****************************************************************************
  1092. TAI_CUT
  1093. ****************************************************************************}
  1094. constructor tai_cut.Create;
  1095. begin
  1096. inherited Create;
  1097. typ:=ait_cut;
  1098. place:=cut_normal;
  1099. end;
  1100. constructor tai_cut.Create_begin;
  1101. begin
  1102. inherited Create;
  1103. typ:=ait_cut;
  1104. place:=cut_begin;
  1105. end;
  1106. constructor tai_cut.Create_end;
  1107. begin
  1108. inherited Create;
  1109. typ:=ait_cut;
  1110. place:=cut_end;
  1111. end;
  1112. constructor tai_cut.ppuload(t:taitype;ppufile:tcompilerppufile);
  1113. begin
  1114. inherited ppuload(t,ppufile);
  1115. place:=TCutPlace(ppufile.getbyte);
  1116. end;
  1117. procedure tai_cut.ppuwrite(ppufile:tcompilerppufile);
  1118. begin
  1119. inherited ppuwrite(ppufile);
  1120. ppufile.putbyte(byte(place));
  1121. end;
  1122. {****************************************************************************
  1123. Tai_Marker
  1124. ****************************************************************************}
  1125. constructor Tai_Marker.Create(_Kind: TMarker);
  1126. begin
  1127. Inherited Create;
  1128. typ := ait_marker;
  1129. Kind := _Kind;
  1130. end;
  1131. constructor Tai_Marker.ppuload(t:taitype;ppufile:tcompilerppufile);
  1132. begin
  1133. inherited ppuload(t,ppufile);
  1134. kind:=TMarker(ppufile.getbyte);
  1135. end;
  1136. procedure Tai_Marker.ppuwrite(ppufile:tcompilerppufile);
  1137. begin
  1138. inherited ppuwrite(ppufile);
  1139. ppufile.putbyte(byte(kind));
  1140. end;
  1141. {*****************************************************************************
  1142. tai_tempalloc
  1143. *****************************************************************************}
  1144. constructor tai_tempalloc.alloc(pos,size:longint);
  1145. begin
  1146. inherited Create;
  1147. typ:=ait_tempalloc;
  1148. allocation:=true;
  1149. temppos:=pos;
  1150. tempsize:=size;
  1151. {$ifdef EXTDEBUG}
  1152. problem:=nil;
  1153. {$endif EXTDEBUG}
  1154. end;
  1155. destructor tai_tempalloc.destroy;
  1156. begin
  1157. {$ifdef EXTDEBUG}
  1158. stringdispose(problem);
  1159. {$endif EXTDEBUG}
  1160. inherited destroy;
  1161. end;
  1162. constructor tai_tempalloc.dealloc(pos,size:longint);
  1163. begin
  1164. inherited Create;
  1165. typ:=ait_tempalloc;
  1166. allocation:=false;
  1167. temppos:=pos;
  1168. tempsize:=size;
  1169. {$ifdef EXTDEBUG}
  1170. problem:=nil;
  1171. {$endif EXTDEBUG}
  1172. end;
  1173. {$ifdef EXTDEBUG}
  1174. constructor tai_tempalloc.allocinfo(pos,size:longint;const st:string);
  1175. begin
  1176. inherited Create;
  1177. typ:=ait_tempalloc;
  1178. allocation:=false;
  1179. temppos:=pos;
  1180. tempsize:=size;
  1181. problem:=stringdup(st);
  1182. end;
  1183. {$endif EXTDEBUG}
  1184. constructor tai_tempalloc.ppuload(t:taitype;ppufile:tcompilerppufile);
  1185. begin
  1186. inherited ppuload(t,ppufile);
  1187. temppos:=ppufile.getlongint;
  1188. tempsize:=ppufile.getlongint;
  1189. allocation:=boolean(ppufile.getbyte);
  1190. {$ifdef EXTDEBUG}
  1191. problem:=nil;
  1192. {$endif EXTDEBUG}
  1193. end;
  1194. procedure tai_tempalloc.ppuwrite(ppufile:tcompilerppufile);
  1195. begin
  1196. inherited ppuwrite(ppufile);
  1197. ppufile.putlongint(temppos);
  1198. ppufile.putlongint(tempsize);
  1199. ppufile.putbyte(byte(allocation));
  1200. end;
  1201. {*****************************************************************************
  1202. tai_regalloc
  1203. *****************************************************************************}
  1204. constructor tai_regalloc.alloc(r : tregister);
  1205. begin
  1206. inherited create;
  1207. typ:=ait_regalloc;
  1208. allocation:=true;
  1209. reg:=r;
  1210. end;
  1211. constructor tai_regalloc.dealloc(r : tregister);
  1212. begin
  1213. inherited create;
  1214. typ:=ait_regalloc;
  1215. allocation:=false;
  1216. reg:=r;
  1217. end;
  1218. constructor tai_regalloc.ppuload(t:taitype;ppufile:tcompilerppufile);
  1219. begin
  1220. inherited ppuload(t,ppufile);
  1221. ppufile.getdata(reg,sizeof(Tregister));
  1222. allocation:=boolean(ppufile.getbyte);
  1223. end;
  1224. procedure tai_regalloc.ppuwrite(ppufile:tcompilerppufile);
  1225. begin
  1226. inherited ppuwrite(ppufile);
  1227. ppufile.putdata(reg,sizeof(Tregister));
  1228. ppufile.putbyte(byte(allocation));
  1229. end;
  1230. {*****************************************************************************
  1231. TaiInstruction
  1232. *****************************************************************************}
  1233. constructor taicpu_abstract.Create(op : tasmop);
  1234. begin
  1235. inherited create;
  1236. typ:=ait_instruction;
  1237. is_jmp:=false;
  1238. opcode:=op;
  1239. ops:=0;
  1240. fillchar(condition,sizeof(condition),0);
  1241. fillchar(oper,sizeof(oper),0);
  1242. end;
  1243. destructor taicpu_abstract.Destroy;
  1244. var
  1245. i : integer;
  1246. begin
  1247. for i:=0 to opercnt-1 do
  1248. begin
  1249. with oper[i]^ do
  1250. begin
  1251. case typ of
  1252. top_ref:
  1253. dispose(ref);
  1254. {$ifdef ARM}
  1255. top_shifterop:
  1256. dispose(shifterop);
  1257. {$endif ARM}
  1258. end;
  1259. end;
  1260. dispose(oper[i]);
  1261. end;
  1262. inherited destroy;
  1263. end;
  1264. { ---------------------------------------------------------------------
  1265. Loading of operands.
  1266. ---------------------------------------------------------------------}
  1267. procedure taicpu_abstract.allocate_oper(opers:longint);
  1268. begin
  1269. while (opers>opercnt) do
  1270. begin
  1271. new(oper[opercnt]);
  1272. fillchar(oper[opercnt]^,sizeof(toper),0);
  1273. inc(opercnt);
  1274. end;
  1275. end;
  1276. procedure taicpu_abstract.loadconst(opidx:longint;l:aword);
  1277. begin
  1278. allocate_oper(opidx+1);
  1279. with oper[opidx]^ do
  1280. begin
  1281. if typ<>top_const then
  1282. clearop(opidx);
  1283. val:=l;
  1284. typ:=top_const;
  1285. end;
  1286. end;
  1287. procedure taicpu_abstract.loadsymbol(opidx:longint;s:tasmsymbol;sofs:longint);
  1288. begin
  1289. if not assigned(s) then
  1290. internalerror(200204251);
  1291. allocate_oper(opidx+1);
  1292. with oper[opidx]^ do
  1293. begin
  1294. if typ<>top_symbol then
  1295. clearop(opidx);
  1296. sym:=s;
  1297. symofs:=sofs;
  1298. typ:=top_symbol;
  1299. end;
  1300. s.increfs;
  1301. end;
  1302. procedure taicpu_abstract.loadlocal(opidx:longint;s:pointer;sofs:longint);
  1303. begin
  1304. if not assigned(s) then
  1305. internalerror(200204251);
  1306. allocate_oper(opidx+1);
  1307. with oper[opidx]^ do
  1308. begin
  1309. if typ<>top_local then
  1310. clearop(opidx);
  1311. localsym:=s;
  1312. localsymofs:=sofs;
  1313. typ:=top_local;
  1314. end;
  1315. end;
  1316. procedure taicpu_abstract.loadref(opidx:longint;const r:treference);
  1317. begin
  1318. allocate_oper(opidx+1);
  1319. with oper[opidx]^ do
  1320. begin
  1321. if typ<>top_ref then
  1322. begin
  1323. clearop(opidx);
  1324. new(ref);
  1325. end;
  1326. ref^:=r;
  1327. {$ifdef i386}
  1328. { We allow this exception for i386, since overloading this would be
  1329. too much of a a speed penalty}
  1330. if (ref^.segment<>NR_NO) and (ref^.segment<>NR_DS) then
  1331. segprefix:=ref^.segment;
  1332. {$endif}
  1333. typ:=top_ref;
  1334. { mark symbol as used }
  1335. if assigned(ref^.symbol) then
  1336. ref^.symbol.increfs;
  1337. end;
  1338. end;
  1339. procedure taicpu_abstract.loadreg(opidx:longint;r:tregister);
  1340. begin
  1341. allocate_oper(opidx+1);
  1342. with oper[opidx]^ do
  1343. begin
  1344. if typ<>top_reg then
  1345. clearop(opidx);
  1346. reg:=r;
  1347. typ:=top_reg;
  1348. end;
  1349. end;
  1350. procedure taicpu_abstract.loadoper(opidx:longint;o:toper);
  1351. begin
  1352. allocate_oper(opidx+1);
  1353. clearop(opidx);
  1354. oper[opidx]^:=o;
  1355. { copy also the reference }
  1356. with oper[opidx]^ do
  1357. begin
  1358. case typ of
  1359. top_ref:
  1360. begin
  1361. new(ref);
  1362. ref^:=o.ref^;
  1363. end;
  1364. {$ifdef ARM}
  1365. top_shifterop:
  1366. begin
  1367. new(shifterop);
  1368. shifterop^:=o.shifterop^;
  1369. end;
  1370. {$endif ARM}
  1371. end;
  1372. end;
  1373. end;
  1374. procedure taicpu_abstract.clearop(opidx:longint);
  1375. begin
  1376. with oper[opidx]^ do
  1377. case typ of
  1378. top_ref:
  1379. dispose(ref);
  1380. {$ifdef ARM}
  1381. top_shifterop:
  1382. dispose(shifterop);
  1383. {$endif ARM}
  1384. end;
  1385. end;
  1386. { ---------------------------------------------------------------------
  1387. Register allocator methods.
  1388. ---------------------------------------------------------------------}
  1389. function taicpu_abstract.get_insert_pos(p:Tai;huntfor1,huntfor2,huntfor3:Tsuperregister;var unusedregsint:tsuperregisterset):Tai;
  1390. var
  1391. back : tsuperregisterset;
  1392. supreg : tsuperregister;
  1393. begin
  1394. back:=unusedregsint;
  1395. get_insert_pos:=p;
  1396. while (p<>nil) and (p.typ=ait_regalloc) do
  1397. begin
  1398. supreg:=getsupreg(Tai_regalloc(p).reg);
  1399. {Rewind the register allocation.}
  1400. if Tai_regalloc(p).allocation then
  1401. supregset_include(unusedregsint,supreg)
  1402. else
  1403. begin
  1404. supregset_exclude(unusedregsint,supreg);
  1405. if supreg=huntfor1 then
  1406. begin
  1407. get_insert_pos:=Tai(p.previous);
  1408. back:=unusedregsint;
  1409. end;
  1410. if supreg=huntfor2 then
  1411. begin
  1412. get_insert_pos:=Tai(p.previous);
  1413. back:=unusedregsint;
  1414. end;
  1415. if supreg=huntfor3 then
  1416. begin
  1417. get_insert_pos:=Tai(p.previous);
  1418. back:=unusedregsint;
  1419. end;
  1420. end;
  1421. p:=Tai(p.previous);
  1422. end;
  1423. unusedregsint:=back;
  1424. end;
  1425. procedure taicpu_abstract.forward_allocation(p:Tai;var unusedregsint:Tsuperregisterset);
  1426. begin
  1427. {Forward the register allocation again.}
  1428. while (p<>self) do
  1429. begin
  1430. if p.typ<>ait_regalloc then
  1431. internalerror(200305311);
  1432. if Tai_regalloc(p).allocation then
  1433. supregset_exclude(unusedregsint,getsupreg(Tai_regalloc(p).reg))
  1434. else
  1435. supregset_include(unusedregsint,getsupreg(Tai_regalloc(p).reg));
  1436. p:=Tai(p.next);
  1437. end;
  1438. end;
  1439. function taicpu_abstract.spill_registers(list:Taasmoutput;
  1440. rgget:Trggetproc;
  1441. rgunget:Trgungetproc;
  1442. const r:Tsuperregisterset;
  1443. var unusedregsint:Tsuperregisterset;
  1444. const spilltemplist:Tspill_temp_list): boolean;
  1445. var
  1446. i:byte;
  1447. supreg, reg1, reg2, reg3: Tsuperregister;
  1448. helpreg:Tregister;
  1449. helpins:Tai;
  1450. op:Tasmop;
  1451. pos:Tai;
  1452. wasload: boolean;
  1453. begin
  1454. spill_registers:=false;
  1455. if (ops = 2) and
  1456. (oper[1]^.typ=top_ref) and
  1457. { oper[1] can also be ref in case of "lis r3,symbol@ha" or so }
  1458. spilling_decode_loadstore(opcode,op,wasload) then
  1459. begin
  1460. { the register that's being stored/loaded }
  1461. supreg:=getsupreg(oper[0]^.reg);
  1462. if supregset_in(r,supreg) then
  1463. begin
  1464. // Example:
  1465. // l?? r20d, 8(r1) ; r20d must be spilled into -60(r1)
  1466. //
  1467. // Change into:
  1468. //
  1469. // l?? r21d, 8(r1)
  1470. // st? r21d, -60(r1)
  1471. //
  1472. // And:
  1473. //
  1474. // st? r20d, 8(r1) ; r20d must be spilled into -60(r1)
  1475. //
  1476. // Change into:
  1477. //
  1478. // l?? r21d, -60(r1)
  1479. // st? r21d, 8(r1)
  1480. pos := get_insert_pos(Tai(previous),supreg,
  1481. getsupreg(oper[1]^.ref^.base),
  1482. getsupreg(oper[1]^.ref^.index),
  1483. unusedregsint);
  1484. rgget(list,pos,R_SUBWHOLE,helpreg);
  1485. spill_registers := true;
  1486. if wasload then
  1487. begin
  1488. helpins:=spilling_create_loadstore(opcode,helpreg,oper[1]^.ref^);
  1489. loadref(1,spilltemplist[supreg]);
  1490. opcode := op;
  1491. end
  1492. else
  1493. helpins:=spilling_create_loadstore(op,helpreg,spilltemplist[supreg]);
  1494. if pos=nil then
  1495. list.insertafter(helpins,list.first)
  1496. else
  1497. list.insertafter(helpins,pos.next);
  1498. loadreg(0,helpreg);
  1499. rgunget(list,helpins,helpreg);
  1500. forward_allocation(tai(helpins.next),unusedregsint);
  1501. {
  1502. writeln('spilling!');
  1503. list.insertafter(tai_comment.Create(strpnew('Spilling!')),helpins);
  1504. }
  1505. end;
  1506. { now the registers used in the reference }
  1507. { a) base }
  1508. supreg := getsupreg(oper[1]^.ref^.base);
  1509. if supregset_in(r,supreg) then
  1510. begin
  1511. if wasload then
  1512. pos:=get_insert_pos(Tai(previous),getsupreg(oper[1]^.ref^.index),getsupreg(oper[0]^.reg),0,unusedregsint)
  1513. else
  1514. pos:=get_insert_pos(Tai(previous),getsupreg(oper[1]^.ref^.index),0,0,unusedregsint);
  1515. rgget(list,pos,R_SUBWHOLE,helpreg);
  1516. spill_registers:=true;
  1517. helpins:=spilling_create_load(spilltemplist[supreg],helpreg);
  1518. if pos=nil then
  1519. list.insertafter(helpins,list.first)
  1520. else
  1521. list.insertafter(helpins,pos.next);
  1522. oper[1]^.ref^.base:=helpreg;
  1523. rgunget(list,helpins,helpreg);
  1524. forward_allocation(Tai(helpins.next),unusedregsint);
  1525. {
  1526. writeln('spilling!');
  1527. list.insertafter(tai_comment.Create(strpnew('Spilling!')),helpins);
  1528. }
  1529. end;
  1530. { b) index }
  1531. supreg := getsupreg(oper[1]^.ref^.index);
  1532. if supregset_in(r,supreg) then
  1533. begin
  1534. if wasload then
  1535. pos:=get_insert_pos(Tai(previous),getsupreg(oper[1]^.ref^.base),getsupreg(oper[0]^.reg),0,unusedregsint)
  1536. else
  1537. pos:=get_insert_pos(Tai(previous),getsupreg(oper[1]^.ref^.base),0,0,unusedregsint);
  1538. rgget(list,pos,R_SUBWHOLE,helpreg);
  1539. spill_registers:=true;
  1540. helpins:=spilling_create_load(spilltemplist[supreg],helpreg);
  1541. if pos=nil then
  1542. list.insertafter(helpins,list.first)
  1543. else
  1544. list.insertafter(helpins,pos.next);
  1545. oper[1]^.ref^.index:=helpreg;
  1546. rgunget(list,helpins,helpreg);
  1547. forward_allocation(Tai(helpins.next),unusedregsint);
  1548. {
  1549. writeln('spilling!');
  1550. list.insertafter(tai_comment.Create(strpnew('Spilling!')),helpins);
  1551. }
  1552. end;
  1553. { load/store is done }
  1554. exit;
  1555. end;
  1556. { all other instructions the compiler generates are the same (I hope): }
  1557. { operand 0 is a register and is the destination, the others are sources }
  1558. { and can be either registers or constants }
  1559. { exception: branches (is_jmp isn't always set for them) }
  1560. if oper[0]^.typ <> top_reg then
  1561. exit;
  1562. reg1 := getsupreg(oper[0]^.reg);
  1563. if oper[1]^.typ = top_reg then
  1564. reg2 := getsupreg(oper[1]^.reg)
  1565. else
  1566. reg2 := 0;
  1567. if (ops >= 3) and
  1568. (oper[2]^.typ = top_reg) then
  1569. reg3 := getsupreg(oper[2]^.reg)
  1570. else
  1571. reg3 := 0;
  1572. supreg:=reg1;
  1573. if supregset_in(r,supreg) then
  1574. begin
  1575. // Example:
  1576. // add r20d, r21d, r22d ; r20d must be spilled into -60(r1)
  1577. //
  1578. // Change into:
  1579. //
  1580. // lwz r23d, -60(r1)
  1581. // add r23d, r21d, r22d
  1582. // stw r23d, -60(r1)
  1583. pos := get_insert_pos(Tai(previous),reg1,reg2,reg3,unusedregsint);
  1584. rgget(list,pos,R_SUBWHOLE,helpreg);
  1585. spill_registers := true;
  1586. helpins:=spilling_create_store(helpreg,spilltemplist[supreg]);
  1587. list.insertafter(helpins,self);
  1588. helpins:=spilling_create_load(spilltemplist[supreg],helpreg);
  1589. if pos=nil then
  1590. list.insertafter(helpins,list.first)
  1591. else
  1592. list.insertafter(helpins,pos.next);
  1593. loadreg(0,helpreg);
  1594. rgunget(list,helpins,helpreg);
  1595. forward_allocation(tai(helpins.next),unusedregsint);
  1596. {
  1597. writeln('spilling!');
  1598. list.insertafter(tai_comment.Create(strpnew('Spilling!')),helpins);
  1599. }
  1600. end;
  1601. for i := 1 to 2 do
  1602. if (oper[i]^.typ = top_reg) then
  1603. begin
  1604. supreg:=getsupreg(oper[i]^.reg);
  1605. if supregset_in(r,supreg) then
  1606. begin
  1607. // Example:
  1608. // add r20d, r21d, r22d ; r20d must be spilled into -60(r1)
  1609. //
  1610. // Change into:
  1611. //
  1612. // lwz r23d, -60(r1)
  1613. // add r23d, r21d, r22d
  1614. // stw r23d, -60(r1)
  1615. pos := get_insert_pos(Tai(previous),reg1,reg2,reg3,unusedregsint);
  1616. rgget(list,pos,R_SUBWHOLE,helpreg);
  1617. spill_registers := true;
  1618. helpins:=spilling_create_load(spilltemplist[supreg],helpreg);
  1619. if pos=nil then
  1620. list.insertafter(helpins,list.first)
  1621. else
  1622. list.insertafter(helpins,pos.next);
  1623. loadreg(i,helpreg);
  1624. rgunget(list,helpins,helpreg);
  1625. forward_allocation(tai(helpins.next),unusedregsint);
  1626. {
  1627. writeln('spilling!');
  1628. list.insertafter(tai_comment.Create(strpnew('Spilling!')),helpins);
  1629. }
  1630. end;
  1631. end;
  1632. end;
  1633. { ---------------------------------------------------------------------
  1634. Miscellaneous methods.
  1635. ---------------------------------------------------------------------}
  1636. procedure taicpu_abstract.SetCondition(const c:TAsmCond);
  1637. begin
  1638. condition:=c;
  1639. end;
  1640. Function taicpu_abstract.getcopy:TLinkedListItem;
  1641. var
  1642. i : longint;
  1643. p : taicpu_abstract;
  1644. begin
  1645. p:=taicpu_abstract(inherited getcopy);
  1646. { make a copy of the references }
  1647. p.opercnt:=0;
  1648. p.allocate_oper(ops);
  1649. for i:=0 to ops-1 do
  1650. begin
  1651. p.oper[i]^:=oper[i]^;
  1652. if (oper[i]^.typ=top_ref) then
  1653. begin
  1654. new(p.oper[i]^.ref);
  1655. p.oper[i]^.ref^:=oper[i]^.ref^;
  1656. end;
  1657. end;
  1658. getcopy:=p;
  1659. end;
  1660. constructor taicpu_abstract.ppuload(t:taitype;ppufile:tcompilerppufile);
  1661. var
  1662. i : integer;
  1663. begin
  1664. inherited ppuload(t,ppufile);
  1665. { hopefully, we don't get problems with big/litte endian here when cross compiling :/ }
  1666. ppufile.getdata(condition,sizeof(tasmcond));
  1667. allocate_oper(ppufile.getbyte);
  1668. for i:=0 to ops-1 do
  1669. ppuloadoper(ppufile,oper[i]^);
  1670. opcode:=tasmop(ppufile.getword);
  1671. {$ifdef i386}
  1672. ppufile.getdata(segprefix,sizeof(Tregister));
  1673. {$endif i386}
  1674. is_jmp:=boolean(ppufile.getbyte);
  1675. end;
  1676. procedure taicpu_abstract.ppuwrite(ppufile:tcompilerppufile);
  1677. var
  1678. i : integer;
  1679. begin
  1680. inherited ppuwrite(ppufile);
  1681. ppufile.putdata(condition,sizeof(tasmcond));
  1682. ppufile.putbyte(ops);
  1683. for i:=0 to ops-1 do
  1684. ppuwriteoper(ppufile,oper[i]^);
  1685. ppufile.putword(word(opcode));
  1686. {$ifdef i386}
  1687. ppufile.putdata(segprefix,sizeof(Tregister));
  1688. {$endif i386}
  1689. ppufile.putbyte(byte(is_jmp));
  1690. end;
  1691. procedure taicpu_abstract.buildderefimpl;
  1692. var
  1693. i : integer;
  1694. begin
  1695. for i:=0 to ops-1 do
  1696. ppubuildderefimploper(oper[i]^);
  1697. end;
  1698. procedure taicpu_abstract.derefimpl;
  1699. var
  1700. i : integer;
  1701. begin
  1702. for i:=0 to ops-1 do
  1703. ppuderefoper(oper[i]^);
  1704. end;
  1705. {****************************************************************************
  1706. tai_align_abstract
  1707. ****************************************************************************}
  1708. constructor tai_align_abstract.Create(b: byte);
  1709. begin
  1710. inherited Create;
  1711. typ:=ait_align;
  1712. if b in [1,2,4,8,16,32] then
  1713. aligntype := b
  1714. else
  1715. aligntype := 1;
  1716. fillsize:=0;
  1717. fillop:=0;
  1718. use_op:=false;
  1719. end;
  1720. constructor tai_align_abstract.Create_op(b: byte; _op: byte);
  1721. begin
  1722. inherited Create;
  1723. typ:=ait_align;
  1724. if b in [1,2,4,8,16,32] then
  1725. aligntype := b
  1726. else
  1727. aligntype := 1;
  1728. fillsize:=0;
  1729. fillop:=_op;
  1730. use_op:=true;
  1731. end;
  1732. function tai_align_abstract.calculatefillbuf(var buf : tfillbuffer):pchar;
  1733. begin
  1734. fillchar(buf,high(buf),fillop);
  1735. calculatefillbuf:=pchar(@buf);
  1736. end;
  1737. constructor tai_align_abstract.ppuload(t:taitype;ppufile:tcompilerppufile);
  1738. begin
  1739. inherited ppuload(t,ppufile);
  1740. aligntype:=ppufile.getbyte;
  1741. fillsize:=0;
  1742. fillop:=ppufile.getbyte;
  1743. use_op:=boolean(ppufile.getbyte);
  1744. end;
  1745. procedure tai_align_abstract.ppuwrite(ppufile:tcompilerppufile);
  1746. begin
  1747. inherited ppuwrite(ppufile);
  1748. ppufile.putbyte(aligntype);
  1749. ppufile.putbyte(fillop);
  1750. ppufile.putbyte(byte(use_op));
  1751. end;
  1752. {*****************************************************************************
  1753. TAAsmOutput
  1754. *****************************************************************************}
  1755. constructor taasmoutput.create;
  1756. begin
  1757. inherited create;
  1758. { make sure the optimizer won't remove the first tai of this list}
  1759. insert(tai_marker.create(marker_blockstart));
  1760. end;
  1761. function taasmoutput.getlasttaifilepos : pfileposinfo;
  1762. var
  1763. hp : tlinkedlistitem;
  1764. begin
  1765. getlasttaifilepos := nil;
  1766. if assigned(last) then
  1767. begin
  1768. { find the last file information record }
  1769. if not (tai(last).typ in SkipLineInfo) then
  1770. getlasttaifilepos:=@tailineinfo(last).fileinfo
  1771. else
  1772. { go through list backwards to find the first entry
  1773. with line information
  1774. }
  1775. begin
  1776. hp:=tai(last);
  1777. while assigned(hp) and (tai(hp).typ in SkipLineInfo) do
  1778. hp:=hp.Previous;
  1779. { found entry }
  1780. if assigned(hp) then
  1781. getlasttaifilepos:=@tailineinfo(hp).fileinfo
  1782. end;
  1783. end;
  1784. end;
  1785. procedure Taasmoutput.InsertAfter(Item,Loc : TLinkedListItem);
  1786. begin
  1787. { This is not possible because it is not sure that the
  1788. tai at Loc has taifileinfo as parent }
  1789. {if assigned(Loc) then
  1790. tailineinfo(Item).fileinfo:=tailineinfo(Loc).fileinfo;}
  1791. inherited InsertAfter(Item,Loc);
  1792. end;
  1793. end.
  1794. {
  1795. $Log$
  1796. Revision 1.48 2003-10-24 17:39:41 peter
  1797. * asmnode.get_position now inserts a marker
  1798. Revision 1.47 2003/10/23 14:44:07 peter
  1799. * splitted buildderef and buildderefimpl to fix interface crc
  1800. calculation
  1801. Revision 1.46 2003/10/22 20:39:59 peter
  1802. * write derefdata in a separate ppu entry
  1803. Revision 1.45 2003/10/21 15:15:35 peter
  1804. * taicpu_abstract.oper[] changed to pointers
  1805. Revision 1.44 2003/10/17 14:38:32 peter
  1806. * 64k registers supported
  1807. * fixed some memory leaks
  1808. Revision 1.43 2003/10/11 16:06:42 florian
  1809. * fixed some MMX<->SSE
  1810. * started to fix ppc, needs an overhaul
  1811. + stabs info improve for spilling, not sure if it works correctly/completly
  1812. - MMX_SUPPORT removed from Makefile.fpc
  1813. Revision 1.42 2003/10/10 17:48:13 peter
  1814. * old trgobj moved to x86/rgcpu and renamed to trgx86fpu
  1815. * tregisteralloctor renamed to trgobj
  1816. * removed rgobj from a lot of units
  1817. * moved location_* and reference_* to cgobj
  1818. * first things for mmx register allocation
  1819. Revision 1.41 2003/10/01 20:34:48 peter
  1820. * procinfo unit contains tprocinfo
  1821. * cginfo renamed to cgbase
  1822. * moved cgmessage to verbose
  1823. * fixed ppc and sparc compiles
  1824. Revision 1.40 2003/09/23 17:56:05 peter
  1825. * locals and paras are allocated in the code generation
  1826. * tvarsym.localloc contains the location of para/local when
  1827. generating code for the current procedure
  1828. Revision 1.39 2003/09/07 22:09:34 peter
  1829. * preparations for different default calling conventions
  1830. * various RA fixes
  1831. Revision 1.38 2003/09/04 00:15:28 florian
  1832. * first bunch of adaptions of arm compiler for new register type
  1833. Revision 1.37 2003/09/03 15:55:00 peter
  1834. * NEWRA branch merged
  1835. Revision 1.36 2003/09/03 11:18:36 florian
  1836. * fixed arm concatcopy
  1837. + arm support in the common compiler sources added
  1838. * moved some generic cg code around
  1839. + tfputype added
  1840. * ...
  1841. Revision 1.35.2.5 2003/08/31 21:08:16 peter
  1842. * first batch of sparc fixes
  1843. Revision 1.35.2.4 2003/08/29 17:28:59 peter
  1844. * next batch of updates
  1845. Revision 1.35.2.3 2003/08/28 18:35:07 peter
  1846. * tregister changed to cardinal
  1847. Revision 1.35.2.2 2003/08/27 20:23:55 peter
  1848. * remove old ra code
  1849. Revision 1.35.2.1 2003/08/27 19:55:54 peter
  1850. * first tregister patch
  1851. Revision 1.35 2003/08/21 14:47:41 peter
  1852. * remove convert_registers
  1853. Revision 1.34 2003/08/20 20:29:06 daniel
  1854. * Some more R_NO changes
  1855. * Preventive code to loadref added
  1856. Revision 1.33 2003/08/17 20:47:47 daniel
  1857. * Notranslation changed into -sr functionality
  1858. Revision 1.32 2003/08/17 16:59:20 jonas
  1859. * fixed regvars so they work with newra (at least for ppc)
  1860. * fixed some volatile register bugs
  1861. + -dnotranslation option for -dnewra, which causes the registers not to
  1862. be translated from virtual to normal registers. Requires support in
  1863. the assembler writer as well, which is only implemented in aggas/
  1864. agppcgas currently
  1865. Revision 1.31 2003/08/11 21:18:20 peter
  1866. * start of sparc support for newra
  1867. Revision 1.30 2003/07/02 16:43:48 jonas
  1868. * always add dummy marker object at the start of an assembler list, so
  1869. the optimizer can't remove the first object
  1870. Revision 1.29 2003/06/03 13:01:59 daniel
  1871. * Register allocator finished
  1872. Revision 1.28 2003/05/12 18:13:57 peter
  1873. * create rtti label using newasmsymboldata and update binding
  1874. only when calling tai_symbol.create
  1875. * tai_symbol.create_global added
  1876. Revision 1.27 2003/04/25 20:59:33 peter
  1877. * removed funcretn,funcretsym, function result is now in varsym
  1878. and aliases for result and function name are added using absolutesym
  1879. * vs_hidden parameter for funcret passed in parameter
  1880. * vs_hidden fixes
  1881. * writenode changed to printnode and released from extdebug
  1882. * -vp option added to generate a tree.log with the nodetree
  1883. * nicer printnode for statements, callnode
  1884. Revision 1.26 2002/04/25 16:12:09 florian
  1885. * fixed more problems with cpubase and x86-64
  1886. Revision 1.25 2003/04/25 08:25:26 daniel
  1887. * Ifdefs around a lot of calls to cleartempgen
  1888. * Fixed registers that are allocated but not freed in several nodes
  1889. * Tweak to register allocator to cause less spills
  1890. * 8-bit registers now interfere with esi,edi and ebp
  1891. Compiler can now compile rtl successfully when using new register
  1892. allocator
  1893. Revision 1.24 2003/04/24 13:03:01 florian
  1894. * comp is now written with its bit pattern to the ppu instead as an extended
  1895. Revision 1.23 2003/04/22 14:33:38 peter
  1896. * removed some notes/hints
  1897. Revision 1.22 2003/04/22 10:09:34 daniel
  1898. + Implemented the actual register allocator
  1899. + Scratch registers unavailable when new register allocator used
  1900. + maybe_save/maybe_restore unavailable when new register allocator used
  1901. Revision 1.21 2003/02/19 22:00:14 daniel
  1902. * Code generator converted to new register notation
  1903. - Horribily outdated todo.txt removed
  1904. Revision 1.20 2003/01/30 21:46:20 peter
  1905. * tai_const_symbol.createdataname added
  1906. Revision 1.19 2003/01/21 08:48:08 daniel
  1907. * Another 200301081 fixed
  1908. Revision 1.18 2003/01/09 20:40:59 daniel
  1909. * Converted some code in cgx86.pas to new register numbering
  1910. Revision 1.17 2003/01/09 15:49:56 daniel
  1911. * Added register conversion
  1912. Revision 1.16 2003/01/08 18:43:56 daniel
  1913. * Tregister changed into a record
  1914. Revision 1.15 2003/01/05 13:36:53 florian
  1915. * x86-64 compiles
  1916. + very basic support for float128 type (x86-64 only)
  1917. Revision 1.14 2002/12/06 17:50:21 peter
  1918. * symbol count fix merged
  1919. Revision 1.13 2002/11/17 16:31:55 carl
  1920. * memory optimization (3-4%) : cleanup of tai fields,
  1921. cleanup of tdef and tsym fields.
  1922. * make it work for m68k
  1923. Revision 1.12 2002/11/15 16:29:30 peter
  1924. * made tasmsymbol.refs private (merged)
  1925. Revision 1.11 2002/11/15 01:58:45 peter
  1926. * merged changes from 1.0.7 up to 04-11
  1927. - -V option for generating bug report tracing
  1928. - more tracing for option parsing
  1929. - errors for cdecl and high()
  1930. - win32 import stabs
  1931. - win32 records<=8 are returned in eax:edx (turned off by default)
  1932. - heaptrc update
  1933. - more info for temp management in .s file with EXTDEBUG
  1934. Revision 1.10 2002/11/09 15:38:03 carl
  1935. + NOOPT removed the optinfo field
  1936. Revision 1.9 2002/10/05 12:43:23 carl
  1937. * fixes for Delphi 6 compilation
  1938. (warning : Some features do not work under Delphi)
  1939. Revision 1.8 2002/08/19 19:36:42 peter
  1940. * More fixes for cross unit inlining, all tnodes are now implemented
  1941. * Moved pocall_internconst to po_internconst because it is not a
  1942. calling type at all and it conflicted when inlining of these small
  1943. functions was requested
  1944. Revision 1.7 2002/08/18 20:06:23 peter
  1945. * inlining is now also allowed in interface
  1946. * renamed write/load to ppuwrite/ppuload
  1947. * tnode storing in ppu
  1948. * nld,ncon,nbas are already updated for storing in ppu
  1949. Revision 1.6 2002/08/16 05:21:09 florian
  1950. * powerpc compilation fix
  1951. Revision 1.5 2002/08/15 19:10:35 peter
  1952. * first things tai,tnode storing in ppu
  1953. Revision 1.4 2002/08/11 14:32:25 peter
  1954. * renamed current_library to objectlibrary
  1955. Revision 1.3 2002/08/11 13:24:10 peter
  1956. * saving of asmsymbols in ppu supported
  1957. * asmsymbollist global is removed and moved into a new class
  1958. tasmlibrarydata that will hold the info of a .a file which
  1959. corresponds with a single module. Added librarydata to tmodule
  1960. to keep the library info stored for the module. In the future the
  1961. objectfiles will also be stored to the tasmlibrarydata class
  1962. * all getlabel/newasmsymbol and friends are moved to the new class
  1963. Revision 1.2 2002/08/05 18:27:48 carl
  1964. + more more more documentation
  1965. + first version include/exclude (can't test though, not enough scratch for i386 :()...
  1966. Revision 1.1 2002/07/01 18:46:20 peter
  1967. * internal linker
  1968. * reorganized aasm layer
  1969. Revision 1.27 2002/05/18 13:34:04 peter
  1970. * readded missing revisions
  1971. Revision 1.25 2002/05/14 19:34:38 peter
  1972. * removed old logs and updated copyright year
  1973. Revision 1.24 2002/05/14 17:28:08 peter
  1974. * synchronized cpubase between powerpc and i386
  1975. * moved more tables from cpubase to cpuasm
  1976. * tai_align_abstract moved to tainst, cpuasm must define
  1977. the tai_align class now, which may be empty
  1978. Revision 1.23 2002/04/15 18:54:34 carl
  1979. - removed tcpuflags
  1980. Revision 1.22 2002/04/07 13:18:19 carl
  1981. + more documentation
  1982. Revision 1.21 2002/04/07 10:17:40 carl
  1983. - remove packenumfixed (requires version 1.0.2 or later to compile now!)
  1984. + changing some comments so its commented automatically
  1985. Revision 1.20 2002/03/24 19:04:31 carl
  1986. + patch for SPARC from Mazen NEIFER
  1987. }