aasmtai.pas 69 KB

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