aasmtai.pas 64 KB

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