cgobj.pas 70 KB

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