cgobj.pas 68 KB

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