aasmtai.pas 71 KB

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