MatchLib
Loading...
Searching...
No Matches
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#ifdef HLS_CATAPULT
23#include <ac_assert.h>
24#endif
25
26// the following is to avoid "statement has no effect"
27// during compilation when CTC coverage is disabled.
28// When coverage is enabled, these warnings are present.
29#ifdef COV_ENABLE
30 #define CTC_SKIP_ASSERT "CTC SKIP";
31 #define CTC_ENDSKIP_ASSERT "CTC ENDSKIP";
32#else
33 #define CTC_SKIP_ASSERT ((void)"CTC SKIP");
34 #define CTC_ENDSKIP_ASSERT ((void)"CTC ENDSKIP");
35#endif
36
37// Some common phrases
38#define __NVHLS_ASSERT(X) CTC_SKIP_ASSERT assert(X); CTC_ENDSKIP_ASSERT
39#define __NVHLS_ASSERT_SYN(X) CTC_SKIP_ASSERT AC_ASSERTION(X); CTC_ENDSKIP_ASSERT
40#define __NVHLS_ASSERT_SOFT(X) CTC_SKIP_ASSERT softassert(X); CTC_ENDSKIP_ASSERT
41#define __NVHLS_ASSERT_SC(X) CTC_SKIP_ASSERT sc_assert(X); CTC_ENDSKIP_ASSERT
42#define __NVHLS_ASSERT_NULL CTC_SKIP_ASSERT ((void)0); CTC_ENDSKIP_ASSERT
43#define __NVHLS_ASSERT_SC_REPORT_ERROR(X,MSG) \
44 if (!(X)) { \
45 DCOUT("Assertion failed. " << MSG); \
46 SC_REPORT_ERROR("NVHLS_ASSERT", "Assertion failed."); \
47 }
48
68#ifdef HLS_CATAPULT
69 #ifdef NVHLS_CONTINUE_ON_ASSERT
70 #define NVHLS_ASSERT(X) __NVHLS_ASSERT_SOFT(X)
71 #else
72 #define NVHLS_ASSERT(X) __NVHLS_ASSERT_SYN(X)
73 #endif
74#else
75 #ifndef __SYNTHESIS__
76 #ifdef NVHLS_CONTINUE_ON_ASSERT
77 #define NVHLS_ASSERT(X) __NVHLS_ASSERT_SC_REPORT_ERROR(X,"")
78 #else
79 #define NVHLS_ASSERT(X) __NVHLS_ASSERT_SC(X)
80 #endif
81 #else
82 #define NVHLS_ASSERT(X) __NVHLS_ASSERT_NULL
83 #endif
84#endif
85
86
106#ifdef HLS_CATAPULT
107 #ifndef __SYNTHESIS__
108 #ifdef NVHLS_CONTINUE_ON_ASSERT
109 #define CMOD_ASSERT(X) __NVHLS_ASSERT_SOFT(X)
110 #else
111 #define CMOD_ASSERT(X) __NVHLS_ASSERT(X)
112 #endif
113 #else
114 #define CMOD_ASSERT(X) __NVHLS_ASSERT_NULL
115 #endif
116#else
117 #ifndef __SYNTHESIS__
118 #ifdef NVHLS_CONTINUE_ON_ASSERT
119 #define NVHLS_ASSERT(X) __NVHLS_ASSERT_SC_REPORT_ERROR(X,"")
120 #else
121 #define NVHLS_ASSERT(X) __NVHLS_ASSERT_SC(X)
122 #endif
123 #else
124 #define NVHLS_ASSERT(X) __NVHLS_ASSERT_NULL
125 #endif
126#endif
127
128
148#ifdef HLS_CATAPULT
149 #ifdef NVHLS_CONTINUE_ON_ASSERT
150 #define NVHLS_ASSERT_MSG(X,MSG) __NVHLS_ASSERT_SOFT(X && MSG)
151 #else
152 #define NVHLS_ASSERT_MSG(X,MSG) __NVHLS_ASSERT_SYN(X && MSG)
153 #endif
154#else
155 #ifndef __SYNTHESIS__
156 #ifdef NVHLS_CONTINUE_ON_ASSERT
157 #define NVHLS_ASSERT_MSG(X,MSG) __NVHLS_ASSERT_SC_REPORT_ERROR(X,MSG)
158 #else
159 #define NVHLS_ASSERT_MSG(X,MSG) __NVHLS_ASSERT_SC(X && MSG)
160 #endif
161 #else
162 #define NVHLS_ASSERT_MSG(X,MSG) __NVHLS_ASSERT_NULL
163 #endif
164#endif
165
166
186#ifdef HLS_CATAPULT
187 #ifndef __SYNTHESIS__
188 #ifdef NVHLS_CONTINUE_ON_ASSERT
189 #define CMOD_ASSERT_MSG(X,MSG) __NVHLS_ASSERT_SOFT(X && MSG)
190 #else
191 #define CMOD_ASSERT_MSG(X,MSG) __NVHLS_ASSERT(X && MSG)
192 #endif
193 #else
194 #define CMOD_ASSERT_MSG(X,MSG) __NVHLS_ASSERT_NULL
195 #endif
196#else
197 #ifndef __SYNTHESIS__
198 #ifdef NVHLS_CONTINUE_ON_ASSERT
199 #define NVHLS_ASSERT_MSG(X,MSG) __NVHLS_ASSERT_SC_REPORT_ERROR(X,MSG)
200 #else
201 #define NVHLS_ASSERT_MSG(X,MSG) __NVHLS_ASSERT_SC(X && MSG)
202 #endif
203 #else
204 #define NVHLS_ASSERT_MSG(X,MSG) __NVHLS_ASSERT_NULL
205 #endif
206#endif
207
208
209#endif