ngppccnv.pas 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163
  1. {
  2. Copyright (c) 1998-2002 by Florian Klaempfl
  3. Generate PowerPC 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 ngppccnv;
  18. {$i fpcdefs.inc}
  19. interface
  20. uses
  21. node,ncnv,ncgcnv;
  22. type
  23. tgenppctypeconvnode = 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. { function first_int_to_real: tnode; override; }
  31. { procedure second_pointer_to_array;override; }
  32. { procedure second_chararray_to_string;override; }
  33. { procedure second_char_to_string;override; }
  34. { procedure second_int_to_real;override; }
  35. { procedure second_real_to_real;override; }
  36. { procedure second_cord_to_pointer;override; }
  37. { procedure second_proc_to_procvar;override; }
  38. { procedure second_bool_to_int;override; }
  39. procedure second_int_to_bool;override;
  40. { procedure second_load_smallset;override; }
  41. { procedure second_ansistring_to_pchar;override; }
  42. { procedure second_pchar_to_string;override; }
  43. { procedure second_class_to_intf;override; }
  44. { procedure second_char_to_char;override; }
  45. end;
  46. implementation
  47. uses
  48. verbose,globtype,globals,systems,
  49. symconst,symdef,aasmbase,aasmtai,aasmdata,
  50. defutil,
  51. cgbase,cgutils,pass_1,pass_2,
  52. ncgutil,procinfo,
  53. cpubase,aasmcpu,
  54. rgobj,tgobj,cgobj;
  55. procedure tgenppctypeconvnode.second_int_to_bool;
  56. var
  57. hreg1,
  58. hreg2 : tregister;
  59. {$ifndef cpu64bit}
  60. href : treference;
  61. {$endif not cpu64bit}
  62. resflags : tresflags;
  63. opsize : tcgsize;
  64. hlabel, oldTrueLabel, oldFalseLabel : tasmlabel;
  65. begin
  66. oldTrueLabel:=current_procinfo.CurrTrueLabel;
  67. oldFalseLabel:=current_procinfo.CurrFalseLabel;
  68. current_asmdata.getjumplabel(current_procinfo.CurrTrueLabel);
  69. current_asmdata.getjumplabel(current_procinfo.CurrFalseLabel);
  70. secondpass(left);
  71. if codegenerror then
  72. exit;
  73. { byte(boolean) or word(wordbool) or longint(longbool) must }
  74. { be accepted for var parameters }
  75. if (nf_explicit in flags) and
  76. (left.resultdef.size=resultdef.size) and
  77. (left.location.loc in [LOC_REFERENCE,LOC_CREFERENCE,LOC_CREGISTER]) then
  78. begin
  79. current_procinfo.CurrTrueLabel:=oldTrueLabel;
  80. current_procinfo.CurrFalseLabel:=oldFalseLabel;
  81. location_copy(location,left.location);
  82. exit;
  83. end;
  84. location_reset(location,LOC_REGISTER,def_cgsize(resultdef));
  85. opsize := def_cgsize(left.resultdef);
  86. case left.location.loc of
  87. LOC_CREFERENCE,LOC_REFERENCE,LOC_REGISTER,LOC_CREGISTER :
  88. begin
  89. if left.location.loc in [LOC_CREFERENCE,LOC_REFERENCE] then
  90. begin
  91. hreg1:=cg.getintregister(current_asmdata.CurrAsmList,OS_INT);
  92. {$ifndef cpu64bit}
  93. if left.location.size in [OS_64,OS_S64] then
  94. begin
  95. cg.a_load_ref_reg(current_asmdata.CurrAsmList,OS_INT,OS_INT,left.location.reference,hreg1);
  96. hreg2:=cg.getintregister(current_asmdata.CurrAsmList,OS_INT);
  97. href:=left.location.reference;
  98. inc(href.offset,4);
  99. cg.a_load_ref_reg(current_asmdata.CurrAsmList,OS_INT,OS_INT,href,hreg2);
  100. cg.a_op_reg_reg_reg(current_asmdata.CurrAsmList,OP_OR,OS_32,hreg1,hreg2,hreg1);
  101. end
  102. else
  103. {$endif not cpu64bit}
  104. cg.a_load_ref_reg(current_asmdata.CurrAsmList,opsize,opsize,left.location.reference,hreg1);
  105. end
  106. else
  107. begin
  108. {$ifndef cpu64bit}
  109. if left.location.size in [OS_64,OS_S64] then
  110. begin
  111. hreg1:=cg.getintregister(current_asmdata.CurrAsmList,OS_32);
  112. cg.a_op_reg_reg_reg(current_asmdata.CurrAsmList,OP_OR,OS_32,left.location.register64.reghi,left.location.register64.reglo,hreg1);
  113. end
  114. else
  115. {$endif not cpu64bit}
  116. hreg1 := left.location.register;
  117. end;
  118. hreg2 := cg.getintregister(current_asmdata.CurrAsmList,OS_INT);
  119. current_asmdata.CurrAsmList.concat(taicpu.op_reg_reg_const(A_SUBIC,hreg2,hreg1,1));
  120. current_asmdata.CurrAsmList.concat(taicpu.op_reg_reg_reg(A_SUBFE,hreg1,hreg2,hreg1));
  121. end;
  122. LOC_FLAGS :
  123. begin
  124. hreg1:=cg.getintregister(current_asmdata.CurrAsmList,OS_INT);
  125. resflags:=left.location.resflags;
  126. cg.g_flags2reg(current_asmdata.CurrAsmList,location.size,resflags,hreg1);
  127. end;
  128. LOC_JUMP :
  129. begin
  130. hreg1:=cg.getintregister(current_asmdata.CurrAsmList,OS_INT);
  131. current_asmdata.getjumplabel(hlabel);
  132. cg.a_label(current_asmdata.CurrAsmList,current_procinfo.CurrTrueLabel);
  133. cg.a_load_const_reg(current_asmdata.CurrAsmList,OS_INT,1,hreg1);
  134. cg.a_jmp_always(current_asmdata.CurrAsmList,hlabel);
  135. cg.a_label(current_asmdata.CurrAsmList,current_procinfo.CurrFalseLabel);
  136. cg.a_load_const_reg(current_asmdata.CurrAsmList,OS_INT,0,hreg1);
  137. cg.a_label(current_asmdata.CurrAsmList,hlabel);
  138. end;
  139. else
  140. internalerror(10062);
  141. end;
  142. location.register := hreg1;
  143. current_procinfo.CurrTrueLabel:=oldTrueLabel;
  144. current_procinfo.CurrFalseLabel:=oldFalseLabel;
  145. end;
  146. end.