cgobj.pas 88 KB

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