cgobj.pas 73 KB

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