n386cnv.pas 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296
  1. {
  2. $Id$
  3. Copyright (c) 1998-2002 by Florian Klaempfl
  4. Generate i386 assembler for type converting nodes
  5. This program is free software; you can redistribute it and/or modify
  6. it under the terms of the GNU General Public License as published by
  7. the Free Software Foundation; either version 2 of the License, or
  8. (at your option) any later version.
  9. This program is distributed in the hope that it will be useful,
  10. but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. GNU General Public License for more details.
  13. You should have received a copy of the GNU General Public License
  14. along with this program; if not, write to the Free Software
  15. Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  16. ****************************************************************************
  17. }
  18. unit n386cnv;
  19. {$i fpcdefs.inc}
  20. interface
  21. uses
  22. node,ncgcnv,defutil,defcmp,nx86cnv;
  23. type
  24. ti386typeconvnode = class(tx86typeconvnode)
  25. protected
  26. { procedure second_int_to_int;override; }
  27. { procedure second_string_to_string;override; }
  28. { procedure second_cstring_to_pchar;override; }
  29. { procedure second_string_to_chararray;override; }
  30. { procedure second_array_to_pointer;override; }
  31. { procedure second_pointer_to_array;override; }
  32. { procedure second_chararray_to_string;override; }
  33. { procedure second_char_to_string;override; }
  34. { function first_int_to_real: tnode; override; }
  35. { procedure second_int_to_real;override; }
  36. { procedure second_real_to_real;override; }
  37. { procedure second_cord_to_pointer;override; }
  38. { procedure second_proc_to_procvar;override; }
  39. { procedure second_bool_to_int;override; }
  40. { procedure second_int_to_bool;override; }
  41. { procedure second_load_smallset;override; }
  42. { procedure second_ansistring_to_pchar;override; }
  43. { procedure second_pchar_to_string;override; }
  44. { procedure second_class_to_intf;override; }
  45. { procedure second_char_to_char;override; }
  46. end;
  47. implementation
  48. uses
  49. verbose,systems,
  50. symconst,symdef,aasmbase,aasmtai,aasmcpu,
  51. cgbase,
  52. ncon,ncal,ncnv,
  53. cpubase,tgobj,
  54. cgobj,cga,cgx86,ncgutil;
  55. begin
  56. ctypeconvnode:=ti386typeconvnode;
  57. end.
  58. {
  59. $Log$
  60. Revision 1.72 2004-02-05 01:24:08 florian
  61. * several fixes to compile x86-64 system
  62. Revision 1.71 2003/12/22 23:08:59 peter
  63. * removed unused checkobject method
  64. Revision 1.70 2003/12/08 15:35:00 peter
  65. * fix loading of word/byte to real
  66. Revision 1.69 2003/12/03 23:13:20 peter
  67. * delayed paraloc allocation, a_param_*() gets extra parameter
  68. if it needs to allocate temp or real paralocation
  69. * optimized/simplified int-real loading
  70. Revision 1.68 2003/11/04 22:30:15 florian
  71. + type cast variant<->enum
  72. * cnv. node second pass uses now as well helper wrappers
  73. Revision 1.67 2003/10/10 17:48:14 peter
  74. * old trgobj moved to x86/rgcpu and renamed to trgx86fpu
  75. * tregisteralloctor renamed to trgobj
  76. * removed rgobj from a lot of units
  77. * moved location_* and reference_* to cgobj
  78. * first things for mmx register allocation
  79. Revision 1.66 2003/10/09 21:31:37 daniel
  80. * Register allocator splitted, ans abstract now
  81. Revision 1.65 2003/10/01 20:34:49 peter
  82. * procinfo unit contains tprocinfo
  83. * cginfo renamed to cgbase
  84. * moved cgmessage to verbose
  85. * fixed ppc and sparc compiles
  86. Revision 1.64 2003/09/28 21:48:20 peter
  87. * fix register leaks
  88. Revision 1.63 2003/09/03 15:55:01 peter
  89. * NEWRA branch merged
  90. Revision 1.62.2.2 2003/08/31 15:46:26 peter
  91. * more updates for tregister
  92. Revision 1.62.2.1 2003/08/31 13:58:46 daniel
  93. * Some more work to make things compile
  94. Revision 1.62 2003/06/03 21:11:09 peter
  95. * cg.a_load_* get a from and to size specifier
  96. * makeregsize only accepts newregister
  97. * i386 uses generic tcgnotnode,tcgunaryminus
  98. Revision 1.61 2003/04/30 20:53:32 florian
  99. * error when address of an abstract method is taken
  100. * fixed some x86-64 problems
  101. * merged some more x86-64 and i386 code
  102. Revision 1.60 2003/04/23 20:16:04 peter
  103. + added currency support based on int64
  104. + is_64bit for use in cg units instead of is_64bitint
  105. * removed cgmessage from n386add, replace with internalerrors
  106. Revision 1.59 2003/04/22 23:50:23 peter
  107. * firstpass uses expectloc
  108. * checks if there are differences between the expectloc and
  109. location.loc from secondpass in EXTDEBUG
  110. Revision 1.58 2003/04/22 10:09:35 daniel
  111. + Implemented the actual register allocator
  112. + Scratch registers unavailable when new register allocator used
  113. + maybe_save/maybe_restore unavailable when new register allocator used
  114. Revision 1.57 2003/03/13 19:52:23 jonas
  115. * and more new register allocator fixes (in the i386 code generator this
  116. time). At least now the ppc cross compiler can compile the linux
  117. system unit again, but I haven't tested it.
  118. Revision 1.56 2003/02/19 22:00:15 daniel
  119. * Code generator converted to new register notation
  120. - Horribily outdated todo.txt removed
  121. Revision 1.55 2003/01/13 18:37:44 daniel
  122. * Work on register conversion
  123. Revision 1.54 2003/01/08 18:43:57 daniel
  124. * Tregister changed into a record
  125. Revision 1.53 2002/12/05 14:27:42 florian
  126. * some variant <-> dyn. array stuff
  127. Revision 1.52 2002/11/25 17:43:26 peter
  128. * splitted defbase in defutil,symutil,defcmp
  129. * merged isconvertable and is_equal into compare_defs(_ext)
  130. * made operator search faster by walking the list only once
  131. Revision 1.51 2002/10/10 16:14:54 florian
  132. * fixed to reflect last tconvtype change
  133. Revision 1.50 2002/10/05 12:43:29 carl
  134. * fixes for Delphi 6 compilation
  135. (warning : Some features do not work under Delphi)
  136. Revision 1.49 2002/09/17 18:54:03 jonas
  137. * a_load_reg_reg() now has two size parameters: source and dest. This
  138. allows some optimizations on architectures that don't encode the
  139. register size in the register name.
  140. Revision 1.48 2002/08/14 19:19:14 carl
  141. * first_int_to_real moved to i386 (other one is generic)
  142. Revision 1.47 2002/08/11 14:32:30 peter
  143. * renamed current_library to objectlibrary
  144. Revision 1.46 2002/08/11 13:24:16 peter
  145. * saving of asmsymbols in ppu supported
  146. * asmsymbollist global is removed and moved into a new class
  147. tasmlibrarydata that will hold the info of a .a file which
  148. corresponds with a single module. Added librarydata to tmodule
  149. to keep the library info stored for the module. In the future the
  150. objectfiles will also be stored to the tasmlibrarydata class
  151. * all getlabel/newasmsymbol and friends are moved to the new class
  152. Revision 1.45 2002/07/27 19:53:51 jonas
  153. + generic implementation of tcg.g_flags2ref()
  154. * tcg.flags2xxx() now also needs a size parameter
  155. Revision 1.44 2002/07/20 11:58:01 florian
  156. * types.pas renamed to defbase.pas because D6 contains a types
  157. unit so this would conflicts if D6 programms are compiled
  158. + Willamette/SSE2 instructions to assembler added
  159. Revision 1.43 2002/07/01 18:46:31 peter
  160. * internal linker
  161. * reorganized aasm layer
  162. Revision 1.42 2002/05/20 13:30:40 carl
  163. * bugfix of hdisponen (base must be set, not index)
  164. * more portability fixes
  165. Revision 1.41 2002/05/18 13:34:24 peter
  166. * readded missing revisions
  167. Revision 1.40 2002/05/16 19:46:51 carl
  168. + defines.inc -> fpcdefs.inc to avoid conflicts if compiling by hand
  169. + try to fix temp allocation (still in ifdef)
  170. + generic constructor calls
  171. + start of tassembler / tmodulebase class cleanup
  172. Revision 1.38 2002/05/12 16:53:17 peter
  173. * moved entry and exitcode to ncgutil and cgobj
  174. * foreach gets extra argument for passing local data to the
  175. iterator function
  176. * -CR checks also class typecasts at runtime by changing them
  177. into as
  178. * fixed compiler to cycle with the -CR option
  179. * fixed stabs with elf writer, finally the global variables can
  180. be watched
  181. * removed a lot of routines from cga unit and replaced them by
  182. calls to cgobj
  183. * u32bit-s32bit updates for and,or,xor nodes. When one element is
  184. u32bit then the other is typecasted also to u32bit without giving
  185. a rangecheck warning/error.
  186. * fixed pascal calling method with reversing also the high tree in
  187. the parast, detected by tcalcst3 test
  188. Revision 1.37 2002/04/21 19:02:07 peter
  189. * removed newn and disposen nodes, the code is now directly
  190. inlined from pexpr
  191. * -an option that will write the secondpass nodes to the .s file, this
  192. requires EXTDEBUG define to actually write the info
  193. * fixed various internal errors and crashes due recent code changes
  194. Revision 1.36 2002/04/21 15:35:23 carl
  195. * changeregsize -> rg.makeregsize
  196. Revision 1.35 2002/04/19 15:39:35 peter
  197. * removed some more routines from cga
  198. * moved location_force_reg/mem to ncgutil
  199. * moved arrayconstructnode secondpass to ncgld
  200. Revision 1.34 2002/04/15 19:44:21 peter
  201. * fixed stackcheck that would be called recursively when a stack
  202. error was found
  203. * generic changeregsize(reg,size) for i386 register resizing
  204. * removed some more routines from cga unit
  205. * fixed returnvalue handling
  206. * fixed default stacksize of linux and go32v2, 8kb was a bit small :-)
  207. Revision 1.33 2002/04/04 19:06:10 peter
  208. * removed unused units
  209. * use tlocation.size in cg.a_*loc*() routines
  210. Revision 1.32 2002/04/02 17:11:36 peter
  211. * tlocation,treference update
  212. * LOC_CONSTANT added for better constant handling
  213. * secondadd splitted in multiple routines
  214. * location_force_reg added for loading a location to a register
  215. of a specified size
  216. * secondassignment parses now first the right and then the left node
  217. (this is compatible with Kylix). This saves a lot of push/pop especially
  218. with string operations
  219. * adapted some routines to use the new cg methods
  220. Revision 1.31 2002/03/31 20:26:38 jonas
  221. + a_loadfpu_* and a_loadmm_* methods in tcg
  222. * register allocation is now handled by a class and is mostly processor
  223. independent (+rgobj.pas and i386/rgcpu.pas)
  224. * temp allocation is now handled by a class (+tgobj.pas, -i386\tgcpu.pas)
  225. * some small improvements and fixes to the optimizer
  226. * some register allocation fixes
  227. * some fpuvaroffset fixes in the unary minus node
  228. * push/popusedregisters is now called rg.save/restoreusedregisters and
  229. (for i386) uses temps instead of push/pop's when using -Op3 (that code is
  230. also better optimizable)
  231. * fixed and optimized register saving/restoring for new/dispose nodes
  232. * LOC_FPU locations now also require their "register" field to be set to
  233. R_ST, not R_ST0 (the latter is used for LOC_CFPUREGISTER locations only)
  234. - list field removed of the tnode class because it's not used currently
  235. and can cause hard-to-find bugs
  236. Revision 1.30 2002/03/04 19:10:13 peter
  237. * removed compiler warnings
  238. }