summaryrefslogtreecommitdiffstatshomepage
path: root/src/lib/netlist/plib/pexception.h
blob: bbbe78b18db75d5372362279e3264a09f4548e4f (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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
// license:GPL-2.0+
// copyright-holders:Couriersud
/*
 * palloc.h
 *
 */

#ifndef PEXCEPTION_H_
#define PEXCEPTION_H_

#include "pstring.h"

#include <exception>

namespace plib {
//============================================================
//  exception base
//============================================================

class pexception : public std::exception
{
public:
	explicit pexception(const pstring &text);
	pexception(const pexception &e) : std::exception(e), m_text(e.m_text) { }

	virtual ~pexception() noexcept;

	const pstring &text() { return m_text; }

private:
	pstring m_text;
};

class file_e : public plib::pexception
{
public:
	file_e(const pstring &fmt, const pstring &filename);
	file_e(const file_e &e) : pexception(e) { }
	virtual ~file_e() noexcept;
};

class file_open_e : public file_e
{
public:
	explicit file_open_e(const pstring &filename);
	file_open_e(const file_open_e &e) : file_e(e) { }
	virtual ~file_open_e() noexcept;
};

class file_read_e : public file_e
{
public:
	explicit file_read_e(const pstring &filename);
	file_read_e(const file_read_e &e) : file_e(e) { }
	virtual ~file_read_e() noexcept;
};

class file_write_e : public file_e
{
public:
	explicit file_write_e(const pstring &filename);
	file_write_e(const file_write_e &e) : file_e(e) { }
	virtual ~file_write_e() noexcept;
};

class null_argument_e : public plib::pexception
{
public:
	explicit null_argument_e(const pstring &argument);
	null_argument_e(const null_argument_e &e) : pexception(e) { }
	virtual ~null_argument_e() noexcept;
};

class out_of_mem_e : public plib::pexception
{
public:
	explicit out_of_mem_e(const pstring &location);
	out_of_mem_e(const out_of_mem_e &e) : pexception(e) { }
	virtual ~out_of_mem_e() noexcept;
};

/* FIXME: currently only a stub for later use. More use could be added by
 * using “-fnon-call-exceptions" and sigaction to enable c++ exception supported.
 */

class fpexception_e : public pexception
{
public:
	explicit fpexception_e(const pstring &text);
	fpexception_e(const fpexception_e &e) : pexception(e) { }
	virtual ~fpexception_e() noexcept;
};

static const unsigned FP_INEXACT = 0x0001;
static const unsigned FP_DIVBYZERO = 0x0002;
static const unsigned FP_UNDERFLOW = 0x0004;
static const unsigned FP_OVERFLOW = 0x0008;
static const unsigned FP_INVALID = 0x00010;
static const unsigned FP_ALL = 0x0001f;

/*
 * Catch SIGFPE on linux for debugging purposes.
 */

class fpsignalenabler
{
public:
	explicit fpsignalenabler(unsigned fpexceptions);
	~fpsignalenabler();

	/* is the functionality supported ? */
	static bool supported();
	/* returns last global enable state */
	static bool global_enable(bool enable);

private:
	int m_last_enabled;

	static bool m_enable;
};


}

#endif /* PEXCEPTION_H_ */