+
+
+typedef struct _vrfy_bad_env_t {
+ int flags;
+ int res;
+} vrfy_bad_env_t;
+
+static void check_bads(ir_node *node, void *env)
+{
+ vrfy_bad_env_t *venv = env;
+ int i, arity = get_irn_arity(node);
+
+ if (is_Block(node)) {
+ if ((venv->flags & BAD_CF) == 0) {
+
+ /* check for Bad Block predecessor */
+ for (i = 0; i < arity; ++i) {
+ ir_node *pred = get_irn_n(node, i);
+
+ if (is_Bad(pred)) {
+ venv->res |= BAD_CF;
+
+ if (opt_do_node_verification == NODE_VERIFICATION_REPORT) {
+ fprintf(stderr, "irg_vrfy_bads: Block %ld has Bad predecessor\n", get_irn_node_nr(node));
+ }
+ if (opt_do_node_verification == NODE_VERIFICATION_ON) {
+ assert(0 && "Bad CF detected");
+ }
+ }
+ }
+ }
+ }
+ else {
+ if ((venv->flags & BAD_BLOCK) == 0) {
+
+ /* check for Bad Block */
+ if (is_Bad(get_nodes_block(node))) {
+ venv->res |= BAD_BLOCK;
+
+ if (opt_do_node_verification == NODE_VERIFICATION_REPORT) {
+ fprintf(stderr, "irg_vrfy_bads: node %ld has Bad Block\n", get_irn_node_nr(node));
+ }
+ if (opt_do_node_verification == NODE_VERIFICATION_ON) {
+ assert(0 && "Bad CF detected");
+ }
+ }
+ }
+
+ if ((venv->flags & TUPLE) == 0) {
+ if (get_irn_op(node) == op_Tuple) {
+ venv->res |= TUPLE;
+
+ if (opt_do_node_verification == NODE_VERIFICATION_REPORT) {
+ fprintf(stderr, "irg_vrfy_bads: node %ld is a Tuple\n", get_irn_node_nr(node));
+ }
+ if (opt_do_node_verification == NODE_VERIFICATION_ON) {
+ assert(0 && "Tuple detected");
+ }
+ }
+ }
+
+ for (i = 0; i < arity; ++i) {
+ ir_node *pred = get_irn_n(node, i);
+
+ if (is_Bad(pred)) {
+ /* check for Phi with Bad inputs */
+ if (is_Phi(node) && !is_Bad(get_nodes_block(node)) && is_Bad(get_irn_n(get_nodes_block(node), i))) {
+ if (venv->flags & BAD_CF)
+ continue;
+ else {
+ venv->res |= BAD_CF;
+
+ if (opt_do_node_verification == NODE_VERIFICATION_REPORT) {
+ fprintf(stderr, "irg_vrfy_bads: Phi %ld has Bad Input\n", get_irn_node_nr(node));
+ }
+ if (opt_do_node_verification == NODE_VERIFICATION_ON) {
+ assert(0 && "Bad CF detected");
+ }
+ }
+ }
+
+ /* Bad node input */
+ if ((venv->flags & BAD_DF) == 0) {
+ venv->res |= BAD_DF;
+
+ if (opt_do_node_verification == NODE_VERIFICATION_REPORT) {
+ fprintf(stderr, "irg_vrfy_bads: node %ld has Bad Input\n", get_irn_node_nr(node));
+ }
+ if (opt_do_node_verification == NODE_VERIFICATION_ON) {
+ assert(0 && "Bad NON-CF detected");
+ }
+ }
+ }
+ }
+ }
+}
+
+/*
+ * verify occurance of bad nodes
+ */
+int irg_vrfy_bads(ir_graph *irg, int flags)
+{
+ vrfy_bad_env_t env;
+
+ env.flags = flags;
+ env.res = 0;
+
+ irg_walk_graph(irg, check_bads, NULL, &env);
+
+ return env.res;
+}
+
+/*
+ * set the default verify operation
+ */
+void firm_set_default_verifyer(ir_op *op)
+{
+#define CASE(a) \
+ case iro_##a: \
+ op->verify_node = verify_node_##a; \
+ break
+
+ switch (op->code) {
+ CASE(Proj);
+ CASE(Block);
+ CASE(Start);
+ CASE(Jmp);
+ CASE(Break);
+ CASE(Cond);
+ CASE(Return);
+ CASE(Raise);
+ CASE(Const);
+ CASE(SymConst);
+ CASE(Sel);
+ CASE(InstOf);
+ CASE(Call);
+ CASE(Add);
+ CASE(Sub);
+ CASE(Minus);
+ CASE(Mul);
+ CASE(Quot);
+ CASE(DivMod);
+ CASE(Div);
+ CASE(Mod);
+ CASE(Abs);
+ CASE(And);
+ CASE(Or);
+ CASE(Eor);
+ CASE(Not);
+ CASE(Cmp);
+ CASE(Shl);
+ CASE(Shr);
+ CASE(Shrs);
+ CASE(Rot);
+ CASE(Conv);
+ CASE(Cast);
+ CASE(Phi);
+ CASE(Filter);
+ CASE(Load);
+ CASE(Store);
+ CASE(Alloc);
+ CASE(Free);
+ CASE(Sync);
+ CASE(Confirm);
+ CASE(Mux);
+ default:
+ op->verify_node = NULL;
+ }
+#undef CASE
+
+#define CASE(a) \
+ case iro_##a: \
+ op->verify_proj_node = verify_node_Proj_##a; \
+ break
+
+ switch (op->code) {
+ CASE(Start);
+ CASE(Cond);
+ CASE(Raise);
+ CASE(InstOf);
+ CASE(Call);
+ CASE(Quot);
+ CASE(DivMod);
+ CASE(Div);
+ CASE(Mod);
+ CASE(Cmp);
+ CASE(Load);
+ CASE(Store);
+ CASE(Alloc);
+ CASE(Proj);
+ CASE(Tuple);
+ CASE(CallBegin);
+ CASE(EndReg);
+ CASE(EndExcept);
+ default:
+ op->verify_proj_node = NULL;
+ }
+#undef CASE
+}