Bitstream Interpretation Library (BIL)  0.1
RegisterLookup.cpp
Go to the documentation of this file.
1 
9 
10 using namespace bil;
11 
12 
14  m_registers(highestAddress + 1, 0)
15 {
16 
17 }
18 
19 
21 {
22  // check if register address fits in lookup table and if slot is free
23  if (reg.address() >= m_registers.size()) throw Exception();
24  if (0 != m_registers[reg.address()]) throw Exception();
25 
26  // insert register reference into lookup table at its address
27  m_registers[reg.address()] = ®
28 }
29 
30 
32 {
33  // if address can not be deleted (because of address out of range or there
34  // is no register tied to this address), return false
35  if (m_registers.size() <= registerAddress) return false;
36  if (0 == m_registers[registerAddress]) return false;
37 
38  // delete address
39  m_registers[registerAddress] = 0;
40  return true;
41 }
42 
43 
45 {
46  // check if address is in lookup table, if not, return 0
47  if (m_registers.size() <= registerAddress) return 0;
48  // do lookup
49  return m_registers[registerAddress];
50 }