aasmtai.pas 70 KB

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