[PATCH] evaluate_sign() typo
[smatch.git] / linearize.h
blob003cf7f7addbf2c5448c38cedc7b9f243615e3b2
1 #ifndef LINEARIZE_H
2 #define LINEARIZE_H
4 #include "lib.h"
5 #include "token.h"
6 #include "parse.h"
7 #include "symbol.h"
9 /* Silly pseudo define. Do this right some day */
10 struct pseudo {
11 int nr;
14 typedef struct pseudo *pseudo_t;
16 extern struct pseudo void_pseudo;
18 #define VOID (&void_pseudo)
20 struct multijmp {
21 struct basic_block *target;
22 int begin, end;
25 struct phi {
26 struct basic_block *source;
27 pseudo_t pseudo;
30 struct instruction {
31 struct symbol *type;
32 int opcode;
33 union {
34 pseudo_t target;
35 pseudo_t cond; /* for branch and switch */
37 union {
38 struct /* branch */ {
39 struct basic_block *bb_true, *bb_false;
41 struct /* switch */ {
42 struct multijmp_list *multijmp_list;
44 struct /* phi_node */ {
45 struct phi_list *phi_list;
47 struct /* unops */ {
48 struct symbol *orig_type; /* casts */
49 pseudo_t src;
51 struct /* binops */ {
52 pseudo_t src1, src2;
54 struct /* slice */ {
55 pseudo_t base;
56 unsigned from, len;
58 struct /* multijump */ {
59 int begin, end;
61 struct /* setval */ {
62 struct expression *val;
64 struct /* call */ {
65 pseudo_t func;
66 struct pseudo_list *arguments;
71 enum opcode {
72 OP_BADOP,
73 /* Terminator */
74 OP_TERMINATOR,
75 OP_RET = OP_TERMINATOR,
76 OP_BR,
77 OP_SWITCH,
78 OP_INVOKE,
79 OP_COMPUTEDGOTO,
80 OP_UNWIND,
81 OP_TERMINATOR_END = OP_UNWIND,
83 /* Binary */
84 OP_BINARY,
85 OP_ADD = OP_BINARY,
86 OP_SUB,
87 OP_MUL,
88 OP_DIV,
89 OP_MOD,
90 OP_SHL,
91 OP_SHR,
92 OP_SEL,
94 /* Logical */
95 OP_AND,
96 OP_OR,
97 OP_XOR,
98 OP_AND_BOOL,
99 OP_OR_BOOL,
100 OP_BINARY_END = OP_OR_BOOL,
102 /* Binary comparison */
103 OP_BINCMP,
104 OP_SET_EQ = OP_BINCMP,
105 OP_SET_NE,
106 OP_SET_LE,
107 OP_SET_GE,
108 OP_SET_LT,
109 OP_SET_GT,
110 OP_SET_B,
111 OP_SET_A,
112 OP_SET_BE,
113 OP_SET_AE,
114 OP_BINCMP_END = OP_SET_AE,
116 /* Uni */
117 OP_NOT,
118 OP_NEG,
120 /* Setcc - always in combination with a select or conditional branch */
121 OP_SETCC,
123 /* Memory */
124 OP_MALLOC,
125 OP_FREE,
126 OP_ALLOCA,
127 OP_LOAD,
128 OP_STORE,
129 OP_SETVAL,
130 OP_GET_ELEMENT_PTR,
132 /* Other */
133 OP_PHI,
134 OP_CAST,
135 OP_CALL,
136 OP_VANEXT,
137 OP_VAARG,
138 OP_SLICE,
141 struct basic_block_list;
142 struct instruction_list;
145 * Basic block flags. Right now we only have one, which keeps
146 * track (at build time) whether the basic block has been branched
147 * out of yet.
149 #define BB_REACHABLE 0x00000001
151 struct basic_block {
152 unsigned long flags; /* BB status flags */
153 struct basic_block_list *parents; /* sources */
154 struct instruction_list *insns; /* Linear list of instructions */
157 static inline int is_branch_goto(struct instruction *br)
159 return br && br->opcode==OP_BR && (!br->bb_true || !br->bb_false);
162 static inline void add_bb(struct basic_block_list **list, struct basic_block *bb)
164 add_ptr_list((struct ptr_list **)list, bb);
167 static inline void add_instruction(struct instruction_list **list, struct instruction *insn)
169 add_ptr_list((struct ptr_list **)list, insn);
172 static inline void add_multijmp(struct multijmp_list **list, struct multijmp *multijmp)
174 add_ptr_list((struct ptr_list **)list, multijmp);
177 static inline void add_phi(struct phi_list **list, struct phi *phi)
179 add_ptr_list((struct ptr_list **)list, phi);
182 static inline void add_pseudo(struct pseudo_list **list, struct pseudo *pseudo)
184 add_ptr_list((struct ptr_list **)list, pseudo);
188 static inline int bb_terminated(struct basic_block *bb)
190 struct instruction *insn;
191 if (!bb)
192 return 0;
193 insn = last_instruction(bb->insns);
194 return insn && insn->opcode >= OP_RET && insn->opcode <= OP_UNWIND;
197 static inline int bb_reachable(struct basic_block *bb)
199 return bb && (bb->parents || (bb->flags & BB_REACHABLE));
202 struct entrypoint {
203 struct symbol *name;
204 struct symbol_list *syms;
205 struct basic_block_list *bbs;
206 struct basic_block *active;
209 struct entrypoint *linearize_symbol(struct symbol *sym);
210 void show_entry(struct entrypoint *ep);
212 #endif /* LINEARIZE_H */