aasmtai.pas 64 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256
  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. al_code,al_bss,al_data,al_rodata,
  520. al_typedconsts,al_rotypedconsts,
  521. al_debug,al_threadvars,al_withdebug,al_imports,al_exports,
  522. al_resources,al_rtti,al_dwarf,
  523. { data used by pic code }
  524. al_picdata,al_resourcestrings);
  525. const
  526. TasmlistStr : array[tasmlist] of string[24] =({ default lists }
  527. 'al_code','al_bss','al_data','al_rodata',
  528. 'al_typedconsts','al_rotypedconsts',
  529. 'al_debug','al_threadvars','al_withdebug','al_imports','al_exports',
  530. 'al_resources','al_rtti','al_dwarf',
  531. { data used by pic code }
  532. 'al_picdata','al_resourcestrings');
  533. var
  534. { array with all class types for tais }
  535. aiclass : taiclassarray;
  536. { Current expression list }
  537. exprasmlist : taasmoutput;
  538. { labels for BREAK and CONTINUE }
  539. aktbreaklabel,aktcontinuelabel : tasmlabel;
  540. { label when the result is true or false }
  541. truelabel,falselabel : tasmlabel;
  542. { hook to notify uses of registers }
  543. add_reg_instruction_hook : tadd_reg_instruction_proc;
  544. asmlist:array[Tasmlist] of Taasmoutput;
  545. cai_align : tai_align_class;
  546. cai_cpu : tai_cpu_class;
  547. function use_smartlink_section:boolean;
  548. function maybe_smartlink_symbol:boolean;
  549. procedure maybe_new_object_file(list:taasmoutput);
  550. procedure new_section(list:taasmoutput;Asectype:TAsmSectionType;Aname:string;Aalign:byte);
  551. function ppuloadai(ppufile:tcompilerppufile):tai;
  552. procedure ppuwriteai(ppufile:tcompilerppufile;n:tai);
  553. implementation
  554. uses
  555. strings,
  556. verbose;
  557. const
  558. pputaimarker = 254;
  559. {****************************************************************************
  560. Helpers
  561. ****************************************************************************}
  562. function ppuloadai(ppufile:tcompilerppufile):tai;
  563. var
  564. b : byte;
  565. t : taitype;
  566. begin
  567. { marker }
  568. b:=ppufile.getbyte;
  569. if b<>pputaimarker then
  570. internalerror(200208181);
  571. { load nodetype }
  572. t:=taitype(ppufile.getbyte);
  573. if t<>ait_none then
  574. begin
  575. if t>high(taitype) then
  576. internalerror(200208182);
  577. if not assigned(aiclass[t]) then
  578. internalerror(200208183);
  579. {writeln('taiload: ',taitypestr[t]);}
  580. { generate tai of the correct class }
  581. ppuloadai:=aiclass[t].ppuload(t,ppufile);
  582. end
  583. else
  584. ppuloadai:=nil;
  585. end;
  586. procedure ppuwriteai(ppufile:tcompilerppufile;n:tai);
  587. begin
  588. { marker, read by ppuloadnode }
  589. ppufile.putbyte(pputaimarker);
  590. if assigned(n) then
  591. begin
  592. { type, read by ppuloadnode }
  593. ppufile.putbyte(byte(n.typ));
  594. {writeln('taiwrite: ',taitypestr[n.typ]);}
  595. n.ppuwrite(ppufile);
  596. end
  597. else
  598. ppufile.putbyte(byte(ait_none));
  599. end;
  600. function use_smartlink_section:boolean;
  601. begin
  602. result:=(af_smartlink_sections in target_asm.flags) and
  603. (tf_smartlink_sections in target_info.flags) and
  604. not(cs_debuginfo in aktmoduleswitches);
  605. end;
  606. function maybe_smartlink_symbol:boolean;
  607. begin
  608. result:=(cs_create_smart in aktmoduleswitches) or
  609. use_smartlink_section;
  610. end;
  611. procedure maybe_new_object_file(list:taasmoutput);
  612. begin
  613. if (cs_create_smart in aktmoduleswitches) and
  614. (not use_smartlink_section) then
  615. list.concat(tai_cutobject.create);
  616. end;
  617. procedure new_section(list:taasmoutput;Asectype:TAsmSectionType;Aname:string;Aalign:byte);
  618. begin
  619. list.concat(tai_section.create(Asectype,Aname,Aalign));
  620. list.concat(cai_align.create(Aalign));
  621. end;
  622. {****************************************************************************
  623. TAI
  624. ****************************************************************************}
  625. constructor tai.Create;
  626. begin
  627. {$ifndef NOOPT}
  628. optinfo:=nil;
  629. {$endif NOOPT}
  630. end;
  631. constructor tai.ppuload(t:taitype;ppufile:tcompilerppufile);
  632. begin
  633. typ:=t;
  634. {$ifndef NOOPT}
  635. optinfo:=nil;
  636. {$endif}
  637. end;
  638. procedure tai.ppuwrite(ppufile:tcompilerppufile);
  639. begin
  640. end;
  641. procedure tai.buildderefimpl;
  642. begin
  643. end;
  644. procedure tai.derefimpl;
  645. begin
  646. end;
  647. {****************************************************************************
  648. TAILINEINFO
  649. ****************************************************************************}
  650. constructor tailineinfo.create;
  651. begin
  652. inherited create;
  653. if not(inlining_procedure and
  654. (cs_gdb_valgrind in aktglobalswitches)) then
  655. fileinfo:=aktfilepos;
  656. end;
  657. constructor tailineinfo.ppuload(t:taitype;ppufile:tcompilerppufile);
  658. begin
  659. inherited ppuload(t,ppufile);
  660. ppufile.getposinfo(fileinfo);
  661. end;
  662. procedure tailineinfo.ppuwrite(ppufile:tcompilerppufile);
  663. begin
  664. inherited ppuwrite(ppufile);
  665. ppufile.putposinfo(fileinfo);
  666. end;
  667. {****************************************************************************
  668. TAI_SIMPLE
  669. ****************************************************************************}
  670. constructor tai_simple.create(_typ : taitype);
  671. begin
  672. inherited create;
  673. typ:=_typ;
  674. end;
  675. {****************************************************************************
  676. TAI_SECTION
  677. ****************************************************************************}
  678. constructor tai_section.Create(Asectype:TAsmSectionType;Aname:string;Aalign:byte);
  679. begin
  680. inherited Create;
  681. typ:=ait_section;
  682. sectype:=asectype;
  683. secalign:=Aalign;
  684. name:=stringdup(Aname);
  685. sec:=nil;
  686. end;
  687. constructor tai_section.ppuload(t:taitype;ppufile:tcompilerppufile);
  688. begin
  689. inherited ppuload(t,ppufile);
  690. sectype:=tasmsectiontype(ppufile.getbyte);
  691. secalign:=ppufile.getbyte;
  692. name:=stringdup(ppufile.getstring);
  693. sec:=nil;
  694. end;
  695. destructor tai_section.Destroy;
  696. begin
  697. stringdispose(name);
  698. end;
  699. procedure tai_section.ppuwrite(ppufile:tcompilerppufile);
  700. begin
  701. inherited ppuwrite(ppufile);
  702. ppufile.putbyte(byte(sectype));
  703. ppufile.putbyte(secalign);
  704. ppufile.putstring(name^);
  705. end;
  706. {****************************************************************************
  707. TAI_DATABLOCK
  708. ****************************************************************************}
  709. constructor tai_datablock.Create(const _name : string;_size : longint);
  710. begin
  711. inherited Create;
  712. typ:=ait_datablock;
  713. sym:=objectlibrary.newasmsymbol(_name,AB_LOCAL,AT_DATA);
  714. { keep things aligned }
  715. if _size<=0 then
  716. _size:=4;
  717. size:=_size;
  718. is_global:=false;
  719. end;
  720. constructor tai_datablock.Create_global(const _name : string;_size : longint);
  721. begin
  722. inherited Create;
  723. typ:=ait_datablock;
  724. sym:=objectlibrary.newasmsymbol(_name,AB_GLOBAL,AT_DATA);
  725. { keep things aligned }
  726. if _size<=0 then
  727. _size:=4;
  728. size:=_size;
  729. is_global:=true;
  730. end;
  731. constructor tai_datablock.ppuload(t:taitype;ppufile:tcompilerppufile);
  732. begin
  733. inherited Create;
  734. sym:=ppufile.getasmsymbol;
  735. size:=ppufile.getlongint;
  736. is_global:=boolean(ppufile.getbyte);
  737. end;
  738. procedure tai_datablock.ppuwrite(ppufile:tcompilerppufile);
  739. begin
  740. inherited ppuwrite(ppufile);
  741. ppufile.putasmsymbol(sym);
  742. ppufile.putlongint(size);
  743. ppufile.putbyte(byte(is_global));
  744. end;
  745. procedure tai_datablock.derefimpl;
  746. begin
  747. objectlibrary.DerefAsmsymbol(sym);
  748. end;
  749. {****************************************************************************
  750. TAI_SYMBOL
  751. ****************************************************************************}
  752. constructor tai_symbol.Create(_sym:tasmsymbol;siz:longint);
  753. begin
  754. inherited Create;
  755. typ:=ait_symbol;
  756. sym:=_sym;
  757. size:=siz;
  758. sym.defbind:=AB_LOCAL;
  759. is_global:=false;
  760. end;
  761. constructor tai_symbol.Create_global(_sym:tasmsymbol;siz:longint);
  762. begin
  763. inherited Create;
  764. typ:=ait_symbol;
  765. sym:=_sym;
  766. size:=siz;
  767. sym.defbind:=AB_GLOBAL;
  768. is_global:=true;
  769. end;
  770. constructor tai_symbol.Createname(const _name : string;_symtyp:Tasmsymtype;siz:longint);
  771. begin
  772. inherited Create;
  773. typ:=ait_symbol;
  774. sym:=objectlibrary.newasmsymbol(_name,AB_LOCAL,_symtyp);
  775. size:=siz;
  776. is_global:=false;
  777. end;
  778. constructor tai_symbol.Createname_global(const _name : string;_symtyp:Tasmsymtype;siz:longint);
  779. begin
  780. inherited Create;
  781. typ:=ait_symbol;
  782. sym:=objectlibrary.newasmsymbol(_name,AB_GLOBAL,_symtyp);
  783. size:=siz;
  784. is_global:=true;
  785. end;
  786. constructor tai_symbol.ppuload(t:taitype;ppufile:tcompilerppufile);
  787. begin
  788. inherited ppuload(t,ppufile);
  789. sym:=ppufile.getasmsymbol;
  790. size:=ppufile.getlongint;
  791. is_global:=boolean(ppufile.getbyte);
  792. end;
  793. procedure tai_symbol.ppuwrite(ppufile:tcompilerppufile);
  794. begin
  795. inherited ppuwrite(ppufile);
  796. ppufile.putasmsymbol(sym);
  797. ppufile.putlongint(size);
  798. ppufile.putbyte(byte(is_global));
  799. end;
  800. procedure tai_symbol.derefimpl;
  801. begin
  802. objectlibrary.DerefAsmsymbol(sym);
  803. end;
  804. {****************************************************************************
  805. TAI_SYMBOL_END
  806. ****************************************************************************}
  807. constructor tai_symbol_end.Create(_sym:tasmsymbol);
  808. begin
  809. inherited Create;
  810. typ:=ait_symbol_end;
  811. sym:=_sym;
  812. end;
  813. constructor tai_symbol_end.Createname(const _name : string);
  814. begin
  815. inherited Create;
  816. typ:=ait_symbol_end;
  817. sym:=objectlibrary.newasmsymbol(_name,AB_GLOBAL,AT_NONE);
  818. end;
  819. constructor tai_symbol_end.ppuload(t:taitype;ppufile:tcompilerppufile);
  820. begin
  821. inherited ppuload(t,ppufile);
  822. sym:=ppufile.getasmsymbol;
  823. end;
  824. procedure tai_symbol_end.ppuwrite(ppufile:tcompilerppufile);
  825. begin
  826. inherited ppuwrite(ppufile);
  827. ppufile.putasmsymbol(sym);
  828. end;
  829. procedure tai_symbol_end.derefimpl;
  830. begin
  831. objectlibrary.DerefAsmsymbol(sym);
  832. end;
  833. {****************************************************************************
  834. TAI_CONST
  835. ****************************************************************************}
  836. constructor tai_const.Create(_typ:taitype;_value : int64);
  837. begin
  838. inherited Create;
  839. typ:=_typ;
  840. value:=_value;
  841. sym:=nil;
  842. endsym:=nil;
  843. end;
  844. constructor tai_const.Create_128bit(_value : int64);
  845. begin
  846. inherited Create;
  847. typ:=ait_const_128bit;
  848. value:=_value;
  849. sym:=nil;
  850. endsym:=nil;
  851. end;
  852. constructor tai_const.Create_64bit(_value : int64);
  853. begin
  854. inherited Create;
  855. typ:=ait_const_64bit;
  856. value:=_value;
  857. sym:=nil;
  858. endsym:=nil;
  859. end;
  860. constructor tai_const.Create_32bit(_value : longint);
  861. begin
  862. inherited Create;
  863. typ:=ait_const_32bit;
  864. value:=_value;
  865. sym:=nil;
  866. endsym:=nil;
  867. end;
  868. constructor tai_const.Create_16bit(_value : word);
  869. begin
  870. inherited Create;
  871. typ:=ait_const_16bit;
  872. value:=_value;
  873. sym:=nil;
  874. endsym:=nil;
  875. end;
  876. constructor tai_const.Create_8bit(_value : byte);
  877. begin
  878. inherited Create;
  879. typ:=ait_const_8bit;
  880. value:=_value;
  881. sym:=nil;
  882. endsym:=nil;
  883. end;
  884. constructor tai_const.Create_sleb128bit(_value : int64);
  885. begin
  886. inherited Create;
  887. typ:=ait_const_sleb128bit;
  888. value:=_value;
  889. sym:=nil;
  890. endsym:=nil;
  891. end;
  892. constructor tai_const.Create_uleb128bit(_value : qword);
  893. begin
  894. inherited Create;
  895. typ:=ait_const_uleb128bit;
  896. value:=int64(_value);
  897. sym:=nil;
  898. endsym:=nil;
  899. end;
  900. constructor tai_const.Create_aint(_value : aint);
  901. begin
  902. inherited Create;
  903. typ:=ait_const_aint;
  904. value:=_value;
  905. sym:=nil;
  906. endsym:=nil;
  907. end;
  908. constructor tai_const.Create_sym(_sym:tasmsymbol);
  909. begin
  910. inherited Create;
  911. typ:=ait_const_ptr;
  912. { sym is allowed to be nil, this is used to write nil pointers }
  913. sym:=_sym;
  914. endsym:=nil;
  915. value:=0;
  916. { update sym info }
  917. if assigned(sym) then
  918. sym.increfs;
  919. end;
  920. constructor tai_const.Create_sym_offset(_sym:tasmsymbol;ofs:aint);
  921. begin
  922. inherited Create;
  923. typ:=ait_const_ptr;
  924. if not assigned(_sym) then
  925. internalerror(200404121);
  926. sym:=_sym;
  927. endsym:=nil;
  928. value:=ofs;
  929. { update sym info }
  930. sym.increfs;
  931. end;
  932. constructor tai_const.Create_rel_sym(_typ:taitype;_sym,_endsym:tasmsymbol);
  933. begin
  934. inherited Create;
  935. typ:=_typ;
  936. sym:=_sym;
  937. endsym:=_endsym;
  938. value:=0;
  939. { update sym info }
  940. sym.increfs;
  941. endsym.increfs;
  942. end;
  943. constructor tai_const.Create_rva_sym(_sym:tasmsymbol);
  944. begin
  945. inherited Create;
  946. typ:=ait_const_rva_symbol;
  947. sym:=_sym;
  948. endsym:=nil;
  949. value:=0;
  950. { update sym info }
  951. sym.increfs;
  952. end;
  953. constructor tai_const.Create_indirect_sym(_sym:tasmsymbol);
  954. begin
  955. inherited Create;
  956. typ:=ait_const_indirect_symbol;
  957. sym:=_sym;
  958. endsym:=nil;
  959. value:=0;
  960. { update sym info }
  961. sym.increfs;
  962. end;
  963. constructor tai_const.Createname(const name:string;_symtyp:Tasmsymtype;ofs:aint);
  964. begin
  965. inherited Create;
  966. typ:=ait_const_ptr;
  967. sym:=objectlibrary.newasmsymbol(name,AB_EXTERNAL,_symtyp);
  968. endsym:=nil;
  969. value:=ofs;
  970. { update sym info }
  971. sym.increfs;
  972. end;
  973. constructor tai_const.Createname_rva(const name:string);
  974. begin
  975. inherited Create;
  976. typ:=ait_const_rva_symbol;
  977. sym:=objectlibrary.newasmsymbol(name,AB_EXTERNAL,AT_FUNCTION);
  978. endsym:=nil;
  979. value:=0;
  980. { update sym info }
  981. sym.increfs;
  982. end;
  983. constructor tai_const.ppuload(t:taitype;ppufile:tcompilerppufile);
  984. begin
  985. inherited ppuload(t,ppufile);
  986. sym:=ppufile.getasmsymbol;
  987. endsym:=ppufile.getasmsymbol;
  988. value:=ppufile.getint64;
  989. end;
  990. procedure tai_const.ppuwrite(ppufile:tcompilerppufile);
  991. begin
  992. inherited ppuwrite(ppufile);
  993. ppufile.putasmsymbol(sym);
  994. ppufile.putasmsymbol(endsym);
  995. ppufile.putint64(value);
  996. end;
  997. procedure tai_const.derefimpl;
  998. begin
  999. objectlibrary.DerefAsmsymbol(sym);
  1000. objectlibrary.DerefAsmsymbol(endsym);
  1001. end;
  1002. function tai_const.getcopy:tlinkedlistitem;
  1003. begin
  1004. getcopy:=inherited getcopy;
  1005. { we need to increase the reference number }
  1006. sym.increfs;
  1007. if assigned(endsym) then
  1008. endsym.increfs;
  1009. end;
  1010. function tai_const.size:longint;
  1011. begin
  1012. case typ of
  1013. ait_const_8bit :
  1014. result:=1;
  1015. ait_const_16bit :
  1016. result:=2;
  1017. ait_const_32bit :
  1018. result:=4;
  1019. ait_const_64bit :
  1020. result:=8;
  1021. ait_const_indirect_symbol,
  1022. ait_const_rva_symbol :
  1023. result:=sizeof(aint);
  1024. end;
  1025. end;
  1026. {****************************************************************************
  1027. TAI_real_32bit
  1028. ****************************************************************************}
  1029. constructor tai_real_32bit.Create(_value : ts32real);
  1030. begin
  1031. inherited Create;
  1032. typ:=ait_real_32bit;
  1033. value:=_value;
  1034. end;
  1035. constructor tai_real_32bit.ppuload(t:taitype;ppufile:tcompilerppufile);
  1036. begin
  1037. inherited ppuload(t,ppufile);
  1038. value:=ppufile.getreal;
  1039. end;
  1040. procedure tai_real_32bit.ppuwrite(ppufile:tcompilerppufile);
  1041. begin
  1042. inherited ppuwrite(ppufile);
  1043. ppufile.putreal(value);
  1044. end;
  1045. {****************************************************************************
  1046. TAI_real_64bit
  1047. ****************************************************************************}
  1048. constructor tai_real_64bit.Create(_value : ts64real);
  1049. begin
  1050. inherited Create;
  1051. typ:=ait_real_64bit;
  1052. value:=_value;
  1053. end;
  1054. {$ifdef ARM}
  1055. constructor tai_real_64bit.Create_hiloswapped(_value : ts64real);
  1056. begin
  1057. inherited Create;
  1058. typ:=ait_real_64bit;
  1059. value:=_value;
  1060. formatoptions:=fo_hiloswapped;
  1061. end;
  1062. {$endif ARM}
  1063. constructor tai_real_64bit.ppuload(t:taitype;ppufile:tcompilerppufile);
  1064. begin
  1065. inherited ppuload(t,ppufile);
  1066. value:=ppufile.getreal;
  1067. {$ifdef ARM}
  1068. formatoptions:=tformatoptions(ppufile.getbyte);
  1069. {$endif ARM}
  1070. end;
  1071. procedure tai_real_64bit.ppuwrite(ppufile:tcompilerppufile);
  1072. begin
  1073. inherited ppuwrite(ppufile);
  1074. ppufile.putreal(value);
  1075. {$ifdef ARM}
  1076. ppufile.putbyte(byte(formatoptions));
  1077. {$endif ARM}
  1078. end;
  1079. {****************************************************************************
  1080. TAI_real_80bit
  1081. ****************************************************************************}
  1082. constructor tai_real_80bit.Create(_value : ts80real);
  1083. begin
  1084. inherited Create;
  1085. typ:=ait_real_80bit;
  1086. value:=_value;
  1087. end;
  1088. constructor tai_real_80bit.ppuload(t:taitype;ppufile:tcompilerppufile);
  1089. begin
  1090. inherited ppuload(t,ppufile);
  1091. value:=ppufile.getreal;
  1092. end;
  1093. procedure tai_real_80bit.ppuwrite(ppufile:tcompilerppufile);
  1094. begin
  1095. inherited ppuwrite(ppufile);
  1096. ppufile.putreal(value);
  1097. end;
  1098. {****************************************************************************
  1099. TAI_real_80bit
  1100. ****************************************************************************}
  1101. constructor tai_real_128bit.Create(_value : ts128real);
  1102. begin
  1103. inherited Create;
  1104. typ:=ait_real_128bit;
  1105. value:=_value;
  1106. end;
  1107. constructor tai_real_128bit.ppuload(t:taitype;ppufile:tcompilerppufile);
  1108. begin
  1109. inherited ppuload(t,ppufile);
  1110. value:=ppufile.getreal;
  1111. end;
  1112. procedure tai_real_128bit.ppuwrite(ppufile:tcompilerppufile);
  1113. begin
  1114. inherited ppuwrite(ppufile);
  1115. ppufile.putreal(value);
  1116. end;
  1117. {****************************************************************************
  1118. Tai_comp_64bit
  1119. ****************************************************************************}
  1120. constructor tai_comp_64bit.Create(_value : ts64comp);
  1121. begin
  1122. inherited Create;
  1123. typ:=ait_comp_64bit;
  1124. value:=_value;
  1125. end;
  1126. constructor tai_comp_64bit.ppuload(t:taitype;ppufile:tcompilerppufile);
  1127. begin
  1128. inherited ppuload(t,ppufile);
  1129. ppufile.putdata(value,sizeof(value));
  1130. end;
  1131. procedure tai_comp_64bit.ppuwrite(ppufile:tcompilerppufile);
  1132. begin
  1133. inherited ppuwrite(ppufile);
  1134. ppufile.getdata(value,sizeof(value));
  1135. end;
  1136. {****************************************************************************
  1137. TAI_STRING
  1138. ****************************************************************************}
  1139. constructor tai_string.Create(const _str : string);
  1140. begin
  1141. inherited Create;
  1142. typ:=ait_string;
  1143. len:=length(_str);
  1144. getmem(str,len+1);
  1145. strpcopy(str,_str);
  1146. end;
  1147. constructor tai_string.Create_pchar(_str : pchar);
  1148. begin
  1149. inherited Create;
  1150. typ:=ait_string;
  1151. str:=_str;
  1152. len:=strlen(_str);
  1153. end;
  1154. constructor tai_string.Create_length_pchar(_str : pchar;length : longint);
  1155. begin
  1156. inherited Create;
  1157. typ:=ait_string;
  1158. str:=_str;
  1159. len:=length;
  1160. end;
  1161. destructor tai_string.destroy;
  1162. begin
  1163. { you can have #0 inside the strings so }
  1164. if str<>nil then
  1165. freemem(str,len+1);
  1166. inherited Destroy;
  1167. end;
  1168. constructor tai_string.ppuload(t:taitype;ppufile:tcompilerppufile);
  1169. begin
  1170. inherited ppuload(t,ppufile);
  1171. len:=ppufile.getlongint;
  1172. getmem(str,len+1);
  1173. ppufile.getdata(str^,len);
  1174. str[len]:=#0;
  1175. end;
  1176. procedure tai_string.ppuwrite(ppufile:tcompilerppufile);
  1177. begin
  1178. inherited ppuwrite(ppufile);
  1179. ppufile.putlongint(len);
  1180. ppufile.putdata(str^,len);
  1181. end;
  1182. function tai_string.getcopy : tlinkedlistitem;
  1183. var
  1184. p : tlinkedlistitem;
  1185. begin
  1186. p:=inherited getcopy;
  1187. getmem(tai_string(p).str,len+1);
  1188. move(str^,tai_string(p).str^,len+1);
  1189. getcopy:=p;
  1190. end;
  1191. {****************************************************************************
  1192. TAI_LABEL
  1193. ****************************************************************************}
  1194. constructor tai_label.create(_l : tasmlabel);
  1195. begin
  1196. inherited Create;
  1197. typ:=ait_label;
  1198. l:=_l;
  1199. l.is_set:=true;
  1200. is_global:=(l.defbind=AB_GLOBAL);
  1201. end;
  1202. constructor tai_label.ppuload(t:taitype;ppufile:tcompilerppufile);
  1203. begin
  1204. inherited ppuload(t,ppufile);
  1205. l:=tasmlabel(ppufile.getasmsymbol);
  1206. is_global:=boolean(ppufile.getbyte);
  1207. end;
  1208. procedure tai_label.ppuwrite(ppufile:tcompilerppufile);
  1209. begin
  1210. inherited ppuwrite(ppufile);
  1211. ppufile.putasmsymbol(l);
  1212. ppufile.putbyte(byte(is_global));
  1213. end;
  1214. procedure tai_label.derefimpl;
  1215. begin
  1216. objectlibrary.DerefAsmsymbol(tasmsymbol(l));
  1217. l.is_set:=true;
  1218. end;
  1219. {****************************************************************************
  1220. TAI_DIRECT
  1221. ****************************************************************************}
  1222. constructor tai_direct.Create(_str : pchar);
  1223. begin
  1224. inherited Create;
  1225. typ:=ait_direct;
  1226. str:=_str;
  1227. end;
  1228. destructor tai_direct.destroy;
  1229. begin
  1230. strdispose(str);
  1231. inherited Destroy;
  1232. end;
  1233. constructor tai_direct.ppuload(t:taitype;ppufile:tcompilerppufile);
  1234. var
  1235. len : longint;
  1236. begin
  1237. inherited ppuload(t,ppufile);
  1238. len:=ppufile.getlongint;
  1239. getmem(str,len+1);
  1240. ppufile.getdata(str^,len);
  1241. str[len]:=#0;
  1242. end;
  1243. procedure tai_direct.ppuwrite(ppufile:tcompilerppufile);
  1244. var
  1245. len : longint;
  1246. begin
  1247. inherited ppuwrite(ppufile);
  1248. len:=strlen(str);
  1249. ppufile.putlongint(len);
  1250. ppufile.putdata(str^,len);
  1251. end;
  1252. function tai_direct.getcopy : tlinkedlistitem;
  1253. var
  1254. p : tlinkedlistitem;
  1255. begin
  1256. p:=inherited getcopy;
  1257. getmem(tai_direct(p).str,strlen(str)+1);
  1258. move(str^,tai_direct(p).str^,strlen(str)+1);
  1259. getcopy:=p;
  1260. end;
  1261. {****************************************************************************
  1262. tai_comment comment to be inserted in the assembler file
  1263. ****************************************************************************}
  1264. constructor tai_comment.Create(_str : pchar);
  1265. begin
  1266. inherited Create;
  1267. typ:=ait_comment;
  1268. str:=_str;
  1269. end;
  1270. destructor tai_comment.destroy;
  1271. begin
  1272. strdispose(str);
  1273. inherited Destroy;
  1274. end;
  1275. constructor tai_comment.ppuload(t:taitype;ppufile:tcompilerppufile);
  1276. var
  1277. len : longint;
  1278. begin
  1279. inherited ppuload(t,ppufile);
  1280. len:=ppufile.getlongint;
  1281. getmem(str,len+1);
  1282. ppufile.getdata(str^,len);
  1283. str[len]:=#0;
  1284. end;
  1285. procedure tai_comment.ppuwrite(ppufile:tcompilerppufile);
  1286. var
  1287. len : longint;
  1288. begin
  1289. inherited ppuwrite(ppufile);
  1290. len:=strlen(str);
  1291. ppufile.putlongint(len);
  1292. ppufile.putdata(str^,len);
  1293. end;
  1294. function tai_comment.getcopy : tlinkedlistitem;
  1295. var
  1296. p : tlinkedlistitem;
  1297. begin
  1298. p:=inherited getcopy;
  1299. getmem(tai_comment(p).str,strlen(str)+1);
  1300. move(str^,tai_comment(p).str^,strlen(str)+1);
  1301. getcopy:=p;
  1302. end;
  1303. {****************************************************************************
  1304. TAI_CUTOBJECT
  1305. ****************************************************************************}
  1306. constructor tai_cutobject.Create;
  1307. begin
  1308. inherited Create;
  1309. typ:=ait_cutobject;
  1310. place:=cut_normal;
  1311. end;
  1312. constructor tai_cutobject.Create_begin;
  1313. begin
  1314. inherited Create;
  1315. typ:=ait_cutobject;
  1316. place:=cut_begin;
  1317. end;
  1318. constructor tai_cutobject.Create_end;
  1319. begin
  1320. inherited Create;
  1321. typ:=ait_cutobject;
  1322. place:=cut_end;
  1323. end;
  1324. constructor tai_cutobject.ppuload(t:taitype;ppufile:tcompilerppufile);
  1325. begin
  1326. inherited ppuload(t,ppufile);
  1327. place:=TCutPlace(ppufile.getbyte);
  1328. end;
  1329. procedure tai_cutobject.ppuwrite(ppufile:tcompilerppufile);
  1330. begin
  1331. inherited ppuwrite(ppufile);
  1332. ppufile.putbyte(byte(place));
  1333. end;
  1334. {****************************************************************************
  1335. Tai_Marker
  1336. ****************************************************************************}
  1337. constructor Tai_Marker.Create(_Kind: TMarker);
  1338. begin
  1339. Inherited Create;
  1340. typ := ait_marker;
  1341. Kind := _Kind;
  1342. end;
  1343. constructor Tai_Marker.ppuload(t:taitype;ppufile:tcompilerppufile);
  1344. begin
  1345. inherited ppuload(t,ppufile);
  1346. kind:=TMarker(ppufile.getbyte);
  1347. end;
  1348. procedure Tai_Marker.ppuwrite(ppufile:tcompilerppufile);
  1349. begin
  1350. inherited ppuwrite(ppufile);
  1351. ppufile.putbyte(byte(kind));
  1352. end;
  1353. {*****************************************************************************
  1354. tai_tempalloc
  1355. *****************************************************************************}
  1356. constructor tai_tempalloc.alloc(pos,size:longint);
  1357. begin
  1358. inherited Create;
  1359. typ:=ait_tempalloc;
  1360. allocation:=true;
  1361. temppos:=pos;
  1362. tempsize:=size;
  1363. {$ifdef EXTDEBUG}
  1364. problem:=nil;
  1365. {$endif EXTDEBUG}
  1366. end;
  1367. destructor tai_tempalloc.destroy;
  1368. begin
  1369. {$ifdef EXTDEBUG}
  1370. stringdispose(problem);
  1371. {$endif EXTDEBUG}
  1372. inherited destroy;
  1373. end;
  1374. constructor tai_tempalloc.dealloc(pos,size:longint);
  1375. begin
  1376. inherited Create;
  1377. typ:=ait_tempalloc;
  1378. allocation:=false;
  1379. temppos:=pos;
  1380. tempsize:=size;
  1381. {$ifdef EXTDEBUG}
  1382. problem:=nil;
  1383. {$endif EXTDEBUG}
  1384. end;
  1385. {$ifdef EXTDEBUG}
  1386. constructor tai_tempalloc.allocinfo(pos,size:longint;const st:string);
  1387. begin
  1388. inherited Create;
  1389. typ:=ait_tempalloc;
  1390. allocation:=false;
  1391. temppos:=pos;
  1392. tempsize:=size;
  1393. problem:=stringdup(st);
  1394. end;
  1395. {$endif EXTDEBUG}
  1396. constructor tai_tempalloc.ppuload(t:taitype;ppufile:tcompilerppufile);
  1397. begin
  1398. inherited ppuload(t,ppufile);
  1399. temppos:=ppufile.getlongint;
  1400. tempsize:=ppufile.getlongint;
  1401. allocation:=boolean(ppufile.getbyte);
  1402. {$ifdef EXTDEBUG}
  1403. problem:=nil;
  1404. {$endif EXTDEBUG}
  1405. end;
  1406. procedure tai_tempalloc.ppuwrite(ppufile:tcompilerppufile);
  1407. begin
  1408. inherited ppuwrite(ppufile);
  1409. ppufile.putlongint(temppos);
  1410. ppufile.putlongint(tempsize);
  1411. ppufile.putbyte(byte(allocation));
  1412. end;
  1413. {*****************************************************************************
  1414. tai_regalloc
  1415. *****************************************************************************}
  1416. constructor tai_regalloc.alloc(r : tregister;ainstr:tai);
  1417. begin
  1418. inherited create;
  1419. typ:=ait_regalloc;
  1420. ratype:=ra_alloc;
  1421. reg:=r;
  1422. { ainstr must be an instruction }
  1423. if assigned(ainstr) and
  1424. (ainstr.typ<>ait_instruction) then
  1425. internalerror(200411011);
  1426. instr:=ainstr;
  1427. end;
  1428. constructor tai_regalloc.dealloc(r : tregister;ainstr:tai);
  1429. begin
  1430. inherited create;
  1431. typ:=ait_regalloc;
  1432. ratype:=ra_dealloc;
  1433. reg:=r;
  1434. { ainstr must be an instruction }
  1435. if assigned(ainstr) and
  1436. (ainstr.typ<>ait_instruction) then
  1437. internalerror(200411012);
  1438. instr:=ainstr;
  1439. end;
  1440. constructor tai_regalloc.sync(r : tregister);
  1441. begin
  1442. inherited create;
  1443. typ:=ait_regalloc;
  1444. ratype:=ra_sync;
  1445. reg:=r;
  1446. end;
  1447. constructor tai_regalloc.resize(r : tregister);
  1448. begin
  1449. inherited create;
  1450. typ:=ait_regalloc;
  1451. ratype:=ra_resize;
  1452. reg:=r;
  1453. end;
  1454. constructor tai_regalloc.ppuload(t:taitype;ppufile:tcompilerppufile);
  1455. begin
  1456. inherited ppuload(t,ppufile);
  1457. ppufile.getdata(reg,sizeof(Tregister));
  1458. ratype:=tregalloctype(ppufile.getbyte);
  1459. end;
  1460. procedure tai_regalloc.ppuwrite(ppufile:tcompilerppufile);
  1461. begin
  1462. inherited ppuwrite(ppufile);
  1463. ppufile.putdata(reg,sizeof(Tregister));
  1464. ppufile.putbyte(byte(ratype));
  1465. end;
  1466. {*****************************************************************************
  1467. TaiInstruction
  1468. *****************************************************************************}
  1469. constructor tai_cpu_abstract.Create(op : tasmop);
  1470. begin
  1471. inherited create;
  1472. typ:=ait_instruction;
  1473. is_jmp:=false;
  1474. opcode:=op;
  1475. ops:=0;
  1476. fillchar(condition,sizeof(condition),0);
  1477. fillchar(oper,sizeof(oper),0);
  1478. end;
  1479. destructor tai_cpu_abstract.Destroy;
  1480. var
  1481. i : integer;
  1482. begin
  1483. for i:=0 to opercnt-1 do
  1484. begin
  1485. clearop(i);
  1486. dispose(oper[i]);
  1487. end;
  1488. inherited destroy;
  1489. end;
  1490. { ---------------------------------------------------------------------
  1491. Loading of operands.
  1492. ---------------------------------------------------------------------}
  1493. procedure tai_cpu_abstract.allocate_oper(opers:longint);
  1494. begin
  1495. while (opers>opercnt) do
  1496. begin
  1497. new(oper[opercnt]);
  1498. fillchar(oper[opercnt]^,sizeof(toper),0);
  1499. inc(opercnt);
  1500. end;
  1501. end;
  1502. procedure tai_cpu_abstract.loadconst(opidx:longint;l:aint);
  1503. begin
  1504. allocate_oper(opidx+1);
  1505. with oper[opidx]^ do
  1506. begin
  1507. if typ<>top_const then
  1508. clearop(opidx);
  1509. val:=l;
  1510. typ:=top_const;
  1511. end;
  1512. end;
  1513. procedure tai_cpu_abstract.loadsymbol(opidx:longint;s:tasmsymbol;sofs:longint);
  1514. var
  1515. r : treference;
  1516. begin
  1517. reference_reset_symbol(r,s,sofs);
  1518. r.refaddr:=addr_full;
  1519. loadref(opidx,r);
  1520. end;
  1521. procedure tai_cpu_abstract.loadlocal(opidx:longint;s:pointer;sofs:longint;indexreg:tregister;scale:byte;getoffset,forceref:boolean);
  1522. begin
  1523. if not assigned(s) then
  1524. internalerror(200204251);
  1525. allocate_oper(opidx+1);
  1526. with oper[opidx]^ do
  1527. begin
  1528. if typ<>top_local then
  1529. begin
  1530. clearop(opidx);
  1531. new(localoper);
  1532. end;
  1533. with oper[opidx]^.localoper^ do
  1534. begin
  1535. localsym:=s;
  1536. localsymofs:=sofs;
  1537. localindexreg:=indexreg;
  1538. localscale:=scale;
  1539. localgetoffset:=getoffset;
  1540. localforceref:=forceref;
  1541. end;
  1542. typ:=top_local;
  1543. end;
  1544. end;
  1545. procedure tai_cpu_abstract.loadref(opidx:longint;const r:treference);
  1546. begin
  1547. allocate_oper(opidx+1);
  1548. with oper[opidx]^ do
  1549. begin
  1550. if typ<>top_ref then
  1551. begin
  1552. clearop(opidx);
  1553. new(ref);
  1554. end;
  1555. ref^:=r;
  1556. {$ifdef x86}
  1557. { We allow this exception for x86, since overloading this would be
  1558. too much of a a speed penalty}
  1559. if (ref^.segment<>NR_NO) and (ref^.segment<>NR_DS) then
  1560. segprefix:=ref^.segment;
  1561. {$endif}
  1562. {$ifdef extdebug}
  1563. if (cs_create_pic in aktmoduleswitches) and
  1564. assigned(r.symbol) and
  1565. (r.refaddr=addr_no) then
  1566. internalerror(200502052);
  1567. {$endif}
  1568. typ:=top_ref;
  1569. if assigned(add_reg_instruction_hook) then
  1570. begin
  1571. add_reg_instruction_hook(self,ref^.base);
  1572. add_reg_instruction_hook(self,ref^.index);
  1573. end;
  1574. { mark symbol as used }
  1575. if assigned(ref^.symbol) then
  1576. ref^.symbol.increfs;
  1577. end;
  1578. end;
  1579. procedure tai_cpu_abstract.loadreg(opidx:longint;r:tregister);
  1580. begin
  1581. allocate_oper(opidx+1);
  1582. with oper[opidx]^ do
  1583. begin
  1584. if typ<>top_reg then
  1585. clearop(opidx);
  1586. reg:=r;
  1587. typ:=top_reg;
  1588. end;
  1589. if assigned(add_reg_instruction_hook) then
  1590. add_reg_instruction_hook(self,r);
  1591. {$ifdef ARM}
  1592. { R15 is the PC on the ARM thus moves to R15 are jumps.
  1593. Due to speed considerations we don't use a virtual overridden method here.
  1594. Because the pc/r15 isn't handled by the reg. allocator this should never cause
  1595. problems with iregs getting r15.
  1596. }
  1597. is_jmp:=(opcode=A_MOV) and (opidx=0) and (r=NR_R15);
  1598. {$endif ARM}
  1599. end;
  1600. procedure tai_cpu_abstract.loadoper(opidx:longint;o:toper);
  1601. begin
  1602. allocate_oper(opidx+1);
  1603. clearop(opidx);
  1604. oper[opidx]^:=o;
  1605. { copy also the reference }
  1606. with oper[opidx]^ do
  1607. begin
  1608. case typ of
  1609. top_reg:
  1610. begin
  1611. if assigned(add_reg_instruction_hook) then
  1612. add_reg_instruction_hook(self,reg);
  1613. end;
  1614. top_ref:
  1615. begin
  1616. new(ref);
  1617. ref^:=o.ref^;
  1618. if assigned(add_reg_instruction_hook) then
  1619. begin
  1620. add_reg_instruction_hook(self,ref^.base);
  1621. add_reg_instruction_hook(self,ref^.index);
  1622. end;
  1623. end;
  1624. {$ifdef ARM}
  1625. top_shifterop:
  1626. begin
  1627. new(shifterop);
  1628. shifterop^:=o.shifterop^;
  1629. if assigned(add_reg_instruction_hook) then
  1630. add_reg_instruction_hook(self,shifterop^.rs);
  1631. end;
  1632. {$endif ARM}
  1633. end;
  1634. end;
  1635. end;
  1636. procedure tai_cpu_abstract.clearop(opidx:longint);
  1637. begin
  1638. with oper[opidx]^ do
  1639. begin
  1640. case typ of
  1641. top_ref:
  1642. dispose(ref);
  1643. top_local:
  1644. dispose(localoper);
  1645. {$ifdef ARM}
  1646. top_shifterop:
  1647. dispose(shifterop);
  1648. top_regset:
  1649. dispose(regset);
  1650. {$endif ARM}
  1651. end;
  1652. typ:=top_none;
  1653. end;
  1654. end;
  1655. { ---------------------------------------------------------------------
  1656. Miscellaneous methods.
  1657. ---------------------------------------------------------------------}
  1658. procedure tai_cpu_abstract.SetCondition(const c:TAsmCond);
  1659. begin
  1660. condition:=c;
  1661. end;
  1662. Function tai_cpu_abstract.getcopy:TLinkedListItem;
  1663. var
  1664. i : longint;
  1665. p : tai_cpu_abstract;
  1666. begin
  1667. p:=tai_cpu_abstract(inherited getcopy);
  1668. { make a copy of the references }
  1669. p.opercnt:=0;
  1670. p.allocate_oper(ops);
  1671. for i:=0 to ops-1 do
  1672. begin
  1673. p.oper[i]^:=oper[i]^;
  1674. case oper[i]^.typ of
  1675. top_local :
  1676. begin
  1677. new(p.oper[i]^.localoper);
  1678. p.oper[i]^.localoper^:=oper[i]^.localoper^;
  1679. end;
  1680. top_ref :
  1681. begin
  1682. new(p.oper[i]^.ref);
  1683. p.oper[i]^.ref^:=oper[i]^.ref^;
  1684. end;
  1685. {$ifdef ARM}
  1686. top_shifterop:
  1687. begin
  1688. new(p.oper[i]^.shifterop);
  1689. p.oper[i]^.shifterop^:=oper[i]^.shifterop^;
  1690. end;
  1691. {$endif ARM}
  1692. end;
  1693. end;
  1694. getcopy:=p;
  1695. end;
  1696. function tai_cpu_abstract.is_same_reg_move(regtype: Tregistertype):boolean;
  1697. begin
  1698. { When the generic RA is used this needs to be overriden, we don't use
  1699. virtual;abstract; to prevent a lot of warnings of unimplemented abstract methods
  1700. when tai_cpu is created (PFV) }
  1701. internalerror(200404091);
  1702. end;
  1703. function tai_cpu_abstract.spilling_get_operation_type(opnr: longint): topertype;
  1704. begin
  1705. internalerror(200404091);
  1706. end;
  1707. function tai_cpu_abstract.spilling_get_operation_type_ref(opnr: longint; reg: tregister): topertype;
  1708. begin
  1709. result := operand_read;
  1710. end;
  1711. constructor tai_cpu_abstract.ppuload(t:taitype;ppufile:tcompilerppufile);
  1712. var
  1713. i : integer;
  1714. begin
  1715. inherited ppuload(t,ppufile);
  1716. { hopefully, we don't get problems with big/litte endian here when cross compiling :/ }
  1717. ppufile.getdata(condition,sizeof(tasmcond));
  1718. allocate_oper(ppufile.getbyte);
  1719. for i:=0 to ops-1 do
  1720. ppuloadoper(ppufile,oper[i]^);
  1721. opcode:=tasmop(ppufile.getword);
  1722. {$ifdef x86}
  1723. ppufile.getdata(segprefix,sizeof(Tregister));
  1724. {$endif x86}
  1725. is_jmp:=boolean(ppufile.getbyte);
  1726. end;
  1727. procedure tai_cpu_abstract.ppuwrite(ppufile:tcompilerppufile);
  1728. var
  1729. i : integer;
  1730. begin
  1731. inherited ppuwrite(ppufile);
  1732. ppufile.putdata(condition,sizeof(tasmcond));
  1733. ppufile.putbyte(ops);
  1734. for i:=0 to ops-1 do
  1735. ppuwriteoper(ppufile,oper[i]^);
  1736. ppufile.putword(word(opcode));
  1737. {$ifdef x86}
  1738. ppufile.putdata(segprefix,sizeof(Tregister));
  1739. {$endif x86}
  1740. ppufile.putbyte(byte(is_jmp));
  1741. end;
  1742. procedure tai_cpu_abstract.buildderefimpl;
  1743. var
  1744. i : integer;
  1745. begin
  1746. for i:=0 to ops-1 do
  1747. ppubuildderefimploper(oper[i]^);
  1748. end;
  1749. procedure tai_cpu_abstract.derefimpl;
  1750. var
  1751. i : integer;
  1752. begin
  1753. for i:=0 to ops-1 do
  1754. ppuderefoper(oper[i]^);
  1755. end;
  1756. {****************************************************************************
  1757. tai_align_abstract
  1758. ****************************************************************************}
  1759. constructor tai_align_abstract.Create(b: byte);
  1760. begin
  1761. inherited Create;
  1762. typ:=ait_align;
  1763. if b in [1,2,4,8,16,32] then
  1764. aligntype := b
  1765. else
  1766. aligntype := 1;
  1767. fillsize:=0;
  1768. fillop:=0;
  1769. use_op:=false;
  1770. end;
  1771. constructor tai_align_abstract.Create_op(b: byte; _op: byte);
  1772. begin
  1773. inherited Create;
  1774. typ:=ait_align;
  1775. if b in [1,2,4,8,16,32] then
  1776. aligntype := b
  1777. else
  1778. aligntype := 1;
  1779. fillsize:=0;
  1780. fillop:=_op;
  1781. use_op:=true;
  1782. end;
  1783. constructor tai_align_abstract.Create_zeros(b: byte);
  1784. begin
  1785. inherited Create;
  1786. typ:=ait_align;
  1787. if b in [1,2,4,8,16,32] then
  1788. aligntype := b
  1789. else
  1790. aligntype := 1;
  1791. use_op:=true;
  1792. fillsize:=0;
  1793. fillop:=0;
  1794. end;
  1795. function tai_align_abstract.calculatefillbuf(var buf : tfillbuffer):pchar;
  1796. begin
  1797. if fillsize>sizeof(buf) then
  1798. internalerror(200404293);
  1799. fillchar(buf,high(buf),fillop);
  1800. calculatefillbuf:=pchar(@buf);
  1801. end;
  1802. constructor tai_align_abstract.ppuload(t:taitype;ppufile:tcompilerppufile);
  1803. begin
  1804. inherited ppuload(t,ppufile);
  1805. aligntype:=ppufile.getbyte;
  1806. fillsize:=0;
  1807. fillop:=ppufile.getbyte;
  1808. use_op:=boolean(ppufile.getbyte);
  1809. end;
  1810. procedure tai_align_abstract.ppuwrite(ppufile:tcompilerppufile);
  1811. begin
  1812. inherited ppuwrite(ppufile);
  1813. ppufile.putbyte(aligntype);
  1814. ppufile.putbyte(fillop);
  1815. ppufile.putbyte(byte(use_op));
  1816. end;
  1817. {*****************************************************************************
  1818. TAAsmOutput
  1819. *****************************************************************************}
  1820. constructor taasmoutput.create;
  1821. begin
  1822. inherited create;
  1823. { make sure the optimizer won't remove the first tai of this list}
  1824. insert(tai_marker.create(marker_blockstart));
  1825. end;
  1826. function taasmoutput.empty : boolean;
  1827. begin
  1828. { there is always a marker_blockstart available,
  1829. see taasmoutput.create }
  1830. result:=(count<=1);
  1831. end;
  1832. function taasmoutput.getlasttaifilepos : pfileposinfo;
  1833. var
  1834. hp : tlinkedlistitem;
  1835. begin
  1836. getlasttaifilepos := nil;
  1837. if assigned(last) then
  1838. begin
  1839. { find the last file information record }
  1840. if not (tai(last).typ in SkipLineInfo) then
  1841. getlasttaifilepos:=@tailineinfo(last).fileinfo
  1842. else
  1843. { go through list backwards to find the first entry
  1844. with line information
  1845. }
  1846. begin
  1847. hp:=tai(last);
  1848. while assigned(hp) and (tai(hp).typ in SkipLineInfo) do
  1849. hp:=hp.Previous;
  1850. { found entry }
  1851. if assigned(hp) then
  1852. getlasttaifilepos:=@tailineinfo(hp).fileinfo
  1853. end;
  1854. end;
  1855. end;
  1856. procedure Taasmoutput.InsertAfter(Item,Loc : TLinkedListItem);
  1857. begin
  1858. { This is not possible because it is not sure that the
  1859. tai at Loc has taifileinfo as parent }
  1860. {if assigned(Loc) then
  1861. tailineinfo(Item).fileinfo:=tailineinfo(Loc).fileinfo;}
  1862. inherited InsertAfter(Item,Loc);
  1863. end;
  1864. begin
  1865. cai_cpu:=tai_cpu_abstract;
  1866. cai_align:=tai_align_abstract;
  1867. end.