aasmtai.pas 67 KB

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