aasmtai.pas 69 KB

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