1 {
2     Copyright (c) 1998-2002 by Florian Klaempfl
3 
4     Helper routines for the i386 code generator
5 
6     This program is free software; you can redistribute it and/or modify
7     it under the terms of the GNU General Public License as published by
8     the Free Software Foundation; either version 2 of the License, or
9     (at your option) any later version.
10 
11     This program is distributed in the hope that it will be useful,
12     but WITHOUT ANY WARRANTY; without even the implied warranty of
13     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14     GNU General Public License for more details.
15 
16     You should have received a copy of the GNU General Public License
17     along with this program; if not, write to the Free Software
18     Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
19 
20  ****************************************************************************
21 }
22 
23 unit cga;
24 
25 {$i fpcdefs.inc}
26 
27 interface
28 
29     uses
30        globtype,
31        cpubase,cgbase,cgutils,
32        aasmbase,aasmdata,aasmcpu;
33 
34     procedure emit_none(i : tasmop;s : topsize);
35 
36     procedure emit_reg(i : tasmop;s : topsize;reg : tregister);
37     procedure emit_ref(i : tasmop;s : topsize;ref : treference);
38 
39     procedure emit_const_reg(i : tasmop;s : topsize;c : aint;reg : tregister);
40     procedure emit_const_ref(i : tasmop;s : topsize;c : aint;ref : treference);
41     procedure emit_ref_reg(i : tasmop;s : topsize;ref : treference;reg : tregister);
42     procedure emit_reg_ref(i : tasmop;s : topsize;reg : tregister;ref : treference);
43     procedure emit_reg_reg(i : tasmop;s : topsize;reg1,reg2 : tregister);
44 
45     procedure emit_const_reg_reg(i : tasmop;s : topsize;c : longint;reg1,reg2 : tregister);
46     procedure emit_reg_reg_reg(i : tasmop;s : topsize;reg1,reg2,reg3 : tregister);
47     procedure emit_ref_reg_reg(i : tasmop;s : topsize;ref : treference;reg1,reg2 : tregister);
48 
49 
50     procedure emit_sym(i : tasmop;s : topsize;op : tasmsymbol);
51 
52 
53 implementation
54 
55     uses
56        verbose,
57        cgobj,cgx86;
58 
59 
60 {*****************************************************************************
61                               Emit Assembler
62 *****************************************************************************}
63 
64     procedure emit_none(i : tasmop;s : topsize);
65       begin
66          current_asmdata.CurrAsmList.concat(Taicpu.Op_none(i,s));
67       end;
68 
69     procedure emit_reg(i : tasmop;s : topsize;reg : tregister);
70       begin
71          current_asmdata.CurrAsmList.concat(Taicpu.Op_reg(i,s,reg));
72       end;
73 
74     procedure emit_ref(i : tasmop;s : topsize;ref : treference);
75       begin
76         tcgx86(cg).make_simple_ref(current_asmdata.CurrAsmList,ref);
77         current_asmdata.CurrAsmList.concat(Taicpu.Op_ref(i,s,ref));
78       end;
79 
80     procedure emit_const_reg(i : tasmop;s : topsize;c : aint;reg : tregister);
81       begin
82          current_asmdata.CurrAsmList.concat(Taicpu.Op_const_reg(i,s,c,reg));
83       end;
84 
85     procedure emit_const_ref(i : tasmop;s : topsize;c : aint;ref : treference);
86       begin
87         tcgx86(cg).make_simple_ref(current_asmdata.CurrAsmList,ref);
88         current_asmdata.CurrAsmList.concat(Taicpu.Op_const_ref(i,s,c,ref));
89       end;
90 
91     procedure emit_ref_reg(i : tasmop;s : topsize;ref : treference;reg : tregister);
92       begin
93         tcgx86(cg).make_simple_ref(current_asmdata.CurrAsmList,ref);
94         current_asmdata.CurrAsmList.concat(Taicpu.Op_ref_reg(i,s,ref,reg));
95       end;
96 
97     procedure emit_reg_ref(i : tasmop;s : topsize;reg : tregister;ref : treference);
98       begin
99         tcgx86(cg).make_simple_ref(current_asmdata.CurrAsmList,ref);
100         current_asmdata.CurrAsmList.concat(Taicpu.Op_reg_ref(i,s,reg,ref));
101       end;
102 
103     procedure emit_reg_reg(i : tasmop;s : topsize;reg1,reg2 : tregister);
104 
105     var instr:Taicpu;
106 
107     begin
108       if not ((reg1=reg2) and (i=A_MOV)) then
109         begin
110           instr:=Taicpu.op_reg_reg(i,s,reg1,reg2);
111           current_asmdata.CurrAsmList.concat(instr);
112           if i=A_MOV then
113             cg.add_move_instruction(instr);
114         end;
115     end;
116 
117     procedure emit_const_reg_reg(i : tasmop;s : topsize;c : longint;reg1,reg2 : tregister);
118       begin
119          current_asmdata.CurrAsmList.concat(Taicpu.Op_const_reg_reg(i,s,c,reg1,reg2));
120       end;
121 
122     procedure emit_reg_reg_reg(i : tasmop;s : topsize;reg1,reg2,reg3 : tregister);
123       begin
124          current_asmdata.CurrAsmList.concat(Taicpu.Op_reg_reg_reg(i,s,reg1,reg2,reg3));
125       end;
126 
127     procedure emit_ref_reg_reg(i : tasmop;s : topsize;ref : treference;reg1,reg2 : tregister);
128       begin
129         tcgx86(cg).make_simple_ref(current_asmdata.CurrAsmList,ref);
130         current_asmdata.CurrAsmList.concat(Taicpu.Op_ref_reg_reg(i,s,ref,reg1,reg2));
131       end;
132 
133     procedure emit_sym(i : tasmop;s : topsize;op : tasmsymbol);
134       begin
135         current_asmdata.CurrAsmList.concat(Taicpu.Op_sym(i,s,op));
136       end;
137 
138 end.
139