narmcnv.pas 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204
  1. {
  2. $Id$
  3. Copyright (c) 1998-2002 by Florian Klaempfl
  4. Generate ARM 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 narmcnv;
  19. {$i fpcdefs.inc}
  20. interface
  21. uses
  22. node,ncnv,ncgcnv,defcmp;
  23. type
  24. tarmtypeconvnode = class(tcgtypeconvnode)
  25. protected
  26. function first_int_to_real: tnode;override;
  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. // function first_int_to_real: tnode; override;
  33. { procedure second_pointer_to_array;override; }
  34. { procedure second_chararray_to_string;override; }
  35. { procedure second_char_to_string;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,globals,systems,
  52. symconst,symdef,aasmbase,aasmtai,
  53. defutil,
  54. cgbase,pass_1,pass_2,
  55. ncon,ncal,
  56. ncgutil,
  57. cpubase,aasmcpu,
  58. rgobj,tgobj,cgobj;
  59. {*****************************************************************************
  60. FirstTypeConv
  61. *****************************************************************************}
  62. function tarmtypeconvnode.first_int_to_real: tnode;
  63. var
  64. fname: string[19];
  65. begin
  66. { converting a 64bit integer to a float requires a helper }
  67. if is_64bitint(left.resulttype.def) then
  68. begin
  69. if is_signed(left.resulttype.def) then
  70. fname := 'fpc_int64_to_double'
  71. else
  72. fname := 'fpc_qword_to_double';
  73. result := ccallnode.createintern(fname,ccallparanode.create(
  74. left,nil));
  75. left:=nil;
  76. firstpass(result);
  77. exit;
  78. end
  79. else
  80. { other integers are supposed to be 32 bit }
  81. begin
  82. if is_signed(left.resulttype.def) then
  83. inserttypeconv(left,s32bittype)
  84. else
  85. inserttypeconv(left,u32bittype);
  86. firstpass(left);
  87. end;
  88. result := nil;
  89. if registersfpu<1 then
  90. registersfpu:=1;
  91. expectloc:=LOC_FPUREGISTER;
  92. end;
  93. procedure tarmtypeconvnode.second_int_to_real;
  94. var
  95. instr : taicpu;
  96. begin
  97. location_reset(location,LOC_FPUREGISTER,def_cgsize(resulttype.def));
  98. location_force_reg(exprasmlist,left.location,OS_32,true);
  99. location.register:=cg.getfpuregister(exprasmlist,location.size);
  100. instr:=taicpu.op_reg_reg(A_FLT,location.register,left.location.register);
  101. instr.oppostfix:=cgsize2fpuoppostfix[def_cgsize(resulttype.def)];
  102. exprasmlist.concat(instr);
  103. end;
  104. procedure tarmtypeconvnode.second_int_to_bool;
  105. begin
  106. end;
  107. procedure tarmtypeconvnode.second_call_helper(c : tconverttype);
  108. const
  109. secondconvert : array[tconverttype] of pointer = (
  110. @second_nothing, {equal}
  111. @second_nothing, {not_possible}
  112. @second_nothing, {second_string_to_string, handled in resulttype pass }
  113. @second_char_to_string,
  114. @second_nothing, {char_to_charray}
  115. @second_nothing, { pchar_to_string, handled in resulttype pass }
  116. @second_nothing, {cchar_to_pchar}
  117. @second_cstring_to_pchar,
  118. @second_ansistring_to_pchar,
  119. @second_string_to_chararray,
  120. @second_nothing, { chararray_to_string, handled in resulttype pass }
  121. @second_array_to_pointer,
  122. @second_pointer_to_array,
  123. @second_int_to_int,
  124. @second_int_to_bool,
  125. @second_bool_to_int, { bool_to_bool }
  126. @second_bool_to_int,
  127. @second_real_to_real,
  128. @second_int_to_real,
  129. @second_nothing, { real_to_currency, handled in resulttype pass }
  130. @second_proc_to_procvar,
  131. @second_nothing, { arrayconstructor_to_set }
  132. @second_nothing, { second_load_smallset, handled in first pass }
  133. @second_cord_to_pointer,
  134. @second_nothing, { interface 2 string }
  135. @second_nothing, { interface 2 guid }
  136. @second_class_to_intf,
  137. @second_char_to_char,
  138. @second_nothing, { normal_2_smallset }
  139. @second_nothing, { dynarray_2_openarray }
  140. @second_nothing,
  141. @second_nothing, { variant_2_dynarray }
  142. @second_nothing { dynarray_2_variant}
  143. );
  144. type
  145. tprocedureofobject = procedure of object;
  146. var
  147. r : packed record
  148. proc : pointer;
  149. obj : pointer;
  150. end;
  151. begin
  152. { this is a little bit dirty but it works }
  153. { and should be quite portable too }
  154. r.proc:=secondconvert[c];
  155. r.obj:=self;
  156. tprocedureofobject(r){$ifdef FPC}();{$endif FPC}
  157. end;
  158. begin
  159. ctypeconvnode:=tarmtypeconvnode;
  160. end.
  161. {
  162. $Log$
  163. Revision 1.5 2003-11-02 14:30:03 florian
  164. * fixed ARM for new reg. allocation scheme
  165. Revision 1.4 2003/09/01 15:11:16 florian
  166. * fixed reference handling
  167. * fixed operand postfix for floating point instructions
  168. * fixed wrong shifter constant handling
  169. Revision 1.3 2003/09/01 09:54:57 florian
  170. * results of work on arm port last weekend
  171. Revision 1.2 2003/08/25 23:20:38 florian
  172. + started to implement FPU support for the ARM
  173. * fixed a lot of other things
  174. Revision 1.1 2003/08/21 23:24:08 florian
  175. * continued to work on the arm skeleton
  176. }