MatchLib
nvhls_assert.h
1 /*
2  * Copyright (c) 2017-2019, NVIDIA CORPORATION. All rights reserved.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License")
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 #ifndef NVHLS_ASSERT_H
18 #define NVHLS_ASSERT_H
19 
20 #include <systemc.h>
21 #include <hls_globals.h>
22 
23 // the following is to avoid "statement has no effect"
24 // during compilation when CTC coverage is disabled.
25 // When coverage is enabled, these warnings are present.
26 #ifdef COV_ENABLE
27  #define CTC_SKIP_ASSERT "CTC SKIP";
28  #define CTC_ENDSKIP_ASSERT "CTC ENDSKIP";
29 #else
30  #define CTC_SKIP_ASSERT ((void)"CTC SKIP");
31  #define CTC_ENDSKIP_ASSERT ((void)"CTC ENDSKIP");
32 #endif
33 
53 #ifdef HLS_CATAPULT
54 #include <ac_assert.h>
55 #define NVHLS_ASSERT(X) CTC_SKIP_ASSERT assert(X); CTC_ENDSKIP_ASSERT
56 #else
57  #ifndef __SYNTHESIS__
58  #define NVHLS_ASSERT(X) CTC_SKIP_ASSERT sc_assert(X); CTC_ENDSKIP_ASSERT
59  #else
60  #define NVHLS_ASSERT(X) CTC_SKIP_ASSERT ((void)0); CTC_ENDSKIP_ASSERT
61  #endif
62 #endif
63 
64 
84 #ifndef __SYNTHESIS__
85 #define CMOD_ASSERT(x) CTC_SKIP_ASSERT assert(x); CTC_ENDSKIP_ASSERT
86 #else
87 #define CMOD_ASSERT(x) CTC_SKIP_ASSERT ((void)0); CTC_ENDSKIP_ASSERT
88 #endif
89 
110 #ifdef HLS_CATAPULT
111 #include <ac_assert.h>
112 #define NVHLS_ASSERT_MSG(X,MSG) \
113  CTC_SKIP_ASSERT assert(X && MSG); CTC_ENDSKIP_ASSERT
114 #else
115  #ifndef __SYNTHESIS__
116  #define NVHLS_ASSERT_MSG(X,MSG) \
117  CTC_SKIP_ASSERT sc_assert(X && MSG); CTC_ENDSKIP_ASSERT
118  #else
119  #define NVHLS_ASSERT_MSG(X,MSG) CTC_SKIP_ASSERT ((void)0); CTC_ENDSKIP_ASSERT
120  #endif
121 #endif
122 
123 
143 #ifndef __SYNTHESIS__
144 #define CMOD_ASSERT_MSG(X,MSG) \
145  if (!(X)) { \
146  DCOUT("Assertion Failed. " << MSG << endl); \
147  } \
148  CTC_SKIP_ASSERT assert(X); CTC_ENDSKIP_ASSERT
149 #else
150 #define CMOD_ASSERT_MSG(X,MSG) CTC_SKIP_ASSERT ((void)0); CTC_ENDSKIP_ASSERT
151 #endif
152 
153 
154 #endif