1 /*
2  * Copyright 2021 The Hafnium Authors.
3  *
4  * Use of this source code is governed by a BSD-style
5  * license that can be found in the LICENSE file or at
6  * https://opensource.org/licenses/BSD-3-Clause.
7  */
8 
9 #pragma once
10 
11 #if !defined(__cplusplus)
12 
13 #include <stdint.h>
14 
15 #include "hf/dlog.h"
16 #include "hf/panic.h"
17 
18 #ifndef PLAT_LOG_LEVEL_ASSERT
19 #define PLAT_LOG_LEVEL_ASSERT LOG_LEVEL
20 #endif
21 
22 #define assert(e) assert_impl(e, __FILE__, __LINE__, #e)
23 
assert_impl(bool cond,const char * file,uint32_t line,const char * expr)24 static inline void assert_impl(bool cond, const char *file, uint32_t line,
25 			       const char *expr)
26 {
27 	if (!ENABLE_ASSERTIONS) {
28 		return;
29 	}
30 
31 	if (cond) {
32 		return;
33 	}
34 
35 	if (PLAT_LOG_LEVEL_ASSERT >= LOG_LEVEL_VERBOSE) {
36 		panic("ASSERT: %s:%d:%s\n", file, line, expr);
37 	} else if (PLAT_LOG_LEVEL_ASSERT >= LOG_LEVEL_INFO) {
38 		panic("ASSERT: %s:%d\n", file, line);
39 	} else {
40 		panic("ASSERT\n");
41 	}
42 }
43 
44 #else
45 #include <assert.h>
46 #endif /* !defined(__cplusplus) */
47