aasmtai.pas 70 KB

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