cgobj.pas 68 KB

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