aasmtai.pas 63 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248
  1. {
  2. Copyright (c) 1998-2002 by Florian Klaempfl
  3. This unit implements an abstract asmoutput class for all processor types
  4. This program is free software; you can redistribute it and/or modify
  5. it under the terms of the GNU General Public License as published by
  6. the Free Software Foundation; either version 2 of the License, or
  7. (at your option) any later version.
  8. This program is distributed in the hope that it will be useful,
  9. but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. GNU General Public License for more details.
  12. You should have received a copy of the GNU General Public License
  13. along with this program; if not, write to the Free Software
  14. Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  15. ****************************************************************************
  16. }
  17. { @abstract(This unit implements an abstract asm output class for all processor types)
  18. This unit implements an abstract assembler output class for all processors, these
  19. are then overriden for each assembler writer to actually write the data in these
  20. classes to an assembler file.
  21. }
  22. unit aasmtai;
  23. {$i fpcdefs.inc}
  24. interface
  25. uses
  26. cutils,cclasses,
  27. globtype,globals,systems,
  28. cpuinfo,cpubase,
  29. cgbase,cgutils,
  30. symtype,
  31. aasmbase;
  32. type
  33. taitype = (
  34. ait_none,
  35. ait_align,
  36. ait_section,
  37. ait_comment,
  38. ait_direct,
  39. ait_string,
  40. ait_instruction,
  41. ait_datablock,
  42. ait_symbol,
  43. ait_symbol_end, { needed to calc the size of a symbol }
  44. ait_label,
  45. { the const_xx must be below each other so it can be used as
  46. array index }
  47. ait_const_128bit,
  48. ait_const_64bit,
  49. ait_const_32bit,
  50. ait_const_16bit,
  51. ait_const_8bit,
  52. ait_const_sleb128bit,
  53. ait_const_uleb128bit,
  54. ait_const_rva_symbol, { win32 only }
  55. ait_const_indirect_symbol, { darwin only }
  56. ait_real_32bit,
  57. ait_real_64bit,
  58. ait_real_80bit,
  59. ait_comp_64bit,
  60. ait_real_128bit,
  61. {$ifdef GDB}
  62. ait_stabn,
  63. ait_stabs,
  64. ait_force_line,
  65. ait_stab_function_name,
  66. {$endif GDB}
  67. {$ifdef alpha}
  68. { the follow is for the DEC Alpha }
  69. ait_frame,
  70. ait_ent,
  71. {$endif alpha}
  72. {$ifdef ia64}
  73. ait_bundle,
  74. ait_stop,
  75. {$endif ia64}
  76. {$ifdef m68k}
  77. ait_labeled_instruction,
  78. {$endif m68k}
  79. { used to split into tiny assembler files }
  80. ait_cutobject,
  81. ait_regalloc,
  82. ait_tempalloc,
  83. { used to mark assembler blocks and inlined functions }
  84. ait_marker,
  85. { special symbol for darwin pic code }
  86. ait_non_lazy_symbol_pointer
  87. );
  88. const
  89. {$ifdef cpu64bit}
  90. ait_const_aint = ait_const_64bit;
  91. ait_const_ptr = ait_const_64bit;
  92. {$else cpu64bit}
  93. ait_const_aint = ait_const_32bit;
  94. ait_const_ptr = ait_const_32bit;
  95. {$endif cpu64bit}
  96. taitypestr : array[taitype] of string[24] = (
  97. '<none>',
  98. 'align',
  99. 'section',
  100. 'comment',
  101. 'direct',
  102. 'string',
  103. 'instruction',
  104. 'datablock',
  105. 'symbol',
  106. 'symbol_end',
  107. 'label',
  108. 'const_128bit',
  109. 'const_64bit',
  110. 'const_32bit',
  111. 'const_16bit',
  112. 'const_8bit',
  113. 'const_sleb128bit',
  114. 'const_uleb128bit',
  115. 'const_rva_symbol',
  116. 'const_indirect_symbol',
  117. 'real_32bit',
  118. 'real_64bit',
  119. 'real_80bit',
  120. 'comp_64bit',
  121. 'real_128bit',
  122. {$ifdef GDB}
  123. 'stabn',
  124. 'stabs',
  125. 'force_line',
  126. 'stab_funcname',
  127. {$endif GDB}
  128. {$ifdef alpha}
  129. { the follow is for the DEC Alpha }
  130. 'frame',
  131. 'ent',
  132. {$endif alpha}
  133. {$ifdef ia64}
  134. 'bundle',
  135. 'stop',
  136. {$endif ia64}
  137. {$ifdef m68k}
  138. 'labeled_instr',
  139. {$endif m68k}
  140. 'cut',
  141. 'regalloc',
  142. 'tempalloc',
  143. 'marker',
  144. 'non_lazy_symbol_pointer'
  145. );
  146. type
  147. { Types of operand }
  148. toptype=(top_none,top_reg,top_ref,top_const,top_bool,top_local,
  149. { ARM only }
  150. top_regset,
  151. top_shifterop,
  152. { m68k only }
  153. top_reglist);
  154. { kinds of operations that an instruction can perform on an operand }
  155. topertype = (operand_read,operand_write,operand_readwrite);
  156. tlocaloper = record
  157. localsym : pointer;
  158. localsymderef : tderef;
  159. localsymofs : longint;
  160. localindexreg : tregister;
  161. localscale : byte;
  162. localgetoffset,
  163. localforceref : boolean
  164. end;
  165. plocaloper = ^tlocaloper;
  166. { please keep the size of this record <=12 bytes and keep it properly aligned }
  167. toper = record
  168. ot : longint;
  169. case typ : toptype of
  170. top_none : ();
  171. top_reg : (reg:tregister);
  172. top_ref : (ref:preference);
  173. top_const : (val:aint);
  174. top_bool : (b:boolean);
  175. { local varsym that will be inserted in pass_2 }
  176. top_local : (localoper:plocaloper);
  177. {$ifdef arm}
  178. top_regset : (regset:^tcpuregisterset);
  179. top_shifterop : (shifterop : pshifterop);
  180. {$endif arm}
  181. {$ifdef m68k}
  182. top_regset : (regset:^tcpuregisterset);
  183. {$endif m68k}
  184. end;
  185. poper=^toper;
  186. { ait_* types which don't result in executable code or which don't influence }
  187. { the way the program runs/behaves, but which may be encountered by the }
  188. { optimizer (= if it's sometimes added to the exprasm list). Update if you add }
  189. { a new ait type! }
  190. const
  191. SkipInstr = [ait_comment, ait_symbol,ait_section
  192. {$ifdef GDB}
  193. ,ait_stabs, ait_stabn, ait_stab_function_name, ait_force_line
  194. {$endif GDB}
  195. ,ait_regalloc, ait_tempalloc, ait_symbol_end];
  196. { ait_* types which do not have line information (and hence which are of type
  197. tai, otherwise, they are of type tailineinfo }
  198. SkipLineInfo =[ait_label,
  199. ait_regalloc,ait_tempalloc,
  200. {$ifdef GDB}
  201. ait_stabn,ait_stabs,ait_stab_function_name,
  202. {$endif GDB}
  203. ait_cutobject,ait_marker,ait_align,ait_section,ait_comment,
  204. ait_const_8bit,ait_const_16bit,ait_const_32bit,ait_const_64bit,ait_const_128bit,
  205. ait_const_sleb128bit,ait_const_uleb128bit,
  206. ait_const_rva_symbol,ait_const_indirect_symbol,
  207. ait_real_32bit,ait_real_64bit,ait_real_80bit,ait_comp_64bit,ait_real_128bit,
  208. ait_non_lazy_symbol_pointer
  209. ];
  210. type
  211. { cut type, required for alphanumeric ordering of the assembler filenames }
  212. TCutPlace=(cut_normal,cut_begin,cut_end);
  213. TRegAllocType = (ra_alloc,ra_dealloc,ra_sync,ra_resize);
  214. TMarker = (NoPropInfoStart,NoPropInfoEnd,
  215. AsmBlockStart,AsmBlockEnd,
  216. InlineStart,InlineEnd,marker_blockstart,
  217. marker_position);
  218. { Buffer type used for alignment }
  219. tfillbuffer = array[0..63] of char;
  220. Tspill_temp_list=array[tsuperregister] of Treference;
  221. { abstract assembler item }
  222. tai = class(TLinkedListItem)
  223. {$ifndef NOOPT}
  224. { pointer to record with optimizer info about this tai object }
  225. optinfo : pointer;
  226. {$endif NOOPT}
  227. typ : taitype;
  228. constructor Create;
  229. constructor ppuload(t:taitype;ppufile:tcompilerppufile);virtual;
  230. procedure ppuwrite(ppufile:tcompilerppufile);virtual;
  231. procedure buildderefimpl;virtual;
  232. procedure derefimpl;virtual;
  233. end;
  234. { abstract assembler item with line information }
  235. tailineinfo = class(tai)
  236. fileinfo : tfileposinfo;
  237. constructor Create;
  238. constructor ppuload(t:taitype;ppufile:tcompilerppufile);override;
  239. procedure ppuwrite(ppufile:tcompilerppufile);override;
  240. end;
  241. tai_simple = class(tai)
  242. constructor create(_typ : taitype);
  243. end;
  244. taiclass = class of tai;
  245. taiclassarray = array[taitype] of taiclass;
  246. { Generates an assembler string }
  247. tai_string = class(tailineinfo)
  248. str : pchar;
  249. { extra len so the string can contain an \0 }
  250. len : longint;
  251. constructor Create(const _str : string);
  252. constructor Create_pchar(_str : pchar);
  253. constructor Create_length_pchar(_str : pchar;length : longint);
  254. destructor Destroy;override;
  255. constructor ppuload(t:taitype;ppufile:tcompilerppufile);override;
  256. procedure ppuwrite(ppufile:tcompilerppufile);override;
  257. function getcopy:tlinkedlistitem;override;
  258. end;
  259. { Generates a common label }
  260. tai_symbol = class(tailineinfo)
  261. is_global : boolean;
  262. sym : tasmsymbol;
  263. size : longint;
  264. constructor Create(_sym:tasmsymbol;siz:longint);
  265. constructor Create_Global(_sym:tasmsymbol;siz:longint);
  266. constructor Createname(const _name : string;_symtyp:Tasmsymtype;siz:longint);
  267. constructor Createname_global(const _name : string;_symtyp:Tasmsymtype;siz:longint);
  268. constructor ppuload(t:taitype;ppufile:tcompilerppufile);override;
  269. procedure ppuwrite(ppufile:tcompilerppufile);override;
  270. procedure derefimpl;override;
  271. end;
  272. tai_symbol_end = class(tailineinfo)
  273. sym : tasmsymbol;
  274. constructor Create(_sym:tasmsymbol);
  275. constructor Createname(const _name : string);
  276. constructor ppuload(t:taitype;ppufile:tcompilerppufile);override;
  277. procedure ppuwrite(ppufile:tcompilerppufile);override;
  278. procedure derefimpl;override;
  279. end;
  280. { Generates an assembler label }
  281. tai_label = class(tai)
  282. is_global : boolean;
  283. l : tasmlabel;
  284. constructor Create(_l : tasmlabel);
  285. constructor ppuload(t:taitype;ppufile:tcompilerppufile);override;
  286. procedure ppuwrite(ppufile:tcompilerppufile);override;
  287. procedure derefimpl;override;
  288. end;
  289. { Directly output data to final assembler file }
  290. tai_direct = class(tailineinfo)
  291. str : pchar;
  292. constructor Create(_str : pchar);
  293. destructor Destroy; override;
  294. constructor ppuload(t:taitype;ppufile:tcompilerppufile);override;
  295. procedure ppuwrite(ppufile:tcompilerppufile);override;
  296. function getcopy:tlinkedlistitem;override;
  297. end;
  298. { Generates an assembler comment }
  299. tai_comment = class(tai)
  300. str : pchar;
  301. constructor Create(_str : pchar);
  302. destructor Destroy; override;
  303. constructor ppuload(t:taitype;ppufile:tcompilerppufile);override;
  304. procedure ppuwrite(ppufile:tcompilerppufile);override;
  305. function getcopy:tlinkedlistitem;override;
  306. end;
  307. { Generates a section / segment directive }
  308. tai_section = class(tai)
  309. sectype : TAsmSectionType;
  310. secalign : byte;
  311. name : pstring;
  312. sec : TAsmSection; { used in binary writer }
  313. constructor Create(Asectype:TAsmSectionType;Aname:string;Aalign:byte);
  314. destructor Destroy;override;
  315. constructor ppuload(t:taitype;ppufile:tcompilerppufile);override;
  316. procedure ppuwrite(ppufile:tcompilerppufile);override;
  317. end;
  318. { Generates an uninitializised data block }
  319. tai_datablock = class(tailineinfo)
  320. is_global : boolean;
  321. sym : tasmsymbol;
  322. size : longint;
  323. constructor Create(const _name : string;_size : longint);
  324. constructor Create_global(const _name : string;_size : longint);
  325. constructor ppuload(t:taitype;ppufile:tcompilerppufile);override;
  326. procedure ppuwrite(ppufile:tcompilerppufile);override;
  327. procedure derefimpl;override;
  328. end;
  329. { Generates an integer const }
  330. tai_const = class(tai)
  331. sym,
  332. endsym : tasmsymbol;
  333. value : int64;
  334. { we use for the 128bit int64/qword for now because I can't imagine a
  335. case where we need 128 bit now (FK) }
  336. constructor Create(_typ:taitype;_value : int64);
  337. constructor Create_128bit(_value : int64);
  338. constructor Create_64bit(_value : int64);
  339. constructor Create_32bit(_value : longint);
  340. constructor Create_16bit(_value : word);
  341. constructor Create_8bit(_value : byte);
  342. constructor Create_sleb128bit(_value : int64);
  343. constructor Create_uleb128bit(_value : qword);
  344. constructor Create_aint(_value : aint);
  345. constructor Create_sym(_sym:tasmsymbol);
  346. constructor Create_sym_offset(_sym:tasmsymbol;ofs:aint);
  347. constructor Create_rel_sym(_typ:taitype;_sym,_endsym:tasmsymbol);
  348. constructor Create_rva_sym(_sym:tasmsymbol);
  349. constructor Create_indirect_sym(_sym:tasmsymbol);
  350. constructor Createname(const name:string;_symtyp:Tasmsymtype;ofs:aint);
  351. constructor Createname_rva(const name:string);
  352. constructor ppuload(t:taitype;ppufile:tcompilerppufile);override;
  353. procedure ppuwrite(ppufile:tcompilerppufile);override;
  354. procedure derefimpl;override;
  355. function getcopy:tlinkedlistitem;override;
  356. function size:longint;
  357. end;
  358. { Generates a single float (32 bit real) }
  359. tai_real_32bit = class(tai)
  360. value : ts32real;
  361. constructor Create(_value : ts32real);
  362. constructor ppuload(t:taitype;ppufile:tcompilerppufile);override;
  363. procedure ppuwrite(ppufile:tcompilerppufile);override;
  364. end;
  365. tformatoptions = (fo_none,fo_hiloswapped);
  366. { Generates a double float (64 bit real) }
  367. tai_real_64bit = class(tai)
  368. value : ts64real;
  369. {$ifdef ARM}
  370. formatoptions : tformatoptions;
  371. constructor Create_hiloswapped(_value : ts64real);
  372. {$endif ARM}
  373. constructor Create(_value : ts64real);
  374. constructor ppuload(t:taitype;ppufile:tcompilerppufile);override;
  375. procedure ppuwrite(ppufile:tcompilerppufile);override;
  376. end;
  377. { Generates an extended float (80 bit real) }
  378. tai_real_80bit = class(tai)
  379. value : ts80real;
  380. constructor Create(_value : ts80real);
  381. constructor ppuload(t:taitype;ppufile:tcompilerppufile);override;
  382. procedure ppuwrite(ppufile:tcompilerppufile);override;
  383. end;
  384. { Generates an float128 (128 bit real) }
  385. tai_real_128bit = class(tai)
  386. value : ts128real;
  387. constructor Create(_value : ts128real);
  388. constructor ppuload(t:taitype;ppufile:tcompilerppufile);override;
  389. procedure ppuwrite(ppufile:tcompilerppufile);override;
  390. end;
  391. { Generates a comp int (integer over 64 bits)
  392. This is Intel 80x86 specific, and is not
  393. really supported on other processors.
  394. }
  395. tai_comp_64bit = class(tai)
  396. value : ts64comp;
  397. constructor Create(_value : ts64comp);
  398. constructor ppuload(t:taitype;ppufile:tcompilerppufile);override;
  399. procedure ppuwrite(ppufile:tcompilerppufile);override;
  400. end;
  401. { Insert a cut to split assembler into several smaller files }
  402. tai_cutobject = class(tai)
  403. place : tcutplace;
  404. constructor Create;
  405. constructor Create_begin;
  406. constructor Create_end;
  407. constructor ppuload(t:taitype;ppufile:tcompilerppufile);override;
  408. procedure ppuwrite(ppufile:tcompilerppufile);override;
  409. end;
  410. { Insert a marker for assembler and inline blocks }
  411. tai_marker = class(tai)
  412. Kind: TMarker;
  413. Constructor Create(_Kind: TMarker);
  414. constructor ppuload(t:taitype;ppufile:tcompilerppufile);override;
  415. procedure ppuwrite(ppufile:tcompilerppufile);override;
  416. end;
  417. tai_tempalloc = class(tai)
  418. allocation : boolean;
  419. {$ifdef EXTDEBUG}
  420. problem : pstring;
  421. {$endif EXTDEBUG}
  422. temppos,
  423. tempsize : longint;
  424. constructor alloc(pos,size:longint);
  425. constructor dealloc(pos,size:longint);
  426. {$ifdef EXTDEBUG}
  427. constructor allocinfo(pos,size:longint;const st:string);
  428. {$endif EXTDEBUG}
  429. constructor ppuload(t:taitype;ppufile:tcompilerppufile);override;
  430. destructor destroy;override;
  431. procedure ppuwrite(ppufile:tcompilerppufile);override;
  432. end;
  433. tai_regalloc = class(tai)
  434. reg : tregister;
  435. ratype : TRegAllocType;
  436. { reg(de)alloc belongs to this instruction, this
  437. is only used for automatic inserted (de)alloc for
  438. imaginary register and required for spilling code }
  439. instr : tai;
  440. constructor alloc(r : tregister;ainstr:tai);
  441. constructor dealloc(r : tregister;ainstr:tai);
  442. constructor sync(r : tregister);
  443. constructor resize(r : tregister);
  444. constructor ppuload(t:taitype;ppufile:tcompilerppufile);override;
  445. procedure ppuwrite(ppufile:tcompilerppufile);override;
  446. end;
  447. Taasmoutput=class;
  448. tadd_reg_instruction_proc=procedure(instr:Tai;r:tregister) of object;
  449. Trggetproc=procedure(list:Taasmoutput;position:Tai;subreg:Tsubregister;var result:Tregister) of object;
  450. Trgungetproc=procedure(list:Taasmoutput;position:Tai;r:Tregister) of object;
  451. { Class template for assembler instructions
  452. }
  453. tai_cpu_abstract = class(tailineinfo)
  454. protected
  455. procedure ppuloadoper(ppufile:tcompilerppufile;var o:toper);virtual;abstract;
  456. procedure ppuwriteoper(ppufile:tcompilerppufile;const o:toper);virtual;abstract;
  457. procedure ppubuildderefimploper(var o:toper);virtual;abstract;
  458. procedure ppuderefoper(var o:toper);virtual;abstract;
  459. public
  460. { Condition flags for instruction }
  461. condition : TAsmCond;
  462. { Number of operands to instruction }
  463. ops : byte;
  464. { Number of allocate oper structures }
  465. opercnt : byte;
  466. { Operands of instruction }
  467. oper : array[0..max_operands-1] of poper;
  468. { Actual opcode of instruction }
  469. opcode : tasmop;
  470. {$ifdef x86}
  471. segprefix : tregister;
  472. {$endif x86}
  473. { true if instruction is a jmp }
  474. is_jmp : boolean; { is this instruction a jump? (needed for optimizer) }
  475. Constructor Create(op : tasmop);virtual;
  476. Destructor Destroy;override;
  477. function getcopy:TLinkedListItem;override;
  478. constructor ppuload(t:taitype;ppufile:tcompilerppufile);override;
  479. procedure ppuwrite(ppufile:tcompilerppufile);override;
  480. procedure buildderefimpl;override;
  481. procedure derefimpl;override;
  482. procedure SetCondition(const c:TAsmCond);
  483. procedure allocate_oper(opers:longint);
  484. procedure loadconst(opidx:longint;l:aint);
  485. procedure loadsymbol(opidx:longint;s:tasmsymbol;sofs:longint);
  486. procedure loadlocal(opidx:longint;s:pointer;sofs:longint;indexreg:tregister;scale:byte;getoffset,forceref:boolean);
  487. procedure loadref(opidx:longint;const r:treference);
  488. procedure loadreg(opidx:longint;r:tregister);
  489. procedure loadoper(opidx:longint;o:toper);
  490. procedure clearop(opidx:longint);
  491. { register allocator }
  492. function is_same_reg_move(regtype: Tregistertype):boolean;virtual;
  493. function spilling_get_operation_type(opnr: longint): topertype;virtual;
  494. function spilling_get_operation_type_ref(opnr: longint; reg: tregister): 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. {$ifdef extdebug}
  1555. if (cs_create_pic in aktmoduleswitches) and
  1556. assigned(r.symbol) and
  1557. (r.refaddr=addr_no) then
  1558. internalerror(200502052);
  1559. {$endif}
  1560. typ:=top_ref;
  1561. if assigned(add_reg_instruction_hook) then
  1562. begin
  1563. add_reg_instruction_hook(self,ref^.base);
  1564. add_reg_instruction_hook(self,ref^.index);
  1565. end;
  1566. { mark symbol as used }
  1567. if assigned(ref^.symbol) then
  1568. ref^.symbol.increfs;
  1569. end;
  1570. end;
  1571. procedure tai_cpu_abstract.loadreg(opidx:longint;r:tregister);
  1572. begin
  1573. allocate_oper(opidx+1);
  1574. with oper[opidx]^ do
  1575. begin
  1576. if typ<>top_reg then
  1577. clearop(opidx);
  1578. reg:=r;
  1579. typ:=top_reg;
  1580. end;
  1581. if assigned(add_reg_instruction_hook) then
  1582. add_reg_instruction_hook(self,r);
  1583. {$ifdef ARM}
  1584. { R15 is the PC on the ARM thus moves to R15 are jumps.
  1585. Due to speed considerations we don't use a virtual overridden method here.
  1586. Because the pc/r15 isn't handled by the reg. allocator this should never cause
  1587. problems with iregs getting r15.
  1588. }
  1589. is_jmp:=(opcode=A_MOV) and (opidx=0) and (r=NR_R15);
  1590. {$endif ARM}
  1591. end;
  1592. procedure tai_cpu_abstract.loadoper(opidx:longint;o:toper);
  1593. begin
  1594. allocate_oper(opidx+1);
  1595. clearop(opidx);
  1596. oper[opidx]^:=o;
  1597. { copy also the reference }
  1598. with oper[opidx]^ do
  1599. begin
  1600. case typ of
  1601. top_reg:
  1602. begin
  1603. if assigned(add_reg_instruction_hook) then
  1604. add_reg_instruction_hook(self,reg);
  1605. end;
  1606. top_ref:
  1607. begin
  1608. new(ref);
  1609. ref^:=o.ref^;
  1610. if assigned(add_reg_instruction_hook) then
  1611. begin
  1612. add_reg_instruction_hook(self,ref^.base);
  1613. add_reg_instruction_hook(self,ref^.index);
  1614. end;
  1615. end;
  1616. {$ifdef ARM}
  1617. top_shifterop:
  1618. begin
  1619. new(shifterop);
  1620. shifterop^:=o.shifterop^;
  1621. if assigned(add_reg_instruction_hook) then
  1622. add_reg_instruction_hook(self,shifterop^.rs);
  1623. end;
  1624. {$endif ARM}
  1625. end;
  1626. end;
  1627. end;
  1628. procedure tai_cpu_abstract.clearop(opidx:longint);
  1629. begin
  1630. with oper[opidx]^ do
  1631. begin
  1632. case typ of
  1633. top_ref:
  1634. dispose(ref);
  1635. top_local:
  1636. dispose(localoper);
  1637. {$ifdef ARM}
  1638. top_shifterop:
  1639. dispose(shifterop);
  1640. top_regset:
  1641. dispose(regset);
  1642. {$endif ARM}
  1643. end;
  1644. typ:=top_none;
  1645. end;
  1646. end;
  1647. { ---------------------------------------------------------------------
  1648. Miscellaneous methods.
  1649. ---------------------------------------------------------------------}
  1650. procedure tai_cpu_abstract.SetCondition(const c:TAsmCond);
  1651. begin
  1652. condition:=c;
  1653. end;
  1654. Function tai_cpu_abstract.getcopy:TLinkedListItem;
  1655. var
  1656. i : longint;
  1657. p : tai_cpu_abstract;
  1658. begin
  1659. p:=tai_cpu_abstract(inherited getcopy);
  1660. { make a copy of the references }
  1661. p.opercnt:=0;
  1662. p.allocate_oper(ops);
  1663. for i:=0 to ops-1 do
  1664. begin
  1665. p.oper[i]^:=oper[i]^;
  1666. case oper[i]^.typ of
  1667. top_local :
  1668. begin
  1669. new(p.oper[i]^.localoper);
  1670. p.oper[i]^.localoper^:=oper[i]^.localoper^;
  1671. end;
  1672. top_ref :
  1673. begin
  1674. new(p.oper[i]^.ref);
  1675. p.oper[i]^.ref^:=oper[i]^.ref^;
  1676. end;
  1677. {$ifdef ARM}
  1678. top_shifterop:
  1679. begin
  1680. new(p.oper[i]^.shifterop);
  1681. p.oper[i]^.shifterop^:=oper[i]^.shifterop^;
  1682. end;
  1683. {$endif ARM}
  1684. end;
  1685. end;
  1686. getcopy:=p;
  1687. end;
  1688. function tai_cpu_abstract.is_same_reg_move(regtype: Tregistertype):boolean;
  1689. begin
  1690. { When the generic RA is used this needs to be overriden, we don't use
  1691. virtual;abstract; to prevent a lot of warnings of unimplemented abstract methods
  1692. when tai_cpu is created (PFV) }
  1693. internalerror(200404091);
  1694. end;
  1695. function tai_cpu_abstract.spilling_get_operation_type(opnr: longint): topertype;
  1696. begin
  1697. internalerror(200404091);
  1698. end;
  1699. function tai_cpu_abstract.spilling_get_operation_type_ref(opnr: longint; reg: tregister): topertype;
  1700. begin
  1701. result := operand_read;
  1702. end;
  1703. constructor tai_cpu_abstract.ppuload(t:taitype;ppufile:tcompilerppufile);
  1704. var
  1705. i : integer;
  1706. begin
  1707. inherited ppuload(t,ppufile);
  1708. { hopefully, we don't get problems with big/litte endian here when cross compiling :/ }
  1709. ppufile.getdata(condition,sizeof(tasmcond));
  1710. allocate_oper(ppufile.getbyte);
  1711. for i:=0 to ops-1 do
  1712. ppuloadoper(ppufile,oper[i]^);
  1713. opcode:=tasmop(ppufile.getword);
  1714. {$ifdef x86}
  1715. ppufile.getdata(segprefix,sizeof(Tregister));
  1716. {$endif x86}
  1717. is_jmp:=boolean(ppufile.getbyte);
  1718. end;
  1719. procedure tai_cpu_abstract.ppuwrite(ppufile:tcompilerppufile);
  1720. var
  1721. i : integer;
  1722. begin
  1723. inherited ppuwrite(ppufile);
  1724. ppufile.putdata(condition,sizeof(tasmcond));
  1725. ppufile.putbyte(ops);
  1726. for i:=0 to ops-1 do
  1727. ppuwriteoper(ppufile,oper[i]^);
  1728. ppufile.putword(word(opcode));
  1729. {$ifdef x86}
  1730. ppufile.putdata(segprefix,sizeof(Tregister));
  1731. {$endif x86}
  1732. ppufile.putbyte(byte(is_jmp));
  1733. end;
  1734. procedure tai_cpu_abstract.buildderefimpl;
  1735. var
  1736. i : integer;
  1737. begin
  1738. for i:=0 to ops-1 do
  1739. ppubuildderefimploper(oper[i]^);
  1740. end;
  1741. procedure tai_cpu_abstract.derefimpl;
  1742. var
  1743. i : integer;
  1744. begin
  1745. for i:=0 to ops-1 do
  1746. ppuderefoper(oper[i]^);
  1747. end;
  1748. {****************************************************************************
  1749. tai_align_abstract
  1750. ****************************************************************************}
  1751. constructor tai_align_abstract.Create(b: byte);
  1752. begin
  1753. inherited Create;
  1754. typ:=ait_align;
  1755. if b in [1,2,4,8,16,32] then
  1756. aligntype := b
  1757. else
  1758. aligntype := 1;
  1759. fillsize:=0;
  1760. fillop:=0;
  1761. use_op:=false;
  1762. end;
  1763. constructor tai_align_abstract.Create_op(b: byte; _op: byte);
  1764. begin
  1765. inherited Create;
  1766. typ:=ait_align;
  1767. if b in [1,2,4,8,16,32] then
  1768. aligntype := b
  1769. else
  1770. aligntype := 1;
  1771. fillsize:=0;
  1772. fillop:=_op;
  1773. use_op:=true;
  1774. end;
  1775. constructor tai_align_abstract.Create_zeros(b: byte);
  1776. begin
  1777. inherited Create;
  1778. typ:=ait_align;
  1779. if b in [1,2,4,8,16,32] then
  1780. aligntype := b
  1781. else
  1782. aligntype := 1;
  1783. use_op:=true;
  1784. fillsize:=0;
  1785. fillop:=0;
  1786. end;
  1787. function tai_align_abstract.calculatefillbuf(var buf : tfillbuffer):pchar;
  1788. begin
  1789. if fillsize>sizeof(buf) then
  1790. internalerror(200404293);
  1791. fillchar(buf,high(buf),fillop);
  1792. calculatefillbuf:=pchar(@buf);
  1793. end;
  1794. constructor tai_align_abstract.ppuload(t:taitype;ppufile:tcompilerppufile);
  1795. begin
  1796. inherited ppuload(t,ppufile);
  1797. aligntype:=ppufile.getbyte;
  1798. fillsize:=0;
  1799. fillop:=ppufile.getbyte;
  1800. use_op:=boolean(ppufile.getbyte);
  1801. end;
  1802. procedure tai_align_abstract.ppuwrite(ppufile:tcompilerppufile);
  1803. begin
  1804. inherited ppuwrite(ppufile);
  1805. ppufile.putbyte(aligntype);
  1806. ppufile.putbyte(fillop);
  1807. ppufile.putbyte(byte(use_op));
  1808. end;
  1809. {*****************************************************************************
  1810. TAAsmOutput
  1811. *****************************************************************************}
  1812. constructor taasmoutput.create;
  1813. begin
  1814. inherited create;
  1815. { make sure the optimizer won't remove the first tai of this list}
  1816. insert(tai_marker.create(marker_blockstart));
  1817. end;
  1818. function taasmoutput.empty : boolean;
  1819. begin
  1820. { there is always a marker_blockstart available,
  1821. see taasmoutput.create }
  1822. result:=(count<=1);
  1823. end;
  1824. function taasmoutput.getlasttaifilepos : pfileposinfo;
  1825. var
  1826. hp : tlinkedlistitem;
  1827. begin
  1828. getlasttaifilepos := nil;
  1829. if assigned(last) then
  1830. begin
  1831. { find the last file information record }
  1832. if not (tai(last).typ in SkipLineInfo) then
  1833. getlasttaifilepos:=@tailineinfo(last).fileinfo
  1834. else
  1835. { go through list backwards to find the first entry
  1836. with line information
  1837. }
  1838. begin
  1839. hp:=tai(last);
  1840. while assigned(hp) and (tai(hp).typ in SkipLineInfo) do
  1841. hp:=hp.Previous;
  1842. { found entry }
  1843. if assigned(hp) then
  1844. getlasttaifilepos:=@tailineinfo(hp).fileinfo
  1845. end;
  1846. end;
  1847. end;
  1848. procedure Taasmoutput.InsertAfter(Item,Loc : TLinkedListItem);
  1849. begin
  1850. { This is not possible because it is not sure that the
  1851. tai at Loc has taifileinfo as parent }
  1852. {if assigned(Loc) then
  1853. tailineinfo(Item).fileinfo:=tailineinfo(Loc).fileinfo;}
  1854. inherited InsertAfter(Item,Loc);
  1855. end;
  1856. begin
  1857. cai_cpu:=tai_cpu_abstract;
  1858. cai_align:=tai_align_abstract;
  1859. end.