aasmtai.pas 65 KB

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