nz80mat.pas 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156
  1. {
  2. Copyright (c) 1998-2002 by Florian Klaempfl
  3. Generate Z80 assembler for math 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 nz80mat;
  18. {$i fpcdefs.inc}
  19. interface
  20. uses
  21. node,nmat,ncgmat;
  22. type
  23. { tz80notnode }
  24. tz80notnode = class(tcgnotnode)
  25. protected
  26. procedure second_boolean;override;
  27. end;
  28. implementation
  29. uses
  30. globtype,systems,constexp,
  31. cutils,verbose,globals,
  32. symconst,symdef,aasmbase,aasmtai,aasmdata,aasmcpu,defutil,
  33. cgbase,pass_2,
  34. ncon,
  35. cpubase,cpuinfo,
  36. ncgutil,cgobj,cgutils,
  37. hlcgobj;
  38. {*****************************************************************************
  39. tz80notnode
  40. *****************************************************************************}
  41. procedure tz80notnode.second_boolean;
  42. var
  43. i: Integer;
  44. begin
  45. if not handle_locjump then
  46. begin
  47. { the second pass could change the location of left }
  48. { if it is a register variable, so we've to do }
  49. { this before the case statement }
  50. secondpass(left);
  51. if left.location.loc in [LOC_CREFERENCE,LOC_REFERENCE] then
  52. hlcg.location_force_reg(current_asmdata.CurrAsmList,left.location,left.resultdef,resultdef,false);
  53. case left.location.loc of
  54. LOC_FLAGS :
  55. begin
  56. location_reset(location,LOC_FLAGS,OS_NO);
  57. location.resflags:=left.location.resflags;
  58. inverse_flags(location.resflags);
  59. end;
  60. (* LOC_CREFERENCE,
  61. LOC_REFERENCE:
  62. begin
  63. {$if defined(cpu32bitalu)}
  64. if is_64bit(resultdef) then
  65. begin
  66. hreg:=cg.GetIntRegister(current_asmdata.CurrAsmList,OS_32);
  67. tcgx86(cg).make_simple_ref(current_asmdata.CurrAsmList,left.location.reference);
  68. cg.a_load_ref_reg(current_asmdata.CurrAsmList,OS_32,OS_32,left.location.reference,hreg);
  69. inc(left.location.reference.offset,4);
  70. cg.a_op_ref_reg(current_asmdata.CurrAsmList,OP_OR,OS_32,left.location.reference,hreg);
  71. end
  72. else
  73. {$elseif defined(cpu16bitalu)}
  74. if is_64bit(resultdef) then
  75. begin
  76. hreg:=cg.GetIntRegister(current_asmdata.CurrAsmList,OS_16);
  77. tcgx86(cg).make_simple_ref(current_asmdata.CurrAsmList,left.location.reference);
  78. cg.a_load_ref_reg(current_asmdata.CurrAsmList,OS_16,OS_16,left.location.reference,hreg);
  79. inc(left.location.reference.offset,2);
  80. cg.a_op_ref_reg(current_asmdata.CurrAsmList,OP_OR,OS_16,left.location.reference,hreg);
  81. inc(left.location.reference.offset,2);
  82. cg.a_op_ref_reg(current_asmdata.CurrAsmList,OP_OR,OS_16,left.location.reference,hreg);
  83. inc(left.location.reference.offset,2);
  84. cg.a_op_ref_reg(current_asmdata.CurrAsmList,OP_OR,OS_16,left.location.reference,hreg);
  85. end
  86. else if is_32bit(resultdef) then
  87. begin
  88. hreg:=cg.GetIntRegister(current_asmdata.CurrAsmList,OS_16);
  89. tcgx86(cg).make_simple_ref(current_asmdata.CurrAsmList,left.location.reference);
  90. cg.a_load_ref_reg(current_asmdata.CurrAsmList,OS_16,OS_16,left.location.reference,hreg);
  91. inc(left.location.reference.offset,2);
  92. cg.a_op_ref_reg(current_asmdata.CurrAsmList,OP_OR,OS_16,left.location.reference,hreg);
  93. end
  94. else
  95. {$endif}
  96. emit_const_ref(A_CMP, TCGSize2Opsize[opsize], 0, left.location.reference);
  97. location_reset(location,LOC_FLAGS,OS_NO);
  98. location.resflags:=F_E;
  99. end;*)
  100. LOC_CONSTANT,
  101. LOC_REGISTER,
  102. LOC_CREGISTER,
  103. LOC_SUBSETREG,
  104. LOC_CSUBSETREG,
  105. LOC_SUBSETREF,
  106. LOC_CSUBSETREF :
  107. begin
  108. if tcgsize2size[def_cgsize(left.resultdef)]<>tcgsize2size[def_cgsize(resultdef)] then
  109. internalerror(2020042209);
  110. hlcg.location_force_reg(current_asmdata.CurrAsmList,left.location,left.resultdef,resultdef,false);
  111. if tcgsize2size[def_cgsize(left.resultdef)]=1 then
  112. begin
  113. cg.getcpuregister(current_asmdata.CurrAsmList,NR_A);
  114. cg.a_load_reg_reg(current_asmdata.CurrAsmList,OS_8,OS_8,left.location.register,NR_A);
  115. current_asmdata.CurrAsmList.Concat(taicpu.op_reg_reg(A_OR,NR_A,NR_A));
  116. cg.ungetcpuregister(current_asmdata.CurrAsmList,NR_A);
  117. end
  118. else
  119. begin
  120. cg.getcpuregister(current_asmdata.CurrAsmList,NR_A);
  121. cg.a_load_reg_reg(current_asmdata.CurrAsmList,OS_8,OS_8,left.location.register,NR_A);
  122. for i:=1 to tcgsize2size[def_cgsize(left.resultdef)]-1 do
  123. current_asmdata.CurrAsmList.Concat(taicpu.op_reg_reg(A_OR,NR_A,cg.GetOffsetReg64(left.location.register,left.location.registerhi,i)));
  124. cg.ungetcpuregister(current_asmdata.CurrAsmList,NR_A);
  125. end;
  126. location_reset(location,LOC_FLAGS,OS_NO);
  127. location.resflags:=F_E;
  128. end;
  129. else
  130. internalerror(2020042208);
  131. end;
  132. end;
  133. end;
  134. begin
  135. cnotnode:=tz80notnode;
  136. end.