f977fbe0f155dde6b0a0a0d193e5469f0f8d8fde
[libfirm] / ir / ir / irvrfy_t.h
1 /*
2  * Copyright (C) 1995-2007 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  * Project:     libFIRM
22  * File name:   ir/ir/irvrfy_t.h
23  * Purpose:     New checker of irnodes for correctness.
24  * Author:      Michael Beck
25  * Modified by:
26  * Created:
27  * CVS-ID:      $Id$
28  * Copyright:   (c) 1998-2005 Universität Karlsruhe
29  */
30 #ifndef _IRVRFY_T_H_
31 #define _IRVRFY_T_H_
32
33 #include "irflag_t.h"
34 #include "irvrfy.h"
35 #include "irdump.h"
36
37 extern const char *firm_vrfy_failure_msg;
38
39 #ifdef NDEBUG
40 /*
41  * in RELEASE mode, returns ret if the expression expr evaluates to zero
42  * in ASSERT mode, asserts the expression expr (and the string string).
43  */
44 #define ASSERT_AND_RET(expr, string, ret)       do { if (!(expr)) return (ret); } while (0)
45
46 /*
47  * in RELEASE mode, returns ret if the expression expr evaluates to zero
48  * in ASSERT mode, executes blk if the expression expr evaluates to zero and asserts expr
49  */
50 #define ASSERT_AND_RET_DBG(expr, string, ret, blk)     do { if (!(expr)) return (ret); } while (0)
51 #else
52 #define ASSERT_AND_RET(expr, string, ret) \
53 do { \
54   if (opt_do_node_verification == FIRM_VERIFICATION_ON) {\
55     if (!(expr) && current_ir_graph != get_const_code_irg()) \
56       dump_ir_block_graph(current_ir_graph, "-assert"); \
57     assert((expr) && string); } \
58   if (!(expr)) { \
59     if (opt_do_node_verification == FIRM_VERIFICATION_REPORT) \
60       fprintf(stderr, #expr " : " string "\n"); \
61     firm_vrfy_failure_msg = #expr " && " string; \
62     return (ret); \
63   } \
64 } while(0)
65
66 #define ASSERT_AND_RET_DBG(expr, string, ret, blk) \
67 do { \
68   if (!(expr)) { \
69     firm_vrfy_failure_msg = #expr " && " string; \
70     if (opt_do_node_verification != FIRM_VERIFICATION_ERROR_ONLY) { blk; } \
71     if (opt_do_node_verification == FIRM_VERIFICATION_REPORT) \
72       fprintf(stderr, #expr " : " string "\n"); \
73     else if (opt_do_node_verification == FIRM_VERIFICATION_ON) { \
74       if (!(expr) && current_ir_graph != get_const_code_irg()) \
75         dump_ir_block_graph(current_ir_graph, "-assert"); \
76       assert((expr) && string); \
77     } \
78     return (ret); \
79   } \
80 } while(0)
81
82 #endif
83
84 /**
85  * Set the default verify_node and verify_proj_node operation for an ir_op_ops.
86  */
87 void firm_set_default_verifyer(ir_opcode code, ir_op_ops *ops);
88
89 #endif /* _IRVRFY_T_H_ */