summaryrefslogtreecommitdiff
path: root/compiler/z80/nz80mat.pas
blob: 446507726cd7d33e150c2c53f09d357cebe0e77f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
{
    Copyright (c) 1998-2002 by Florian Klaempfl

    Generate Z80 assembler for math nodes

    This program is free software; you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation; either version 2 of the License, or
    (at your option) any later version.

    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with this program; if not, write to the Free Software
    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.

 ****************************************************************************
}
unit nz80mat;

{$i fpcdefs.inc}

interface

    uses
      node,nmat,ncgmat;

    type

      { tz80notnode }

      tz80notnode = class(tcgnotnode)
      protected
        procedure second_boolean;override;
      end;


implementation

    uses
      globtype,systems,constexp,
      cutils,verbose,globals,
      symconst,symdef,aasmbase,aasmtai,aasmdata,aasmcpu,defutil,
      cgbase,pass_2,
      ncon,
      cpubase,cpuinfo,
      ncgutil,cgobj,cgutils,
      hlcgobj;

{*****************************************************************************
                                tz80notnode
*****************************************************************************}


    procedure tz80notnode.second_boolean;
      var
        i: Integer;
      begin
        if not handle_locjump then
          begin
            { the second pass could change the location of left }
            { if it is a register variable, so we've to do      }
            { this before the case statement                    }
            secondpass(left);

            if left.location.loc in [LOC_CREFERENCE,LOC_REFERENCE] then
              hlcg.location_force_reg(current_asmdata.CurrAsmList,left.location,left.resultdef,resultdef,false);
            case left.location.loc of
              LOC_FLAGS :
                begin
                  location_reset(location,LOC_FLAGS,OS_NO);
                  location.resflags:=left.location.resflags;
                  inverse_flags(location.resflags);
                end;
(*              LOC_CREFERENCE,
              LOC_REFERENCE:
                begin
 {$if defined(cpu32bitalu)}
                  if is_64bit(resultdef) then
                    begin
                      hreg:=cg.GetIntRegister(current_asmdata.CurrAsmList,OS_32);
                      tcgx86(cg).make_simple_ref(current_asmdata.CurrAsmList,left.location.reference);
                      cg.a_load_ref_reg(current_asmdata.CurrAsmList,OS_32,OS_32,left.location.reference,hreg);
                      inc(left.location.reference.offset,4);
                      cg.a_op_ref_reg(current_asmdata.CurrAsmList,OP_OR,OS_32,left.location.reference,hreg);
                    end
                  else
 {$elseif defined(cpu16bitalu)}
                  if is_64bit(resultdef) then
                    begin
                      hreg:=cg.GetIntRegister(current_asmdata.CurrAsmList,OS_16);
                      tcgx86(cg).make_simple_ref(current_asmdata.CurrAsmList,left.location.reference);
                      cg.a_load_ref_reg(current_asmdata.CurrAsmList,OS_16,OS_16,left.location.reference,hreg);
                      inc(left.location.reference.offset,2);
                      cg.a_op_ref_reg(current_asmdata.CurrAsmList,OP_OR,OS_16,left.location.reference,hreg);
                      inc(left.location.reference.offset,2);
                      cg.a_op_ref_reg(current_asmdata.CurrAsmList,OP_OR,OS_16,left.location.reference,hreg);
                      inc(left.location.reference.offset,2);
                      cg.a_op_ref_reg(current_asmdata.CurrAsmList,OP_OR,OS_16,left.location.reference,hreg);
                    end
                  else if is_32bit(resultdef) then
                    begin
                      hreg:=cg.GetIntRegister(current_asmdata.CurrAsmList,OS_16);
                      tcgx86(cg).make_simple_ref(current_asmdata.CurrAsmList,left.location.reference);
                      cg.a_load_ref_reg(current_asmdata.CurrAsmList,OS_16,OS_16,left.location.reference,hreg);
                      inc(left.location.reference.offset,2);
                      cg.a_op_ref_reg(current_asmdata.CurrAsmList,OP_OR,OS_16,left.location.reference,hreg);
                    end
                  else
 {$endif}
                    emit_const_ref(A_CMP, TCGSize2Opsize[opsize], 0, left.location.reference);
                  location_reset(location,LOC_FLAGS,OS_NO);
                  location.resflags:=F_E;
                end;*)
              LOC_CONSTANT,
              LOC_REGISTER,
              LOC_CREGISTER,
              LOC_SUBSETREG,
              LOC_CSUBSETREG,
              LOC_SUBSETREF,
              LOC_CSUBSETREF :
                begin
                  if tcgsize2size[def_cgsize(left.resultdef)]<>tcgsize2size[def_cgsize(resultdef)] then
                    internalerror(2020042209);
                  hlcg.location_force_reg(current_asmdata.CurrAsmList,left.location,left.resultdef,resultdef,false);
                  if tcgsize2size[def_cgsize(left.resultdef)]=1 then
                    begin
                      cg.getcpuregister(current_asmdata.CurrAsmList,NR_A);
                      cg.a_load_reg_reg(current_asmdata.CurrAsmList,OS_8,OS_8,left.location.register,NR_A);
                      current_asmdata.CurrAsmList.Concat(taicpu.op_reg_reg(A_OR,NR_A,NR_A));
                      cg.ungetcpuregister(current_asmdata.CurrAsmList,NR_A);
                    end
                  else
                    begin
                      cg.getcpuregister(current_asmdata.CurrAsmList,NR_A);
                      cg.a_load_reg_reg(current_asmdata.CurrAsmList,OS_8,OS_8,left.location.register,NR_A);
                      for i:=1 to tcgsize2size[def_cgsize(left.resultdef)]-1 do
                        current_asmdata.CurrAsmList.Concat(taicpu.op_reg_reg(A_OR,NR_A,cg.GetOffsetReg64(left.location.register,left.location.registerhi,i)));
                      cg.ungetcpuregister(current_asmdata.CurrAsmList,NR_A);
                    end;
                  location_reset(location,LOC_FLAGS,OS_NO);
                  location.resflags:=F_E;
                end;
              else
                internalerror(2020042208);
            end;
          end;
      end;


begin
   cnotnode:=tz80notnode;
end.