aasmtai.pas 63 KB

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