sc_logic.cc (13160:1e959d3afc64) sc_logic.cc (13325:86323e6cc8ec)
1/*****************************************************************************
2
3 Licensed to Accellera Systems Initiative Inc. (Accellera) under one or
4 more contributor license agreements. See the NOTICE file distributed
5 with this work for additional information regarding copyright ownership.
6 Accellera licenses this file to you under the Apache License, Version 2.0
7 (the "License"); you may not use this file except in compliance with the
8 License. You may obtain a copy of the License at
9
10 http://www.apache.org/licenses/LICENSE-2.0
11
12 Unless required by applicable law or agreed to in writing, software
13 distributed under the License is distributed on an "AS IS" BASIS,
14 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
15 implied. See the License for the specific language governing
16 permissions and limitations under the License.
17
18 *****************************************************************************/
19
20/*****************************************************************************
21
22 sc_logic.cpp -- C++ implementation of logic type. Behaves
23 pretty much the same way as HDLs logic type.
24
25 Original Author: Stan Y. Liao, Synopsys, Inc.
26
27 *****************************************************************************/
28
29/*****************************************************************************
30
31 MODIFICATION LOG - modifiers, enter your name, affiliation, date and
32 changes you are making here.
33
34 Name, Affiliation, Date:
35 Description of Modification:
36
37 *****************************************************************************/
38
39
40// $Log: sc_logic.cpp,v $
41// Revision 1.1.1.1 2006/12/15 20:20:04 acg
42// SystemC 2.3
43//
44// Revision 1.3 2006/01/13 18:53:53 acg
45// Andy Goodrich: added $Log command so that CVS comments are reproduced in
46// the source.
47//
48
49#include <sstream>
50
1/*****************************************************************************
2
3 Licensed to Accellera Systems Initiative Inc. (Accellera) under one or
4 more contributor license agreements. See the NOTICE file distributed
5 with this work for additional information regarding copyright ownership.
6 Accellera licenses this file to you under the Apache License, Version 2.0
7 (the "License"); you may not use this file except in compliance with the
8 License. You may obtain a copy of the License at
9
10 http://www.apache.org/licenses/LICENSE-2.0
11
12 Unless required by applicable law or agreed to in writing, software
13 distributed under the License is distributed on an "AS IS" BASIS,
14 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
15 implied. See the License for the specific language governing
16 permissions and limitations under the License.
17
18 *****************************************************************************/
19
20/*****************************************************************************
21
22 sc_logic.cpp -- C++ implementation of logic type. Behaves
23 pretty much the same way as HDLs logic type.
24
25 Original Author: Stan Y. Liao, Synopsys, Inc.
26
27 *****************************************************************************/
28
29/*****************************************************************************
30
31 MODIFICATION LOG - modifiers, enter your name, affiliation, date and
32 changes you are making here.
33
34 Name, Affiliation, Date:
35 Description of Modification:
36
37 *****************************************************************************/
38
39
40// $Log: sc_logic.cpp,v $
41// Revision 1.1.1.1 2006/12/15 20:20:04 acg
42// SystemC 2.3
43//
44// Revision 1.3 2006/01/13 18:53:53 acg
45// Andy Goodrich: added $Log command so that CVS comments are reproduced in
46// the source.
47//
48
49#include <sstream>
50
51#include "systemc/ext/dt/bit/messages.hh"
51#include "systemc/ext/dt/bit/sc_logic.hh"
52#include "systemc/ext/utils/sc_report_handler.hh"
53
54namespace sc_dt
55{
56
57// ----------------------------------------------------------------------------
58// CLASS : sc_logic
59//
60// Four-valued logic type.
61// ----------------------------------------------------------------------------
62
63// support methods
64void
65sc_logic::invalid_value(sc_logic_value_t v)
66{
67 invalid_value((int)v);
68}
69
70void
71sc_logic::invalid_value(char c)
72{
73 std::stringstream msg;
74 msg << "sc_logic('" << c << "')";
52#include "systemc/ext/dt/bit/sc_logic.hh"
53#include "systemc/ext/utils/sc_report_handler.hh"
54
55namespace sc_dt
56{
57
58// ----------------------------------------------------------------------------
59// CLASS : sc_logic
60//
61// Four-valued logic type.
62// ----------------------------------------------------------------------------
63
64// support methods
65void
66sc_logic::invalid_value(sc_logic_value_t v)
67{
68 invalid_value((int)v);
69}
70
71void
72sc_logic::invalid_value(char c)
73{
74 std::stringstream msg;
75 msg << "sc_logic('" << c << "')";
75 SC_REPORT_ERROR("(E204) value is not valid", msg.str().c_str());
76 SC_REPORT_ERROR(sc_core::SC_ID_VALUE_NOT_VALID_, msg.str().c_str());
76}
77
78void
79sc_logic::invalid_value(int i)
80{
81 std::stringstream msg;
82 msg << "sc_logic(" << i << ")";
77}
78
79void
80sc_logic::invalid_value(int i)
81{
82 std::stringstream msg;
83 msg << "sc_logic(" << i << ")";
83 SC_REPORT_ERROR("(E204) value is not valid", msg.str().c_str());
84 SC_REPORT_ERROR(sc_core::SC_ID_VALUE_NOT_VALID_, msg.str().c_str());
84}
85
86
87void
88sc_logic::invalid_01() const
89{
85}
86
87
88void
89sc_logic::invalid_01() const
90{
90 if ((int)m_val == Log_Z) {
91 SC_REPORT_WARNING(
92 "(W211) sc_logic value 'Z' cannot be converted to bool", 0);
93 } else {
94 SC_REPORT_WARNING(
95 "(W212) sc_logic value 'X' cannot be converted to bool", 0);
96 }
91 if ((int)m_val == Log_Z)
92 SC_REPORT_WARNING(sc_core::SC_ID_LOGIC_Z_TO_BOOL_, 0);
93 else
94 SC_REPORT_WARNING(sc_core::SC_ID_LOGIC_X_TO_BOOL_, 0);
97}
98
99
100// conversion tables
101const sc_logic_value_t sc_logic::char_to_logic[128] = {
102 Log_0, Log_1, Log_Z, Log_X, Log_X, Log_X, Log_X, Log_X,
103 Log_X, Log_X, Log_X, Log_X, Log_X, Log_X, Log_X, Log_X,
104 Log_X, Log_X, Log_X, Log_X, Log_X, Log_X, Log_X, Log_X,
105 Log_X, Log_X, Log_X, Log_X, Log_X, Log_X, Log_X, Log_X,
106 Log_X, Log_X, Log_X, Log_X, Log_X, Log_X, Log_X, Log_X,
107 Log_X, Log_X, Log_X, Log_X, Log_X, Log_X, Log_X, Log_X,
108 Log_0, Log_1, Log_X, Log_X, Log_X, Log_X, Log_X, Log_X,
109 Log_X, Log_X, Log_X, Log_X, Log_X, Log_X, Log_X, Log_X,
110 Log_X, Log_X, Log_X, Log_X, Log_X, Log_X, Log_X, Log_X,
111 Log_X, Log_X, Log_X, Log_X, Log_X, Log_X, Log_X, Log_X,
112 Log_X, Log_X, Log_X, Log_X, Log_X, Log_X, Log_X, Log_X,
113 Log_X, Log_X, Log_Z, Log_X, Log_X, Log_X, Log_X, Log_X,
114 Log_X, Log_X, Log_X, Log_X, Log_X, Log_X, Log_X, Log_X,
115 Log_X, Log_X, Log_X, Log_X, Log_X, Log_X, Log_X, Log_X,
116 Log_X, Log_X, Log_X, Log_X, Log_X, Log_X, Log_X, Log_X,
117 Log_X, Log_X, Log_Z, Log_X, Log_X, Log_X, Log_X, Log_X
118};
119
120const char sc_logic::logic_to_char[4] = { '0', '1', 'Z', 'X' };
121
122const sc_logic_value_t sc_logic::and_table[4][4] = {
123 { Log_0, Log_0, Log_0, Log_0 },
124 { Log_0, Log_1, Log_X, Log_X },
125 { Log_0, Log_X, Log_X, Log_X },
126 { Log_0, Log_X, Log_X, Log_X }
127};
128
129const sc_logic_value_t sc_logic::or_table[4][4] = {
130 { Log_0, Log_1, Log_X, Log_X },
131 { Log_1, Log_1, Log_1, Log_1 },
132 { Log_X, Log_1, Log_X, Log_X },
133 { Log_X, Log_1, Log_X, Log_X }
134};
135
136const sc_logic_value_t sc_logic::xor_table[4][4] = {
137 { Log_0, Log_1, Log_X, Log_X },
138 { Log_1, Log_0, Log_X, Log_X },
139 { Log_X, Log_X, Log_X, Log_X },
140 { Log_X, Log_X, Log_X, Log_X }
141};
142
143const sc_logic_value_t sc_logic::not_table[4] = {
144 Log_1, Log_0, Log_X, Log_X
145};
146
147// other methods
148void
149sc_logic::scan(::std::istream &is)
150{
151 char c;
152 is >> c;
153 *this = c;
154}
155
156// #ifdef SC_DT_DEPRECATED
157const sc_logic sc_logic_0(Log_0);
158const sc_logic sc_logic_1(Log_1);
159const sc_logic sc_logic_Z(Log_Z);
160const sc_logic sc_logic_X(Log_X);
161// #endif
162
163const sc_logic SC_LOGIC_0(Log_0);
164const sc_logic SC_LOGIC_1(Log_1);
165const sc_logic SC_LOGIC_Z(Log_Z);
166const sc_logic SC_LOGIC_X(Log_X);
167
168} // namespace sc_dt
95}
96
97
98// conversion tables
99const sc_logic_value_t sc_logic::char_to_logic[128] = {
100 Log_0, Log_1, Log_Z, Log_X, Log_X, Log_X, Log_X, Log_X,
101 Log_X, Log_X, Log_X, Log_X, Log_X, Log_X, Log_X, Log_X,
102 Log_X, Log_X, Log_X, Log_X, Log_X, Log_X, Log_X, Log_X,
103 Log_X, Log_X, Log_X, Log_X, Log_X, Log_X, Log_X, Log_X,
104 Log_X, Log_X, Log_X, Log_X, Log_X, Log_X, Log_X, Log_X,
105 Log_X, Log_X, Log_X, Log_X, Log_X, Log_X, Log_X, Log_X,
106 Log_0, Log_1, Log_X, Log_X, Log_X, Log_X, Log_X, Log_X,
107 Log_X, Log_X, Log_X, Log_X, Log_X, Log_X, Log_X, Log_X,
108 Log_X, Log_X, Log_X, Log_X, Log_X, Log_X, Log_X, Log_X,
109 Log_X, Log_X, Log_X, Log_X, Log_X, Log_X, Log_X, Log_X,
110 Log_X, Log_X, Log_X, Log_X, Log_X, Log_X, Log_X, Log_X,
111 Log_X, Log_X, Log_Z, Log_X, Log_X, Log_X, Log_X, Log_X,
112 Log_X, Log_X, Log_X, Log_X, Log_X, Log_X, Log_X, Log_X,
113 Log_X, Log_X, Log_X, Log_X, Log_X, Log_X, Log_X, Log_X,
114 Log_X, Log_X, Log_X, Log_X, Log_X, Log_X, Log_X, Log_X,
115 Log_X, Log_X, Log_Z, Log_X, Log_X, Log_X, Log_X, Log_X
116};
117
118const char sc_logic::logic_to_char[4] = { '0', '1', 'Z', 'X' };
119
120const sc_logic_value_t sc_logic::and_table[4][4] = {
121 { Log_0, Log_0, Log_0, Log_0 },
122 { Log_0, Log_1, Log_X, Log_X },
123 { Log_0, Log_X, Log_X, Log_X },
124 { Log_0, Log_X, Log_X, Log_X }
125};
126
127const sc_logic_value_t sc_logic::or_table[4][4] = {
128 { Log_0, Log_1, Log_X, Log_X },
129 { Log_1, Log_1, Log_1, Log_1 },
130 { Log_X, Log_1, Log_X, Log_X },
131 { Log_X, Log_1, Log_X, Log_X }
132};
133
134const sc_logic_value_t sc_logic::xor_table[4][4] = {
135 { Log_0, Log_1, Log_X, Log_X },
136 { Log_1, Log_0, Log_X, Log_X },
137 { Log_X, Log_X, Log_X, Log_X },
138 { Log_X, Log_X, Log_X, Log_X }
139};
140
141const sc_logic_value_t sc_logic::not_table[4] = {
142 Log_1, Log_0, Log_X, Log_X
143};
144
145// other methods
146void
147sc_logic::scan(::std::istream &is)
148{
149 char c;
150 is >> c;
151 *this = c;
152}
153
154// #ifdef SC_DT_DEPRECATED
155const sc_logic sc_logic_0(Log_0);
156const sc_logic sc_logic_1(Log_1);
157const sc_logic sc_logic_Z(Log_Z);
158const sc_logic sc_logic_X(Log_X);
159// #endif
160
161const sc_logic SC_LOGIC_0(Log_0);
162const sc_logic SC_LOGIC_1(Log_1);
163const sc_logic SC_LOGIC_Z(Log_Z);
164const sc_logic SC_LOGIC_X(Log_X);
165
166} // namespace sc_dt