aasmtai.pas 69 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371
  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. ait_const_64bit,
  47. ait_const_32bit,
  48. ait_const_16bit,
  49. ait_const_8bit,
  50. ait_const_symbol,
  51. { the following is only used by the win32 version of the compiler }
  52. { and only the GNU AS Win32 is able to write it }
  53. ait_const_rva,
  54. ait_real_32bit,
  55. ait_real_64bit,
  56. ait_real_80bit,
  57. ait_comp_64bit,
  58. ait_real_128bit,
  59. {$ifdef GDB}
  60. ait_stabn,
  61. ait_stabs,
  62. ait_force_line,
  63. ait_stab_function_name,
  64. {$endif GDB}
  65. {$ifdef alpha}
  66. { the follow is for the DEC Alpha }
  67. ait_frame,
  68. ait_ent,
  69. {$endif alpha}
  70. {$ifdef ia64}
  71. ait_bundle,
  72. ait_stop,
  73. {$endif ia64}
  74. {$ifdef m68k}
  75. ait_labeled_instruction,
  76. {$endif m68k}
  77. { used to split into tiny assembler files }
  78. ait_cut,
  79. ait_regalloc,
  80. ait_tempalloc,
  81. { used to mark assembler blocks and inlined functions }
  82. ait_marker,
  83. { special symbols for darwin pic code }
  84. ait_indirect_symbol,
  85. ait_non_lazy_symbol_pointer
  86. );
  87. const
  88. taitypestr : array[taitype] of string[14] = (
  89. '<none>',
  90. 'align',
  91. 'section',
  92. 'comment',
  93. 'direct',
  94. 'string',
  95. 'instruction',
  96. 'datablock',
  97. 'symbol',
  98. 'symbol_end',
  99. 'label',
  100. 'const_64bit',
  101. 'const_32bit',
  102. 'const_16bit',
  103. 'const_8bit',
  104. 'const_symbol',
  105. 'const_rva',
  106. 'real_32bit',
  107. 'real_64bit',
  108. 'real_80bit',
  109. 'comp_64bit',
  110. 'real_128bit',
  111. {$ifdef GDB}
  112. 'stabn',
  113. 'stabs',
  114. 'force_line',
  115. 'stab_funcname',
  116. {$endif GDB}
  117. {$ifdef alpha}
  118. { the follow is for the DEC Alpha }
  119. 'frame',
  120. 'ent',
  121. {$endif alpha}
  122. {$ifdef ia64}
  123. 'bundle',
  124. 'stop',
  125. {$endif ia64}
  126. {$ifdef m68k}
  127. 'labeled_instr',
  128. {$endif m68k}
  129. 'cut',
  130. 'regalloc',
  131. 'tempalloc',
  132. 'marker',
  133. 'indirect_symbol',
  134. 'non_lazy_symbol_pointer'
  135. );
  136. type
  137. { Types of operand }
  138. toptype=(top_none,top_reg,top_ref,top_const,top_bool,top_local,
  139. { ARM only }
  140. top_regset,
  141. top_shifterop,
  142. { m68k only }
  143. top_reglist);
  144. { kinds of operations that an instruction can perform on an operand }
  145. topertype = (operand_read,operand_write,operand_readwrite);
  146. tlocaloper = record
  147. localsym : pointer;
  148. localsymderef : tderef;
  149. localsymofs : longint;
  150. localindexreg : tregister;
  151. localscale : byte;
  152. localgetoffset : boolean
  153. end;
  154. plocaloper = ^tlocaloper;
  155. { please keep the size of this record <=12 bytes and keep it properly aligned }
  156. toper = record
  157. ot : longint;
  158. case typ : toptype of
  159. top_none : ();
  160. top_reg : (reg:tregister);
  161. top_ref : (ref:preference);
  162. top_const : (val:aword);
  163. top_bool : (b:boolean);
  164. { local varsym that will be inserted in pass_2 }
  165. top_local : (localoper:plocaloper);
  166. {$ifdef arm}
  167. top_regset : (regset:^tcpuregisterset);
  168. top_shifterop : (shifterop : pshifterop);
  169. {$endif arm}
  170. {$ifdef m68k}
  171. top_regset : (regset:^tcpuregisterset);
  172. {$endif m68k}
  173. end;
  174. poper=^toper;
  175. { ait_* types which don't result in executable code or which don't influence }
  176. { the way the program runs/behaves, but which may be encountered by the }
  177. { optimizer (= if it's sometimes added to the exprasm list). Update if you add }
  178. { a new ait type! }
  179. const
  180. SkipInstr = [ait_comment, ait_symbol,ait_section
  181. {$ifdef GDB}
  182. ,ait_stabs, ait_stabn, ait_stab_function_name, ait_force_line
  183. {$endif GDB}
  184. ,ait_regalloc, ait_tempalloc, ait_symbol_end];
  185. { ait_* types which do not have line information (and hence which are of type
  186. tai, otherwise, they are of type tailineinfo }
  187. SkipLineInfo =[ait_label,
  188. ait_regalloc,ait_tempalloc,
  189. {$ifdef GDB}
  190. ait_stabn,ait_stabs,ait_stab_function_name,
  191. {$endif GDB}
  192. ait_cut,ait_marker,ait_align,ait_section,ait_comment,
  193. ait_const_8bit,ait_const_16bit,ait_const_32bit,
  194. ait_real_32bit,ait_real_64bit,ait_real_80bit,ait_comp_64bit,ait_real_128bit,
  195. ait_non_lazy_symbol_pointer
  196. ];
  197. type
  198. { cut type, required for alphanumeric ordering of the assembler filenames }
  199. TCutPlace=(cut_normal,cut_begin,cut_end);
  200. TMarker = (NoPropInfoStart,NoPropInfoEnd,
  201. AsmBlockStart,AsmBlockEnd,
  202. InlineStart,InlineEnd,marker_blockstart,
  203. marker_position);
  204. { Buffer type used for alignment }
  205. tfillbuffer = array[0..63] of char;
  206. Tspill_temp_list=array[tsuperregister] of Treference;
  207. { abstract assembler item }
  208. tai = class(TLinkedListItem)
  209. {$ifndef NOOPT}
  210. { pointer to record with optimizer info about this tai object }
  211. optinfo : pointer;
  212. {$endif NOOPT}
  213. typ : taitype;
  214. constructor Create;
  215. constructor ppuload(t:taitype;ppufile:tcompilerppufile);virtual;
  216. procedure ppuwrite(ppufile:tcompilerppufile);virtual;
  217. procedure buildderefimpl;virtual;
  218. procedure derefimpl;virtual;
  219. end;
  220. { abstract assembler item with line information }
  221. tailineinfo = class(tai)
  222. fileinfo : tfileposinfo;
  223. constructor Create;
  224. constructor ppuload(t:taitype;ppufile:tcompilerppufile);override;
  225. procedure ppuwrite(ppufile:tcompilerppufile);override;
  226. end;
  227. tai_simple = class(tai)
  228. constructor create(_typ : taitype);
  229. end;
  230. taiclass = class of tai;
  231. taiclassarray = array[taitype] of taiclass;
  232. { Generates an assembler string }
  233. tai_string = class(tailineinfo)
  234. str : pchar;
  235. { extra len so the string can contain an \0 }
  236. len : longint;
  237. constructor Create(const _str : string);
  238. constructor Create_pchar(_str : pchar);
  239. constructor Create_length_pchar(_str : pchar;length : longint);
  240. destructor Destroy;override;
  241. constructor ppuload(t:taitype;ppufile:tcompilerppufile);override;
  242. procedure ppuwrite(ppufile:tcompilerppufile);override;
  243. function getcopy:tlinkedlistitem;override;
  244. end;
  245. { Generates a common label }
  246. tai_symbol = class(tailineinfo)
  247. is_global : boolean;
  248. sym : tasmsymbol;
  249. size : longint;
  250. constructor Create(_sym:tasmsymbol;siz:longint);
  251. constructor Create_Global(_sym:tasmsymbol;siz:longint);
  252. constructor Createname(const _name : string;_symtyp:Tasmsymtype;siz:longint);
  253. constructor Createname_global(const _name : string;_symtyp:Tasmsymtype;siz:longint);
  254. constructor ppuload(t:taitype;ppufile:tcompilerppufile);override;
  255. procedure ppuwrite(ppufile:tcompilerppufile);override;
  256. procedure derefimpl;override;
  257. end;
  258. tai_symbol_end = class(tailineinfo)
  259. sym : tasmsymbol;
  260. constructor Create(_sym:tasmsymbol);
  261. constructor Createname(const _name : string);
  262. constructor ppuload(t:taitype;ppufile:tcompilerppufile);override;
  263. procedure ppuwrite(ppufile:tcompilerppufile);override;
  264. procedure derefimpl;override;
  265. end;
  266. { Generates an assembler label }
  267. tai_label = class(tai)
  268. is_global : boolean;
  269. l : tasmlabel;
  270. constructor Create(_l : tasmlabel);
  271. constructor ppuload(t:taitype;ppufile:tcompilerppufile);override;
  272. procedure ppuwrite(ppufile:tcompilerppufile);override;
  273. procedure derefimpl;override;
  274. end;
  275. { Directly output data to final assembler file }
  276. tai_direct = class(tailineinfo)
  277. str : pchar;
  278. constructor Create(_str : pchar);
  279. destructor Destroy; override;
  280. constructor ppuload(t:taitype;ppufile:tcompilerppufile);override;
  281. procedure ppuwrite(ppufile:tcompilerppufile);override;
  282. function getcopy:tlinkedlistitem;override;
  283. end;
  284. { Generates an assembler comment }
  285. tai_comment = class(tai)
  286. str : pchar;
  287. constructor Create(_str : pchar);
  288. destructor Destroy; override;
  289. constructor ppuload(t:taitype;ppufile:tcompilerppufile);override;
  290. procedure ppuwrite(ppufile:tcompilerppufile);override;
  291. function getcopy:tlinkedlistitem;override;
  292. end;
  293. { Generates a section / segment directive }
  294. tai_section = class(tai)
  295. sec : TSection;
  296. constructor Create(s : TSection);
  297. constructor ppuload(t:taitype;ppufile:tcompilerppufile);override;
  298. procedure ppuwrite(ppufile:tcompilerppufile);override;
  299. end;
  300. { Generates an uninitializised data block }
  301. tai_datablock = class(tailineinfo)
  302. is_global : boolean;
  303. sym : tasmsymbol;
  304. size : longint;
  305. constructor Create(const _name : string;_size : longint);
  306. constructor Create_global(const _name : string;_size : longint);
  307. constructor ppuload(t:taitype;ppufile:tcompilerppufile);override;
  308. procedure ppuwrite(ppufile:tcompilerppufile);override;
  309. procedure derefimpl;override;
  310. end;
  311. { Generates an integer const }
  312. tai_const = class(tai)
  313. value : qword;
  314. constructor Create_ptr(_value : TConstPtrUInt);
  315. constructor Create_64bit(_value : qword);
  316. constructor Create_32bit(_value : cardinal);
  317. constructor Create_16bit(_value : word);
  318. constructor Create_8bit(_value : byte);
  319. constructor ppuload(t:taitype;ppufile:tcompilerppufile);override;
  320. procedure ppuwrite(ppufile:tcompilerppufile);override;
  321. end;
  322. tai_const_symbol = class(tailineinfo)
  323. sym : tasmsymbol;
  324. offset : aint;
  325. constructor Create(_sym:tasmsymbol);
  326. constructor Create_offset(_sym:tasmsymbol;ofs:aint);
  327. constructor Create_rva(_sym:tasmsymbol);
  328. constructor Create_indirect(_sym:tasmsymbol);
  329. constructor Createname(const name:string;_symtyp:Tasmsymtype;ofs:aint);
  330. constructor Createname_rva(const name:string);
  331. constructor ppuload(t:taitype;ppufile:tcompilerppufile);override;
  332. procedure ppuwrite(ppufile:tcompilerppufile);override;
  333. procedure derefimpl;override;
  334. function getcopy:tlinkedlistitem;override;
  335. end;
  336. { Generates a single float (32 bit real) }
  337. tai_real_32bit = class(tai)
  338. value : ts32real;
  339. constructor Create(_value : ts32real);
  340. constructor ppuload(t:taitype;ppufile:tcompilerppufile);override;
  341. procedure ppuwrite(ppufile:tcompilerppufile);override;
  342. end;
  343. tformatoptions = (fo_none,fo_hiloswapped);
  344. { Generates a double float (64 bit real) }
  345. tai_real_64bit = class(tai)
  346. value : ts64real;
  347. {$ifdef ARM}
  348. formatoptions : tformatoptions;
  349. constructor Create_hiloswapped(_value : ts64real);
  350. {$endif ARM}
  351. constructor Create(_value : ts64real);
  352. constructor ppuload(t:taitype;ppufile:tcompilerppufile);override;
  353. procedure ppuwrite(ppufile:tcompilerppufile);override;
  354. end;
  355. { Generates an extended float (80 bit real) }
  356. tai_real_80bit = class(tai)
  357. value : ts80real;
  358. constructor Create(_value : ts80real);
  359. constructor ppuload(t:taitype;ppufile:tcompilerppufile);override;
  360. procedure ppuwrite(ppufile:tcompilerppufile);override;
  361. end;
  362. { Generates an float128 (128 bit real) }
  363. tai_real_128bit = class(tai)
  364. value : ts128real;
  365. constructor Create(_value : ts128real);
  366. constructor ppuload(t:taitype;ppufile:tcompilerppufile);override;
  367. procedure ppuwrite(ppufile:tcompilerppufile);override;
  368. end;
  369. { Generates a comp int (integer over 64 bits)
  370. This is Intel 80x86 specific, and is not
  371. really supported on other processors.
  372. }
  373. tai_comp_64bit = class(tai)
  374. value : ts64comp;
  375. constructor Create(_value : ts64comp);
  376. constructor ppuload(t:taitype;ppufile:tcompilerppufile);override;
  377. procedure ppuwrite(ppufile:tcompilerppufile);override;
  378. end;
  379. { Insert a cut to split assembler into several smaller files }
  380. tai_cut = class(tai)
  381. place : tcutplace;
  382. constructor Create;
  383. constructor Create_begin;
  384. constructor Create_end;
  385. constructor ppuload(t:taitype;ppufile:tcompilerppufile);override;
  386. procedure ppuwrite(ppufile:tcompilerppufile);override;
  387. end;
  388. { Insert a marker for assembler and inline blocks }
  389. tai_marker = class(tai)
  390. Kind: TMarker;
  391. Constructor Create(_Kind: TMarker);
  392. constructor ppuload(t:taitype;ppufile:tcompilerppufile);override;
  393. procedure ppuwrite(ppufile:tcompilerppufile);override;
  394. end;
  395. tai_tempalloc = class(tai)
  396. allocation : boolean;
  397. {$ifdef EXTDEBUG}
  398. problem : pstring;
  399. {$endif EXTDEBUG}
  400. temppos,
  401. tempsize : longint;
  402. constructor alloc(pos,size:longint);
  403. constructor dealloc(pos,size:longint);
  404. {$ifdef EXTDEBUG}
  405. constructor allocinfo(pos,size:longint;const st:string);
  406. {$endif EXTDEBUG}
  407. constructor ppuload(t:taitype;ppufile:tcompilerppufile);override;
  408. destructor destroy;override;
  409. procedure ppuwrite(ppufile:tcompilerppufile);override;
  410. end;
  411. tai_regalloc = class(tai)
  412. allocation : boolean;
  413. reg : tregister;
  414. constructor alloc(r : tregister);
  415. constructor dealloc(r : tregister);
  416. constructor ppuload(t:taitype;ppufile:tcompilerppufile);override;
  417. procedure ppuwrite(ppufile:tcompilerppufile);override;
  418. end;
  419. Taasmoutput=class;
  420. tadd_reg_instruction_proc=procedure(instr:Tai;r:tregister) of object;
  421. Trggetproc=procedure(list:Taasmoutput;position:Tai;subreg:Tsubregister;var result:Tregister) of object;
  422. Trgungetproc=procedure(list:Taasmoutput;position:Tai;r:Tregister) of object;
  423. { Class template for assembler instructions
  424. }
  425. taicpu_abstract = class(tailineinfo)
  426. protected
  427. procedure ppuloadoper(ppufile:tcompilerppufile;var o:toper);virtual;abstract;
  428. procedure ppuwriteoper(ppufile:tcompilerppufile;const o:toper);virtual;abstract;
  429. procedure ppubuildderefimploper(var o:toper);virtual;abstract;
  430. procedure ppuderefoper(var o:toper);virtual;abstract;
  431. public
  432. { Condition flags for instruction }
  433. condition : TAsmCond;
  434. { Number of operands to instruction }
  435. ops : byte;
  436. { Number of allocate oper structures }
  437. opercnt : byte;
  438. { Operands of instruction }
  439. oper : array[0..max_operands-1] of poper;
  440. { Actual opcode of instruction }
  441. opcode : tasmop;
  442. {$ifdef x86}
  443. segprefix : tregister;
  444. {$endif x86}
  445. { true if instruction is a jmp }
  446. is_jmp : boolean; { is this instruction a jump? (needed for optimizer) }
  447. Constructor Create(op : tasmop);
  448. Destructor Destroy;override;
  449. function getcopy:TLinkedListItem;override;
  450. constructor ppuload(t:taitype;ppufile:tcompilerppufile);override;
  451. procedure ppuwrite(ppufile:tcompilerppufile);override;
  452. procedure buildderefimpl;override;
  453. procedure derefimpl;override;
  454. procedure SetCondition(const c:TAsmCond);
  455. procedure allocate_oper(opers:longint);
  456. procedure loadconst(opidx:longint;l:aword);
  457. procedure loadsymbol(opidx:longint;s:tasmsymbol;sofs:longint);
  458. procedure loadlocal(opidx:longint;s:pointer;sofs:longint;indexreg:tregister;scale:byte;getoffset:boolean);
  459. procedure loadref(opidx:longint;const r:treference);
  460. procedure loadreg(opidx:longint;r:tregister);
  461. procedure loadoper(opidx:longint;o:toper);
  462. procedure clearop(opidx:longint);
  463. function is_same_reg_move(regtype: Tregistertype):boolean;virtual;abstract;
  464. { register allocator }
  465. function spilling_create_load(const ref:treference;r:tregister): tai;virtual;abstract;
  466. function spilling_create_store(r:tregister; const ref:treference): tai;virtual;abstract;
  467. function spilling_get_operation_type(opnr: longint): topertype;virtual;abstract;
  468. end;
  469. { alignment for operator }
  470. tai_align_abstract = class(tai)
  471. aligntype : byte; { 1 = no align, 2 = word align, 4 = dword align }
  472. fillsize : byte; { real size to fill }
  473. fillop : byte; { value to fill with - optional }
  474. use_op : boolean;
  475. constructor Create(b:byte);
  476. constructor Create_op(b: byte; _op: byte);
  477. constructor ppuload(t:taitype;ppufile:tcompilerppufile);override;
  478. procedure ppuwrite(ppufile:tcompilerppufile);override;
  479. function calculatefillbuf(var buf : tfillbuffer):pchar;virtual;
  480. end;
  481. taasmoutput = class(tlinkedlist)
  482. constructor create;
  483. function getlasttaifilepos : pfileposinfo;
  484. procedure InsertAfter(Item,Loc : TLinkedListItem);
  485. end;
  486. var
  487. { array with all class types for tais }
  488. aiclass : taiclassarray;
  489. { Current expression list }
  490. exprasmlist : taasmoutput;
  491. { labels for BREAK and CONTINUE }
  492. aktbreaklabel,aktcontinuelabel : tasmlabel;
  493. { label when the result is true or false }
  494. truelabel,falselabel : tasmlabel;
  495. { hook to notify uses of registers }
  496. add_reg_instruction_hook : tadd_reg_instruction_proc;
  497. { default lists }
  498. datasegment,codesegment,bsssegment,
  499. debuglist,withdebuglist,consts,
  500. importssection,exportssection,
  501. resourcesection,rttilist,
  502. { data used by pic code }
  503. picdata,
  504. resourcestringlist : taasmoutput;
  505. function ppuloadai(ppufile:tcompilerppufile):tai;
  506. procedure ppuwriteai(ppufile:tcompilerppufile;n:tai);
  507. implementation
  508. uses
  509. {$ifdef delphi}
  510. sysutils,
  511. {$else}
  512. strings,
  513. {$endif}
  514. verbose;
  515. const
  516. pputaimarker = 254;
  517. {****************************************************************************
  518. Helpers
  519. ****************************************************************************}
  520. function ppuloadai(ppufile:tcompilerppufile):tai;
  521. var
  522. b : byte;
  523. t : taitype;
  524. begin
  525. { marker }
  526. b:=ppufile.getbyte;
  527. if b<>pputaimarker then
  528. internalerror(200208181);
  529. { load nodetype }
  530. t:=taitype(ppufile.getbyte);
  531. if t<>ait_none then
  532. begin
  533. if t>high(taitype) then
  534. internalerror(200208182);
  535. if not assigned(aiclass[t]) then
  536. internalerror(200208183);
  537. {writeln('taiload: ',taitypestr[t]);}
  538. { generate tai of the correct class }
  539. ppuloadai:=aiclass[t].ppuload(t,ppufile);
  540. end
  541. else
  542. ppuloadai:=nil;
  543. end;
  544. procedure ppuwriteai(ppufile:tcompilerppufile;n:tai);
  545. begin
  546. { marker, read by ppuloadnode }
  547. ppufile.putbyte(pputaimarker);
  548. if assigned(n) then
  549. begin
  550. { type, read by ppuloadnode }
  551. ppufile.putbyte(byte(n.typ));
  552. {writeln('taiwrite: ',taitypestr[n.typ]);}
  553. n.ppuwrite(ppufile);
  554. end
  555. else
  556. ppufile.putbyte(byte(ait_none));
  557. end;
  558. {****************************************************************************
  559. TAI
  560. ****************************************************************************}
  561. constructor tai.Create;
  562. begin
  563. {$ifndef NOOPT}
  564. optinfo:=nil;
  565. {$endif NOOPT}
  566. end;
  567. constructor tai.ppuload(t:taitype;ppufile:tcompilerppufile);
  568. begin
  569. typ:=t;
  570. {$ifndef NOOPT}
  571. optinfo:=nil;
  572. {$endif}
  573. end;
  574. procedure tai.ppuwrite(ppufile:tcompilerppufile);
  575. begin
  576. end;
  577. procedure tai.buildderefimpl;
  578. begin
  579. end;
  580. procedure tai.derefimpl;
  581. begin
  582. end;
  583. {****************************************************************************
  584. TAILINEINFO
  585. ****************************************************************************}
  586. constructor tailineinfo.create;
  587. begin
  588. inherited create;
  589. if (not inlining_procedure) and
  590. (cs_gdb_valgrind in aktglobalswitches) then
  591. fileinfo:=aktfilepos;
  592. end;
  593. constructor tailineinfo.ppuload(t:taitype;ppufile:tcompilerppufile);
  594. begin
  595. inherited ppuload(t,ppufile);
  596. ppufile.getposinfo(fileinfo);
  597. end;
  598. procedure tailineinfo.ppuwrite(ppufile:tcompilerppufile);
  599. begin
  600. inherited ppuwrite(ppufile);
  601. ppufile.putposinfo(fileinfo);
  602. end;
  603. {****************************************************************************
  604. TAI_SIMPLE
  605. ****************************************************************************}
  606. constructor tai_simple.create(_typ : taitype);
  607. begin
  608. inherited create;
  609. typ:=_typ;
  610. end;
  611. {****************************************************************************
  612. TAI_SECTION
  613. ****************************************************************************}
  614. constructor tai_section.Create(s : TSection);
  615. begin
  616. inherited Create;
  617. typ:=ait_section;
  618. sec:=s;
  619. end;
  620. constructor tai_section.ppuload(t:taitype;ppufile:tcompilerppufile);
  621. begin
  622. inherited ppuload(t,ppufile);
  623. sec:=tsection(ppufile.getbyte);
  624. end;
  625. procedure tai_section.ppuwrite(ppufile:tcompilerppufile);
  626. begin
  627. inherited ppuwrite(ppufile);
  628. ppufile.putbyte(byte(sec));
  629. end;
  630. {****************************************************************************
  631. TAI_DATABLOCK
  632. ****************************************************************************}
  633. constructor tai_datablock.Create(const _name : string;_size : longint);
  634. begin
  635. inherited Create;
  636. typ:=ait_datablock;
  637. sym:=objectlibrary.newasmsymbol(_name,AB_LOCAL,AT_DATA);
  638. { keep things aligned }
  639. if _size<=0 then
  640. _size:=4;
  641. size:=_size;
  642. is_global:=false;
  643. end;
  644. constructor tai_datablock.Create_global(const _name : string;_size : longint);
  645. begin
  646. inherited Create;
  647. typ:=ait_datablock;
  648. sym:=objectlibrary.newasmsymbol(_name,AB_GLOBAL,AT_DATA);
  649. { keep things aligned }
  650. if _size<=0 then
  651. _size:=4;
  652. size:=_size;
  653. is_global:=true;
  654. end;
  655. constructor tai_datablock.ppuload(t:taitype;ppufile:tcompilerppufile);
  656. begin
  657. inherited Create;
  658. sym:=ppufile.getasmsymbol;
  659. size:=ppufile.getlongint;
  660. is_global:=boolean(ppufile.getbyte);
  661. end;
  662. procedure tai_datablock.ppuwrite(ppufile:tcompilerppufile);
  663. begin
  664. inherited ppuwrite(ppufile);
  665. ppufile.putasmsymbol(sym);
  666. ppufile.putlongint(size);
  667. ppufile.putbyte(byte(is_global));
  668. end;
  669. procedure tai_datablock.derefimpl;
  670. begin
  671. objectlibrary.DerefAsmsymbol(sym);
  672. end;
  673. {****************************************************************************
  674. TAI_SYMBOL
  675. ****************************************************************************}
  676. constructor tai_symbol.Create(_sym:tasmsymbol;siz:longint);
  677. begin
  678. inherited Create;
  679. typ:=ait_symbol;
  680. sym:=_sym;
  681. size:=siz;
  682. sym.defbind:=AB_LOCAL;
  683. is_global:=false;
  684. end;
  685. constructor tai_symbol.Create_global(_sym:tasmsymbol;siz:longint);
  686. begin
  687. inherited Create;
  688. typ:=ait_symbol;
  689. sym:=_sym;
  690. size:=siz;
  691. sym.defbind:=AB_GLOBAL;
  692. is_global:=true;
  693. end;
  694. constructor tai_symbol.Createname(const _name : string;_symtyp:Tasmsymtype;siz:longint);
  695. begin
  696. inherited Create;
  697. typ:=ait_symbol;
  698. sym:=objectlibrary.newasmsymbol(_name,AB_LOCAL,_symtyp);
  699. size:=siz;
  700. is_global:=false;
  701. end;
  702. constructor tai_symbol.Createname_global(const _name : string;_symtyp:Tasmsymtype;siz:longint);
  703. begin
  704. inherited Create;
  705. typ:=ait_symbol;
  706. sym:=objectlibrary.newasmsymbol(_name,AB_GLOBAL,_symtyp);
  707. size:=siz;
  708. is_global:=true;
  709. end;
  710. constructor tai_symbol.ppuload(t:taitype;ppufile:tcompilerppufile);
  711. begin
  712. inherited ppuload(t,ppufile);
  713. sym:=ppufile.getasmsymbol;
  714. size:=ppufile.getlongint;
  715. is_global:=boolean(ppufile.getbyte);
  716. end;
  717. procedure tai_symbol.ppuwrite(ppufile:tcompilerppufile);
  718. begin
  719. inherited ppuwrite(ppufile);
  720. ppufile.putasmsymbol(sym);
  721. ppufile.putlongint(size);
  722. ppufile.putbyte(byte(is_global));
  723. end;
  724. procedure tai_symbol.derefimpl;
  725. begin
  726. objectlibrary.DerefAsmsymbol(sym);
  727. end;
  728. {****************************************************************************
  729. TAI_SYMBOL_END
  730. ****************************************************************************}
  731. constructor tai_symbol_end.Create(_sym:tasmsymbol);
  732. begin
  733. inherited Create;
  734. typ:=ait_symbol_end;
  735. sym:=_sym;
  736. end;
  737. constructor tai_symbol_end.Createname(const _name : string);
  738. begin
  739. inherited Create;
  740. typ:=ait_symbol_end;
  741. sym:=objectlibrary.newasmsymbol(_name,AB_GLOBAL,AT_NONE);
  742. end;
  743. constructor tai_symbol_end.ppuload(t:taitype;ppufile:tcompilerppufile);
  744. begin
  745. inherited ppuload(t,ppufile);
  746. sym:=ppufile.getasmsymbol;
  747. end;
  748. procedure tai_symbol_end.ppuwrite(ppufile:tcompilerppufile);
  749. begin
  750. inherited ppuwrite(ppufile);
  751. ppufile.putasmsymbol(sym);
  752. end;
  753. procedure tai_symbol_end.derefimpl;
  754. begin
  755. objectlibrary.DerefAsmsymbol(sym);
  756. end;
  757. {****************************************************************************
  758. TAI_CONST
  759. ****************************************************************************}
  760. constructor tai_const.Create_ptr(_value : TConstPtrUInt);
  761. begin
  762. {$ifdef cpu64bit}
  763. self.create_64bit(_value);
  764. {$else cpu64bit}
  765. self.create_32bit(_value);
  766. {$endif cpu64bit}
  767. end;
  768. constructor tai_const.Create_64bit(_value : qword);
  769. begin
  770. inherited Create;
  771. typ:=ait_const_64bit;
  772. value:=_value;
  773. end;
  774. constructor tai_const.Create_32bit(_value : cardinal);
  775. begin
  776. inherited Create;
  777. typ:=ait_const_32bit;
  778. value:=_value;
  779. end;
  780. constructor tai_const.Create_16bit(_value : word);
  781. begin
  782. inherited Create;
  783. typ:=ait_const_16bit;
  784. value:=_value;
  785. end;
  786. constructor tai_const.Create_8bit(_value : byte);
  787. begin
  788. inherited Create;
  789. typ:=ait_const_8bit;
  790. value:=_value;
  791. end;
  792. constructor tai_const.ppuload(t:taitype;ppufile:tcompilerppufile);
  793. begin
  794. inherited ppuload(t,ppufile);
  795. value:=ppufile.getlongint;
  796. end;
  797. procedure tai_const.ppuwrite(ppufile:tcompilerppufile);
  798. begin
  799. inherited ppuwrite(ppufile);
  800. ppufile.putlongint(value);
  801. end;
  802. {****************************************************************************
  803. TAI_CONST_SYMBOL
  804. ****************************************************************************}
  805. constructor tai_const_symbol.Create(_sym:tasmsymbol);
  806. begin
  807. inherited Create;
  808. typ:=ait_const_symbol;
  809. sym:=_sym;
  810. offset:=0;
  811. { update sym info }
  812. sym.increfs;
  813. end;
  814. constructor tai_const_symbol.Create_offset(_sym:tasmsymbol;ofs:longint);
  815. begin
  816. inherited Create;
  817. typ:=ait_const_symbol;
  818. sym:=_sym;
  819. offset:=ofs;
  820. { update sym info }
  821. sym.increfs;
  822. end;
  823. constructor tai_const_symbol.Create_rva(_sym:tasmsymbol);
  824. begin
  825. inherited Create;
  826. typ:=ait_const_rva;
  827. sym:=_sym;
  828. offset:=0;
  829. { update sym info }
  830. sym.increfs;
  831. end;
  832. constructor tai_const_symbol.Create_indirect(_sym:tasmsymbol);
  833. begin
  834. inherited Create;
  835. typ:=ait_indirect_symbol;
  836. sym:=_sym;
  837. offset:=0;
  838. { update sym info }
  839. sym.increfs;
  840. end;
  841. constructor tai_const_symbol.Createname(const name:string;_symtyp:Tasmsymtype;ofs:longint);
  842. begin
  843. inherited Create;
  844. typ:=ait_const_symbol;
  845. sym:=objectlibrary.newasmsymbol(name,AB_EXTERNAL,_symtyp);
  846. offset:=ofs;
  847. { update sym info }
  848. sym.increfs;
  849. end;
  850. constructor tai_const_symbol.Createname_rva(const name:string);
  851. begin
  852. inherited Create;
  853. typ:=ait_const_rva;
  854. sym:=objectlibrary.newasmsymbol(name,AB_EXTERNAL,AT_FUNCTION);
  855. offset:=0;
  856. { update sym info }
  857. sym.increfs;
  858. end;
  859. constructor tai_const_symbol.ppuload(t:taitype;ppufile:tcompilerppufile);
  860. begin
  861. inherited ppuload(t,ppufile);
  862. sym:=ppufile.getasmsymbol;
  863. offset:=ppufile.getlongint;
  864. end;
  865. procedure tai_const_symbol.ppuwrite(ppufile:tcompilerppufile);
  866. begin
  867. inherited ppuwrite(ppufile);
  868. ppufile.putasmsymbol(sym);
  869. ppufile.putlongint(offset);
  870. end;
  871. procedure tai_const_symbol.derefimpl;
  872. begin
  873. objectlibrary.DerefAsmsymbol(sym);
  874. end;
  875. function tai_const_symbol.getcopy:tlinkedlistitem;
  876. begin
  877. getcopy:=inherited getcopy;
  878. { we need to increase the reference number }
  879. sym.increfs;
  880. end;
  881. {****************************************************************************
  882. TAI_real_32bit
  883. ****************************************************************************}
  884. constructor tai_real_32bit.Create(_value : ts32real);
  885. begin
  886. inherited Create;
  887. typ:=ait_real_32bit;
  888. value:=_value;
  889. end;
  890. constructor tai_real_32bit.ppuload(t:taitype;ppufile:tcompilerppufile);
  891. begin
  892. inherited ppuload(t,ppufile);
  893. value:=ppufile.getreal;
  894. end;
  895. procedure tai_real_32bit.ppuwrite(ppufile:tcompilerppufile);
  896. begin
  897. inherited ppuwrite(ppufile);
  898. ppufile.putreal(value);
  899. end;
  900. {****************************************************************************
  901. TAI_real_64bit
  902. ****************************************************************************}
  903. constructor tai_real_64bit.Create(_value : ts64real);
  904. begin
  905. inherited Create;
  906. typ:=ait_real_64bit;
  907. value:=_value;
  908. end;
  909. {$ifdef ARM}
  910. constructor tai_real_64bit.Create_hiloswapped(_value : ts64real);
  911. begin
  912. inherited Create;
  913. typ:=ait_real_64bit;
  914. value:=_value;
  915. formatoptions:=fo_hiloswapped;
  916. end;
  917. {$endif ARM}
  918. constructor tai_real_64bit.ppuload(t:taitype;ppufile:tcompilerppufile);
  919. begin
  920. inherited ppuload(t,ppufile);
  921. value:=ppufile.getreal;
  922. {$ifdef ARM}
  923. formatoptions:=tformatoptions(ppufile.getbyte);
  924. {$endif ARM}
  925. end;
  926. procedure tai_real_64bit.ppuwrite(ppufile:tcompilerppufile);
  927. begin
  928. inherited ppuwrite(ppufile);
  929. ppufile.putreal(value);
  930. {$ifdef ARM}
  931. ppufile.putbyte(byte(formatoptions));
  932. {$endif ARM}
  933. end;
  934. {****************************************************************************
  935. TAI_real_80bit
  936. ****************************************************************************}
  937. constructor tai_real_80bit.Create(_value : ts80real);
  938. begin
  939. inherited Create;
  940. typ:=ait_real_80bit;
  941. value:=_value;
  942. end;
  943. constructor tai_real_80bit.ppuload(t:taitype;ppufile:tcompilerppufile);
  944. begin
  945. inherited ppuload(t,ppufile);
  946. value:=ppufile.getreal;
  947. end;
  948. procedure tai_real_80bit.ppuwrite(ppufile:tcompilerppufile);
  949. begin
  950. inherited ppuwrite(ppufile);
  951. ppufile.putreal(value);
  952. end;
  953. {****************************************************************************
  954. TAI_real_80bit
  955. ****************************************************************************}
  956. constructor tai_real_128bit.Create(_value : ts128real);
  957. begin
  958. inherited Create;
  959. typ:=ait_real_128bit;
  960. value:=_value;
  961. end;
  962. constructor tai_real_128bit.ppuload(t:taitype;ppufile:tcompilerppufile);
  963. begin
  964. inherited ppuload(t,ppufile);
  965. value:=ppufile.getreal;
  966. end;
  967. procedure tai_real_128bit.ppuwrite(ppufile:tcompilerppufile);
  968. begin
  969. inherited ppuwrite(ppufile);
  970. ppufile.putreal(value);
  971. end;
  972. {****************************************************************************
  973. Tai_comp_64bit
  974. ****************************************************************************}
  975. constructor tai_comp_64bit.Create(_value : ts64comp);
  976. begin
  977. inherited Create;
  978. typ:=ait_comp_64bit;
  979. value:=_value;
  980. end;
  981. constructor tai_comp_64bit.ppuload(t:taitype;ppufile:tcompilerppufile);
  982. begin
  983. inherited ppuload(t,ppufile);
  984. ppufile.putdata(value,sizeof(value));
  985. end;
  986. procedure tai_comp_64bit.ppuwrite(ppufile:tcompilerppufile);
  987. begin
  988. inherited ppuwrite(ppufile);
  989. ppufile.getdata(value,sizeof(value));
  990. end;
  991. {****************************************************************************
  992. TAI_STRING
  993. ****************************************************************************}
  994. constructor tai_string.Create(const _str : string);
  995. begin
  996. inherited Create;
  997. typ:=ait_string;
  998. len:=length(_str);
  999. getmem(str,len+1);
  1000. strpcopy(str,_str);
  1001. end;
  1002. constructor tai_string.Create_pchar(_str : pchar);
  1003. begin
  1004. inherited Create;
  1005. typ:=ait_string;
  1006. str:=_str;
  1007. len:=strlen(_str);
  1008. end;
  1009. constructor tai_string.Create_length_pchar(_str : pchar;length : longint);
  1010. begin
  1011. inherited Create;
  1012. typ:=ait_string;
  1013. str:=_str;
  1014. len:=length;
  1015. end;
  1016. destructor tai_string.destroy;
  1017. begin
  1018. { you can have #0 inside the strings so }
  1019. if str<>nil then
  1020. freemem(str,len+1);
  1021. inherited Destroy;
  1022. end;
  1023. constructor tai_string.ppuload(t:taitype;ppufile:tcompilerppufile);
  1024. begin
  1025. inherited ppuload(t,ppufile);
  1026. len:=ppufile.getlongint;
  1027. getmem(str,len+1);
  1028. ppufile.getdata(str^,len);
  1029. str[len]:=#0;
  1030. end;
  1031. procedure tai_string.ppuwrite(ppufile:tcompilerppufile);
  1032. begin
  1033. inherited ppuwrite(ppufile);
  1034. ppufile.putlongint(len);
  1035. ppufile.putdata(str^,len);
  1036. end;
  1037. function tai_string.getcopy : tlinkedlistitem;
  1038. var
  1039. p : tlinkedlistitem;
  1040. begin
  1041. p:=inherited getcopy;
  1042. getmem(tai_string(p).str,len+1);
  1043. move(str^,tai_string(p).str^,len+1);
  1044. getcopy:=p;
  1045. end;
  1046. {****************************************************************************
  1047. TAI_LABEL
  1048. ****************************************************************************}
  1049. constructor tai_label.create(_l : tasmlabel);
  1050. begin
  1051. inherited Create;
  1052. typ:=ait_label;
  1053. l:=_l;
  1054. l.is_set:=true;
  1055. is_global:=(l.defbind=AB_GLOBAL);
  1056. end;
  1057. constructor tai_label.ppuload(t:taitype;ppufile:tcompilerppufile);
  1058. begin
  1059. inherited ppuload(t,ppufile);
  1060. l:=tasmlabel(ppufile.getasmsymbol);
  1061. is_global:=boolean(ppufile.getbyte);
  1062. end;
  1063. procedure tai_label.ppuwrite(ppufile:tcompilerppufile);
  1064. begin
  1065. inherited ppuwrite(ppufile);
  1066. ppufile.putasmsymbol(l);
  1067. ppufile.putbyte(byte(is_global));
  1068. end;
  1069. procedure tai_label.derefimpl;
  1070. begin
  1071. objectlibrary.DerefAsmsymbol(tasmsymbol(l));
  1072. l.is_set:=true;
  1073. end;
  1074. {****************************************************************************
  1075. TAI_DIRECT
  1076. ****************************************************************************}
  1077. constructor tai_direct.Create(_str : pchar);
  1078. begin
  1079. inherited Create;
  1080. typ:=ait_direct;
  1081. str:=_str;
  1082. end;
  1083. destructor tai_direct.destroy;
  1084. begin
  1085. strdispose(str);
  1086. inherited Destroy;
  1087. end;
  1088. constructor tai_direct.ppuload(t:taitype;ppufile:tcompilerppufile);
  1089. var
  1090. len : longint;
  1091. begin
  1092. inherited ppuload(t,ppufile);
  1093. len:=ppufile.getlongint;
  1094. getmem(str,len+1);
  1095. ppufile.getdata(str^,len);
  1096. str[len]:=#0;
  1097. end;
  1098. procedure tai_direct.ppuwrite(ppufile:tcompilerppufile);
  1099. var
  1100. len : longint;
  1101. begin
  1102. inherited ppuwrite(ppufile);
  1103. len:=strlen(str);
  1104. ppufile.putlongint(len);
  1105. ppufile.putdata(str^,len);
  1106. end;
  1107. function tai_direct.getcopy : tlinkedlistitem;
  1108. var
  1109. p : tlinkedlistitem;
  1110. begin
  1111. p:=inherited getcopy;
  1112. getmem(tai_direct(p).str,strlen(str)+1);
  1113. move(str^,tai_direct(p).str^,strlen(str)+1);
  1114. getcopy:=p;
  1115. end;
  1116. {****************************************************************************
  1117. tai_comment comment to be inserted in the assembler file
  1118. ****************************************************************************}
  1119. constructor tai_comment.Create(_str : pchar);
  1120. begin
  1121. inherited Create;
  1122. typ:=ait_comment;
  1123. str:=_str;
  1124. end;
  1125. destructor tai_comment.destroy;
  1126. begin
  1127. strdispose(str);
  1128. inherited Destroy;
  1129. end;
  1130. constructor tai_comment.ppuload(t:taitype;ppufile:tcompilerppufile);
  1131. var
  1132. len : longint;
  1133. begin
  1134. inherited ppuload(t,ppufile);
  1135. len:=ppufile.getlongint;
  1136. getmem(str,len+1);
  1137. ppufile.getdata(str^,len);
  1138. str[len]:=#0;
  1139. end;
  1140. procedure tai_comment.ppuwrite(ppufile:tcompilerppufile);
  1141. var
  1142. len : longint;
  1143. begin
  1144. inherited ppuwrite(ppufile);
  1145. len:=strlen(str);
  1146. ppufile.putlongint(len);
  1147. ppufile.putdata(str^,len);
  1148. end;
  1149. function tai_comment.getcopy : tlinkedlistitem;
  1150. var
  1151. p : tlinkedlistitem;
  1152. begin
  1153. p:=inherited getcopy;
  1154. getmem(tai_comment(p).str,strlen(str)+1);
  1155. move(str^,tai_comment(p).str^,strlen(str)+1);
  1156. getcopy:=p;
  1157. end;
  1158. {****************************************************************************
  1159. TAI_CUT
  1160. ****************************************************************************}
  1161. constructor tai_cut.Create;
  1162. begin
  1163. inherited Create;
  1164. typ:=ait_cut;
  1165. place:=cut_normal;
  1166. end;
  1167. constructor tai_cut.Create_begin;
  1168. begin
  1169. inherited Create;
  1170. typ:=ait_cut;
  1171. place:=cut_begin;
  1172. end;
  1173. constructor tai_cut.Create_end;
  1174. begin
  1175. inherited Create;
  1176. typ:=ait_cut;
  1177. place:=cut_end;
  1178. end;
  1179. constructor tai_cut.ppuload(t:taitype;ppufile:tcompilerppufile);
  1180. begin
  1181. inherited ppuload(t,ppufile);
  1182. place:=TCutPlace(ppufile.getbyte);
  1183. end;
  1184. procedure tai_cut.ppuwrite(ppufile:tcompilerppufile);
  1185. begin
  1186. inherited ppuwrite(ppufile);
  1187. ppufile.putbyte(byte(place));
  1188. end;
  1189. {****************************************************************************
  1190. Tai_Marker
  1191. ****************************************************************************}
  1192. constructor Tai_Marker.Create(_Kind: TMarker);
  1193. begin
  1194. Inherited Create;
  1195. typ := ait_marker;
  1196. Kind := _Kind;
  1197. end;
  1198. constructor Tai_Marker.ppuload(t:taitype;ppufile:tcompilerppufile);
  1199. begin
  1200. inherited ppuload(t,ppufile);
  1201. kind:=TMarker(ppufile.getbyte);
  1202. end;
  1203. procedure Tai_Marker.ppuwrite(ppufile:tcompilerppufile);
  1204. begin
  1205. inherited ppuwrite(ppufile);
  1206. ppufile.putbyte(byte(kind));
  1207. end;
  1208. {*****************************************************************************
  1209. tai_tempalloc
  1210. *****************************************************************************}
  1211. constructor tai_tempalloc.alloc(pos,size:longint);
  1212. begin
  1213. inherited Create;
  1214. typ:=ait_tempalloc;
  1215. allocation:=true;
  1216. temppos:=pos;
  1217. tempsize:=size;
  1218. {$ifdef EXTDEBUG}
  1219. problem:=nil;
  1220. {$endif EXTDEBUG}
  1221. end;
  1222. destructor tai_tempalloc.destroy;
  1223. begin
  1224. {$ifdef EXTDEBUG}
  1225. stringdispose(problem);
  1226. {$endif EXTDEBUG}
  1227. inherited destroy;
  1228. end;
  1229. constructor tai_tempalloc.dealloc(pos,size:longint);
  1230. begin
  1231. inherited Create;
  1232. typ:=ait_tempalloc;
  1233. allocation:=false;
  1234. temppos:=pos;
  1235. tempsize:=size;
  1236. {$ifdef EXTDEBUG}
  1237. problem:=nil;
  1238. {$endif EXTDEBUG}
  1239. end;
  1240. {$ifdef EXTDEBUG}
  1241. constructor tai_tempalloc.allocinfo(pos,size:longint;const st:string);
  1242. begin
  1243. inherited Create;
  1244. typ:=ait_tempalloc;
  1245. allocation:=false;
  1246. temppos:=pos;
  1247. tempsize:=size;
  1248. problem:=stringdup(st);
  1249. end;
  1250. {$endif EXTDEBUG}
  1251. constructor tai_tempalloc.ppuload(t:taitype;ppufile:tcompilerppufile);
  1252. begin
  1253. inherited ppuload(t,ppufile);
  1254. temppos:=ppufile.getlongint;
  1255. tempsize:=ppufile.getlongint;
  1256. allocation:=boolean(ppufile.getbyte);
  1257. {$ifdef EXTDEBUG}
  1258. problem:=nil;
  1259. {$endif EXTDEBUG}
  1260. end;
  1261. procedure tai_tempalloc.ppuwrite(ppufile:tcompilerppufile);
  1262. begin
  1263. inherited ppuwrite(ppufile);
  1264. ppufile.putlongint(temppos);
  1265. ppufile.putlongint(tempsize);
  1266. ppufile.putbyte(byte(allocation));
  1267. end;
  1268. {*****************************************************************************
  1269. tai_regalloc
  1270. *****************************************************************************}
  1271. constructor tai_regalloc.alloc(r : tregister);
  1272. begin
  1273. inherited create;
  1274. typ:=ait_regalloc;
  1275. allocation:=true;
  1276. reg:=r;
  1277. end;
  1278. constructor tai_regalloc.dealloc(r : tregister);
  1279. begin
  1280. inherited create;
  1281. typ:=ait_regalloc;
  1282. allocation:=false;
  1283. reg:=r;
  1284. end;
  1285. constructor tai_regalloc.ppuload(t:taitype;ppufile:tcompilerppufile);
  1286. begin
  1287. inherited ppuload(t,ppufile);
  1288. ppufile.getdata(reg,sizeof(Tregister));
  1289. allocation:=boolean(ppufile.getbyte);
  1290. end;
  1291. procedure tai_regalloc.ppuwrite(ppufile:tcompilerppufile);
  1292. begin
  1293. inherited ppuwrite(ppufile);
  1294. ppufile.putdata(reg,sizeof(Tregister));
  1295. ppufile.putbyte(byte(allocation));
  1296. end;
  1297. {*****************************************************************************
  1298. TaiInstruction
  1299. *****************************************************************************}
  1300. constructor taicpu_abstract.Create(op : tasmop);
  1301. begin
  1302. inherited create;
  1303. typ:=ait_instruction;
  1304. is_jmp:=false;
  1305. opcode:=op;
  1306. ops:=0;
  1307. fillchar(condition,sizeof(condition),0);
  1308. fillchar(oper,sizeof(oper),0);
  1309. end;
  1310. destructor taicpu_abstract.Destroy;
  1311. var
  1312. i : integer;
  1313. begin
  1314. for i:=0 to opercnt-1 do
  1315. begin
  1316. clearop(i);
  1317. dispose(oper[i]);
  1318. end;
  1319. inherited destroy;
  1320. end;
  1321. { ---------------------------------------------------------------------
  1322. Loading of operands.
  1323. ---------------------------------------------------------------------}
  1324. procedure taicpu_abstract.allocate_oper(opers:longint);
  1325. begin
  1326. while (opers>opercnt) do
  1327. begin
  1328. new(oper[opercnt]);
  1329. fillchar(oper[opercnt]^,sizeof(toper),0);
  1330. inc(opercnt);
  1331. end;
  1332. end;
  1333. procedure taicpu_abstract.loadconst(opidx:longint;l:aword);
  1334. begin
  1335. allocate_oper(opidx+1);
  1336. with oper[opidx]^ do
  1337. begin
  1338. if typ<>top_const then
  1339. clearop(opidx);
  1340. val:=l;
  1341. typ:=top_const;
  1342. end;
  1343. end;
  1344. procedure taicpu_abstract.loadsymbol(opidx:longint;s:tasmsymbol;sofs:longint);
  1345. var
  1346. r : treference;
  1347. begin
  1348. reference_reset_symbol(r,s,sofs);
  1349. r.refaddr:=addr_full;
  1350. loadref(opidx,r);
  1351. end;
  1352. procedure taicpu_abstract.loadlocal(opidx:longint;s:pointer;sofs:longint;indexreg:tregister;scale:byte;getoffset:boolean);
  1353. begin
  1354. if not assigned(s) then
  1355. internalerror(200204251);
  1356. allocate_oper(opidx+1);
  1357. with oper[opidx]^ do
  1358. begin
  1359. if typ<>top_local then
  1360. begin
  1361. clearop(opidx);
  1362. new(localoper);
  1363. end;
  1364. with oper[opidx]^.localoper^ do
  1365. begin
  1366. localsym:=s;
  1367. localsymofs:=sofs;
  1368. localindexreg:=indexreg;
  1369. localscale:=scale;
  1370. localgetoffset:=getoffset;
  1371. end;
  1372. typ:=top_local;
  1373. end;
  1374. end;
  1375. procedure taicpu_abstract.loadref(opidx:longint;const r:treference);
  1376. begin
  1377. allocate_oper(opidx+1);
  1378. with oper[opidx]^ do
  1379. begin
  1380. if typ<>top_ref then
  1381. begin
  1382. clearop(opidx);
  1383. new(ref);
  1384. end;
  1385. ref^:=r;
  1386. {$ifdef x86}
  1387. { We allow this exception for x86, since overloading this would be
  1388. too much of a a speed penalty}
  1389. if (ref^.segment<>NR_NO) and (ref^.segment<>NR_DS) then
  1390. segprefix:=ref^.segment;
  1391. {$endif}
  1392. typ:=top_ref;
  1393. if assigned(add_reg_instruction_hook) then
  1394. begin
  1395. add_reg_instruction_hook(self,ref^.base);
  1396. add_reg_instruction_hook(self,ref^.index);
  1397. end;
  1398. { mark symbol as used }
  1399. if assigned(ref^.symbol) then
  1400. ref^.symbol.increfs;
  1401. end;
  1402. end;
  1403. procedure taicpu_abstract.loadreg(opidx:longint;r:tregister);
  1404. begin
  1405. allocate_oper(opidx+1);
  1406. with oper[opidx]^ do
  1407. begin
  1408. if typ<>top_reg then
  1409. clearop(opidx);
  1410. reg:=r;
  1411. typ:=top_reg;
  1412. end;
  1413. if assigned(add_reg_instruction_hook) then
  1414. add_reg_instruction_hook(self,r);
  1415. {$ifdef ARM}
  1416. { R15 is the PC on the ARM thus moves to R15 are jumps.
  1417. Due to speed considerations we don't use a virtual overridden method here.
  1418. Because the pc/r15 isn't handled by the reg. allocator this should never cause
  1419. problems with iregs getting r15.
  1420. }
  1421. is_jmp:=(opcode=A_MOV) and (opidx=0) and (r=NR_R15);
  1422. {$endif ARM}
  1423. end;
  1424. procedure taicpu_abstract.loadoper(opidx:longint;o:toper);
  1425. begin
  1426. allocate_oper(opidx+1);
  1427. clearop(opidx);
  1428. oper[opidx]^:=o;
  1429. { copy also the reference }
  1430. with oper[opidx]^ do
  1431. begin
  1432. case typ of
  1433. top_reg:
  1434. begin
  1435. if assigned(add_reg_instruction_hook) then
  1436. add_reg_instruction_hook(self,reg);
  1437. end;
  1438. top_ref:
  1439. begin
  1440. new(ref);
  1441. ref^:=o.ref^;
  1442. if assigned(add_reg_instruction_hook) then
  1443. begin
  1444. add_reg_instruction_hook(self,ref^.base);
  1445. add_reg_instruction_hook(self,ref^.index);
  1446. end;
  1447. end;
  1448. {$ifdef ARM}
  1449. top_shifterop:
  1450. begin
  1451. new(shifterop);
  1452. shifterop^:=o.shifterop^;
  1453. if assigned(add_reg_instruction_hook) then
  1454. add_reg_instruction_hook(self,shifterop^.rs);
  1455. end;
  1456. {$endif ARM}
  1457. end;
  1458. end;
  1459. end;
  1460. procedure taicpu_abstract.clearop(opidx:longint);
  1461. begin
  1462. with oper[opidx]^ do
  1463. begin
  1464. case typ of
  1465. top_ref:
  1466. dispose(ref);
  1467. top_local:
  1468. dispose(localoper);
  1469. {$ifdef ARM}
  1470. top_shifterop:
  1471. dispose(shifterop);
  1472. top_regset:
  1473. dispose(regset);
  1474. {$endif ARM}
  1475. end;
  1476. typ:=top_none;
  1477. end;
  1478. end;
  1479. { ---------------------------------------------------------------------
  1480. Miscellaneous methods.
  1481. ---------------------------------------------------------------------}
  1482. procedure taicpu_abstract.SetCondition(const c:TAsmCond);
  1483. begin
  1484. condition:=c;
  1485. end;
  1486. Function taicpu_abstract.getcopy:TLinkedListItem;
  1487. var
  1488. i : longint;
  1489. p : taicpu_abstract;
  1490. begin
  1491. p:=taicpu_abstract(inherited getcopy);
  1492. { make a copy of the references }
  1493. p.opercnt:=0;
  1494. p.allocate_oper(ops);
  1495. for i:=0 to ops-1 do
  1496. begin
  1497. p.oper[i]^:=oper[i]^;
  1498. if (oper[i]^.typ=top_ref) then
  1499. begin
  1500. new(p.oper[i]^.ref);
  1501. p.oper[i]^.ref^:=oper[i]^.ref^;
  1502. end;
  1503. end;
  1504. getcopy:=p;
  1505. end;
  1506. constructor taicpu_abstract.ppuload(t:taitype;ppufile:tcompilerppufile);
  1507. var
  1508. i : integer;
  1509. begin
  1510. inherited ppuload(t,ppufile);
  1511. { hopefully, we don't get problems with big/litte endian here when cross compiling :/ }
  1512. ppufile.getdata(condition,sizeof(tasmcond));
  1513. allocate_oper(ppufile.getbyte);
  1514. for i:=0 to ops-1 do
  1515. ppuloadoper(ppufile,oper[i]^);
  1516. opcode:=tasmop(ppufile.getword);
  1517. {$ifdef x86}
  1518. ppufile.getdata(segprefix,sizeof(Tregister));
  1519. {$endif x86}
  1520. is_jmp:=boolean(ppufile.getbyte);
  1521. end;
  1522. procedure taicpu_abstract.ppuwrite(ppufile:tcompilerppufile);
  1523. var
  1524. i : integer;
  1525. begin
  1526. inherited ppuwrite(ppufile);
  1527. ppufile.putdata(condition,sizeof(tasmcond));
  1528. ppufile.putbyte(ops);
  1529. for i:=0 to ops-1 do
  1530. ppuwriteoper(ppufile,oper[i]^);
  1531. ppufile.putword(word(opcode));
  1532. {$ifdef x86}
  1533. ppufile.putdata(segprefix,sizeof(Tregister));
  1534. {$endif x86}
  1535. ppufile.putbyte(byte(is_jmp));
  1536. end;
  1537. procedure taicpu_abstract.buildderefimpl;
  1538. var
  1539. i : integer;
  1540. begin
  1541. for i:=0 to ops-1 do
  1542. ppubuildderefimploper(oper[i]^);
  1543. end;
  1544. procedure taicpu_abstract.derefimpl;
  1545. var
  1546. i : integer;
  1547. begin
  1548. for i:=0 to ops-1 do
  1549. ppuderefoper(oper[i]^);
  1550. end;
  1551. {****************************************************************************
  1552. tai_align_abstract
  1553. ****************************************************************************}
  1554. constructor tai_align_abstract.Create(b: byte);
  1555. begin
  1556. inherited Create;
  1557. typ:=ait_align;
  1558. if b in [1,2,4,8,16,32] then
  1559. aligntype := b
  1560. else
  1561. aligntype := 1;
  1562. fillsize:=0;
  1563. fillop:=0;
  1564. use_op:=false;
  1565. end;
  1566. constructor tai_align_abstract.Create_op(b: byte; _op: byte);
  1567. begin
  1568. inherited Create;
  1569. typ:=ait_align;
  1570. if b in [1,2,4,8,16,32] then
  1571. aligntype := b
  1572. else
  1573. aligntype := 1;
  1574. fillsize:=0;
  1575. fillop:=_op;
  1576. use_op:=true;
  1577. end;
  1578. function tai_align_abstract.calculatefillbuf(var buf : tfillbuffer):pchar;
  1579. begin
  1580. fillchar(buf,high(buf),fillop);
  1581. calculatefillbuf:=pchar(@buf);
  1582. end;
  1583. constructor tai_align_abstract.ppuload(t:taitype;ppufile:tcompilerppufile);
  1584. begin
  1585. inherited ppuload(t,ppufile);
  1586. aligntype:=ppufile.getbyte;
  1587. fillsize:=0;
  1588. fillop:=ppufile.getbyte;
  1589. use_op:=boolean(ppufile.getbyte);
  1590. end;
  1591. procedure tai_align_abstract.ppuwrite(ppufile:tcompilerppufile);
  1592. begin
  1593. inherited ppuwrite(ppufile);
  1594. ppufile.putbyte(aligntype);
  1595. ppufile.putbyte(fillop);
  1596. ppufile.putbyte(byte(use_op));
  1597. end;
  1598. {*****************************************************************************
  1599. TAAsmOutput
  1600. *****************************************************************************}
  1601. constructor taasmoutput.create;
  1602. begin
  1603. inherited create;
  1604. { make sure the optimizer won't remove the first tai of this list}
  1605. insert(tai_marker.create(marker_blockstart));
  1606. end;
  1607. function taasmoutput.getlasttaifilepos : pfileposinfo;
  1608. var
  1609. hp : tlinkedlistitem;
  1610. begin
  1611. getlasttaifilepos := nil;
  1612. if assigned(last) then
  1613. begin
  1614. { find the last file information record }
  1615. if not (tai(last).typ in SkipLineInfo) then
  1616. getlasttaifilepos:=@tailineinfo(last).fileinfo
  1617. else
  1618. { go through list backwards to find the first entry
  1619. with line information
  1620. }
  1621. begin
  1622. hp:=tai(last);
  1623. while assigned(hp) and (tai(hp).typ in SkipLineInfo) do
  1624. hp:=hp.Previous;
  1625. { found entry }
  1626. if assigned(hp) then
  1627. getlasttaifilepos:=@tailineinfo(hp).fileinfo
  1628. end;
  1629. end;
  1630. end;
  1631. procedure Taasmoutput.InsertAfter(Item,Loc : TLinkedListItem);
  1632. begin
  1633. { This is not possible because it is not sure that the
  1634. tai at Loc has taifileinfo as parent }
  1635. {if assigned(Loc) then
  1636. tailineinfo(Item).fileinfo:=tailineinfo(Loc).fileinfo;}
  1637. inherited InsertAfter(Item,Loc);
  1638. end;
  1639. end.
  1640. {
  1641. $Log$
  1642. Revision 1.78 2004-03-14 22:47:56 peter
  1643. * fix memleak with top_local
  1644. Revision 1.77 2004/03/14 20:10:56 peter
  1645. * disable some debuginfo info when valgrind support is used
  1646. Revision 1.76 2004/03/02 17:32:12 florian
  1647. * make cycle fixed
  1648. + pic support for darwin
  1649. + support of importing vars from shared libs on darwin implemented
  1650. Revision 1.75 2004/03/02 00:36:32 olle
  1651. * big transformation of Tai_[const_]Symbol.Create[data]name*
  1652. Revision 1.74 2004/02/27 12:13:15 daniel
  1653. - Removed troublesome writeln statement
  1654. Revision 1.73 2004/02/27 10:21:04 florian
  1655. * top_symbol killed
  1656. + refaddr to treference added
  1657. + refsymbol to treference added
  1658. * top_local stuff moved to an extra record to save memory
  1659. + aint introduced
  1660. * tppufile.get/putint64/aint implemented
  1661. Revision 1.72 2004/02/26 16:16:38 peter
  1662. * tai_const.create_ptr added
  1663. Revision 1.71 2004/02/08 23:10:21 jonas
  1664. * taicpu.is_same_reg_move() now gets a regtype parameter so it only
  1665. removes moves of that particular register type. This is necessary so
  1666. we don't remove the live_start instruction of a register before it
  1667. has been processed
  1668. Revision 1.70 2004/02/08 20:15:42 jonas
  1669. - removed taicpu.is_reg_move because it's not used anymore
  1670. + support tracking fpu register moves by rgobj for the ppc
  1671. Revision 1.69 2004/01/31 17:45:16 peter
  1672. * Change several $ifdef i386 to x86
  1673. * Change several OS_32 to OS_INT/OS_ADDR
  1674. Revision 1.68 2004/01/30 13:42:03 florian
  1675. * fixed more alignment issues
  1676. Revision 1.67 2004/01/26 16:12:27 daniel
  1677. * reginfo now also only allocated during register allocation
  1678. * third round of gdb cleanups: kick out most of concatstabto
  1679. Revision 1.66 2004/01/24 18:12:40 florian
  1680. * fixed several arm floating point issues
  1681. Revision 1.65 2004/01/23 15:12:49 florian
  1682. * fixed generic shl/shr operations
  1683. + added register allocation hook calls for arm specific operand types:
  1684. register set and shifter op
  1685. Revision 1.64 2004/01/12 16:37:59 peter
  1686. * moved spilling code from taicpu to rg
  1687. Revision 1.63 2003/12/28 16:20:09 jonas
  1688. - removed unused methods from old generic spilling code
  1689. Revision 1.62 2003/12/26 14:02:30 peter
  1690. * sparc updates
  1691. * use registertype in spill_register
  1692. Revision 1.61 2003/12/15 21:25:48 peter
  1693. * reg allocations for imaginary register are now inserted just
  1694. before reg allocation
  1695. * tregister changed to enum to allow compile time check
  1696. * fixed several tregister-tsuperregister errors
  1697. Revision 1.60 2003/12/14 20:24:28 daniel
  1698. * Register allocator speed optimizations
  1699. - Worklist no longer a ringbuffer
  1700. - No find operations are left
  1701. - Simplify now done in constant time
  1702. - unusedregs is now a Tsuperregisterworklist
  1703. - Microoptimizations
  1704. Revision 1.59 2003/12/08 22:34:24 peter
  1705. * tai_const.create_32bit changed to cardinal
  1706. Revision 1.58 2003/12/06 22:16:12 jonas
  1707. * completely overhauled and fixed generic spilling code. New method:
  1708. spilling_get_operation_type(operand_number): returns the operation
  1709. performed by the instruction on the operand: read/write/read+write.
  1710. See powerpc/aasmcpu.pas for an example
  1711. Revision 1.57 2003/12/03 17:39:04 florian
  1712. * fixed several arm calling conventions issues
  1713. * fixed reference reading in the assembler reader
  1714. * fixed a_loadaddr_ref_reg
  1715. Revision 1.55 2003/11/12 16:05:39 florian
  1716. * assembler readers OOPed
  1717. + typed currency constants
  1718. + typed 128 bit float constants if the CPU supports it
  1719. Revision 1.54 2003/11/07 15:58:32 florian
  1720. * Florian's culmutative nr. 1; contains:
  1721. - invalid calling conventions for a certain cpu are rejected
  1722. - arm softfloat calling conventions
  1723. - -Sp for cpu dependend code generation
  1724. - several arm fixes
  1725. - remaining code for value open array paras on heap
  1726. Revision 1.53 2003/10/30 19:59:00 peter
  1727. * support scalefactor for opr_local
  1728. * support reference with opr_local set, fixes tw2631
  1729. Revision 1.52 2003/10/29 21:06:39 jonas
  1730. * allow more than 3 args in the spilling routine
  1731. Revision 1.51 2003/10/29 15:40:20 peter
  1732. * support indexing and offset retrieval for locals
  1733. Revision 1.50 2003/10/29 14:42:14 mazen
  1734. * code reformatted
  1735. Revision 1.49 2003/10/29 14:05:45 mazen
  1736. * Splling function devided to sub functions to make it easy to understand.
  1737. This commit is just to allow easy diffs to validate the migration (hint use -w)
  1738. Revision 1.48 2003/10/24 17:39:41 peter
  1739. * asmnode.get_position now inserts a marker
  1740. Revision 1.47 2003/10/23 14:44:07 peter
  1741. * splitted buildderef and buildderefimpl to fix interface crc
  1742. calculation
  1743. Revision 1.46 2003/10/22 20:39:59 peter
  1744. * write derefdata in a separate ppu entry
  1745. Revision 1.45 2003/10/21 15:15:35 peter
  1746. * taicpu_abstract.oper[] changed to pointers
  1747. Revision 1.44 2003/10/17 14:38:32 peter
  1748. * 64k registers supported
  1749. * fixed some memory leaks
  1750. Revision 1.43 2003/10/11 16:06:42 florian
  1751. * fixed some MMX<->SSE
  1752. * started to fix ppc, needs an overhaul
  1753. + stabs info improve for spilling, not sure if it works correctly/completly
  1754. - MMX_SUPPORT removed from Makefile.fpc
  1755. Revision 1.42 2003/10/10 17:48:13 peter
  1756. * old trgobj moved to x86/rgcpu and renamed to trgx86fpu
  1757. * tregisteralloctor renamed to trgobj
  1758. * removed rgobj from a lot of units
  1759. * moved location_* and reference_* to cgobj
  1760. * first things for mmx register allocation
  1761. Revision 1.41 2003/10/01 20:34:48 peter
  1762. * procinfo unit contains tprocinfo
  1763. * cginfo renamed to cgbase
  1764. * moved cgmessage to verbose
  1765. * fixed ppc and sparc compiles
  1766. Revision 1.40 2003/09/23 17:56:05 peter
  1767. * locals and paras are allocated in the code generation
  1768. * tvarsym.localloc contains the location of para/local when
  1769. generating code for the current procedure
  1770. Revision 1.39 2003/09/07 22:09:34 peter
  1771. * preparations for different default calling conventions
  1772. * various RA fixes
  1773. Revision 1.38 2003/09/04 00:15:28 florian
  1774. * first bunch of adaptions of arm compiler for new register type
  1775. Revision 1.37 2003/09/03 15:55:00 peter
  1776. * NEWRA branch merged
  1777. Revision 1.36 2003/09/03 11:18:36 florian
  1778. * fixed arm concatcopy
  1779. + arm support in the common compiler sources added
  1780. * moved some generic cg code around
  1781. + tfputype added
  1782. * ...
  1783. Revision 1.35.2.5 2003/08/31 21:08:16 peter
  1784. * first batch of sparc fixes
  1785. Revision 1.35.2.4 2003/08/29 17:28:59 peter
  1786. * next batch of updates
  1787. Revision 1.35.2.3 2003/08/28 18:35:07 peter
  1788. * tregister changed to cardinal
  1789. Revision 1.35.2.2 2003/08/27 20:23:55 peter
  1790. * remove old ra code
  1791. Revision 1.35.2.1 2003/08/27 19:55:54 peter
  1792. * first tregister patch
  1793. Revision 1.35 2003/08/21 14:47:41 peter
  1794. * remove convert_registers
  1795. Revision 1.34 2003/08/20 20:29:06 daniel
  1796. * Some more R_NO changes
  1797. * Preventive code to loadref added
  1798. Revision 1.33 2003/08/17 20:47:47 daniel
  1799. * Notranslation changed into -sr functionality
  1800. Revision 1.32 2003/08/17 16:59:20 jonas
  1801. * fixed regvars so they work with newra (at least for ppc)
  1802. * fixed some volatile register bugs
  1803. + -dnotranslation option for -dnewra, which causes the registers not to
  1804. be translated from virtual to normal registers. Requires support in
  1805. the assembler writer as well, which is only implemented in aggas/
  1806. agppcgas currently
  1807. Revision 1.31 2003/08/11 21:18:20 peter
  1808. * start of sparc support for newra
  1809. Revision 1.30 2003/07/02 16:43:48 jonas
  1810. * always add dummy marker object at the start of an assembler list, so
  1811. the optimizer can't remove the first object
  1812. Revision 1.29 2003/06/03 13:01:59 daniel
  1813. * Register allocator finished
  1814. Revision 1.28 2003/05/12 18:13:57 peter
  1815. * create rtti label using newasmsymboldata and update binding
  1816. only when calling tai_symbol.create
  1817. * tai_symbol.create_global added
  1818. Revision 1.27 2003/04/25 20:59:33 peter
  1819. * removed funcretn,funcretsym, function result is now in varsym
  1820. and aliases for result and function name are added using absolutesym
  1821. * vs_hidden parameter for funcret passed in parameter
  1822. * vs_hidden fixes
  1823. * writenode changed to printnode and released from extdebug
  1824. * -vp option added to generate a tree.log with the nodetree
  1825. * nicer printnode for statements, callnode
  1826. Revision 1.26 2002/04/25 16:12:09 florian
  1827. * fixed more problems with cpubase and x86-64
  1828. Revision 1.25 2003/04/25 08:25:26 daniel
  1829. * Ifdefs around a lot of calls to cleartempgen
  1830. * Fixed registers that are allocated but not freed in several nodes
  1831. * Tweak to register allocator to cause less spills
  1832. * 8-bit registers now interfere with esi,edi and ebp
  1833. Compiler can now compile rtl successfully when using new register
  1834. allocator
  1835. Revision 1.24 2003/04/24 13:03:01 florian
  1836. * comp is now written with its bit pattern to the ppu instead as an extended
  1837. Revision 1.23 2003/04/22 14:33:38 peter
  1838. * removed some notes/hints
  1839. Revision 1.22 2003/04/22 10:09:34 daniel
  1840. + Implemented the actual register allocator
  1841. + Scratch registers unavailable when new register allocator used
  1842. + maybe_save/maybe_restore unavailable when new register allocator used
  1843. Revision 1.21 2003/02/19 22:00:14 daniel
  1844. * Code generator converted to new register notation
  1845. - Horribily outdated todo.txt removed
  1846. Revision 1.20 2003/01/30 21:46:20 peter
  1847. * tai_const_symbol.createdataname added
  1848. Revision 1.19 2003/01/21 08:48:08 daniel
  1849. * Another 200301081 fixed
  1850. Revision 1.18 2003/01/09 20:40:59 daniel
  1851. * Converted some code in cgx86.pas to new register numbering
  1852. Revision 1.17 2003/01/09 15:49:56 daniel
  1853. * Added register conversion
  1854. Revision 1.16 2003/01/08 18:43:56 daniel
  1855. * Tregister changed into a record
  1856. Revision 1.15 2003/01/05 13:36:53 florian
  1857. * x86-64 compiles
  1858. + very basic support for float128 type (x86-64 only)
  1859. Revision 1.14 2002/12/06 17:50:21 peter
  1860. * symbol count fix merged
  1861. Revision 1.13 2002/11/17 16:31:55 carl
  1862. * memory optimization (3-4%) : cleanup of tai fields,
  1863. cleanup of tdef and tsym fields.
  1864. * make it work for m68k
  1865. Revision 1.12 2002/11/15 16:29:30 peter
  1866. * made tasmsymbol.refs private (merged)
  1867. Revision 1.11 2002/11/15 01:58:45 peter
  1868. * merged changes from 1.0.7 up to 04-11
  1869. - -V option for generating bug report tracing
  1870. - more tracing for option parsing
  1871. - errors for cdecl and high()
  1872. - win32 import stabs
  1873. - win32 records<=8 are returned in eax:edx (turned off by default)
  1874. - heaptrc update
  1875. - more info for temp management in .s file with EXTDEBUG
  1876. Revision 1.10 2002/11/09 15:38:03 carl
  1877. + NOOPT removed the optinfo field
  1878. Revision 1.9 2002/10/05 12:43:23 carl
  1879. * fixes for Delphi 6 compilation
  1880. (warning : Some features do not work under Delphi)
  1881. Revision 1.8 2002/08/19 19:36:42 peter
  1882. * More fixes for cross unit inlining, all tnodes are now implemented
  1883. * Moved pocall_internconst to po_internconst because it is not a
  1884. calling type at all and it conflicted when inlining of these small
  1885. functions was requested
  1886. Revision 1.7 2002/08/18 20:06:23 peter
  1887. * inlining is now also allowed in interface
  1888. * renamed write/load to ppuwrite/ppuload
  1889. * tnode storing in ppu
  1890. * nld,ncon,nbas are already updated for storing in ppu
  1891. Revision 1.6 2002/08/16 05:21:09 florian
  1892. * powerpc compilation fix
  1893. Revision 1.5 2002/08/15 19:10:35 peter
  1894. * first things tai,tnode storing in ppu
  1895. Revision 1.4 2002/08/11 14:32:25 peter
  1896. * renamed current_library to objectlibrary
  1897. Revision 1.3 2002/08/11 13:24:10 peter
  1898. * saving of asmsymbols in ppu supported
  1899. * asmsymbollist global is removed and moved into a new class
  1900. tasmlibrarydata that will hold the info of a .a file which
  1901. corresponds with a single module. Added librarydata to tmodule
  1902. to keep the library info stored for the module. In the future the
  1903. objectfiles will also be stored to the tasmlibrarydata class
  1904. * all getlabel/newasmsymbol and friends are moved to the new class
  1905. Revision 1.2 2002/08/05 18:27:48 carl
  1906. + more more more documentation
  1907. + first version include/exclude (can't test though, not enough scratch for i386 :()...
  1908. Revision 1.1 2002/07/01 18:46:20 peter
  1909. * internal linker
  1910. * reorganized aasm layer
  1911. Revision 1.27 2002/05/18 13:34:04 peter
  1912. * readded missing revisions
  1913. Revision 1.25 2002/05/14 19:34:38 peter
  1914. * removed old logs and updated copyright year
  1915. Revision 1.24 2002/05/14 17:28:08 peter
  1916. * synchronized cpubase between powerpc and i386
  1917. * moved more tables from cpubase to cpuasm
  1918. * tai_align_abstract moved to tainst, cpuasm must define
  1919. the tai_align class now, which may be empty
  1920. Revision 1.23 2002/04/15 18:54:34 carl
  1921. - removed tcpuflags
  1922. Revision 1.22 2002/04/07 13:18:19 carl
  1923. + more documentation
  1924. Revision 1.21 2002/04/07 10:17:40 carl
  1925. - remove packenumfixed (requires version 1.0.2 or later to compile now!)
  1926. + changing some comments so its commented automatically
  1927. Revision 1.20 2002/03/24 19:04:31 carl
  1928. + patch for SPARC from Mazen NEIFER
  1929. }