aasmtai.pas 72 KB

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