summaryrefslogtreecommitdiffstats
path: root/contrib/restricted/wavm/Include/WAVM/Inline/Assert.h
blob: 498f24c44ca480ba9c3c2c558b0bc04ba4d1916e (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
#pragma once

#include <cstdarg>
#include <stdexcept>
#include "WAVM/Inline/Config.h"
#include "WAVM/Platform/Defines.h"
#include "WAVM/Platform/Error.h"

#define WAVM_ENABLE_ASSERTS 1

#ifndef WAVM_STRINGIZE
#define WAVM_STRINGIZE_DETAIL(x) #x
#define WAVM_STRINGIZE(x) WAVM_STRINGIZE_DETAIL(x)
#endif

#define WAVM_ASSERT(condition)                                                                                       \
	if(!(condition))                                                                                                 \
	{                                                                                                                \
		const char* message = "WAVM assertion failed at " __FILE__ ":" WAVM_STRINGIZE(__LINE__) " (" #condition ")"; \
		throw std::runtime_error(message);                                                                           \
	}

#define WAVM_ERROR_UNLESS(condition)                                                                                    \
	if(!(condition))                                                                                                    \
	{                                                                                                                   \
		const char* message = "WAVM error unless failed at " __FILE__ ":" WAVM_STRINGIZE(__LINE__) " (" #condition ")"; \
		throw std::runtime_error(message);                                                                              \
	}

#define WAVM_UNREACHABLE(condition)                                                                             \
	while(true)                                                                                                 \
	{                                                                                                           \
		const char* message = "WAVM unreachable at " __FILE__ ":" WAVM_STRINGIZE(__LINE__) " (" #condition ")"; \
		throw std::runtime_error(message);                                                                      \
	}