cgobj.pas 69 KB

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