aasmtai.pas 64 KB

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