CGRA-ME
src
core
BitSetting.cpp
Go to the documentation of this file.
1
/*******************************************************************************
2
* The software programs comprising "CGRA-ME" and the documentation provided
3
* with them are copyright by its authors and the University of Toronto. Only
4
* non-commercial, not-for-profit use of this software is permitted without ex-
5
* plicit permission. This software is provided "as is" with no warranties or
6
* guarantees of support. See the LICENCE for more details. You should have re-
7
* ceived a copy of the full licence along with this software. If not, see
8
* <http://cgra-me.ece.utoronto.ca/license/>.
9
******************************************************************************/
10
11
#include <
CGRA/BitSetting.h
>
12
#include <
CGRA/Exception.h
>
13
14
#include <iostream>
15
16
template
<>
17
BitSetting
from_bool<BitSetting>
(
bool
b) {
18
if
(b) {
19
return
BitSetting::HIGH
;
20
}
else
{
21
return
BitSetting::LOW
;
22
}
23
}
24
25
BitSetting
force_to_rail
(
const
BitSetting
& bs) {
26
switch
(bs) {
27
case
BitSetting::LOW
:
28
case
BitSetting::DONT_CARE_PREFER_LOW
:
29
return
BitSetting::LOW
;
30
case
BitSetting::HIGH
:
31
case
BitSetting::DONT_CARE_PREFER_HIGH
:
32
return
BitSetting::HIGH
;
33
default
:
34
throw
cgrame_error
(
"don't know how to force BitSetting to rail"
);
35
}
36
}
37
38
std::ostream&
operator<<
(std::ostream& os,
const
BitSetting
& bs) {
39
switch
(bs) {
40
case
BitSetting::LOW
:
41
return
os <<
"0"
;
42
case
BitSetting::HIGH
:
43
return
os <<
"1"
;
44
case
BitSetting::DONT_CARE_PREFER_LOW
:
45
case
BitSetting::DONT_CARE_PREFER_HIGH
:
46
return
os <<
"x"
;
47
case
BitSetting::HIGH_IMPEDANCE
:
48
return
os <<
"z"
;
49
default
:
50
throw
cgrame_error
(
"unhandled BitSetting in stream printing function"
);
51
}
52
}
53
54
std::ostream&
operator<<
(std::ostream& os,
const
std::vector<BitSetting>& bits) {
55
os <<
'{'
;
56
for
(
const
auto
& bit : bits) {
57
os << bit;
58
}
59
os <<
'}'
;
60
return
os;
61
}
62
63
std::ostream&
operator<<
(std::ostream& os,
const
BitSettingForVerilog
& bs) {
64
switch
(bs.
val
) {
65
case
BitSetting::LOW
:
66
return
os <<
"1'b0"
;
67
case
BitSetting::HIGH
:
68
return
os <<
"1'b1"
;
69
case
BitSetting::DONT_CARE_PREFER_LOW
:
70
case
BitSetting::DONT_CARE_PREFER_HIGH
:
71
return
os <<
"1'bx"
;
72
case
BitSetting::HIGH_IMPEDANCE
:
73
return
os <<
"1'bz"
;
74
default
:
75
throw
cgrame_error
(
"unhandled BitSettingForVerilog in stream printing function"
);
76
}
77
}
BitSetting::HIGH
@ HIGH
BitSetting::DONT_CARE_PREFER_HIGH
@ DONT_CARE_PREFER_HIGH
BitSetting::HIGH_IMPEDANCE
@ HIGH_IMPEDANCE
BitSetting
BitSetting
Definition:
BitSetting.h:18
BitSetting::DONT_CARE_PREFER_LOW
@ DONT_CARE_PREFER_LOW
from_bool< BitSetting >
BitSetting from_bool< BitSetting >(bool b)
Definition:
BitSetting.cpp:17
BitSetting::LOW
@ LOW
Exception.h
BitSetting.h
force_to_rail
BitSetting force_to_rail(const BitSetting &bs)
Definition:
BitSetting.cpp:25
BitSettingForVerilog::val
BitSetting val
Definition:
BitSetting.h:37
cgrame_error
Definition:
Exception.h:20
operator<<
std::ostream & operator<<(std::ostream &os, const BitSetting &bs)
Definition:
BitSetting.cpp:38
BitSettingForVerilog
Definition:
BitSetting.h:36
Generated on Fri Nov 17 2023 12:26:43 for CGRA-ME by
1.8.17