nx64cnv.pas 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180
  1. {
  2. $Id$
  3. Copyright (c) 1998-2002 by Florian Klaempfl
  4. Generate x86-64 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 nx64cnv;
  19. {$i fpcdefs.inc}
  20. interface
  21. uses
  22. node,ncgcnv,defutil,defcmp,
  23. nx86cnv;
  24. type
  25. tx86_64typeconvnode = class(tx86typeconvnode)
  26. protected
  27. { procedure second_int_to_int;override; }
  28. { procedure second_string_to_string;override; }
  29. { procedure second_cstring_to_pchar;override; }
  30. { procedure second_string_to_chararray;override; }
  31. { procedure second_array_to_pointer;override; }
  32. { procedure second_pointer_to_array;override; }
  33. { procedure second_chararray_to_string;override; }
  34. { procedure second_char_to_string;override; }
  35. { function first_int_to_real: tnode; override; }
  36. procedure second_int_to_real;override;
  37. { procedure second_real_to_real;override; }
  38. { procedure second_cord_to_pointer;override; }
  39. { procedure second_proc_to_procvar;override; }
  40. { procedure second_bool_to_int;override; }
  41. { procedure second_int_to_bool;override; }
  42. { procedure second_load_smallset;override; }
  43. { procedure second_ansistring_to_pchar;override; }
  44. { procedure second_pchar_to_string;override; }
  45. { procedure second_class_to_intf;override; }
  46. { procedure second_char_to_char;override; }
  47. procedure second_call_helper(c : tconverttype);override;
  48. end;
  49. implementation
  50. uses
  51. verbose,systems,globtype,
  52. symconst,symdef,aasmbase,aasmtai,aasmcpu,
  53. cginfo,cgbase,pass_2,
  54. ncon,ncal,ncnv,
  55. cpubase,
  56. cgobj,cga,tgobj,rgobj,rgcpu,ncgutil;
  57. procedure tx86_64typeconvnode.second_int_to_real;
  58. begin
  59. internalerror(200304305);
  60. end;
  61. procedure tx86_64typeconvnode.second_call_helper(c : tconverttype);
  62. {$ifdef fpc}
  63. const
  64. secondconvert : array[tconverttype] of pointer = (
  65. @second_nothing, {equal}
  66. @second_nothing, {not_possible}
  67. @second_nothing, {second_string_to_string, handled in resulttype pass }
  68. @second_char_to_string,
  69. @second_nothing, {char_to_charray}
  70. @second_nothing, { pchar_to_string, handled in resulttype pass }
  71. @second_nothing, {cchar_to_pchar}
  72. @second_cstring_to_pchar,
  73. @second_ansistring_to_pchar,
  74. @second_string_to_chararray,
  75. @second_nothing, { chararray_to_string, handled in resulttype pass }
  76. @second_array_to_pointer,
  77. @second_pointer_to_array,
  78. @second_int_to_int,
  79. @second_int_to_bool,
  80. @second_bool_to_bool,
  81. @second_bool_to_int,
  82. @second_real_to_real,
  83. @second_int_to_real,
  84. @second_nothing, { real_to_currency, handled in resulttype pass }
  85. @second_proc_to_procvar,
  86. @second_nothing, { arrayconstructor_to_set }
  87. @second_nothing, { second_load_smallset, handled in first pass }
  88. @second_cord_to_pointer,
  89. @second_nothing, { interface 2 string }
  90. @second_nothing, { interface 2 guid }
  91. @second_class_to_intf,
  92. @second_char_to_char,
  93. @second_nothing, { normal_2_smallset }
  94. @second_nothing, { dynarray_2_openarray }
  95. @second_nothing, { pwchar_2_string }
  96. @second_nothing, { variant_2_dynarray }
  97. @second_nothing { dynarray_2_variant}
  98. );
  99. type
  100. tprocedureofobject = procedure of object;
  101. var
  102. r : packed record
  103. proc : pointer;
  104. obj : pointer;
  105. end;
  106. begin
  107. { this is a little bit dirty but it works }
  108. { and should be quite portable too }
  109. r.proc:=secondconvert[c];
  110. r.obj:=self;
  111. tprocedureofobject(r)();
  112. end;
  113. {$else fpc}
  114. begin
  115. case c of
  116. tc_equal,
  117. tc_not_possible,
  118. tc_string_2_string : second_nothing;
  119. tc_char_2_string : second_char_to_string;
  120. tc_char_2_chararray : second_nothing;
  121. tc_pchar_2_string : second_nothing;
  122. tc_cchar_2_pchar : second_nothing;
  123. tc_cstring_2_pchar : second_cstring_to_pchar;
  124. tc_ansistring_2_pchar : second_ansistring_to_pchar;
  125. tc_string_2_chararray : second_string_to_chararray;
  126. tc_chararray_2_string : second_nothing;
  127. tc_array_2_pointer : second_array_to_pointer;
  128. tc_pointer_2_array : second_pointer_to_array;
  129. tc_int_2_int : second_int_to_int;
  130. tc_int_2_bool : second_int_to_bool;
  131. tc_bool_2_bool : second_bool_to_bool;
  132. tc_bool_2_int : second_bool_to_int;
  133. tc_real_2_real : second_real_to_real;
  134. tc_int_2_real : second_int_to_real;
  135. tc_real_2_currency : second_nothing;
  136. tc_proc_2_procvar : second_proc_to_procvar;
  137. tc_arrayconstructor_2_set : second_nothing;
  138. tc_load_smallset : second_nothing;
  139. tc_cord_2_pointer : second_cord_to_pointer;
  140. tc_intf_2_string : second_nothing;
  141. tc_intf_2_guid : second_nothing;
  142. tc_class_2_intf : second_class_to_intf;
  143. tc_char_2_char : second_char_to_char;
  144. tc_normal_2_smallset : second_nothing;
  145. tc_dynarray_2_openarray : second_nothing;
  146. tc_pwchar_2_string : second_nothing;
  147. tc_variant_2_dynarray : second_nothing;
  148. tc_dynarray_2_variant : second_nothing;
  149. else internalerror(2002101101);
  150. end;
  151. end;
  152. {$endif fpc}
  153. begin
  154. ctypeconvnode:=tx86_64typeconvnode;
  155. end.
  156. {
  157. $Log$
  158. Revision 1.1 2003-04-30 20:53:32 florian
  159. * error when address of an abstract method is taken
  160. * fixed some x86-64 problems
  161. * merged some more x86-64 and i386 code
  162. }