aasmtai.pas 69 KB

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