cgobj.pas 94 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381
  1. {
  2. $Id$
  3. Copyright (c) 1998-2002 by Florian Klaempfl
  4. Member of the Free Pascal development team
  5. This unit implements the basic code generator object
  6. This program is free software; you can redistribute it and/or modify
  7. it under the terms of the GNU General Public License as published by
  8. the Free Software Foundation; either version 2 of the License, or
  9. (at your option) any later version.
  10. This program is distributed in the hope that it will be useful,
  11. but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. GNU General Public License for more details.
  14. You should have received a copy of the GNU General Public License
  15. along with this program; if not, write to the Free Software
  16. Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  17. ****************************************************************************
  18. }
  19. {# @abstract(Abstract code generator unit)
  20. Abstreact code generator unit. This contains the base class
  21. to implement for all new supported processors.
  22. WARNING: None of the routines implemented in these modules,
  23. or their descendants, should use the temp. allocator, as
  24. these routines may be called inside genentrycode, and the
  25. stack frame is already setup!
  26. }
  27. unit cgobj;
  28. {$i fpcdefs.inc}
  29. interface
  30. uses
  31. {$ifdef delphi}
  32. dmisc,
  33. {$endif}
  34. cclasses,
  35. cpubase,cpuinfo,cgbase,
  36. aasmbase,aasmtai,aasmcpu,
  37. symconst,symbase,symtype,symdef,symtable,rgobj
  38. ;
  39. type
  40. talignment = (AM_NATURAL,AM_NONE,AM_2BYTE,AM_4BYTE,AM_8BYTE);
  41. {# @abstract(Abstract code generator)
  42. This class implements an abstract instruction generator. Some of
  43. the methods of this class are generic, while others must
  44. be overriden for all new processors which will be supported
  45. by Free Pascal. For 32-bit processors, the base class
  46. sould be @link(tcg64f32) and not @var(tcg).
  47. }
  48. tcg = class
  49. public
  50. alignment : talignment;
  51. rg : array[tregistertype] of trgobj;
  52. t_times:cardinal;
  53. {************************************************}
  54. { basic routines }
  55. constructor create;
  56. {# Initialize the register allocators needed for the codegenerator.}
  57. procedure init_register_allocators;virtual;abstract;
  58. {# Clean up the register allocators needed for the codegenerator.}
  59. procedure done_register_allocators;virtual;abstract;
  60. {# Gets a register suitable to do integer operations on.}
  61. function getintregister(list:Taasmoutput;size:Tcgsize):Tregister;virtual;
  62. {# Gets a register suitable to do integer operations on.}
  63. function getaddressregister(list:Taasmoutput):Tregister;virtual;
  64. function getfpuregister(list:Taasmoutput;size:Tcgsize):Tregister;virtual;
  65. function getmmregister(list:Taasmoutput;size:Tcgsize):Tregister;virtual;
  66. function getflagregister(list:Taasmoutput;size:Tcgsize):Tregister;virtual;abstract;
  67. {Does the generic cg need SIMD registers, like getmmxregister? Or should
  68. the cpu specific child cg object have such a method?}
  69. procedure ungetregister(list:Taasmoutput;r:Tregister);virtual;
  70. procedure ungetreference(list:Taasmoutput;const r:Treference);virtual;
  71. procedure add_move_instruction(instr:Taicpu);virtual;
  72. function uses_registers(rt:Tregistertype):boolean;virtual;
  73. {# Get a specific register.}
  74. procedure getexplicitregister(list:Taasmoutput;r:Tregister);virtual;
  75. {# Get multiple registers specified.}
  76. procedure allocexplicitregisters(list:Taasmoutput;rt:Tregistertype;r:Tcpuregisterset);virtual;
  77. {# Free multiple registers specified.}
  78. procedure deallocexplicitregisters(list:Taasmoutput;rt:Tregistertype;r:Tcpuregisterset);virtual;
  79. procedure do_register_allocation(list:Taasmoutput;headertai:tai);virtual;
  80. function makeregsize(reg:Tregister;size:Tcgsize):Tregister;
  81. {# Returns the tcgsize corresponding with the size of reg.}
  82. class function reg_cgsize(const reg: tregister) : tcgsize; virtual;
  83. {# Emit a label to the instruction stream. }
  84. procedure a_label(list : taasmoutput;l : tasmlabel);virtual;
  85. {# Allocates register r by inserting a pai_realloc record }
  86. procedure a_reg_alloc(list : taasmoutput;r : tregister);
  87. {# Deallocates register r by inserting a pa_regdealloc record}
  88. procedure a_reg_dealloc(list : taasmoutput;r : tregister);
  89. {# Pass a parameter, which is located in a register, to a routine.
  90. This routine should push/send the parameter to the routine, as
  91. required by the specific processor ABI and routine modifiers.
  92. This must be overriden for each CPU target.
  93. @param(size size of the operand in the register)
  94. @param(r register source of the operand)
  95. @param(locpara where the parameter will be stored)
  96. }
  97. procedure a_param_reg(list : taasmoutput;size : tcgsize;r : tregister;const locpara : tparalocation);virtual;
  98. {# Pass a parameter, which is a constant, to a routine.
  99. A generic version is provided. This routine should
  100. be overriden for optimization purposes if the cpu
  101. permits directly sending this type of parameter.
  102. @param(size size of the operand in constant)
  103. @param(a value of constant to send)
  104. @param(locpara where the parameter will be stored)
  105. }
  106. procedure a_param_const(list : taasmoutput;size : tcgsize;a : aword;const locpara : tparalocation);virtual;
  107. {# Pass the value of a parameter, which is located in memory, to a routine.
  108. A generic version is provided. This routine should
  109. be overriden for optimization purposes if the cpu
  110. permits directly sending this type of parameter.
  111. @param(size size of the operand in constant)
  112. @param(r Memory reference of value to send)
  113. @param(locpara where the parameter will be stored)
  114. }
  115. procedure a_param_ref(list : taasmoutput;size : tcgsize;const r : treference;const locpara : tparalocation);virtual;
  116. {# Pass the value of a parameter, which can be located either in a register or memory location,
  117. to a routine.
  118. A generic version is provided.
  119. @param(l location of the operand to send)
  120. @param(nr parameter number (starting from one) of routine (from left to right))
  121. @param(locpara where the parameter will be stored)
  122. }
  123. procedure a_param_loc(list : taasmoutput;const l : tlocation;const locpara : tparalocation);
  124. {# Pass the address of a reference to a routine. This routine
  125. will calculate the address of the reference, and pass this
  126. calculated address as a parameter.
  127. A generic version is provided. This routine should
  128. be overriden for optimization purposes if the cpu
  129. permits directly sending this type of parameter.
  130. @param(r reference to get address from)
  131. @param(nr parameter number (starting from one) of routine (from left to right))
  132. }
  133. procedure a_paramaddr_ref(list : taasmoutput;const r : treference;const locpara : tparalocation);virtual;
  134. { Copies a whole memory block to the stack, the locpara must be a memory location }
  135. procedure a_param_copy_ref(list : taasmoutput;size : qword;const r : treference;const locpara : tparalocation);
  136. { Remarks:
  137. * If a method specifies a size you have only to take care
  138. of that number of bits, i.e. load_const_reg with OP_8 must
  139. only load the lower 8 bit of the specified register
  140. the rest of the register can be undefined
  141. if necessary the compiler will call a method
  142. to zero or sign extend the register
  143. * The a_load_XX_XX with OP_64 needn't to be
  144. implemented for 32 bit
  145. processors, the code generator takes care of that
  146. * the addr size is for work with the natural pointer
  147. size
  148. * the procedures without fpu/mm are only for integer usage
  149. * normally the first location is the source and the
  150. second the destination
  151. }
  152. { Copy a parameter to a (temporary) reference }
  153. procedure a_loadany_param_ref(list : taasmoutput;const locpara : tparalocation;const ref:treference;shuffle : pmmshuffle);virtual;
  154. { Copy a parameter to a register }
  155. procedure a_loadany_param_reg(list : taasmoutput;const locpara : tparalocation;const reg:tregister;shuffle : pmmshuffle);virtual;
  156. {# Emits instruction to call the method specified by symbol name.
  157. This routine must be overriden for each new target cpu.
  158. There is no a_call_ref because loading the reference will use
  159. a temp register on most cpu's resulting in conflicts with the
  160. registers used for the parameters (PFV)
  161. }
  162. procedure a_call_name(list : taasmoutput;const s : string);virtual; abstract;
  163. procedure a_call_reg(list : taasmoutput;reg : tregister);virtual;abstract;
  164. { move instructions }
  165. procedure a_load_const_reg(list : taasmoutput;size : tcgsize;a : aword;register : tregister);virtual; abstract;
  166. procedure a_load_const_ref(list : taasmoutput;size : tcgsize;a : aword;const ref : treference);virtual;
  167. procedure a_load_const_loc(list : taasmoutput;a : aword;const loc : tlocation);
  168. procedure a_load_reg_ref(list : taasmoutput;fromsize,tosize : tcgsize;register : tregister;const ref : treference);virtual; abstract;
  169. procedure a_load_reg_reg(list : taasmoutput;fromsize,tosize : tcgsize;reg1,reg2 : tregister);virtual; abstract;
  170. procedure a_load_reg_loc(list : taasmoutput;fromsize : tcgsize;reg : tregister;const loc: tlocation);
  171. procedure a_load_ref_reg(list : taasmoutput;fromsize,tosize : tcgsize;const ref : treference;register : tregister);virtual; abstract;
  172. procedure a_load_ref_ref(list : taasmoutput;fromsize,tosize : tcgsize;const sref : treference;const dref : treference);virtual;
  173. procedure a_load_loc_reg(list : taasmoutput;tosize: tcgsize; const loc: tlocation; reg : tregister);
  174. procedure a_load_loc_ref(list : taasmoutput;tosize: tcgsize; const loc: tlocation; const ref : treference);
  175. procedure a_loadaddr_ref_reg(list : taasmoutput;const ref : treference;r : tregister);virtual; abstract;
  176. { fpu move instructions }
  177. procedure a_loadfpu_reg_reg(list: taasmoutput; size:tcgsize; reg1, reg2: tregister); virtual; abstract;
  178. procedure a_loadfpu_ref_reg(list: taasmoutput; size: tcgsize; const ref: treference; reg: tregister); virtual; abstract;
  179. procedure a_loadfpu_reg_ref(list: taasmoutput; size: tcgsize; reg: tregister; const ref: treference); virtual; abstract;
  180. procedure a_loadfpu_loc_reg(list: taasmoutput; const loc: tlocation; const reg: tregister);
  181. procedure a_loadfpu_reg_loc(list: taasmoutput; size: tcgsize; const reg: tregister; const loc: tlocation);
  182. procedure a_paramfpu_reg(list : taasmoutput;size : tcgsize;const r : tregister;const locpara : tparalocation);virtual;
  183. procedure a_paramfpu_ref(list : taasmoutput;size : tcgsize;const ref : treference;const locpara : tparalocation);virtual;
  184. { vector register move instructions }
  185. procedure a_loadmm_reg_reg(list: taasmoutput; fromsize, tosize : tcgsize;reg1, reg2: tregister;shuffle : pmmshuffle); virtual; abstract;
  186. procedure a_loadmm_ref_reg(list: taasmoutput; fromsize, tosize : tcgsize;const ref: treference; reg: tregister;shuffle : pmmshuffle); virtual; abstract;
  187. procedure a_loadmm_reg_ref(list: taasmoutput; fromsize, tosize : tcgsize;reg: tregister; const ref: treference;shuffle : pmmshuffle); virtual; abstract;
  188. procedure a_loadmm_loc_reg(list: taasmoutput; size: tcgsize; const loc: tlocation; const reg: tregister;shuffle : pmmshuffle);
  189. procedure a_loadmm_reg_loc(list: taasmoutput; size: tcgsize; const reg: tregister; const loc: tlocation;shuffle : pmmshuffle);
  190. procedure a_parammm_reg(list: taasmoutput; size: tcgsize; reg: tregister;const locpara : tparalocation;shuffle : pmmshuffle); virtual;
  191. procedure a_parammm_ref(list: taasmoutput; size: tcgsize; ref: treference;const locpara : tparalocation;shuffle : pmmshuffle); virtual;
  192. procedure a_parammm_loc(list: taasmoutput; loc: tlocation; const locpara : tparalocation;shuffle : pmmshuffle); virtual;
  193. { basic arithmetic operations }
  194. { note: for operators which require only one argument (not, neg), use }
  195. { the op_reg_reg, op_reg_ref or op_reg_loc methods and keep in mind }
  196. { that in this case the *second* operand is used as both source and }
  197. { destination (JM) }
  198. procedure a_op_const_reg(list : taasmoutput; Op: TOpCG; size: TCGSize; a: AWord; reg: TRegister); virtual; abstract;
  199. procedure a_op_const_ref(list : taasmoutput; Op: TOpCG; size: TCGSize; a: AWord; const ref: TReference); virtual;
  200. procedure a_op_const_loc(list : taasmoutput; Op: TOpCG; a: AWord; const loc: tlocation);
  201. procedure a_op_reg_reg(list : taasmoutput; Op: TOpCG; size: TCGSize; reg1, reg2: TRegister); virtual; abstract;
  202. procedure a_op_reg_ref(list : taasmoutput; Op: TOpCG; size: TCGSize; reg: TRegister; const ref: TReference); virtual;
  203. procedure a_op_ref_reg(list : taasmoutput; Op: TOpCG; size: TCGSize; const ref: TReference; reg: TRegister); virtual;
  204. procedure a_op_reg_loc(list : taasmoutput; Op: TOpCG; reg: tregister; const loc: tlocation);
  205. procedure a_op_ref_loc(list : taasmoutput; Op: TOpCG; const ref: TReference; const loc: tlocation);
  206. { trinary operations for processors that support them, 'emulated' }
  207. { on others. None with "ref" arguments since I don't think there }
  208. { are any processors that support it (JM) }
  209. procedure a_op_const_reg_reg(list: taasmoutput; op: TOpCg;
  210. size: tcgsize; a: aword; src, dst: tregister); virtual;
  211. procedure a_op_reg_reg_reg(list: taasmoutput; op: TOpCg;
  212. size: tcgsize; src1, src2, dst: tregister); virtual;
  213. { comparison operations }
  214. procedure a_cmp_const_reg_label(list : taasmoutput;size : tcgsize;cmp_op : topcmp;a : aword;reg : tregister;
  215. l : tasmlabel);virtual; abstract;
  216. procedure a_cmp_const_ref_label(list : taasmoutput;size : tcgsize;cmp_op : topcmp;a : aword;const ref : treference;
  217. l : tasmlabel); virtual;
  218. procedure a_cmp_const_loc_label(list: taasmoutput; size: tcgsize;cmp_op: topcmp; a: aword; const loc: tlocation;
  219. l : tasmlabel);
  220. procedure a_cmp_reg_reg_label(list : taasmoutput;size : tcgsize;cmp_op : topcmp;reg1,reg2 : tregister;l : tasmlabel); virtual; abstract;
  221. procedure a_cmp_ref_reg_label(list : taasmoutput;size : tcgsize;cmp_op : topcmp; const ref: treference; reg : tregister; l : tasmlabel); virtual;
  222. procedure a_cmp_loc_reg_label(list : taasmoutput;size : tcgsize;cmp_op : topcmp; const loc: tlocation; reg : tregister; l : tasmlabel);
  223. procedure a_cmp_ref_loc_label(list: taasmoutput; size: tcgsize;cmp_op: topcmp; const ref: treference; const loc: tlocation;
  224. l : tasmlabel);
  225. procedure a_jmp_always(list : taasmoutput;l: tasmlabel); virtual; abstract;
  226. procedure a_jmp_flags(list : taasmoutput;const f : TResFlags;l: tasmlabel); virtual; abstract;
  227. {# Depending on the value to check in the flags, either sets the register reg to one (if the flag is set)
  228. or zero (if the flag is cleared). The size parameter indicates the destination size register.
  229. }
  230. procedure g_flags2reg(list: taasmoutput; size: TCgSize; const f: tresflags; reg: TRegister); virtual; abstract;
  231. procedure g_flags2ref(list: taasmoutput; size: TCgSize; const f: tresflags; const ref:TReference); virtual;
  232. {
  233. This routine tries to optimize the const_reg opcode, and should be
  234. called at the start of a_op_const_reg. It returns the actual opcode
  235. to emit, and the constant value to emit. If this routine returns
  236. TRUE, @var(no) instruction should be emitted (.eg : imul reg by 1 )
  237. @param(op The opcode to emit, returns the opcode which must be emitted)
  238. @param(a The constant which should be emitted, returns the constant which must
  239. be emitted)
  240. @param(reg The register to emit the opcode with, returns the register with
  241. which the opcode will be emitted)
  242. }
  243. function optimize_op_const_reg(list: taasmoutput; var op: topcg; var a : aword; var reg: tregister): boolean;virtual;
  244. {#
  245. This routine is used in exception management nodes. It should
  246. save the exception reason currently in the FUNCTION_RETURN_REG. The
  247. save should be done either to a temp (pointed to by href).
  248. or on the stack (pushing the value on the stack).
  249. The size of the value to save is OS_S32. The default version
  250. saves the exception reason to a temp. memory area.
  251. }
  252. procedure g_exception_reason_save(list : taasmoutput; const href : treference);virtual;
  253. {#
  254. This routine is used in exception management nodes. It should
  255. save the exception reason constant. The
  256. save should be done either to a temp (pointed to by href).
  257. or on the stack (pushing the value on the stack).
  258. The size of the value to save is OS_S32. The default version
  259. saves the exception reason to a temp. memory area.
  260. }
  261. procedure g_exception_reason_save_const(list : taasmoutput; const href : treference; a: aword);virtual;
  262. {#
  263. This routine is used in exception management nodes. It should
  264. load the exception reason to the FUNCTION_RETURN_REG. The saved value
  265. should either be in the temp. area (pointed to by href , href should
  266. *NOT* be freed) or on the stack (the value should be popped).
  267. The size of the value to save is OS_S32. The default version
  268. saves the exception reason to a temp. memory area.
  269. }
  270. procedure g_exception_reason_load(list : taasmoutput; const href : treference);virtual;
  271. procedure g_maybe_testself(list : taasmoutput;reg:tregister);
  272. procedure g_maybe_testvmt(list : taasmoutput;reg:tregister;objdef:tobjectdef);
  273. {# This should emit the opcode to copy len bytes from the source
  274. to destination, if loadref is true, it assumes that it first must load
  275. the source address from the memory location where
  276. source points to.
  277. It must be overriden for each new target processor.
  278. @param(source Source reference of copy)
  279. @param(dest Destination reference of copy)
  280. @param(delsource Indicates if the source reference's resources should be freed)
  281. @param(loadref Is the source reference a pointer to the actual source (TRUE), is it the actual source address (FALSE))
  282. }
  283. procedure g_concatcopy(list : taasmoutput;const source,dest : treference;len : aword;delsource,loadref : boolean);virtual; abstract;
  284. {# This should emit the opcode to a shortrstring from the source
  285. to destination, if loadref is true, it assumes that it first must load
  286. the source address from the memory location where
  287. source points to.
  288. @param(source Source reference of copy)
  289. @param(dest Destination reference of copy)
  290. @param(delsource Indicates if the source reference's resources should be freed)
  291. @param(loadref Is the source reference a pointer to the actual source (TRUE), is it the actual source address (FALSE))
  292. }
  293. procedure g_copyshortstring(list : taasmoutput;const source,dest : treference;len:byte;delsource,loadref : boolean);
  294. procedure g_incrrefcount(list : taasmoutput;t: tdef; const ref: treference;loadref : boolean);
  295. procedure g_decrrefcount(list : taasmoutput;t: tdef; const ref: treference;loadref : boolean);
  296. procedure g_initialize(list : taasmoutput;t : tdef;const ref : treference;loadref : boolean);
  297. procedure g_finalize(list : taasmoutput;t : tdef;const ref : treference;loadref : boolean);
  298. {# Emits the call to the stack checking routine of
  299. the runtime library. The default behavior
  300. does not need to be modified, as it is generic
  301. for all platforms.
  302. @param(stackframesize Number of bytes which will be allocated on the stack)
  303. }
  304. procedure g_stackcheck(list : taasmoutput;stackframesize : longint);virtual;
  305. {# Generates range checking code. It is to note
  306. that this routine does not need to be overriden,
  307. as it takes care of everything.
  308. @param(p Node which contains the value to check)
  309. @param(todef Type definition of node to range check)
  310. }
  311. procedure g_rangecheck(list: taasmoutput; const l:tlocation; fromdef,todef: tdef); virtual;
  312. {# Generates overflow checking code for a node }
  313. procedure g_overflowcheck(list: taasmoutput; const l:tlocation; def:tdef); virtual; abstract;
  314. procedure g_copyvaluepara_openarray(list : taasmoutput;const ref, lenref:treference;elesize:aword);virtual;abstract;
  315. procedure g_releasevaluepara_openarray(list : taasmoutput;const ref:treference);virtual;
  316. {# Emits instructions which should be emitted when entering
  317. a routine declared as @var(interrupt). The default
  318. behavior does nothing, should be overriden as required.
  319. }
  320. procedure g_interrupt_stackframe_entry(list : taasmoutput);virtual;
  321. {# Emits instructions which should be emitted when exiting
  322. a routine declared as @var(interrupt). The default
  323. behavior does nothing, should be overriden as required.
  324. }
  325. procedure g_interrupt_stackframe_exit(list : taasmoutput;accused,acchiused:boolean);virtual;
  326. {# Emits instructions when compilation is done in profile
  327. mode (this is set as a command line option). The default
  328. behavior does nothing, should be overriden as required.
  329. }
  330. procedure g_profilecode(list : taasmoutput);virtual;
  331. {# Emits instruction for allocating @var(size) bytes at the stackpointer
  332. @param(size Number of bytes to allocate)
  333. }
  334. procedure g_stackpointer_alloc(list : taasmoutput;size : longint);virtual; abstract;
  335. {# Emits instruction for allocating the locals in entry
  336. code of a routine. This is one of the first
  337. routine called in @var(genentrycode).
  338. @param(localsize Number of bytes to allocate as locals)
  339. }
  340. procedure g_stackframe_entry(list : taasmoutput;localsize : longint);virtual; abstract;
  341. {# Emits instructiona for restoring the frame pointer
  342. at routine exit. For some processors, this routine
  343. may do nothing at all.
  344. }
  345. procedure g_restore_frame_pointer(list : taasmoutput);virtual; abstract;
  346. {# Emits instructions for returning from a subroutine.
  347. Should also restore the stack.
  348. @param(parasize Number of bytes of parameters to deallocate from stack)
  349. }
  350. procedure g_return_from_proc(list : taasmoutput;parasize : aword);virtual; abstract;
  351. {# This routine is called when generating the code for the entry point
  352. of a routine. It should save all registers which are not used in this
  353. routine, and which should be declared as saved in the std_saved_registers
  354. set.
  355. This routine is mainly used when linking to code which is generated
  356. by ABI-compliant compilers (like GCC), to make sure that the reserved
  357. registers of that ABI are not clobbered.
  358. @param(usedinproc Registers which are used in the code of this routine)
  359. }
  360. procedure g_save_standard_registers(list:Taasmoutput);virtual;abstract;
  361. {# This routine is called when generating the code for the exit point
  362. of a routine. It should restore all registers which were previously
  363. saved in @var(g_save_standard_registers).
  364. @param(usedinproc Registers which are used in the code of this routine)
  365. }
  366. procedure g_restore_standard_registers(list:Taasmoutput);virtual;abstract;
  367. procedure g_save_all_registers(list : taasmoutput);virtual;abstract;
  368. procedure g_restore_all_registers(list : taasmoutput;accused,acchiused:boolean);virtual;abstract;
  369. end;
  370. {# @abstract(Abstract code generator for 64 Bit operations)
  371. This class implements an abstract code generator class
  372. for 64 Bit operations.
  373. }
  374. tcg64 = class
  375. { Allocates 64 Bit register r by inserting a pai_realloc record }
  376. procedure a_reg_alloc(list : taasmoutput;r : tregister64);virtual;abstract;
  377. { Deallocates 64 Bit register r by inserting a pa_regdealloc record}
  378. procedure a_reg_dealloc(list : taasmoutput;r : tregister64);virtual;abstract;
  379. procedure a_load64_const_ref(list : taasmoutput;value : qword;const ref : treference);virtual;abstract;
  380. procedure a_load64_reg_ref(list : taasmoutput;reg : tregister64;const ref : treference);virtual;abstract;
  381. procedure a_load64_ref_reg(list : taasmoutput;const ref : treference;reg : tregister64;delete : boolean);virtual;abstract;
  382. procedure a_load64_reg_reg(list : taasmoutput;regsrc,regdst : tregister64;delete : boolean);virtual;abstract;
  383. procedure a_load64_const_reg(list : taasmoutput;value : qword;reg : tregister64);virtual;abstract;
  384. procedure a_load64_loc_reg(list : taasmoutput;const l : tlocation;reg : tregister64;delete : boolean);virtual;abstract;
  385. procedure a_load64_loc_ref(list : taasmoutput;const l : tlocation;const ref : treference);virtual;abstract;
  386. procedure a_load64_const_loc(list : taasmoutput;value : qword;const l : tlocation);virtual;abstract;
  387. procedure a_load64_reg_loc(list : taasmoutput;reg : tregister64;const l : tlocation);virtual;abstract;
  388. procedure a_load64high_reg_ref(list : taasmoutput;reg : tregister;const ref : treference);virtual;abstract;
  389. procedure a_load64low_reg_ref(list : taasmoutput;reg : tregister;const ref : treference);virtual;abstract;
  390. procedure a_load64high_ref_reg(list : taasmoutput;const ref : treference;reg : tregister);virtual;abstract;
  391. procedure a_load64low_ref_reg(list : taasmoutput;const ref : treference;reg : tregister);virtual;abstract;
  392. procedure a_load64high_loc_reg(list : taasmoutput;const l : tlocation;reg : tregister);virtual;abstract;
  393. procedure a_load64low_loc_reg(list : taasmoutput;const l : tlocation;reg : tregister);virtual;abstract;
  394. procedure a_op64_ref_reg(list : taasmoutput;op:TOpCG;const ref : treference;reg : tregister64);virtual;abstract;
  395. procedure a_op64_reg_reg(list : taasmoutput;op:TOpCG;regsrc,regdst : tregister64);virtual;abstract;
  396. procedure a_op64_reg_ref(list : taasmoutput;op:TOpCG;regsrc : tregister64;const ref : treference);virtual;abstract;
  397. procedure a_op64_const_reg(list : taasmoutput;op:TOpCG;value : qword;regdst : tregister64);virtual;abstract;
  398. procedure a_op64_const_ref(list : taasmoutput;op:TOpCG;value : qword;const ref : treference);virtual;abstract;
  399. procedure a_op64_const_loc(list : taasmoutput;op:TOpCG;value : qword;const l: tlocation);virtual;abstract;
  400. procedure a_op64_reg_loc(list : taasmoutput;op:TOpCG;reg : tregister64;const l : tlocation);virtual;abstract;
  401. procedure a_op64_loc_reg(list : taasmoutput;op:TOpCG;const l : tlocation;reg64 : tregister64);virtual;abstract;
  402. procedure a_op64_const_reg_reg(list: taasmoutput;op:TOpCG;value : qword;regsrc,regdst : tregister64);virtual;
  403. procedure a_op64_reg_reg_reg(list: taasmoutput;op:TOpCG;regsrc1,regsrc2,regdst : tregister64);virtual;
  404. procedure a_param64_reg(list : taasmoutput;reg64 : tregister64;const loc : tparalocation);virtual;abstract;
  405. procedure a_param64_const(list : taasmoutput;value : qword;const loc : tparalocation);virtual;abstract;
  406. procedure a_param64_ref(list : taasmoutput;const r : treference;const loc : tparalocation);virtual;abstract;
  407. procedure a_param64_loc(list : taasmoutput;const l : tlocation;const loc : tparalocation);virtual;abstract;
  408. {
  409. This routine tries to optimize the const_reg opcode, and should be
  410. called at the start of a_op64_const_reg. It returns the actual opcode
  411. to emit, and the constant value to emit. If this routine returns
  412. TRUE, @var(no) instruction should be emitted (.eg : imul reg by 1 )
  413. @param(op The opcode to emit, returns the opcode which must be emitted)
  414. @param(a The constant which should be emitted, returns the constant which must
  415. be emitted)
  416. @param(reg The register to emit the opcode with, returns the register with
  417. which the opcode will be emitted)
  418. }
  419. function optimize64_op_const_reg(list: taasmoutput; var op: topcg; var a : qword; var reg: tregister64): boolean;virtual;abstract;
  420. { override to catch 64bit rangechecks }
  421. procedure g_rangecheck64(list: taasmoutput; const l:tlocation; fromdef,todef: tdef);virtual;abstract;
  422. end;
  423. { trerefence handling }
  424. {# Clear to zero a treference }
  425. procedure reference_reset(var ref : treference);
  426. {# Clear to zero a treference, and set is base address
  427. to base register.
  428. }
  429. procedure reference_reset_base(var ref : treference;base : tregister;offset : longint);
  430. procedure reference_reset_symbol(var ref : treference;sym : tasmsymbol;offset : longint);
  431. procedure reference_release(list: taasmoutput; const ref : treference);
  432. { This routine verifies if two references are the same, and
  433. if so, returns TRUE, otherwise returns false.
  434. }
  435. function references_equal(sref : treference;dref : treference) : boolean;
  436. { tlocation handling }
  437. procedure location_reset(var l : tlocation;lt:TCGLoc;lsize:TCGSize);
  438. procedure location_release(list: taasmoutput; const l : tlocation);
  439. procedure location_freetemp(list: taasmoutput; const l : tlocation);
  440. procedure location_copy(var destloc:tlocation; const sourceloc : tlocation);
  441. procedure location_swap(var destloc,sourceloc : tlocation);
  442. var
  443. {# Main code generator class }
  444. cg : tcg;
  445. {# Code generator class for all operations working with 64-Bit operands }
  446. cg64 : tcg64;
  447. implementation
  448. uses
  449. globals,globtype,options,systems,
  450. verbose,defutil,paramgr,
  451. tgobj,cutils;
  452. const
  453. { Please leave this here, this module should NOT use
  454. exprasmlist, the lists are always passed as arguments.
  455. Declaring it as string here results in an error when compiling (PFV) }
  456. exprasmlist = 'error';
  457. {*****************************************************************************
  458. basic functionallity
  459. ******************************************************************************}
  460. constructor tcg.create;
  461. begin
  462. end;
  463. function Tcg.makeregsize(reg:Tregister;size:Tcgsize):Tregister;
  464. var
  465. subreg:Tsubregister;
  466. begin
  467. subreg:=cgsize2subreg(size);
  468. result:=reg;
  469. setsubreg(result,subreg);
  470. end;
  471. {*****************************************************************************
  472. register allocation
  473. ******************************************************************************}
  474. function tcg.getintregister(list:Taasmoutput;size:Tcgsize):Tregister;
  475. begin
  476. if not assigned(rg[R_INTREGISTER]) then
  477. internalerror(200312122);
  478. result:=rg[R_INTREGISTER].getregister(list,cgsize2subreg(size));
  479. end;
  480. function tcg.getfpuregister(list:Taasmoutput;size:Tcgsize):Tregister;
  481. begin
  482. if not assigned(rg[R_FPUREGISTER]) then
  483. internalerror(200312123);
  484. result:=rg[R_FPUREGISTER].getregister(list,cgsize2subreg(size));
  485. end;
  486. function tcg.getmmregister(list:Taasmoutput;size:Tcgsize):Tregister;
  487. begin
  488. if not assigned(rg[R_MMREGISTER]) then
  489. internalerror(200312124);
  490. result:=rg[R_MMREGISTER].getregister(list,cgsize2subreg(size));
  491. end;
  492. function tcg.getaddressregister(list:Taasmoutput):Tregister;
  493. begin
  494. if assigned(rg[R_ADDRESSREGISTER]) then
  495. result:=rg[R_ADDRESSREGISTER].getregister(list,R_SUBWHOLE)
  496. else
  497. begin
  498. if not assigned(rg[R_INTREGISTER]) then
  499. internalerror(200312121);
  500. result:=rg[R_INTREGISTER].getregister(list,R_SUBWHOLE);
  501. end;
  502. end;
  503. procedure tcg.getexplicitregister(list:Taasmoutput;r:Tregister);
  504. begin
  505. if not assigned(rg[getregtype(r)]) then
  506. internalerror(200312125);
  507. rg[getregtype(r)].getexplicitregister(list,r);
  508. end;
  509. procedure tcg.ungetregister(list:Taasmoutput;r:Tregister);
  510. begin
  511. if not assigned(rg[getregtype(r)]) then
  512. internalerror(200312126);
  513. rg[getregtype(r)].ungetregister(list,r);
  514. end;
  515. procedure tcg.ungetreference(list:Taasmoutput;const r:Treference);
  516. begin
  517. if r.base<>NR_NO then
  518. ungetregister(list,r.base);
  519. end;
  520. procedure tcg.allocexplicitregisters(list:Taasmoutput;rt:Tregistertype;r:Tcpuregisterset);
  521. begin
  522. if assigned(rg[rt]) then
  523. rg[rt].allocexplicitregisters(list,r)
  524. else
  525. internalerror(200310092);
  526. end;
  527. procedure tcg.deallocexplicitregisters(list:Taasmoutput;rt:Tregistertype;r:Tcpuregisterset);
  528. begin
  529. if assigned(rg[rt]) then
  530. rg[rt].deallocexplicitregisters(list,r)
  531. else
  532. internalerror(200310093);
  533. end;
  534. function tcg.uses_registers(rt:Tregistertype):boolean;
  535. begin
  536. if assigned(rg[rt]) then
  537. result:=rg[rt].uses_registers
  538. else
  539. internalerror(200310094);
  540. end;
  541. procedure tcg.add_move_instruction(instr:Taicpu);
  542. var
  543. rt : tregistertype;
  544. begin
  545. rt:=getregtype(instr.oper[O_MOV_SOURCE]^.reg);
  546. if assigned(rg[rt]) then
  547. rg[rt].add_move_instruction(instr)
  548. else
  549. internalerror(200310095);
  550. end;
  551. procedure tcg.do_register_allocation(list:Taasmoutput;headertai:tai);
  552. var
  553. rt : tregistertype;
  554. begin
  555. for rt:=low(tregistertype) to high(tregistertype) do
  556. begin
  557. if assigned(rg[rt]) then
  558. begin
  559. rg[rt].check_unreleasedregs;
  560. rg[rt].do_register_allocation(list,headertai);
  561. rg[rt].translate_registers(list);
  562. end;
  563. end;
  564. end;
  565. procedure tcg.a_reg_alloc(list : taasmoutput;r : tregister);
  566. begin
  567. list.concat(tai_regalloc.alloc(r));
  568. end;
  569. procedure tcg.a_reg_dealloc(list : taasmoutput;r : tregister);
  570. begin
  571. list.concat(tai_regalloc.dealloc(r));
  572. end;
  573. procedure tcg.a_label(list : taasmoutput;l : tasmlabel);
  574. begin
  575. list.concat(tai_label.create(l));
  576. end;
  577. {*****************************************************************************
  578. for better code generation these methods should be overridden
  579. ******************************************************************************}
  580. procedure tcg.a_param_reg(list : taasmoutput;size : tcgsize;r : tregister;const locpara : tparalocation);
  581. var
  582. ref : treference;
  583. begin
  584. case locpara.loc of
  585. LOC_REGISTER,LOC_CREGISTER:
  586. a_load_reg_reg(list,size,locpara.size,r,locpara.register);
  587. LOC_REFERENCE,LOC_CREFERENCE:
  588. begin
  589. reference_reset(ref);
  590. ref.base:=locpara.reference.index;
  591. ref.offset:=locpara.reference.offset;
  592. a_load_reg_ref(list,size,size,r,ref);
  593. end
  594. else
  595. internalerror(2002071004);
  596. end;
  597. end;
  598. procedure tcg.a_param_const(list : taasmoutput;size : tcgsize;a : aword;const locpara : tparalocation);
  599. var
  600. hr : tregister;
  601. begin
  602. hr:=getintregister(list,size);
  603. a_load_const_reg(list,size,a,hr);
  604. ungetregister(list,hr);
  605. a_param_reg(list,size,hr,locpara);
  606. end;
  607. procedure tcg.a_param_ref(list : taasmoutput;size : tcgsize;const r : treference;const locpara : tparalocation);
  608. var
  609. hr : tregister;
  610. begin
  611. hr:=getintregister(list,size);
  612. a_load_ref_reg(list,size,size,r,hr);
  613. ungetregister(list,hr);
  614. a_param_reg(list,size,hr,locpara);
  615. end;
  616. procedure tcg.a_param_loc(list : taasmoutput;const l:tlocation;const locpara : tparalocation);
  617. begin
  618. case l.loc of
  619. LOC_REGISTER,
  620. LOC_CREGISTER :
  621. a_param_reg(list,l.size,l.register,locpara);
  622. LOC_CONSTANT :
  623. a_param_const(list,l.size,l.value,locpara);
  624. LOC_CREFERENCE,
  625. LOC_REFERENCE :
  626. a_param_ref(list,l.size,l.reference,locpara);
  627. else
  628. internalerror(2002032211);
  629. end;
  630. end;
  631. procedure tcg.a_paramaddr_ref(list : taasmoutput;const r : treference;const locpara : tparalocation);
  632. var
  633. hr : tregister;
  634. begin
  635. hr:=getaddressregister(list);
  636. a_loadaddr_ref_reg(list,r,hr);
  637. ungetregister(list,hr);
  638. a_param_reg(list,OS_ADDR,hr,locpara);
  639. end;
  640. procedure tcg.a_param_copy_ref(list : taasmoutput;size : qword;const r : treference;const locpara : tparalocation);
  641. var
  642. ref : treference;
  643. begin
  644. if not(locpara.loc in [LOC_REFERENCE,LOC_CREFERENCE]) then
  645. internalerror(2003010901);
  646. reference_reset_base(ref,locpara.reference.index,locpara.reference.offset);
  647. g_concatcopy(list,r,ref,size,false,false);
  648. end;
  649. procedure tcg.a_loadany_param_ref(list : taasmoutput;const locpara : tparalocation;const ref:treference;shuffle : pmmshuffle);
  650. begin
  651. case locpara.loc of
  652. LOC_CREGISTER,
  653. LOC_REGISTER:
  654. begin
  655. if (locpara.size in [OS_S64,OS_64]) then
  656. begin
  657. {$ifdef cpu64bit}
  658. ungetregisterint(list,locpara.register64);
  659. {$else cpu64bit}
  660. getexplicitregister(list,locpara.registerlow);
  661. getexplicitregister(list,locpara.registerhigh);
  662. ungetregister(list,locpara.registerlow);
  663. ungetregister(list,locpara.registerhigh);
  664. {$endif cpu64bit}
  665. cg64.a_load64_reg_ref(list,locpara.register64,ref)
  666. end
  667. else
  668. begin
  669. getexplicitregister(list,locpara.register);
  670. ungetregister(list,locpara.register);
  671. a_load_reg_ref(list,locpara.size,locpara.size,locpara.register,ref);
  672. end;
  673. end;
  674. LOC_MMREGISTER,
  675. LOC_CMMREGISTER:
  676. begin
  677. getexplicitregister(list,locpara.register);
  678. ungetregister(list,locpara.register);
  679. a_loadmm_reg_ref(list,locpara.size,locpara.size,locpara.register,ref,shuffle);
  680. end;
  681. LOC_FPUREGISTER,
  682. LOC_CFPUREGISTER:
  683. begin
  684. getexplicitregister(list,locpara.register);
  685. ungetregister(list,locpara.register);
  686. a_loadfpu_reg_ref(list,locpara.size,locpara.register,ref);
  687. end;
  688. else
  689. internalerror(2002081302);
  690. end;
  691. end;
  692. procedure tcg.a_loadany_param_reg(list : taasmoutput;const locpara : tparalocation;const reg:tregister;shuffle : pmmshuffle);
  693. var
  694. href : treference;
  695. begin
  696. case locpara.loc of
  697. LOC_CREGISTER,
  698. LOC_REGISTER:
  699. begin
  700. if not(locpara.size in [OS_S64,OS_64]) then
  701. begin
  702. getexplicitregister(list,locpara.register);
  703. ungetregister(list,locpara.register);
  704. getexplicitregister(list,reg);
  705. a_load_reg_reg(list,locpara.size,locpara.size,locpara.register,reg)
  706. end
  707. else
  708. internalerror(2003053011);
  709. end;
  710. LOC_CFPUREGISTER,
  711. LOC_FPUREGISTER:
  712. begin
  713. getexplicitregister(list,locpara.register);
  714. ungetregister(list,locpara.register);
  715. getexplicitregister(list,reg);
  716. a_loadfpu_reg_reg(list,locpara.size,locpara.register,reg);
  717. end;
  718. LOC_MMREGISTER,
  719. LOC_CMMREGISTER:
  720. begin
  721. getexplicitregister(list,locpara.register);
  722. ungetregister(list,locpara.register);
  723. getexplicitregister(list,reg);
  724. a_loadmm_reg_reg(list,locpara.size,locpara.size,locpara.register,reg,shuffle);
  725. end;
  726. LOC_REFERENCE,
  727. LOC_CREFERENCE:
  728. begin
  729. reference_reset_base(href,locpara.reference.index,locpara.reference.offset);
  730. getexplicitregister(list,reg);
  731. a_load_ref_reg(list,locpara.size,locpara.size,href,reg);
  732. end;
  733. else
  734. internalerror(2003053010);
  735. end
  736. end;
  737. {****************************************************************************
  738. some generic implementations
  739. ****************************************************************************}
  740. procedure tcg.a_load_ref_ref(list : taasmoutput;fromsize,tosize : tcgsize;const sref : treference;const dref : treference);
  741. var
  742. tmpreg: tregister;
  743. begin
  744. { verify if we have the same reference }
  745. if references_equal(sref,dref) then
  746. exit;
  747. tmpreg:=getintregister(list,tosize);
  748. a_load_ref_reg(list,fromsize,tosize,sref,tmpreg);
  749. a_load_reg_ref(list,tosize,tosize,tmpreg,dref);
  750. ungetregister(list,tmpreg);
  751. end;
  752. procedure tcg.a_load_const_ref(list : taasmoutput;size : tcgsize;a : aword;const ref : treference);
  753. var
  754. tmpreg: tregister;
  755. begin
  756. tmpreg:=getintregister(list,size);
  757. a_load_const_reg(list,size,a,tmpreg);
  758. a_load_reg_ref(list,size,size,tmpreg,ref);
  759. ungetregister(list,tmpreg);
  760. end;
  761. procedure tcg.a_load_const_loc(list : taasmoutput;a : aword;const loc: tlocation);
  762. begin
  763. case loc.loc of
  764. LOC_REFERENCE,LOC_CREFERENCE:
  765. a_load_const_ref(list,loc.size,a,loc.reference);
  766. LOC_REGISTER,LOC_CREGISTER:
  767. a_load_const_reg(list,loc.size,a,loc.register);
  768. else
  769. internalerror(200203272);
  770. end;
  771. end;
  772. procedure tcg.a_load_reg_loc(list : taasmoutput;fromsize : tcgsize;reg : tregister;const loc: tlocation);
  773. begin
  774. case loc.loc of
  775. LOC_REFERENCE,LOC_CREFERENCE:
  776. a_load_reg_ref(list,fromsize,loc.size,reg,loc.reference);
  777. LOC_REGISTER,LOC_CREGISTER:
  778. a_load_reg_reg(list,fromsize,loc.size,reg,loc.register);
  779. else
  780. internalerror(200203271);
  781. end;
  782. end;
  783. procedure tcg.a_load_loc_reg(list : taasmoutput; tosize: tcgsize; const loc: tlocation; reg : tregister);
  784. begin
  785. case loc.loc of
  786. LOC_REFERENCE,LOC_CREFERENCE:
  787. a_load_ref_reg(list,loc.size,tosize,loc.reference,reg);
  788. LOC_REGISTER,LOC_CREGISTER:
  789. a_load_reg_reg(list,loc.size,tosize,loc.register,reg);
  790. LOC_CONSTANT:
  791. a_load_const_reg(list,tosize,loc.value,reg);
  792. else
  793. internalerror(200109092);
  794. end;
  795. end;
  796. procedure tcg.a_load_loc_ref(list : taasmoutput;tosize: tcgsize; const loc: tlocation; const ref : treference);
  797. begin
  798. case loc.loc of
  799. LOC_REFERENCE,LOC_CREFERENCE:
  800. a_load_ref_ref(list,loc.size,tosize,loc.reference,ref);
  801. LOC_REGISTER,LOC_CREGISTER:
  802. a_load_reg_ref(list,loc.size,tosize,loc.register,ref);
  803. LOC_CONSTANT:
  804. a_load_const_ref(list,tosize,loc.value,ref);
  805. else
  806. internalerror(200109302);
  807. end;
  808. end;
  809. function tcg.optimize_op_const_reg(list: taasmoutput; var op: topcg; var a : aword; var reg:tregister): boolean;
  810. var
  811. powerval : longint;
  812. begin
  813. optimize_op_const_reg := false;
  814. case op of
  815. { or with zero returns same result }
  816. OP_OR : if a = 0 then optimize_op_const_reg := true;
  817. { and with max returns same result }
  818. OP_AND : if (a = high(a)) then optimize_op_const_reg := true;
  819. { division by 1 returns result }
  820. OP_DIV :
  821. begin
  822. if a = 1 then
  823. optimize_op_const_reg := true
  824. else if ispowerof2(int64(a), powerval) then
  825. begin
  826. a := powerval;
  827. op:= OP_SHR;
  828. end;
  829. exit;
  830. end;
  831. OP_IDIV:
  832. begin
  833. if a = 1 then
  834. optimize_op_const_reg := true
  835. else if ispowerof2(int64(a), powerval) then
  836. begin
  837. a := powerval;
  838. op:= OP_SAR;
  839. end;
  840. exit;
  841. end;
  842. OP_MUL,OP_IMUL:
  843. begin
  844. if a = 1 then
  845. optimize_op_const_reg := true
  846. else if ispowerof2(int64(a), powerval) then
  847. begin
  848. a := powerval;
  849. op:= OP_SHL;
  850. end;
  851. exit;
  852. end;
  853. OP_SAR,OP_SHL,OP_SHR:
  854. begin
  855. if a = 0 then
  856. optimize_op_const_reg := true;
  857. exit;
  858. end;
  859. end;
  860. end;
  861. procedure tcg.a_loadfpu_loc_reg(list: taasmoutput; const loc: tlocation; const reg: tregister);
  862. begin
  863. case loc.loc of
  864. LOC_REFERENCE, LOC_CREFERENCE:
  865. a_loadfpu_ref_reg(list,loc.size,loc.reference,reg);
  866. LOC_FPUREGISTER, LOC_CFPUREGISTER:
  867. a_loadfpu_reg_reg(list,loc.size,loc.register,reg);
  868. else
  869. internalerror(200203301);
  870. end;
  871. end;
  872. procedure tcg.a_loadfpu_reg_loc(list: taasmoutput; size: tcgsize; const reg: tregister; const loc: tlocation);
  873. begin
  874. case loc.loc of
  875. LOC_REFERENCE, LOC_CREFERENCE:
  876. a_loadfpu_reg_ref(list,size,reg,loc.reference);
  877. LOC_FPUREGISTER, LOC_CFPUREGISTER:
  878. a_loadfpu_reg_reg(list,size,reg,loc.register);
  879. else
  880. internalerror(48991);
  881. end;
  882. end;
  883. procedure tcg.a_paramfpu_reg(list : taasmoutput;size : tcgsize;const r : tregister;const locpara : tparalocation);
  884. var
  885. ref : treference;
  886. begin
  887. case locpara.loc of
  888. LOC_FPUREGISTER,LOC_CFPUREGISTER:
  889. a_loadfpu_reg_reg(list,size,r,locpara.register);
  890. LOC_REFERENCE,LOC_CREFERENCE:
  891. begin
  892. reference_reset(ref);
  893. ref.base:=locpara.reference.index;
  894. ref.offset:=locpara.reference.offset;
  895. a_loadfpu_reg_ref(list,size,r,ref);
  896. end
  897. else
  898. internalerror(2002071004);
  899. end;
  900. end;
  901. procedure tcg.a_paramfpu_ref(list : taasmoutput;size : tcgsize;const ref : treference;const locpara : tparalocation);
  902. var
  903. hr : tregister;
  904. begin
  905. hr:=getfpuregister(list,size);
  906. a_loadfpu_ref_reg(list,size,ref,hr);
  907. a_paramfpu_reg(list,size,hr,locpara);
  908. ungetregister(list,hr);
  909. end;
  910. procedure tcg.a_op_const_ref(list : taasmoutput; Op: TOpCG; size: TCGSize; a: AWord; const ref: TReference);
  911. var
  912. tmpreg: tregister;
  913. begin
  914. tmpreg:=getintregister(list,size);
  915. a_load_ref_reg(list,size,size,ref,tmpreg);
  916. a_op_const_reg(list,op,size,a,tmpreg);
  917. a_load_reg_ref(list,size,size,tmpreg,ref);
  918. ungetregister(list,tmpreg);
  919. end;
  920. procedure tcg.a_op_const_loc(list : taasmoutput; Op: TOpCG; a: AWord; const loc: tlocation);
  921. begin
  922. case loc.loc of
  923. LOC_REGISTER, LOC_CREGISTER:
  924. a_op_const_reg(list,op,loc.size,a,loc.register);
  925. LOC_REFERENCE, LOC_CREFERENCE:
  926. a_op_const_ref(list,op,loc.size,a,loc.reference);
  927. else
  928. internalerror(200109061);
  929. end;
  930. end;
  931. procedure tcg.a_op_reg_ref(list : taasmoutput; Op: TOpCG; size: TCGSize;reg: TRegister; const ref: TReference);
  932. var
  933. tmpreg: tregister;
  934. begin
  935. tmpreg:=getintregister(list,size);
  936. a_load_ref_reg(list,size,size,ref,tmpreg);
  937. a_op_reg_reg(list,op,size,reg,tmpreg);
  938. a_load_reg_ref(list,size,size,tmpreg,ref);
  939. ungetregister(list,tmpreg);
  940. end;
  941. procedure tcg.a_op_ref_reg(list : taasmoutput; Op: TOpCG; size: TCGSize; const ref: TReference; reg: TRegister);
  942. var
  943. tmpreg: tregister;
  944. begin
  945. case op of
  946. OP_NOT,OP_NEG:
  947. { handle it as "load ref,reg; op reg" }
  948. begin
  949. a_load_ref_reg(list,size,size,ref,reg);
  950. a_op_reg_reg(list,op,size,reg,reg);
  951. end;
  952. else
  953. begin
  954. tmpreg:=getintregister(list,size);
  955. a_load_ref_reg(list,size,size,ref,tmpreg);
  956. a_op_reg_reg(list,op,size,tmpreg,reg);
  957. ungetregister(list,tmpreg);
  958. end;
  959. end;
  960. end;
  961. procedure tcg.a_op_reg_loc(list : taasmoutput; Op: TOpCG; reg: tregister; const loc: tlocation);
  962. begin
  963. case loc.loc of
  964. LOC_REGISTER, LOC_CREGISTER:
  965. a_op_reg_reg(list,op,loc.size,reg,loc.register);
  966. LOC_REFERENCE, LOC_CREFERENCE:
  967. a_op_reg_ref(list,op,loc.size,reg,loc.reference);
  968. else
  969. internalerror(200109061);
  970. end;
  971. end;
  972. procedure tcg.a_op_ref_loc(list : taasmoutput; Op: TOpCG; const ref: TReference; const loc: tlocation);
  973. var
  974. tmpreg: tregister;
  975. begin
  976. case loc.loc of
  977. LOC_REGISTER,LOC_CREGISTER:
  978. a_op_ref_reg(list,op,loc.size,ref,loc.register);
  979. LOC_REFERENCE,LOC_CREFERENCE:
  980. begin
  981. tmpreg:=getintregister(list,loc.size);
  982. a_load_ref_reg(list,loc.size,loc.size,ref,tmpreg);
  983. a_op_reg_ref(list,op,loc.size,tmpreg,loc.reference);
  984. ungetregister(list,tmpreg);
  985. end;
  986. else
  987. internalerror(200109061);
  988. end;
  989. end;
  990. procedure Tcg.a_op_const_reg_reg(list:Taasmoutput;op:Topcg;size:Tcgsize;
  991. a:aword;src,dst:Tregister);
  992. begin
  993. a_load_reg_reg(list,size,size,src,dst);
  994. a_op_const_reg(list,op,size,a,dst);
  995. end;
  996. procedure tcg.a_op_reg_reg_reg(list: taasmoutput; op: TOpCg;
  997. size: tcgsize; src1, src2, dst: tregister);
  998. var
  999. tmpreg: tregister;
  1000. begin
  1001. if (dst<>src1) then
  1002. begin
  1003. a_load_reg_reg(list,size,size,src2,dst);
  1004. a_op_reg_reg(list,op,size,src1,dst);
  1005. end
  1006. else
  1007. begin
  1008. tmpreg:=cg.getintregister(list,size);
  1009. a_load_reg_reg(list,size,size,src2,tmpreg);
  1010. a_op_reg_reg(list,op,size,src1,tmpreg);
  1011. a_load_reg_reg(list,size,size,tmpreg,dst);
  1012. ungetregister(list,tmpreg);
  1013. end;
  1014. end;
  1015. procedure tcg.a_cmp_const_ref_label(list : taasmoutput;size : tcgsize;cmp_op : topcmp;a : aword;const ref : treference;
  1016. l : tasmlabel);
  1017. var
  1018. tmpreg: tregister;
  1019. begin
  1020. tmpreg:=getintregister(list,size);
  1021. a_load_ref_reg(list,size,size,ref,tmpreg);
  1022. a_cmp_const_reg_label(list,size,cmp_op,a,tmpreg,l);
  1023. ungetregister(list,tmpreg);
  1024. end;
  1025. procedure tcg.a_cmp_const_loc_label(list : taasmoutput;size : tcgsize;cmp_op : topcmp;a : aword;const loc : tlocation;
  1026. l : tasmlabel);
  1027. begin
  1028. case loc.loc of
  1029. LOC_REGISTER,LOC_CREGISTER:
  1030. a_cmp_const_reg_label(list,size,cmp_op,a,loc.register,l);
  1031. LOC_REFERENCE,LOC_CREFERENCE:
  1032. a_cmp_const_ref_label(list,size,cmp_op,a,loc.reference,l);
  1033. else
  1034. internalerror(200109061);
  1035. end;
  1036. end;
  1037. procedure tcg.a_cmp_ref_reg_label(list : taasmoutput;size : tcgsize;cmp_op : topcmp; const ref: treference; reg : tregister; l : tasmlabel);
  1038. var
  1039. tmpreg: tregister;
  1040. begin
  1041. tmpreg:=getintregister(list,size);
  1042. a_load_ref_reg(list,size,size,ref,tmpreg);
  1043. a_cmp_reg_reg_label(list,size,cmp_op,tmpreg,reg,l);
  1044. ungetregister(list,tmpreg);
  1045. end;
  1046. procedure tcg.a_cmp_loc_reg_label(list : taasmoutput;size : tcgsize;cmp_op : topcmp; const loc: tlocation; reg : tregister; l : tasmlabel);
  1047. begin
  1048. case loc.loc of
  1049. LOC_REGISTER,
  1050. LOC_CREGISTER:
  1051. a_cmp_reg_reg_label(list,size,cmp_op,loc.register,reg,l);
  1052. LOC_REFERENCE,
  1053. LOC_CREFERENCE :
  1054. a_cmp_ref_reg_label(list,size,cmp_op,loc.reference,reg,l);
  1055. LOC_CONSTANT:
  1056. a_cmp_const_reg_label(list,size,cmp_op,loc.value,reg,l);
  1057. else
  1058. internalerror(200203231);
  1059. end;
  1060. end;
  1061. procedure tcg.a_cmp_ref_loc_label(list : taasmoutput;size : tcgsize;cmp_op : topcmp;const ref: treference;const loc : tlocation;
  1062. l : tasmlabel);
  1063. var
  1064. tmpreg: tregister;
  1065. begin
  1066. case loc.loc of
  1067. LOC_REGISTER,LOC_CREGISTER:
  1068. a_cmp_ref_reg_label(list,size,cmp_op,ref,loc.register,l);
  1069. LOC_REFERENCE,LOC_CREFERENCE:
  1070. begin
  1071. tmpreg:=getintregister(list,size);
  1072. a_load_ref_reg(list,size,size,loc.reference,tmpreg);
  1073. a_cmp_ref_reg_label(list,size,cmp_op,ref,tmpreg,l);
  1074. ungetregister(list,tmpreg);
  1075. end
  1076. else
  1077. internalerror(200109061);
  1078. end;
  1079. end;
  1080. procedure tcg.a_loadmm_loc_reg(list: taasmoutput; size: tcgsize; const loc: tlocation; const reg: tregister;shuffle : pmmshuffle);
  1081. begin
  1082. case loc.loc of
  1083. LOC_MMREGISTER,LOC_CMMREGISTER:
  1084. a_loadmm_reg_reg(list,loc.size,size,loc.register,reg,shuffle);
  1085. LOC_REFERENCE,LOC_CREFERENCE:
  1086. a_loadmm_ref_reg(list,loc.size,size,loc.reference,reg,shuffle);
  1087. else
  1088. internalerror(200310121);
  1089. end;
  1090. end;
  1091. procedure tcg.a_loadmm_reg_loc(list: taasmoutput; size: tcgsize; const reg: tregister; const loc: tlocation;shuffle : pmmshuffle);
  1092. var
  1093. tmpreg: tregister;
  1094. begin
  1095. case loc.loc of
  1096. LOC_MMREGISTER,LOC_CMMREGISTER:
  1097. a_loadmm_reg_reg(list,size,loc.size,reg,loc.register,shuffle);
  1098. LOC_REFERENCE,LOC_CREFERENCE:
  1099. a_loadmm_reg_ref(list,size,loc.size,reg,loc.reference,shuffle);
  1100. else
  1101. internalerror(200310122);
  1102. end;
  1103. end;
  1104. procedure tcg.a_parammm_reg(list: taasmoutput; size: tcgsize; reg: tregister;const locpara : tparalocation;shuffle : pmmshuffle);
  1105. var
  1106. ref : treference;
  1107. begin
  1108. case locpara.loc of
  1109. LOC_MMREGISTER,LOC_CMMREGISTER:
  1110. a_loadmm_reg_reg(list,size,locpara.size,reg,locpara.register,shuffle);
  1111. LOC_REFERENCE,LOC_CREFERENCE:
  1112. begin
  1113. reference_reset(ref);
  1114. ref.base:=locpara.reference.index;
  1115. ref.offset:=locpara.reference.offset;
  1116. a_loadmm_reg_ref(list,size,locpara.size,reg,ref,shuffle);
  1117. end
  1118. else
  1119. internalerror(200310123);
  1120. end;
  1121. end;
  1122. procedure tcg.a_parammm_ref(list: taasmoutput; size: tcgsize; ref: treference;const locpara : tparalocation;shuffle : pmmshuffle);
  1123. var
  1124. hr : tregister;
  1125. hs : tmmshuffle;
  1126. begin
  1127. hr:=getmmregister(list,locpara.size);
  1128. a_loadmm_ref_reg(list,size,locpara.size,ref,hr,shuffle);
  1129. if realshuffle(shuffle) then
  1130. begin
  1131. hs:=shuffle^;
  1132. removeshuffles(hs);
  1133. a_parammm_reg(list,locpara.size,hr,locpara,@hs);
  1134. end
  1135. else
  1136. a_parammm_reg(list,locpara.size,hr,locpara,shuffle);
  1137. ungetregister(list,hr);
  1138. end;
  1139. procedure tcg.a_parammm_loc(list: taasmoutput; loc: tlocation; const locpara : tparalocation;shuffle : pmmshuffle);
  1140. begin
  1141. case loc.loc of
  1142. LOC_MMREGISTER,LOC_CMMREGISTER:
  1143. a_parammm_reg(list,loc.size,loc.register,locpara,shuffle);
  1144. LOC_REFERENCE,LOC_CREFERENCE:
  1145. a_parammm_ref(list,loc.size,loc.reference,locpara,shuffle);
  1146. else
  1147. internalerror(200310123);
  1148. end;
  1149. end;
  1150. class function tcg.reg_cgsize(const reg: tregister) : tcgsize;
  1151. begin
  1152. reg_cgsize := OS_INT;
  1153. end;
  1154. procedure tcg.g_copyshortstring(list : taasmoutput;const source,dest : treference;len:byte;delsource,loadref : boolean);
  1155. var
  1156. paraloc1,paraloc2,paraloc3 : tparalocation;
  1157. begin
  1158. {$ifdef FPC}
  1159. {$warning FIX ME!}
  1160. {$endif}
  1161. paraloc1:=paramanager.getintparaloc(pocall_default,1);
  1162. paraloc2:=paramanager.getintparaloc(pocall_default,2);
  1163. paraloc3:=paramanager.getintparaloc(pocall_default,3);
  1164. paramanager.allocparaloc(list,paraloc3);
  1165. a_paramaddr_ref(list,dest,paraloc3);
  1166. paramanager.allocparaloc(list,paraloc2);
  1167. if loadref then
  1168. a_param_ref(list,OS_ADDR,source,paraloc2)
  1169. else
  1170. a_paramaddr_ref(list,source,paraloc2);
  1171. if delsource then
  1172. reference_release(list,source);
  1173. paramanager.allocparaloc(list,paraloc1);
  1174. a_param_const(list,OS_INT,len,paraloc1);
  1175. paramanager.freeparaloc(list,paraloc3);
  1176. paramanager.freeparaloc(list,paraloc2);
  1177. paramanager.freeparaloc(list,paraloc1);
  1178. allocexplicitregisters(list,R_INTREGISTER,paramanager.get_volatile_registers_int(pocall_default));
  1179. a_call_name(list,'FPC_SHORTSTR_ASSIGN');
  1180. deallocexplicitregisters(list,R_INTREGISTER,paramanager.get_volatile_registers_int(pocall_default));
  1181. end;
  1182. procedure tcg.g_incrrefcount(list : taasmoutput;t: tdef; const ref: treference;loadref : boolean);
  1183. var
  1184. href : treference;
  1185. incrfunc : string;
  1186. paraloc1,paraloc2 : tparalocation;
  1187. begin
  1188. paraloc1:=paramanager.getintparaloc(pocall_default,1);
  1189. paraloc2:=paramanager.getintparaloc(pocall_default,2);
  1190. { These functions should not change the registers (they use
  1191. the saveregister proc directive }
  1192. if is_interfacecom(t) then
  1193. incrfunc:='FPC_INTF_INCR_REF'
  1194. else if is_ansistring(t) then
  1195. incrfunc:='FPC_ANSISTR_INCR_REF'
  1196. else if is_widestring(t) then
  1197. incrfunc:='FPC_WIDESTR_INCR_REF'
  1198. else if is_dynamic_array(t) then
  1199. incrfunc:='FPC_DYNARRAY_INCR_REF'
  1200. else
  1201. incrfunc:='';
  1202. { call the special incr function or the generic addref }
  1203. if incrfunc<>'' then
  1204. begin
  1205. { these functions get the pointer by value }
  1206. paramanager.allocparaloc(list,paraloc1);
  1207. a_param_ref(list,OS_ADDR,ref,paraloc1);
  1208. paramanager.freeparaloc(list,paraloc1);
  1209. allocexplicitregisters(list,R_INTREGISTER,paramanager.get_volatile_registers_int(pocall_default));
  1210. a_call_name(list,incrfunc);
  1211. deallocexplicitregisters(list,R_INTREGISTER,paramanager.get_volatile_registers_int(pocall_default));
  1212. end
  1213. else
  1214. begin
  1215. reference_reset_symbol(href,tstoreddef(t).get_rtti_label(initrtti),0);
  1216. paramanager.allocparaloc(list,paraloc2);
  1217. a_paramaddr_ref(list,href,paraloc2);
  1218. paramanager.allocparaloc(list,paraloc1);
  1219. if loadref then
  1220. a_param_ref(list,OS_ADDR,ref,paraloc1)
  1221. else
  1222. a_paramaddr_ref(list,ref,paraloc1);
  1223. paramanager.freeparaloc(list,paraloc1);
  1224. paramanager.freeparaloc(list,paraloc2);
  1225. allocexplicitregisters(list,R_INTREGISTER,paramanager.get_volatile_registers_int(pocall_default));
  1226. a_call_name(list,'FPC_ADDREF');
  1227. deallocexplicitregisters(list,R_INTREGISTER,paramanager.get_volatile_registers_int(pocall_default));
  1228. end;
  1229. end;
  1230. procedure tcg.g_decrrefcount(list : taasmoutput;t: tdef; const ref: treference; loadref:boolean);
  1231. var
  1232. href : treference;
  1233. decrfunc : string;
  1234. needrtti : boolean;
  1235. paraloc1,paraloc2 : tparalocation;
  1236. begin
  1237. paraloc1:=paramanager.getintparaloc(pocall_default,1);
  1238. paraloc2:=paramanager.getintparaloc(pocall_default,2);
  1239. needrtti:=false;
  1240. if is_interfacecom(t) then
  1241. decrfunc:='FPC_INTF_DECR_REF'
  1242. else if is_ansistring(t) then
  1243. decrfunc:='FPC_ANSISTR_DECR_REF'
  1244. else if is_widestring(t) then
  1245. decrfunc:='FPC_WIDESTR_DECR_REF'
  1246. else if is_dynamic_array(t) then
  1247. begin
  1248. decrfunc:='FPC_DYNARRAY_DECR_REF';
  1249. needrtti:=true;
  1250. end
  1251. else
  1252. decrfunc:='';
  1253. { call the special decr function or the generic decref }
  1254. if decrfunc<>'' then
  1255. begin
  1256. if needrtti then
  1257. begin
  1258. reference_reset_symbol(href,tstoreddef(t).get_rtti_label(initrtti),0);
  1259. paramanager.allocparaloc(list,paraloc2);
  1260. a_paramaddr_ref(list,href,paraloc2);
  1261. end;
  1262. paramanager.allocparaloc(list,paraloc1);
  1263. if loadref then
  1264. a_param_ref(list,OS_ADDR,ref,paraloc1)
  1265. else
  1266. a_paramaddr_ref(list,ref,paraloc1);
  1267. paramanager.freeparaloc(list,paraloc1);
  1268. if needrtti then
  1269. paramanager.freeparaloc(list,paraloc2);
  1270. allocexplicitregisters(list,R_INTREGISTER,paramanager.get_volatile_registers_int(pocall_default));
  1271. a_call_name(list,decrfunc);
  1272. deallocexplicitregisters(list,R_INTREGISTER,paramanager.get_volatile_registers_int(pocall_default));
  1273. end
  1274. else
  1275. begin
  1276. reference_reset_symbol(href,tstoreddef(t).get_rtti_label(initrtti),0);
  1277. paramanager.allocparaloc(list,paraloc2);
  1278. a_paramaddr_ref(list,href,paraloc2);
  1279. paramanager.allocparaloc(list,paraloc1);
  1280. if loadref then
  1281. a_param_ref(list,OS_ADDR,ref,paraloc1)
  1282. else
  1283. a_paramaddr_ref(list,ref,paraloc1);
  1284. paramanager.freeparaloc(list,paraloc1);
  1285. paramanager.freeparaloc(list,paraloc2);
  1286. allocexplicitregisters(list,R_INTREGISTER,paramanager.get_volatile_registers_int(pocall_default));
  1287. a_call_name(list,'FPC_DECREF');
  1288. deallocexplicitregisters(list,R_INTREGISTER,paramanager.get_volatile_registers_int(pocall_default));
  1289. end;
  1290. end;
  1291. procedure tcg.g_initialize(list : taasmoutput;t : tdef;const ref : treference;loadref : boolean);
  1292. var
  1293. href : treference;
  1294. paraloc1,paraloc2 : tparalocation;
  1295. begin
  1296. paraloc1:=paramanager.getintparaloc(pocall_default,1);
  1297. paraloc2:=paramanager.getintparaloc(pocall_default,2);
  1298. if is_ansistring(t) or
  1299. is_widestring(t) or
  1300. is_interfacecom(t) then
  1301. a_load_const_ref(list,OS_ADDR,0,ref)
  1302. else
  1303. begin
  1304. reference_reset_symbol(href,tstoreddef(t).get_rtti_label(initrtti),0);
  1305. paramanager.allocparaloc(list,paraloc2);
  1306. a_paramaddr_ref(list,href,paraloc2);
  1307. paramanager.allocparaloc(list,paraloc1);
  1308. if loadref then
  1309. a_param_ref(list,OS_ADDR,ref,paraloc1)
  1310. else
  1311. a_paramaddr_ref(list,ref,paraloc1);
  1312. paramanager.freeparaloc(list,paraloc1);
  1313. paramanager.freeparaloc(list,paraloc2);
  1314. allocexplicitregisters(list,R_INTREGISTER,paramanager.get_volatile_registers_int(pocall_default));
  1315. a_call_name(list,'FPC_INITIALIZE');
  1316. deallocexplicitregisters(list,R_INTREGISTER,paramanager.get_volatile_registers_int(pocall_default));
  1317. end;
  1318. end;
  1319. procedure tcg.g_finalize(list : taasmoutput;t : tdef;const ref : treference;loadref : boolean);
  1320. var
  1321. href : treference;
  1322. paraloc1,paraloc2 : tparalocation;
  1323. begin
  1324. paraloc1:=paramanager.getintparaloc(pocall_default,1);
  1325. paraloc2:=paramanager.getintparaloc(pocall_default,2);
  1326. if is_ansistring(t) or
  1327. is_widestring(t) or
  1328. is_interfacecom(t) then
  1329. g_decrrefcount(list,t,ref,loadref)
  1330. else
  1331. begin
  1332. reference_reset_symbol(href,tstoreddef(t).get_rtti_label(initrtti),0);
  1333. paramanager.allocparaloc(list,paraloc2);
  1334. a_paramaddr_ref(list,href,paraloc2);
  1335. paramanager.allocparaloc(list,paraloc1);
  1336. if loadref then
  1337. a_param_ref(list,OS_ADDR,ref,paraloc1)
  1338. else
  1339. a_paramaddr_ref(list,ref,paraloc1);
  1340. paramanager.freeparaloc(list,paraloc1);
  1341. paramanager.freeparaloc(list,paraloc2);
  1342. allocexplicitregisters(list,R_INTREGISTER,paramanager.get_volatile_registers_int(pocall_default));
  1343. a_call_name(list,'FPC_FINALIZE');
  1344. deallocexplicitregisters(list,R_INTREGISTER,paramanager.get_volatile_registers_int(pocall_default));
  1345. end;
  1346. end;
  1347. procedure tcg.g_rangecheck(list: taasmoutput; const l:tlocation;fromdef,todef: tdef);
  1348. { generate range checking code for the value at location p. The type }
  1349. { type used is checked against todefs ranges. fromdef (p.resulttype.def) }
  1350. { is the original type used at that location. When both defs are equal }
  1351. { the check is also insert (needed for succ,pref,inc,dec) }
  1352. const
  1353. {$ifdef ver1_0}
  1354. awordsignedmax=high(longint);
  1355. {$else}
  1356. awordsignedmax=high(aword) div 2;
  1357. {$endif}
  1358. var
  1359. neglabel : tasmlabel;
  1360. hreg : tregister;
  1361. lto,hto,
  1362. lfrom,hfrom : TConstExprInt;
  1363. from_signed: boolean;
  1364. begin
  1365. { range checking on and range checkable value? }
  1366. if not(cs_check_range in aktlocalswitches) or
  1367. not(fromdef.deftype in [orddef,enumdef,arraydef]) then
  1368. exit;
  1369. if is_64bit(fromdef) or is_64bit(todef) then
  1370. begin
  1371. cg64.g_rangecheck64(list,l,fromdef,todef);
  1372. exit;
  1373. end;
  1374. { only check when assigning to scalar, subranges are different, }
  1375. { when todef=fromdef then the check is always generated }
  1376. getrange(fromdef,lfrom,hfrom);
  1377. getrange(todef,lto,hto);
  1378. { no range check if from and to are equal and are both longint/dword }
  1379. { (if we have a 32bit processor) or int64/qword, since such }
  1380. { operations can at most cause overflows (JM) }
  1381. { Note that these checks are mostly processor independent, they only }
  1382. { have to be changed once we introduce 64bit subrange types }
  1383. if (fromdef = todef) and
  1384. (fromdef.deftype=orddef) and
  1385. (((sizeof(aword) = 4) and
  1386. (((torddef(fromdef).typ = s32bit) and
  1387. (lfrom = low(longint)) and
  1388. (hfrom = high(longint))) or
  1389. ((torddef(fromdef).typ = u32bit) and
  1390. (lfrom = low(cardinal)) and
  1391. (hfrom = high(cardinal)))))) then
  1392. exit;
  1393. if todef<>fromdef then
  1394. begin
  1395. { if the from-range falls completely in the to-range, no check }
  1396. { is necessary }
  1397. if (lto<=lfrom) and (hto>=hfrom) then
  1398. exit;
  1399. end;
  1400. { generate the rangecheck code for the def where we are going to }
  1401. { store the result }
  1402. { use the trick that }
  1403. { a <= x <= b <=> 0 <= x-a <= b-a <=> unsigned(x-a) <= unsigned(b-a) }
  1404. { To be able to do that, we have to make sure however that either }
  1405. { fromdef and todef are both signed or unsigned, or that we leave }
  1406. { the parts < 0 and > maxlongint out }
  1407. { is_signed now also works for arrays (it checks the rangetype) (JM) }
  1408. from_signed := is_signed(fromdef);
  1409. if from_signed xor is_signed(todef) then
  1410. if from_signed then
  1411. { from is signed, to is unsigned }
  1412. begin
  1413. { if high(from) < 0 -> always range error }
  1414. if (hfrom < 0) or
  1415. { if low(to) > maxlongint also range error }
  1416. (lto > awordsignedmax) then
  1417. begin
  1418. a_call_name(list,'FPC_RANGEERROR');
  1419. exit
  1420. end;
  1421. { from is signed and to is unsigned -> when looking at from }
  1422. { as an unsigned value, it must be < maxlongint (otherwise }
  1423. { it's negative, which is invalid since "to" is unsigned) }
  1424. if hto > awordsignedmax then
  1425. hto := awordsignedmax;
  1426. end
  1427. else
  1428. { from is unsigned, to is signed }
  1429. begin
  1430. if (lfrom > awordsignedmax) or
  1431. (hto < 0) then
  1432. begin
  1433. a_call_name(list,'FPC_RANGEERROR');
  1434. exit
  1435. end;
  1436. { from is unsigned and to is signed -> when looking at to }
  1437. { as an unsigned value, it must be >= 0 (since negative }
  1438. { values are the same as values > maxlongint) }
  1439. if lto < 0 then
  1440. lto := 0;
  1441. end;
  1442. hreg:=getintregister(list,OS_INT);
  1443. a_load_loc_reg(list,OS_INT,l,hreg);
  1444. a_op_const_reg(list,OP_SUB,OS_INT,aword(lto),hreg);
  1445. objectlibrary.getlabel(neglabel);
  1446. a_cmp_const_reg_label(list,OS_INT,OC_BE,aword(hto-lto),hreg,neglabel);
  1447. { !!! should happen right after the compare (JM) }
  1448. ungetregister(list,hreg);
  1449. a_call_name(list,'FPC_RANGEERROR');
  1450. a_label(list,neglabel);
  1451. end;
  1452. procedure tcg.g_stackcheck(list : taasmoutput;stackframesize : longint);
  1453. var
  1454. paraloc1 : tparalocation;
  1455. begin
  1456. paraloc1:=paramanager.getintparaloc(pocall_default,1);
  1457. paramanager.allocparaloc(list,paraloc1);
  1458. a_param_const(list,OS_32,stackframesize,paraloc1);
  1459. paramanager.freeparaloc(list,paraloc1);
  1460. { No register saving needed, saveregisters is used }
  1461. {$ifndef x86}
  1462. allocexplicitregisters(list,R_INTREGISTER,paramanager.get_volatile_registers_int(pocall_default));
  1463. {$endif x86}
  1464. a_call_name(list,'FPC_STACKCHECK');
  1465. {$ifndef x86}
  1466. deallocexplicitregisters(list,R_INTREGISTER,paramanager.get_volatile_registers_int(pocall_default));
  1467. {$endif x86}
  1468. end;
  1469. procedure tcg.g_flags2ref(list: taasmoutput; size: TCgSize; const f: tresflags; const ref:TReference);
  1470. var
  1471. tmpreg : tregister;
  1472. begin
  1473. tmpreg:=getintregister(list,size);
  1474. g_flags2reg(list,size,f,tmpreg);
  1475. a_load_reg_ref(list,size,size,tmpreg,ref);
  1476. ungetregister(list,tmpreg);
  1477. end;
  1478. procedure tcg.g_maybe_testself(list : taasmoutput;reg:tregister);
  1479. var
  1480. OKLabel : tasmlabel;
  1481. paraloc1 : tparalocation;
  1482. begin
  1483. if (cs_check_object in aktlocalswitches) or
  1484. (cs_check_range in aktlocalswitches) then
  1485. begin
  1486. objectlibrary.getlabel(oklabel);
  1487. a_cmp_const_reg_label(list,OS_ADDR,OC_NE,0,reg,oklabel);
  1488. paraloc1:=paramanager.getintparaloc(pocall_default,1);
  1489. paramanager.allocparaloc(list,paraloc1);
  1490. a_param_const(list,OS_INT,210,paraloc1);
  1491. paramanager.freeparaloc(list,paraloc1);
  1492. a_call_name(list,'FPC_HANDLEERROR');
  1493. a_label(list,oklabel);
  1494. end;
  1495. end;
  1496. procedure tcg.g_maybe_testvmt(list : taasmoutput;reg:tregister;objdef:tobjectdef);
  1497. var
  1498. hrefvmt : treference;
  1499. paraloc1,paraloc2 : tparalocation;
  1500. begin
  1501. paraloc1:=paramanager.getintparaloc(pocall_default,1);
  1502. paraloc2:=paramanager.getintparaloc(pocall_default,2);
  1503. if (cs_check_object in aktlocalswitches) then
  1504. begin
  1505. reference_reset_symbol(hrefvmt,objectlibrary.newasmsymboldata(objdef.vmt_mangledname),0);
  1506. paramanager.allocparaloc(list,paraloc2);
  1507. a_paramaddr_ref(list,hrefvmt,paraloc2);
  1508. paramanager.allocparaloc(list,paraloc1);
  1509. a_param_reg(list,OS_ADDR,reg,paraloc1);
  1510. paramanager.freeparaloc(list,paraloc1);
  1511. paramanager.freeparaloc(list,paraloc2);
  1512. { No register saving needed, saveregisters is used }
  1513. {$ifndef x86}
  1514. allocexplicitregisters(list,R_INTREGISTER,paramanager.get_volatile_registers_int(pocall_default));
  1515. {$endif x86}
  1516. a_call_name(list,'FPC_CHECK_OBJECT_EXT');
  1517. {$ifndef x86}
  1518. deallocexplicitregisters(list,R_INTREGISTER,paramanager.get_volatile_registers_int(pocall_default));
  1519. {$endif x86}
  1520. end
  1521. else
  1522. if (cs_check_range in aktlocalswitches) then
  1523. begin
  1524. paramanager.allocparaloc(list,paraloc1);
  1525. a_param_reg(list,OS_ADDR,reg,paraloc1);
  1526. paramanager.freeparaloc(list,paraloc1);
  1527. { No register saving needed, saveregisters is used }
  1528. {$ifndef x86}
  1529. allocexplicitregisters(list,R_INTREGISTER,paramanager.get_volatile_registers_int(pocall_default));
  1530. {$endif x86}
  1531. a_call_name(list,'FPC_CHECK_OBJECT');
  1532. {$ifndef x86}
  1533. deallocexplicitregisters(list,R_INTREGISTER,paramanager.get_volatile_registers_int(pocall_default));
  1534. {$endif x86}
  1535. end;
  1536. end;
  1537. {*****************************************************************************
  1538. Entry/Exit Code Functions
  1539. *****************************************************************************}
  1540. procedure tcg.g_releasevaluepara_openarray(list : taasmoutput;const ref:treference);
  1541. begin
  1542. end;
  1543. procedure tcg.g_interrupt_stackframe_entry(list : taasmoutput);
  1544. begin
  1545. end;
  1546. procedure tcg.g_interrupt_stackframe_exit(list : taasmoutput;accused,acchiused:boolean);
  1547. begin
  1548. end;
  1549. procedure tcg.g_profilecode(list : taasmoutput);
  1550. begin
  1551. end;
  1552. procedure tcg.g_exception_reason_save(list : taasmoutput; const href : treference);
  1553. begin
  1554. a_load_reg_ref(list, OS_S32, OS_32, NR_FUNCTION_RETURN_REG, href);
  1555. end;
  1556. procedure tcg.g_exception_reason_save_const(list : taasmoutput; const href : treference; a: aword);
  1557. begin
  1558. a_load_const_ref(list, OS_S32, a, href);
  1559. end;
  1560. procedure tcg.g_exception_reason_load(list : taasmoutput; const href : treference);
  1561. begin
  1562. a_load_ref_reg(list, OS_S32, OS_S32, href, NR_FUNCTION_RETURN_REG);
  1563. end;
  1564. {*****************************************************************************
  1565. TCG64
  1566. *****************************************************************************}
  1567. procedure tcg64.a_op64_const_reg_reg(list: taasmoutput;op:TOpCG;value : qword; regsrc,regdst : tregister64);
  1568. begin
  1569. a_load64_reg_reg(list,regsrc,regdst,false);
  1570. a_op64_const_reg(list,op,value,regdst);
  1571. end;
  1572. procedure tcg64.a_op64_reg_reg_reg(list: taasmoutput;op:TOpCG;regsrc1,regsrc2,regdst : tregister64);
  1573. begin
  1574. a_load64_reg_reg(list,regsrc2,regdst,false);
  1575. a_op64_reg_reg(list,op,regsrc1,regdst);
  1576. end;
  1577. {****************************************************************************
  1578. TReference
  1579. ****************************************************************************}
  1580. procedure reference_reset(var ref : treference);
  1581. begin
  1582. FillChar(ref,sizeof(treference),0);
  1583. {$ifdef arm}
  1584. ref.signindex:=1;
  1585. {$endif arm}
  1586. end;
  1587. procedure reference_reset_base(var ref : treference;base : tregister;offset : longint);
  1588. begin
  1589. reference_reset(ref);
  1590. ref.base:=base;
  1591. ref.offset:=offset;
  1592. end;
  1593. procedure reference_reset_symbol(var ref : treference;sym : tasmsymbol;offset : longint);
  1594. begin
  1595. reference_reset(ref);
  1596. ref.symbol:=sym;
  1597. ref.offset:=offset;
  1598. end;
  1599. procedure reference_release(list: taasmoutput; const ref : treference);
  1600. begin
  1601. cg.ungetreference(list,ref);
  1602. end;
  1603. function references_equal(sref : treference;dref : treference):boolean;
  1604. begin
  1605. references_equal:=CompareByte(sref,dref,sizeof(treference))=0;
  1606. end;
  1607. {****************************************************************************
  1608. TLocation
  1609. ****************************************************************************}
  1610. procedure location_reset(var l : tlocation;lt:TCGLoc;lsize:TCGSize);
  1611. begin
  1612. FillChar(l,sizeof(tlocation),0);
  1613. l.loc:=lt;
  1614. l.size:=lsize;
  1615. {$ifdef arm}
  1616. if l.loc in [LOC_REFERENCE,LOC_CREFERENCE] then
  1617. l.reference.signindex:=1;
  1618. {$endif arm}
  1619. end;
  1620. procedure location_release(list: taasmoutput; const l : tlocation);
  1621. begin
  1622. case l.loc of
  1623. LOC_REGISTER,LOC_CREGISTER :
  1624. begin
  1625. cg.ungetregister(list,l.register);
  1626. if l.size in [OS_64,OS_S64] then
  1627. cg.ungetregister(list,l.registerhigh);
  1628. end;
  1629. LOC_FPUREGISTER,LOC_CFPUREGISTER :
  1630. cg.ungetregister(list,l.register);
  1631. LOC_CREFERENCE,LOC_REFERENCE :
  1632. cg.ungetreference(list, l.reference);
  1633. end;
  1634. end;
  1635. procedure location_freetemp(list:taasmoutput; const l : tlocation);
  1636. begin
  1637. if (l.loc in [LOC_REFERENCE,LOC_CREFERENCE]) then
  1638. tg.ungetiftemp(list,l.reference);
  1639. end;
  1640. procedure location_copy(var destloc:tlocation; const sourceloc : tlocation);
  1641. begin
  1642. destloc:=sourceloc;
  1643. end;
  1644. procedure location_swap(var destloc,sourceloc : tlocation);
  1645. var
  1646. swapl : tlocation;
  1647. begin
  1648. swapl := destloc;
  1649. destloc := sourceloc;
  1650. sourceloc := swapl;
  1651. end;
  1652. initialization
  1653. ;
  1654. finalization
  1655. cg.free;
  1656. cg64.free;
  1657. end.
  1658. {
  1659. $Log$
  1660. Revision 1.138 2003-12-12 17:16:17 peter
  1661. * rg[tregistertype] added in tcg
  1662. Revision 1.137 2003/12/06 22:11:47 jonas
  1663. + allocate volatile registers around calls to procedures declared with
  1664. "saveregisters" on non-x86 processors
  1665. Revision 1.136 2003/12/06 01:15:22 florian
  1666. * reverted Peter's alloctemp patch; hopefully properly
  1667. Revision 1.135 2003/12/03 23:13:19 peter
  1668. * delayed paraloc allocation, a_param_*() gets extra parameter
  1669. if it needs to allocate temp or real paralocation
  1670. * optimized/simplified int-real loading
  1671. Revision 1.134 2003/11/05 23:05:13 florian
  1672. * elesize of g_copyvaluepara_openarray changed
  1673. + g_releaesvaluepara_openarray added
  1674. Revision 1.133 2003/10/19 01:34:30 florian
  1675. * some ppc stuff fixed
  1676. * memory leak fixed
  1677. Revision 1.132 2003/10/17 15:25:18 florian
  1678. * fixed more ppc stuff
  1679. Revision 1.131 2003/10/17 14:38:32 peter
  1680. * 64k registers supported
  1681. * fixed some memory leaks
  1682. Revision 1.130 2003/10/13 01:23:13 florian
  1683. * some ideas for mm support implemented
  1684. Revision 1.129 2003/10/11 16:06:42 florian
  1685. * fixed some MMX<->SSE
  1686. * started to fix ppc, needs an overhaul
  1687. + stabs info improve for spilling, not sure if it works correctly/completly
  1688. - MMX_SUPPORT removed from Makefile.fpc
  1689. Revision 1.128 2003/10/10 17:48:13 peter
  1690. * old trgobj moved to x86/rgcpu and renamed to trgx86fpu
  1691. * tregisteralloctor renamed to trgobj
  1692. * removed rgobj from a lot of units
  1693. * moved location_* and reference_* to cgobj
  1694. * first things for mmx register allocation
  1695. Revision 1.127 2003/10/09 21:31:37 daniel
  1696. * Register allocator splitted, ans abstract now
  1697. Revision 1.126 2003/10/01 20:34:48 peter
  1698. * procinfo unit contains tprocinfo
  1699. * cginfo renamed to cgbase
  1700. * moved cgmessage to verbose
  1701. * fixed ppc and sparc compiles
  1702. Revision 1.125 2003/09/28 17:55:03 peter
  1703. * parent framepointer changed to hidden parameter
  1704. * tloadparentfpnode added
  1705. Revision 1.124 2003/09/28 13:40:13 peter
  1706. * a_call_ref removed
  1707. Revision 1.123 2003/09/25 21:26:24 peter
  1708. * remove obsolete tparalocation.sp_fixup
  1709. Revision 1.122 2003/09/23 20:37:16 peter
  1710. * fpc_check_object(_ext) has saveregisters and doesn't need
  1711. saving of registers
  1712. Revision 1.121 2003/09/10 08:31:47 marco
  1713. * Patch from Peter for paraloc
  1714. Revision 1.120 2003/09/09 20:59:27 daniel
  1715. * Adding register allocation order
  1716. Revision 1.119 2003/09/07 22:09:34 peter
  1717. * preparations for different default calling conventions
  1718. * various RA fixes
  1719. Revision 1.118 2003/09/03 15:55:00 peter
  1720. * NEWRA branch merged
  1721. Revision 1.117 2003/09/03 11:18:36 florian
  1722. * fixed arm concatcopy
  1723. + arm support in the common compiler sources added
  1724. * moved some generic cg code around
  1725. + tfputype added
  1726. * ...
  1727. Revision 1.116.2.4 2003/08/29 17:28:59 peter
  1728. * next batch of updates
  1729. Revision 1.116.2.3 2003/08/28 18:35:07 peter
  1730. * tregister changed to cardinal
  1731. Revision 1.116.2.2 2003/08/27 20:23:55 peter
  1732. * remove old ra code
  1733. Revision 1.116.2.1 2003/08/27 19:55:54 peter
  1734. * first tregister patch
  1735. Revision 1.116 2003/08/17 16:59:20 jonas
  1736. * fixed regvars so they work with newra (at least for ppc)
  1737. * fixed some volatile register bugs
  1738. + -dnotranslation option for -dnewra, which causes the registers not to
  1739. be translated from virtual to normal registers. Requires support in
  1740. the assembler writer as well, which is only implemented in aggas/
  1741. agppcgas currently
  1742. Revision 1.115 2003/07/23 11:01:14 jonas
  1743. * several rg.allocexplicitregistersint/rg.deallocexplicitregistersint
  1744. pairs round calls to helpers
  1745. Revision 1.114 2003/07/06 17:58:22 peter
  1746. * framepointer fixes for sparc
  1747. * parent framepointer code more generic
  1748. Revision 1.113 2003/07/02 22:18:04 peter
  1749. * paraloc splitted in callerparaloc,calleeparaloc
  1750. * sparc calling convention updates
  1751. Revision 1.112 2003/06/13 21:19:30 peter
  1752. * current_procdef removed, use current_procinfo.procdef instead
  1753. Revision 1.111 2003/06/12 21:11:10 peter
  1754. * ungetregisterfpu gets size parameter
  1755. Revision 1.110 2003/06/12 16:43:07 peter
  1756. * newra compiles for sparc
  1757. Revision 1.109 2003/06/07 18:57:04 jonas
  1758. + added freeintparaloc
  1759. * ppc get/freeintparaloc now check whether the parameter regs are
  1760. properly allocated/deallocated (and get an extra list para)
  1761. * ppc a_call_* now internalerrors if pi_do_call is not yet set
  1762. * fixed lot of missing pi_do_call's
  1763. Revision 1.108 2003/06/06 14:43:02 peter
  1764. * g_copyopenarrayvalue gets length reference
  1765. * don't copy open arrays for cdecl
  1766. Revision 1.107 2003/06/03 21:11:09 peter
  1767. * cg.a_load_* get a from and to size specifier
  1768. * makeregsize only accepts newregister
  1769. * i386 uses generic tcgnotnode,tcgunaryminus
  1770. Revision 1.106 2003/06/03 13:01:59 daniel
  1771. * Register allocator finished
  1772. Revision 1.105 2003/06/01 21:38:06 peter
  1773. * getregisterfpu size parameter added
  1774. * op_const_reg size parameter added
  1775. * sparc updates
  1776. Revision 1.104 2003/06/01 01:02:39 peter
  1777. * generic a_call_ref
  1778. Revision 1.103 2003/05/30 23:57:08 peter
  1779. * more sparc cleanup
  1780. * accumulator removed, splitted in function_return_reg (called) and
  1781. function_result_reg (caller)
  1782. Revision 1.102 2003/05/30 23:49:18 jonas
  1783. * a_load_loc_reg now has an extra size parameter for the destination
  1784. register (properly fixes what I worked around in revision 1.106 of
  1785. ncgutil.pas)
  1786. Revision 1.101 2003/05/30 21:40:00 jonas
  1787. * fixed bug in a_load_loc_ref (the source instead of dest size was passed
  1788. to a_load_reg_ref in case of a register)
  1789. Revision 1.100 2003/05/30 12:36:13 jonas
  1790. * use as little different registers on the ppc until newra is released,
  1791. since every used register must be saved
  1792. Revision 1.99 2003/05/23 14:27:35 peter
  1793. * remove some unit dependencies
  1794. * current_procinfo changes to store more info
  1795. Revision 1.98 2003/05/15 18:58:53 peter
  1796. * removed selfpointer_offset, vmtpointer_offset
  1797. * tvarsym.adjusted_address
  1798. * address in localsymtable is now in the real direction
  1799. * removed some obsolete globals
  1800. Revision 1.97 2003/05/13 19:14:41 peter
  1801. * failn removed
  1802. * inherited result code check moven to pexpr
  1803. Revision 1.96 2003/05/11 21:37:03 peter
  1804. * moved implicit exception frame from ncgutil to psub
  1805. * constructor/destructor helpers moved from cobj/ncgutil to psub
  1806. Revision 1.95 2003/05/09 17:47:02 peter
  1807. * self moved to hidden parameter
  1808. * removed hdisposen,hnewn,selfn
  1809. Revision 1.94 2003/05/01 12:23:46 jonas
  1810. * fix for op_reg_reg_reg in case the destination is the same as the first
  1811. source register
  1812. Revision 1.93 2003/04/29 07:28:52 michael
  1813. + Patch from peter to fix wrong pushing of ansistring function results in open array
  1814. Revision 1.92 2003/04/27 11:21:32 peter
  1815. * aktprocdef renamed to current_procinfo.procdef
  1816. * procinfo renamed to current_procinfo
  1817. * procinfo will now be stored in current_module so it can be
  1818. cleaned up properly
  1819. * gen_main_procsym changed to create_main_proc and release_main_proc
  1820. to also generate a tprocinfo structure
  1821. * fixed unit implicit initfinal
  1822. Revision 1.91 2003/04/27 07:29:50 peter
  1823. * current_procinfo.procdef cleanup, current_procdef is now always nil when parsing
  1824. a new procdef declaration
  1825. * aktprocsym removed
  1826. * lexlevel removed, use symtable.symtablelevel instead
  1827. * implicit init/final code uses the normal genentry/genexit
  1828. * funcret state checking updated for new funcret handling
  1829. Revision 1.90 2003/04/26 20:57:17 florian
  1830. * fixed para locations of fpc_class_new helper call
  1831. Revision 1.89 2003/04/26 17:21:08 florian
  1832. * fixed passing of fpu values by fpu register
  1833. Revision 1.88 2003/04/23 20:16:03 peter
  1834. + added currency support based on int64
  1835. + is_64bit for use in cg units instead of is_64bitint
  1836. * removed cgmessage from n386add, replace with internalerrors
  1837. Revision 1.87 2003/04/23 14:42:07 daniel
  1838. * Further register allocator work. Compiler now smaller with new
  1839. allocator than without.
  1840. * Somebody forgot to adjust ppu version number
  1841. Revision 1.86 2003/04/23 13:20:34 peter
  1842. * fix self passing to fpc_help_fail
  1843. Revision 1.85 2003/04/23 12:35:34 florian
  1844. * fixed several issues with powerpc
  1845. + applied a patch from Jonas for nested function calls (PowerPC only)
  1846. * ...
  1847. Revision 1.84 2003/04/22 14:33:38 peter
  1848. * removed some notes/hints
  1849. Revision 1.83 2003/04/22 13:47:08 peter
  1850. * fixed C style array of const
  1851. * fixed C array passing
  1852. * fixed left to right with high parameters
  1853. Revision 1.82 2003/04/22 10:09:34 daniel
  1854. + Implemented the actual register allocator
  1855. + Scratch registers unavailable when new register allocator used
  1856. + maybe_save/maybe_restore unavailable when new register allocator used
  1857. Revision 1.81 2003/04/06 21:11:23 olle
  1858. * changed newasmsymbol to newasmsymboldata for data symbols
  1859. Revision 1.80 2003/03/28 19:16:56 peter
  1860. * generic constructor working for i386
  1861. * remove fixed self register
  1862. * esi added as address register for i386
  1863. Revision 1.79 2003/03/22 18:07:18 jonas
  1864. + add used scratch registers to usedintbyproc for non-i386
  1865. Revision 1.78 2003/03/11 21:46:24 jonas
  1866. * lots of new regallocator fixes, both in generic and ppc-specific code
  1867. (ppc compiler still can't compile the linux system unit though)
  1868. Revision 1.77 2003/02/19 22:00:14 daniel
  1869. * Code generator converted to new register notation
  1870. - Horribily outdated todo.txt removed
  1871. Revision 1.76 2003/01/31 22:47:48 peter
  1872. * maybe_testself now really uses the passed register
  1873. Revision 1.75 2003/01/30 21:46:35 peter
  1874. * maybe_testvmt added
  1875. Revision 1.74 2003/01/17 12:45:40 daniel
  1876. * Fixed internalerror 200301081 problem
  1877. Revision 1.73 2003/01/13 14:54:34 daniel
  1878. * Further work to convert codegenerator register convention;
  1879. internalerror bug fixed.
  1880. Revision 1.72 2003/01/09 22:00:53 florian
  1881. * fixed some PowerPC issues
  1882. Revision 1.71 2003/01/09 20:41:10 florian
  1883. * fixed broken PowerPC compiler
  1884. Revision 1.70 2003/01/08 18:43:56 daniel
  1885. * Tregister changed into a record
  1886. Revision 1.69 2002/12/24 15:56:50 peter
  1887. * stackpointer_alloc added for adjusting ESP. Win32 needs
  1888. this for the pageprotection
  1889. Revision 1.68 2002/12/20 18:14:04 peter
  1890. * removed some runerror and writeln
  1891. Revision 1.67 2002/12/14 15:02:03 carl
  1892. * maxoperands -> max_operands (for portability in rautils.pas)
  1893. * fix some range-check errors with loadconst
  1894. + add ncgadd unit to m68k
  1895. * some bugfix of a_param_reg with LOC_CREFERENCE
  1896. Revision 1.66 2002/11/25 17:43:16 peter
  1897. * splitted defbase in defutil,symutil,defcmp
  1898. * merged isconvertable and is_equal into compare_defs(_ext)
  1899. * made operator search faster by walking the list only once
  1900. Revision 1.65 2002/11/17 16:27:31 carl
  1901. * document flags2reg
  1902. Revision 1.64 2002/11/16 17:06:28 peter
  1903. * return error 210 for failed self test
  1904. Revision 1.63 2002/11/15 01:58:46 peter
  1905. * merged changes from 1.0.7 up to 04-11
  1906. - -V option for generating bug report tracing
  1907. - more tracing for option parsing
  1908. - errors for cdecl and high()
  1909. - win32 import stabs
  1910. - win32 records<=8 are returned in eax:edx (turned off by default)
  1911. - heaptrc update
  1912. - more info for temp management in .s file with EXTDEBUG
  1913. Revision 1.62 2002/10/16 19:01:43 peter
  1914. + $IMPLICITEXCEPTIONS switch to turn on/off generation of the
  1915. implicit exception frames for procedures with initialized variables
  1916. and for constructors. The default is on for compatibility
  1917. Revision 1.61 2002/10/05 12:43:23 carl
  1918. * fixes for Delphi 6 compilation
  1919. (warning : Some features do not work under Delphi)
  1920. Revision 1.60 2002/10/02 18:20:52 peter
  1921. * Copy() is now internal syssym that calls compilerprocs
  1922. Revision 1.59 2002/09/17 18:54:02 jonas
  1923. * a_load_reg_reg() now has two size parameters: source and dest. This
  1924. allows some optimizations on architectures that don't encode the
  1925. register size in the register name.
  1926. Revision 1.58 2002/09/09 19:29:29 peter
  1927. * fixed dynarr_decr_ref call
  1928. Revision 1.57 2002/09/07 15:25:01 peter
  1929. * old logs removed and tabs fixed
  1930. Revision 1.56 2002/09/01 21:04:47 florian
  1931. * several powerpc related stuff fixed
  1932. Revision 1.55 2002/09/01 17:05:43 florian
  1933. + added abstract tcg.g_removevaluepara_openarray
  1934. Revision 1.54 2002/09/01 12:09:27 peter
  1935. + a_call_reg, a_call_loc added
  1936. * removed exprasmlist references
  1937. Revision 1.53 2002/08/19 18:17:48 carl
  1938. + optimize64_op_const_reg implemented (optimizes 64-bit constant opcodes)
  1939. * more fixes to m68k for 64-bit operations
  1940. Revision 1.52 2002/08/17 22:09:43 florian
  1941. * result type handling in tcgcal.pass_2 overhauled
  1942. * better tnode.dowrite
  1943. * some ppc stuff fixed
  1944. Revision 1.51 2002/08/17 09:23:33 florian
  1945. * first part of procinfo rewrite
  1946. Revision 1.50 2002/08/16 14:24:57 carl
  1947. * issameref() to test if two references are the same (then emit no opcodes)
  1948. + ret_in_reg to replace ret_in_acc
  1949. (fix some register allocation bugs at the same time)
  1950. + save_std_register now has an extra parameter which is the
  1951. usedinproc registers
  1952. Revision 1.49 2002/08/15 08:13:54 carl
  1953. - a_load_sym_ofs_reg removed
  1954. * loadvmt now calls loadaddr_ref_reg instead
  1955. Revision 1.48 2002/08/14 19:26:02 carl
  1956. + routine to optimize opcodes with constants
  1957. Revision 1.47 2002/08/11 14:32:26 peter
  1958. * renamed current_library to objectlibrary
  1959. Revision 1.46 2002/08/11 13:24:11 peter
  1960. * saving of asmsymbols in ppu supported
  1961. * asmsymbollist global is removed and moved into a new class
  1962. tasmlibrarydata that will hold the info of a .a file which
  1963. corresponds with a single module. Added librarydata to tmodule
  1964. to keep the library info stored for the module. In the future the
  1965. objectfiles will also be stored to the tasmlibrarydata class
  1966. * all getlabel/newasmsymbol and friends are moved to the new class
  1967. Revision 1.45 2002/08/10 17:15:20 jonas
  1968. * register parameters are now LOC_CREGISTER instead of LOC_REGISTER
  1969. Revision 1.44 2002/08/09 19:10:05 carl
  1970. - moved new_exception and free_exception to ncgutils
  1971. Revision 1.43 2002/08/05 18:27:48 carl
  1972. + more more more documentation
  1973. + first version include/exclude (can't test though, not enough scratch for i386 :()...
  1974. Revision 1.42 2002/08/04 19:08:21 carl
  1975. + added generic exception support (still does not work!)
  1976. + more documentation
  1977. Revision 1.41 2002/07/30 20:50:43 florian
  1978. * the code generator knows now if parameters are in registers
  1979. Revision 1.40 2002/07/29 21:16:02 florian
  1980. * some more ppc fixes
  1981. Revision 1.39 2002/07/28 15:56:00 jonas
  1982. + tcg64.a_op64_const_reg_reg() and tcg64.a_op64_reg_reg_reg() methods +
  1983. generic implementation
  1984. Revision 1.38 2002/07/27 19:53:51 jonas
  1985. + generic implementation of tcg.g_flags2ref()
  1986. * tcg.flags2xxx() now also needs a size parameter
  1987. Revision 1.37 2002/07/20 11:57:53 florian
  1988. * types.pas renamed to defbase.pas because D6 contains a types
  1989. unit so this would conflicts if D6 programms are compiled
  1990. + Willamette/SSE2 instructions to assembler added
  1991. }