Bitstream Interpretation Library (BIL)  0.1
XDLExtractor.cpp
Go to the documentation of this file.
1 
7 #include <xdl/model/Design.hpp>
8 #include <xdlrc/model/Device.hpp>
9 
10 using namespace bil;
11 
12 
13 XDLExtractor::XDLExtractor(const Design& design, const Device& device):
14  m_design(&design),
15  m_device(&device)
16 {
17 
18 }
19 
20 
22  TileIndices& tileIndices, size_t tileTypeIndex)
23 {
24  // clear old data
25  units.clear();
26  tileIndices.clear();
27  m_tileUnitMap.clear();
28 
29  // get PIP count of requested tile type
30  const TileTypes& tileTypes = m_device->tileTypes();
31  const TileType& tileType = tileTypes.at(tileTypeIndex);
32  m_pipCount = (tileType.pips()).size();
33 
34  // cache some pointers
35  const Nets& nets = m_design->nets();
36  const Tiles& tiles = m_device->tiles();
37 
38  // loop over all nets in design
39  size_t netCount = nets.size();
40  for (size_t i = 0; i < netCount; ++i)
41  {
42  // loop over all active PIPs in current net
43  const Net& net = nets[i];
44  const PIPRefs& pips = net.pipRefs();
45  size_t activePIPCount = pips.size();
46  for (size_t j = 0; j < activePIPCount; ++j)
47  {
48  const PIPRef pip = pips[j];
49 
50  // lookup PIP's tile location and test, if its type is given one
51  size_t tileIndex = pip.tileIndex();
52  const Tile& tile = tiles.at(tileIndex);
53  if (tile.typeIndex() != tileTypeIndex) continue;
54 
55  // if so, create/find map entry for that tile and set this PIP
56  CorrelationUnit& unit = addCorrelationUnit(tileIndex);
57  unit.setPIPBit(pip.pipIndex());
58  }
59  }
60 
61  // set result lists to match unit count
62  size_t tileUnitCount = m_tileUnitMap.size();
63  units.reserve(tileUnitCount);
64  tileIndices.reserve(tileUnitCount);
65  // copy from map to result lists
66  tileUnitMap_t::const_iterator it = m_tileUnitMap.begin();
67  tileUnitMap_t::const_iterator itEnd = m_tileUnitMap.end();
68  for (; it != itEnd; ++it)
69  {
70  units.push_back(it->second);
71  tileIndices.push_back(it->first);
72  }
73 
74  // clear map
75  m_tileUnitMap.clear();
76 }
77 
78 
79 CorrelationUnit& XDLExtractor::addCorrelationUnit(size_t tileIndex)
80 {
81  // Check, if given tile index is already in map. If so, return its
82  // associated correlation unit.
83  tileUnitMap_t::iterator lb = m_tileUnitMap.lower_bound(tileIndex);
84  if ((m_tileUnitMap.end() != lb) && (tileIndex == lb->first))
85  return lb->second;
86 
87  // create a new entry in map
88  tileUnitMap_t::iterator it =
89  m_tileUnitMap.insert(lb, std::make_pair(tileIndex, CorrelationUnit()));
90  // set its PIP count
91  CorrelationUnit& unit = it->second;
92  unit.pipBitSize(m_pipCount);
93 
94  // return it
95  return unit;
96 }