navrcnv.pas 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180
  1. {
  2. Copyright (c) 1998-2009 by Florian Klaempfl
  3. Generate AVR assembler for type converting nodes
  4. This program is free software; you can redistribute it and/or modify
  5. it under the terms of the GNU General Public License as published by
  6. the Free Software Foundation; either version 2 of the License, or
  7. (at your option) any later version.
  8. This program is distributed in the hope that it will be useful,
  9. but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. GNU General Public License for more details.
  12. You should have received a copy of the GNU General Public License
  13. along with this program; if not, write to the Free Software
  14. Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  15. ****************************************************************************
  16. }
  17. unit navrcnv;
  18. {$i fpcdefs.inc}
  19. interface
  20. uses
  21. node,ncnv,ncgcnv,defcmp;
  22. type
  23. tarmtypeconvnode = class(tcgtypeconvnode)
  24. protected
  25. { procedure second_int_to_int;override; }
  26. { procedure second_string_to_string;override; }
  27. { procedure second_cstring_to_pchar;override; }
  28. { procedure second_string_to_chararray;override; }
  29. { procedure second_array_to_pointer;override; }
  30. { procedure second_pointer_to_array;override; }
  31. { procedure second_chararray_to_string;override; }
  32. { procedure second_char_to_string;override; }
  33. { procedure second_int_to_real;override; }
  34. { procedure second_real_to_real;override; }
  35. { procedure second_cord_to_pointer;override; }
  36. { procedure second_proc_to_procvar;override; }
  37. { procedure second_bool_to_int;override; }
  38. procedure second_int_to_bool;override;
  39. { procedure second_load_smallset;override; }
  40. { procedure second_ansistring_to_pchar;override; }
  41. { procedure second_pchar_to_string;override; }
  42. { procedure second_class_to_intf;override; }
  43. { procedure second_char_to_char;override; }
  44. end;
  45. implementation
  46. uses
  47. verbose,globtype,globals,systems,
  48. symconst,symdef,aasmbase,aasmtai,aasmdata,
  49. defutil,
  50. cgbase,cgutils,
  51. pass_1,pass_2,procinfo,
  52. ncon,ncal,
  53. ncgutil,
  54. cpubase,aasmcpu,
  55. rgobj,tgobj,cgobj,cgcpu;
  56. procedure tarmtypeconvnode.second_int_to_bool;
  57. var
  58. hregister : tregister;
  59. href : treference;
  60. resflags : tresflags;
  61. hlabel,oldTrueLabel,oldFalseLabel : tasmlabel;
  62. newsize : tcgsize;
  63. begin
  64. {
  65. oldTrueLabel:=current_procinfo.CurrTrueLabel;
  66. oldFalseLabel:=current_procinfo.CurrFalseLabel;
  67. current_asmdata.getjumplabel(current_procinfo.CurrTrueLabel);
  68. current_asmdata.getjumplabel(current_procinfo.CurrFalseLabel);
  69. secondpass(left);
  70. if codegenerror then
  71. exit;
  72. { Explicit typecasts from any ordinal type to a boolean type }
  73. { must not change the ordinal value }
  74. if (nf_explicit in flags) and
  75. not(left.location.loc in [LOC_FLAGS,LOC_JUMP]) then
  76. begin
  77. location_copy(location,left.location);
  78. newsize:=def_cgsize(resultdef);
  79. { change of size? change sign only if location is LOC_(C)REGISTER? Then we have to sign/zero-extend }
  80. if (tcgsize2size[newsize]<>tcgsize2size[left.location.size]) or
  81. ((newsize<>left.location.size) and (location.loc in [LOC_REGISTER,LOC_CREGISTER])) then
  82. location_force_reg(current_asmdata.CurrAsmList,location,newsize,true)
  83. else
  84. location.size:=newsize;
  85. current_procinfo.CurrTrueLabel:=oldTrueLabel;
  86. current_procinfo.CurrFalseLabel:=oldFalseLabel;
  87. exit;
  88. end;
  89. { Load left node into flag F_NE/F_E }
  90. resflags:=F_NE;
  91. case left.location.loc of
  92. LOC_CREFERENCE,
  93. LOC_REFERENCE :
  94. begin
  95. if left.location.size in [OS_64,OS_S64] then
  96. begin
  97. hregister:=cg.getintregister(current_asmdata.CurrAsmList,OS_INT);
  98. cg.a_load_ref_reg(current_asmdata.CurrAsmList,OS_32,OS_32,left.location.reference,hregister);
  99. href:=left.location.reference;
  100. inc(href.offset,4);
  101. tcgarm(cg).cgsetflags:=true;
  102. cg.a_op_ref_reg(current_asmdata.CurrAsmList,OP_OR,OS_32,href,hregister);
  103. tcgarm(cg).cgsetflags:=false;
  104. end
  105. else
  106. begin
  107. location_force_reg(current_asmdata.CurrAsmList,left.location,left.location.size,true);
  108. tcgarm(cg).cgsetflags:=true;
  109. cg.a_op_reg_reg(current_asmdata.CurrAsmList,OP_OR,left.location.size,left.location.register,left.location.register);
  110. tcgarm(cg).cgsetflags:=false;
  111. end;
  112. end;
  113. LOC_FLAGS :
  114. begin
  115. resflags:=left.location.resflags;
  116. end;
  117. LOC_REGISTER,LOC_CREGISTER :
  118. begin
  119. if left.location.size in [OS_64,OS_S64] then
  120. begin
  121. hregister:=cg.getintregister(current_asmdata.CurrAsmList,OS_32);
  122. cg.a_load_reg_reg(current_asmdata.CurrAsmList,OS_32,OS_32,left.location.register64.reglo,hregister);
  123. tcgarm(cg).cgsetflags:=true;
  124. cg.a_op_reg_reg(current_asmdata.CurrAsmList,OP_OR,OS_32,left.location.register64.reghi,hregister);
  125. tcgarm(cg).cgsetflags:=false;
  126. end
  127. else
  128. begin
  129. tcgarm(cg).cgsetflags:=true;
  130. cg.a_op_reg_reg(current_asmdata.CurrAsmList,OP_OR,left.location.size,left.location.register,left.location.register);
  131. tcgarm(cg).cgsetflags:=false;
  132. end;
  133. end;
  134. LOC_JUMP :
  135. begin
  136. hregister:=cg.getintregister(current_asmdata.CurrAsmList,OS_INT);
  137. current_asmdata.getjumplabel(hlabel);
  138. cg.a_label(current_asmdata.CurrAsmList,current_procinfo.CurrTrueLabel);
  139. cg.a_load_const_reg(current_asmdata.CurrAsmList,OS_INT,1,hregister);
  140. cg.a_jmp_always(current_asmdata.CurrAsmList,hlabel);
  141. cg.a_label(current_asmdata.CurrAsmList,current_procinfo.CurrFalseLabel);
  142. cg.a_load_const_reg(current_asmdata.CurrAsmList,OS_INT,0,hregister);
  143. cg.a_label(current_asmdata.CurrAsmList,hlabel);
  144. tcgarm(cg).cgsetflags:=true;
  145. cg.a_op_reg_reg(current_asmdata.CurrAsmList,OP_OR,OS_INT,hregister,hregister);
  146. tcgarm(cg).cgsetflags:=false;
  147. end;
  148. else
  149. internalerror(200311301);
  150. end;
  151. { load flags to register }
  152. location_reset(location,LOC_REGISTER,def_cgsize(resultdef));
  153. location.register:=cg.getintregister(current_asmdata.CurrAsmList,location.size);
  154. cg.g_flags2reg(current_asmdata.CurrAsmList,location.size,resflags,location.register);
  155. if (is_cbool(resultdef)) then
  156. cg.a_op_reg_reg(current_asmdata.CurrAsmList,OP_NEG,location.size,location.register,location.register);
  157. current_procinfo.CurrTrueLabel:=oldTrueLabel;
  158. current_procinfo.CurrFalseLabel:=oldFalseLabel;
  159. }
  160. end;
  161. begin
  162. ctypeconvnode:=tarmtypeconvnode;
  163. end.