aasmtai.pas 71 KB

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