Added FuncCall op
[libfirm] / ir / ir / irop.c
1 /*
2  * Project:     libFIRM
3  * File name:   ir/ir/irop.c
4  * Purpose:     Representation of opcode of intermediate operation.
5  * Author:      Christian Schaefer
6  * Modified by: Goetz Lindenmaier
7  * Created:
8  * CVS-ID:      $Id$
9  * Copyright:   (c) 1998-2003 Universität Karlsruhe
10  * Licence:     This file protected by GPL -  GNU GENERAL PUBLIC LICENSE.
11  */
12
13 #ifdef HAVE_CONFIG_H
14 # include <config.h>
15 #endif
16
17 # include <string.h>
18
19 # include "irop_t.h"
20 # include "irnode_t.h"
21
22 # include "xmalloc.h"
23
24 ir_op *op_Block;           ir_op *get_op_Block     () { return op_Block;     }
25
26 ir_op *op_Start;           ir_op *get_op_Start     () { return op_Start;     }
27 ir_op *op_End;             ir_op *get_op_End       () { return op_End;       }
28 ir_op *op_Jmp;             ir_op *get_op_Jmp       () { return op_Jmp;       }
29 ir_op *op_Cond;            ir_op *get_op_Cond      () { return op_Cond;      }
30 ir_op *op_Return;          ir_op *get_op_Return    () { return op_Return;    }
31 ir_op *op_Raise;           ir_op *get_op_Raise     () { return op_Raise;     }
32
33 ir_op *op_Sel;             ir_op *get_op_Sel       () { return op_Sel;       }
34 ir_op *op_InstOf;          ir_op *get_op_InstOf    () { return op_InstOf;    }
35
36 ir_op *op_Const;           ir_op *get_op_Const     () { return op_Const;     }
37 ir_op *op_SymConst;        ir_op *get_op_SymConst  () { return op_SymConst;  }
38
39 ir_op *op_Call;            ir_op *get_op_Call      () { return op_Call;      }
40 ir_op *op_Add;             ir_op *get_op_Add       () { return op_Add;       }
41 ir_op *op_Sub;             ir_op *get_op_Sub       () { return op_Sub;       }
42 ir_op *op_Minus;           ir_op *get_op_Minus     () { return op_Minus;     }
43 ir_op *op_Mul;             ir_op *get_op_Mul       () { return op_Mul;       }
44 ir_op *op_Quot;            ir_op *get_op_Quot      () { return op_Quot;      }
45 ir_op *op_DivMod;          ir_op *get_op_DivMod    () { return op_DivMod;    }
46 ir_op *op_Div;             ir_op *get_op_Div       () { return op_Div;       }
47 ir_op *op_Mod;             ir_op *get_op_Mod       () { return op_Mod;       }
48 ir_op *op_Abs;             ir_op *get_op_Abs       () { return op_Abs;       }
49 ir_op *op_And;             ir_op *get_op_And       () { return op_And;       }
50 ir_op *op_Or;              ir_op *get_op_Or        () { return op_Or;        }
51 ir_op *op_Eor;             ir_op *get_op_Eor       () { return op_Eor;       }
52 ir_op *op_Not;             ir_op *get_op_Not       () { return op_Not;       }
53 ir_op *op_Cmp;             ir_op *get_op_Cmp       () { return op_Cmp;       }
54 ir_op *op_Shl;             ir_op *get_op_Shl       () { return op_Shl;       }
55 ir_op *op_Shr;             ir_op *get_op_Shr       () { return op_Shr;       }
56 ir_op *op_Shrs;            ir_op *get_op_Shrs      () { return op_Shrs;      }
57 ir_op *op_Rot;             ir_op *get_op_Rot       () { return op_Rot;       }
58 ir_op *op_Conv;            ir_op *get_op_Conv      () { return op_Conv;      }
59 ir_op *op_Cast;            ir_op *get_op_Cast      () { return op_Cast;      }
60
61 ir_op *op_Phi;             ir_op *get_op_Phi       () { return op_Phi;       }
62
63 ir_op *op_Load;            ir_op *get_op_Load      () { return op_Load;      }
64 ir_op *op_Store;           ir_op *get_op_Store     () { return op_Store;     }
65 ir_op *op_Alloc;           ir_op *get_op_Alloc     () { return op_Alloc;     }
66 ir_op *op_Free;            ir_op *get_op_Free      () { return op_Free;      }
67 ir_op *op_Sync;            ir_op *get_op_Sync      () { return op_Sync;      }
68
69 ir_op *op_Tuple;           ir_op *get_op_Tuple     () { return op_Tuple;     }
70 ir_op *op_Proj;            ir_op *get_op_Proj      () { return op_Proj;      }
71 ir_op *op_Id;              ir_op *get_op_Id        () { return op_Id;        }
72 ir_op *op_Bad;             ir_op *get_op_Bad       () { return op_Bad;       }
73 ir_op *op_Confirm;         ir_op *get_op_Confirm   () { return op_Confirm;   }
74
75 ir_op *op_Unknown;         ir_op *get_op_Unknown   () { return op_Unknown;   }
76 ir_op *op_Filter;          ir_op *get_op_Filter    () { return op_Filter;    }
77 ir_op *op_Break;           ir_op *get_op_Break     () { return op_Break;     }
78 ir_op *op_CallBegin;       ir_op *get_op_CallBegin () { return op_CallBegin; }
79 ir_op *op_EndReg;          ir_op *get_op_EndReg    () { return op_EndReg;    }
80 ir_op *op_EndExcept;       ir_op *get_op_EndExcept () { return op_EndExcept; }
81
82 ir_op *op_FuncCall;        ir_op *get_op_FuncCall  () { return op_FuncCall; }
83
84
85 ir_op *
86 new_ir_op (opcode code, const char *name, op_pinned p, int labeled, size_t attr_size)
87 {
88   ir_op *res;
89
90   res = (ir_op *) xmalloc (sizeof (ir_op));
91   res->code = code;
92   res->name = id_from_str(name, strlen(name));
93   res->pinned = p;
94   res->attr_size = attr_size;
95   res->labeled = labeled;   /* For vcg dumping.
96                                Set labeled = 1 if the edges should be
97                                enumarated in vcg output, otherwise set
98                                labeled = 0. */
99   return res;
100 }
101
102
103 void
104 init_op(void)
105 {
106   op_Block     = new_ir_op (iro_Block,     "Block",     pinned, 1, sizeof (block_attr));
107
108   op_Start     = new_ir_op (iro_Start,     "Start",     pinned, 0, sizeof (start_attr));
109   op_End       = new_ir_op (iro_End,       "End",       pinned, 0, 0);
110   op_Jmp       = new_ir_op (iro_Jmp,       "Jmp",       pinned, 0, 0);
111   op_Cond      = new_ir_op (iro_Cond,      "Cond",      pinned, 1, sizeof(cond_attr));
112   op_Return    = new_ir_op (iro_Return,    "Return",    pinned, 1, 0);
113   op_Raise     = new_ir_op (iro_Raise,     "Raise",     pinned, 1, 0);
114
115   op_Const     = new_ir_op (iro_Const,     "Const",     floats, 0, sizeof (const_attr));
116   op_SymConst  = new_ir_op (iro_SymConst,  "SymConst",  floats, 0, sizeof (symconst_attr));
117
118   op_Sel       = new_ir_op (iro_Sel,       "Sel",       floats, 1, sizeof (sel_attr));
119   op_InstOf    = new_ir_op (iro_InstOf,    "InstOf",    floats, 1, sizeof (sel_attr));
120
121   op_Call      = new_ir_op (iro_Call,      "Call",      pinned, 1, sizeof (call_attr));
122   op_Add       = new_ir_op (iro_Add,       "Add",       floats, 0, 0);
123   op_Minus     = new_ir_op (iro_Minus,     "Minus",     floats, 0, 0);
124   op_Sub       = new_ir_op (iro_Sub,       "Sub",       floats, 1, 0);
125   op_Mul       = new_ir_op (iro_Mul,       "Mul",       floats, 0, 0);
126   op_Quot      = new_ir_op (iro_Quot,      "Quot",      pinned, 1, sizeof(struct irnode **));
127   op_DivMod    = new_ir_op (iro_DivMod,    "DivMod",    pinned, 1, sizeof(struct irnode **));
128   op_Div       = new_ir_op (iro_Div,       "Div",       pinned, 1, sizeof(struct irnode **));
129   op_Mod       = new_ir_op (iro_Mod,       "Mod",       pinned, 1, sizeof(struct irnode **));
130   op_Abs       = new_ir_op (iro_Abs,       "Abs",       floats, 0, 0);
131   op_And       = new_ir_op (iro_And,       "And",       floats, 0, 0);
132   op_Or        = new_ir_op (iro_Or,        "Or",        floats, 0, 0);
133   op_Eor       = new_ir_op (iro_Eor,       "Eor",       floats, 0, 0);
134   op_Not       = new_ir_op (iro_Not,       "Not",       floats, 0, 0);
135   op_Cmp       = new_ir_op (iro_Cmp,       "Cmp",       floats, 1, 0);
136   op_Shl       = new_ir_op (iro_Shl,       "Shl",       floats, 1, 0);
137   op_Shr       = new_ir_op (iro_Shr,       "Shr",       floats, 1, 0);
138   op_Shrs      = new_ir_op (iro_Shrs,      "Shrs",      floats, 1, 0);
139   op_Rot       = new_ir_op (iro_Rot,       "Rot",       floats, 1, 0);
140   op_Conv      = new_ir_op (iro_Conv,      "Conv",      floats, 0, 0);
141   op_Cast      = new_ir_op (iro_Cast,      "Cast",      floats, 0, sizeof (cast_attr));
142
143   op_Phi       = new_ir_op (iro_Phi,       "Phi",       pinned, 1, sizeof (int));
144
145   op_Load      = new_ir_op (iro_Load,      "Load",      pinned, 1, sizeof(struct irnode **));
146   op_Store     = new_ir_op (iro_Store,     "Store",     pinned, 1, sizeof(struct irnode **));
147   op_Alloc     = new_ir_op (iro_Alloc,     "Alloc",     pinned, 1, sizeof (alloc_attr));
148   op_Free      = new_ir_op (iro_Free,      "Free",      pinned, 1, sizeof (type *));
149   op_Sync      = new_ir_op (iro_Sync,      "Sync",      pinned, 0, 0);
150
151   op_Proj      = new_ir_op (iro_Proj,      "Proj",      floats, 0, sizeof (long));
152   op_Tuple     = new_ir_op (iro_Tuple,     "Tuple",     floats, 1, 0);
153   op_Id        = new_ir_op (iro_Id,        "Id",        floats, 0, 0);
154   op_Bad       = new_ir_op (iro_Bad,       "Bad",       floats, 0, 0);
155   op_Confirm   = new_ir_op (iro_Confirm,   "Confirm",   floats, 1, sizeof (confirm_attr));
156
157   op_Unknown   = new_ir_op (iro_Unknown,   "Unknown",   floats, 0, 0);
158   op_Filter    = new_ir_op (iro_Filter,    "Filter",    pinned, 1, sizeof(filter_attr));
159   op_Break     = new_ir_op (iro_Break,     "Break",     pinned, 0, 0);
160   op_CallBegin = new_ir_op (iro_CallBegin, "CallBegin", pinned, 0, sizeof(callbegin_attr));
161   op_EndReg    = new_ir_op (iro_EndReg,    "EndReg",    pinned, 0, sizeof(end_attr));
162   op_EndExcept = new_ir_op (iro_EndExcept, "EndExcept", pinned, 0, sizeof(end_attr));
163
164   op_FuncCall  = new_ir_op (iro_FuncCall,  "FuncCall",  floats, 1, sizeof (call_attr));
165 }
166
167 /* Returns the string for the opcode. */
168 const char *get_op_name (const ir_op *op) {
169   return get_id_str(op->name);
170 }
171
172 opcode get_op_code (const ir_op *op){
173   return op->code;
174 }
175
176 ident *get_op_ident(ir_op *op){
177   return op->name;
178 }
179
180 op_pinned get_op_pinned (const ir_op *op){
181   return op->pinned;
182 }
183
184 /* Sets pinned in the opcode.  Setting it to floating has no effect
185    for Phi, Block and control flow nodes. */
186 void      set_op_pinned(ir_op *op, op_pinned pinned) {
187   if (op == op_Block || op == op_Phi || is_cfopcode(op)) return;
188   op->pinned = pinned;
189 }
190
191
192 /* returns the attribute size of the operator. */
193 int get_op_attr_size (const ir_op *op) {
194   return op->attr_size;
195 }
196
197 int is_cfopcode(const ir_op *op) {
198   return ((op == op_Start)
199           || (op == op_Jmp)
200           || (op == op_Cond)
201           || (op == op_Return)
202           || (op == op_Raise)
203           || (op == op_Bad)
204           || (op == op_End)
205           || (op == op_Unknown)
206           || (op == op_Break)
207           || (op == op_CallBegin)
208           || (op == op_EndReg)
209           || (op == op_EndExcept));
210 }
211
212 /* Returns true if the operation manipulates interprocedural control flow:
213    CallBegin, EndReg, EndExcept */
214 int is_ip_cfopcode(const ir_op *op) {
215   return ((op == op_CallBegin)
216           || (op == op_EndReg)
217           || (op == op_EndExcept));
218 }