2
0

cgobj.pas 70 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711
  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. cclasses,aasmbase,aasmtai,aasmcpu,symtable,
  32. cpubase,cpuinfo,cpupara,
  33. cginfo,
  34. symconst,symbase,symtype,node
  35. {$ifdef delphi}
  36. ,dmisc
  37. {$endif}
  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. scratch_register_array_pointer : aword;
  50. {# List of currently unused scratch registers }
  51. unusedscratchregisters : tregisterset;
  52. alignment : talignment;
  53. {************************************************}
  54. { basic routines }
  55. constructor create;
  56. { returns the tcgsize corresponding with the size of reg }
  57. class function reg_cgsize(const reg: tregister) : tcgsize; virtual;
  58. {# Emit a label to the instruction stream. }
  59. procedure a_label(list : taasmoutput;l : tasmlabel);virtual;
  60. {# Allocates register r by inserting a pai_realloc record }
  61. procedure a_reg_alloc(list : taasmoutput;r : tregister);
  62. {# Deallocates register r by inserting a pa_regdealloc record}
  63. procedure a_reg_dealloc(list : taasmoutput;r : tregister);
  64. {# @abstract(Returns an int register for use as scratch register)
  65. This routine returns a register which can be used by
  66. the code generator as a general purpose scratch register.
  67. Since scratch_registers are scarce resources, the register
  68. should be freed by calling @link(free_scratch_reg) as
  69. soon as it is no longer required.
  70. }
  71. function get_scratch_reg_int(list : taasmoutput) : tregister;virtual;
  72. {# @abstract(Returns an address register for use as scratch register)
  73. This routine returns a register which can be used by
  74. the code generator as a pointer scratch register.
  75. Since scratch_registers are scarce resources, the register
  76. should be freed by calling @link(free_scratch_reg) as
  77. soon as it is no longer required.
  78. }
  79. function get_scratch_reg_address(list : taasmoutput) : tregister;virtual;
  80. {# @abstract(Releases a scratch register)
  81. Releases a scratch register.
  82. This routine is used to free a register which
  83. was previously allocated using @link(get_scratch_reg).
  84. }
  85. procedure free_scratch_reg(list : taasmoutput;r : tregister);
  86. {# Pass a parameter, which is located in a register, to a routine.
  87. This routine should push/send the parameter to the routine, as
  88. required by the specific processor ABI and routine modifiers.
  89. This must be overriden for each CPU target.
  90. @param(size size of the operand in the register)
  91. @param(r register source of the operand)
  92. @param(locpara where the parameter will be stored)
  93. }
  94. procedure a_param_reg(list : taasmoutput;size : tcgsize;r : tregister;const locpara : tparalocation);virtual;
  95. {# Pass a parameter, which is a constant, to a routine.
  96. A generic version is provided. This routine should
  97. be overriden for optimization purposes if the cpu
  98. permits directly sending this type of parameter.
  99. @param(size size of the operand in constant)
  100. @param(a value of constant to send)
  101. @param(locpara where the parameter will be stored)
  102. }
  103. procedure a_param_const(list : taasmoutput;size : tcgsize;a : aword;const locpara : tparalocation);virtual;
  104. {# Pass the value of a parameter, which is located in memory, to a routine.
  105. A generic version is provided. This routine should
  106. be overriden for optimization purposes if the cpu
  107. permits directly sending this type of parameter.
  108. @param(size size of the operand in constant)
  109. @param(r Memory reference of value to send)
  110. @param(locpara where the parameter will be stored)
  111. }
  112. procedure a_param_ref(list : taasmoutput;size : tcgsize;const r : treference;const locpara : tparalocation);virtual;
  113. {# Pass the value of a parameter, which can be located either in a register or memory location,
  114. to a routine.
  115. A generic version is provided.
  116. @param(l location of the operand to send)
  117. @param(nr parameter number (starting from one) of routine (from left to right))
  118. @param(locpara where the parameter will be stored)
  119. }
  120. procedure a_param_loc(list : taasmoutput;const l : tlocation;const locpara : tparalocation);
  121. {# Pass the address of a reference to a routine. This routine
  122. will calculate the address of the reference, and pass this
  123. calculated address as a parameter.
  124. A generic version is provided. This routine should
  125. be overriden for optimization purposes if the cpu
  126. permits directly sending this type of parameter.
  127. @param(r reference to get address from)
  128. @param(nr parameter number (starting from one) of routine (from left to right))
  129. }
  130. procedure a_paramaddr_ref(list : taasmoutput;const r : treference;const locpara : tparalocation);virtual;
  131. (* Remarks:
  132. * If a method specifies a size you have only to take care
  133. of that number of bits, i.e. load_const_reg with OP_8 must
  134. only load the lower 8 bit of the specified register
  135. the rest of the register can be undefined
  136. if necessary the compiler will call a method
  137. to zero or sign extend the register
  138. * The a_load_XX_XX with OP_64 needn't to be
  139. implemented for 32 bit
  140. processors, the code generator takes care of that
  141. * the addr size is for work with the natural pointer
  142. size
  143. * the procedures without fpu/mm are only for integer usage
  144. * normally the first location is the source and the
  145. second the destination
  146. *)
  147. {# Emits instruction to call the method specified by symbol name.
  148. This routine must be overriden for each new target cpu.
  149. }
  150. procedure a_call_name(list : taasmoutput;const s : string);virtual; abstract;
  151. procedure a_call_ref(list : taasmoutput;const ref : treference);virtual;abstract;
  152. procedure a_call_reg(list : taasmoutput;reg : tregister);virtual;abstract;
  153. procedure a_call_loc(list : taasmoutput;const loc:tlocation);
  154. { move instructions }
  155. procedure a_load_const_reg(list : taasmoutput;size : tcgsize;a : aword;register : tregister);virtual; abstract;
  156. procedure a_load_const_ref(list : taasmoutput;size : tcgsize;a : aword;const ref : treference);virtual;
  157. procedure a_load_const_loc(list : taasmoutput;a : aword;const loc : tlocation);
  158. procedure a_load_reg_ref(list : taasmoutput;size : tcgsize;register : tregister;const ref : treference);virtual; abstract;
  159. procedure a_load_reg_reg(list : taasmoutput;fromsize, tosize : tcgsize;reg1,reg2 : tregister);virtual; abstract;
  160. procedure a_load_reg_loc(list : taasmoutput;size : tcgsize;reg : tregister;const loc: tlocation);
  161. procedure a_load_ref_reg(list : taasmoutput;size : tcgsize;const ref : treference;register : tregister);virtual; abstract;
  162. procedure a_load_ref_ref(list : taasmoutput;size : tcgsize;const sref : treference;const dref : treference);virtual;
  163. procedure a_load_loc_reg(list : taasmoutput;const loc: tlocation; reg : tregister);
  164. procedure a_load_loc_ref(list : taasmoutput;const loc: tlocation; const ref : treference);
  165. procedure a_loadaddr_ref_reg(list : taasmoutput;const ref : treference;r : tregister);virtual; abstract;
  166. { fpu move instructions }
  167. procedure a_loadfpu_reg_reg(list: taasmoutput; reg1, reg2: tregister); virtual; abstract;
  168. procedure a_loadfpu_ref_reg(list: taasmoutput; size: tcgsize; const ref: treference; reg: tregister); virtual; abstract;
  169. procedure a_loadfpu_reg_ref(list: taasmoutput; size: tcgsize; reg: tregister; const ref: treference); virtual; abstract;
  170. procedure a_loadfpu_loc_reg(list: taasmoutput; const loc: tlocation; const reg: tregister);
  171. procedure a_loadfpu_reg_loc(list: taasmoutput; size: tcgsize; const reg: tregister; const loc: tlocation);
  172. { vector register move instructions }
  173. procedure a_loadmm_reg_reg(list: taasmoutput; reg1, reg2: tregister); virtual; abstract;
  174. procedure a_loadmm_ref_reg(list: taasmoutput; const ref: treference; reg: tregister); virtual; abstract;
  175. procedure a_loadmm_reg_ref(list: taasmoutput; reg: tregister; const ref: treference); virtual; abstract;
  176. procedure a_parammm_reg(list: taasmoutput; reg: tregister); virtual; abstract;
  177. { basic arithmetic operations }
  178. { note: for operators which require only one argument (not, neg), use }
  179. { the op_reg_reg, op_reg_ref or op_reg_loc methods and keep in mind }
  180. { that in this case the *second* operand is used as both source and }
  181. { destination (JM) }
  182. procedure a_op_const_reg(list : taasmoutput; Op: TOpCG; a: AWord; reg: TRegister); virtual; abstract;
  183. procedure a_op_const_ref(list : taasmoutput; Op: TOpCG; size: TCGSize; a: AWord; const ref: TReference); virtual;
  184. procedure a_op_const_loc(list : taasmoutput; Op: TOpCG; a: AWord; const loc: tlocation);
  185. procedure a_op_reg_reg(list : taasmoutput; Op: TOpCG; size: TCGSize; reg1, reg2: TRegister); virtual; abstract;
  186. procedure a_op_reg_ref(list : taasmoutput; Op: TOpCG; size: TCGSize; reg: TRegister; const ref: TReference); virtual;
  187. procedure a_op_ref_reg(list : taasmoutput; Op: TOpCG; size: TCGSize; const ref: TReference; reg: TRegister); virtual;
  188. procedure a_op_reg_loc(list : taasmoutput; Op: TOpCG; reg: tregister; const loc: tlocation);
  189. procedure a_op_ref_loc(list : taasmoutput; Op: TOpCG; const ref: TReference; const loc: tlocation);
  190. { trinary operations for processors that support them, 'emulated' }
  191. { on others. None with "ref" arguments since I don't think there }
  192. { are any processors that support it (JM) }
  193. procedure a_op_const_reg_reg(list: taasmoutput; op: TOpCg;
  194. size: tcgsize; a: aword; src, dst: tregister); virtual;
  195. procedure a_op_reg_reg_reg(list: taasmoutput; op: TOpCg;
  196. size: tcgsize; src1, src2, dst: tregister); virtual;
  197. { comparison operations }
  198. procedure a_cmp_const_reg_label(list : taasmoutput;size : tcgsize;cmp_op : topcmp;a : aword;reg : tregister;
  199. l : tasmlabel);virtual; abstract;
  200. procedure a_cmp_const_ref_label(list : taasmoutput;size : tcgsize;cmp_op : topcmp;a : aword;const ref : treference;
  201. l : tasmlabel); virtual;
  202. procedure a_cmp_const_loc_label(list: taasmoutput; size: tcgsize;cmp_op: topcmp; a: aword; const loc: tlocation;
  203. l : tasmlabel);
  204. procedure a_cmp_reg_reg_label(list : taasmoutput;size : tcgsize;cmp_op : topcmp;reg1,reg2 : tregister;l : tasmlabel); virtual; abstract;
  205. procedure a_cmp_ref_reg_label(list : taasmoutput;size : tcgsize;cmp_op : topcmp; const ref: treference; reg : tregister; l : tasmlabel); virtual;
  206. procedure a_cmp_loc_reg_label(list : taasmoutput;size : tcgsize;cmp_op : topcmp; const loc: tlocation; reg : tregister; l : tasmlabel);
  207. procedure a_cmp_ref_loc_label(list: taasmoutput; size: tcgsize;cmp_op: topcmp; const ref: treference; const loc: tlocation;
  208. l : tasmlabel);
  209. procedure a_jmp_always(list : taasmoutput;l: tasmlabel); virtual; abstract;
  210. procedure a_jmp_flags(list : taasmoutput;const f : TResFlags;l: tasmlabel); virtual; abstract;
  211. procedure g_flags2reg(list: taasmoutput; size: TCgSize; const f: tresflags; reg: TRegister); virtual; abstract;
  212. procedure g_flags2ref(list: taasmoutput; size: TCgSize; const f: tresflags; const ref:TReference); virtual;
  213. {
  214. This routine tries to optimize the const_reg opcode, and should be
  215. called at the start of a_op_const_reg. It returns the actual opcode
  216. to emit, and the constant value to emit. If this routine returns
  217. TRUE, @var(no) instruction should be emitted (.eg : imul reg by 1 )
  218. @param(op The opcode to emit, returns the opcode which must be emitted)
  219. @param(a The constant which should be emitted, returns the constant which must
  220. be emitted)
  221. @param(reg The register to emit the opcode with, returns the register with
  222. which the opcode will be emitted)
  223. }
  224. function optimize_op_const_reg(list: taasmoutput; var op: topcg; var a : aword; var reg: tregister): boolean;virtual;
  225. {#
  226. This routine is used in exception management nodes. It should
  227. save the exception reason currently in the accumulator. The
  228. save should be done either to a temp (pointed to by href).
  229. or on the stack (pushing the value on the stack).
  230. The size of the value to save is OS_S32. The default version
  231. saves the exception reason to a temp. memory area.
  232. }
  233. procedure g_exception_reason_save(list : taasmoutput; const href : treference);virtual;
  234. {#
  235. This routine is used in exception management nodes. It should
  236. save the exception reason constant. The
  237. save should be done either to a temp (pointed to by href).
  238. or on the stack (pushing the value on the stack).
  239. The size of the value to save is OS_S32. The default version
  240. saves the exception reason to a temp. memory area.
  241. }
  242. procedure g_exception_reason_save_const(list : taasmoutput; const href : treference; a: aword);virtual;
  243. {#
  244. This routine is used in exception management nodes. It should
  245. load the exception reason to the accumulator. The saved value
  246. should either be in the temp. area (pointed to by href , href should
  247. *NOT* be freed) or on the stack (the value should be popped).
  248. The size of the value to save is OS_S32. The default version
  249. saves the exception reason to a temp. memory area.
  250. }
  251. procedure g_exception_reason_load(list : taasmoutput; const href : treference);virtual;
  252. procedure g_maybe_loadself(list : taasmoutput);virtual;
  253. {# This should emit the opcode to copy len bytes from the source
  254. to destination, if loadref is true, it assumes that it first must load
  255. the source address from the memory location where
  256. source points to.
  257. It must be overriden for each new target processor.
  258. @param(source Source reference of copy)
  259. @param(dest Destination reference of copy)
  260. @param(delsource Indicates if the source reference's resources should be freed)
  261. @param(loadref Is the source reference a pointer to the actual source (TRUE), is it the actual source address (FALSE))
  262. }
  263. procedure g_concatcopy(list : taasmoutput;const source,dest : treference;len : aword;delsource,loadref : boolean);virtual; abstract;
  264. {# This should emit the opcode to a shortrstring from the source
  265. to destination, if loadref is true, it assumes that it first must load
  266. the source address from the memory location where
  267. source points to.
  268. @param(source Source reference of copy)
  269. @param(dest Destination reference of copy)
  270. @param(delsource Indicates if the source reference's resources should be freed)
  271. @param(loadref Is the source reference a pointer to the actual source (TRUE), is it the actual source address (FALSE))
  272. }
  273. procedure g_copyshortstring(list : taasmoutput;const source,dest : treference;len:byte;delsource,loadref : boolean);
  274. procedure g_incrrefcount(list : taasmoutput;t: tdef; const ref: treference);
  275. procedure g_decrrefcount(list : taasmoutput;t: tdef; const ref: treference);
  276. procedure g_initialize(list : taasmoutput;t : tdef;const ref : treference;loadref : boolean);
  277. procedure g_finalize(list : taasmoutput;t : tdef;const ref : treference;loadref : boolean);
  278. {# Emits the call to the stack checking routine of
  279. the runtime library. The default behavior
  280. does not need to be modified, as it is generic
  281. for all platforms.
  282. @param(stackframesize Number of bytes which will be allocated on the stack)
  283. }
  284. procedure g_stackcheck(list : taasmoutput;stackframesize : longint);virtual;
  285. {# Generates range checking code. It is to note
  286. that this routine does not need to be overriden,
  287. as it takes care of everything.
  288. @param(p Node which contains the value to check)
  289. @param(todef Type definition of node to range check)
  290. }
  291. procedure g_rangecheck(list: taasmoutput; const p: tnode;
  292. const todef: tdef); virtual;
  293. {# Generates overflow checking code for a node }
  294. procedure g_overflowcheck(list: taasmoutput; const p: tnode); virtual; abstract;
  295. procedure g_copyvaluepara_openarray(list : taasmoutput;const ref:treference;elesize:integer);virtual;abstract;
  296. procedure g_removevaluepara_openarray(list : taasmoutput;const ref:treference;elesize:integer);virtual;abstract;
  297. {# Emits instructions which should be emitted when entering
  298. a routine declared as @var(interrupt). The default
  299. behavior does nothing, should be overriden as required.
  300. }
  301. procedure g_interrupt_stackframe_entry(list : taasmoutput);virtual;
  302. {# Emits instructions which should be emitted when exiting
  303. a routine declared as @var(interrupt). The default
  304. behavior does nothing, should be overriden as required.
  305. }
  306. procedure g_interrupt_stackframe_exit(list : taasmoutput;selfused,accused,acchiused:boolean);virtual;
  307. {# Emits instructions when compilation is done in profile
  308. mode (this is set as a command line option). The default
  309. behavior does nothing, should be overriden as required.
  310. }
  311. procedure g_profilecode(list : taasmoutput);virtual;
  312. {# Emits instruction for allocating the locals in entry
  313. code of a routine. This is one of the first
  314. routine called in @var(genentrycode).
  315. @param(localsize Number of bytes to allocate as locals)
  316. }
  317. procedure g_stackframe_entry(list : taasmoutput;localsize : longint);virtual; abstract;
  318. {# Emits instructiona for restoring the frame pointer
  319. at routine exit. For some processors, this routine
  320. may do nothing at all.
  321. }
  322. procedure g_restore_frame_pointer(list : taasmoutput);virtual; abstract;
  323. {# Emits instructions for returning from a subroutine.
  324. Should also restore the stack.
  325. @param(parasize Number of bytes of parameters to deallocate from stack)
  326. }
  327. procedure g_return_from_proc(list : taasmoutput;parasize : aword);virtual; abstract;
  328. procedure g_call_constructor_helper(list : taasmoutput);virtual;
  329. procedure g_call_destructor_helper(list : taasmoutput);virtual;
  330. procedure g_call_fail_helper(list : taasmoutput);virtual;
  331. {# This routine is called when generating the code for the entry point
  332. of a routine. It should save all registers which are not used in this
  333. routine, and which should be declared as saved in the std_saved_registers
  334. set.
  335. This routine is mainly used when linking to code which is generated
  336. by ABI-compliant compilers (like GCC), to make sure that the reserved
  337. registers of that ABI are not clobbered.
  338. @param(usedinproc Registers which are used in the code of this routine)
  339. }
  340. procedure g_save_standard_registers(list : taasmoutput; usedinproc : tregisterset);virtual;abstract;
  341. {# This routine is called when generating the code for the exit point
  342. of a routine. It should restore all registers which were previously
  343. saved in @var(g_save_standard_registers).
  344. @param(usedinproc Registers which are used in the code of this routine)
  345. }
  346. procedure g_restore_standard_registers(list : taasmoutput; usedinproc : tregisterset);virtual;abstract;
  347. procedure g_save_all_registers(list : taasmoutput);virtual;abstract;
  348. procedure g_restore_all_registers(list : taasmoutput;selfused,accused,acchiused:boolean);virtual;abstract;
  349. end;
  350. {# @abstract(Abstract code generator for 64 Bit operations)
  351. This class implements an abstract code generator class
  352. for 64 Bit operations.
  353. }
  354. tcg64 = class
  355. { Allocates 64 Bit register r by inserting a pai_realloc record }
  356. procedure a_reg_alloc(list : taasmoutput;r : tregister64);virtual;abstract;
  357. { Deallocates 64 Bit register r by inserting a pa_regdealloc record}
  358. procedure a_reg_dealloc(list : taasmoutput;r : tregister64);virtual;abstract;
  359. procedure a_load64_const_ref(list : taasmoutput;value : qword;const ref : treference);virtual;abstract;
  360. procedure a_load64_reg_ref(list : taasmoutput;reg : tregister64;const ref : treference);virtual;abstract;
  361. procedure a_load64_ref_reg(list : taasmoutput;const ref : treference;reg : tregister64);virtual;abstract;
  362. procedure a_load64_reg_reg(list : taasmoutput;regsrc,regdst : tregister64);virtual;abstract;
  363. procedure a_load64_const_reg(list : taasmoutput;value : qword;reg : tregister64);virtual;abstract;
  364. procedure a_load64_loc_reg(list : taasmoutput;const l : tlocation;reg : tregister64);virtual;abstract;
  365. procedure a_load64_loc_ref(list : taasmoutput;const l : tlocation;const ref : treference);virtual;abstract;
  366. procedure a_load64_const_loc(list : taasmoutput;value : qword;const l : tlocation);virtual;abstract;
  367. procedure a_load64_reg_loc(list : taasmoutput;reg : tregister64;const l : tlocation);virtual;abstract;
  368. procedure a_load64high_reg_ref(list : taasmoutput;reg : tregister;const ref : treference);virtual;abstract;
  369. procedure a_load64low_reg_ref(list : taasmoutput;reg : tregister;const ref : treference);virtual;abstract;
  370. procedure a_load64high_ref_reg(list : taasmoutput;const ref : treference;reg : tregister);virtual;abstract;
  371. procedure a_load64low_ref_reg(list : taasmoutput;const ref : treference;reg : tregister);virtual;abstract;
  372. procedure a_load64high_loc_reg(list : taasmoutput;const l : tlocation;reg : tregister);virtual;abstract;
  373. procedure a_load64low_loc_reg(list : taasmoutput;const l : tlocation;reg : tregister);virtual;abstract;
  374. procedure a_op64_ref_reg(list : taasmoutput;op:TOpCG;const ref : treference;reg : tregister64);virtual;abstract;
  375. procedure a_op64_reg_reg(list : taasmoutput;op:TOpCG;regsrc,regdst : tregister64);virtual;abstract;
  376. procedure a_op64_reg_ref(list : taasmoutput;op:TOpCG;regsrc : tregister64;const ref : treference);virtual;abstract;
  377. procedure a_op64_const_reg(list : taasmoutput;op:TOpCG;value : qword;regdst : tregister64);virtual;abstract;
  378. procedure a_op64_const_ref(list : taasmoutput;op:TOpCG;value : qword;const ref : treference);virtual;abstract;
  379. procedure a_op64_const_loc(list : taasmoutput;op:TOpCG;value : qword;const l: tlocation);virtual;abstract;
  380. procedure a_op64_reg_loc(list : taasmoutput;op:TOpCG;reg : tregister64;const l : tlocation);virtual;abstract;
  381. procedure a_op64_loc_reg(list : taasmoutput;op:TOpCG;const l : tlocation;reg64 : tregister64);virtual;abstract;
  382. procedure a_op64_const_reg_reg(list: taasmoutput;op:TOpCG;value : qword;regsrc,regdst : tregister64);virtual;
  383. procedure a_op64_reg_reg_reg(list: taasmoutput;op:TOpCG;regsrc1,regsrc2,regdst : tregister64);virtual;
  384. procedure a_param64_reg(list : taasmoutput;reg64 : tregister64;const loc : tparalocation);virtual;abstract;
  385. procedure a_param64_const(list : taasmoutput;value : qword;const loc : tparalocation);virtual;abstract;
  386. procedure a_param64_ref(list : taasmoutput;const r : treference;const loc : tparalocation);virtual;abstract;
  387. procedure a_param64_loc(list : taasmoutput;const l : tlocation;const loc : tparalocation);virtual;abstract;
  388. {
  389. This routine tries to optimize the const_reg opcode, and should be
  390. called at the start of a_op64_const_reg. It returns the actual opcode
  391. to emit, and the constant value to emit. If this routine returns
  392. TRUE, @var(no) instruction should be emitted (.eg : imul reg by 1 )
  393. @param(op The opcode to emit, returns the opcode which must be emitted)
  394. @param(a The constant which should be emitted, returns the constant which must
  395. be emitted)
  396. @param(reg The register to emit the opcode with, returns the register with
  397. which the opcode will be emitted)
  398. }
  399. function optimize64_op_const_reg(list: taasmoutput; var op: topcg; var a : qword; var reg: tregister64): boolean;virtual;abstract;
  400. { override to catch 64bit rangechecks }
  401. procedure g_rangecheck64(list: taasmoutput; const p: tnode;
  402. const todef: tdef);virtual;abstract;
  403. end;
  404. var
  405. {# Main code generator class }
  406. cg : tcg;
  407. {# Code generator class for all operations working with 64-Bit operands }
  408. cg64 : tcg64;
  409. implementation
  410. uses
  411. globals,globtype,options,systems,cgbase,
  412. verbose,defbase,tgobj,symdef,paramgr,
  413. rgobj,cutils;
  414. const
  415. max_scratch_regs = high(scratch_regs) - low(scratch_regs) + 1;
  416. {*****************************************************************************
  417. basic functionallity
  418. ******************************************************************************}
  419. constructor tcg.create;
  420. var
  421. i : longint;
  422. begin
  423. scratch_register_array_pointer:=1;
  424. for i:=low(scratch_regs) to high(scratch_regs) do
  425. include(unusedscratchregisters,scratch_regs[i]);
  426. end;
  427. procedure tcg.a_reg_alloc(list : taasmoutput;r : tregister);
  428. begin
  429. list.concat(tai_regalloc.alloc(r));
  430. end;
  431. procedure tcg.a_reg_dealloc(list : taasmoutput;r : tregister);
  432. begin
  433. list.concat(tai_regalloc.dealloc(r));
  434. end;
  435. procedure tcg.a_label(list : taasmoutput;l : tasmlabel);
  436. begin
  437. list.concat(tai_label.create(l));
  438. end;
  439. function tcg.get_scratch_reg_int(list : taasmoutput) : tregister;
  440. var
  441. r : tregister;
  442. i : longint;
  443. begin
  444. if unusedscratchregisters=[] then
  445. internalerror(68996);
  446. for i:=scratch_register_array_pointer to
  447. (scratch_register_array_pointer+max_scratch_regs-1) do
  448. if scratch_regs[(i mod max_scratch_regs)+1] in unusedscratchregisters then
  449. begin
  450. r:=scratch_regs[(i mod max_scratch_regs)+1];
  451. break;
  452. end;
  453. exclude(unusedscratchregisters,r);
  454. inc(scratch_register_array_pointer);
  455. if scratch_register_array_pointer>max_scratch_regs then
  456. scratch_register_array_pointer:=1;
  457. a_reg_alloc(list,r);
  458. get_scratch_reg_int:=r;
  459. end;
  460. { the default behavior simply returns a general purpose register }
  461. function tcg.get_scratch_reg_address(list : taasmoutput) : tregister;
  462. begin
  463. get_scratch_reg_address := get_scratch_reg_int(list);
  464. end;
  465. procedure tcg.free_scratch_reg(list : taasmoutput;r : tregister);
  466. begin
  467. include(unusedscratchregisters,rg.makeregsize(r,OS_INT));
  468. a_reg_dealloc(list,r);
  469. end;
  470. {*****************************************************************************
  471. for better code generation these methods should be overridden
  472. ******************************************************************************}
  473. procedure tcg.a_param_reg(list : taasmoutput;size : tcgsize;r : tregister;const locpara : tparalocation);
  474. var
  475. ref : treference;
  476. begin
  477. case locpara.loc of
  478. LOC_REGISTER,LOC_CREGISTER:
  479. a_load_reg_reg(list,size,locpara.size,r,locpara.register);
  480. LOC_REFERENCE:
  481. begin
  482. if locpara.sp_fixup<>0 then
  483. a_op_const_reg(list,OP_ADD,locpara.sp_fixup,stack_pointer_reg);
  484. reference_reset(ref);
  485. ref.base:=locpara.reference.index;
  486. ref.offset:=locpara.reference.offset;
  487. a_load_reg_ref(list,size,r,ref);
  488. end
  489. else
  490. internalerror(2002071004);
  491. end;
  492. end;
  493. procedure tcg.a_param_const(list : taasmoutput;size : tcgsize;a : aword;const locpara : tparalocation);
  494. var
  495. hr : tregister;
  496. begin
  497. hr:=get_scratch_reg_int(list);
  498. a_load_const_reg(list,size,a,hr);
  499. a_param_reg(list,size,hr,locpara);
  500. free_scratch_reg(list,hr);
  501. end;
  502. procedure tcg.a_param_ref(list : taasmoutput;size : tcgsize;const r : treference;const locpara : tparalocation);
  503. var
  504. hr : tregister;
  505. begin
  506. hr:=get_scratch_reg_int(list);
  507. a_load_ref_reg(list,size,r,hr);
  508. a_param_reg(list,size,hr,locpara);
  509. free_scratch_reg(list,hr);
  510. end;
  511. procedure tcg.a_param_loc(list : taasmoutput;const l:tlocation;const locpara : tparalocation);
  512. begin
  513. case l.loc of
  514. LOC_REGISTER,
  515. LOC_CREGISTER :
  516. a_param_reg(list,l.size,l.register,locpara);
  517. LOC_CONSTANT :
  518. a_param_const(list,l.size,l.value,locpara);
  519. LOC_CREFERENCE,
  520. LOC_REFERENCE :
  521. a_param_ref(list,l.size,l.reference,locpara);
  522. else
  523. internalerror(2002032211);
  524. end;
  525. end;
  526. procedure tcg.a_paramaddr_ref(list : taasmoutput;const r : treference;const locpara : tparalocation);
  527. var
  528. hr : tregister;
  529. begin
  530. hr:=get_scratch_reg_address(list);
  531. a_loadaddr_ref_reg(list,r,hr);
  532. a_param_reg(list,OS_ADDR,hr,locpara);
  533. free_scratch_reg(list,hr);
  534. end;
  535. {****************************************************************************
  536. some generic implementations
  537. ****************************************************************************}
  538. procedure tcg.a_load_ref_ref(list : taasmoutput;size : tcgsize;const sref : treference;const dref : treference);
  539. var
  540. tmpreg: tregister;
  541. {$ifdef i386}
  542. pushed_reg: tregister;
  543. {$endif i386}
  544. begin
  545. { verify if we have the same reference }
  546. if references_equal(sref,dref) then
  547. exit;
  548. {$ifdef i386}
  549. { the following is done with defines to avoid a speed penalty, }
  550. { since all this is only necessary for the 80x86 (because EDI }
  551. { doesn't have an 8bit component which is directly addressable) }
  552. pushed_reg := R_NO;
  553. if size in [OS_8,OS_S8] then
  554. if (rg.countunusedregsint = 0) then
  555. begin
  556. if (dref.base <> R_EBX) and
  557. (dref.index <> R_EBX) then
  558. pushed_reg := R_EBX
  559. else if (dref.base <> R_EAX) and
  560. (dref.index <> R_EAX) then
  561. pushed_reg := R_EAX
  562. else pushed_reg := R_ECX;
  563. tmpreg := rg.makeregsize(pushed_reg,OS_8);
  564. list.concat(taicpu.op_reg(A_PUSH,S_L,pushed_reg));
  565. end
  566. else
  567. tmpreg := rg.getregisterint(list)
  568. else
  569. {$endif i386}
  570. tmpreg := get_scratch_reg_int(list);
  571. tmpreg:=rg.makeregsize(tmpreg,size);
  572. a_load_ref_reg(list,size,sref,tmpreg);
  573. a_load_reg_ref(list,size,tmpreg,dref);
  574. {$ifdef i386}
  575. if size in [OS_8,OS_S8] then
  576. begin
  577. if (pushed_reg <> R_NO) then
  578. list.concat(taicpu.op_reg(A_POP,S_L,pushed_reg))
  579. else
  580. rg.ungetregister(list,tmpreg)
  581. end
  582. else
  583. {$endif i386}
  584. free_scratch_reg(list,tmpreg);
  585. end;
  586. procedure tcg.a_load_const_ref(list : taasmoutput;size : tcgsize;a : aword;const ref : treference);
  587. var
  588. tmpreg: tregister;
  589. begin
  590. tmpreg := get_scratch_reg_int(list);
  591. a_load_const_reg(list,size,a,tmpreg);
  592. a_load_reg_ref(list,size,tmpreg,ref);
  593. free_scratch_reg(list,tmpreg);
  594. end;
  595. procedure tcg.a_load_const_loc(list : taasmoutput;a : aword;const loc: tlocation);
  596. begin
  597. case loc.loc of
  598. LOC_REFERENCE,LOC_CREFERENCE:
  599. a_load_const_ref(list,loc.size,a,loc.reference);
  600. LOC_REGISTER,LOC_CREGISTER:
  601. a_load_const_reg(list,loc.size,a,loc.register);
  602. else
  603. internalerror(200203272);
  604. end;
  605. end;
  606. procedure tcg.a_load_reg_loc(list : taasmoutput;size : tcgsize;reg : tregister;const loc: tlocation);
  607. begin
  608. case loc.loc of
  609. LOC_REFERENCE,LOC_CREFERENCE:
  610. a_load_reg_ref(list,size,reg,loc.reference);
  611. LOC_REGISTER,LOC_CREGISTER:
  612. a_load_reg_reg(list,size,loc.size,reg,loc.register);
  613. else
  614. internalerror(200203271);
  615. end;
  616. end;
  617. procedure tcg.a_load_loc_reg(list : taasmoutput;const loc: tlocation; reg : tregister);
  618. begin
  619. case loc.loc of
  620. LOC_REFERENCE,LOC_CREFERENCE:
  621. a_load_ref_reg(list,loc.size,loc.reference,reg);
  622. LOC_REGISTER,LOC_CREGISTER:
  623. a_load_reg_reg(list,loc.size,loc.size,loc.register,reg);
  624. LOC_CONSTANT:
  625. a_load_const_reg(list,loc.size,loc.value,reg);
  626. else
  627. begin
  628. writeln(ord(loc.loc));
  629. runerror(216);
  630. internalerror(200109092);
  631. end;
  632. end;
  633. end;
  634. procedure tcg.a_load_loc_ref(list : taasmoutput;const loc: tlocation; const ref : treference);
  635. begin
  636. case loc.loc of
  637. LOC_REFERENCE,LOC_CREFERENCE:
  638. a_load_ref_ref(list,loc.size,loc.reference,ref);
  639. LOC_REGISTER,LOC_CREGISTER:
  640. a_load_reg_ref(list,loc.size,loc.register,ref);
  641. LOC_CONSTANT:
  642. a_load_const_ref(list,loc.size,loc.value,ref);
  643. else
  644. internalerror(200109302);
  645. end;
  646. end;
  647. procedure tcg.a_call_loc(list : taasmoutput;const loc:tlocation);
  648. begin
  649. case loc.loc of
  650. LOC_REGISTER,LOC_CREGISTER:
  651. cg.a_call_reg(list,loc.register);
  652. LOC_REFERENCE,LOC_CREFERENCE :
  653. cg.a_call_ref(list,loc.reference);
  654. else
  655. internalerror(200203311);
  656. end;
  657. end;
  658. function tcg.optimize_op_const_reg(list: taasmoutput; var op: topcg; var a : aword; var reg:tregister): boolean;
  659. var
  660. powerval : longint;
  661. begin
  662. optimize_op_const_reg := false;
  663. case op of
  664. { or with zero returns same result }
  665. OP_OR : if a = 0 then optimize_op_const_reg := true;
  666. { and with max returns same result }
  667. OP_AND : if (a = high(a)) then optimize_op_const_reg := true;
  668. { division by 1 returns result }
  669. OP_DIV :
  670. begin
  671. if a = 1 then
  672. optimize_op_const_reg := true
  673. else if ispowerof2(int64(a), powerval) then
  674. begin
  675. a := powerval;
  676. op:= OP_SHR;
  677. end;
  678. exit;
  679. end;
  680. OP_IDIV:
  681. begin
  682. if a = 1 then
  683. optimize_op_const_reg := true
  684. else if ispowerof2(int64(a), powerval) then
  685. begin
  686. a := powerval;
  687. op:= OP_SAR;
  688. end;
  689. exit;
  690. end;
  691. OP_MUL,OP_IMUL:
  692. begin
  693. if a = 1 then
  694. optimize_op_const_reg := true
  695. else if ispowerof2(int64(a), powerval) then
  696. begin
  697. a := powerval;
  698. op:= OP_SHL;
  699. end;
  700. exit;
  701. end;
  702. OP_SAR,OP_SHL,OP_SHR:
  703. begin
  704. if a = 0 then
  705. optimize_op_const_reg := true;
  706. exit;
  707. end;
  708. end;
  709. end;
  710. procedure tcg.a_loadfpu_loc_reg(list: taasmoutput; const loc: tlocation; const reg: tregister);
  711. begin
  712. case loc.loc of
  713. LOC_REFERENCE, LOC_CREFERENCE:
  714. a_loadfpu_ref_reg(list,loc.size,loc.reference,reg);
  715. LOC_FPUREGISTER, LOC_CFPUREGISTER:
  716. a_loadfpu_reg_reg(list,loc.register,reg);
  717. else
  718. runerror(226);
  719. // internalerror(200203301);
  720. end;
  721. end;
  722. procedure tcg.a_loadfpu_reg_loc(list: taasmoutput; size: tcgsize; const reg: tregister; const loc: tlocation);
  723. begin
  724. case loc.loc of
  725. LOC_REFERENCE, LOC_CREFERENCE:
  726. a_loadfpu_reg_ref(list,size,reg,loc.reference);
  727. LOC_FPUREGISTER, LOC_CFPUREGISTER:
  728. a_loadfpu_reg_reg(list,reg,loc.register);
  729. else
  730. internalerror(48991);
  731. end;
  732. end;
  733. procedure tcg.a_op_const_ref(list : taasmoutput; Op: TOpCG; size: TCGSize; a: AWord; const ref: TReference);
  734. var
  735. tmpreg: tregister;
  736. begin
  737. tmpreg := get_scratch_reg_int(list);
  738. a_load_ref_reg(list,size,ref,tmpreg);
  739. a_op_const_reg(list,op,a,tmpreg);
  740. a_load_reg_ref(list,size,tmpreg,ref);
  741. free_scratch_reg(list,tmpreg);
  742. end;
  743. procedure tcg.a_op_const_loc(list : taasmoutput; Op: TOpCG; a: AWord; const loc: tlocation);
  744. begin
  745. case loc.loc of
  746. LOC_REGISTER, LOC_CREGISTER:
  747. a_op_const_reg(list,op,a,loc.register);
  748. LOC_REFERENCE, LOC_CREFERENCE:
  749. a_op_const_ref(list,op,loc.size,a,loc.reference);
  750. else
  751. internalerror(200109061);
  752. end;
  753. end;
  754. procedure tcg.a_op_reg_ref(list : taasmoutput; Op: TOpCG; size: TCGSize;reg: TRegister; const ref: TReference);
  755. var
  756. tmpreg: tregister;
  757. begin
  758. tmpreg := get_scratch_reg_int(list);
  759. a_load_ref_reg(list,size,ref,tmpreg);
  760. a_op_reg_reg(list,op,size,reg,tmpreg);
  761. a_load_reg_ref(list,size,tmpreg,ref);
  762. free_scratch_reg(list,tmpreg);
  763. end;
  764. procedure tcg.a_op_ref_reg(list : taasmoutput; Op: TOpCG; size: TCGSize; const ref: TReference; reg: TRegister);
  765. var
  766. tmpreg: tregister;
  767. begin
  768. case op of
  769. OP_NOT,OP_NEG:
  770. { handle it as "load ref,reg; op reg" }
  771. begin
  772. a_load_ref_reg(list,size,ref,reg);
  773. a_op_reg_reg(list,op,size,reg,reg);
  774. end;
  775. else
  776. begin
  777. tmpreg := get_scratch_reg_int(list);
  778. a_load_ref_reg(list,size,ref,tmpreg);
  779. a_op_reg_reg(list,op,size,tmpreg,reg);
  780. free_scratch_reg(list,tmpreg);
  781. end;
  782. end;
  783. end;
  784. procedure tcg.a_op_reg_loc(list : taasmoutput; Op: TOpCG; reg: tregister; const loc: tlocation);
  785. begin
  786. case loc.loc of
  787. LOC_REGISTER, LOC_CREGISTER:
  788. a_op_reg_reg(list,op,loc.size,reg,loc.register);
  789. LOC_REFERENCE, LOC_CREFERENCE:
  790. a_op_reg_ref(list,op,loc.size,reg,loc.reference);
  791. else
  792. internalerror(200109061);
  793. end;
  794. end;
  795. procedure tcg.a_op_ref_loc(list : taasmoutput; Op: TOpCG; const ref: TReference; const loc: tlocation);
  796. var
  797. tmpreg: tregister;
  798. begin
  799. case loc.loc of
  800. LOC_REGISTER,LOC_CREGISTER:
  801. a_op_ref_reg(list,op,loc.size,ref,loc.register);
  802. LOC_REFERENCE,LOC_CREFERENCE:
  803. begin
  804. tmpreg := get_scratch_reg_int(list);
  805. tmpreg:=rg.makeregsize(tmpreg,loc.size);
  806. a_load_ref_reg(list,loc.size,ref,tmpreg);
  807. a_op_reg_ref(list,op,loc.size,tmpreg,loc.reference);
  808. free_scratch_reg(list,tmpreg);
  809. end;
  810. else
  811. internalerror(200109061);
  812. end;
  813. end;
  814. procedure tcg.a_op_const_reg_reg(list: taasmoutput; op: TOpCg;
  815. size: tcgsize; a: aword; src, dst: tregister);
  816. begin
  817. a_load_reg_reg(list,size,size,src,dst);
  818. a_op_const_reg(list,op,a,dst);
  819. end;
  820. procedure tcg.a_op_reg_reg_reg(list: taasmoutput; op: TOpCg;
  821. size: tcgsize; src1, src2, dst: tregister);
  822. begin
  823. a_load_reg_reg(list,size,size,src2,dst);
  824. a_op_reg_reg(list,op,size,src1,dst);
  825. end;
  826. procedure tcg.a_cmp_const_ref_label(list : taasmoutput;size : tcgsize;cmp_op : topcmp;a : aword;const ref : treference;
  827. l : tasmlabel);
  828. var
  829. tmpreg: tregister;
  830. begin
  831. tmpreg := get_scratch_reg_int(list);
  832. a_load_ref_reg(list,size,ref,tmpreg);
  833. a_cmp_const_reg_label(list,size,cmp_op,a,tmpreg,l);
  834. free_scratch_reg(list,tmpreg);
  835. end;
  836. procedure tcg.a_cmp_const_loc_label(list : taasmoutput;size : tcgsize;cmp_op : topcmp;a : aword;const loc : tlocation;
  837. l : tasmlabel);
  838. begin
  839. case loc.loc of
  840. LOC_REGISTER,LOC_CREGISTER:
  841. a_cmp_const_reg_label(list,size,cmp_op,a,loc.register,l);
  842. LOC_REFERENCE,LOC_CREFERENCE:
  843. a_cmp_const_ref_label(list,size,cmp_op,a,loc.reference,l);
  844. else
  845. internalerror(200109061);
  846. end;
  847. end;
  848. procedure tcg.a_cmp_ref_reg_label(list : taasmoutput;size : tcgsize;cmp_op : topcmp; const ref: treference; reg : tregister; l : tasmlabel);
  849. var
  850. tmpreg: tregister;
  851. begin
  852. tmpreg := get_scratch_reg_int(list);
  853. a_load_ref_reg(list,size,ref,tmpreg);
  854. a_cmp_reg_reg_label(list,size,cmp_op,tmpreg,reg,l);
  855. free_scratch_reg(list,tmpreg);
  856. end;
  857. procedure tcg.a_cmp_loc_reg_label(list : taasmoutput;size : tcgsize;cmp_op : topcmp; const loc: tlocation; reg : tregister; l : tasmlabel);
  858. begin
  859. case loc.loc of
  860. LOC_REGISTER,
  861. LOC_CREGISTER:
  862. a_cmp_reg_reg_label(list,size,cmp_op,loc.register,reg,l);
  863. LOC_REFERENCE,
  864. LOC_CREFERENCE :
  865. a_cmp_ref_reg_label(list,size,cmp_op,loc.reference,reg,l);
  866. LOC_CONSTANT:
  867. a_cmp_const_reg_label(list,size,cmp_op,loc.value,reg,l);
  868. else
  869. internalerror(200203231);
  870. end;
  871. end;
  872. procedure tcg.a_cmp_ref_loc_label(list : taasmoutput;size : tcgsize;cmp_op : topcmp;const ref: treference;const loc : tlocation;
  873. l : tasmlabel);
  874. var
  875. tmpreg: tregister;
  876. begin
  877. case loc.loc of
  878. LOC_REGISTER,LOC_CREGISTER:
  879. a_cmp_ref_reg_label(list,size,cmp_op,ref,loc.register,l);
  880. LOC_REFERENCE,LOC_CREFERENCE:
  881. begin
  882. {$ifdef i386}
  883. { the following is done with defines to avoid a speed penalty, }
  884. { since all this is only necessary for the 80x86 (because EDI }
  885. { doesn't have an 8bit component which is directly addressable) }
  886. if size in [OS_8,OS_S8] then
  887. tmpreg := rg.getregisterint(list)
  888. else
  889. {$endif i386}
  890. tmpreg := get_scratch_reg_int(list);
  891. tmpreg := rg.makeregsize(tmpreg,size);
  892. a_load_ref_reg(list,size,loc.reference,tmpreg);
  893. a_cmp_ref_reg_label(list,size,cmp_op,ref,tmpreg,l);
  894. {$ifdef i386}
  895. if size in [OS_8,OS_S8] then
  896. rg.ungetregister(list,tmpreg)
  897. else
  898. {$endif i386}
  899. free_scratch_reg(list,tmpreg);
  900. end
  901. else
  902. internalerror(200109061);
  903. end;
  904. end;
  905. class function tcg.reg_cgsize(const reg: tregister) : tcgsize;
  906. begin
  907. reg_cgsize := OS_INT;
  908. end;
  909. procedure tcg.g_copyshortstring(list : taasmoutput;const source,dest : treference;len:byte;delsource,loadref : boolean);
  910. begin
  911. {$ifdef FPC}
  912. {$warning FIX ME!}
  913. {$endif}
  914. a_paramaddr_ref(list,dest,paramanager.getintparaloc(3));
  915. if loadref then
  916. a_param_ref(list,OS_ADDR,source,paramanager.getintparaloc(2))
  917. else
  918. a_paramaddr_ref(list,source,paramanager.getintparaloc(2));
  919. if delsource then
  920. reference_release(list,source);
  921. a_param_const(list,OS_INT,len,paramanager.getintparaloc(1));
  922. a_call_name(list,'FPC_SHORTSTR_ASSIGN');
  923. g_maybe_loadself(list);
  924. end;
  925. procedure tcg.g_incrrefcount(list : taasmoutput;t: tdef; const ref: treference);
  926. var
  927. href : treference;
  928. incrfunc : string;
  929. begin
  930. { These functions should not change the registers (they use
  931. the saveregister proc directive }
  932. if is_interfacecom(t) then
  933. incrfunc:='FPC_INTF_INCR_REF'
  934. else if is_ansistring(t) then
  935. incrfunc:='FPC_ANSISTR_INCR_REF'
  936. else if is_widestring(t) then
  937. incrfunc:='FPC_WIDESTR_INCR_REF'
  938. else if is_dynamic_array(t) then
  939. incrfunc:='FPC_DYNARRAY_INCR_REF'
  940. else
  941. incrfunc:='';
  942. { call the special incr function or the generic addref }
  943. if incrfunc<>'' then
  944. begin
  945. a_param_ref(list,OS_ADDR,ref,paramanager.getintparaloc(1));
  946. a_call_name(list,incrfunc);
  947. end
  948. else
  949. begin
  950. reference_reset_symbol(href,tstoreddef(t).get_rtti_label(initrtti),0);
  951. a_paramaddr_ref(list,href,paramanager.getintparaloc(2));
  952. a_paramaddr_ref(list,ref,paramanager.getintparaloc(1));
  953. a_call_name(list,'FPC_ADDREF');
  954. end;
  955. end;
  956. procedure tcg.g_decrrefcount(list : taasmoutput;t: tdef; const ref: treference);
  957. var
  958. href : treference;
  959. decrfunc : string;
  960. needrtti : boolean;
  961. begin
  962. needrtti:=false;
  963. if is_interfacecom(t) then
  964. decrfunc:='FPC_INTF_DECR_REF'
  965. else if is_ansistring(t) then
  966. decrfunc:='FPC_ANSISTR_DECR_REF'
  967. else if is_widestring(t) then
  968. decrfunc:='FPC_WIDESTR_DECR_REF'
  969. else if is_dynamic_array(t) then
  970. begin
  971. decrfunc:='FPC_DYNARRAY_DECR_REF';
  972. needrtti:=true;
  973. end
  974. else
  975. decrfunc:='';
  976. { call the special decr function or the generic decref }
  977. if decrfunc<>'' then
  978. begin
  979. if needrtti then
  980. begin
  981. reference_reset_symbol(href,tstoreddef(t).get_rtti_label(initrtti),0);
  982. a_paramaddr_ref(list,href,paramanager.getintparaloc(2));
  983. end;
  984. a_paramaddr_ref(list,ref,paramanager.getintparaloc(1));
  985. a_call_name(list,decrfunc);
  986. end
  987. else
  988. begin
  989. reference_reset_symbol(href,tstoreddef(t).get_rtti_label(initrtti),0);
  990. a_paramaddr_ref(list,href,paramanager.getintparaloc(2));
  991. a_paramaddr_ref(list,ref,paramanager.getintparaloc(1));
  992. a_call_name(list,'FPC_DECREF');
  993. end;
  994. end;
  995. procedure tcg.g_initialize(list : taasmoutput;t : tdef;const ref : treference;loadref : boolean);
  996. var
  997. href : treference;
  998. begin
  999. if is_ansistring(t) or
  1000. is_widestring(t) or
  1001. is_interfacecom(t) then
  1002. a_load_const_ref(list,OS_ADDR,0,ref)
  1003. else
  1004. begin
  1005. reference_reset_symbol(href,tstoreddef(t).get_rtti_label(initrtti),0);
  1006. a_paramaddr_ref(list,href,paramanager.getintparaloc(2));
  1007. if loadref then
  1008. a_param_ref(list,OS_ADDR,ref,paramanager.getintparaloc(1))
  1009. else
  1010. a_paramaddr_ref(list,ref,paramanager.getintparaloc(1));
  1011. a_call_name(list,'FPC_INITIALIZE');
  1012. end;
  1013. end;
  1014. procedure tcg.g_finalize(list : taasmoutput;t : tdef;const ref : treference;loadref : boolean);
  1015. var
  1016. href : treference;
  1017. begin
  1018. if is_ansistring(t) or
  1019. is_widestring(t) or
  1020. is_interfacecom(t) then
  1021. g_decrrefcount(list,t,ref)
  1022. else
  1023. begin
  1024. reference_reset_symbol(href,tstoreddef(t).get_rtti_label(initrtti),0);
  1025. a_paramaddr_ref(list,href,paramanager.getintparaloc(2));
  1026. if loadref then
  1027. a_param_ref(list,OS_ADDR,ref,paramanager.getintparaloc(1))
  1028. else
  1029. a_paramaddr_ref(list,ref,paramanager.getintparaloc(1));
  1030. a_call_name(list,'FPC_FINALIZE');
  1031. end;
  1032. end;
  1033. procedure tcg.g_rangecheck(list: taasmoutput; const p: tnode;const todef: tdef);
  1034. { generate range checking code for the value at location p. The type }
  1035. { type used is checked against todefs ranges. fromdef (p.resulttype.def) }
  1036. { is the original type used at that location. When both defs are equal }
  1037. { the check is also insert (needed for succ,pref,inc,dec) }
  1038. const
  1039. {$ifdef ver1_0}
  1040. awordsignedmax=high(longint);
  1041. {$else}
  1042. awordsignedmax=high(aword) div 2;
  1043. {$endif}
  1044. var
  1045. neglabel : tasmlabel;
  1046. hreg : tregister;
  1047. fromdef : tdef;
  1048. lto,hto,
  1049. lfrom,hfrom : TConstExprInt;
  1050. from_signed: boolean;
  1051. begin
  1052. { range checking on and range checkable value? }
  1053. if not(cs_check_range in aktlocalswitches) or
  1054. not(todef.deftype in [orddef,enumdef,arraydef]) then
  1055. exit;
  1056. if is_64bitint(p.resulttype.def) or is_64bitint(todef) then
  1057. begin
  1058. cg64.g_rangecheck64(list,p,todef);
  1059. exit;
  1060. end;
  1061. { only check when assigning to scalar, subranges are different, }
  1062. { when todef=fromdef then the check is always generated }
  1063. fromdef:=p.resulttype.def;
  1064. getrange(p.resulttype.def,lfrom,hfrom);
  1065. getrange(todef,lto,hto);
  1066. { no range check if from and to are equal and are both longint/dword }
  1067. { (if we have a 32bit processor) or int64/qword, since such }
  1068. { operations can at most cause overflows (JM) }
  1069. { Note that these checks are mostly processor independent, they only }
  1070. { have to be changed once we introduce 64bit subrange types }
  1071. if (fromdef = todef) and
  1072. (fromdef.deftype=orddef) and
  1073. (((sizeof(aword) = 4) and
  1074. (((torddef(fromdef).typ = s32bit) and
  1075. (lfrom = low(longint)) and
  1076. (hfrom = high(longint))) or
  1077. ((torddef(fromdef).typ = u32bit) and
  1078. (lfrom = low(cardinal)) and
  1079. (hfrom = high(cardinal)))))) then
  1080. exit;
  1081. if todef<>fromdef then
  1082. begin
  1083. { if the from-range falls completely in the to-range, no check }
  1084. { is necessary }
  1085. if (lto<=lfrom) and (hto>=hfrom) then
  1086. exit;
  1087. end;
  1088. { generate the rangecheck code for the def where we are going to }
  1089. { store the result }
  1090. { use the trick that }
  1091. { a <= x <= b <=> 0 <= x-a <= b-a <=> unsigned(x-a) <= unsigned(b-a) }
  1092. { To be able to do that, we have to make sure however that either }
  1093. { fromdef and todef are both signed or unsigned, or that we leave }
  1094. { the parts < 0 and > maxlongint out }
  1095. { is_signed now also works for arrays (it checks the rangetype) (JM) }
  1096. from_signed := is_signed(fromdef);
  1097. if from_signed xor is_signed(todef) then
  1098. if from_signed then
  1099. { from is signed, to is unsigned }
  1100. begin
  1101. { if high(from) < 0 -> always range error }
  1102. if (hfrom < 0) or
  1103. { if low(to) > maxlongint also range error }
  1104. (lto > awordsignedmax) then
  1105. begin
  1106. a_call_name(list,'FPC_RANGEERROR');
  1107. exit
  1108. end;
  1109. { from is signed and to is unsigned -> when looking at from }
  1110. { as an unsigned value, it must be < maxlongint (otherwise }
  1111. { it's negative, which is invalid since "to" is unsigned) }
  1112. if hto > awordsignedmax then
  1113. hto := awordsignedmax;
  1114. end
  1115. else
  1116. { from is unsigned, to is signed }
  1117. begin
  1118. if (lfrom > awordsignedmax) or
  1119. (hto < 0) then
  1120. begin
  1121. a_call_name(list,'FPC_RANGEERROR');
  1122. exit
  1123. end;
  1124. { from is unsigned and to is signed -> when looking at to }
  1125. { as an unsigned value, it must be >= 0 (since negative }
  1126. { values are the same as values > maxlongint) }
  1127. if lto < 0 then
  1128. lto := 0;
  1129. end;
  1130. hreg := get_scratch_reg_int(list);
  1131. if (p.location.loc in [LOC_REGISTER,LOC_CREGISTER]) then
  1132. a_op_const_reg_reg(list,OP_SUB,def_cgsize(p.resulttype.def),
  1133. aword(lto),p.location.register,hreg)
  1134. else
  1135. begin
  1136. a_load_ref_reg(list,def_cgsize(p.resulttype.def),
  1137. p.location.reference,hreg);
  1138. a_op_const_reg(list,OP_SUB,aword(lto),hreg);
  1139. end;
  1140. objectlibrary.getlabel(neglabel);
  1141. a_cmp_const_reg_label(list,OS_INT,OC_BE,aword(hto-lto),hreg,neglabel);
  1142. { !!! should happen right after the compare (JM) }
  1143. free_scratch_reg(list,hreg);
  1144. a_call_name(list,'FPC_RANGEERROR');
  1145. a_label(list,neglabel);
  1146. end;
  1147. procedure tcg.g_stackcheck(list : taasmoutput;stackframesize : longint);
  1148. begin
  1149. a_param_const(list,OS_32,stackframesize,paramanager.getintparaloc(1));
  1150. a_call_name(list,'FPC_STACKCHECK');
  1151. end;
  1152. procedure tcg.g_flags2ref(list: taasmoutput; size: TCgSize; const f: tresflags; const ref:TReference);
  1153. var
  1154. tmpreg : tregister;
  1155. begin
  1156. tmpreg := get_scratch_reg_int(list);
  1157. g_flags2reg(list,size,f,tmpreg);
  1158. a_load_reg_ref(list,size,tmpreg,ref);
  1159. free_scratch_reg(list,tmpreg);
  1160. end;
  1161. procedure tcg.g_maybe_loadself(list : taasmoutput);
  1162. var
  1163. hp : treference;
  1164. p : tprocinfo;
  1165. i : longint;
  1166. begin
  1167. if assigned(procinfo._class) then
  1168. begin
  1169. list.concat(tai_regalloc.Alloc(SELF_POINTER_REG));
  1170. if lexlevel>normal_function_level then
  1171. begin
  1172. reference_reset_base(hp,procinfo.framepointer,procinfo.framepointer_offset);
  1173. a_load_ref_reg(list,OS_ADDR,hp,SELF_POINTER_REG);
  1174. p:=procinfo.parent;
  1175. for i:=3 to lexlevel-1 do
  1176. begin
  1177. reference_reset_base(hp,SELF_POINTER_REG,p.framepointer_offset);
  1178. a_load_ref_reg(list,OS_ADDR,hp,SELF_POINTER_REG);
  1179. p:=p.parent;
  1180. end;
  1181. reference_reset_base(hp,SELF_POINTER_REG,p.selfpointer_offset);
  1182. a_load_ref_reg(list,OS_ADDR,hp,SELF_POINTER_REG);
  1183. end
  1184. else
  1185. begin
  1186. reference_reset_base(hp,procinfo.framepointer,procinfo.selfpointer_offset);
  1187. a_load_ref_reg(list,OS_ADDR,hp,SELF_POINTER_REG);
  1188. end;
  1189. end;
  1190. end;
  1191. {*****************************************************************************
  1192. Entry/Exit Code Functions
  1193. *****************************************************************************}
  1194. procedure tcg.g_call_constructor_helper(list : taasmoutput);
  1195. var
  1196. href : treference;
  1197. hregister : tregister;
  1198. begin
  1199. if is_class(procinfo._class) then
  1200. begin
  1201. if (cs_implicit_exceptions in aktmoduleswitches) then
  1202. procinfo.flags:=procinfo.flags or pi_needs_implicit_finally;
  1203. { parameter 2 : self pointer / flag }
  1204. {!! this is a terrible hack, normally the helper should get three params : }
  1205. { one with self register, one with flag and one with VMT pointer }
  1206. {reference_reset_base(href, procinfo.framepointer,procinfo.selfpointer_offset+POINTER_SIZE);}
  1207. a_param_reg(list, OS_ADDR, SELF_POINTER_REG, paramanager.getintparaloc(2));
  1208. { parameter 1 : vmt pointer (stored at the selfpointer address on stack) }
  1209. reference_reset_base(href, procinfo.framepointer,procinfo.selfpointer_offset);
  1210. a_param_ref(list, OS_ADDR,href,paramanager.getintparaloc(1));
  1211. a_call_name(list,'FPC_NEW_CLASS');
  1212. a_load_reg_reg(list,OS_ADDR,OS_ADDR,accumulator,SELF_POINTER_REG);
  1213. { save the self pointer result }
  1214. a_load_reg_ref(list,OS_ADDR,SELF_POINTER_REG,href);
  1215. a_cmp_const_reg_label(list,OS_ADDR,OC_EQ,0,accumulator,faillabel);
  1216. end
  1217. else if is_object(procinfo._class) then
  1218. begin
  1219. { parameter 3 :vmt_offset }
  1220. a_param_const(list, OS_32, procinfo._class.vmt_offset, paramanager.getintparaloc(3));
  1221. { parameter 2 : address of pointer to vmt }
  1222. { this is the first(?) parameter which was pushed to the constructor }
  1223. reference_reset_base(href, procinfo.framepointer,procinfo.selfpointer_offset-POINTER_SIZE);
  1224. hregister:=get_scratch_reg_address(list);
  1225. a_loadaddr_ref_reg(list, href, hregister);
  1226. a_param_reg(list, OS_ADDR,hregister,paramanager.getintparaloc(2));
  1227. free_scratch_reg(list, hregister);
  1228. { parameter 1 : address of self pointer }
  1229. reference_reset_base(href, procinfo.framepointer,procinfo.selfpointer_offset);
  1230. hregister:=get_scratch_reg_address(list);
  1231. a_loadaddr_ref_reg(list, href, hregister);
  1232. a_param_reg(list, OS_ADDR,hregister,paramanager.getintparaloc(1));
  1233. free_scratch_reg(list, hregister);
  1234. a_call_name(list,'FPC_HELP_CONSTRUCTOR');
  1235. a_load_reg_reg(list,OS_ADDR,OS_ADDR,accumulator,SELF_POINTER_REG);
  1236. a_cmp_const_reg_label(list,OS_ADDR,OC_EQ,0,accumulator,faillabel);
  1237. end
  1238. else
  1239. internalerror(200006161);
  1240. end;
  1241. procedure tcg.g_call_destructor_helper(list : taasmoutput);
  1242. var
  1243. nofinal : tasmlabel;
  1244. href : treference;
  1245. hregister : tregister;
  1246. begin
  1247. if is_class(procinfo._class) then
  1248. begin
  1249. { 2nd parameter : flag }
  1250. reference_reset_base(href, procinfo.framepointer,procinfo.selfpointer_offset+POINTER_SIZE);
  1251. a_param_ref(list, OS_ADDR,href,paramanager.getintparaloc(2));
  1252. { 1st parameter to destructor : self }
  1253. reference_reset_base(href, procinfo.framepointer,procinfo.selfpointer_offset);
  1254. a_param_ref(list, OS_ADDR,href,paramanager.getintparaloc(1));
  1255. a_call_name(list,'FPC_DISPOSE_CLASS')
  1256. end
  1257. else if is_object(procinfo._class) then
  1258. begin
  1259. { must the object be finalized ? }
  1260. if procinfo._class.needs_inittable then
  1261. begin
  1262. objectlibrary.getlabel(nofinal);
  1263. reference_reset_base(href,procinfo.framepointer,target_info.first_parm_offset);
  1264. a_cmp_const_ref_label(list,OS_ADDR,OC_EQ,0,href,nofinal);
  1265. reference_reset_base(href,SELF_POINTER_REG,0);
  1266. g_finalize(list,procinfo._class,href,false);
  1267. a_label(list,nofinal);
  1268. end;
  1269. { actually call destructor }
  1270. { parameter 3 :vmt_offset }
  1271. a_param_const(list, OS_32, procinfo._class.vmt_offset, paramanager.getintparaloc(3));
  1272. { parameter 2 : pointer to vmt }
  1273. { this is the first parameter which was pushed to the destructor }
  1274. reference_reset_base(href, procinfo.framepointer,procinfo.selfpointer_offset-POINTER_SIZE);
  1275. a_param_ref(list, OS_ADDR, href ,paramanager.getintparaloc(2));
  1276. { parameter 1 : address of self pointer }
  1277. reference_reset_base(href, procinfo.framepointer,procinfo.selfpointer_offset);
  1278. hregister:=get_scratch_reg_address(list);
  1279. a_loadaddr_ref_reg(list, href, hregister);
  1280. a_param_reg(list, OS_ADDR,hregister,paramanager.getintparaloc(1));
  1281. free_scratch_reg(list, hregister);
  1282. a_call_name(list,'FPC_HELP_DESTRUCTOR');
  1283. end
  1284. else
  1285. internalerror(200006162);
  1286. end;
  1287. procedure tcg.g_call_fail_helper(list : taasmoutput);
  1288. var
  1289. href : treference;
  1290. hregister : tregister;
  1291. begin
  1292. if is_class(procinfo._class) then
  1293. begin
  1294. {
  1295. Dispose of the class then set self_pointer to nil
  1296. both in stack and in self register.
  1297. }
  1298. { 2nd parameter : flag }
  1299. a_param_const(list,OS_32,1,paramanager.getintparaloc(2));
  1300. { 1st parameter to destructor : self }
  1301. reference_reset_base(href, procinfo.framepointer,procinfo.selfpointer_offset);
  1302. a_param_ref(list, OS_ADDR,href,paramanager.getintparaloc(1));
  1303. a_call_name(list,'FPC_DISPOSE_CLASS');
  1304. { SET SELF TO NIL }
  1305. a_load_const_reg(list,OS_ADDR,0,SELF_POINTER_REG);
  1306. { set the self pointer in the stack to nil }
  1307. a_load_reg_ref(list,OS_ADDR,SELF_POINTER_REG,href);
  1308. end
  1309. else if is_object(procinfo._class) then
  1310. begin
  1311. { parameter 3 :vmt_offset }
  1312. a_param_const(list, OS_32, procinfo._class.vmt_offset, paramanager.getintparaloc(3));
  1313. { parameter 2 : address of pointer to vmt }
  1314. { this is the first(?) parameter which was pushed to the constructor }
  1315. reference_reset_base(href, procinfo.framepointer,procinfo.selfpointer_offset-POINTER_SIZE);
  1316. hregister:=get_scratch_reg_address(list);
  1317. a_loadaddr_ref_reg(list, href, hregister);
  1318. a_param_reg(list, OS_ADDR,hregister,paramanager.getintparaloc(2));
  1319. free_scratch_reg(list, hregister);
  1320. { parameter 1 : address of self pointer }
  1321. reference_reset_base(href, procinfo.framepointer,procinfo.selfpointer_offset);
  1322. hregister:=get_scratch_reg_address(list);
  1323. a_loadaddr_ref_reg(list, href, hregister);
  1324. a_param_reg(list, OS_ADDR,hregister,paramanager.getintparaloc(1));
  1325. free_scratch_reg(list, hregister);
  1326. a_call_name(list,'FPC_HELP_FAIL');
  1327. { SET SELF TO NIL }
  1328. a_load_const_reg(list,OS_ADDR,0,SELF_POINTER_REG);
  1329. end
  1330. else
  1331. internalerror(200006163);
  1332. end;
  1333. procedure tcg.g_interrupt_stackframe_entry(list : taasmoutput);
  1334. begin
  1335. end;
  1336. procedure tcg.g_interrupt_stackframe_exit(list : taasmoutput;selfused,accused,acchiused:boolean);
  1337. begin
  1338. end;
  1339. procedure tcg.g_profilecode(list : taasmoutput);
  1340. begin
  1341. end;
  1342. procedure tcg.g_exception_reason_save(list : taasmoutput; const href : treference);
  1343. begin
  1344. a_load_reg_ref(list, OS_S32, accumulator, href);
  1345. end;
  1346. procedure tcg.g_exception_reason_save_const(list : taasmoutput; const href : treference; a: aword);
  1347. begin
  1348. a_load_const_ref(list, OS_S32, a, href);
  1349. end;
  1350. procedure tcg.g_exception_reason_load(list : taasmoutput; const href : treference);
  1351. begin
  1352. a_load_ref_reg(list, OS_S32, href, accumulator);
  1353. end;
  1354. procedure tcg64.a_op64_const_reg_reg(list: taasmoutput;op:TOpCG;value : qword;
  1355. regsrc,regdst : tregister64);
  1356. begin
  1357. a_load64_reg_reg(list,regsrc,regdst);
  1358. a_op64_const_reg(list,op,value,regdst);
  1359. end;
  1360. procedure tcg64.a_op64_reg_reg_reg(list: taasmoutput;op:TOpCG;regsrc1,regsrc2,regdst : tregister64);
  1361. begin
  1362. a_load64_reg_reg(list,regsrc2,regdst);
  1363. a_op64_reg_reg(list,op,regsrc1,regdst);
  1364. end;
  1365. initialization
  1366. ;
  1367. finalization
  1368. cg.free;
  1369. cg64.free;
  1370. end.
  1371. {
  1372. $Log$
  1373. Revision 1.62 2002-10-16 19:01:43 peter
  1374. + $IMPLICITEXCEPTIONS switch to turn on/off generation of the
  1375. implicit exception frames for procedures with initialized variables
  1376. and for constructors. The default is on for compatibility
  1377. Revision 1.61 2002/10/05 12:43:23 carl
  1378. * fixes for Delphi 6 compilation
  1379. (warning : Some features do not work under Delphi)
  1380. Revision 1.60 2002/10/02 18:20:52 peter
  1381. * Copy() is now internal syssym that calls compilerprocs
  1382. Revision 1.59 2002/09/17 18:54:02 jonas
  1383. * a_load_reg_reg() now has two size parameters: source and dest. This
  1384. allows some optimizations on architectures that don't encode the
  1385. register size in the register name.
  1386. Revision 1.58 2002/09/09 19:29:29 peter
  1387. * fixed dynarr_decr_ref call
  1388. Revision 1.57 2002/09/07 15:25:01 peter
  1389. * old logs removed and tabs fixed
  1390. Revision 1.56 2002/09/01 21:04:47 florian
  1391. * several powerpc related stuff fixed
  1392. Revision 1.55 2002/09/01 17:05:43 florian
  1393. + added abstract tcg.g_removevaluepara_openarray
  1394. Revision 1.54 2002/09/01 12:09:27 peter
  1395. + a_call_reg, a_call_loc added
  1396. * removed exprasmlist references
  1397. Revision 1.53 2002/08/19 18:17:48 carl
  1398. + optimize64_op_const_reg implemented (optimizes 64-bit constant opcodes)
  1399. * more fixes to m68k for 64-bit operations
  1400. Revision 1.52 2002/08/17 22:09:43 florian
  1401. * result type handling in tcgcal.pass_2 overhauled
  1402. * better tnode.dowrite
  1403. * some ppc stuff fixed
  1404. Revision 1.51 2002/08/17 09:23:33 florian
  1405. * first part of procinfo rewrite
  1406. Revision 1.50 2002/08/16 14:24:57 carl
  1407. * issameref() to test if two references are the same (then emit no opcodes)
  1408. + ret_in_reg to replace ret_in_acc
  1409. (fix some register allocation bugs at the same time)
  1410. + save_std_register now has an extra parameter which is the
  1411. usedinproc registers
  1412. Revision 1.49 2002/08/15 08:13:54 carl
  1413. - a_load_sym_ofs_reg removed
  1414. * loadvmt now calls loadaddr_ref_reg instead
  1415. Revision 1.48 2002/08/14 19:26:02 carl
  1416. + routine to optimize opcodes with constants
  1417. Revision 1.47 2002/08/11 14:32:26 peter
  1418. * renamed current_library to objectlibrary
  1419. Revision 1.46 2002/08/11 13:24:11 peter
  1420. * saving of asmsymbols in ppu supported
  1421. * asmsymbollist global is removed and moved into a new class
  1422. tasmlibrarydata that will hold the info of a .a file which
  1423. corresponds with a single module. Added librarydata to tmodule
  1424. to keep the library info stored for the module. In the future the
  1425. objectfiles will also be stored to the tasmlibrarydata class
  1426. * all getlabel/newasmsymbol and friends are moved to the new class
  1427. Revision 1.45 2002/08/10 17:15:20 jonas
  1428. * register parameters are now LOC_CREGISTER instead of LOC_REGISTER
  1429. Revision 1.44 2002/08/09 19:10:05 carl
  1430. - moved new_exception and free_exception to ncgutils
  1431. Revision 1.43 2002/08/05 18:27:48 carl
  1432. + more more more documentation
  1433. + first version include/exclude (can't test though, not enough scratch for i386 :()...
  1434. Revision 1.42 2002/08/04 19:08:21 carl
  1435. + added generic exception support (still does not work!)
  1436. + more documentation
  1437. Revision 1.41 2002/07/30 20:50:43 florian
  1438. * the code generator knows now if parameters are in registers
  1439. Revision 1.40 2002/07/29 21:16:02 florian
  1440. * some more ppc fixes
  1441. Revision 1.39 2002/07/28 15:56:00 jonas
  1442. + tcg64.a_op64_const_reg_reg() and tcg64.a_op64_reg_reg_reg() methods +
  1443. generic implementation
  1444. Revision 1.38 2002/07/27 19:53:51 jonas
  1445. + generic implementation of tcg.g_flags2ref()
  1446. * tcg.flags2xxx() now also needs a size parameter
  1447. Revision 1.37 2002/07/20 11:57:53 florian
  1448. * types.pas renamed to defbase.pas because D6 contains a types
  1449. unit so this would conflicts if D6 programms are compiled
  1450. + Willamette/SSE2 instructions to assembler added
  1451. }