sc_nbutils.cc (13160:1e959d3afc64) sc_nbutils.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

--- 47 unchanged lines hidden (view full) ---

56// source.
57//
58
59#include <cctype>
60#include <cstdio>
61#include <cstring>
62#include <sstream>
63
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

--- 47 unchanged lines hidden (view full) ---

56// source.
57//
58
59#include <cctype>
60#include <cstdio>
61#include <cstring>
62#include <sstream>
63
64#include "systemc/ext/dt/bit/messages.hh"
65#include "systemc/ext/dt/int/messages.hh"
64#include "systemc/ext/dt/int/sc_nbutils.hh"
65#include "systemc/ext/utils/functions.hh"
66
67namespace sc_dt
68{
69
70// only used within vec_from_str (non-standard, deprecated)
71static inline void

--- 12 unchanged lines hidden (view full) ---

84 "is_valid_base( sc_numrep base ) : "
85 "bases SC_CSD, or ending in _US and _SM are "
86 "not supported");
87 break;
88 default:
89 std::stringstream msg;
90 msg << "is_valid_base( sc_numrep base ) : base = " << base <<
91 " is not valid";
66#include "systemc/ext/dt/int/sc_nbutils.hh"
67#include "systemc/ext/utils/functions.hh"
68
69namespace sc_dt
70{
71
72// only used within vec_from_str (non-standard, deprecated)
73static inline void

--- 12 unchanged lines hidden (view full) ---

86 "is_valid_base( sc_numrep base ) : "
87 "bases SC_CSD, or ending in _US and _SM are "
88 "not supported");
89 break;
90 default:
91 std::stringstream msg;
92 msg << "is_valid_base( sc_numrep base ) : base = " << base <<
93 " is not valid";
92 SC_REPORT_ERROR("(E204) value is not valid", msg.str().c_str() );
94 SC_REPORT_ERROR(sc_core::SC_ID_VALUE_NOT_VALID_, msg.str().c_str());
93 }
94}
95
96// ----------------------------------------------------------------------------
97// ENUM : sc_numrep
98//
99// Enumeration of number representations for character string conversion.
100// ----------------------------------------------------------------------------

--- 127 unchanged lines hidden (view full) ---

228 v += nskip;
229
230 // Handles empty strings or strings without any digits after the
231 // base or base and sign specifier.
232 if (*v == '\0') {
233 static const char msg[] =
234 "get_base_and_sign( const char* v, small_type&, small_type& ) : "
235 "v = \"\" is not valid";
95 }
96}
97
98// ----------------------------------------------------------------------------
99// ENUM : sc_numrep
100//
101// Enumeration of number representations for character string conversion.
102// ----------------------------------------------------------------------------

--- 127 unchanged lines hidden (view full) ---

230 v += nskip;
231
232 // Handles empty strings or strings without any digits after the
233 // base or base and sign specifier.
234 if (*v == '\0') {
235 static const char msg[] =
236 "get_base_and_sign( const char* v, small_type&, small_type& ) : "
237 "v = \"\" is not valid";
236 SC_REPORT_ERROR("conversion failed", msg);
238 SC_REPORT_ERROR(sc_core::SC_ID_CONVERSION_FAILED_, msg);
237 }
238 return v;
239}
240
241//-----------------------------------------------------------------------------
242//"parse_binary_bits"
243//
244// This function parses the supplied string into the supplied vector as a

--- 14 unchanged lines hidden (view full) ---

259 sc_digit data; // Data word now assembling.
260 int delta_n; // src_n - dst_n*BITS_PER_DIGIT.
261 int src_i; // Index in src_p now accessing (left to right).
262 int src_n; // Length of source that is left in bits.
263 int word_i; // Bit within word now accessing (left to right).
264
265 // MAKE SURE WE HAVE A STRING TO PARSE:
266 if (src_p == 0) {
239 }
240 return v;
241}
242
243//-----------------------------------------------------------------------------
244//"parse_binary_bits"
245//
246// This function parses the supplied string into the supplied vector as a

--- 14 unchanged lines hidden (view full) ---

261 sc_digit data; // Data word now assembling.
262 int delta_n; // src_n - dst_n*BITS_PER_DIGIT.
263 int src_i; // Index in src_p now accessing (left to right).
264 int src_n; // Length of source that is left in bits.
265 int word_i; // Bit within word now accessing (left to right).
266
267 // MAKE SURE WE HAVE A STRING TO PARSE:
268 if (src_p == 0) {
267 SC_REPORT_ERROR("conversion failed",
269 SC_REPORT_ERROR(sc_core::SC_ID_CONVERSION_FAILED_,
268 "character string is zero");
269 return;
270 }
271 if (*src_p == 0) {
270 "character string is zero");
271 return;
272 }
273 if (*src_p == 0) {
272 SC_REPORT_ERROR("conversion failed",
274 SC_REPORT_ERROR(sc_core::SC_ID_CONVERSION_FAILED_,
273 "character string is empty");
274 return;
275 }
276
277
278 // INDEX INTO THE SOURCE TO A DEPTH THAT WILL ACCOMODATE OUR SIZE:
279 //
280 // If the source is smaller than our value initialize our value to zero.

--- 35 unchanged lines hidden (view full) ---

316 case 'Z':
317 case 'z': ctrl = ctrl | 1; break;
318 case '0': break;
319 default:
320 {
321 std::stringstream msg;
322 msg << "character string '" << src_p <<
323 "' is not valid";
275 "character string is empty");
276 return;
277 }
278
279
280 // INDEX INTO THE SOURCE TO A DEPTH THAT WILL ACCOMODATE OUR SIZE:
281 //
282 // If the source is smaller than our value initialize our value to zero.

--- 35 unchanged lines hidden (view full) ---

318 case 'Z':
319 case 'z': ctrl = ctrl | 1; break;
320 case '0': break;
321 default:
322 {
323 std::stringstream msg;
324 msg << "character string '" << src_p <<
325 "' is not valid";
324 SC_REPORT_ERROR("conversion failed",
326 SC_REPORT_ERROR(sc_core::SC_ID_CONVERSION_FAILED_,
325 msg.str().c_str());
326 return;
327 }
328 break;
329 }
330 }
331 if (ctrl_p)
332 ctrl_p[word_i] = ctrl;

--- 14 unchanged lines hidden (view full) ---

347 case 'Z':
348 case 'z': ctrl = ctrl | 1; break;
349 case '0': break;
350 default:
351 {
352 std::stringstream msg;
353 msg << "character string '" << src_p <<
354 "' is not valid";
327 msg.str().c_str());
328 return;
329 }
330 break;
331 }
332 }
333 if (ctrl_p)
334 ctrl_p[word_i] = ctrl;

--- 14 unchanged lines hidden (view full) ---

349 case 'Z':
350 case 'z': ctrl = ctrl | 1; break;
351 case '0': break;
352 default:
353 {
354 std::stringstream msg;
355 msg << "character string '" << src_p <<
356 "' is not valid";
355 SC_REPORT_ERROR("conversion failed",
357 SC_REPORT_ERROR(sc_core::SC_ID_CONVERSION_FAILED_,
356 msg.str().c_str());
357 return;
358 }
359 break;
360 }
361 }
362 if (ctrl_p)
363 ctrl_p[word_i] = ctrl;

--- 24 unchanged lines hidden (view full) ---

388 int delta_n; // src_n - dst_n*BITS_PER_DIGIT.
389 int digit_i; // Number of digit now processing.
390 int src_i; // Index in src_p now accessing (left to right).
391 int src_n; // Length of source that is left in bits.
392 int word_i; // Bit within word now accessing (left to right).
393
394 // MAKE SURE WE HAVE A STRING TO PARSE:
395 if (src_p == 0) {
358 msg.str().c_str());
359 return;
360 }
361 break;
362 }
363 }
364 if (ctrl_p)
365 ctrl_p[word_i] = ctrl;

--- 24 unchanged lines hidden (view full) ---

390 int delta_n; // src_n - dst_n*BITS_PER_DIGIT.
391 int digit_i; // Number of digit now processing.
392 int src_i; // Index in src_p now accessing (left to right).
393 int src_n; // Length of source that is left in bits.
394 int word_i; // Bit within word now accessing (left to right).
395
396 // MAKE SURE WE HAVE A STRING TO PARSE:
397 if (src_p == 0) {
396 SC_REPORT_ERROR("conversion failed",
398 SC_REPORT_ERROR(sc_core::SC_ID_CONVERSION_FAILED_,
397 "character string is zero");
398 return;
399 }
400 if (*src_p == 0) {
399 "character string is zero");
400 return;
401 }
402 if (*src_p == 0) {
401 SC_REPORT_ERROR("conversion failed",
403 SC_REPORT_ERROR(sc_core::SC_ID_CONVERSION_FAILED_,
402 "character string is empty");
403 return;
404 }
405
406 // INDEX INTO THE SOURCE TO A DEPTH THAT WILL ACCOMODATE OUR SIZE:
407 //
408 // If the source is smaller than our value initialize our value to zero.
409 src_n = strlen(src_p);

--- 53 unchanged lines hidden (view full) ---

463 case '0': break;
464 case 'Z':
465 case 'z': ctrl = ctrl | 15; break;
466 default:
467 {
468 std::stringstream msg;
469 msg << "character string '" << src_p <<
470 "' is not valid";
404 "character string is empty");
405 return;
406 }
407
408 // INDEX INTO THE SOURCE TO A DEPTH THAT WILL ACCOMODATE OUR SIZE:
409 //
410 // If the source is smaller than our value initialize our value to zero.
411 src_n = strlen(src_p);

--- 53 unchanged lines hidden (view full) ---

465 case '0': break;
466 case 'Z':
467 case 'z': ctrl = ctrl | 15; break;
468 default:
469 {
470 std::stringstream msg;
471 msg << "character string '" << src_p <<
472 "' is not valid";
471 SC_REPORT_ERROR("conversion failed",
473 SC_REPORT_ERROR(sc_core::SC_ID_CONVERSION_FAILED_,
472 msg.str().c_str());
473 return;
474 }
475 break;
476 }
477 }
478 if (ctrl_p)
479 ctrl_p[word_i] = ctrl;

--- 33 unchanged lines hidden (view full) ---

513 case '1': data = data | 1; break;
514 case '0': break;
515 case 'Z':
516 case 'z': ctrl = ctrl | 15; break;
517 default:
518 {
519 std::stringstream msg;
520 msg << "character string '" << src_p << "' is not valid";
474 msg.str().c_str());
475 return;
476 }
477 break;
478 }
479 }
480 if (ctrl_p)
481 ctrl_p[word_i] = ctrl;

--- 33 unchanged lines hidden (view full) ---

515 case '1': data = data | 1; break;
516 case '0': break;
517 case 'Z':
518 case 'z': ctrl = ctrl | 15; break;
519 default:
520 {
521 std::stringstream msg;
522 msg << "character string '" << src_p << "' is not valid";
521 SC_REPORT_ERROR("conversion failed",
523 SC_REPORT_ERROR(sc_core::SC_ID_CONVERSION_FAILED_,
522 msg.str().c_str() );
523 return;
524 }
525 break;
526 }
527 }
528 if (ctrl_p)
529 ctrl_p[word_i] = ctrl;

--- 26 unchanged lines hidden (view full) ---

556 if (base != SC_NOBASE) {
557 if (b == NB_DEFAULT_BASE) {
558 b = base;
559 } else {
560 std::stringstream msg;
561 msg << "vec_from_str( int, int, sc_digit*, const char*, " <<
562 "sc_numrep base ) : base = " << base <<
563 " does not match the default base";
524 msg.str().c_str() );
525 return;
526 }
527 break;
528 }
529 }
530 if (ctrl_p)
531 ctrl_p[word_i] = ctrl;

--- 26 unchanged lines hidden (view full) ---

558 if (base != SC_NOBASE) {
559 if (b == NB_DEFAULT_BASE) {
560 b = base;
561 } else {
562 std::stringstream msg;
563 msg << "vec_from_str( int, int, sc_digit*, const char*, " <<
564 "sc_numrep base ) : base = " << base <<
565 " does not match the default base";
564 SC_REPORT_ERROR("conversion failed",
566 SC_REPORT_ERROR(sc_core::SC_ID_CONVERSION_FAILED_,
565 msg.str().c_str());
566 return 0;
567 }
568 }
569
570 vec_zero(und, u);
571
572 char c;

--- 6 unchanged lines hidden (view full) ---

579 else
580 val = c - '0';
581
582 if (val >= b) {
583 std::stringstream msg;
584 msg << "vec_from_str( int, int, sc_digit*, const char*, " <<
585 "sc_numrep base ) : '" << *v << "' is not a valid " <<
586 "digit in base " << b;
567 msg.str().c_str());
568 return 0;
569 }
570 }
571
572 vec_zero(und, u);
573
574 char c;

--- 6 unchanged lines hidden (view full) ---

581 else
582 val = c - '0';
583
584 if (val >= b) {
585 std::stringstream msg;
586 msg << "vec_from_str( int, int, sc_digit*, const char*, " <<
587 "sc_numrep base ) : '" << *v << "' is not a valid " <<
588 "digit in base " << b;
587 SC_REPORT_ERROR("conversion failed",
589 SC_REPORT_ERROR(sc_core::SC_ID_CONVERSION_FAILED_,
588 msg.str().c_str());
589 return 0;
590 }
591
592 // digit = digit * b + val;
593 vec_mul_small_on(und, u, b);
594
595 if (val)
596 vec_add_small_on(und, u, val);
597 } else {
598 std::stringstream msg;
599 msg << "vec_from_str( int, int, sc_digit*, const char*, " <<
600 "sc_numrep base ) : '" << *v << "' is not a valid " <<
601 "digit in base " << b;
590 msg.str().c_str());
591 return 0;
592 }
593
594 // digit = digit * b + val;
595 vec_mul_small_on(und, u, b);
596
597 if (val)
598 vec_add_small_on(und, u, val);
599 } else {
600 std::stringstream msg;
601 msg << "vec_from_str( int, int, sc_digit*, const char*, " <<
602 "sc_numrep base ) : '" << *v << "' is not a valid " <<
603 "digit in base " << b;
602 SC_REPORT_ERROR("conversion failed",
604 SC_REPORT_ERROR(sc_core::SC_ID_CONVERSION_FAILED_,
603 msg.str().c_str());
604 return 0;
605 }
606 }
607
608 return convert_signed_SM_to_2C_to_SM(s, unb, und, u);
609}
610

--- 1087 unchanged lines hidden (view full) ---

1698 sc_assert((unb > 0) && (und > 0) && (ud != NULL));
1699 sc_assert((0 <= r) && (r <= l) && (l < unb));
1700#endif
1701
1702 if (l < r) {
1703 std::stringstream msg;
1704 msg << "vec_reverse( int, int, sc_digit*, int l, int r ) : " <<
1705 "l = " << l << " < r = " << r << " is not valid",
605 msg.str().c_str());
606 return 0;
607 }
608 }
609
610 return convert_signed_SM_to_2C_to_SM(s, unb, und, u);
611}
612

--- 1087 unchanged lines hidden (view full) ---

1700 sc_assert((unb > 0) && (und > 0) && (ud != NULL));
1701 sc_assert((0 <= r) && (r <= l) && (l < unb));
1702#endif
1703
1704 if (l < r) {
1705 std::stringstream msg;
1706 msg << "vec_reverse( int, int, sc_digit*, int l, int r ) : " <<
1707 "l = " << l << " < r = " << r << " is not valid",
1706 SC_REPORT_ERROR("conversion failed", msg.str().c_str());
1708 SC_REPORT_ERROR(sc_core::SC_ID_CONVERSION_FAILED_, msg.str().c_str());
1707 return;
1708 }
1709
1710 // Make sure that l and r are within bounds.
1711 r = sc_max(r, 0);
1712 l = sc_min(l, unb - 1);
1713
1714 // Allocate memory for processing.

--- 35 unchanged lines hidden ---
1709 return;
1710 }
1711
1712 // Make sure that l and r are within bounds.
1713 r = sc_max(r, 0);
1714 l = sc_min(l, unb - 1);
1715
1716 // Allocate memory for processing.

--- 35 unchanged lines hidden ---