cgobj.pas 69 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764
  1. {
  2. $Id$
  3. Copyright (c) 1998-2000 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. }
  23. unit cgobj;
  24. {$i defines.inc}
  25. interface
  26. uses
  27. cclasses,aasm,symtable,
  28. cpuasm,cpubase,cpuinfo,
  29. cginfo,
  30. symconst,symbase,symtype,node;
  31. type
  32. talignment = (AM_NATURAL,AM_NONE,AM_2BYTE,AM_4BYTE,AM_8BYTE);
  33. {# @abstract(Abstract code generator)
  34. This class implements an abstract instruction generator. Some of
  35. the methods of this class are generic, while others must
  36. be overriden for all new processors which will be supported
  37. by Free Pascal. For 32-bit processors, the base class
  38. sould be @link(tcg64f32) and not @var(tcg).
  39. }
  40. tcg = class
  41. scratch_register_array_pointer : aword;
  42. {# List of currently unused scratch registers }
  43. unusedscratchregisters : tregisterset;
  44. alignment : talignment;
  45. {************************************************}
  46. { basic routines }
  47. constructor create;
  48. {# Emit a label to the instruction stream. }
  49. procedure a_label(list : taasmoutput;l : tasmlabel);virtual;
  50. {# Allocates register r by inserting a pai_realloc record }
  51. procedure a_reg_alloc(list : taasmoutput;r : tregister);
  52. {# Deallocates register r by inserting a pa_regdealloc record}
  53. procedure a_reg_dealloc(list : taasmoutput;r : tregister);
  54. {# @abstract(Returns a register for use as scratch register)
  55. This routine returns a register which can be used by
  56. the code generator as a scratch register. Since
  57. scratch_registers are scarce resources, the register
  58. should be freed by calling @link(get_scratch_reg) as
  59. soon as it is no longer required.
  60. }
  61. function get_scratch_reg(list : taasmoutput) : tregister;
  62. {# @abstract(Releases a scratch register)
  63. Releases a scratch register.
  64. This routine is used to free a register which
  65. was previously allocated using @link(get_scratch_reg).
  66. }
  67. procedure free_scratch_reg(list : taasmoutput;r : tregister);
  68. {************************************************}
  69. { code generation for subroutine entry/exit code }
  70. { helper routines }
  71. procedure g_initialize_data(list : taasmoutput;p : tsym);
  72. procedure g_incr_data(list : taasmoutput;p : tsym);
  73. procedure g_finalize_data(list : taasmoutput;p : tnamedindexitem);
  74. procedure g_copyvalueparas(list : taasmoutput;p : tnamedindexitem);
  75. procedure g_entrycode(alist : TAAsmoutput;make_global:boolean;
  76. stackframe:longint;
  77. var parasize:longint;var nostackframe:boolean;
  78. inlined : boolean);
  79. procedure g_exitcode(list : taasmoutput;parasize : longint;
  80. nostackframe,inlined : boolean);
  81. { passing parameters, per default the parameter is pushed }
  82. { nr gives the number of the parameter (enumerated from }
  83. { left to right), this allows to move the parameter to }
  84. { register, if the cpu supports register calling }
  85. { conventions }
  86. {# Pass a parameter, which is located in a register, to a routine.
  87. This routine should push/send the parameter to the routine, as
  88. required by the specific processor ABI. This must be overriden for
  89. each CPU target.
  90. @param(size size of the operand in the register)
  91. @param(r register source of the operand)
  92. @param(nr parameter number (starting from one) of routine (from left to right))
  93. }
  94. procedure a_param_reg(list : taasmoutput;size : tcgsize;r : tregister;nr : longint);virtual; abstract;
  95. {# Pass a parameter, which is a constant, to a routine.
  96. A generic version is provided.
  97. @param(size size of the operand in constant)
  98. @param(a value of constant to send)
  99. @param(nr parameter number (starting from one) of routine (from left to right))
  100. }
  101. procedure a_param_const(list : taasmoutput;size : tcgsize;a : aword;nr : longint);virtual;
  102. {# Pass the value of a parameter, which is located in memory, to a routine.
  103. A generic version is provided.
  104. @param(size size of the operand in constant)
  105. @param(r Memory reference of value to send)
  106. @param(nr parameter number (starting from one) of routine (from left to right))
  107. }
  108. procedure a_param_ref(list : taasmoutput;size : tcgsize;const r : treference;nr : longint);virtual;
  109. {# Pass the value of a parameter, which can be located either in a register or memory location,
  110. to a routine.
  111. A generic version is provided.
  112. @param(l location of the operand to send)
  113. @param(nr parameter number (starting from one) of routine (from left to right))
  114. }
  115. procedure a_param_loc(list : taasmoutput;const l : tlocation;nr : longint);
  116. {# Pass the address of a reference to a routine.
  117. A generic version is provided.
  118. @param(r reference to get address from)
  119. @param(nr parameter number (starting from one) of routine (from left to right))
  120. }
  121. procedure a_paramaddr_ref(list : taasmoutput;const r : treference;nr : longint);virtual;
  122. {**********************************}
  123. { these methods must be overriden: }
  124. { Remarks:
  125. * If a method specifies a size you have only to take care
  126. of that number of bits, i.e. load_const_reg with OP_8 must
  127. only load the lower 8 bit of the specified register
  128. the rest of the register can be undefined
  129. if necessary the compiler will call a method
  130. to zero or sign extend the register
  131. * The a_load_XX_XX with OP_64 needn't to be
  132. implemented for 32 bit
  133. processors, the code generator takes care of that
  134. * the addr size is for work with the natural pointer
  135. size
  136. * the procedures without fpu/mm are only for integer usage
  137. * normally the first location is the source and the
  138. second the destination
  139. }
  140. {# Emits instruction to call the method specified by symbol name @var(s) with offset
  141. to symbol in @var(offset). This routine must be overriden for each new target cpu.
  142. }
  143. procedure a_call_name(list : taasmoutput;const s : string;
  144. offset : longint);virtual; abstract;
  145. { move instructions }
  146. procedure a_load_const_reg(list : taasmoutput;size : tcgsize;a : aword;register : tregister);virtual; abstract;
  147. procedure a_load_const_ref(list : taasmoutput;size : tcgsize;a : aword;const ref : treference);virtual;
  148. procedure a_load_const_loc(list : taasmoutput;a : aword;const loc : tlocation);
  149. procedure a_load_reg_ref(list : taasmoutput;size : tcgsize;register : tregister;const ref : treference);virtual; abstract;
  150. procedure a_load_reg_reg(list : taasmoutput;size : tcgsize;reg1,reg2 : tregister);virtual; abstract;
  151. procedure a_load_reg_loc(list : taasmoutput;size : tcgsize;reg : tregister;const loc: tlocation);
  152. procedure a_load_ref_reg(list : taasmoutput;size : tcgsize;const ref : treference;register : tregister);virtual; abstract;
  153. procedure a_load_ref_ref(list : taasmoutput;size : tcgsize;const sref : treference;const dref : treference);virtual;
  154. procedure a_load_loc_reg(list : taasmoutput;const loc: tlocation; reg : tregister);
  155. procedure a_load_loc_ref(list : taasmoutput;const loc: tlocation; const ref : treference);
  156. procedure a_load_sym_ofs_reg(list: taasmoutput; const sym: tasmsymbol; ofs: longint; reg: tregister);virtual; abstract;
  157. { fpu move instructions }
  158. procedure a_loadfpu_reg_reg(list: taasmoutput; reg1, reg2: tregister); virtual; abstract;
  159. procedure a_loadfpu_ref_reg(list: taasmoutput; size: tcgsize; const ref: treference; reg: tregister); virtual; abstract;
  160. procedure a_loadfpu_reg_ref(list: taasmoutput; size: tcgsize; reg: tregister; const ref: treference); virtual; abstract;
  161. procedure a_loadfpu_loc_reg(list: taasmoutput; const loc: tlocation; const reg: tregister);
  162. procedure a_loadfpu_reg_loc(list: taasmoutput; size: tcgsize; const reg: tregister; const loc: tlocation);
  163. { vector register move instructions }
  164. procedure a_loadmm_reg_reg(list: taasmoutput; reg1, reg2: tregister); virtual; abstract;
  165. procedure a_loadmm_ref_reg(list: taasmoutput; const ref: treference; reg: tregister); virtual; abstract;
  166. procedure a_loadmm_reg_ref(list: taasmoutput; reg: tregister; const ref: treference); virtual; abstract;
  167. procedure a_parammm_reg(list: taasmoutput; reg: tregister); virtual; abstract;
  168. { basic arithmetic operations }
  169. { note: for operators which require only one argument (not, neg), use }
  170. { the op_reg_reg, op_reg_ref or op_reg_loc methods and keep in mind }
  171. { that in this case the *second* operand is used as both source and }
  172. { destination (JM) }
  173. procedure a_op_const_reg(list : taasmoutput; Op: TOpCG; a: AWord; reg: TRegister); virtual; abstract;
  174. procedure a_op_const_ref(list : taasmoutput; Op: TOpCG; size: TCGSize; a: AWord; const ref: TReference); virtual;
  175. procedure a_op_const_loc(list : taasmoutput; Op: TOpCG; a: AWord; const loc: tlocation);
  176. procedure a_op_reg_reg(list : taasmoutput; Op: TOpCG; size: TCGSize; reg1, reg2: TRegister); virtual; abstract;
  177. procedure a_op_reg_ref(list : taasmoutput; Op: TOpCG; size: TCGSize; reg: TRegister; const ref: TReference); virtual;
  178. procedure a_op_ref_reg(list : taasmoutput; Op: TOpCG; size: TCGSize; const ref: TReference; reg: TRegister); virtual;
  179. procedure a_op_reg_loc(list : taasmoutput; Op: TOpCG; reg: tregister; const loc: tlocation);
  180. procedure a_op_ref_loc(list : taasmoutput; Op: TOpCG; const ref: TReference; const loc: tlocation);
  181. { trinary operations for processors that support them, 'emulated' }
  182. { on others. None with "ref" arguments since I don't think there }
  183. { are any processors that support it (JM) }
  184. procedure a_op_const_reg_reg(list: taasmoutput; op: TOpCg;
  185. size: tcgsize; a: aword; src, dst: tregister); virtual;
  186. procedure a_op_reg_reg_reg(list: taasmoutput; op: TOpCg;
  187. size: tcgsize; src1, src2, dst: tregister); virtual;
  188. { comparison operations }
  189. procedure a_cmp_const_reg_label(list : taasmoutput;size : tcgsize;cmp_op : topcmp;a : aword;reg : tregister;
  190. l : tasmlabel);virtual; abstract;
  191. procedure a_cmp_const_ref_label(list : taasmoutput;size : tcgsize;cmp_op : topcmp;a : aword;const ref : treference;
  192. l : tasmlabel); virtual;
  193. procedure a_cmp_const_loc_label(list: taasmoutput; size: tcgsize;cmp_op: topcmp; a: aword; const loc: tlocation;
  194. l : tasmlabel);
  195. procedure a_cmp_reg_reg_label(list : taasmoutput;size : tcgsize;cmp_op : topcmp;reg1,reg2 : tregister;l : tasmlabel); virtual; abstract;
  196. procedure a_cmp_ref_reg_label(list : taasmoutput;size : tcgsize;cmp_op : topcmp; const ref: treference; reg : tregister; l : tasmlabel); virtual;
  197. procedure a_cmp_loc_reg_label(list : taasmoutput;size : tcgsize;cmp_op : topcmp; const loc: tlocation; reg : tregister; l : tasmlabel);
  198. procedure a_cmp_ref_loc_label(list: taasmoutput; size: tcgsize;cmp_op: topcmp; const ref: treference; const loc: tlocation;
  199. l : tasmlabel);
  200. procedure a_jmp_always(list : taasmoutput;l: tasmlabel); virtual; abstract;
  201. procedure a_jmp_flags(list : taasmoutput;const f : TResFlags;l: tasmlabel); virtual; abstract;
  202. procedure g_flags2reg(list: taasmoutput; const f: tresflags; reg: TRegister); virtual; abstract;
  203. procedure a_loadaddr_ref_reg(list : taasmoutput;const ref : treference;r : tregister);virtual; abstract;
  204. procedure g_stackframe_entry(list : taasmoutput;localsize : longint);virtual; abstract;
  205. { restores the frame pointer at procedure exit, for the }
  206. { i386 it generates a simple leave }
  207. procedure g_restore_frame_pointer(list : taasmoutput);virtual; abstract;
  208. { some processors like the PPC doesn't allow to change the stack in }
  209. { a procedure, so we need to maintain an extra stack for the }
  210. { result values of setjmp in exception code }
  211. { this two procedures are for pushing an exception value, }
  212. { they can use the scratch registers }
  213. procedure g_push_exception_value_reg(list : taasmoutput;reg : tregister);virtual; abstract;
  214. procedure g_push_exception_value_const(list : taasmoutput;reg : tregister);virtual; abstract;
  215. { that procedure pops a exception value }
  216. procedure g_pop_exception_value_reg(list : taasmoutput;reg : tregister);virtual; abstract;
  217. procedure g_return_from_proc(list : taasmoutput;parasize : aword);virtual; abstract;
  218. {********************************************************}
  219. { these methods can be overriden for extra functionality }
  220. {# Emits instructions which should be emitted when entering
  221. a routine declared as @var(interrupt). The default
  222. behavior does nothing, should be overriden as required.
  223. }
  224. procedure g_interrupt_stackframe_entry(list : taasmoutput);virtual;
  225. {# Emits instructions which should be emitted when exiting
  226. a routine declared as @var(interrupt). The default
  227. behavior does nothing, should be overriden as required.
  228. }
  229. procedure g_interrupt_stackframe_exit(list : taasmoutput);virtual;
  230. {# Emits instructions when compilation is done in profile
  231. mode (this is set as a command line option). The default
  232. behavior does nothing, should be overriden as required.
  233. }
  234. procedure g_profilecode(list : taasmoutput);virtual;
  235. procedure g_maybe_loadself(list : taasmoutput);virtual; abstract;
  236. {# This should emit the opcode to copy len bytes from the source
  237. to destination, if loadref is true, it assumes that it first must load
  238. the source address from the memory location where
  239. source points to.
  240. It must be overriden for each new target processor.
  241. @param(source Source reference of copy)
  242. @param(dest Destination reference of copy)
  243. @param(delsource Indicates if the source reference's resources should be freed)
  244. @param(loadref Is the source reference a pointer to the actual source (TRUE), is it the actual source address (FALSE))
  245. }
  246. procedure g_concatcopy(list : taasmoutput;const source,dest : treference;len : aword;delsource,loadref : boolean);virtual; abstract;
  247. {# This should emit the opcode to a shortrstring from the source
  248. to destination, if loadref is true, it assumes that it first must load
  249. the source address from the memory location where
  250. source points to.
  251. @param(source Source reference of copy)
  252. @param(dest Destination reference of copy)
  253. @param(delsource Indicates if the source reference's resources should be freed)
  254. @param(loadref Is the source reference a pointer to the actual source (TRUE), is it the actual source address (FALSE))
  255. }
  256. procedure g_copyshortstring(list : taasmoutput;const source,dest : treference;len:byte;delsource,loadref : boolean);
  257. procedure g_incrrefcount(list : taasmoutput;t: tdef; const ref: treference);
  258. procedure g_decrrefcount(list : taasmoutput;t: tdef; const ref: treference);
  259. procedure g_initialize(list : taasmoutput;t : tdef;const ref : treference;loadref : boolean);
  260. procedure g_finalize(list : taasmoutput;t : tdef;const ref : treference;loadref : boolean);
  261. {# Emits the call to the stack checking routine of
  262. the runtime library. The default behavior
  263. does not need to be modified, as it is generic
  264. for all platforms.
  265. }
  266. procedure g_stackcheck(list : taasmoutput;stackframesize : longint);virtual;
  267. {# Generates range checking code. It is to note
  268. that this routine does not need to be overriden,
  269. as it takes care of everything.
  270. @param(p Node which contains the value to check)
  271. @param(todef Type definition of node to range check)
  272. }
  273. procedure g_rangecheck(list: taasmoutput; const p: tnode;
  274. const todef: tdef); virtual;
  275. { generates overflow checking code for a node }
  276. procedure g_overflowcheck(list: taasmoutput; const p: tnode); virtual; abstract;
  277. { returns the tcgsize corresponding with the size of reg }
  278. class function reg_cgsize(const reg: tregister) : tcgsize; virtual;
  279. end;
  280. var
  281. cg : tcg; { this is the main code generator class }
  282. implementation
  283. uses
  284. globals,globtype,options,systems,cgbase,
  285. verbose,types,tgobj,symdef,cga,tainst,rgobj;
  286. const
  287. max_scratch_regs = high(scratch_regs) - low(scratch_regs) + 1;
  288. {*****************************************************************************
  289. basic functionallity
  290. ******************************************************************************}
  291. constructor tcg.create;
  292. var
  293. i : longint;
  294. begin
  295. scratch_register_array_pointer:=1;
  296. for i:=low(scratch_regs) to high(scratch_regs) do
  297. include(unusedscratchregisters,scratch_regs[i]);
  298. end;
  299. procedure tcg.a_reg_alloc(list : taasmoutput;r : tregister);
  300. begin
  301. list.concat(tairegalloc.alloc(r));
  302. end;
  303. procedure tcg.a_reg_dealloc(list : taasmoutput;r : tregister);
  304. begin
  305. list.concat(tairegalloc.dealloc(r));
  306. end;
  307. procedure tcg.a_label(list : taasmoutput;l : tasmlabel);
  308. begin
  309. list.concat(tai_label.create(l));
  310. end;
  311. function tcg.get_scratch_reg(list : taasmoutput) : tregister;
  312. var
  313. r : tregister;
  314. i : longint;
  315. begin
  316. if unusedscratchregisters=[] then
  317. internalerror(68996);
  318. for i:=scratch_register_array_pointer to
  319. (scratch_register_array_pointer+max_scratch_regs-1) do
  320. if scratch_regs[(i mod max_scratch_regs)+1] in unusedscratchregisters then
  321. begin
  322. r:=scratch_regs[(i mod max_scratch_regs)+1];
  323. break;
  324. end;
  325. exclude(unusedscratchregisters,r);
  326. inc(scratch_register_array_pointer);
  327. if scratch_register_array_pointer>max_scratch_regs then
  328. scratch_register_array_pointer:=1;
  329. a_reg_alloc(list,r);
  330. get_scratch_reg:=r;
  331. end;
  332. procedure tcg.free_scratch_reg(list : taasmoutput;r : tregister);
  333. begin
  334. include(unusedscratchregisters,rg.makeregsize(r,OS_INT));
  335. a_reg_dealloc(list,r);
  336. end;
  337. {*****************************************************************************
  338. this methods must be overridden for extra functionality
  339. ******************************************************************************}
  340. procedure tcg.g_interrupt_stackframe_entry(list : taasmoutput);
  341. begin
  342. end;
  343. procedure tcg.g_interrupt_stackframe_exit(list : taasmoutput);
  344. begin
  345. end;
  346. procedure tcg.g_profilecode(list : taasmoutput);
  347. begin
  348. end;
  349. {*****************************************************************************
  350. for better code generation these methods should be overridden
  351. ******************************************************************************}
  352. procedure tcg.a_param_const(list : taasmoutput;size : tcgsize;a : aword;nr : longint);
  353. var
  354. hr : tregister;
  355. begin
  356. hr:=get_scratch_reg(list);
  357. a_load_const_reg(list,size,a,hr);
  358. a_param_reg(list,size,hr,nr);
  359. free_scratch_reg(list,hr);
  360. end;
  361. procedure tcg.a_param_ref(list : taasmoutput;size : tcgsize;const r : treference;nr : longint);
  362. var
  363. hr : tregister;
  364. begin
  365. hr:=get_scratch_reg(list);
  366. a_load_ref_reg(list,size,r,hr);
  367. a_param_reg(list,size,hr,nr);
  368. free_scratch_reg(list,hr);
  369. end;
  370. procedure tcg.a_param_loc(list : taasmoutput;const l:tlocation;nr : longint);
  371. begin
  372. case l.loc of
  373. LOC_REGISTER,
  374. LOC_CREGISTER :
  375. a_param_reg(list,l.size,l.register,nr);
  376. LOC_CONSTANT :
  377. a_param_const(list,l.size,l.value,nr);
  378. LOC_CREFERENCE,
  379. LOC_REFERENCE :
  380. a_param_ref(list,l.size,l.reference,nr);
  381. else
  382. internalerror(2002032211);
  383. end;
  384. end;
  385. procedure tcg.a_paramaddr_ref(list : taasmoutput;const r : treference;nr : longint);
  386. var
  387. hr : tregister;
  388. begin
  389. hr:=get_scratch_reg(list);
  390. a_loadaddr_ref_reg(list,r,hr);
  391. a_param_reg(list,OS_ADDR,hr,nr);
  392. free_scratch_reg(list,hr);
  393. end;
  394. {*****************************************************************************
  395. Code generation for subroutine entry- and exit code
  396. *****************************************************************************}
  397. { generates the code for initialisation of local data }
  398. procedure tcg.g_initialize_data(list : taasmoutput;p : tsym);
  399. { var
  400. hr : treference; }
  401. begin
  402. (*
  403. if (tsym(p)^.typ=varsym) and
  404. assigned(pvarsym(p)^.vartype.def) and
  405. not((pvarsym(p)^.vartype.def^.deftype=objectdef) and
  406. pobjectdef(pvarsym(p)^.vartype.def)^.is_class) and
  407. pvarsym(p)^.vartype.def^.needs_inittable then
  408. begin
  409. procinfo^.flags:=procinfo^.flags or pi_needs_implicit_finally;
  410. reset_reference(hr);
  411. if tsym(p)^.owner^.symtabletype=localsymtable then
  412. begin
  413. hr.base:=procinfo^.framepointer;
  414. hr.offset:=-pvarsym(p)^.address;
  415. end
  416. else
  417. begin
  418. hr.symbol:=newasmsymbol(pvarsym(p)^.mangledname);
  419. end;
  420. g_initialize(list,pvarsym(p)^.vartype.def,hr,false);
  421. end;
  422. *)
  423. runerror(211);
  424. end;
  425. { generates the code for incrementing the reference count of parameters }
  426. procedure tcg.g_incr_data(list : taasmoutput;p : tsym);
  427. { var
  428. hr : treference; }
  429. begin
  430. (*
  431. if (tsym(p)^.typ=varsym) and
  432. not((pvarsym(p)^.vartype.def^.deftype=objectdef) and
  433. pobjectdef(pvarsym(p)^.vartype.def)^.is_class) and
  434. pvarsym(p)^.vartype.def^.needs_inittable and
  435. ((pvarsym(p)^.varspez=vs_value)) then
  436. begin
  437. procinfo^.flags:=procinfo^.flags or pi_needs_implicit_finally;
  438. reset_reference(hr);
  439. hr.symbol:=pvarsym(p)^.vartype.def^.get_inittable_label;
  440. a_param_ref_addr(list,hr,2);
  441. reset_reference(hr);
  442. hr.base:=procinfo^.framepointer;
  443. hr.offset:=pvarsym(p)^.address+procinfo^.para_offset;
  444. a_param_ref_addr(list,hr,1);
  445. reset_reference(hr);
  446. a_call_name(list,'FPC_ADDREF',0);
  447. end;
  448. *)
  449. runerror(211);
  450. end;
  451. { generates the code for finalisation of local data }
  452. procedure tcg.g_finalize_data(list : taasmoutput;p : tnamedindexitem);
  453. { var
  454. hr : treference; }
  455. begin
  456. (*
  457. if (tsym(p)^.typ=varsym) and
  458. assigned(pvarsym(p)^.vartype.def) and
  459. not((pvarsym(p)^.vartype.def^.deftype=objectdef) and
  460. pobjectdef(pvarsym(p)^.vartype.def)^.is_class) and
  461. pvarsym(p)^.vartype.def^.needs_inittable then
  462. begin
  463. { not all kind of parameters need to be finalized }
  464. if (tsym(p)^.owner^.symtabletype=parasymtable) and
  465. ((pvarsym(p)^.varspez=vs_var) or
  466. (pvarsym(p)^.varspez=vs_const) { and
  467. (dont_copy_const_param(pvarsym(p)^.definition)) } ) then
  468. exit;
  469. procinfo^.flags:=procinfo^.flags or pi_needs_implicit_finally;
  470. reset_reference(hr);
  471. case tsym(p)^.owner^.symtabletype of
  472. localsymtable:
  473. begin
  474. hr.base:=procinfo^.framepointer;
  475. hr.offset:=-pvarsym(p)^.address;
  476. end;
  477. parasymtable:
  478. begin
  479. hr.base:=procinfo^.framepointer;
  480. hr.offset:=pvarsym(p)^.address+procinfo^.para_offset;
  481. end;
  482. else
  483. hr.symbol:=newasmsymbol(pvarsym(p)^.mangledname);
  484. end;
  485. g_finalize(list,pvarsym(p)^.vartype.def,hr,false);
  486. end;
  487. *)
  488. runerror(211);
  489. end;
  490. { generates the code to make local copies of the value parameters }
  491. procedure tcg.g_copyvalueparas(list : taasmoutput;p : tnamedindexitem);
  492. begin
  493. runerror(255);
  494. end;
  495. (*
  496. var
  497. _list : taasmoutput;
  498. { wrappers for the methods, because TP doesn't know procedures }
  499. { of objects }
  500. procedure _copyvalueparas(s : tnamedindexitem);{$ifndef FPC}far;{$endif}
  501. begin
  502. cg^.g_copyvalueparas(_list,s);
  503. end;
  504. procedure _finalize_data(s : tnamedindexitem);{$ifndef FPC}far;{$endif}
  505. begin
  506. cg^.g_finalize_data(_list,s);
  507. end;
  508. procedure _incr_data(s : tnamedindexitem);{$ifndef FPC}far;{$endif}
  509. begin
  510. cg^.g_incr_data(_list,tsym(s));
  511. end;
  512. procedure _initialize_data(s : tnamedindexitem);{$ifndef FPC}far;{$endif}
  513. begin
  514. cg^.g_initialize_data(_list,tsym(s));
  515. end;
  516. *)
  517. { generates the entry code for a procedure }
  518. procedure tcg.g_entrycode(alist : TAAsmoutput;make_global:boolean;
  519. stackframe:longint;
  520. var parasize:longint;var nostackframe:boolean;
  521. inlined : boolean);
  522. (*
  523. var
  524. hs : string;
  525. hp : pused_unit;
  526. initcode : taasmoutput;
  527. {$ifdef GDB}
  528. stab_function_name : Pai_stab_function_name;
  529. {$endif GDB}
  530. hr : treference;
  531. r : tregister;
  532. *)
  533. begin
  534. (*
  535. { Align }
  536. if (not inlined) then
  537. begin
  538. { gprof uses 16 byte granularity !! }
  539. if (cs_profile in aktmoduleswitches) then
  540. list^.insert(new(pai_align,init(16)))
  541. else
  542. if not(cs_littlesize in aktglobalswitches) then
  543. list^.insert(new(pai_align,init(4)));
  544. end;
  545. { save registers on cdecl }
  546. if (po_savestdregs in aktprocsym^.definition^.procoptions) then
  547. begin
  548. for r:=firstreg to lastreg do
  549. begin
  550. if (r in registers_saved_on_cdecl) then
  551. if (r in (tg.availabletempregsint+
  552. tg.availabletempregsfpu+
  553. tg.availabletempregsmm)) then
  554. begin
  555. if not(r in tg.usedinproc) then
  556. {!!!!!!!!!!!! a_push_reg(list,r) }
  557. end
  558. else
  559. {!!!!!!!! a_push_reg(list,r) };
  560. end;
  561. end;
  562. { omit stack frame ? }
  563. if not inlined then
  564. if procinfo^.framepointer=STACK_POINTER_REG then
  565. begin
  566. CGMessage(cg_d_stackframe_omited);
  567. nostackframe:=true;
  568. if (aktprocsym^.definition^.proctypeoption in [potype_unitinit,potype_proginit,potype_unitfinalize]) then
  569. parasize:=0
  570. else
  571. parasize:=aktprocsym^.definition^.parast^.datasize+procinfo^.para_offset-pointersize;
  572. end
  573. else
  574. begin
  575. if (aktprocsym^.definition^.proctypeoption in [potype_unitinit,potype_proginit,potype_unitfinalize]) then
  576. parasize:=0
  577. else
  578. parasize:=aktprocsym^.definition^.parast^.datasize+procinfo^.para_offset-pointersize*2;
  579. nostackframe:=false;
  580. if (po_interrupt in aktprocsym^.definition^.procoptions) then
  581. g_interrupt_stackframe_entry(list);
  582. g_stackframe_entry(list,stackframe);
  583. if (cs_check_stack in aktlocalswitches) and
  584. (tf_supports_stack_checking in target_info.flags) then
  585. g_stackcheck(@initcode,stackframe);
  586. end;
  587. if cs_profile in aktmoduleswitches then
  588. g_profilecode(@initcode);
  589. if (not inlined) and (aktprocsym^.definition^.proctypeoption in [potype_unitinit]) then
  590. begin
  591. { needs the target a console flags ? }
  592. if tf_needs_isconsole in target_info.flags then
  593. begin
  594. hr.symbol:=newasmsymbol('U_'+target_info.system_unit+'_ISCONSOLE');
  595. if apptype=at_cui then
  596. a_load_const_ref(list,OS_8,1,hr)
  597. else
  598. a_load_const_ref(list,OS_8,0,hr);
  599. dispose(hr.symbol,done);
  600. end;
  601. hp:=pused_unit(usedunits.first);
  602. while assigned(hp) do
  603. begin
  604. { call the unit init code and make it external }
  605. if (hp^.u^.flags and uf_init)<>0 then
  606. a_call_name(list,
  607. 'INIT$$'+hp^.u^.modulename^,0);
  608. hp:=Pused_unit(hp^.next);
  609. end;
  610. end;
  611. {$ifdef dummy}
  612. { a constructor needs a help procedure }
  613. if (aktprocsym^.definition^.options and poconstructor)<>0 then
  614. begin
  615. if procinfo^._class^.isclass then
  616. begin
  617. list^.concat(new(paicpu,op_sym(A_CALL,S_NO,newasmsymbol('FPC_NEW_CLASS'))));
  618. list^.concat(new(paicpu,op_cond_sym(A_Jcc,C_Z,S_NO,quickexitlabel)));
  619. end
  620. else
  621. begin
  622. {
  623. list^.insert(new(pai_labeled,init(A_JZ,quickexitlabel)));
  624. list^.insert(new(paicpu,op_csymbol(A_CALL,S_NO,
  625. newcsymbol('FPC_HELP_CONSTRUCTOR',0))));
  626. list^.insert(new(paicpu,op_const_reg(A_MOV,S_L,procinfo^._class^.vmt_offset,R_EDI)));
  627. concat_external('FPC_HELP_CONSTRUCTOR',EXT_NEAR);
  628. }
  629. end;
  630. end;
  631. {$endif dummy}
  632. {$ifdef GDB}
  633. if (cs_debuginfo in aktmoduleswitches) then
  634. list^.insert(new(pai_force_line,init));
  635. {$endif GDB}
  636. { initialize return value }
  637. if assigned(procinfo^.returntype.def) and
  638. is_ansistring(procinfo^.returntype.def) or
  639. is_widestring(procinfo^.returntype.def) then
  640. begin
  641. reset_reference(hr);
  642. hr.offset:=procinfo^.return_offset;
  643. hr.base:=procinfo^.framepointer;
  644. a_load_const_ref(list,OS_32,0,hr);
  645. end;
  646. _list:=list;
  647. { generate copies of call by value parameters }
  648. if (po_assembler in aktprocsym^.definition^.procoptions) then
  649. aktprocsym^.definition^.parast^.foreach({$ifdef FPCPROCVAR}@{$endif}_copyvalueparas);
  650. { initialisizes local data }
  651. aktprocsym^.definition^.localst^.foreach({$ifdef FPCPROCVAR}@{$endif}_initialize_data);
  652. { add a reference to all call by value/const parameters }
  653. aktprocsym^.definition^.parast^.foreach({$ifdef FPCPROCVAR}@{$endif}_incr_data);
  654. if (cs_profile in aktmoduleswitches) or
  655. (aktprocsym^.definition^.owner^.symtabletype=globalsymtable) or
  656. (assigned(procinfo^._class) and (procinfo^._class^.owner^.symtabletype=globalsymtable)) then
  657. make_global:=true;
  658. if not inlined then
  659. begin
  660. hs:=proc_names.get;
  661. {$ifdef GDB}
  662. if (cs_debuginfo in aktmoduleswitches) and target_os.use_function_relative_addresses then
  663. stab_function_name := new(pai_stab_function_name,init(strpnew(hs)));
  664. {$endif GDB}
  665. { insert the names for the procedure }
  666. while hs<>'' do
  667. begin
  668. if make_global then
  669. exprasmlist^.insert(new(pai_symbol,initname_global(hs,0)))
  670. else
  671. exprasmlist^.insert(new(pai_symbol,initname(hs,0)));
  672. {$ifdef GDB}
  673. if (cs_debuginfo in aktmoduleswitches) then
  674. begin
  675. if target_os.use_function_relative_addresses then
  676. list^.insert(new(pai_stab_function_name,init(strpnew(hs))));
  677. end;
  678. {$endif GDB}
  679. hs:=proc_names.get;
  680. end;
  681. end;
  682. {$ifdef GDB}
  683. if (not inlined) and (cs_debuginfo in aktmoduleswitches) then
  684. begin
  685. if target_os.use_function_relative_addresses then
  686. list^.insert(stab_function_name);
  687. if make_global or ((procinfo^.flags and pi_is_global) <> 0) then
  688. aktprocsym^.is_global := True;
  689. list^.insert(new(pai_stabs,init(aktprocsym^.stabstring)));
  690. aktprocsym^.isstabwritten:=true;
  691. end;
  692. {$endif GDB}
  693. *)
  694. runerror(211);
  695. end;
  696. procedure tcg.g_exitcode(list : taasmoutput;parasize:longint;nostackframe,inlined:boolean);
  697. (*
  698. var
  699. {$ifdef GDB}
  700. mangled_length : longint;
  701. p : pchar;
  702. {$endif GDB}
  703. nofinal,noreraiselabel : tasmlabel;
  704. hr : treference;
  705. r : tregister;
  706. *)
  707. begin
  708. (*
  709. if aktexitlabel^.is_used then
  710. list^.insert(new(pai_label,init(aktexitlabel)));
  711. { call the destructor help procedure }
  712. if (aktprocsym^.definition^.proctypeoption=potype_destructor) then
  713. begin
  714. if procinfo^._class^.is_class then
  715. a_call_name(list,'FPC_DISPOSE_CLASS',0)
  716. else
  717. begin
  718. if procinfo^._class^.needs_inittable then
  719. begin
  720. getlabel(nofinal);
  721. {!!!!!!!!!!
  722. reset_reference(hr);
  723. hr.base:=R_EBP;
  724. hr.offset:=8;
  725. a_cmp_reg_const_label(list,OS_ADDR,OZ_EQ,
  726. }
  727. reset_reference(hr);
  728. hr.symbol:=procinfo^._class^.get_inittable_label;
  729. a_paramaddr_ref(list,hr,2);
  730. a_param_reg(list,OS_ADDR,self_pointer_reg,1);
  731. a_call_name(list,'FPC_FINALIZE',0);
  732. a_label(list,nofinal);
  733. end;
  734. { vmt_offset_reg can be a scratch register, }
  735. { but it must be always the same }
  736. a_reg_alloc(list,vmt_offset_reg);
  737. a_load_const_reg(list,OS_32,procinfo^._class^.vmt_offset,vmt_offset_reg);
  738. a_call_name(list,'FPC_HELP_DESTRUCTOR',0);
  739. a_reg_dealloc(list,vmt_offset_reg);
  740. end;
  741. end;
  742. { finalize temporary data }
  743. g_finalizetempansistrings(list);
  744. _list:=list;
  745. { finalize local data }
  746. aktprocsym^.definition^.localst^.foreach({$ifdef FPCPROCVAR}@{$endif}_finalize_data);
  747. { finalize paras data }
  748. if assigned(aktprocsym^.definition^.parast) then
  749. aktprocsym^.definition^.parast^.foreach({$ifdef FPCPROCVAR}@{$endif}_finalize_data);
  750. { do we need to handle exceptions because of ansi/widestrings ? }
  751. if (procinfo^.flags and pi_needs_implicit_finally)<>0 then
  752. begin
  753. getlabel(noreraiselabel);
  754. a_call_name(list,'FPC_POPADDRSTACK',0);
  755. a_reg_alloc(list,accumulator);
  756. g_pop_exception_value_reg(list,accumulator);
  757. a_cmp_const_reg_label(list,OS_32,OC_EQ,0,accumulator,noreraiselabel);
  758. a_reg_dealloc(list,accumulator);
  759. { must be the return value finalized before reraising the exception? }
  760. if (procinfo^.returntype.def<>tdef(voiddef)) and
  761. (procinfo^.returntype.def^.needs_inittable) and
  762. ((procinfo^.returntype.def^.deftype<>objectdef) or
  763. not(pobjectdef(procinfo^.returntype.def)^.is_class)) then
  764. begin
  765. reset_reference(hr);
  766. hr.offset:=procinfo^.return_offset;
  767. hr.base:=procinfo^.framepointer;
  768. g_finalize(list,procinfo^.returntype.def,hr,ret_in_param(procinfo^.returntype.def));
  769. end;
  770. a_call_name(list,'FPC_RERAISE',0);
  771. a_label(list,noreraiselabel);
  772. end;
  773. { call __EXIT for main program }
  774. if (not DLLsource) and (not inlined) and (aktprocsym^.definition^.proctypeoption=potype_proginit) then
  775. a_call_name(list,'FPC_DO_EXIT',0);
  776. { handle return value }
  777. if not(po_assembler in aktprocsym^.definition^.procoptions) then
  778. if (aktprocsym^.definition^.proctypeoption<>potype_constructor) then
  779. { handle_return_value(inlined) }
  780. else
  781. begin
  782. { return self in EAX }
  783. a_label(list,quickexitlabel);
  784. a_reg_alloc(list,accumulator);
  785. a_load_reg_reg(list,OS_ADDR,self_pointer_reg,accumulator);
  786. a_reg_dealloc(list,self_pointer_reg);
  787. a_label(list,quickexitlabel);
  788. { we can't clear the zero flag because the Alpha }
  789. { for example doesn't have flags, we have to compare }
  790. { the accu. in the caller }
  791. end;
  792. { stabs uses the label also ! }
  793. if aktexit2label^.is_used or
  794. ((cs_debuginfo in aktmoduleswitches) and not inlined) then
  795. a_label(list,aktexit2label);
  796. {$ifdef dummy}
  797. { should we restore edi ? }
  798. { for all i386 gcc implementations }
  799. {!!!!!!!!!!! I don't know how to handle register saving yet }
  800. if (po_savestdregs in aktprocsym^.definition^.procoptions) then
  801. begin
  802. if (aktprocsym^.definition^.usedregisters and ($80 shr byte(R_EBX)))<>0 then
  803. exprasmlist^.concat(new(paicpu,op_reg(A_POP,S_L,R_EBX)));
  804. exprasmlist^.concat(new(paicpu,op_reg(A_POP,S_L,R_ESI)));
  805. exprasmlist^.concat(new(paicpu,op_reg(A_POP,S_L,R_EDI)));
  806. { here we could reset R_EBX
  807. but that is risky because it only works
  808. if genexitcode is called after genentrycode
  809. so lets skip this for the moment PM
  810. aktprocsym^.definition^.usedregisters:=
  811. aktprocsym^.definition^.usedregisters or not ($80 shr byte(R_EBX));
  812. }
  813. end;
  814. {$endif dummy}
  815. if not(nostackframe) and not inlined then
  816. g_restore_frame_pointer(list);
  817. { at last, the return is generated }
  818. if not inlined then
  819. if po_interrupt in aktprocsym^.definition^.procoptions then
  820. g_interrupt_stackframe_exit(list)
  821. else
  822. g_return_from_proc(list,parasize);
  823. list^.concat(new(pai_symbol_end,initname(aktprocsym^.definition^.mangledname)));
  824. {$ifdef GDB}
  825. if (cs_debuginfo in aktmoduleswitches) and not inlined then
  826. begin
  827. aktprocsym^.concatstabto(list);
  828. if assigned(procinfo^._class) then
  829. if (not assigned(procinfo^.parent) or
  830. not assigned(procinfo^.parent^._class)) then
  831. list^.concat(new(pai_stabs,init(strpnew(
  832. '"$t:v'+procinfo^._class^.numberstring+'",'+
  833. tostr(N_PSYM)+',0,0,'+tostr(procinfo^.selfpointer_offset)))));
  834. {!!!!!!!!!!!!
  835. else
  836. list^.concat(new(pai_stabs,init(strpnew(
  837. '"$t:r'+procinfo^._class^.numberstring+'",'+
  838. tostr(N_RSYM)+',0,0,'+tostr(GDB_i386index[R_ESI])))));
  839. }
  840. if (tdef(aktprocsym^.definition^.rettype.def) <> tdef(voiddef)) then
  841. begin
  842. if ret_in_param(aktprocsym^.definition^.rettype.def) then
  843. list^.concat(new(pai_stabs,init(strpnew(
  844. '"'+aktprocsym^.name+':X*'+aktprocsym^.definition^.rettype.def^.numberstring+'",'+
  845. tostr(N_PSYM)+',0,0,'+tostr(procinfo^.return_offset)))))
  846. else
  847. list^.concat(new(pai_stabs,init(strpnew(
  848. '"'+aktprocsym^.name+':X'+aktprocsym^.definition^.rettype.def^.numberstring+'",'+
  849. tostr(N_PSYM)+',0,0,'+tostr(procinfo^.return_offset)))));
  850. if (m_result in aktmodeswitches) then
  851. if ret_in_param(aktprocsym^.definition^.rettype.def) then
  852. list^.concat(new(pai_stabs,init(strpnew(
  853. '"RESULT:X*'+aktprocsym^.definition^.rettype.def^.numberstring+'",'+
  854. tostr(N_PSYM)+',0,0,'+tostr(procinfo^.return_offset)))))
  855. else
  856. list^.concat(new(pai_stabs,init(strpnew(
  857. '"RESULT:X'+aktprocsym^.definition^.rettype.def^.numberstring+'",'+
  858. tostr(N_PSYM)+',0,0,'+tostr(procinfo^.return_offset)))));
  859. end;
  860. mangled_length:=length(aktprocsym^.definition^.mangledname);
  861. getmem(p,mangled_length+50);
  862. strpcopy(p,'192,0,0,');
  863. strpcopy(strend(p),aktprocsym^.definition^.mangledname);
  864. list^.concat(new(pai_stabn,init(strnew(p))));
  865. {list^.concat(new(pai_stabn,init(strpnew('192,0,0,'
  866. +aktprocsym^.definition^.mangledname))));
  867. p[0]:='2';p[1]:='2';p[2]:='4';
  868. strpcopy(strend(p),'_end');}
  869. freemem(p,mangled_length+50);
  870. list^.concat(new(pai_stabn,init(
  871. strpnew('224,0,0,'+aktexit2label^.name))));
  872. { strpnew('224,0,0,'
  873. +aktprocsym^.definition^.mangledname+'_end'))));}
  874. end;
  875. {$endif GDB}
  876. *)
  877. runerror(211);
  878. end;
  879. {*****************************************************************************
  880. some generic implementations
  881. ****************************************************************************}
  882. procedure tcg.a_load_ref_ref(list : taasmoutput;size : tcgsize;const sref : treference;const dref : treference);
  883. var
  884. tmpreg: tregister;
  885. begin
  886. {$ifdef i386}
  887. { the following is done with defines to avoid a speed penalty, }
  888. { since all this is only necessary for the 80x86 (because EDI }
  889. { doesn't have an 8bit component which is directly addressable) }
  890. if size in [OS_8,OS_S8] then
  891. tmpreg := rg.getregisterint(exprasmlist)
  892. else
  893. {$endif i386}
  894. tmpreg := get_scratch_reg(list);
  895. tmpreg:=rg.makeregsize(tmpreg,size);
  896. a_load_ref_reg(list,size,sref,tmpreg);
  897. a_load_reg_ref(list,size,tmpreg,dref);
  898. {$ifdef i386}
  899. if size in [OS_8,OS_S8] then
  900. rg.ungetregister(exprasmlist,tmpreg)
  901. else
  902. {$endif i386}
  903. free_scratch_reg(list,tmpreg);
  904. end;
  905. procedure tcg.a_load_const_ref(list : taasmoutput;size : tcgsize;a : aword;const ref : treference);
  906. var
  907. tmpreg: tregister;
  908. begin
  909. tmpreg := get_scratch_reg(list);
  910. a_load_const_reg(list,size,a,tmpreg);
  911. a_load_reg_ref(list,size,tmpreg,ref);
  912. free_scratch_reg(list,tmpreg);
  913. end;
  914. procedure tcg.a_load_const_loc(list : taasmoutput;a : aword;const loc: tlocation);
  915. begin
  916. case loc.loc of
  917. LOC_REFERENCE,LOC_CREFERENCE:
  918. a_load_const_ref(list,loc.size,a,loc.reference);
  919. LOC_REGISTER,LOC_CREGISTER:
  920. a_load_const_reg(list,loc.size,a,loc.register);
  921. else
  922. internalerror(200203272);
  923. end;
  924. end;
  925. procedure tcg.a_load_reg_loc(list : taasmoutput;size : tcgsize;reg : tregister;const loc: tlocation);
  926. begin
  927. case loc.loc of
  928. LOC_REFERENCE,LOC_CREFERENCE:
  929. a_load_reg_ref(list,size,reg,loc.reference);
  930. LOC_REGISTER,LOC_CREGISTER:
  931. a_load_reg_reg(list,size,reg,loc.register);
  932. else
  933. internalerror(200203271);
  934. end;
  935. end;
  936. procedure tcg.a_load_loc_reg(list : taasmoutput;const loc: tlocation; reg : tregister);
  937. begin
  938. case loc.loc of
  939. LOC_REFERENCE,LOC_CREFERENCE:
  940. a_load_ref_reg(list,loc.size,loc.reference,reg);
  941. LOC_REGISTER,LOC_CREGISTER:
  942. a_load_reg_reg(list,loc.size,loc.register,reg);
  943. LOC_CONSTANT:
  944. a_load_const_reg(list,loc.size,loc.value,reg);
  945. else
  946. internalerror(200109092);
  947. end;
  948. end;
  949. procedure tcg.a_load_loc_ref(list : taasmoutput;const loc: tlocation; const ref : treference);
  950. begin
  951. case loc.loc of
  952. LOC_REFERENCE,LOC_CREFERENCE:
  953. a_load_ref_ref(list,loc.size,loc.reference,ref);
  954. LOC_REGISTER,LOC_CREGISTER:
  955. a_load_reg_ref(list,loc.size,loc.register,ref);
  956. LOC_CONSTANT:
  957. a_load_const_ref(list,loc.size,loc.value,ref);
  958. else
  959. internalerror(200109302);
  960. end;
  961. end;
  962. procedure tcg.a_loadfpu_loc_reg(list: taasmoutput; const loc: tlocation; const reg: tregister);
  963. begin
  964. case loc.loc of
  965. LOC_REFERENCE, LOC_CREFERENCE:
  966. a_loadfpu_ref_reg(list,loc.size,loc.reference,reg);
  967. LOC_FPUREGISTER, LOC_CFPUREGISTER:
  968. a_loadfpu_reg_reg(list,loc.register,reg);
  969. else
  970. internalerror(200203301);
  971. end;
  972. end;
  973. procedure tcg.a_loadfpu_reg_loc(list: taasmoutput; size: tcgsize; const reg: tregister; const loc: tlocation);
  974. begin
  975. case loc.loc of
  976. LOC_REFERENCE, LOC_CREFERENCE:
  977. a_loadfpu_reg_ref(list,size,reg,loc.reference);
  978. LOC_FPUREGISTER, LOC_CFPUREGISTER:
  979. a_loadfpu_reg_reg(list,reg,loc.register);
  980. else
  981. internalerror(48991);
  982. end;
  983. end;
  984. procedure tcg.a_op_const_ref(list : taasmoutput; Op: TOpCG; size: TCGSize; a: AWord; const ref: TReference);
  985. var
  986. tmpreg: tregister;
  987. begin
  988. tmpreg := get_scratch_reg(list);
  989. a_load_ref_reg(list,size,ref,tmpreg);
  990. a_op_const_reg(list,op,a,tmpreg);
  991. a_load_reg_ref(list,size,tmpreg,ref);
  992. free_scratch_reg(list,tmpreg);
  993. end;
  994. procedure tcg.a_op_const_loc(list : taasmoutput; Op: TOpCG; a: AWord; const loc: tlocation);
  995. begin
  996. case loc.loc of
  997. LOC_REGISTER, LOC_CREGISTER:
  998. a_op_const_reg(list,op,a,loc.register);
  999. LOC_REFERENCE, LOC_CREFERENCE:
  1000. a_op_const_ref(list,op,loc.size,a,loc.reference);
  1001. else
  1002. internalerror(200109061);
  1003. end;
  1004. end;
  1005. procedure tcg.a_op_reg_ref(list : taasmoutput; Op: TOpCG; size: TCGSize;reg: TRegister; const ref: TReference);
  1006. var
  1007. tmpreg: tregister;
  1008. begin
  1009. tmpreg := get_scratch_reg(list);
  1010. a_load_ref_reg(list,size,ref,tmpreg);
  1011. a_op_reg_reg(list,op,size,reg,tmpreg);
  1012. a_load_reg_ref(list,size,tmpreg,ref);
  1013. free_scratch_reg(list,tmpreg);
  1014. end;
  1015. procedure tcg.a_op_ref_reg(list : taasmoutput; Op: TOpCG; size: TCGSize; const ref: TReference; reg: TRegister);
  1016. var
  1017. tmpreg: tregister;
  1018. begin
  1019. case op of
  1020. OP_NOT,OP_NEG:
  1021. { handle it as "load ref,reg; op reg" }
  1022. begin
  1023. a_load_ref_reg(list,size,ref,reg);
  1024. a_op_reg_reg(list,op,size,reg,reg);
  1025. end;
  1026. else
  1027. begin
  1028. tmpreg := get_scratch_reg(list);
  1029. a_load_ref_reg(list,size,ref,tmpreg);
  1030. a_op_reg_reg(list,op,size,tmpreg,reg);
  1031. free_scratch_reg(list,tmpreg);
  1032. end;
  1033. end;
  1034. end;
  1035. procedure tcg.a_op_reg_loc(list : taasmoutput; Op: TOpCG; reg: tregister; const loc: tlocation);
  1036. begin
  1037. case loc.loc of
  1038. LOC_REGISTER, LOC_CREGISTER:
  1039. a_op_reg_reg(list,op,loc.size,reg,loc.register);
  1040. LOC_REFERENCE, LOC_CREFERENCE:
  1041. a_op_reg_ref(list,op,loc.size,reg,loc.reference);
  1042. else
  1043. internalerror(200109061);
  1044. end;
  1045. end;
  1046. procedure tcg.a_op_ref_loc(list : taasmoutput; Op: TOpCG; const ref: TReference; const loc: tlocation);
  1047. var
  1048. tmpreg: tregister;
  1049. begin
  1050. case loc.loc of
  1051. LOC_REGISTER,LOC_CREGISTER:
  1052. a_op_ref_reg(list,op,loc.size,ref,loc.register);
  1053. LOC_REFERENCE,LOC_CREFERENCE:
  1054. begin
  1055. tmpreg := get_scratch_reg(list);
  1056. tmpreg:=rg.makeregsize(tmpreg,loc.size);
  1057. a_load_ref_reg(list,loc.size,ref,tmpreg);
  1058. a_op_reg_ref(list,op,loc.size,tmpreg,loc.reference);
  1059. free_scratch_reg(list,tmpreg);
  1060. end;
  1061. else
  1062. internalerror(200109061);
  1063. end;
  1064. end;
  1065. procedure tcg.a_op_const_reg_reg(list: taasmoutput; op: TOpCg;
  1066. size: tcgsize; a: aword; src, dst: tregister);
  1067. begin
  1068. a_load_reg_reg(list,size,src,dst);
  1069. a_op_const_reg(list,op,a,dst);
  1070. end;
  1071. procedure tcg.a_op_reg_reg_reg(list: taasmoutput; op: TOpCg;
  1072. size: tcgsize; src1, src2, dst: tregister);
  1073. begin
  1074. a_load_reg_reg(list,size,src2,dst);
  1075. a_op_reg_reg(list,op,size,src1,dst);
  1076. end;
  1077. procedure tcg.a_cmp_const_ref_label(list : taasmoutput;size : tcgsize;cmp_op : topcmp;a : aword;const ref : treference;
  1078. l : tasmlabel);
  1079. var
  1080. tmpreg: tregister;
  1081. begin
  1082. tmpreg := get_scratch_reg(list);
  1083. a_load_ref_reg(list,size,ref,tmpreg);
  1084. a_cmp_const_reg_label(list,size,cmp_op,a,tmpreg,l);
  1085. free_scratch_reg(list,tmpreg);
  1086. end;
  1087. procedure tcg.a_cmp_const_loc_label(list : taasmoutput;size : tcgsize;cmp_op : topcmp;a : aword;const loc : tlocation;
  1088. l : tasmlabel);
  1089. begin
  1090. case loc.loc of
  1091. LOC_REGISTER,LOC_CREGISTER:
  1092. a_cmp_const_reg_label(list,size,cmp_op,a,loc.register,l);
  1093. LOC_REFERENCE,LOC_CREFERENCE:
  1094. a_cmp_const_ref_label(list,size,cmp_op,a,loc.reference,l);
  1095. else
  1096. internalerror(200109061);
  1097. end;
  1098. end;
  1099. procedure tcg.a_cmp_ref_reg_label(list : taasmoutput;size : tcgsize;cmp_op : topcmp; const ref: treference; reg : tregister; l : tasmlabel);
  1100. var
  1101. tmpreg: tregister;
  1102. begin
  1103. tmpreg := get_scratch_reg(list);
  1104. a_load_ref_reg(list,size,ref,tmpreg);
  1105. a_cmp_reg_reg_label(list,size,cmp_op,tmpreg,reg,l);
  1106. free_scratch_reg(list,tmpreg);
  1107. end;
  1108. procedure tcg.a_cmp_loc_reg_label(list : taasmoutput;size : tcgsize;cmp_op : topcmp; const loc: tlocation; reg : tregister; l : tasmlabel);
  1109. begin
  1110. case loc.loc of
  1111. LOC_REGISTER,
  1112. LOC_CREGISTER:
  1113. a_cmp_reg_reg_label(list,size,cmp_op,loc.register,reg,l);
  1114. LOC_REFERENCE,
  1115. LOC_CREFERENCE :
  1116. a_cmp_ref_reg_label(list,size,cmp_op,loc.reference,reg,l);
  1117. LOC_CONSTANT:
  1118. a_cmp_const_reg_label(list,size,cmp_op,loc.value,reg,l);
  1119. else
  1120. internalerror(200203231);
  1121. end;
  1122. end;
  1123. procedure tcg.a_cmp_ref_loc_label(list : taasmoutput;size : tcgsize;cmp_op : topcmp;const ref: treference;const loc : tlocation;
  1124. l : tasmlabel);
  1125. var
  1126. tmpreg: tregister;
  1127. begin
  1128. case loc.loc of
  1129. LOC_REGISTER,LOC_CREGISTER:
  1130. a_cmp_ref_reg_label(list,size,cmp_op,ref,loc.register,l);
  1131. LOC_REFERENCE,LOC_CREFERENCE:
  1132. begin
  1133. {$ifdef i386}
  1134. { the following is done with defines to avoid a speed penalty, }
  1135. { since all this is only necessary for the 80x86 (because EDI }
  1136. { doesn't have an 8bit component which is directly addressable) }
  1137. if size in [OS_8,OS_S8] then
  1138. tmpreg := rg.getregisterint(exprasmlist)
  1139. else
  1140. {$endif i386}
  1141. tmpreg := get_scratch_reg(list);
  1142. tmpreg := rg.makeregsize(tmpreg,size);
  1143. a_load_ref_reg(list,size,loc.reference,tmpreg);
  1144. a_cmp_ref_reg_label(list,size,cmp_op,ref,tmpreg,l);
  1145. {$ifdef i386}
  1146. if size in [OS_8,OS_S8] then
  1147. rg.ungetregister(exprasmlist,tmpreg)
  1148. else
  1149. {$endif i386}
  1150. free_scratch_reg(list,tmpreg);
  1151. end
  1152. else
  1153. internalerror(200109061);
  1154. end;
  1155. end;
  1156. function tcg.reg_cgsize(const reg: tregister) : tcgsize;
  1157. begin
  1158. reg_cgsize := OS_INT;
  1159. end;
  1160. procedure tcg.g_copyshortstring(list : taasmoutput;const source,dest : treference;len:byte;delsource,loadref : boolean);
  1161. begin
  1162. a_paramaddr_ref(list,dest,3);
  1163. if loadref then
  1164. a_param_ref(list,OS_ADDR,source,2)
  1165. else
  1166. a_paramaddr_ref(list,source,2);
  1167. if delsource then
  1168. reference_release(list,source);
  1169. a_param_const(list,OS_INT,len,1);
  1170. a_call_name(list,'FPC_SHORTSTR_COPY',0);
  1171. g_maybe_loadself(list);
  1172. end;
  1173. procedure tcg.g_incrrefcount(list : taasmoutput;t: tdef; const ref: treference);
  1174. var
  1175. href : treference;
  1176. pushedregs : tpushedsaved;
  1177. decrfunc : string;
  1178. begin
  1179. rg.saveusedregisters(list,pushedregs,all_registers);
  1180. if is_interfacecom(t) then
  1181. decrfunc:='FPC_INTF_INCR_REF'
  1182. else if is_ansistring(t) then
  1183. decrfunc:='FPC_ANSISTR_INCR_REF'
  1184. else if is_widestring(t) then
  1185. decrfunc:='FPC_WIDESTR_INCR_REF'
  1186. else
  1187. decrfunc:='';
  1188. { call the special decr function or the generic decref }
  1189. if decrfunc<>'' then
  1190. cg.a_param_ref(list,OS_ADDR,ref,1)
  1191. else
  1192. begin
  1193. reference_reset_symbol(href,tstoreddef(t).get_rtti_label(initrtti),0);
  1194. a_paramaddr_ref(list,href,2);
  1195. a_paramaddr_ref(list,ref,1);
  1196. decrfunc:='FPC_ADDREF';
  1197. end;
  1198. rg.saveregvars(exprasmlist,all_registers);
  1199. a_call_name(list,decrfunc,0);
  1200. rg.restoreusedregisters(list,pushedregs);
  1201. end;
  1202. procedure tcg.g_decrrefcount(list : taasmoutput;t: tdef; const ref: treference);
  1203. var
  1204. href : treference;
  1205. pushedregs : tpushedsaved;
  1206. decrfunc : string;
  1207. begin
  1208. rg.saveusedregisters(list,pushedregs,all_registers);
  1209. if is_interfacecom(t) then
  1210. decrfunc:='FPC_INTF_DECR_REF'
  1211. else if is_ansistring(t) then
  1212. decrfunc:='FPC_ANSISTR_DECR_REF'
  1213. else if is_widestring(t) then
  1214. decrfunc:='FPC_WIDESTR_DECR_REF'
  1215. else
  1216. decrfunc:='';
  1217. { call the special decr function or the generic decref }
  1218. if decrfunc<>'' then
  1219. cg.a_paramaddr_ref(list,ref,1)
  1220. else
  1221. begin
  1222. reference_reset_symbol(href,tstoreddef(t).get_rtti_label(initrtti),0);
  1223. a_paramaddr_ref(list,href,2);
  1224. a_paramaddr_ref(list,ref,1);
  1225. decrfunc:='FPC_DECREF';
  1226. end;
  1227. rg.saveregvars(exprasmlist,all_registers);
  1228. a_call_name(list,decrfunc,0);
  1229. rg.restoreusedregisters(list,pushedregs);
  1230. end;
  1231. procedure tcg.g_initialize(list : taasmoutput;t : tdef;const ref : treference;loadref : boolean);
  1232. var
  1233. href : treference;
  1234. begin
  1235. if is_ansistring(t) or
  1236. is_widestring(t) or
  1237. is_interfacecom(t) then
  1238. a_load_const_ref(list,OS_ADDR,0,ref)
  1239. else
  1240. begin
  1241. reference_reset_symbol(href,tstoreddef(t).get_rtti_label(initrtti),0);
  1242. a_paramaddr_ref(list,href,2);
  1243. if loadref then
  1244. a_param_ref(list,OS_ADDR,ref,1)
  1245. else
  1246. a_paramaddr_ref(list,ref,1);
  1247. a_call_name(list,'FPC_INITIALIZE',0);
  1248. end;
  1249. end;
  1250. procedure tcg.g_finalize(list : taasmoutput;t : tdef;const ref : treference;loadref : boolean);
  1251. var
  1252. href : treference;
  1253. begin
  1254. if is_ansistring(t) or
  1255. is_widestring(t) or
  1256. is_interfacecom(t) then
  1257. g_decrrefcount(list,t,ref)
  1258. else
  1259. begin
  1260. reference_reset_symbol(href,tstoreddef(t).get_rtti_label(initrtti),0);
  1261. a_paramaddr_ref(list,href,2);
  1262. if loadref then
  1263. a_param_ref(list,OS_ADDR,ref,1)
  1264. else
  1265. a_paramaddr_ref(list,ref,1);
  1266. a_call_name(list,'FPC_FINALIZE',0);
  1267. end;
  1268. end;
  1269. procedure tcg.g_rangecheck(list: taasmoutput; const p: tnode;const todef: tdef);
  1270. { generate range checking code for the value at location p. The type }
  1271. { type used is checked against todefs ranges. fromdef (p.resulttype.def) }
  1272. { is the original type used at that location. When both defs are equal }
  1273. { the check is also insert (needed for succ,pref,inc,dec) }
  1274. const
  1275. {$ifdef ver1_0}
  1276. awordsignedmax=high(longint);
  1277. {$else}
  1278. awordsignedmax=high(aword) div 2;
  1279. {$endif}
  1280. var
  1281. neglabel : tasmlabel;
  1282. hreg : tregister;
  1283. fromdef : tdef;
  1284. lto,hto,
  1285. lfrom,hfrom : TConstExprInt;
  1286. from_signed: boolean;
  1287. begin
  1288. { range checking on and range checkable value? }
  1289. if not(cs_check_range in aktlocalswitches) or
  1290. not(todef.deftype in [orddef,enumdef,arraydef]) then
  1291. exit;
  1292. { only check when assigning to scalar, subranges are different, }
  1293. { when todef=fromdef then the check is always generated }
  1294. fromdef:=p.resulttype.def;
  1295. getrange(p.resulttype.def,lfrom,hfrom);
  1296. getrange(todef,lto,hto);
  1297. { no range check if from and to are equal and are both longint/dword }
  1298. { (if we have a 32bit processor) or int64/qword, since such }
  1299. { operations can at most cause overflows (JM) }
  1300. { Note that these checks are mostly processor independent, they only }
  1301. { have to be changed once we introduce 64bit subrange types }
  1302. if (fromdef = todef) and
  1303. { then fromdef and todef can only be orddefs }
  1304. (((sizeof(aword) = 4) and
  1305. (((torddef(fromdef).typ = s32bit) and
  1306. (lfrom = low(longint)) and
  1307. (hfrom = high(longint))) or
  1308. ((torddef(fromdef).typ = u32bit) and
  1309. (lfrom = low(cardinal)) and
  1310. (hfrom = high(cardinal))))) or
  1311. is_64bitint(fromdef)) then
  1312. exit;
  1313. if todef<>fromdef then
  1314. begin
  1315. { if the from-range falls completely in the to-range, no check }
  1316. { is necessary }
  1317. if (lto<=lfrom) and (hto>=hfrom) then
  1318. exit;
  1319. end;
  1320. { generate the rangecheck code for the def where we are going to }
  1321. { store the result }
  1322. { use the trick that }
  1323. { a <= x <= b <=> 0 <= x-a <= b-a <=> cardinal(x-a) <= cardinal(b-a) }
  1324. { To be able to do that, we have to make sure however that either }
  1325. { fromdef and todef are both signed or unsigned, or that we leave }
  1326. { the parts < 0 and > maxlongint out }
  1327. { is_signed now also works for arrays (it checks the rangetype) (JM) }
  1328. from_signed := is_signed(fromdef);
  1329. if from_signed xor is_signed(todef) then
  1330. if from_signed then
  1331. { from is signed, to is unsigned }
  1332. begin
  1333. { if high(from) < 0 -> always range error }
  1334. if (hfrom < 0) or
  1335. { if low(to) > maxlongint also range error }
  1336. (lto > awordsignedmax) then
  1337. begin
  1338. a_call_name(list,'FPC_RANGEERROR',0);
  1339. exit
  1340. end;
  1341. { from is signed and to is unsigned -> when looking at from }
  1342. { as an unsigned value, it must be < maxlongint (otherwise }
  1343. { it's negative, which is invalid since "to" is unsigned) }
  1344. if hto > awordsignedmax then
  1345. hto := awordsignedmax;
  1346. end
  1347. else
  1348. { from is unsigned, to is signed }
  1349. begin
  1350. if (lfrom > awordsignedmax) or
  1351. (hto < 0) then
  1352. begin
  1353. a_call_name(list,'FPC_RANGEERROR',0);
  1354. exit
  1355. end;
  1356. { from is unsigned and to is signed -> when looking at to }
  1357. { as an unsigned value, it must be >= 0 (since negative }
  1358. { values are the same as values > maxlongint) }
  1359. if lto < 0 then
  1360. lto := 0;
  1361. end;
  1362. hreg := get_scratch_reg(list);
  1363. if (p.location.loc in [LOC_REGISTER,LOC_CREGISTER]) then
  1364. a_op_const_reg_reg(list,OP_SUB,def_cgsize(p.resulttype.def),
  1365. aword(longint(lto and $ffffffff)),p.location.register,hreg)
  1366. else
  1367. begin
  1368. a_load_ref_reg(list,def_cgsize(p.resulttype.def),
  1369. p.location.reference,hreg);
  1370. a_op_const_reg(list,OP_SUB,aword(longint(lto and $ffffffff)),hreg);
  1371. end;
  1372. getlabel(neglabel);
  1373. a_cmp_const_reg_label(list,OS_INT,OC_BE,aword(longint((hto-lto) and $ffffffff)),hreg,neglabel);
  1374. { !!! should happen right after the compare (JM) }
  1375. free_scratch_reg(list,hreg);
  1376. a_call_name(list,'FPC_RANGEERROR',0);
  1377. a_label(list,neglabel);
  1378. end;
  1379. procedure tcg.g_stackcheck(list : taasmoutput;stackframesize : longint);
  1380. begin
  1381. a_param_const(list,OS_32,stackframesize,1);
  1382. a_call_name(list,'FPC_STACKCHECK',0);
  1383. end;
  1384. finalization
  1385. cg.free;
  1386. end.
  1387. {
  1388. $Log$
  1389. Revision 1.18 2002-04-25 20:16:38 peter
  1390. * moved more routines from cga/n386util
  1391. Revision 1.17 2002/04/22 16:30:05 peter
  1392. * fixed @methodpointer
  1393. Revision 1.16 2002/04/21 15:25:30 carl
  1394. + a_jmp_cond -> a_jmp_always (a_jmp_cond is NOT portable)
  1395. + changeregsize -> rg.makeregsize
  1396. Revision 1.15 2002/04/20 21:32:23 carl
  1397. + generic FPC_CHECKPOINTER
  1398. + first parameter offset in stack now portable
  1399. * rename some constants
  1400. + move some cpu stuff to other units
  1401. - remove unused constents
  1402. * fix stacksize for some targets
  1403. * fix generic size problems which depend now on EXTEND_SIZE constant
  1404. Revision 1.14 2002/04/15 19:44:18 peter
  1405. * fixed stackcheck that would be called recursively when a stack
  1406. error was found
  1407. * generic changeregsize(reg,size) for i386 register resizing
  1408. * removed some more routines from cga unit
  1409. * fixed returnvalue handling
  1410. * fixed default stacksize of linux and go32v2, 8kb was a bit small :-)
  1411. Revision 1.13 2002/04/07 13:22:11 carl
  1412. + more documentation
  1413. Revision 1.12 2002/04/07 09:12:46 carl
  1414. + documentation
  1415. Revision 1.11 2002/04/06 18:10:42 jonas
  1416. * several powerpc-related additions and fixes
  1417. Revision 1.10 2002/04/04 19:05:54 peter
  1418. * removed unused units
  1419. * use tlocation.size in cg.a_*loc*() routines
  1420. Revision 1.9 2002/04/02 17:11:27 peter
  1421. * tlocation,treference update
  1422. * LOC_CONSTANT added for better constant handling
  1423. * secondadd splitted in multiple routines
  1424. * location_force_reg added for loading a location to a register
  1425. of a specified size
  1426. * secondassignment parses now first the right and then the left node
  1427. (this is compatible with Kylix). This saves a lot of push/pop especially
  1428. with string operations
  1429. * adapted some routines to use the new cg methods
  1430. Revision 1.8 2002/03/31 20:26:33 jonas
  1431. + a_loadfpu_* and a_loadmm_* methods in tcg
  1432. * register allocation is now handled by a class and is mostly processor
  1433. independent (+rgobj.pas and i386/rgcpu.pas)
  1434. * temp allocation is now handled by a class (+tgobj.pas, -i386\tgcpu.pas)
  1435. * some small improvements and fixes to the optimizer
  1436. * some register allocation fixes
  1437. * some fpuvaroffset fixes in the unary minus node
  1438. * push/popusedregisters is now called rg.save/restoreusedregisters and
  1439. (for i386) uses temps instead of push/pop's when using -Op3 (that code is
  1440. also better optimizable)
  1441. * fixed and optimized register saving/restoring for new/dispose nodes
  1442. * LOC_FPU locations now also require their "register" field to be set to
  1443. R_ST, not R_ST0 (the latter is used for LOC_CFPUREGISTER locations only)
  1444. - list field removed of the tnode class because it's not used currently
  1445. and can cause hard-to-find bugs
  1446. Revision 1.7 2002/03/04 19:10:11 peter
  1447. * removed compiler warnings
  1448. Revision 1.6 2001/12/30 17:24:48 jonas
  1449. * range checking is now processor independent (part in cgobj,
  1450. part in cg64f32) and should work correctly again (it needed
  1451. some changes after the changes of the low and high of
  1452. tordef's to int64)
  1453. * maketojumpbool() is now processor independent (in ncgutil)
  1454. * getregister32 is now called getregisterint
  1455. Revision 1.5 2001/12/29 15:28:58 jonas
  1456. * powerpc/cgcpu.pas compiles :)
  1457. * several powerpc-related fixes
  1458. * cpuasm unit is now based on common tainst unit
  1459. + nppcmat unit for powerpc (almost complete)
  1460. Revision 1.4 2001/09/30 21:26:42 peter
  1461. * removed obsolete newst defines
  1462. Revision 1.3 2001/09/30 16:17:17 jonas
  1463. * made most constant and mem handling processor independent
  1464. Revision 1.2 2001/09/28 20:39:32 jonas
  1465. * changed all flow control structures (except for exception handling
  1466. related things) to processor independent code (in new ncgflw unit)
  1467. + generic cgobj unit which contains lots of code generator helpers with
  1468. global "cg" class instance variable
  1469. + cgcpu unit for i386 (implements processor specific routines of the above
  1470. unit)
  1471. * updated cgbase and cpubase for the new code generator units
  1472. * include ncgflw unit in cpunode unit
  1473. Revision 1.5 2001/09/09 17:10:26 jonas
  1474. * some more things implemented
  1475. Revision 1.4 2001/09/06 15:25:55 jonas
  1476. * changed type of tcg from object to class -> abstract methods are now
  1477. a lot cleaner :)
  1478. + more updates: load_*_loc methods, op_*_* methods, g_flags2reg method
  1479. (if possible with geenric implementation and necessary ppc
  1480. implementations)
  1481. * worked a bit further on cgflw, now working on exitnode
  1482. Revision 1.3 2001/09/05 20:21:03 jonas
  1483. * new cgflow based on n386flw with all nodes until forn "translated"
  1484. + a_cmp_loc_*_label methods for tcg
  1485. + base implementatino for a_cmp_ref_*_label methods
  1486. * small bugfixes to powerpc cg
  1487. Revision 1.2 2001/08/26 13:37:04 florian
  1488. * some cg reorganisation
  1489. * some PPC updates
  1490. Revision 1.1 2000/07/13 06:30:07 michael
  1491. + Initial import
  1492. }