[PATCH] treat `enum opcode' as enumeration rather than int

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



This change also required a move of `struct instruction' below
`enum opcode' due to new dependency and a default case to the switch
in `opcode_sign' to suppress compiler warnings about unhandled enumeration
values.

Signed-off-by: Jan Pokorny <pokorny_jan@xxxxxxxxx>
---
 example.c   |   13 +++---
 flow.c      |    4 +-
 linearize.c |   31 ++++++++-------
 linearize.h |  124 +++++++++++++++++++++++++++++-----------------------------
 simplify.c  |    4 +-
 5 files changed, 90 insertions(+), 86 deletions(-)

diff --git a/example.c b/example.c
index 24444c6..b38e1e7 100644
--- a/example.c
+++ b/example.c
@@ -142,7 +142,8 @@ struct bb_state {
 	struct storage_hash_list *internal;
 
 	/* CC cache.. */
-	int cc_opcode, cc_dead;
+	enum opcode cc_opcode;
+	int cc_dead;
 	pseudo_t cc_target;
 };
 
@@ -552,9 +553,9 @@ static void flush_pseudo(struct bb_state *state, pseudo_t pseudo, struct storage
 
 static void flush_cc_cache_to_reg(struct bb_state *state, pseudo_t pseudo, struct hardreg *reg)
 {
-	int opcode = state->cc_opcode;
+	enum opcode opcode = state->cc_opcode;
 
-	state->cc_opcode = 0;
+	state->cc_opcode = OP_BADOP;
 	state->cc_target = NULL;
 	output_insn(state, "%s %s", opcodes[opcode], reg->name);
 }
@@ -575,7 +576,7 @@ static void flush_cc_cache(struct bb_state *state)
 	}
 }
 
-static void add_cc_cache(struct bb_state *state, int opcode, pseudo_t pseudo)
+static void add_cc_cache(struct bb_state *state, enum opcode opcode, pseudo_t pseudo)
 {
 	assert(!state->cc_target);
 	state->cc_target = pseudo;
@@ -1346,7 +1347,7 @@ static void generate_compare(struct bb_state *state, struct instruction *insn)
 {
 	struct hardreg *src;
 	const char *src2;
-	int opcode;
+	enum opcode opcode;
 
 	flush_cc_cache(state);
 	opcode = insn->opcode;
@@ -1772,7 +1773,7 @@ static void output_bb(struct basic_block *bb, unsigned long generation)
 	state.inputs = gather_storage(bb, STOR_IN);
 	state.outputs = gather_storage(bb, STOR_OUT);
 	state.internal = NULL;
-	state.cc_opcode = 0;
+	state.cc_opcode = OP_BADOP;
 	state.cc_target = NULL;
 
 	/* Mark incoming registers used */
diff --git a/flow.c b/flow.c
index 5bd9a1d..3687207 100644
--- a/flow.c
+++ b/flow.c
@@ -291,7 +291,7 @@ static inline int same_memop(struct instruction *a, struct instruction *b)
  */
 int dominates(pseudo_t pseudo, struct instruction *insn, struct instruction *dom, int local)
 {
-	int opcode = dom->opcode;
+	enum opcode opcode = dom->opcode;
 
 	if (opcode == OP_CALL || opcode == OP_ENTRY)
 		return local ? 0 : -1;
@@ -495,7 +495,7 @@ static void kill_dead_stores(pseudo_t pseudo, unsigned long generation, struct b
 		return;
 	bb->generation = generation;
 	FOR_EACH_PTR_REVERSE(bb->insns, insn) {
-		int opcode = insn->opcode;
+		enum opcode opcode = insn->opcode;
 
 		if (opcode != OP_LOAD && opcode != OP_STORE) {
 			if (local)
diff --git a/linearize.c b/linearize.c
index f2034ce..5819862 100644
--- a/linearize.c
+++ b/linearize.c
@@ -25,7 +25,7 @@
 pseudo_t linearize_statement(struct entrypoint *ep, struct statement *stmt);
 pseudo_t linearize_expression(struct entrypoint *ep, struct expression *expr);
 
-static pseudo_t add_binary_op(struct entrypoint *ep, struct symbol *ctype, int op, pseudo_t left, pseudo_t right);
+static pseudo_t add_binary_op(struct entrypoint *ep, struct symbol *ctype, enum opcode op, pseudo_t left, pseudo_t right);
 static pseudo_t add_setval(struct entrypoint *ep, struct symbol *ctype, struct expression *val);
 static pseudo_t linearize_one_symbol(struct entrypoint *ep, struct symbol *sym);
 
@@ -39,7 +39,7 @@ static struct position current_pos;
 
 ALLOCATOR(pseudo_user, "pseudo_user");
 
-static struct instruction *alloc_instruction(int opcode, int size)
+static struct instruction *alloc_instruction(enum opcode opcode, int size)
 {
 	struct instruction * insn = __alloc_instruction(0);
 	insn->opcode = opcode;
@@ -53,7 +53,7 @@ static inline int type_size(struct symbol *type)
 	return type ? type->bit_size > 0 ? type->bit_size : 0 : 0;
 }
 
-static struct instruction *alloc_typed_instruction(int opcode, struct symbol *type)
+static struct instruction *alloc_typed_instruction(enum opcode opcode, struct symbol *type)
 {
 	struct instruction *insn = alloc_instruction(opcode, type_size(type));
 	insn->type = type;
@@ -274,7 +274,7 @@ static char *show_asm(char *buf, struct instruction *insn)
 
 const char *show_instruction(struct instruction *insn)
 {
-	int opcode = insn->opcode;
+	enum opcode opcode = insn->opcode;
 	static char buffer[4096];
 	char *buf;
 
@@ -956,7 +956,7 @@ static pseudo_t linearize_store_gen(struct entrypoint *ep,
 	return value;
 }
 
-static pseudo_t add_binary_op(struct entrypoint *ep, struct symbol *ctype, int op, pseudo_t left, pseudo_t right)
+static pseudo_t add_binary_op(struct entrypoint *ep, struct symbol *ctype, enum opcode op, pseudo_t left, pseudo_t right)
 {
 	struct instruction *insn = alloc_typed_instruction(op, ctype);
 	pseudo_t target = alloc_pseudo(insn);
@@ -1018,7 +1018,7 @@ static pseudo_t linearize_inc_dec(struct entrypoint *ep, struct expression *expr
 {
 	struct access_data ad = { NULL, };
 		pseudo_t old, new, one;
-	int op = expr->op == SPECIAL_INCREMENT ? OP_ADD : OP_SUB;
+	enum opcode op = expr->op == SPECIAL_INCREMENT ? OP_ADD : OP_SUB;
 
 	if (!linearize_address_gen(ep, expr->unop, &ad))
 		return VOID;
@@ -1031,7 +1031,7 @@ static pseudo_t linearize_inc_dec(struct entrypoint *ep, struct expression *expr
 	return postop ? old : new;
 }
 
-static pseudo_t add_uniop(struct entrypoint *ep, struct expression *expr, int op, pseudo_t src)
+static pseudo_t add_uniop(struct entrypoint *ep, struct expression *expr, enum opcode op, pseudo_t src)
 {
 	struct instruction *insn = alloc_typed_instruction(op, expr->ctype);
 	pseudo_t new = alloc_pseudo(insn);
@@ -1101,7 +1101,7 @@ static pseudo_t linearize_postop(struct entrypoint *ep, struct expression *expr)
  */
 static struct instruction *alloc_cast_instruction(struct symbol *src, struct symbol *ctype)
 {
-	int opcode = OP_CAST;
+	enum opcode opcode = OP_CAST;
 	struct symbol *base = src;
 
 	if (base->ctype.modifiers & MOD_SIGNED)
@@ -1138,12 +1138,15 @@ static pseudo_t cast_pseudo(struct entrypoint *ep, pseudo_t src, struct symbol *
 	return result;
 }
 
-static int opcode_sign(int opcode, struct symbol *ctype)
+static enum opcode opcode_sign(enum opcode opcode, struct symbol *ctype)
 {
 	if (ctype && (ctype->ctype.modifiers & MOD_SIGNED)) {
 		switch(opcode) {
 		case OP_MULU: case OP_DIVU: case OP_MODU: case OP_LSR:
 			opcode++;
+			break;
+		default:
+			break;
 		}
 	}
 	return opcode;
@@ -1162,7 +1165,7 @@ static pseudo_t linearize_assignment(struct entrypoint *ep, struct expression *e
 	if (expr->op != '=') {
 		pseudo_t oldvalue = linearize_load_gen(ep, &ad);
 		pseudo_t dst;
-		static const int op_trans[] = {
+		static const enum opcode op_trans[] = {
 			[SPECIAL_ADD_ASSIGN - SPECIAL_BASE] = OP_ADD,
 			[SPECIAL_SUB_ASSIGN - SPECIAL_BASE] = OP_SUB,
 			[SPECIAL_MUL_ASSIGN - SPECIAL_BASE] = OP_MULU,
@@ -1174,7 +1177,7 @@ static pseudo_t linearize_assignment(struct entrypoint *ep, struct expression *e
 			[SPECIAL_OR_ASSIGN  - SPECIAL_BASE] = OP_OR,
 			[SPECIAL_XOR_ASSIGN - SPECIAL_BASE] = OP_XOR
 		};
-		int opcode;
+		enum opcode opcode;
 
 		if (!src)
 			return VOID;
@@ -1262,7 +1265,7 @@ static pseudo_t linearize_call_expression(struct entrypoint *ep, struct expressi
 static pseudo_t linearize_binop(struct entrypoint *ep, struct expression *expr)
 {
 	pseudo_t src1, src2, dst;
-	static const int opcode[] = {
+	static const enum opcode opcode[] = {
 		['+'] = OP_ADD, ['-'] = OP_SUB,
 		['*'] = OP_MULU, ['/'] = OP_DIVU,
 		['%'] = OP_MODU, ['&'] = OP_AND,
@@ -1272,7 +1275,7 @@ static pseudo_t linearize_binop(struct entrypoint *ep, struct expression *expr)
 		[SPECIAL_LOGICAL_AND] = OP_AND_BOOL,
 		[SPECIAL_LOGICAL_OR] = OP_OR_BOOL,
 	};
-	int op;
+	enum opcode op;
 
 	src1 = linearize_expression(ep, expr->left);
 	src2 = linearize_expression(ep, expr->right);
@@ -1396,7 +1399,7 @@ static pseudo_t linearize_logical(struct entrypoint *ep, struct expression *expr
 
 static pseudo_t linearize_compare(struct entrypoint *ep, struct expression *expr)
 {
-	static const int cmpop[] = {
+	static const enum opcode cmpop[] = {
 		['>'] = OP_SET_GT, ['<'] = OP_SET_LT,
 		[SPECIAL_EQUAL] = OP_SET_EQ,
 		[SPECIAL_NOTEQUAL] = OP_SET_NE,
diff --git a/linearize.h b/linearize.h
index 50b3601..cd3376d 100644
--- a/linearize.h
+++ b/linearize.h
@@ -66,68 +66,6 @@ struct asm_rules {
 
 DECLARE_ALLOCATOR(asm_rules);
 
-struct instruction {
-	unsigned opcode:8,
-		 size:24;
-	struct basic_block *bb;
-	struct position pos;
-	struct symbol *type;
-	union {
-		pseudo_t target;
-		pseudo_t cond;		/* for branch and switch */
-	};
-	union {
-		struct /* entrypoint */ {
-			struct pseudo_list *arg_list;
-		};
-		struct /* branch */ {
-			struct basic_block *bb_true, *bb_false;
-		};
-		struct /* switch */ {
-			struct multijmp_list *multijmp_list;
-		};
-		struct /* phi_node */ {
-			struct pseudo_list *phi_list;
-		};
-		struct /* phi source */ {
-			pseudo_t phi_src;
-			struct instruction_list *phi_users;
-		};
-		struct /* unops */ {
-			pseudo_t src;
-			struct symbol *orig_type;	/* casts */
-			unsigned int offset;		/* memops */
-		};
-		struct /* binops and sel */ {
-			pseudo_t src1, src2, src3;
-		};
-		struct /* slice */ {
-			pseudo_t base;
-			unsigned from, len;
-		};
-		struct /* multijump */ {
-			int begin, end;
-		};
-		struct /* setval */ {
-			pseudo_t symbol;		/* Subtle: same offset as "src" !! */
-			struct expression *val;
-		};
-		struct /* call */ {
-			pseudo_t func;
-			struct pseudo_list *arguments;
-		};
-		struct /* context */ {
-			int increment;
-			int check;
-			struct expression *context_expr;
-		};
-		struct /* asm */ {
-			const char *string;
-			struct asm_rules *asm_rules;
-		};
-	};
-};
-
 enum opcode {
 	OP_BADOP,
 
@@ -219,6 +157,68 @@ enum opcode {
 	OP_COPY,
 };
 
+struct instruction {
+	enum opcode opcode:8;
+	unsigned size:24;
+	struct basic_block *bb;
+	struct position pos;
+	struct symbol *type;
+	union {
+		pseudo_t target;
+		pseudo_t cond;		/* for branch and switch */
+	};
+	union {
+		struct /* entrypoint */ {
+			struct pseudo_list *arg_list;
+		};
+		struct /* branch */ {
+			struct basic_block *bb_true, *bb_false;
+		};
+		struct /* switch */ {
+			struct multijmp_list *multijmp_list;
+		};
+		struct /* phi_node */ {
+			struct pseudo_list *phi_list;
+		};
+		struct /* phi source */ {
+			pseudo_t phi_src;
+			struct instruction_list *phi_users;
+		};
+		struct /* unops */ {
+			pseudo_t src;
+			struct symbol *orig_type;	/* casts */
+			unsigned int offset;		/* memops */
+		};
+		struct /* binops and sel */ {
+			pseudo_t src1, src2, src3;
+		};
+		struct /* slice */ {
+			pseudo_t base;
+			unsigned from, len;
+		};
+		struct /* multijump */ {
+			int begin, end;
+		};
+		struct /* setval */ {
+			pseudo_t symbol;		/* Subtle: same offset as "src" !! */
+			struct expression *val;
+		};
+		struct /* call */ {
+			pseudo_t func;
+			struct pseudo_list *arguments;
+		};
+		struct /* context */ {
+			int increment;
+			int check;
+			struct expression *context_expr;
+		};
+		struct /* asm */ {
+			const char *string;
+			struct asm_rules *asm_rules;
+		};
+	};
+};
+
 struct basic_block_list;
 struct instruction_list;
 
diff --git a/simplify.c b/simplify.c
index 8200584..9e9c893 100644
--- a/simplify.c
+++ b/simplify.c
@@ -693,7 +693,7 @@ static int simplify_cast(struct instruction *insn)
 	}
 
 	if (size == orig_size) {
-		int op = (orig_type->ctype.modifiers & MOD_SIGNED) ? OP_SCAST : OP_CAST;
+		enum opcode op = (orig_type->ctype.modifiers & MOD_SIGNED) ? OP_SCAST : OP_CAST;
 		if (insn->opcode == op)
 			goto simplify;
 	}
@@ -729,7 +729,7 @@ static int simplify_select(struct instruction *insn)
 
 		/* The pair 0/1 is special - replace with SETNE/SETEQ */
 		if ((val1 | val2) == 1) {
-			int opcode = OP_SET_EQ;
+			enum opcode opcode = OP_SET_EQ;
 			if (val1) {
 				src1 = src2;
 				opcode = OP_SET_NE;
-- 
1.7.1
--
To unsubscribe from this list: send the line "unsubscribe linux-sparse" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[Index of Archives]     [Newbies FAQ]     [LKML]     [IETF Annouce]     [DCCP]     [Netdev]     [Networking]     [Security]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux SCSI]     [Trinity Fuzzer Tool]

  Powered by Linux