MatchLib
nvhls_assert.h
1 /*
2  * Copyright (c) 2017-2024, 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 
34 // Some common phrases
35 #define __NVHLS_ASSERT(X) CTC_SKIP_ASSERT assert(X); CTC_ENDSKIP_ASSERT
36 #define __NVHLS_ASSERT_SC(X) CTC_SKIP_ASSERT sc_assert(X); CTC_ENDSKIP_ASSERT
37 #define __NVHLS_ASSERT_NULL CTC_SKIP_ASSERT ((void)0); CTC_ENDSKIP_ASSERT
38 #define __NVHLS_ASSERT_SC_REPORT_ERROR(X,MSG) \
39  if (!(X)) { \
40  DCOUT("Assertion failed. " << MSG); \
41  SC_REPORT_ERROR("NVHLS_ASSERT", "Assertion failed."); \
42  }
43 
63 #ifdef NVHLS_CONTINUE_ON_ASSERT
64  #define NVHLS_ASSERT(X) __NVHLS_ASSERT_SC_REPORT_ERROR(X,"")
65 #else
66  #ifdef HLS_CATAPULT
67  #include <ac_assert.h>
68  #define NVHLS_ASSERT(X) __NVHLS_ASSERT(X)
69  #else
70  #ifndef __SYNTHESIS__
71  #define NVHLS_ASSERT(X) __NVHLS_ASSERT_SC(X)
72  #else
73  #define NVHLS_ASSERT(X) __NVHLS_ASSERT_NULL
74  #endif
75  #endif
76 #endif
77 
78 
98 #ifndef __SYNTHESIS__
99  #ifdef NVHLS_CONTINUE_ON_ASSERT
100  #define CMOD_ASSERT(X) __NVHLS_ASSERT_SC_REPORT_ERROR(X,"")
101  #else
102  #define CMOD_ASSERT(X) __NVHLS_ASSERT(X)
103  #endif
104 #else
105  #define CMOD_ASSERT(X) __NVHLS_ASSERT_NULL
106 #endif
107 
127 #ifdef NVHLS_CONTINUE_ON_ASSERT
128  #define NVHLS_ASSERT_MSG(X,MSG) __NVHLS_ASSERT_SC_REPORT_ERROR(X,MSG)
129 #else
130  #ifdef HLS_CATAPULT
131  #include <ac_assert.h>
132  #define NVHLS_ASSERT_MSG(X,MSG) __NVHLS_ASSERT(X && MSG)
133  #else
134  #ifndef __SYNTHESIS__
135  #define NVHLS_ASSERT_MSG(X,MSG) __NVHLS_ASSERT_SC(X && MSG)
136  #else
137  #define NVHLS_ASSERT_MSG(X,MSG) __NVHLS_ASSERT_NULL
138  #endif
139  #endif
140 #endif
141 
142 
162 #ifndef __SYNTHESIS__
163  #ifdef NVHLS_CONTINUE_ON_ASSERT
164  #define CMOD_ASSERT_MSG(X,MSG) __NVHLS_ASSERT_SC_REPORT_ERROR(X,MSG)
165  #else
166  #define CMOD_ASSERT_MSG(X,MSG) \
167  if (!(X)) { \
168  DCOUT("Error: Assertion failed. " << MSG << endl); \
169  } \
170  __NVHLS_ASSERT(X)
171  #endif
172 #else
173  #define CMOD_ASSERT_MSG(X,MSG) __NVHLS_ASSERT_NULL
174 #endif
175 
176 
177 #endif