@@ -199,45 +199,25 @@ void OverrideDelayModel::set_base_delay_model(std::unique_ptr<DeltaDelayModel> b
199199 base_delay_model_ = std::move (base_delay_model_obj);
200200}
201201
202- /* *
203- * When writing capnp targetted serialization, always allow compilation when
204- * VTR_ENABLE_CAPNPROTO=OFF. Generally this means throwing an exception instead.
205- */
206- #ifndef VTR_ENABLE_CAPNPROTO
207- # define DISABLE_ERROR \
208- " is disable because VTR_ENABLE_CAPNPROTO=OFF." \
209- " Re-compile with CMake option VTR_ENABLE_CAPNPROTO=ON to enable."
210-
211- void OverrideDelayModel::read (const std::string& /* file*/ ) {
212- VPR_THROW (VPR_ERROR_PLACE, " OverrideDelayModel::read " DISABLE_ERROR);
213- }
214-
215- void OverrideDelayModel::write (const std::string& /* file*/ ) const {
216- VPR_THROW (VPR_ERROR_PLACE, " OverrideDelayModel::write " DISABLE_ERROR);
217- }
218-
219- #else /* VTR_ENABLE_CAPNPROTO */
220-
221- static void ToFloat (float * out, const VprFloatEntry::Reader& in) {
222- // Getting a scalar field is always "get<field name>()".
223- *out = in.getValue ();
224- }
225-
226- static void FromFloat (VprFloatEntry::Builder* out, const float & in) {
227- // Setting a scalar field is always "set<field name>(value)".
228- out->setValue (in);
229- }
230-
231202void OverrideDelayModel::read (const std::string& file) {
203+ #ifndef VTR_ENABLE_CAPNPROTO
204+ VPR_THROW (VPR_ERROR_PLACE,
205+ " OverrideDelayModel::read is disabled because VTR_ENABLE_CAPNPROTO=OFF. "
206+ " Re-compile with CMake option VTR_ENABLE_CAPNPROTO=ON to enable." );
207+ #else
232208 MmapFile f (file);
233209
234210 /* Increase reader limit to 1G words to allow for large files. */
235211 ::capnp::ReaderOptions opts = default_large_capnp_opts ();
236212 ::capnp::FlatArrayMessageReader reader (f.getData (), opts);
237213
214+ auto toFloat = [](float * out, const VprFloatEntry::Reader& in) -> void {
215+ *out = in.getValue ();
216+ };
217+
238218 vtr::NdMatrix<float , 4 > delays;
239219 auto model = reader.getRoot <VprOverrideDelayModel>();
240- ToNdMatrix<4 , VprFloatEntry, float >(&delays, model.getDelays (), ToFloat );
220+ ToNdMatrix<4 , VprFloatEntry, float >(&delays, model.getDelays (), toFloat );
241221
242222 base_delay_model_ = std::make_unique<DeltaDelayModel>(cross_layer_delay_, delays, is_flat_);
243223
@@ -258,14 +238,24 @@ void OverrideDelayModel::read(const std::string& file) {
258238 }
259239
260240 delay_overrides_ = vtr::make_flat_map2 (std::move (overrides_arr));
241+ #endif
261242}
262243
263244void OverrideDelayModel::write (const std::string& file) const {
245+ #ifndef VTR_ENABLE_CAPNPROTO
246+ VPR_THROW (VPR_ERROR_PLACE,
247+ " OverrideDelayModel::write is disabled because VTR_ENABLE_CAPNPROTO=OFF. "
248+ " Re-compile with CMake option VTR_ENABLE_CAPNPROTO=ON to enable.\" );
249+ #else
264250 ::capnp::MallocMessageBuilder builder;
265251 auto model = builder.initRoot<VprOverrideDelayModel>();
266252
253+ auto fromFloat = [](VprFloatEntry::Builder* out, const float& in) -> void {
254+ out->setValue(in);
255+ };
256+
267257 auto delays = model.getDelays();
268- FromNdMatrix<4 , VprFloatEntry, float >(&delays, base_delay_model_->delays (), FromFloat );
258+ FromNdMatrix<4, VprFloatEntry, float>(&delays, base_delay_model_->delays(), fromFloat );
269259
270260 // Non-scalar capnproto fields should be first initialized with
271261 // init<field name>(count), and then accessed from the returned
@@ -285,6 +275,6 @@ void OverrideDelayModel::write(const std::string& file) const {
285275 }
286276
287277 writeMessageToFile(file, &builder);
278+ #endif
288279}
289280
290- #endif
0 commit comments