Bitstream Interpretation Library (BIL)  0.1
DeviceCfgDbFiller.cpp
Go to the documentation of this file.
1 
6 #include <utility>
8 #include <xdlrc/model/Device.hpp>
9 
10 using namespace bil;
11 
12 
14  const Device& device)
15 {
16  // clear device database
17  deviceDb.clear();
18 
19  // get tile types from device
20  const TileTypes& tileTypes = device.tileTypes();
21  size_t tileTypeCount = tileTypes.size();
22 
23  // create one tile type database for every tile type
24  TileTypeCfgDbs& tileTypeDbs = deviceDb.tileTypeDbs();
25  tileTypeDbs.resize(tileTypeCount);
26 
27  // loop over all tile type databases and fill them
28  for (size_t i = 0; i < tileTypeCount; ++i)
29  initTileTypeDb(tileTypeDbs[i], tileTypes[i], i);
30 }
31 
32 
34  const TileType& tileType, size_t tileTypeIndex)
35 {
36  // clear tile type database
37  tileTypeDb.clear();
38 
39  // set its tile type
40  tileTypeDb.typeIndex(tileTypeIndex);
41 
42  // clear map and copy pointer to control sets
43  m_pipControlSetMap.clear();
44  m_pipControlSets = &(tileTypeDb.pipControlSets());
45 
46  // loop over all PIPs and sort them into control sets
47  const PIPs& pips = tileType.pips();
48  size_t pipCount = pips.size();
49  for (size_t i = 0; i < pipCount; ++i)
50  {
51  // get current PIP and create/find its control set
52  const PIP& pip = pips[i];
53  PIPControlSet& controlSet = addPIPControlSet(pip.endWireIndex());
54 
55  // add new PIPBitValue entry to control set
56  PIPBitValues& pipBitValues = controlSet.pipBitValues();
57  size_t count = pipBitValues.size();
58  pipBitValues.push_back(PIPBitValue());
59  PIPBitValue& pipBitValue = pipBitValues[count];
60 
61  // set its properties
62  pipBitValue.pipIndex(i);
64  }
65 
66  // empty map
67  m_pipControlSetMap.clear();
68 
69  // collapse all control sets with only one PIP into one
70  // collapsePIPControlSets(); // Not sure if that's a good idea
71 
72  // empty control sets pointer again
73  m_pipControlSets = 0;
74 }
75 
76 
77 PIPControlSet& DeviceCfgDbFiller::addPIPControlSet(size_t endWireIndex)
78 {
79  // check, if control set for given end wire exists: if not, create it.
80  pipControlSetMap_t::iterator lb = m_pipControlSetMap.lower_bound(endWireIndex);
81  if ((m_pipControlSetMap.end() == lb) || (endWireIndex != lb->first))
82  {
83  // create a new control set
84  size_t count = m_pipControlSets->size();
85  m_pipControlSets->push_back(PIPControlSet());
86  PIPControlSet& controlSet = (*m_pipControlSets)[count];
87 
88  // create a new entry in map
89  pipControlSetMap_t::iterator it =
90  m_pipControlSetMap.insert(lb, std::make_pair(endWireIndex, count));
91 
92  // return it
93  return controlSet;
94  }
95  else
96  {
97  // fetch control set index from map
98  size_t controlSetIndex = lb->second;
99  return (*m_pipControlSets)[controlSetIndex];
100  }
101 }
102 
103 
104 void DeviceCfgDbFiller::collapsePIPControlSets()
105 {
106  // loop over all control sets of a tile type and find first control set,
107  // that has only one PIP
108  size_t pipControlSetCount = m_pipControlSets->size();
109  size_t pipControlSetIndex = pipControlSetCount;
110  for (size_t i = 0; i < pipControlSetCount; ++i)
111  {
112  const PIPControlSet& pipControlSet = (*m_pipControlSets)[i];
113  const PIPBitValues& pipBitValues = pipControlSet.pipBitValues();
114  if (pipBitValues.size() <= 1)
115  {
116  pipControlSetIndex = i;
117  break;
118  }
119  }
120 
121  // If not found, return. Else use this to collapse further single PIP
122  // control sets into it.
123  if (pipControlSetIndex >= pipControlSetCount) return;
124  PIPControlSet& dstPIPControlSet = (*m_pipControlSets)[pipControlSetIndex];
125  PIPBitValues& dstPIPBitValues = dstPIPControlSet.pipBitValues();
126 
127  // loop over control sets again, but start behind found one
128  size_t i = pipControlSetIndex + 1;
129  while (i < m_pipControlSets->size())
130  {
131  // get current control set and its PIPs
132  const PIPControlSet& pipControlSet = (*m_pipControlSets)[i];
133  const PIPBitValues& pipBitValues = pipControlSet.pipBitValues();
134  size_t pipCount = pipBitValues.size();
135  // if it has less than 2 PIPs, copy it to first one, and delete it
136  if (1 >= pipCount)
137  {
138  if (1 == pipCount) dstPIPBitValues.push_back(pipBitValues[0]);
139  m_pipControlSets->erase(m_pipControlSets->begin() + i);
140  }
141  else ++i;
142  }
143 }