File: sc_uint_base.h

package info (click to toggle)
cbmc 6.6.0-4
  • links: PTS
  • area: main
  • in suites: forky, sid, trixie
  • size: 153,852 kB
  • sloc: cpp: 386,459; ansic: 114,466; java: 28,405; python: 6,003; yacc: 4,552; makefile: 4,041; lex: 2,487; xml: 2,388; sh: 2,050; perl: 557; pascal: 184; javascript: 163; ada: 36
file content (114 lines) | stat: -rw-r--r-- 1,899 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
#ifndef SYSTEMC_SC_UINT_BASE_H
#define SYSTEMC_SC_UINT_BASE_H

#include <cassert>
#include "systemc_util.h"

class sc_uint_subref;
class sc_uint_base;

class sc_uint_subref
{
 friend class sc_uint_base;
 
 public:
  sc_uint_subref(sc_uint_base *_ptr, int _left, int _right)
    : ptr(_ptr), left(_left), right(_right)
  {}

  // TODO: doesn't work
  // operator sc_uint_base ();

  sc_uint_base &operator=(const sc_uint_base &other);
  sc_uint_base &operator=(const sc_uint_subref &other);

  int length() const
  {
    return left-right+1;
  } 

  unsigned int to_uint() const;

 protected:
  sc_uint_base *ptr;
  int left, right;
  
};

class sc_uint_base
{
 friend class sc_uint_subref;

 public:
  explicit sc_uint_base(unsigned long v, int _len)
    : val(v), m_len(_len)
  {
  }

  sc_uint_base(const sc_uint_subref &other);

  sc_uint_base &operator=(const sc_uint_base &other)
  {
    val = other.val;
    return *this;
  }

  sc_uint_base &operator=(const sc_uint_subref &other);
  
  bool operator==(const sc_uint_base &other)
  {
    return val == other.val;
  }

  sc_uint_base operator+=(const sc_uint_base &other)
  {
    val += other.val; 
    return *this;
  }

  sc_uint_base operator-=(const sc_uint_base &other)
  {
    val -= other.val; 
    return *this;
  }

  sc_uint_base operator*=(const sc_uint_base &other)
  {
    val *= other.val; 
    return *this;
  }

  sc_uint_base operator>>=(int v) //uint_type v
  {
    val >>= v; 
    return *this;
  }

  sc_uint_base operator+(const sc_uint_base &other)
  {
    return sc_uint_base(val+other.val, m_len);
  }

  sc_uint_base operator*(const sc_uint_base &other)
  {
    return sc_uint_base(val*other.val, m_len);
  }

  sc_uint_subref range(int left, int right);

  int length() const
  {
    return m_len;
  } 

  unsigned int to_uint() const
  {
    return val;
  }

  bv_type val;
 protected:
  const int m_len;
};

#endif