sc_bv_base.cc (12854:c95c35407325) | sc_bv_base.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 --- 41 unchanged lines hidden (view full) --- 50// Revision 1.3 2006/01/13 18:53:53 acg 51// Andy Goodrich: added $Log command so that CVS comments are reproduced in 52// the source. 53// 54 55#include <cstring> 56#include <sstream> 57 | 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 --- 41 unchanged lines hidden (view full) --- 50// Revision 1.3 2006/01/13 18:53:53 acg 51// Andy Goodrich: added $Log command so that CVS comments are reproduced in 52// the source. 53// 54 55#include <cstring> 56#include <sstream> 57 |
58#include "systemc/ext/dt/bit/messages.hh" |
|
58#include "systemc/ext/dt/bit/sc_bv_base.hh" 59#include "systemc/ext/dt/fx/sc_fix.hh" 60#include "systemc/ext/dt/fx/sc_ufix.hh" 61#include "systemc/ext/utils/sc_report.hh" 62 63namespace sc_dt 64{ 65 66// ---------------------------------------------------------------------------- 67// CLASS : sc_bv_base 68// 69// Arbitrary size bit vector base class. 70// ---------------------------------------------------------------------------- 71 72void 73sc_bv_base::init(int length_, bool init_value) 74{ 75 // check the length 76 if (length_ <= 0) { | 59#include "systemc/ext/dt/bit/sc_bv_base.hh" 60#include "systemc/ext/dt/fx/sc_fix.hh" 61#include "systemc/ext/dt/fx/sc_ufix.hh" 62#include "systemc/ext/utils/sc_report.hh" 63 64namespace sc_dt 65{ 66 67// ---------------------------------------------------------------------------- 68// CLASS : sc_bv_base 69// 70// Arbitrary size bit vector base class. 71// ---------------------------------------------------------------------------- 72 73void 74sc_bv_base::init(int length_, bool init_value) 75{ 76 // check the length 77 if (length_ <= 0) { |
77 SC_REPORT_ERROR("zero length", 0); | 78 SC_REPORT_ERROR(sc_core::SC_ID_ZERO_LENGTH_, 0); |
78 sc_core::sc_abort(); // can't recover from here 79 } 80 // allocate memory for the data and control words 81 m_len = length_; 82 m_size = (m_len - 1) / SC_DIGIT_SIZE + 1; 83 m_data = new sc_digit[m_size]; 84 // initialize the bits to 'init_value' 85 sc_digit dw = init_value ? ~SC_DIGIT_ZERO : SC_DIGIT_ZERO; --- 10 unchanged lines hidden (view full) --- 96 // s must have been converted to bin 97 int len = m_len; 98 int s_len = s.length() - 1; 99 int min_len = sc_min(len, s_len); 100 int i = 0; 101 for (; i < min_len; ++i) { 102 char c = s[s_len - i - 1]; 103 if (c != '0' && c != '1') { | 79 sc_core::sc_abort(); // can't recover from here 80 } 81 // allocate memory for the data and control words 82 m_len = length_; 83 m_size = (m_len - 1) / SC_DIGIT_SIZE + 1; 84 m_data = new sc_digit[m_size]; 85 // initialize the bits to 'init_value' 86 sc_digit dw = init_value ? ~SC_DIGIT_ZERO : SC_DIGIT_ZERO; --- 10 unchanged lines hidden (view full) --- 97 // s must have been converted to bin 98 int len = m_len; 99 int s_len = s.length() - 1; 100 int min_len = sc_min(len, s_len); 101 int i = 0; 102 for (; i < min_len; ++i) { 103 char c = s[s_len - i - 1]; 104 if (c != '0' && c != '1') { |
104 SC_REPORT_ERROR("cannot perform conversion", | 105 SC_REPORT_ERROR(sc_core::SC_ID_CANNOT_CONVERT_, |
105 "string can contain only '0' and '1' characters"); 106 // may continue, if suppressed 107 c = '0'; 108 } 109 set_bit(i, sc_logic_value_t(c - '0')); 110 } 111 // if formatted, fill the rest with sign(s), otherwise fill with zeros 112 sc_logic_value_t fill = (s[s_len] == 'F' ? sc_logic_value_t(s[0] - '0') --- 43 unchanged lines hidden (view full) --- 156 157const std::string 158convert_to_bin(const char *s) 159{ 160 // Beware: logic character strings cannot start with '0x' or '0X', 161 // because this is seen as a hexadecimal encoding prefix! 162 163 if (s == 0) { | 106 "string can contain only '0' and '1' characters"); 107 // may continue, if suppressed 108 c = '0'; 109 } 110 set_bit(i, sc_logic_value_t(c - '0')); 111 } 112 // if formatted, fill the rest with sign(s), otherwise fill with zeros 113 sc_logic_value_t fill = (s[s_len] == 'F' ? sc_logic_value_t(s[0] - '0') --- 43 unchanged lines hidden (view full) --- 157 158const std::string 159convert_to_bin(const char *s) 160{ 161 // Beware: logic character strings cannot start with '0x' or '0X', 162 // because this is seen as a hexadecimal encoding prefix! 163 164 if (s == 0) { |
164 SC_REPORT_ERROR("cannot perform conversion", 165 "character string is zero"); | 165 SC_REPORT_ERROR(sc_core::SC_ID_CANNOT_CONVERT_, 166 "character string is zero"); |
166 return std::string(); 167 } 168 if (*s == 0) { | 167 return std::string(); 168 } 169 if (*s == 0) { |
169 SC_REPORT_ERROR("cannot perform conversion", | 170 SC_REPORT_ERROR(sc_core::SC_ID_CANNOT_CONVERT_, |
170 "character string is empty"); 171 return std::string(); 172 } 173 174 int n = strlen(s); 175 int i = 0; 176 if (s[0] == '-' || s[0] == '+') { 177 ++i; --- 20 unchanged lines hidden (view full) --- 198 const char *p = str.c_str() + 2; 199 while (p[1] && p[0] == p[1]) { 200 ++p; 201 } 202 return std::string(p); 203 } catch (const sc_core::sc_report &) { 204 std::stringstream msg; 205 msg << "character string '" << s << "' is not valid"; | 171 "character string is empty"); 172 return std::string(); 173 } 174 175 int n = strlen(s); 176 int i = 0; 177 if (s[0] == '-' || s[0] == '+') { 178 ++i; --- 20 unchanged lines hidden (view full) --- 199 const char *p = str.c_str() + 2; 200 while (p[1] && p[0] == p[1]) { 201 ++p; 202 } 203 return std::string(p); 204 } catch (const sc_core::sc_report &) { 205 std::stringstream msg; 206 msg << "character string '" << s << "' is not valid"; |
206 SC_REPORT_ERROR("cannot perform conversion", | 207 SC_REPORT_ERROR(sc_core::SC_ID_CANNOT_CONVERT_, |
207 msg.str().c_str()); 208 return std::string(); 209 } 210 } 211 } 212 213 // bin by default 214 std::string str(s); --- 17 unchanged lines hidden --- | 208 msg.str().c_str()); 209 return std::string(); 210 } 211 } 212 } 213 214 // bin by default 215 std::string str(s); --- 17 unchanged lines hidden --- |