12
12
13
13
#include " vpr_constraints_uxsdcxx_interface.h"
14
14
15
+ /* *
16
+ * @file
17
+ * @brief The reading of vpr floorplanning constraints is now done via uxsdcxx and the 'vpr_constraints.xsd' file.
18
+ * The interface between the generated code and VPR is provided by VprConstraintsBase, which is in the
19
+ * file 'vpr/src/base/gen/vpr_constraints_uxsdcxx_interface.h'.
20
+ * This file implements the virtual functions from VprConstraintsBase.
21
+ *
22
+ * Overview
23
+ * ========
24
+ * 'vpr_constraints.xsd' is an XML schema that specifies the desired format for a VPR constraints file.
25
+ * If this schema is changed, the following files must be regenerated: 'vpr/src/base/gen/vpr_constraints_uxsdcxx.h' and
26
+ * 'vpr/src/base/gen/vpr_constraints_uxsdcxx_interface.h'.
27
+ *
28
+ * Instructions to Update the Files
29
+ * ================================
30
+ *
31
+ * 1. Clone https://github.com/duck2/uxsdcxx/
32
+ * 2. Run 'python3 -mpip install --user -r requirements.txt'
33
+ * 3. Run 'python3 uxsdcxx.py vpr/src/base/vpr_constraints.xsd'
34
+ * 4. Copy 'vpr_constraints_uxsdcxx.h' and 'vpr_constraints_uxsdcxx_interface.h' to vpr/src/base/gen
35
+ * 5. Run 'make format'
36
+ * 6. Update 'vpr/src/base/vpr_constraints_serializer.h' (this file) by adding or changing functions as needed.
37
+ * If the schema has changed, the compiler will complain that virtual functions are missing if they are
38
+ * not implemented here.
39
+ *
40
+ * Functions in this file
41
+ * ======================
42
+ *
43
+ * This file implements all the functions that are necessary for the load/read interface of uxsdcxx. These are start_load, finish_load,
44
+ * error_encountered, and any function starting with 'set', 'add', 'preallocate' or 'finish'. Some of the load functions (ex. finish_load and
45
+ * the preallocate functions) have been stubbed out because the load could be successfully completed without implementing them.
46
+ *
47
+ * The functions related to the write interface have also been stubbed out because writing vpr_constraints XML files is not needed at this time.
48
+ * These functions can be implemented to make the write interface if needed.
49
+ *
50
+ * For more detail on how the load and write interfaces work with uxsdcxx, refer to 'vpr/src/route/SCHEMA_GENERATOR.md'
51
+ */
52
+
15
53
struct VprConstraintsContextTypes : public uxsd ::DefaultVprConstraintsContextTypes {
16
54
using AddAtomReadContext = void *;
17
55
using AddRegionReadContext = void *;
@@ -61,11 +99,16 @@ class VprConstraintsSerializer final : public uxsd::VprConstraintsBase<VprConstr
61
99
62
100
auto atom_name_regex = std::regex (atom_name);
63
101
64
- std::vector<AtomBlockId> clear_atoms;
65
- atoms_ = clear_atoms;
102
+ atoms_.clear ();
66
103
67
104
atom_id_ = atom_ctx.nlist .find_block (name_pattern);
68
105
106
+ /* The constraints file may either provide a specific atom name or a regex.
107
+ * If the a valid atom ID is found for the atom name, then a specific atom name
108
+ * must have been read in from the file. The if condition checks for this case.
109
+ * The else statement checks for atoms that may match a regex.
110
+ * This code may get slow if many regexes are given in the file.
111
+ */
69
112
if (atom_id_ != AtomBlockId::INVALID ()) {
70
113
atoms_.push_back (atom_id_);
71
114
} else {
@@ -75,8 +118,7 @@ class VprConstraintsSerializer final : public uxsd::VprConstraintsBase<VprConstr
75
118
for (auto block_id : atom_ctx.nlist .blocks ()) {
76
119
auto block_name = atom_ctx.nlist .block_name (block_id);
77
120
78
- if (std::regex_match (block_name, atom_name_regex)) {
79
- VTR_LOG (" Matched block %s with ID %d to regex\n " , block_name.c_str (), block_id);
121
+ if (std::regex_search (block_name, atom_name_regex)) {
80
122
atoms_.push_back (block_id);
81
123
}
82
124
}
@@ -154,9 +196,7 @@ class VprConstraintsSerializer final : public uxsd::VprConstraintsBase<VprConstr
154
196
PartitionId part_id (num_partitions_);
155
197
156
198
for (unsigned int i = 0 ; i < atoms_.size (); i++) {
157
- if (atoms_[i] != AtomBlockId::INVALID ()) {
158
- constraints_.add_constrained_atom (atoms_[i], part_id);
159
- }
199
+ constraints_.add_constrained_atom (atoms_[i], part_id);
160
200
}
161
201
}
162
202
@@ -259,12 +299,20 @@ class VprConstraintsSerializer final : public uxsd::VprConstraintsBase<VprConstr
259
299
260
300
// temp data for loads
261
301
const std::function<void (const char *)>* report_error_;
302
+
303
+ // temp data structures to be loaded during file reading
262
304
Region loaded_region;
263
305
Partition loaded_partition;
264
306
PartitionRegion loaded_part_region;
265
307
VprConstraints constraints_;
308
+
309
+ // temp string used when a method must return a const char*
266
310
std::string temp_;
311
+
312
+ // used to count the number of partitions read in from the file
267
313
int num_partitions_ = 0 ;
314
+
315
+ // used when reading in atom names and regular expressions for atoms
268
316
AtomBlockId atom_id_;
269
317
std::vector<AtomBlockId> atoms_;
270
318
};
0 commit comments