CGRA-ME
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<>
18  if (b) {
19  return BitSetting::HIGH;
20  } else {
21  return BitSetting::LOW;
22  }
23 }
24 
26  switch (bs) {
27  case BitSetting::LOW:
29  return BitSetting::LOW;
30  case BitSetting::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";
46  return os << "x";
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";
71  return os << "1'bx";
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