1 | #ifndef ADDRESS_H_ |
---|
2 | #define ADDRESS_H_ |
---|
3 | |
---|
4 | #include <systemc.h> |
---|
5 | #include <iomanip> |
---|
6 | #include <iostream> |
---|
7 | #include "raw_address.h" |
---|
8 | |
---|
9 | class Address { |
---|
10 | public: |
---|
11 | unsigned int block_size; |
---|
12 | unsigned int block; |
---|
13 | unsigned int displacement; |
---|
14 | |
---|
15 | // default constructor |
---|
16 | Address (const unsigned int block = 0, const unsigned long displacement = 0, const unsigned int block_size = 0) { |
---|
17 | this->block = block; |
---|
18 | this->displacement = displacement; |
---|
19 | this->block_size = block_size; |
---|
20 | } |
---|
21 | |
---|
22 | Address (const RawAddress req, const int block_size) |
---|
23 | { |
---|
24 | this->block = req.address / block_size; |
---|
25 | this->displacement = req.address % block_size; |
---|
26 | this->block_size = block_size; |
---|
27 | } |
---|
28 | |
---|
29 | inline bool operator == (const Address & rhs) const { |
---|
30 | return (rhs.block * rhs.block_size + rhs.displacement == block * block_size + displacement ); |
---|
31 | } |
---|
32 | |
---|
33 | inline Address& operator = (const Address& rhs) { |
---|
34 | block = rhs.block; |
---|
35 | block_size = rhs.block_size; |
---|
36 | displacement = rhs.displacement; |
---|
37 | return *this; |
---|
38 | } |
---|
39 | |
---|
40 | inline friend void sc_trace(sc_trace_file *tf, const Address & v, const std::string & NAME ) { |
---|
41 | // FIXME |
---|
42 | // sc_trace(tf,v.block, NAME + ".info"); |
---|
43 | // sc_trace(tf,v.displacement, NAME + ".flag"); |
---|
44 | } |
---|
45 | |
---|
46 | inline friend ostream& operator << ( ostream& os, Address const & v ) { |
---|
47 | os << "0x" << hex << std::setfill('0') << std::setw(8) << (v.block * v.block_size + v.displacement) ; |
---|
48 | return os; |
---|
49 | } |
---|
50 | |
---|
51 | inline bool operator < (const Address & rhs) const { |
---|
52 | return (rhs.block * rhs.block_size + rhs.displacement < block * block_size + displacement); |
---|
53 | } |
---|
54 | |
---|
55 | inline const unsigned int as_absolute() { |
---|
56 | return (block * block_size + displacement); |
---|
57 | } |
---|
58 | |
---|
59 | }; |
---|
60 | #endif |
---|
61 | |
---|
62 | |
---|