aasmtai.pas 64 KB

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