Deleted Added
sdiff udiff text old ( 12854:c95c35407325 ) new ( 13325:86323e6cc8ec )
full compact
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/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) {
77 SC_REPORT_ERROR("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') {
104 SC_REPORT_ERROR("cannot perform conversion",
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) {
164 SC_REPORT_ERROR("cannot perform conversion",
165 "character string is zero");
166 return std::string();
167 }
168 if (*s == 0) {
169 SC_REPORT_ERROR("cannot perform conversion",
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";
206 SC_REPORT_ERROR("cannot perform conversion",
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 ---