verify: Clarify assertion message.
[libfirm] / ir / ir / irverify_t.h
1 /*
2  * Copyright (C) 1995-2008 University of Karlsruhe.  All right reserved.
3  *
4  * This file is part of libFirm.
5  *
6  * This file may be distributed and/or modified under the terms of the
7  * GNU General Public License version 2 as published by the Free Software
8  * Foundation and appearing in the file LICENSE.GPL included in the
9  * packaging of this file.
10  *
11  * Licensees holding valid libFirm Professional Edition licenses may use
12  * this file in accordance with the libFirm Commercial License.
13  * Agreement provided with the Software.
14  *
15  * This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
16  * WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR
17  * PURPOSE.
18  */
19
20 /**
21  * @file
22  * @brief    New checker of irnodes for correctness.
23  * @author   Michael Beck
24  */
25 #ifndef FIRM_IR_IRVERIFY_T_H
26 #define FIRM_IR_IRVERIFY_T_H
27
28 #include "irflag_t.h"
29 #include "irverify.h"
30 #include "irdump.h"
31
32 #include "beutil.h"
33
34 extern const char *firm_verify_failure_msg;
35
36 #ifdef NDEBUG
37 /*
38  * in RELEASE mode, returns ret if the expression expr evaluates to zero
39  * in ASSERT mode, asserts the expression expr (and the string string).
40  */
41 #define ASSERT_AND_RET(expr, string, ret)       do { if (!(expr)) return (ret); } while (0)
42
43 /*
44  * in RELEASE mode, returns ret if the expression expr evaluates to zero
45  * in ASSERT mode, executes blk if the expression expr evaluates to zero and asserts expr
46  */
47 #define ASSERT_AND_RET_DBG(expr, string, ret, blk)     do { if (!(expr)) return (ret); } while (0)
48 #else
49 #define ASSERT_AND_RET(expr, string, ret) \
50 do { \
51   if (opt_do_node_verification == FIRM_VERIFICATION_ON) {\
52     if (!(expr) && current_ir_graph != get_const_code_irg()) \
53       dump_ir_graph(current_ir_graph, "assert"); \
54     assert((expr) && string); } \
55   if (!(expr)) { \
56     if (opt_do_node_verification == FIRM_VERIFICATION_REPORT) \
57       fprintf(stderr, #expr " : " string "\n"); \
58     firm_verify_failure_msg = #expr " && " string; \
59     return (ret); \
60   } \
61 } while(0)
62
63 #define ASSERT_AND_RET_DBG(expr, string, ret, blk) \
64 do { \
65   if (!(expr)) { \
66     firm_verify_failure_msg = #expr " && " string; \
67     if (opt_do_node_verification != FIRM_VERIFICATION_ERROR_ONLY) { blk } \
68     if (opt_do_node_verification == FIRM_VERIFICATION_REPORT) \
69       fprintf(stderr, #expr " : " string "\n"); \
70     else if (opt_do_node_verification == FIRM_VERIFICATION_ON) { \
71       if (!(expr) && current_ir_graph != get_const_code_irg()) \
72         dump_ir_graph(current_ir_graph, "assert"); \
73       assert((expr) && string); \
74     } \
75     return (ret); \
76   } \
77 } while(0)
78
79 #endif
80
81 /**
82  * Set the default verify_node and verify_proj_node operations.
83  */
84 void ir_register_verify_node_ops(void);
85
86 #endif