aasmtai.pas 77 KB

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