OpenASIP  2.0
HDBManager.cc
Go to the documentation of this file.
1 /*
2  Copyright (c) 2002-2014 Tampere University.
3 
4  This file is part of TTA-Based Codesign Environment (TCE).
5 
6  Permission is hereby granted, free of charge, to any person obtaining a
7  copy of this software and associated documentation files (the "Software"),
8  to deal in the Software without restriction, including without limitation
9  the rights to use, copy, modify, merge, publish, distribute, sublicense,
10  and/or sell copies of the Software, and to permit persons to whom the
11  Software is furnished to do so, subject to the following conditions:
12 
13  The above copyright notice and this permission notice shall be included in
14  all copies or substantial portions of the Software.
15 
16  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17  IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18  FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
19  THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20  LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
21  FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
22  DEALINGS IN THE SOFTWARE.
23  */
24 /**
25  * @file HDBManager.cc
26  *
27  * Implementation of HDBManager class.
28  *
29  * @author Lasse Laasonen 2005 (lasse.laasonen-no.spam-tut.fi)
30  * @author Esa Määttä 2007 (esa.maatta-no.spam-tut.fi)
31  * @author Vinogradov Viacheslav(added Verilog generating) 2012
32  * @note rating: red
33  */
34 
35 #include <string>
36 #include <sstream>
37 #include <list>
38 #include <map>
39 #include <boost/format.hpp>
40 
41 #include "HDBManager.hh"
42 #include "FUEntry.hh"
43 #include "FUArchitecture.hh"
44 #include "FUImplementation.hh"
45 #include "FUPortImplementation.hh"
46 #include "FUExternalPort.hh"
47 #include "RFExternalPort.hh"
48 #include "RFArchitecture.hh"
49 #include "RFEntry.hh"
50 #include "RFImplementation.hh"
51 #include "RFPortImplementation.hh"
53 #include "CostFunctionPlugin.hh"
54 
55 #include "FunctionUnit.hh"
56 #include "FUPort.hh"
57 #include "HWOperation.hh"
58 #include "ExecutionPipeline.hh"
59 #include "PipelineElement.hh"
60 
61 #include "SQLite.hh"
63 #include "DataObject.hh"
64 #include "Application.hh"
65 #include "MapTools.hh"
66 #include "AssocTools.hh"
67 #include "SetTools.hh"
68 
69 #include "FUValidator.hh"
71 #include "Conversion.hh"
72 
73 using std::string;
74 using boost::format;
75 using namespace TTAMachine;
76 
77 // Remove this define when opcode editing should be disabled.
78 // Also edit HDBEditor/FUImplementationDialog.hh/.cc to hide the ability to
79 // modify opcodes
80 #define ALLOW_OPCODE_EDITING
81 
82 const bool READ_ACTION = true;
83 const bool WRITE_ACTION = false;
84 
85 const string IN_DIRECTION = "IN";
86 const string OUT_DIRECTION = "OUT";
87 const string BIDIR_DIRECTION = "BIDIR";
88 const string VHDL_FORMAT = "VHDL";
89 const string VERILOG_FORMAT = "Verilog";
90 const string VHDL_SIM_FORMAT = "VHDL simulation";
91 const string VERILOG_SIM_FORMAT = "Verilog simulation";
92 
93 const int DEFAULT_PORT_WIDTH = 32;
94 
95 /// Possible cost function plugin types
96 const std::string COST_PLUGIN_TYPE_FU = "fu";
97 const std::string COST_PLUGIN_TYPE_RF = "rf";
98 const std::string COST_PLUGIN_TYPE_DECOMP = "decomp";
99 const std::string COST_PLUGIN_TYPE_ICDEC = "icdec";
100 
101 // database table Creation Queries (CQ)
102 const string CQ_FU =
103  "CREATE TABLE fu ("
104  " id INTEGER PRIMARY KEY,"
105  " architecture REFERENCES fu_architecture(id),"
106  " cost_function REFERENCES cost_function_plugin(id));";
107 
108 const string CQ_FU_ARCHITECTURE =
109  "CREATE TABLE fu_architecture("
110  " id INTEGER PRIMARY KEY);";
111 
112 const string CQ_PIPELINE_RESOURCE =
113  "CREATE TABLE pipeline_resource("
114  " id INTEGER PRIMARY KEY,"
115  " fu_arch REFERENCES fu_architecture(id) NOT NULL);";
116 
117 const string CQ_OPERATION_PIPELINE =
118  "CREATE TABLE operation_pipeline("
119  " id INTEGER PRIMARY KEY,"
120  " fu_arch REFERENCES fu_architecture(id) NOT NULL,"
121  " operation REFERENCES operation(id) NOT NULL);";
122 
124  "CREATE TABLE pipeline_resource_usage("
125  " id INTEGER PRIMARY KEY,"
126  " cycle INTEGER NOT NULL,"
127  " resource REFERENCES pipeline_resource(id) NOT NULL,"
128  " pipeline REFERENCES operation_pipeline(id) NOT NULL);";
129 
130 const string CQ_IO_USAGE =
131  "CREATE TABLE io_usage("
132  " id INTEGER PRIMARY KEY,"
133  " cycle INTEGER NOT NULL,"
134  " io_number INTEGER NOT NULL,"
135  " action BOOLEAN NOT NULL,"
136  " pipeline REFERENCES operation_pipeline(id) NOT NULL);";
137 
138 const string CQ_OPERATION =
139  "CREATE TABLE operation("
140  " id INTEGER PRIMARY KEY,"
141  " name TEXT UNIQUE NOT NULL);";
142 
143 const string CQ_FU_DATA_PORT =
144  "CREATE TABLE fu_data_port("
145  " id INTEGER PRIMARY KEY,"
146  " triggers BOOLEAN NOT NULL,"
147  " sets_opcode BOOLEAN NOT NULL,"
148  " guard_support BOOLEAN NOT NULL,"
149  " width INTEGER,"
150  " fu_arch REFERENCES fu_architecture(id));";
151 
152 const string CQ_IO_BINDING =
153  "CREATE TABLE io_binding("
154  " id INTEGER PRIMARY KEY,"
155  " io_number INTEGER NOT NULL,"
156  " port REFERENCES fu_data_port(id) NOT NULL,"
157  " operation REFERENCES operation(id) NOT NULL);";
158 
159 const string CQ_FU_IMPLEMENTATION =
160  "CREATE TABLE fu_implementation("
161  " id INTEGER PRIMARY KEY,"
162  " name TEXT NOT NULL,"
163  " opcode_port TEXT,"
164  " clk_port TEXT NOT NULL,"
165  " rst_port TEXT NOT NULL,"
166  " glock_port TEXT NOT NULL,"
167  " glock_req_port TEXT,"
168  " fu REFERENCES fu(id) UNIQUE NOT NULL);";
169 
170 const string CQ_OPCODE_MAP =
171  "CREATE TABLE opcode_map("
172  " id INTEGER PRIMARY KEY,"
173  " opcode INTEGER NOT NULL,"
174  " operation REFERENCES operation(id) NOT NULL,"
175  " fu_impl REFERENCES fu_implementation(id) NOT NULL);";
176 
177 const string CQ_FU_PORT_MAP =
178  "CREATE TABLE fu_port_map("
179  " id INTEGER PRIMARY KEY,"
180  " name TEXT NOT NULL,"
181  " width_formula TEXT NOT NULL,"
182  " load_port TEXT,"
183  " guard_port TEXT,"
184  " fu_impl REFERENCES fu_implementation(id) NOT NULL,"
185  " arch_port REFERENCES fu_data_port(id) NOT NULL,"
186  " UNIQUE (name, fu_impl));";
187 
188 const string CQ_FU_EXTERNAL_PORT =
189  "CREATE TABLE fu_external_port("
190  " id INTEGER PRIMARY KEY,"
191  " name TEXT NOT NULL,"
192  " direction TEXT NOT NULL,"
193  " width_formula TEXT NOT NULL,"
194  " description TEXT,"
195  " fu_impl REFERENCES fu_implementation(id) NOT NULL, "
196  " UNIQUE (name, fu_impl));";
197 
198 const string CQ_RF_EXTERNAL_PORT =
199  "CREATE TABLE rf_external_port("
200  " id INTEGER PRIMARY KEY,"
201  " name TEXT NOT NULL,"
202  " direction TEXT NOT NULL,"
203  " width_formula TEXT NOT NULL,"
204  " description TEXT,"
205  " rf_impl REFERENCES rf_implementation(id) NOT NULL, "
206  " UNIQUE (name, rf_impl));";
207 
209  "CREATE TABLE fu_implementation_parameter("
210  " id INTEGER PRIMARY KEY,"
211  " name TEXT NOT NULL,"
212  " type TEXT,"
213  " value TEXT,"
214  " fu_impl REFERENCES fu_implementation(id) NOT NULL);";
215 
217  "CREATE TABLE rf_implementation_parameter("
218  " id INTEGER PRIMARY KEY,"
219  " name TEXT NOT NULL,"
220  " type TEXT,"
221  " value TEXT,"
222  " rf_impl REFERENCES rf_implementation(id) NOT NULL);";
223 
225  "CREATE TABLE fu_ext_port_parameter_dependency("
226  " id INTEGER PRIMARY KEY,"
227  " port REFERENCES fu_external_port(id) NOT NULL,"
228  " parameter REFERENCES fu_implementation_parameter(id) NOT NULL);";
229 
231  "CREATE TABLE rf_ext_port_parameter_dependency("
232  " id INTEGER PRIMARY KEY,"
233  " port REFERENCES rf_external_port(id) NOT NULL,"
234  " parameter REFERENCES rf_implementation_parameter(id) NOT NULL);";
235 
236 const string CQ_RF =
237  "CREATE TABLE rf("
238  " id INTEGER PRIMARY KEY,"
239  " architecture REFERENCES rf_architecture(id),"
240  " cost_function REFERENCES cost_function_plugin(id));";
241 
242 const string CQ_RF_ARCHITECTURE =
243  "CREATE TABLE rf_architecture("
244  " id INTEGER PRIMARY KEY,"
245  " size INTEGER,"
246  " width INTEGER,"
247  " read_ports INTEGER NOT NULL,"
248  " write_ports INTEGER NOT NULL,"
249  " bidir_ports INTEGER NOT NULL,"
250  " latency INTEGER NOT NULL,"
251  " max_reads INTEGER NOT NULL,"
252  " max_writes INTEGER NOT NULL,"
253  " guard_support BOOLEAN NOT NULL,"
254  " guard_latency INTEGER NOT NULL,"
255  " zero_register BOOLEAN DEFAULT FALSE);";
256 
257 const string CQ_RF_IMPLEMENTATION =
258  "CREATE TABLE rf_implementation("
259  " id INTEGER PRIMARY KEY,"
260  " name TEXT NOT NULL,"
261  " size_param TEXT,"
262  " width_param TEXT,"
263  " clk_port TEXT NOT NULL,"
264  " rst_port TEXT NOT NULL,"
265  " glock_port TEXT NOT NULL,"
266  " guard_port TEXT,"
267  " rf REFERENCES rf(id) NOT NULL,"
268  " sac_param INTEGER DEFAULT 0);"; // Separate address cycle
269 
270 const string CQ_RF_DATA_PORT =
271  "CREATE TABLE rf_data_port("
272  " id INTEGER PRIMARY KEY,"
273  " name TEXT NOT NULL,"
274  " direction TEXT NOT NULL,"
275  " load_port TEXT NOT NULL,"
276  " opcode_port TEXT NOT NULL,"
277  " opcode_port_width_formula TEXT NOT NULL,"
278  " rf_impl REFERENCES rf_implementation(id),"
279  " UNIQUE (name, rf_impl));";
280 
281 const string CQ_BLOCK_SOURCE_FILE =
282  "CREATE TABLE block_source_file("
283  " id INTEGER PRIMARY KEY,"
284  " file TEXT NOT NULL,"
285  " format REFERENCES format(id));";
286 
287 const string CQ_RF_SOURCE_FILE =
288  "CREATE TABLE rf_source_file("
289  " id INTEGER PRIMARY KEY,"
290  " rf_impl REFERENCES rf_implementation(id),"
291  " file REFERENCES block_source_file(id));";
292 
293 const string CQ_FU_SOURCE_FILE =
294  "CREATE TABLE fu_source_file("
295  " id INTEGER PRIMARY KEY,"
296  " fu_impl REFERENCES fu_implementation(id),"
297  " file REFERENCES block_source_file(id));";
298 
299 const string CQ_FORMAT =
300  "CREATE TABLE format("
301  " id INTEGER PRIMARY KEY,"
302  " format TEXT NOT NULL);";
303 
304 const string CQ_BUS =
305  "CREATE TABLE bus ("
306  " id INTEGER PRIMARY KEY);";
307 
308 const string CQ_SOCKET =
309  "CREATE TABLE socket ("
310  " id INTEGER PRIMARY KEY);";
311 
312 const string CQ_COST_FUNCTION_PLUGIN =
313  "CREATE TABLE cost_function_plugin("
314  " id INTEGER PRIMARY KEY, "
315  " description TEXT, "
316  " name TEXT, "
317  " plugin_file_path TEXT NOT NULL, "
318  " type STRING NOT NULL);"; /// type: {'fu'|'rf'|'decomp'|'icdec'}
319 
321  "CREATE TABLE cost_estimation_data("
322  " id INTEGER PRIMARY KEY, "
323  " plugin_reference REFERENCES cost_function_plugin(id), "
324  " rf_reference REFERENCES rf(id), "
325  " fu_reference REFERENCES fu(id), "
326  " bus_reference REFERENCES bus(id), "
327  " socket_reference REFERENCES socket(id), "
328  " name TEXT, "
329  " value TEXT);";
330 
332  "CREATE INDEX fu_port_map_arch_index ON fu_port_map(arch_port)";
333 
335  "CREATE INDEX fu_impl_entry_index ON fu_implementation(fu)";
336 
338  "CREATE INDEX rf_impl_entry_index ON rf_implementation(rf)";
339 
341  "CREATE TABLE operation_implementation_resource_source_file("
342  " id INTEGER PRIMARY KEY,"
343  " resource REFERENCES operation_implementation_resource(id),"
344  " file REFERENCES block_source_file(id)"
345  ");";
346 
348  "CREATE TABLE operation_implementation_source_file("
349  " id INTEGER PRIMARY KEY,"
350  " operation REFERENCES operation_implementation(id),"
351  " file REFERENCES block_source_file(id)"
352  ");";
353 
355  "CREATE TABLE operation_implementation_resource("
356  " id INTEGER PRIMARY KEY,"
357  " name TEXT NOT NULL"
358  ");";
359 
361  "CREATE TABLE operation_implementation("
362  " id INTEGER PRIMARY KEY,"
363  " name TEXT NOT NULL"
364  ");";
365 
367  "CREATE TABLE operation_implementation_resources("
368  " id INTEGER PRIMARY KEY,"
369  " operation REFERENCES operation_implementation(id),"
370  " resource REFERENCES operation_implementation_resource(id),"
371  " count INTEGER NOT NULL"
372  ");";
373 
375  "CREATE TABLE operation_implementation_variable("
376  " id INTEGER PRIMARY KEY,"
377  " operation REFERENCES operation_implementation(id),"
378  " name TEXT NOT NULL,"
379  " width TEXT NOT NULL,"
380  " type TEXT NOT NULL,"
381  " language TEXT NOT NULL"
382  ");";
383 
384 namespace HDB {
385 
386 HDBManager* HDBManager::instance_ = NULL;
387 
388 /**
389  * The constructor.
390  *
391  * @param hdbFile Name of the HDB file to be managed by the manager.
392  * @exception IOException If connection to the DB cannot be established.
393  */
394 HDBManager::HDBManager(const std::string& hdbFile)
395  : db_(new SQLite()), dbConnection_(NULL), hdbFile_(hdbFile) {
396  if (!FileSystem::fileExists(hdbFile)) {
397  string errorMsg = "File '" + hdbFile + "' doesn't exist.";
398  throw FileNotFound(__FILE__, __LINE__, __func__, errorMsg);
399  }
400 
401  if (!FileSystem::fileIsReadable(hdbFile)) {
402  string errorMsg = "File '" + hdbFile + "' has no read rights.";
403  throw IOException(__FILE__, __LINE__, __func__, errorMsg);
404  }
405 
406  try {
407  dbConnection_ = &db_->connect(hdbFile);
408  } catch (const RelationalDBException& exception) {
409  throw IOException(
410  __FILE__, __LINE__, __func__, exception.errorMessage());
411  }
412 
413  // Update outdated HDB.
414  // Version 0 indicates db without version number also.
415  int dbVersion = dbConnection_->version();
416 
417  // Version 0 -> 1
418  if (dbVersion < 1) {
419  // Initial fu-gen tables and fugen stuff.
426  dbConnection_->updateQuery(std::string(
427  "INSERT INTO format(id,format) VALUES"
428  "(NULL,\"" + VHDL_SIM_FORMAT + "\");"));
429  dbConnection_->updateQuery(std::string(
430  "INSERT INTO format(id,format) VALUES"
431  "(NULL,\"" + VERILOG_SIM_FORMAT + "\");"));
433  }
434 
435  // Version 1 -> 2
436  if (dbVersion < 2) {
437  // Variables for operation snippets.
440  }
441 
442  // Version 2 -> 3
443  if (dbVersion < 3) {
444  // ipxact to resource table
445  dbConnection_->updateQuery(std::string(
446  "ALTER TABLE operation_implementation_resource ADD COLUMN "
447  "ipxact TEXT;"));
449  }
450 
451  // Version 3 -> 4
452  if (dbVersion < 4) {
453  // support for post-operation (for LOADs) and
454  // operation bus definitions for FUGen.
455  dbConnection_->updateQuery(std::string(
456  "ALTER TABLE operation_implementation ADD COLUMN "
457  "bus_definition TEXT;"));
458  dbConnection_->updateQuery(std::string(
459  "ALTER TABLE operation_implementation ADD COLUMN "
460  "post_op_vhdl TEXT;"));
461  dbConnection_->updateQuery(std::string(
462  "ALTER TABLE operation_implementation ADD COLUMN "
463  "post_op_verilog TEXT;"));
465  }
466 
467  // Version 4 -> 5
468  if (dbVersion < 5) {
469  dbConnection_->updateQuery(std::string(
470  "ALTER TABLE operation_implementation_resource ADD COLUMN "
471  "latency INTEGER;"));
472  dbConnection_->updateQuery(std::string(
473  "ALTER TABLE operation_implementation ADD COLUMN "
474  "default_verilog TEXT;"));
475  dbConnection_->updateQuery(std::string(
476  "ALTER TABLE operation_implementation ADD COLUMN "
477  "default_vhdl TEXT;"));
479  }
480 
481  // Version 5 -> 6
482  if (dbVersion < 6) {
483  try {
484  // rename default_vhdl and default_verilog to initial_*
485  // and add latency column
486  dbConnection_->updateQuery(std::string(
487  "ALTER TABLE operation_implementation RENAME TO "
488  "operation_implementation_old"));
489  dbConnection_->updateQuery(std::string(
490  "CREATE TABLE operation_implementation ( "
491  "id INTEGER PRIMARY KEY, "
492  "latency INTEGER, "
493  "name TEXT NOT NULL, "
494  "bus_definition TEXT, "
495  "post_op_vhdl TEXT, "
496  "post_op_verilog TEXT, "
497  "initial_vhdl TEXT, "
498  "initial_verilog TEXT)"));
499  dbConnection_->updateQuery(std::string(
500  "INSERT INTO operation_implementation "
501  "(id, name, bus_definition, post_op_vhdl, post_op_verilog, "
502  "initial_vhdl, initial_verilog) "
503  "SELECT id, name, bus_definition, post_op_vhdl, post_op_verilog, "
504  "default_vhdl, default_verilog "
505  "FROM operation_implementation_old"));
506  dbConnection_->updateQuery(std::string(
507  "DROP TABLE operation_implementation_old"));
508 
510  } catch (const RelationalDBException& exception) {
511  throw IOException(
512  __FILE__, __LINE__, __func__, exception.errorMessage());
513  }
515  }
516 
517  if (dbVersion < 7) {
518  try {
519  if (!hasColumn("rf_architecture", "zero_register")) {
520  addBooleanColumn("rf_architecture", "zero_register");
521  }
522  } catch (const RelationalDBException& exception) {
523  throw IOException(
524  __FILE__, __LINE__, __func__, exception.errorMessage());
525  }
527  }
528 
529 }
530 
531 /**
532  * The destructor.
533  */
536  delete db_;
537 }
538 
539 
540 /**
541  * Creates a new HDB to the given file.
542  *
543  * @param file The database file to be created.
544  * @exception UnreachableStream If the given file exists already or cannot be
545  * created for another reason.
546  */
547 void
548 HDBManager::createNew(const std::string& file) {
549  if (!FileSystem::fileIsCreatable(file)) {
550  const string procName = "HDBManager::createNew";
551  throw UnreachableStream(__FILE__, __LINE__, procName);
552  }
553 
554  try {
555  SQLite db;
556  RelationalDBConnection& connection = db.connect(file);
557 
558  // create tables to the database
559  connection.DDLQuery(CQ_FU);
560  connection.DDLQuery(CQ_FU_ARCHITECTURE);
561  connection.DDLQuery(CQ_PIPELINE_RESOURCE);
562  connection.DDLQuery(CQ_OPERATION_PIPELINE);
564  connection.DDLQuery(CQ_IO_USAGE);
565  connection.DDLQuery(CQ_OPERATION);
566  connection.DDLQuery(CQ_FU_DATA_PORT);
567  connection.DDLQuery(CQ_IO_BINDING);
568  connection.DDLQuery(CQ_FU_IMPLEMENTATION);
569  connection.DDLQuery(CQ_OPCODE_MAP);
570  connection.DDLQuery(CQ_FU_PORT_MAP);
571  connection.DDLQuery(CQ_FU_EXTERNAL_PORT);
574  connection.DDLQuery(CQ_RF);
575  connection.DDLQuery(CQ_RF_ARCHITECTURE);
576  connection.DDLQuery(CQ_RF_IMPLEMENTATION);
578  connection.DDLQuery(CQ_RF_EXTERNAL_PORT);
580  connection.DDLQuery(CQ_RF_DATA_PORT);
581  connection.DDLQuery(CQ_FORMAT);
582  connection.DDLQuery(CQ_BUS);
583  connection.DDLQuery(CQ_SOCKET);
584  connection.DDLQuery(CQ_COST_FUNCTION_PLUGIN);
585  connection.DDLQuery(CQ_COST_ESTIMATION_DATA);
586  connection.DDLQuery(CQ_BLOCK_SOURCE_FILE);
587  connection.DDLQuery(CQ_RF_SOURCE_FILE);
588  connection.DDLQuery(CQ_FU_SOURCE_FILE);
590  connection.DDLQuery(CQ_FU_IMPL_ENTRY_INDEX);
591  connection.DDLQuery(CQ_RF_IMPL_ENTRY_INDEX);
592 
593  // insert the contents to format table
594  insertFileFormats(connection);
595  db.close(connection);
596  } catch (const Exception& e) {
597  debugLog(
598  std::string("Initialization of HDB failed. ") +
599  e.errorMessage());
600  // this should not normally happen, but only if our table creation
601  // queries are broken, thus it's a program error and not input error
602  assert(false);
603  }
604 }
605 
606 /**
607  * Returns the file name of the HDB managed by this HDBManager.
608  *
609  * @return Absolute path to the HDB file.
610  */
611 std::string
614 }
615 
616 
617 /**
618  * Add the given CostFunctionPlugin to the database.
619  *
620  * @param plugin The CostFunctionPlugin to add.
621  * @return ID of the plugin added.
622  * @exception Exception May throw InvalidData if the CostFunctionPlugin type
623  * is unknown.
624  */
625 RowID
627  RowID pluginID;
628  try {
630 
631  // insert into cost_function_plugin table
632  string description = plugin.description();
633  string pluginFilePath = plugin.pluginFilePath();
634  string type = "";
635  switch (plugin.type()) {
637  type = COST_PLUGIN_TYPE_FU;
638  break;
640  type = COST_PLUGIN_TYPE_RF;
641  break;
644  break;
646  type = COST_PLUGIN_TYPE_ICDEC;
647  break;
648  default:
649  InvalidData ex(
650  __FILE__, __LINE__, __func__,
651  (boost::format("Illegal cost_function_plugin type %d.") %
652  type).str());
653  throw ex;
654  break;
655  }
656  string name = plugin.name();
657 
659  std::string(
660  "INSERT INTO cost_function_plugin(id,description,name,"
661  "plugin_file_path,type) VALUES"
662  "(NULL,\"" + description + "\",\"" + name + "\",\"" +
663  pluginFilePath + "\",\"" + type + "\");"));
664  pluginID = dbConnection_->lastInsertRowID();
666  } catch (const RelationalDBException& e) {
668  debugLog(e.errorMessage());
669  assert(false);
670  } catch (const Exception& e) {
672  debugLog(e.errorMessage());
673  assert(false);
674  }
675  return pluginID;
676 }
677 
678 /**
679  * Removes the CostFunctionPlugin that has the given ID.
680  *
681  * @param pluginID ID of the cost plugin.
682  */
683 void
685 
686  try {
688 
689  // remove from cost_function_plugin table
691  std::string(
692  "DELETE FROM cost_function_plugin "
693  "WHERE id=" + Conversion::toString(pluginID) + ";"));
695  std::string(
696  "DELETE FROM cost_estimation_data "
697  "WHERE plugin_reference=" +
698  Conversion::toString(pluginID) + ";"));
699 
701  } catch (const Exception& e) {
703  debugLog(e.errorMessage());
704  assert(false);
705  }
706 }
707 
708 
709 /**
710  * Adds the given FU architecture to the database.
711  *
712  * @param arch The FU architecture to add.
713  * @return ID of the architecture added.
714  * @exception InvalidData If the FU architecture is invalid.
715  */
716 RowID
718  // check the operand bindings of the FU
719  FunctionUnit& fu = arch.architecture();
720  MachineValidatorResults results;
721  FUValidator::checkOperations(fu, results);
723  if (results.errorCount() > 0) {
724  throw InvalidData(
725  __FILE__, __LINE__, __func__, results.error(0).second);
726  }
727 
728  RowID archID;
729  std::map<FUPort*, RowID> portIDMap;
730 
731  try {
733 
734  // insert into fu_architecture table
736  std::string("INSERT INTO fu_architecture(id) VALUES(NULL);"));
737  archID = dbConnection_->lastInsertRowID();
738 
739  // insert into fu_data_port table
740  for (int i = 0; i < fu.operationPortCount(); i++) {
741  FUPort* port = fu.operationPort(i);
742  string query(
743  "INSERT INTO fu_data_port(id,triggers,sets_opcode,"
744  "guard_support,width,fu_arch) "
745  "VALUES(NULL," +
746  Conversion::toString(port->isTriggering()) + "," +
747  Conversion::toString(port->isOpcodeSetting()) + "," +
749  + ",");
750  if (arch.hasParameterizedWidth(port->name())) {
751  query += "NULL,";
752  } else {
753  query += (Conversion::toString(port->width()) + ",");
754  }
755  query += (Conversion::toString(archID) + ");");
756  dbConnection_->updateQuery(query);
757  RowID portID = dbConnection_->lastInsertRowID();
758  portIDMap.insert(std::pair<FUPort*, RowID>(port, portID));
759  }
760 
761  // insert into operation table
762  for (int i = 0; i < fu.operationCount(); i++) {
763  HWOperation* operation = fu.operation(i);
764  if (!containsOperation(operation->name())) {
766  std::string(
767  "INSERT INTO operation(id,name) VALUES(NULL,\"" +
768  operation->name() + "\");"));
769  }
770  }
771 
772  // insert into io_binding table
773  for (int i = 0; i < fu.operationCount(); i++) {
774  HWOperation* operation = fu.operation(i);
775  for (int i = 0; i < fu.operationPortCount(); i++) {
776  FUPort* port = fu.operationPort(i);
777  if (operation->isBound(*port)) {
778  int io = operation->io(*port);
779  string query(
780  "INSERT INTO io_binding(id,io_number,port,operation)"
781  " VALUES(NULL," + Conversion::toString(io) + "," +
783  MapTools::valueForKey<RowID>(portIDMap, port)) +
784  ",(SELECT id FROM operation WHERE "
785  "lower(name)=\"" + operation->name() + "\"));");
786  dbConnection_->updateQuery(query);
787  }
788  }
789  }
790 
791  std::map<HWOperation*, RowID> pLineIDMap;
792 
793  // insert into operation pipeline table
794  for (int i = 0; i < fu.operationCount(); i++) {
795  HWOperation* operation = fu.operation(i);
797  std::string(
798  "INSERT INTO operation_pipeline(id,fu_arch,operation) "
799  "VALUES(NULL," + Conversion::toString(archID) +
800  ",(SELECT id FROM operation WHERE lower(name)=\"" +
801  operation->name() + "\"));"));
802  pLineIDMap.insert(
803  std::pair<HWOperation*, RowID>(
804  operation, dbConnection_->lastInsertRowID()));
805  }
806 
807  // insert into io_usage_table
808  for (int i = 0; i < fu.operationCount(); i++) {
809  HWOperation* operation = fu.operation(i);
810  ExecutionPipeline* pLine = operation->pipeline();
811  for (int cycle = 0; cycle < pLine->latency(); cycle++) {
812  ExecutionPipeline::OperandSet readOperands =
813  pLine->readOperands(cycle);
814  ExecutionPipeline::OperandSet writtenOperands =
815  pLine->writtenOperands(cycle);
816  for (ExecutionPipeline::OperandSet::const_iterator iter =
817  readOperands.begin();
818  iter != readOperands.end(); iter++) {
820  std::string(
821  "INSERT INTO io_usage(id,cycle,io_number,action,"
822  "pipeline) VALUES(NULL," +
823  Conversion::toString(cycle) + "," +
824  Conversion::toString(*iter) + "," +
827  MapTools::valueForKey<RowID>(
828  pLineIDMap, operation)) + ");"));
829  }
830  for (ExecutionPipeline::OperandSet::const_iterator iter =
831  writtenOperands.begin();
832  iter != writtenOperands.end(); iter++) {
834  std::string(
835  "INSERT INTO io_usage(id,cycle,io_number,action,"
836  "pipeline) VALUES(NULL," +
837  Conversion::toString(cycle) + "," +
838  Conversion::toString(*iter) + "," +
841  MapTools::valueForKey<RowID>(
842  pLineIDMap, operation)) + ");"));
843  }
844  }
845  }
846 
847  // insert into pipeline_resource table
848  std::map<PipelineElement*, RowID> pipelineElementMap;
849  for (int i = 0; i < fu.pipelineElementCount(); i++) {
850  PipelineElement* element = fu.pipelineElement(i);
852  std::string(
853  "INSERT INTO pipeline_resource(id,fu_arch) VALUES "
854  "(NULL," + Conversion::toString(archID) + ");"));
855  pipelineElementMap.insert(
856  std::pair<PipelineElement*, RowID>(
857  element, dbConnection_->lastInsertRowID()));
858  }
859 
860  // insert into pipeline_resource_usage table
861  for (int i = 0; i < fu.operationCount(); i++) {
862  HWOperation* operation = fu.operation(i);
863  ExecutionPipeline* pLine = operation->pipeline();
864  for (int i = 0; i < fu.pipelineElementCount(); i++) {
865  PipelineElement* element = fu.pipelineElement(i);
866  for (int cycle = 0; cycle < pLine->latency(); cycle++) {
867  if (pLine->isResourceUsed(element->name(), cycle)) {
868  string resID = Conversion::toString(
869  MapTools::valueForKey<RowID>(
870  pipelineElementMap, element));
871  string pLineID = Conversion::toString(
872  MapTools::valueForKey<RowID>(
873  pLineIDMap, operation));
875  std::string(
876  "INSERT INTO pipeline_resource_usage(id,"
877  "cycle,resource,pipeline) VALUES(NULL," +
878  Conversion::toString(cycle) + "," +
879  resID + "," + pLineID + ");"));
880  }
881  }
882  }
883  }
884 
886 
887  } catch (const Exception& e) {
889  debugLog(e.errorMessage());
890  assert(false);
891  }
892 
893  return archID;
894 }
895 
896 /**
897  * Tells whether the FU architecture that has the given ID can be removed
898  * from the database. It can be removed only if no FU entry uses it.
899  *
900  * @param archID ID of the FU architecture.
901  * @return True if the architecture can be removed, otherwise false.
902  */
903 bool
905 
906  // check whether the architecture is used by FU entries
907  try {
909  std::string(
910  "SELECT id FROM fu WHERE architecture=" +
911  Conversion::toString(archID) + ";"));
912  if (queryResult->hasNext()) {
913  // there is an FU entry using the architecture
914  delete queryResult;
915  return false;
916  } else {
917  delete queryResult;
918  return true;
919  }
920  } catch (const Exception& e) {
921  debugLog(e.errorMessage());
922  assert(false);
923  }
924 
925  // dummy return to avoid compiler whining
926  assert(false);
927  return false;
928 }
929 
930 
931 /**
932  * Removes the FU architecture that has the given ID. The architecture is
933  * removed only it is not used by any FU entry. Otherwise an exception is
934  * thrown.
935  *
936  * @param archID ID of the FU architecture.
937  * @exception InvalidData If the architecture cannot be removed since it
938  * is used by some FU entry.
939  */
940 void
942  if (!canRemoveFUArchitecture(archID)) {
943  throw InvalidData(__FILE__, __LINE__, __func__);
944  }
945 
946  try {
948 
949  // remove from io_binding table
951  std::string(
952  "DELETE FROM io_binding "
953  "WHERE port IN "
954  "(SELECT id "
955  "FROM fu_data_port "
956  "WHERE fu_arch=" + Conversion::toString(archID) + ");"));
957 
958  // remove from fu_data_port table
960  std::string(
961  "DELETE FROM fu_data_port "
962  "WHERE fu_arch=" + Conversion::toString(archID) + ";"));
963 
964  // remove from io_usage_table
966  std::string(
967  "DELETE FROM io_usage "
968  "WHERE pipeline IN "
969  "(SELECT id FROM operation_pipeline "
970  "WHERE fu_arch=" + Conversion::toString(archID) + ");"));
971 
972  // remove from pipeline_resource_usage table
974  std::string(
975  "DELETE FROM pipeline_resource_usage "
976  "WHERE pipeline IN "
977  "(SELECT id FROM operation_pipeline "
978  "WHERE fu_arch=" + Conversion::toString(archID) + ");"));
979 
980  // remove from pipeline_resource_table
982  std::string(
983  "DELETE FROM pipeline_resource "
984  "WHERE fu_arch=" + Conversion::toString(archID) + ";"));
985 
986  // remove from operation_pipeline_table
988  std::string(
989  "DELETE FROM operation_pipeline "
990  "WHERE fu_arch=" + Conversion::toString(archID) + ";"));
991 
992  // remove from fu_architecture table
994  std::string(
995  "DELETE FROM fu_architecture "
996  "WHERE id=" + Conversion::toString(archID) + ";"));
997 
999 
1000  } catch (const Exception& e) {
1002  debugLog(e.errorMessage());
1003  assert(false);
1004  }
1005 }
1006 
1007 /**
1008  * Adds an empty FU entry to the database.
1009  *
1010  * @param entry The FU entry.
1011  * @return ID of the added FU entry.
1012  */
1013 RowID
1015  try {
1017  std::string("INSERT INTO fu(id) VALUES(NULL);"));
1018  return dbConnection_->lastInsertRowID();
1019  } catch (const Exception& e) {
1020  debugLog(e.errorMessage());
1021  assert(false);
1022  }
1023 
1024  // dummy return to avoid compiler whining
1025  assert(false);
1026  return 0;
1027 }
1028 
1029 
1030 /**
1031  * Removes the FU entry that has the given ID from the database.
1032  *
1033  * The entry is removed entirely, meaning that all also FU implementation
1034  * and cost estimation data of that entry are removed.
1035  *
1036  * @param id The ID of the FU entry.
1037  */
1038 void
1040 
1041  if (!hasFUEntry(id)) {
1042  return;
1043  }
1044 
1045  // remove implementation
1046  try {
1047  // get the ID of the implementation
1049  std::string(
1050  "SELECT id FROM fu_implementation "
1051  "WHERE fu=" + Conversion::toString(id) + ";"));
1052  if (result->hasNext()) {
1053  result->next();
1054  const DataObject& implIDData = result->data(0);
1055  int implID = implIDData.integerValue();
1056  removeFUImplementation(implID);
1057  }
1058  delete result;
1059  } catch (const Exception& e) {
1060  debugLog(e.errorMessage());
1061  assert(false);
1062  }
1063 
1064  // remove cost estimation data
1065  try {
1066  // get the IDs of cost estimation datas
1068  std::string(
1069  "SELECT id FROM cost_estimation_data "
1070  "WHERE fu_reference=" + Conversion::toString(id) + ";"));
1071  while (result->hasNext()) {
1072  result->next();
1073  const DataObject& costIDData = result->data(0);
1074  int dataID = costIDData.integerValue();
1075  removeCostEstimationData(dataID);
1076  }
1077  delete result;
1078  } catch (const Exception& e) {
1079  debugLog(e.errorMessage());
1080  assert(false);
1081  }
1082 
1083  // remove from fu table
1084  try {
1086  std::string(
1087  "DELETE FROM fu "
1088  "WHERE id=" + Conversion::toString(id) + ";"));
1089  } catch (const Exception& e) {
1090  debugLog(e.errorMessage());
1091  assert(false);
1092  }
1093 }
1094 
1095 
1096 /**
1097  * Adds the implementation of the given FU entry to the database.
1098  *
1099  * In practice the implementation is added for the FU entry that has the
1100  * same ID as the given FUEntry instance. The given FUEntry instance must
1101  * also have an architecture similar to the architecture of the FU entry
1102  * in the database. This is required in port mapping.
1103  *
1104  * @param entry The FU entry containing the implementation to add.
1105  * @return ID of the implementation that was added.
1106  * @exception InvalidData If the given FUEntry instance is invalid or
1107  * if the FU entry does not have architecture in
1108  * the database of if the FU entry has an
1109  * implementation already.
1110  */
1111 RowID
1113  if (!entry.hasID() || !entry.hasImplementation() ||
1114  !entry.hasArchitecture() || !hasFUEntry(entry.id())) {
1115  throw InvalidData(__FILE__, __LINE__, __func__);
1116  }
1117 
1118  FUImplementation& impl = entry.implementation();
1119  FUArchitecture& arch = entry.architecture();
1120  FunctionUnit& fu = arch.architecture();
1121 
1122  FUEntry* existingEntry = fuByEntryID(entry.id());
1123  if (existingEntry->hasImplementation() ||
1124  !existingEntry->hasArchitecture()) {
1125  delete existingEntry;
1126  throw InvalidData(__FILE__, __LINE__, __func__);
1127  }
1128  delete existingEntry;
1129  existingEntry = NULL;
1130 
1131  RowID archID = fuArchitectureID(entry.id());
1132  RowID implID;
1133 
1134  try {
1136 
1137  // insert into fu_implementation table
1138  string module = impl.moduleName();
1139  string opcPort = impl.opcodePort();
1140  string clkPort = impl.clkPort();
1141  string rstPort = impl.rstPort();
1142  string glockPort = impl.glockPort();
1143  string glockReqPort = impl.glockReqPort();
1144 
1146  std::string(
1147  "INSERT INTO fu_implementation(id,name,opcode_port,"
1148  "clk_port,rst_port,glock_port,glock_req_port,fu) VALUES"
1149  "(NULL,\"" + module + "\",\"" + opcPort + "\",\"" +
1150  clkPort + "\",\"" + rstPort + "\",\"" + glockPort + "\",\""
1151  + glockReqPort + "\"," + Conversion::toString(entry.id())
1152  + ");"));
1153  implID = dbConnection_->lastInsertRowID();
1154 
1155  // insert into fu_port_map table
1156  for (int i = 0; i < impl.architecturePortCount(); i++) {
1157  FUPortImplementation& portImpl = impl.architecturePort(i);
1158  string name = portImpl.name();
1159  string widthFormula = portImpl.widthFormula();
1160  string loadPort = portImpl.loadPort();
1161  string guardPort = portImpl.guardPort();
1162  string archPortName = portImpl.architecturePort();
1163  if (!fu.hasOperationPort(archPortName)) {
1164  throw InvalidData(__FILE__, __LINE__, __func__);
1165  }
1166  FUPort* port = fu.operationPort(archPortName);
1167  bool portAdded = false;
1168  for (int j = 0; j < fu.operationCount(); j++) {
1169  HWOperation* operation = fu.operation(j);
1170  if (operation->isBound(*port)) {
1171  int io = operation->io(*port);
1172  // find the fu_data_port from DB
1174  std::string(
1175  "SELECT fu_data_port.id FROM fu_data_port,"
1176  "io_binding,operation WHERE "
1177  "fu_data_port.fu_arch=" +
1178  Conversion::toString(archID) +
1179  " AND io_binding.port=fu_data_port.id AND "
1180  "io_binding.io_number=" +
1181  Conversion::toString(io) +
1182  " AND lower(operation.name)=\"" +
1183  operation->name() +
1184  "\" AND io_binding.operation=operation.id;"));
1185  if (!result->hasNext()) {
1186  delete result;
1187  throw InvalidData(__FILE__, __LINE__, __func__);
1188  }
1189  result->next();
1190  string portID = result->data(0).stringValue();
1191  delete result;
1192 
1193  // update fu_port_map table
1195  std::string(
1196  "INSERT INTO fu_port_map(id,name,width_formula,"
1197  "load_port,guard_port,fu_impl,arch_port) VALUES"
1198  "(NULL,\"" + name + "\",\"" + widthFormula +
1199  "\",\"" + loadPort + "\",\"" + guardPort +
1200  "\"," + Conversion::toString(implID) + "," +
1201  portID + ");"));
1202  portAdded = true;
1203  break;
1204  }
1205  }
1206 
1207  if (!portAdded) {
1208  throw InvalidData(__FILE__, __LINE__, __func__);
1209  }
1210  }
1211 #ifdef ALLOW_OPCODE_EDITING
1212  // insert into opcode_map table
1213  for (int i = 0; i < fu.operationCount(); i++) {
1214  HWOperation* operation = fu.operation(i);
1215  if (!containsOperation(operation->name())) {
1216  format errorMsg(
1217  "FU implementation uses unknown operation %1%.");
1218  errorMsg % operation->name();
1219  throw InvalidData(
1220  __FILE__, __LINE__, __func__, errorMsg.str());
1221  }
1222  if (fu.operationCount() > 1 &&
1223  !impl.hasOpcode(operation->name())) {
1224  format errorMsg("Opcode not defined for operation %1%.");
1225  errorMsg % operation->name();
1226  throw InvalidData(
1227  __FILE__, __LINE__, __func__, errorMsg.str());
1228  }
1229  if (fu.operationCount() > 1) {
1230  int opcode = impl.opcode(operation->name());
1232  std::string(
1233  "INSERT INTO opcode_map(id,opcode,operation,fu_impl)"
1234  " VALUES(NULL," + Conversion::toString(opcode) +
1235  ",(SELECT id FROM operation WHERE lower(name)=\"" +
1236  operation->name() + "\")," +
1237  Conversion::toString(implID) + ");"));
1238  }
1239  }
1240 #endif
1241  // insert into fu_external_port table
1242  for (int i = 0; i < impl.externalPortCount(); i++) {
1243  FUExternalPort& port = impl.externalPort(i);
1244  string direction = directionString(port.direction());
1246  std::string(
1247  "INSERT INTO fu_external_port(id,name,direction,"
1248  "width_formula,description,fu_impl) VALUES(NULL,\"" +
1249  port.name() + "\",\"" + direction + "\",\"" +
1250  port.widthFormula() + "\",\"" + port.description() +
1251  "\"," + Conversion::toString(implID) + ");"));
1252  }
1253 
1254  // insert into fu_implementation_parameter table
1255  for (int i = 0; i < impl.parameterCount(); i++) {
1256  FUImplementation::Parameter param = impl.parameter(i);
1258  std::string(
1259  "INSERT INTO fu_implementation_parameter(id,name,type,"
1260  "value,fu_impl) VALUES(NULL,\"" + param.name +
1261  "\",\"" + param.type + "\",\"" + param.value +
1262  "\"," + Conversion::toString(implID) + ");"));
1263  }
1264 
1265  // insert into fu_ext_port_parameter_dependency table
1266  for (int i = 0; i < impl.externalPortCount(); i++) {
1267  FUExternalPort& port = impl.externalPort(i);
1268  for (int i = 0; i < port.parameterDependencyCount(); i++) {
1269  string param = port.parameterDependency(i);
1271  std::string(
1272  "INSERT INTO fu_ext_port_parameter_dependency(id,"
1273  "port,parameter) VALUES(NULL,(SELECT id FROM "
1274  "fu_external_port WHERE fu_impl=" +
1275  Conversion::toString(implID) + " AND name=\"" +
1276  port.name() + "\"),(SELECT id FROM "
1277  "fu_implementation_parameter WHERE fu_impl=" +
1278  Conversion::toString(implID) + " AND name=\"" +
1279  param + "\"));"));
1280  }
1281  }
1282 
1283  // insert into block_source_file table
1284  for (int i = 0; i < impl.implementationFileCount(); i++) {
1285  BlockImplementationFile& file = impl.file(i);
1287  }
1288 
1289  // insert into fu_source_file table
1290  for (int i = 0; i < impl.implementationFileCount(); i++) {
1291  BlockImplementationFile& file = impl.file(i);
1292  string path = file.pathToFile();
1294  std::string(
1295  "INSERT INTO fu_source_file(id,fu_impl,file) "
1296  "VALUES(NULL," + Conversion::toString(implID) +
1297  ",(SELECT id FROM block_source_file WHERE file=\"" +
1298  path + "\"));"));
1299  }
1300 
1301  dbConnection_->commit();
1302 
1303  } catch (const RelationalDBException& e) {
1305  debugLog(e.errorMessage());
1306  assert(false);
1307  } catch (const InvalidData& e) {
1309  throw;
1310  } catch (const Exception& e) {
1312  debugLog(e.errorMessage());
1313  assert(false);
1314  }
1315 
1316  return implID;
1317 }
1318 
1319 /**
1320  * Removes the given FU implementation from the database.
1321  *
1322  * @param implID ID of the FU implementation.
1323  */
1324 void
1326 
1327  try {
1329 
1330  // remove from fu_ext_port_parameter_dependency table
1332  std::string(
1333  "DELETE FROM fu_ext_port_parameter_dependency "
1334  "WHERE parameter in (SELECT ALL id FROM "
1335  "fu_implementation_parameter WHERE fu_impl="
1336  + Conversion::toString(implID) + ");"));
1337 
1338  // remove from fu_external_port table
1340  std::string(
1341  "DELETE FROM fu_external_port "
1342  "WHERE fu_impl=" + Conversion::toString(implID) + ";"));
1343 
1344  // remove from fu_port_map table
1346  std::string(
1347  "DELETE FROM fu_port_map "
1348  "WHERE fu_impl=" + Conversion::toString(implID) + ";"));
1349 
1350  // remove from opcode_map table
1352  std::string(
1353  "DELETE FROM opcode_map "
1354  "WHERE fu_impl=" + Conversion::toString(implID) + ";"));
1355 
1356  // remove from fu_implementation_parameter
1358  std::string(
1359  "DELETE FROM fu_implementation_parameter "
1360  "WHERE fu_impl=" + Conversion::toString(implID) + ";"));
1361 
1362  // remove from fu_source_file
1364  std::string(
1365  "DELETE FROM fu_source_file "
1366  "WHERE fu_impl=" + Conversion::toString(implID) + ";"));
1367 
1368  // remove from block_source_file
1370  std::string(
1371  "DELETE FROM block_source_file "
1372  "WHERE id NOT IN "
1373  "(SELECT file FROM fu_source_file UNION "
1374  "SELECT file FROM rf_source_file);"));
1375 
1376  // remove from fu_implementation
1378  std::string(
1379  "DELETE FROM fu_implementation "
1380  "WHERE id=" + Conversion::toString(implID) + ";"));
1381 
1382  dbConnection_->commit();
1383 
1384  } catch (const Exception& e) {
1386  debugLog(e.errorMessage());
1387  assert(false);
1388  }
1389 }
1390 
1391 
1392 /**
1393  * Sets the given architecture for the given FU entry.
1394  *
1395  * @param fuID ID of the FU entry.
1396  * @param archID ID of the FU architecture.
1397  * @exception InvalidData If the FU entry has an implementation already or
1398  * if the HDB does not have FU or architecture by the given ID.
1399  */
1400 void
1402  if (!hasFUEntry(fuID) || !containsFUArchitecture(archID)) {
1403  throw InvalidData(__FILE__, __LINE__, __func__);
1404  }
1405 
1406  FUEntry* entry = fuByEntryID(fuID);
1407  if (entry->hasImplementation()) {
1408  throw InvalidData(__FILE__, __LINE__, __func__);
1409  }
1410 
1411  // set the architecture
1412  try {
1414  std::string(
1415  "UPDATE fu SET architecture=" +
1416  Conversion::toString(archID) + " WHERE id=" +
1417  Conversion::toString(fuID) + ";"));
1418  } catch (const Exception& e) {
1419  debugLog(e.errorMessage());
1420  assert(false);
1421  }
1422 }
1423 
1424 /**
1425  * Unsets the architecture of the given FU entry.
1426  *
1427  * @param fuID ID of the FU entry.
1428  * @exception InvalidData If the HDB does not contain the given FU entry
1429  * or if the FU entry has an implementation.
1430  */
1431 void
1433  if (!hasFUEntry(fuID)) {
1434  throw InvalidData(__FILE__, __LINE__, __func__);
1435  }
1436 
1437  FUEntry* entry = fuByEntryID(fuID);
1438  if (entry->hasImplementation()) {
1439  throw InvalidData(__FILE__, __LINE__, __func__);
1440  }
1441 
1442  // unset the architecture
1443  try {
1445  std::string(
1446  "UPDATE fu SET architecture=NULL WHERE id=" +
1447  Conversion::toString(fuID)));
1448  } catch (const Exception& e) {
1449  debugLog(e.errorMessage());
1450  assert(false);
1451  }
1452 }
1453 
1454 /**
1455  * Adds the given RF architecture to the HDB.
1456  *
1457  * @param architecture The architecture to add.
1458  * @return ID of the architecture added.
1459  */
1460 RowID
1461 HDBManager::addRFArchitecture(const RFArchitecture& architecture) const {
1462 
1463  try {
1464  string query =
1465  "INSERT INTO rf_architecture(id,size,width,read_ports,"
1466  "write_ports,bidir_ports,latency,max_reads,max_writes,"
1467  "guard_support,guard_latency,zero_register) VALUES(NULL,";
1468  if (architecture.hasParameterizedSize()) {
1469  query += "NULL,";
1470  } else {
1471  query += (Conversion::toString(architecture.size()) + ",");
1472  }
1473  if (architecture.hasParameterizedWidth()) {
1474  query += "NULL,";
1475  } else {
1476  query += (Conversion::toString(architecture.width()) + ",");
1477  }
1478  query += (Conversion::toString(architecture.readPortCount()) + ",");
1479  query += (Conversion::toString(architecture.writePortCount()) + ",");
1480  query += (Conversion::toString(architecture.bidirPortCount()) + ",");
1481  query += (Conversion::toString(architecture.latency()) + ",");
1482  query += (Conversion::toString(architecture.maxReads()) + ",");
1483  query += (Conversion::toString(architecture.maxWrites()) + ",");
1484  query +=
1485  (Conversion::toString(architecture.hasGuardSupport()) + ",");
1486  query += (Conversion::toString(architecture.guardLatency()) + ",");
1487  query += (Conversion::toString(architecture.zeroRegister()));
1488  query += ");";
1489 
1490  dbConnection_->updateQuery(query);
1491  } catch (const Exception& e) {
1492  debugLog(e.errorMessage());
1493  assert(false);
1494  }
1495 
1496  return dbConnection_->lastInsertRowID();
1497 }
1498 
1499 
1500 /**
1501  * Tells whether the given RF architecture can be removed.
1502  *
1503  * The architecture can be removed if it is not used by any RF entry.
1504  *
1505  * @param archID ID of the RF architecture.
1506  */
1507 bool
1509  try {
1511  std::string(
1512  "SELECT id FROM rf WHERE architecture=" +
1513  Conversion::toString(archID) + ";"));
1514  bool returnValue = !result->hasNext();
1515  delete result;
1516  return returnValue;
1517  } catch (const Exception& e) {
1518  debugLog(e.errorMessage());
1519  assert(false);
1520  }
1521 
1522  // dummy return to avoid compiler whining
1523  assert(false);
1524  return false;
1525 }
1526 
1527 
1528 /**
1529  * Removes the RF architecture that has the given ID.
1530  *
1531  * @param archID ID of the RF architecture.
1532  * @exception InvalidData If the RF architecture cannot be removed.
1533  */
1534 void
1536  if (!canRemoveRFArchitecture(archID)) {
1537  throw InvalidData(__FILE__, __LINE__, __func__);
1538  }
1539 
1540  try {
1542  std::string(
1543  "DELETE FROM rf_architecture WHERE id=" +
1544  Conversion::toString(archID) + ";"));
1545  } catch (const Exception& e) {
1546  debugLog(e.errorMessage());
1547  assert(false);
1548  }
1549 }
1550 
1551 /**
1552  * Adds an empty RF entry to the database.
1553  *
1554  * @return ID of the entry added.
1555  */
1556 RowID
1558  try {
1560  std::string(
1561  "INSERT INTO rf(id,architecture,cost_function) "
1562  "VALUES(NULL,NULL,NULL);"));
1563  return dbConnection_->lastInsertRowID();
1564  } catch (const Exception& e) {
1565  debugLog(e.errorMessage());
1566  assert(false);
1567  }
1568 
1569  // dummy return to avoid compiler whining
1570  assert(false);
1571  return 0;
1572 }
1573 
1574 
1575 /**
1576  * Removes the RF entry that has the given ID.
1577  *
1578  * Cost estimation data and implementation of the entry are removed too.
1579  *
1580  * @param id ID of the RF entry.
1581  */
1582 void
1584 
1585  if (!hasRFEntry(id)) {
1586  return;
1587  }
1588 
1589  // remove from cost_estimation_data
1590  try {
1592  std::string(
1593  "DELETE FROM cost_estimation_data WHERE rf_reference=" +
1594  Conversion::toString(id) + ";"));
1595  } catch (const Exception& e) {
1596  debugLog(e.errorMessage());
1597  assert(false);
1598  }
1599 
1600  // remove implementation
1601  try {
1603  std::string(
1604  "SELECT id FROM rf_implementation WHERE rf=" +
1605  Conversion::toString(id) + ";"));
1606  if (result->hasNext()) {
1607  result->next();
1608  RowID implID = result->data(0).integerValue();
1609  removeRFImplementation(implID);
1610  }
1611  delete result;
1612  } catch (const Exception& e) {
1613  debugLog(e.errorMessage());
1614  assert(false);
1615  }
1616 
1617  // remove the entry
1618  try {
1620  std::string(
1621  "DELETE FROM rf WHERE id=" + Conversion::toString(id)
1622  + ";"));
1623  } catch (const Exception& e) {
1624  debugLog(e.errorMessage());
1625  assert(false);
1626  }
1627 }
1628 
1629 
1630 /**
1631  * Adds an implementation for the the given RF entry.
1632  *
1633  * @param implementation The implementation to add.
1634  * @param rfEntryID ID of the RF entry.
1635  * @exception InvalidData If the RF entry has an implementation already or
1636  * if the database does not contain an RF entry
1637  * with the given ID.
1638  */
1639 RowID
1641  const RFImplementation& implementation, RowID rfEntryID) {
1642  if (!hasRFEntry(rfEntryID)) {
1643  throw InvalidData(__FILE__, __LINE__, __func__);
1644  }
1645 
1646  RFEntry* entry = rfByEntryID(rfEntryID);
1647  if (entry->hasImplementation()) {
1648  throw InvalidData(__FILE__, __LINE__, __func__);
1649  }
1650  delete entry;
1651  entry = NULL;
1652 
1653  if(!hasColumn("rf_implementation", "sac_param")) {
1654  addBooleanColumn("rf_implementation", "sac_param");
1655  }
1656 
1657  // Create tables for external ports, parameters and parameter dependecies
1658  // if needed.
1659  if (!dbConnection_->tableExistsInDB("rf_implementation_parameter")) {
1661  }
1662  if (!dbConnection_->tableExistsInDB("rf_external_port")) {
1664  }
1665  if (!dbConnection_->tableExistsInDB("rf_ext_port_parameter_dependency")) {
1667 
1668  }
1669 
1670  try {
1672 
1673  int sacFlagAsInt = implementation.separateAddressCycleParameter();
1674 
1675  // insert into rf_implementation table
1676  std::string insert_query(
1677  "INSERT INTO rf_implementation(id,name,size_param,"
1678  "width_param,clk_port,rst_port,glock_port,guard_port,sac_param,rf) "
1679  "VALUES(NULL,\"" + implementation.moduleName() + "\",\"" +
1680  implementation.sizeParameter() + "\",\"" +
1681  implementation.widthParameter() + "\",\"" +
1682  implementation.clkPort() + "\",\"" +
1683  implementation.rstPort() + "\",\"" +
1684  implementation.glockPort() + "\",\"" +
1685  implementation.guardPort() + "\"," +
1686  Conversion::toString(sacFlagAsInt) + "," +
1687  Conversion::toString(rfEntryID) + ");");
1688 
1689  dbConnection_->updateQuery(insert_query);
1690  RowID implID = dbConnection_->lastInsertRowID();
1691 
1692  // insert into rf_data_port table
1693  for (int i = 0; i < implementation.portCount(); i++) {
1694  RFPortImplementation& port = implementation.port(i);
1696  std::string(
1697  "INSERT INTO rf_data_port(id,name,direction,load_port,"
1698  "opcode_port,opcode_port_width_formula,rf_impl) "
1699  "VALUES(NULL,\"" + port.name() + "\",\"" +
1700  directionString(port.direction()) + "\",\"" +
1701  port.loadPort() + "\",\"" + port.opcodePort() + "\",\""
1702  + port.opcodePortWidthFormula() + "\"," +
1703  Conversion::toString(implID) + ");"));
1704  }
1705 
1706  // insert into block_source_file table
1707  for (int i = 0; i < implementation.implementationFileCount(); i++) {
1708  BlockImplementationFile& file = implementation.file(i);
1710  }
1711 
1712  // insert into rf_source_file table
1713  for (int i = 0; i < implementation.implementationFileCount(); i++) {
1714  BlockImplementationFile& file = implementation.file(i);
1715  string path = file.pathToFile();
1717  std::string(
1718  "INSERT INTO rf_source_file values(NULL, " +
1719  Conversion::toString(implID) +
1720  ", (SELECT id FROM block_source_file WHERE file=\"" +
1721  path + "\"));"));
1722  }
1723 
1724  // insert into rf_external_port table
1725  for (int i = 0; i < implementation.externalPortCount(); i++) {
1726  RFExternalPort& port = implementation.externalPort(i);
1727  string direction = directionString(port.direction());
1729  std::string(
1730  "INSERT INTO rf_external_port(id,name,direction,"
1731  "width_formula,description,rf_impl) VALUES(NULL,\"" +
1732  port.name() + "\",\"" + direction + "\",\"" +
1733  port.widthFormula() + "\",\"" + port.description() +
1734  "\"," + Conversion::toString(implID) + ");"));
1735  }
1736 
1737  // insert into rf_implementation_parameter table
1738  for (int i = 0; i < implementation.parameterCount(); i++) {
1739  RFImplementation::Parameter param = implementation.parameter(i);
1741  std::string(
1742  "INSERT INTO rf_implementation_parameter(id,name,type,"
1743  "value,rf_impl) VALUES(NULL,\"" + param.name +
1744  "\",\"" + param.type + "\",\"" + param.value +
1745  "\"," + Conversion::toString(implID) + ");"));
1746  }
1747 
1748  // Insert implicit parameters to rf_implementation_parameter table
1749  // (size and width parameter references if not empty and parameters
1750  // for them do not exists).
1751  string widthParam = implementation.widthParameter();
1752  if (!widthParam.empty() && !implementation.hasParameter(widthParam)) {
1754  std::string(
1755  "INSERT INTO rf_implementation_parameter(id,name,type,"
1756  "value,rf_impl) VALUES(NULL,\"" + widthParam +
1757  "\", \"integer\", \"\"," +
1758  Conversion::toString(implID) + ");"));
1759  }
1760  string sizeParam = implementation.sizeParameter();
1761  if (!sizeParam.empty() && !implementation.hasParameter(sizeParam)) {
1763  std::string(
1764  "INSERT INTO rf_implementation_parameter(id,name,type,"
1765  "value,rf_impl) VALUES(NULL,\"" + sizeParam +
1766  "\", \"integer\", \"\"," +
1767  Conversion::toString(implID) + ");"));
1768  }
1769 
1770  // insert into rf_ext_port_parameter_dependency table
1771  for (int i = 0; i < implementation.externalPortCount(); i++) {
1772  RFExternalPort& port = implementation.externalPort(i);
1773  for (int i = 0; i < port.parameterDependencyCount(); i++) {
1774  string param = port.parameterDependency(i);
1776  std::string(
1777  "INSERT INTO rf_ext_port_parameter_dependency(id,"
1778  "port,parameter) VALUES(NULL,(SELECT id FROM "
1779  "rf_external_port WHERE rf_impl=" +
1780  Conversion::toString(implID) + " AND name=\"" +
1781  port.name() + "\"),(SELECT id FROM "
1782  "rf_implementation_parameter WHERE rf_impl=" +
1783  Conversion::toString(implID) + " AND name=\"" +
1784  param + "\"));"));
1785  }
1786  }
1787 
1788  dbConnection_->commit();
1789  return implID;
1790 
1791  } catch (const Exception& e) {
1793  debugLog(e.errorMessage());
1794  assert(false);
1795  }
1796 
1797  // dummy return to avoid compiler whining
1798  assert(false);
1799  return 0;
1800 }
1801 
1802 /**
1803  * Removes the RF implementation that has the given ID.
1804  *
1805  * @param implID ID of the RF implementation.
1806  */
1807 void
1809 
1810  bool dependencyTableExists =
1811  dbConnection_->tableExistsInDB("rf_ext_port_parameter_dependency");
1812  bool parameterTableExists =
1813  dbConnection_->tableExistsInDB("rf_implementation_parameter");
1814  bool externalPortTableExists =
1815  dbConnection_->tableExistsInDB("rf_external_port");
1816 
1817  try {
1819 
1820  // remove from rf_ext_port_parameter_dependency table if it exists
1821  // (backward compatibility for old HDBs).
1822  if (dependencyTableExists) {
1823  assert(parameterTableExists && externalPortTableExists);
1825  std::string(
1826  "DELETE FROM rf_ext_port_parameter_dependency "
1827  "WHERE parameter in (SELECT ALL id "
1828  "FROM rf_implementation_parameter WHERE rf_impl = " +
1829  Conversion::toString(implID) + ");"));
1830  }
1831 
1832  // remove from rf_external_port table if it exists
1833  // (backward compatibility for old HDBs).
1834  if (externalPortTableExists) {
1836  std::string(
1837  "DELETE FROM rf_external_port "
1838  "WHERE rf_impl=" +
1839  Conversion::toString(implID) + ";"));
1840  }
1841 
1842  // remove from rf_implementation_parameter table if it exists
1843  // (backward compatibility for old HDBs).
1844  if (parameterTableExists) {
1846  std::string(
1847  "DELETE FROM rf_implementation_parameter "
1848  "WHERE rf_impl=" + Conversion::toString(implID) + ";"));
1849  }
1850 
1851  // remove from rf_source_file table
1853  std::string(
1854  "DELETE FROM rf_source_file WHERE rf_impl=" +
1855  Conversion::toString(implID) + ";"));
1856 
1857  // remove from block_source_file table
1859  std::string(
1860  "DELETE FROM block_source_file WHERE id NOT IN "
1861  "(SELECT file FROM fu_source_file UNION "
1862  "SELECT file FROM rf_source_file);"));
1863 
1864  // remove from rf_data_port
1866  std::string(
1867  "DELETE FROM rf_data_port WHERE rf_impl=" +
1868  Conversion::toString(implID) + ";"));
1869 
1870  // remove from rf_implementation
1872  std::string(
1873  "DELETE FROM rf_implementation WHERE id=" +
1874  Conversion::toString(implID) + ";"));
1875 
1876  dbConnection_->commit();
1877 
1878  } catch (const Exception& e) {
1880  debugLog(e.errorMessage());
1881  assert(false);
1882  }
1883 }
1884 
1885 
1886 /**
1887  * Sets architecture for an RF entry.
1888  *
1889  * @param rfID ID of the RF entry.
1890  * @param archID ID of the RF architecture to set.
1891  * @exception InvalidData If the database does not contain the given IDs or
1892  * if the RF entry has an architecture already.
1893  */
1894 void
1896  if (!hasRFEntry(rfID)) {
1897  throw InvalidData(__FILE__, __LINE__, __func__);
1898  }
1899 
1900  RFEntry* entry = rfByEntryID(rfID);
1901  if (entry->hasArchitecture()) {
1902  delete entry;
1903  throw InvalidData(__FILE__, __LINE__, __func__);
1904  }
1905  delete entry;
1906  entry = NULL;
1907 
1908  if (!containsRFArchitecture(archID)) {
1909  throw InvalidData(__FILE__, __LINE__, __func__);
1910  }
1911 
1912  try {
1914  std::string(
1915  "UPDATE rf SET architecture=" +
1916  Conversion::toString(archID) + " WHERE id=" +
1917  Conversion::toString(rfID) + ";"));
1918  } catch (const Exception& e) {
1919  debugLog(e.errorMessage());
1920  assert(false);
1921  }
1922 }
1923 
1924 /**
1925  * Unsets architecture of the given RF entry.
1926  *
1927  * @param rfID ID of the RF entry.
1928  */
1929 void
1931  try {
1933  std::string(
1934  "UPDATE rf SET architecture=NULL WHERE id=" +
1935  Conversion::toString(rfID)));
1936  } catch (const Exception& e) {
1937  debugLog(e.errorMessage());
1938  assert(false);
1939  }
1940 }
1941 
1942 
1943 /**
1944  * Sets the given cost function plugin for the given FU entry.
1945  *
1946  * @param fuID ID of the FU entry.
1947  * @param pluginID ID of the cost function plugin.
1948  */
1949 void
1951 
1952  // set the cost function plugin for fu
1953  try {
1955  std::string(
1956  "UPDATE fu SET cost_function=" +
1957  Conversion::toString(pluginID) + " WHERE id=" +
1958  Conversion::toString(fuID) + ";"));
1959  } catch (const Exception& e) {
1960  debugLog(e.errorMessage());
1961  assert(false);
1962  }
1963 }
1964 
1965 /**
1966  * Unsets cost function plugin of the given FU entry.
1967  *
1968  * @param fuID ID of the FU entry.
1969  */
1970 void
1972 
1973  // unset the cost function plugin
1974  try {
1976  std::string(
1977  "UPDATE fu SET cost_function=NULL WHERE id=" +
1978  Conversion::toString(fuID)));
1979  } catch (const Exception& e) {
1980  debugLog(e.errorMessage());
1981  assert(false);
1982  }
1983 }
1984 
1985 
1986 /**
1987  * Sets the given cost function plugin for the given RF entry.
1988  *
1989  * @param rfID ID of the RF entry.
1990  * @param pluginID ID of the cost function plugin.
1991  */
1992 void
1994 
1995  // set the cost function plugin for rf
1996  try {
1998  std::string(
1999  "UPDATE rf SET cost_function=" +
2000  Conversion::toString(pluginID) + " WHERE id=" +
2001  Conversion::toString(rfID) + ";"));
2002  } catch (const Exception& e) {
2003  debugLog(e.errorMessage());
2004  assert(false);
2005  }
2006 }
2007 
2008 /**
2009  * Unsets cost function plugin of the given RF entry.
2010  *
2011  * @param rfID ID of the RF entry.
2012  */
2013 void
2015 
2016  // unset the cost function plugin
2017  try {
2019  std::string(
2020  "UPDATE rf SET cost_function=NULL WHERE id=" +
2021  Conversion::toString(rfID)));
2022  } catch (const Exception& e) {
2023  debugLog(e.errorMessage());
2024  assert(false);
2025  }
2026 }
2027 
2028 
2029 /**
2030  * Returns a set of FU entry IDs in the database.
2031  *
2032  * @return A set containing all the FU entry IDs in the database.
2033  */
2034 std::set<RowID>
2036 
2037  string query = "SELECT id AS 'fu.id' FROM fu;";
2038 
2039  // make the SQL query to obtain all the IDs
2040  RelationalDBQueryResult* queryResult = NULL;
2041  try {
2042  queryResult = dbConnection_->query(query);
2043  } catch (const Exception& e) {
2044  // should not throw in any case
2045  debugLog(e.errorMessage());
2046  assert(false);
2047  }
2048 
2049  std::set<RowID> idSet;
2050  while (queryResult->hasNext()) {
2051  queryResult->next();
2052  const DataObject& idData = queryResult->data("fu.id");
2053  idSet.insert(idData.integerValue());
2054  }
2055 
2056  delete queryResult;
2057  return idSet;
2058 }
2059 
2060 
2061 /**
2062  * Returns a set of RF entry IDs in the database.
2063  *
2064  * @return A set containing all the RF entry IDs in the database.
2065  */
2066 std::set<RowID>
2068 
2069  string query = "SELECT id AS 'rf.id' FROM rf;";
2070 
2071  // make the SQL query to obtain all the IDs
2072  RelationalDBQueryResult* queryResult = NULL;
2073  try {
2074  queryResult = dbConnection_->query(query);
2075  } catch (const Exception& e) {
2076  // should not throw in any case
2077  debugLog(e.errorMessage());
2078  assert(false);
2079  }
2080 
2081  std::set<RowID> idSet;
2082  while (queryResult->hasNext()) {
2083  queryResult->next();
2084  const DataObject& idData = queryResult->data("rf.id");
2085  idSet.insert(idData.integerValue());
2086  }
2087 
2088  delete queryResult;
2089  return idSet;
2090 }
2091 
2092 
2093 /**
2094  * Returns a set of Bus entry IDs in the database.
2095  *
2096  * @return A set containing all the Bus entry IDs in the database.
2097  */
2098 std::set<RowID>
2100 
2101  string query = "SELECT id AS 'bus.id' FROM bus;";
2102 
2103  // make the SQL query to obtain all the IDs
2104  RelationalDBQueryResult* queryResult = NULL;
2105  try {
2106  queryResult = dbConnection_->query(query);
2107  } catch (const Exception& e) {
2108  // should not throw in any case
2109  debugLog(e.errorMessage());
2110  assert(false);
2111  }
2112 
2113  std::set<RowID> idSet;
2114  while (queryResult->hasNext()) {
2115  queryResult->next();
2116  const DataObject& idData = queryResult->data("bus.id");
2117  idSet.insert(idData.integerValue());
2118  }
2119 
2120  delete queryResult;
2121  return idSet;
2122 }
2123 
2124 
2125 /**
2126  * Returns a set of Socket entry IDs in the database.
2127  *
2128  * @return A set containing all the Socket entry IDs in the database.
2129  */
2130 std::set<RowID>
2132 
2133  string query = "SELECT id AS 'socket.id' FROM socket;";
2134 
2135  // make the SQL query to obtain all the IDs
2136  RelationalDBQueryResult* queryResult = NULL;
2137  try {
2138  queryResult = dbConnection_->query(query);
2139  } catch (const Exception& e) {
2140  // should not throw in any case
2141  debugLog(e.errorMessage());
2142  assert(false);
2143  }
2144 
2145  std::set<RowID> idSet;
2146  while (queryResult->hasNext()) {
2147  queryResult->next();
2148  const DataObject& idData = queryResult->data("socket.id");
2149  idSet.insert(idData.integerValue());
2150  }
2151 
2152  delete queryResult;
2153  return idSet;
2154 }
2155 
2156 
2157 /**
2158  * Returns a set of FU architecture IDs in the database.
2159  *
2160  * @return A set containing all the FU architecture IDs in the database.
2161  */
2162 std::set<RowID>
2164 
2165  RelationalDBQueryResult* result = NULL;
2166  try {
2167  result = dbConnection_->query(
2168  std::string("SELECT id FROM fu_architecture;"));
2169  } catch (const Exception& e) {
2170  debugLog(e.errorMessage());
2171  assert(false);
2172  }
2173 
2174  std::set<RowID> idSet;
2175  while (result->hasNext()) {
2176  result->next();
2177  const DataObject& idData = result->data(0);
2178  idSet.insert(idData.integerValue());
2179  }
2180 
2181  delete result;
2182  return idSet;
2183 }
2184 
2185 
2186 /**
2187  * Returns a set of Operation Implementation Resource IDs in the database.
2188  *
2189  * @return A set containing all the Operation Implementation Resource
2190  * IDs in the database.
2191  */
2192 std::set<RowID>
2194  RelationalDBQueryResult* result = NULL;
2195  try {
2196  result = dbConnection_->query(
2197  std::string("SELECT id FROM operation_implementation;"));
2198  } catch (const Exception& e) {
2199  debugLog(e.errorMessage());
2200  assert(false);
2201  }
2202 
2203  std::set<RowID> idSet;
2204  while (result->hasNext()) {
2205  result->next();
2206  const DataObject& idData = result->data(0);
2207  idSet.insert(idData.integerValue());
2208  }
2209 
2210  delete result;
2211  return idSet;
2212 }
2213 
2214 /**
2215  * Returns a set of Operation Implementation IDs in the database.
2216  *
2217  * @return A set containing all the Operation Implemnetation
2218  * IDs in the database.
2219  */
2220 std::set<RowID>
2222  RelationalDBQueryResult* result = NULL;
2223  try {
2224  result = dbConnection_->query(
2225  std::string("SELECT id FROM operation_implementation_resource;"));
2226  } catch (const Exception& e) {
2227  debugLog(e.errorMessage());
2228  assert(false);
2229  }
2230 
2231  std::set<RowID> idSet;
2232  while (result->hasNext()) {
2233  result->next();
2234  const DataObject& idData = result->data(0);
2235  idSet.insert(idData.integerValue());
2236  }
2237 
2238  delete result;
2239  return idSet;
2240 }
2241 
2242 /**
2243  * Returns OperationImplementation.
2244  *
2245  * @return OperationImplementation.
2246  */
2249  RelationalDBQueryResult* result = nullptr;
2250  try {
2251  result = dbConnection_->query(
2252  std::string("SELECT * FROM operation_implementation WHERE id = ") +
2253  std::to_string(id) +
2254  std::string(";"));
2255  } catch (const Exception& e) {
2256  debugLog(e.errorMessage());
2257  assert(false);
2258  }
2259 
2260  OperationImplementation retval;
2261  if (result->hasNext()) {
2262  result->next();
2263 
2264  retval.id = id;
2265  retval.latency = result->data("latency").integerValue();
2266  retval.name = result->data("name").stringValue();
2267  retval.postOpImplFileVhdl =
2268  result->data("post_op_vhdl").stringValue();
2269  retval.postOpImplFileVerilog =
2270  result->data("post_op_verilog").stringValue();
2271  retval.absBusDefFile =
2272  result->data("bus_definition").stringValue();
2273  retval.initialImplFileVerilog =
2274  result->data("initial_verilog").stringValue();
2275  retval.initialImplFileVhdl =
2276  result->data("initial_vhdl").stringValue();
2277  }
2278  delete result;
2279  result = nullptr;
2280 
2281  try {
2282  result = dbConnection_->query(
2283  std::string("SELECT block_source_file.file "
2284  "FROM operation_implementation_source_file, "
2285  "block_source_file "
2286  "WHERE operation_implementation_source_"
2287  "file.operation = ") +
2288  std::to_string(id) +
2289  std::string(" AND operation_implementation_source_file.file = "
2290  " block_source_file.id"
2291  " AND block_source_file.format = "
2292  + std::to_string(
2294  ";"));
2295 
2296  } catch (const Exception& e) {
2297  debugLog(e.errorMessage());
2298  assert(false);
2299  }
2300  if (result->hasNext()) {
2301  result->next();
2302  retval.implFileVhdl = result->data("file").stringValue();
2303  }
2304  delete result;
2305  result = nullptr;
2306 
2307  try {
2308  result = dbConnection_->query(
2309  std::string("SELECT block_source_file.file "
2310  "FROM operation_implementation_source_file, "
2311  "block_source_file "
2312  "WHERE operation_implementation_"
2313  "source_file.operation = ") +
2314  std::to_string(id) +
2315  std::string(" AND operation_implementation_source_file.file = "
2316  " block_source_file.id"
2317  " AND block_source_file.format = "
2318  + std::to_string(
2320  ";"));
2321 
2322  } catch (const Exception& e) {
2323  debugLog(e.errorMessage());
2324  assert(false);
2325  }
2326  if (result->hasNext()) {
2327  result->next();
2328  retval.implFileVerilog = result->data("file").stringValue();
2329  }
2330  delete result;
2331  result = nullptr;
2332 
2333  std::string q1 = "SELECT resource, count "
2334  "FROM operation_implementation_resources "
2335  "WHERE operation_implementation_resources.operation = "
2336  + std::to_string(id) + ";";
2337  result = dbConnection_->query(q1);
2338  while (result->hasNext()) {
2339  result->next();
2340  int resource = result->data("resource").integerValue();
2343  r.count = result->data("count").integerValue();
2344  retval.resources.emplace_back(r);
2345  }
2346 
2347  std::string q2 = "SELECT name, width, type, language "
2348  "FROM operation_implementation_variable "
2349  "WHERE CAST(operation as TEXT) = \"" + std::to_string(id) + "\";";
2350  result = dbConnection_->query(q2);
2351  while (result->hasNext()) {
2352  result->next();
2353  std::string name = result->data("name").stringValue();
2354  std::string width = result->data("width").stringValue();
2355  std::string type = result->data("type").stringValue();
2356  std::string lang = result->data("language").stringValue();
2357  // TODO not all HDBs have a rename column yet, so variable renaming is
2358  // hardcoded
2359  bool rename = true;
2360  // std::string renamestr = result->data("rename").stringValue();
2361  // bool rename = renamestr != "0";
2362  if (lang == "VHDL") {
2363  Variable var = {name, width, type, rename};
2364  retval.vhdlVariables.emplace_back(var);
2365  } else if (lang == "Verilog") {
2366  retval.verilogVariables.emplace_back(
2367  Variable{name, width, type, rename});
2368  } else {
2369  throw std::runtime_error("Unknown language");
2370  }
2371  }
2372 
2374  "operation_implementation_globalsignal")) {
2375  std::string q3 =
2376  "SELECT name, width, type, language, rename "
2377  "FROM operation_implementation_globalsignal "
2378  "WHERE CAST(operation as TEXT) = \"" +
2379  std::to_string(id) + "\";";
2380  result = dbConnection_->query(q3);
2381  while (result->hasNext()) {
2382  result->next();
2383  std::string name = result->data("name").stringValue();
2384  std::string width = result->data("width").stringValue();
2385  std::string type = result->data("type").stringValue();
2386  std::string lang = result->data("language").stringValue();
2387  std::string renamestr = result->data("rename").stringValue();
2388  bool rename = renamestr != "0";
2389  if (lang == "VHDL") {
2390  Variable var = {name, width, type, rename};
2391  retval.vhdlGlobalSignals.emplace_back(var);
2392  } else if (lang == "Verilog") {
2393  retval.verilogGlobalSignals.emplace_back(
2394  Variable{name, width, type, rename});
2395  } else {
2396  throw std::runtime_error("Unknown language");
2397  }
2398  }
2399  }
2400 
2401  return retval;
2402 }
2403 
2404 /**
2405  * Returns OperationImplementationResource.
2406  *
2407  * @return OperationImplementationResource.
2408  */
2411  RelationalDBQueryResult* result = nullptr;
2412  try {
2413  result = dbConnection_->query(
2414  std::string("SELECT * FROM "
2415  "operation_implementation_resource WHERE id = ") +
2416  std::to_string(id) +
2417  std::string(";"));
2418  } catch (const Exception& e) {
2419  debugLog(e.errorMessage());
2420  assert(false);
2421  }
2422 
2424  if (result->hasNext()) {
2425  result->next();
2426 
2427  retval.id = id;
2428  retval.name = result->data("name").stringValue();
2429  retval.ipxact = result->data("ipxact").stringValue();
2430  }
2431  delete result;
2432  result = nullptr;
2433 
2434  try {
2435  result = dbConnection_->query(
2436  std::string("SELECT block_source_file.file, "
2437  "format.format "
2438  "FROM operation_implementation_resource_"
2439  "source_file, block_source_file, "
2440  "format "
2441  "WHERE operation_implementation_resource_"
2442  "source_file.resource = ") +
2443  std::to_string(id) +
2444  std::string(" AND operation_implementation_resource_"
2445  "source_file.file = "
2446  " block_source_file.id "
2447  "AND block_source_file.format = "
2448  "format.id;"
2449  ));
2450 
2451  } catch (const Exception& e) {
2452  debugLog(e.errorMessage());
2453  assert(false);
2454  }
2455  while (result->hasNext()) {
2456  result->next();
2457  std::string format = result->data("format").stringValue();
2458  if (format == VHDL_FORMAT) {
2459  retval.synFiles.push_back(result->data("file").stringValue());
2460  retval.synFormats.push_back(format);
2461  } else if (format == VHDL_SIM_FORMAT) {
2462  retval.simFiles.push_back(result->data("file").stringValue());
2463  retval.simFormats.push_back(format);
2464  } else if (format == VERILOG_FORMAT) {
2465  retval.synFiles.push_back(result->data("file").stringValue());
2466  retval.synFormats.push_back(format);
2467  } else if (format == VERILOG_SIM_FORMAT) {
2468  retval.simFiles.push_back(result->data("file").stringValue());
2469  retval.simFormats.push_back(format);
2470  }
2471  }
2472  delete result;
2473  result = nullptr;
2474 
2475  return retval;
2476 }
2477 
2478 /**
2479  * Add addOperationImplementationResource to the DB.
2480  */
2481 void
2483  const OperationImplementationResource& resource) {
2484 
2486  std::string(
2487  "INSERT INTO operation_implementation_resource(id,name,ipxact) "
2488  "VALUES (NULL, \"" +
2489  resource.name +"\", \"" + resource.ipxact+ "\");"));
2490  RowID resourceID = dbConnection_->lastInsertRowID();
2491 
2492  auto t = resource.simFormats.begin();
2493  auto f = resource.simFiles.begin();
2494  for (; f != resource.simFiles.end(); ++f, ++t) {
2495  int type = fileFormat(*t) + 1;
2496 
2498  std::string(
2499  "INSERT INTO block_source_file(id,file,format) "
2500  "VALUES (NULL, \"" + *f + "\","
2501  + std::to_string(type) +
2502  ");"));
2503  RowID fileID = dbConnection_->lastInsertRowID();
2504 
2506  std::string(
2507  "INSERT INTO operation_implementation_resource_source_file"
2508  "(id,resource,file) "
2509  "VALUES (NULL, " + std::to_string(resourceID) + ", "
2510  + std::to_string(fileID) +
2511  ");"));
2512  }
2513 
2514  auto st = resource.synFormats.begin();
2515  auto sf = resource.synFiles.begin();
2516  for (; sf != resource.synFiles.end(); ++sf, ++st) {
2517  int type = fileFormat(*st) + 1;
2518 
2520  std::string(
2521  "INSERT INTO block_source_file(id,file,format) "
2522  "VALUES (NULL, \"" + *sf + "\","
2523  + std::to_string(type) +
2524  ");"));
2525  RowID fileID = dbConnection_->lastInsertRowID();
2526 
2528  std::string(
2529  "INSERT INTO operation_implementation_resource_source_file"
2530  "(id,resource,file) "
2531  "VALUES (NULL, " + std::to_string(resourceID) + ", "
2532  + std::to_string(fileID) +
2533  ");"));
2534  }
2535 }
2536 
2537 /**
2538  * Add addOperationImplementation to the DB.
2539  */
2540 void
2542  const OperationImplementation& operation) {
2543 
2544 
2545  std::string i1 = "INSERT INTO operation_implementation(id,name,latency,"
2546  "post_op_vhdl,post_op_verilog,bus_definition,"
2547  "initial_vhdl,initial_verilog) "
2548  "VALUES (NULL,\"" + operation.name + "\","
2549  + std::to_string(operation.latency) + ","
2550  "\"" + operation.postOpImplFileVhdl + "\","
2551  "\"" + operation.postOpImplFileVerilog + "\","
2552  "\"" + operation.absBusDefFile + "\","
2553  "\"" + operation.initialImplFileVhdl + "\","
2554  "\"" + operation.initialImplFileVerilog +
2555  "\");";
2557  RowID newid = dbConnection_->lastInsertRowID();
2558 
2559  for (const auto r : operation.resources) {
2560  std::string i2 = "INSERT INTO operation_implementation_resources("
2561  "id, operation, resource, count) "
2562  "VALUES (NULL, " + std::to_string(newid)
2563  + ", " + std::to_string(r.id)
2564  + ", " + std::to_string(r.count)
2565  + ");";
2567  }
2568 
2569  for (const auto r : operation.vhdlVariables) {
2570  std::string i2 = "INSERT INTO operation_implementation_variable("
2571  "id, operation, name, width, type, language) "
2572  "VALUES (NULL, " + std::to_string(newid)
2573  + ", \"" + r.name + "\""
2574  + ", \"" + r.width + "\""
2575  + ", \"" + r.type + "\""
2576  + ", \"VHDL\");";
2578  }
2579 
2580  for (const auto r : operation.verilogVariables) {
2581  std::string i2 = "INSERT INTO operation_implementation_variable("
2582  "id, operation, name, width, type, language) "
2583  "VALUES (NULL, " + std::to_string(newid)
2584  + ", \"" + r.name + "\""
2585  + ", \"" + r.width + "\""
2586  + ", \"" + r.type + "\""
2587  + ", \"Verilog\");";
2589  }
2590 
2591  std::string i3 = "INSERT INTO block_source_file(id,file,format) "
2592  "VALUES (NULL,\"" + operation.implFileVhdl +
2593  "\", " + std::to_string(BlockImplementationFile::VHDL) + ");";
2596 
2597  std::string i4 = "INSERT INTO "
2598  "operation_implementation_source_file(id, operation, file) "
2599  "VALUES (NULL, " + std::to_string(newid) +
2600  ", " + std::to_string(vhdl) +
2601  ");";
2603 
2604  std::string i5 = "INSERT INTO block_source_file(id,file,format) "
2605  "VALUES (NULL,\"" + operation.implFileVerilog +
2606  "\", " + std::to_string(BlockImplementationFile::Verilog) + ");";
2608  RowID verilog = dbConnection_->lastInsertRowID();
2609 
2610  std::string i6 = "INSERT INTO "
2611  "operation_implementation_source_file(id, operation, file) "
2612  "VALUES (NULL, " + std::to_string(newid) +
2613  ", " + std::to_string(verilog) +
2614  ");";
2616 }
2617 
2618 /**
2619  * Remove Operation Implemententation from DB.
2620  */
2621 void
2623  std::string d1 = "DELETE FROM operation_implementation "
2624  "WHERE id = " + std::to_string(id) + ";";
2625  std::string d2 =
2626  "DELETE FROM operation_implementation_source_file "
2627  "WHERE operation = " + std::to_string(id) + ";";
2628  std::string d3 =
2629  "DELETE FROM operation_implementation_resources "
2630  "WHERE operation = " + std::to_string(id) + ";";
2631  std::string d4 =
2632  "DELETE FROM operation_implementation_variable "
2633  "WHERE operation = " + std::to_string(id) + ";";
2634  std::string s1 = "SELECT file FROM "
2635  "operation_implementation_source_file "
2636  "WHERE operation = " + std::to_string(id) + ";";
2637 
2639  while (result->hasNext()) {
2640  result->next();
2641  int file_id = result->data(0).integerValue();
2642  std::string d3lete = "DELETE FROM block_source_file "
2643  "WHERE id = " + std::to_string(file_id) + ";";
2644  dbConnection_->updateQuery(d3lete);
2645  }
2646 
2651  delete result;
2652 }
2653 
2654 /**
2655  * Remove Operation Implemententation Resource from DB.
2656  */
2657 void
2659  std::string d1 = "DELETE FROM operation_implementation_resource "
2660  "WHERE id = " + std::to_string(id) + ";";
2661  std::string d2 =
2662  "DELETE FROM operation_implementation_resource_source_file "
2663  "WHERE resource = " + std::to_string(id) + ";";
2664  std::string s1 = "SELECT file FROM "
2665  "operation_implementation_resource_source_file "
2666  "WHERE resource = " + std::to_string(id) + ";";
2667 
2669  while (result->hasNext()) {
2670  result->next();
2671  int file_id = result->data(0).integerValue();
2672  std::string d3 = "DELETE FROM block_source_file "
2673  "WHERE id = " + std::to_string(file_id) + ";";
2675  }
2676 
2679  delete result;
2680 }
2681 
2682 
2683 std::set<RowID>
2685  const std::set<std::string>& operationNames) const {
2686 
2687  RelationalDBQueryResult* result = NULL;
2688  try {
2689  std::string operationQuery = "(";
2690  std::set<string>::const_iterator iter = operationNames.begin();
2691  while (iter != operationNames.end()) {
2692  // LIKE makes case-insensitive match to operation names
2693  operationQuery +=
2694  "operation.name LIKE '" + *iter + "'";
2695  iter++;
2696  if (iter != operationNames.end()) {
2697  operationQuery += " OR ";
2698  }
2699  }
2700  operationQuery += ")";
2701  if (operationQuery == "()") {
2702  return std::set<RowID>();
2703  }
2704  result = dbConnection_->query(
2705  std::string("SELECT fu_architecture.id FROM operation_pipeline,"
2706  "operation, fu_architecture WHERE "
2707  "operation.id=operation_pipeline.operation AND "
2708  "operation_pipeline.fu_arch=fu_architecture.id AND "
2709  + operationQuery +
2710  "GROUP BY fu_architecture.id ORDER BY "
2711  "fu_architecture.id;"));
2712  } catch (const Exception& e) {
2713  std::string eMsg = ", HDB file where error occurred was: " + hdbFile_;
2714  debugLog(e.errorMessage() + eMsg);
2715  assert(false);
2716  }
2717 
2718  std::set<RowID> idSet;
2719  while (result->hasNext()) {
2720  result->next();
2721  const DataObject& idData = result->data(0);
2722  idSet.insert(idData.integerValue());
2723  }
2724 
2725  delete result;
2726  return idSet;
2727 }
2728 /**
2729  * Returns a set of RF architecture IDs in the database.
2730  *
2731  * @return A set containing all the RF architecture IDs in the database.
2732  */
2733 std::set<RowID>
2735 
2736  RelationalDBQueryResult* result = NULL;
2737  try {
2738  result = dbConnection_->query(
2739  std::string("SELECT id FROM rf_architecture;"));
2740  } catch (const Exception& e) {
2741  debugLog(e.errorMessage());
2742  assert(false);
2743  }
2744 
2745  std::set<RowID> idSet;
2746  while (result->hasNext()) {
2747  result->next();
2748  const DataObject& idData = result->data(0);
2749  idSet.insert(idData.integerValue());
2750  }
2751 
2752  delete result;
2753  return idSet;
2754 }
2755 
2756 
2757 /**
2758  * Returns the ID of the FU entry that has the given implementation ID.
2759  *
2760  * @param implID The implementation ID.
2761  * @return The FU entry ID.
2762  * @exception KeyNotFound If there is no implementation by the given ID.
2763  */
2764 RowID
2766  RelationalDBQueryResult* result = NULL;
2767  try {
2768  result = dbConnection_->query(
2769  std::string(
2770  "SELECT fu from fu_implementation WHERE id=" +
2771  Conversion::toString(implID) + ";"));
2772  } catch (const Exception& e) {
2773  debugLog(e.errorMessage());
2774  assert(false);
2775  }
2776 
2777  if (result->hasNext()) {
2778  result->next();
2779  RowID id = result->data(0).integerValue();
2780  delete result;
2781  return id;
2782  } else {
2783  delete result;
2784  throw KeyNotFound(__FILE__, __LINE__, __func__);
2785  }
2786 }
2787 
2788 /**
2789  * Returns the ID of the RF entry that has the given implementation ID.
2790  *
2791  * @param implID The implementation ID.
2792  * @return The RF entry ID.
2793  * @exception KeyNotFound If there is no implementation by the given ID.
2794  */
2795 RowID
2797  RelationalDBQueryResult* result = NULL;
2798  try {
2799  result = dbConnection_->query(
2800  std::string(
2801  "SELECT rf from rf_implementation WHERE id=" +
2802  Conversion::toString(implID) + ";"));
2803  } catch (const Exception& e) {
2804  debugLog(e.errorMessage());
2805  assert(false);
2806  }
2807 
2808  if (result->hasNext()) {
2809  result->next();
2810  RowID id = result->data(0).integerValue();
2811  delete result;
2812  return id;
2813  } else {
2814  delete result;
2815  throw KeyNotFound(__FILE__, __LINE__, __func__);
2816  }
2817 }
2818 
2819 /**
2820  * Returns the FU entry that has the given ID.
2821  *
2822  * @param id The ID of the FU entry.
2823  * @return The FU entry.
2824  * @excpetion KeyNotFound If the HDB does not contain an FU entry with the
2825  * given ID.
2826  */
2827 FUEntry*
2829  std::string query = "SELECT architecture FROM fu WHERE id=";
2830  query += Conversion::toString(id) + ";";
2831 
2832  RelationalDBQueryResult* result = NULL;
2833  try {
2834  result = dbConnection_->query(query);
2835  } catch (const Exception& e) {
2836  debugLog(e.errorMessage());
2837  assert(false);
2838  }
2839 
2840  bool hasArch = false;
2841  RowID archID = -1;
2842  if (result->hasNext()) {
2843  result->next();
2844  DataObject data = result->data(0);
2845  if (!data.isNull()) {
2846  hasArch = true;
2847  archID = data.integerValue();
2848  }
2849  delete result;
2850  result = NULL;
2851  } else {
2852  delete result;
2853  std::ostringstream stream;
2854  stream << "FU entry with id " << id << " not found from hdb "
2855  << hdbFile_;
2856  throw KeyNotFound(__FILE__, __LINE__, __func__, stream.str());
2857  }
2858 
2859  FUEntry* entry = new FUEntry();
2860  entry->setID(id);
2861  if (hasArch) {
2862  FUArchitecture* architecture = fuArchitectureByID(archID);
2863  entry->setArchitecture(architecture);
2865  *architecture, id);
2867  }
2868 
2869  CostFunctionPlugin* costFunction = createCostFunctionOfFU(id);
2870  entry->setCostFunction(costFunction);
2871  entry->setHDBFile(hdbFile_);
2872  delete result;
2873  return entry;
2874 }
2875 
2876 /**
2877  * Returns the RF entry that has the given ID.
2878  *
2879  * @param id The ID of the RF entry.
2880  * @return The RF entry.
2881  * @exception KeyNotFound If the HDB does not contain an RF entry with the
2882  * given ID.
2883  */
2884 RFEntry*
2886  std::string query = "SELECT architecture FROM rf WHERE id=";
2887  query += Conversion::toString(id) + ";";
2888 
2889  RelationalDBQueryResult* result = NULL;
2890  try {
2891  result = dbConnection_->query(query);
2892  } catch (const Exception& e) {
2893  debugLog(e.errorMessage());
2894  assert(false);
2895  }
2896 
2897  bool hasArch = false;
2898  RowID archID = -1;
2899  if (result->hasNext()) {
2900  result->next();
2901  DataObject data = result->data(0);
2902  if (!data.isNull()) {
2903  hasArch = true;
2904  archID = data.integerValue();
2905  }
2906  delete result;
2907  result = NULL;
2908  } else {
2909  delete result;
2910  throw KeyNotFound(__FILE__, __LINE__, __func__);
2911  }
2912 
2913  RFEntry* entry = new RFEntry();
2914  entry->setID(id);
2915  if (hasArch) {
2916  RFArchitecture* architecture = rfArchitectureByID(archID);
2917  entry->setArchitecture(architecture);
2918  }
2919 
2921  CostFunctionPlugin* costFunction = createCostFunctionOfRF(id);
2923  entry->setCostFunction(costFunction);
2924  entry->setHDBFile(hdbFile_);
2925  delete result;
2926 
2927  return entry;
2928 }
2929 
2930 /**
2931  * Creates an FUArchitecture instance of the FU architecture that has the
2932  * given ID.
2933  *
2934  * @param ID The ID of the FU architecture.
2935  * @return The newly created FUArchitecture instance.
2936  * @exception KeyNotFound If the HDB does not have a FU architecture with the
2937  * given ID.
2938  */
2941  if (!containsFUArchitecture(id)) {
2942  throw KeyNotFound(__FILE__, __LINE__, __func__);
2943  }
2944 
2945  FunctionUnit* fu = new FunctionUnit("name");
2946  FUArchitecture* architecture = new FUArchitecture(fu);
2947  architecture->setID(id);
2948  addPortsAndBindingsToFUArchitecture(*architecture, id);
2949  addOperationPipelinesToFUArchitecture(*architecture, id);
2950  return architecture;
2951 }
2952 
2953 /**
2954  * Creates an RFArchitecture instance of the RF architecture that has the
2955  * given ID.
2956  *
2957  * @param id The ID of the RF architecture.
2958  * @return The newly created RFArchitecture instance.
2959  * @exception KeyNotFound If the HDB does not contain RF architecture with the
2960  * given ID.
2961  */
2964  if (!containsRFArchitecture(id)) {
2965  throw KeyNotFound(__FILE__, __LINE__, __func__);
2966  }
2967 
2968  RelationalDBQueryResult* architectureData;
2969  try {
2970  architectureData = dbConnection_->query(rfArchitectureByIDQuery(id));
2971  } catch (const Exception& e) {
2972  debugLog(e.errorMessage());
2973  assert(false);
2974  }
2975 
2976  int sizeColumn = architectureData->column("size");
2977  int widthColumn = architectureData->column("width");
2978  int readPortsColumn = architectureData->column("read_ports");
2979  int writePortsColumn = architectureData->column("write_ports");
2980  int bidirPortsColumn = architectureData->column("bidir_ports");
2981  int latencyColumn = architectureData->column("latency");
2982  int maxReadsColumn = architectureData->column("max_reads");
2983  int maxWritesColumn = architectureData->column("max_writes");
2984  int guardSupportColumn = architectureData->column("guard_support");
2985  int guardLatencyColumn = architectureData->column("guard_latency");
2986  int zeroRegisterColumn = architectureData->column("zero_register");
2987 
2988  assert(architectureData->hasNext());
2989  architectureData->next();
2990  assert(!architectureData->hasNext());
2991  const DataObject& sizeData = architectureData->data(sizeColumn);
2992  const DataObject& widthData = architectureData->data(widthColumn);
2993  const DataObject& readPortsData = architectureData->data(
2994  readPortsColumn);
2995  const DataObject& writePortsData = architectureData->data(
2996  writePortsColumn);
2997  const DataObject& bidirPortsData = architectureData->data(
2998  bidirPortsColumn);
2999  const DataObject& latencyData = architectureData->data(
3000  latencyColumn);
3001  const DataObject& maxReadsData = architectureData->data(
3002  maxReadsColumn);
3003  const DataObject& maxWritesData = architectureData->data(
3004  maxWritesColumn);
3005  const DataObject& guardSupportData = architectureData->data(
3006  guardSupportColumn);
3007  const DataObject& guardLatencyData = architectureData->data(
3008  guardLatencyColumn);
3009  const DataObject& zeroRegisterData = architectureData->data(
3010  zeroRegisterColumn);
3011  RFArchitecture* architecture = new RFArchitecture(
3012  readPortsData.integerValue(), writePortsData.integerValue(),
3013  bidirPortsData.integerValue(), maxReadsData.integerValue(),
3014  maxWritesData.integerValue(), latencyData.integerValue(),
3015  guardSupportData.boolValue(), guardLatencyData.integerValue(),
3016  zeroRegisterData.boolValue());
3017  std::cout.flush();
3018  architecture->setID(id);
3019  if (!sizeData.isNull()) {
3020  architecture->setSize(sizeData.integerValue());
3021  }
3022  if (!widthData.isNull()) {
3023  architecture->setWidth(widthData.integerValue());
3024  }
3025  delete architectureData;
3026  return architecture;
3027 }
3028 
3029 /**
3030  * Returns a set of FU entry IDs that have a corresponding architecture
3031  * with the given one.
3032  *
3033  * The set may contain FU entry IDs that have ports with parametrized
3034  * width while the given one has fixed width.
3035  *
3036  * @param fu The FU architecture.
3037  * @return Set of FU entry IDs.
3038  */
3039 std::set<RowID>
3041  const TTAMachine::FunctionUnit& fu) const {
3042 
3043  std::set<RowID> architectureIDs;
3044  std::set<RowID> entryIDs;
3045 
3046  try {
3047  // get FU architectures with required operation set
3048  string query = "";
3049  for (int i = 0; i < fu.operationCount(); i++) {
3050  query +=
3051  "SELECT fu_arch FROM operation_pipeline,operation "
3052  "WHERE operation.name=\"" + fu.operation(i)->name() +
3053  "\" AND operation_pipeline.operation=operation.id";
3054  if (i+1 < fu.operationCount()) {
3055  query += " INTERSECT ";
3056  } else {
3057  query += ";";
3058  }
3059  }
3060 
3061  RelationalDBQueryResult* queryResult = dbConnection_->query(query);
3062 
3063  // check the architectures are compeletely similar
3064  while (queryResult->hasNext()) {
3065  queryResult->next();
3066  const DataObject& archID = queryResult->data(0);
3068  if (isMatchingArchitecture(fu, *arch)) {
3069  architectureIDs.insert(arch->id());
3070  }
3071  delete arch;
3072  }
3073 
3074  delete queryResult;
3075 
3076  if (!architectureIDs.empty()) {
3077  // find the FU entry IDs
3078  string fuEntryQuery = "SELECT id FROM fu WHERE ";
3079  for (std::set<RowID>::const_iterator iter =
3080  architectureIDs.begin();
3081  iter != architectureIDs.end(); iter++) {
3082  fuEntryQuery += "architecture=" +
3083  Conversion::toString(*iter);
3084  std::set<RowID>::const_iterator nextIter = iter;
3085  nextIter++;
3086  if (nextIter == architectureIDs.end()) {
3087  fuEntryQuery += ";";
3088  } else {
3089  fuEntryQuery += " OR ";
3090  }
3091  }
3092 
3093  RelationalDBQueryResult* fuEntryResult = dbConnection_->query(
3094  fuEntryQuery);
3095  while (fuEntryResult->hasNext()) {
3096  fuEntryResult->next();
3097  const DataObject& idData = fuEntryResult->data(0);
3098  entryIDs.insert(idData.integerValue());
3099  }
3100 
3101  delete fuEntryResult;
3102  }
3103 
3104  } catch (const Exception& e) {
3105  debugLog(e.errorMessage());
3106  ;
3107  }
3108 
3109  return entryIDs;
3110 }
3111 
3112 
3113 /**
3114  * Returns a set of RF entry IDs that have the described architecture.
3115  *
3116  * In case that size or width is given as a parameter are also the RF entries
3117  * with a parameterized width or size returned as are the entries with matched
3118  * width and/or size.
3119  *
3120  * @param readPorts The number of read ports.
3121  * @param writePorts The number of write ports.
3122  * @param bidirPorts The number of bidirectional ports.
3123  * @param maxRead The (minimum) max reads value.
3124  * @param latency The exact latency.
3125  * @param guardSupport Guard support.
3126  * @param guardLatency The guard latency.
3127  * @param width The bit withd of the register file.
3128  * @param size The number of registers in the register file.
3129  * @param zeroRegister zero register of the register file
3130  * @return Set of RF entry IDs.
3131  */
3132 std::set<RowID>
3134  int readPorts,
3135  int writePorts,
3136  int bidirPorts,
3137  int maxReads,
3138  int maxWrites,
3139  int latency,
3140  bool guardSupport,
3141  int guardLatency,
3142  int width,
3143  int size,
3144  bool zeroRegister) const {
3145 
3146  RelationalDBQueryResult* result = NULL;
3147  try {
3148  string query = "SELECT rf.id FROM rf,rf_architecture "
3149  "WHERE rf_architecture.read_ports=" +
3150  Conversion::toString(readPorts) +
3151  " AND rf_architecture.write_ports=" +
3152  Conversion::toString(writePorts) +
3153  " AND rf_architecture.bidir_ports=" +
3154  Conversion::toString(bidirPorts) +
3155  " AND rf_architecture.max_reads>=" +
3156  Conversion::toString(maxReads) +
3157  " AND rf_architecture.max_writes>=" +
3158  Conversion::toString(maxWrites) +
3159  " AND rf_architecture.latency=" +
3160  Conversion::toString(latency);
3161  if (guardSupport) {
3162  query += " AND rf_architecture.guard_support=" +
3163  Conversion::toString(guardSupport) +
3164  " AND rf_architecture.guard_latency=" +
3165  Conversion::toString(guardLatency);
3166  }
3167  if (size != 0) {
3168  query += " AND (rf_architecture.size=" +
3169  Conversion::toString(size) +
3170  " OR rf_architecture.size is NULL)";
3171  }
3172  if (width != 0) {
3173  query += " AND (rf_architecture.width=" +
3174  Conversion::toString(width) +
3175  " OR rf_architecture.width is NULL)";
3176  }
3177  query += " AND (rf_architecture.zero_register=" +
3178  Conversion::toString(zeroRegister);
3179  if (!zeroRegister) {
3180  query += " OR rf_architecture.zero_register is NULL";
3181  }
3182  query += ")";
3183  query += " AND rf.architecture=rf_architecture.id;";
3184  result = dbConnection_->query(query);
3185  } catch (const Exception& e) {
3186  debugLog(e.errorMessage());
3187  ;
3188  }
3189 
3190  std::set<RowID> entryIDs;
3191  while (result->hasNext()) {
3192  result->next();
3193  entryIDs.insert(result->data(0).integerValue());
3194  }
3195  delete result;
3196 
3197  return entryIDs;
3198 }
3199 
3200 
3201 /**
3202  * Adds the given cost estimation data values to given FU entry.
3203  *
3204  * @param fuID The ID of the FU entry the cost data will be added.
3205  * @valueName The name of the cost value.
3206  * @value The cost value.
3207  * @pluginID The ID of the cost function plugin that owns this data.
3208  */
3209 RowID
3211  RowID fuID,
3212  const std::string& valueName,
3213  const std::string& value,
3214  RowID pluginID) const {
3215 
3216 
3217  RowID dataID;
3218 
3219  // add the data
3220  try {
3222  std::string(
3223  "INSERT INTO cost_estimation_data (id,plugin_reference,"
3224  "fu_reference,name,value) VALUES (NULL," +
3225  Conversion::toString(pluginID) + "," +
3226  Conversion::toString(fuID) + ",\"" + valueName + "\",\"" +
3227  value + "\");"));
3228  dataID = dbConnection_->lastInsertRowID();
3229  } catch (const Exception& e) {
3230  debugLog(e.errorMessage());
3231  assert(false);
3232  }
3233  return dataID;
3234 }
3235 
3236 
3237 /**
3238  * Adds the given cost estimation data values to given RF entry.
3239  *
3240  * @param rfID The ID of the RF entry the cost data will be added.
3241  * @valueName The name of the cost value.
3242  * @value The cost value.
3243  * @pluginID The ID of the cost function plugin that owns this data.
3244  */
3245 RowID
3247  RowID rfID,
3248  const std::string& valueName,
3249  const std::string& value,
3250  RowID pluginID) const {
3251 
3252  RowID dataID;
3253 
3254  // add the data
3255  try {
3257  std::string(
3258  "INSERT INTO cost_estimation_data (id,plugin_reference,"
3259  "rf_reference,name,value) VALUES (NULL," +
3260  Conversion::toString(pluginID) + "," +
3261  Conversion::toString(rfID) + ",\"" + valueName + "\",\"" +
3262  value + "\");"));
3263  dataID = dbConnection_->lastInsertRowID();
3264  } catch (const Exception& e) {
3265  debugLog(e.errorMessage());
3266  assert(false);
3267  }
3268  return dataID;
3269 }
3270 
3271 
3272 /**
3273  * Returns FU cost estimation data.
3274  *
3275  * This version assumes that there's only one entry with given parameters.
3276  *
3277  * @todo Another version for fetching lists of data.
3278  * @todo Refactor most of the code in *costEstimationData() functions to
3279  * a helper function
3280  *
3281  * @param valueName Name of the value to fetch.
3282  * @param implementationId The ID of the FU entry.
3283  * @param pluginName Name of the cost estimation plugin that owns the data.
3284  * @return The data.
3285  * @exception KeyNotFound If the HDB does not contain FU cost estimation data
3286  * with the given arguments.
3287  */
3288 DataObject
3290  const std::string& valueName, RowID implementationId,
3291  const std::string& pluginName) const {
3292  // make the SQL query to obtain implementation data
3293  RelationalDBQueryResult* queryResult = NULL;
3294  try {
3295  queryResult = dbConnection_->query(
3296  std::string(
3297  "SELECT value "
3298  "FROM cost_estimation_data, cost_function_plugin "
3299  "WHERE plugin_reference = cost_function_plugin.id AND "
3300  "cost_function_plugin.name LIKE('") +
3301  pluginName + "') " +
3302  " AND rf_reference IS NULL " +
3303  " AND bus_reference IS NULL " +
3304  " AND socket_reference IS NULL AND " +
3305  " fu_reference = " + Conversion::toString(implementationId) +
3306  " AND cost_estimation_data.name LIKE('" + valueName + "');");
3307  } catch (const Exception& e) {
3308  // should not throw in any case
3309  debugLog(e.errorMessage());
3310  assert(false);
3311  }
3312 
3313  if (queryResult->hasNext()) {
3314  queryResult->next();
3315 
3316  DataObject value = queryResult->data("value");
3317 
3318  delete queryResult;
3319  queryResult = NULL;
3320 
3321  return value;
3322  } else {
3323  delete queryResult;
3324  throw KeyNotFound(__FILE__, __LINE__, __func__);
3325  }
3326  // silence compiler warning
3327  throw 1;
3328 }
3329 
3330 /**
3331  * Returns RF cost estimation data.
3332  *
3333  * This version assumes that there's only one entry with given parameters.
3334  *
3335  * @todo Another version for fetching lists of data.
3336  *
3337  * @param valueName Name of the value to fetch.
3338  * @param implementationId The ID of the RF entry.
3339  * @param pluginName Name of the cost estimation plugin that owns the data.
3340  * @return The data.
3341  * @exception KeyNotFound If the HDB does not contain RF cost estimation data
3342  * with the given arguments.
3343  */
3344 DataObject
3346  const std::string& valueName, RowID implementationId,
3347  const std::string& pluginName) const {
3348  // make the SQL query to obtain implementation data
3349  RelationalDBQueryResult* queryResult = NULL;
3350  try {
3351  queryResult = dbConnection_->query(
3352  std::string(
3353  "SELECT value "
3354  "FROM cost_estimation_data, cost_function_plugin "
3355  "WHERE plugin_reference = cost_function_plugin.id AND "
3356  "cost_function_plugin.name LIKE('") +
3357  pluginName + "') " +
3358  " AND fu_reference IS NULL " +
3359  " AND bus_reference IS NULL " +
3360  " AND socket_reference IS NULL AND " +
3361  " rf_reference = " + Conversion::toString(implementationId) +
3362  " AND cost_estimation_data.name LIKE('" + valueName + "');");
3363  } catch (const Exception& e) {
3364  // should not throw in any case
3365  debugLog(e.errorMessage());
3366  assert(false);
3367  }
3368 
3369  if (queryResult->hasNext()) {
3370  queryResult->next();
3371 
3372  DataObject value = queryResult->data("value");
3373 
3374  delete queryResult;
3375  queryResult = NULL;
3376 
3377  return value;
3378  } else {
3379  delete queryResult;
3380  throw KeyNotFound(__FILE__, __LINE__, __func__);
3381  }
3382  // silence compiler warning
3383  throw 1;
3384 }
3385 
3386 /**
3387  * Adds an empty Bus entry to the database.
3388  *
3389  * @param entry The Bus entry.
3390  * @return ID of the added Bus entry.
3391  */
3392 RowID
3394  try {
3396  std::string("INSERT INTO bus(id) VALUES(NULL);"));
3397  return dbConnection_->lastInsertRowID();
3398  } catch (const Exception& e) {
3399  debugLog(e.errorMessage());
3400  assert(false);
3401  }
3402 
3403  // dummy return to avoid compiler whining
3404  assert(false);
3405  return 0;
3406 }
3407 
3408 
3409 /**
3410  * Removes the Bus entry that has the given ID from the database.
3411  *
3412  * The entry is removed entirely, meaning that also cost estimation data
3413  * of that entry are removed.
3414  *
3415  * @param id The ID of the Bus entry.
3416  */
3417 void
3419 
3420  if (!hasBusEntry(id)) {
3421  return;
3422  }
3423 
3424  // remove cost estimation data
3425  try {
3426  // get the IDs of cost estimation datas
3428  std::string(
3429  "SELECT id FROM cost_estimation_data "
3430  "WHERE bus_reference=" + Conversion::toString(id) + ";"));
3431  while (result->hasNext()) {
3432  result->next();
3433  const DataObject& costIDData = result->data(0);
3434  int dataID = costIDData.integerValue();
3435  removeCostEstimationData(dataID);
3436  }
3437  delete result;
3438  } catch (const Exception& e) {
3439  debugLog(e.errorMessage());
3440  assert(false);
3441  }
3442 
3443  // remove from bus table
3444  try {
3446  std::string(
3447  "DELETE FROM bus "
3448  "WHERE id=" + Conversion::toString(id) + ";"));
3449  } catch (const Exception& e) {
3450  debugLog(e.errorMessage());
3451  assert(false);
3452  }
3453 }
3454 
3455 
3456 /**
3457  * Adds the given cost estimation data values to given Bus entry.
3458  *
3459  * @param busID The ID of the Bus entry the cost data will be added.
3460  * @valueName The name of the cost value.
3461  * @value The cost value.
3462  * @pluginID The ID of the cost function plugin that owns this data.
3463  */
3464 RowID
3466  RowID busID,
3467  const std::string& valueName,
3468  const std::string& value,
3469  RowID pluginID) const {
3470 
3471 
3472  RowID dataID;
3473 
3474  // add the data
3475  try {
3477  std::string(
3478  "INSERT INTO cost_estimation_data (id,plugin_reference,"
3479  "bus_reference,name,value) VALUES (NULL," +
3480  Conversion::toString(pluginID) + "," +
3481  Conversion::toString(busID) + ",\"" + valueName + "\",\"" +
3482  value + "\");"));
3483  dataID = dbConnection_->lastInsertRowID();
3484  } catch (const Exception& e) {
3485  debugLog(e.errorMessage());
3486  assert(false);
3487  }
3488  return dataID;
3489 }
3490 
3491 
3492 
3493 /**
3494  * Returns bus cost estimation data.
3495  *
3496  * This version assumes that there's only one entry with given parameters.
3497  *
3498  * @param valueName Name of the value to fetch.
3499  * @param busID The ID of the bus entry.
3500  * @param pluginName Name of the cost estimation plugin that owns the data.
3501  * @return The data.
3502  * @exception KeyNotFound If the HDB does not contain bus cost estimation data
3503  * with the given arguments.
3504  */
3505 DataObject
3507  const std::string& valueName, RowID busID,
3508  const std::string& pluginName) const {
3509  RelationalDBQueryResult* queryResult = NULL;
3510  try {
3511  queryResult = dbConnection_->query(
3512  std::string(
3513  "SELECT value "
3514  "FROM cost_estimation_data, cost_function_plugin "
3515  "WHERE plugin_reference = cost_function_plugin.id AND "
3516  "cost_function_plugin.name LIKE('") +
3517  pluginName + "') " +
3518  " AND rf_reference IS NULL " +
3519  " AND socket_reference IS NULL AND " +
3520  " bus_reference = " + Conversion::toString(busID) +
3521  " AND cost_estimation_data.name LIKE('" + valueName + "');");
3522  } catch (const Exception& e) {
3523  // should not throw in any case
3524  debugLog(e.errorMessage());
3525  assert(false);
3526  }
3527 
3528  if (queryResult->hasNext()) {
3529  queryResult->next();
3530 
3531  DataObject value = queryResult->data("value");
3532 
3533  delete queryResult;
3534  queryResult = NULL;
3535 
3536  return value;
3537  } else {
3538  delete queryResult;
3539  throw KeyNotFound(__FILE__, __LINE__, __func__);
3540  }
3541  // silence compiler warning
3542  throw 1;
3543 }
3544 
3545 /**
3546  * Returns a list of bus cost estimation data.
3547  *
3548  * @param valueName Name of the value to fetch.
3549  * @param busID The ID of the bus entry.
3550  * @param pluginName Name of the cost estimation plugin that owns the data.
3551  * @return The data. Becomes property of the caller.
3552  * @exception KeyNotFound If the HDB does not contain bus cost estimation data
3553  * with the given arguments.
3554  */
3557  const std::string& valueName, RowID busID,
3558  const std::string& pluginName) const {
3559  RelationalDBQueryResult* queryResult = NULL;
3560  try {
3561  queryResult = dbConnection_->query(
3562  std::string(
3563  "SELECT value "
3564  "FROM cost_estimation_data, cost_function_plugin "
3565  "WHERE plugin_reference = cost_function_plugin.id AND "
3566  "cost_function_plugin.name LIKE('") +
3567  pluginName + "') " +
3568  " AND rf_reference IS NULL " +
3569  " AND socket_reference IS NULL AND " +
3570  " bus_reference = " + Conversion::toString(busID) +
3571  " AND cost_estimation_data.name LIKE('" + valueName + "');");
3572  } catch (const Exception& e) {
3573  // should not throw in any case
3574  debugLog(e.errorMessage());
3575  assert(false);
3576  }
3577 
3578  if (queryResult->hasNext()) {
3579 
3580  DataObjectList* data = new DataObjectList;
3581 
3582  while (queryResult->hasNext()) {
3583  queryResult->next();
3584  DataObject value = queryResult->data("value");
3585  data->push_back(value);
3586  }
3587 
3588  delete queryResult;
3589  queryResult = NULL;
3590  return data;
3591  } else {
3592  delete queryResult;
3593  throw KeyNotFound(__FILE__, __LINE__, __func__);
3594  }
3595  // silence compiler warning
3596  throw 1;
3597 }
3598 
3599 /**
3600  * Adds an empty Socket entry to the database.
3601  *
3602  * @param entry The Socket entry.
3603  * @return ID of the added Socket entry.
3604  */
3605 RowID
3607  try {
3609  std::string("INSERT INTO socket(id) VALUES(NULL);"));
3610  return dbConnection_->lastInsertRowID();
3611  } catch (const Exception& e) {
3612  debugLog(e.errorMessage());
3613  assert(false);
3614  }
3615 
3616  // dummy return to avoid compiler whining
3617  assert(false);
3618  return 0;
3619 }
3620 
3621 
3622 /**
3623  * Removes the Socket entry that has the given ID from the database.
3624  *
3625  * The entry is removed entirely, meaning that also cost estimation data
3626  * of that entry are removed.
3627  *
3628  * @param id The ID of the Socket entry.
3629  */
3630 void
3632 
3633  if (!hasSocketEntry(id)) {
3634  return;
3635  }
3636 
3637  // remove cost estimation data
3638  try {
3639  // get the IDs of cost estimation datas
3641  std::string(
3642  "SELECT id FROM cost_estimation_data "
3643  "WHERE socket_reference=" + Conversion::toString(id) + ";"));
3644  while (result->hasNext()) {
3645  result->next();
3646  const DataObject& costIDData = result->data(0);
3647  int dataID = costIDData.integerValue();
3648  removeCostEstimationData(dataID);
3649  }
3650  delete result;
3651  } catch (const Exception& e) {
3652  debugLog(e.errorMessage());
3653  assert(false);
3654  }
3655 
3656  // remove from socket table
3657  try {
3659  std::string(
3660  "DELETE FROM socket "
3661  "WHERE id=" + Conversion::toString(id) + ";"));
3662  } catch (const Exception& e) {
3663  debugLog(e.errorMessage());
3664  assert(false);
3665  }
3666 }
3667 
3668 
3669 /**
3670  * Adds the given cost estimation data values to given Socket entry.
3671  *
3672  * @param socketID The ID of the Socket entry the cost data will be added.
3673  * @valueName The name of the cost value.
3674  * @value The cost value.
3675  * @pluginID The ID of the cost function plugin that owns this data.
3676  */
3677 RowID
3679  RowID socketID,
3680  const std::string& valueName,
3681  const std::string& value,
3682  RowID pluginID) const {
3683 
3684 
3685  RowID dataID;
3686 
3687  // add the data
3688  try {
3690  std::string(
3691  "INSERT INTO cost_estimation_data (id,plugin_reference,"
3692  "socket_reference,name,value) VALUES (NULL," +
3693  Conversion::toString(pluginID) + "," +
3694  Conversion::toString(socketID) + ",\"" + valueName + "\",\"" +
3695  value + "\");"));
3696  dataID = dbConnection_->lastInsertRowID();
3697  } catch (const Exception& e) {
3698  debugLog(e.errorMessage());
3699  assert(false);
3700  }
3701  return dataID;
3702 }
3703 
3704 
3705 /**
3706  * Returns socket cost estimation data.
3707  *
3708  * This version assumes that there's only one entry with given parameters.
3709  *
3710  * @param valueName Name of the value to fetch.
3711  * @param socketID The ID of the socket entry.
3712  * @param pluginName Name of the cost estimation plugin that owns the data.
3713  * @return The data.
3714  * @exception KeyNotFound If the HDB does not contain socket cost estimation
3715  * data with the given arguments.
3716  */
3717 DataObject
3719  const std::string& valueName, RowID socketID,
3720  const std::string& pluginName) const {
3721  // make the SQL query to obtain implementation data
3722  RelationalDBQueryResult* queryResult = NULL;
3723  try {
3724  std::string theQuery =
3725  std::string(
3726  "SELECT value "
3727  "FROM cost_estimation_data, cost_function_plugin "
3728  "WHERE plugin_reference = cost_function_plugin.id AND "
3729  "cost_function_plugin.name LIKE('") +
3730  pluginName + "') " +
3731  " AND rf_reference IS NULL " +
3732  " AND bus_reference IS NULL AND " +
3733  " socket_reference = " +
3734  Conversion::toString(socketID) +
3735  " AND cost_estimation_data.name LIKE('" + valueName + "');";
3736  queryResult = dbConnection_->query(theQuery);
3737 
3738  } catch (const Exception& e) {
3739  // should not throw in any case
3740  debugLog(e.errorMessage());
3741  assert(false);
3742  }
3743 
3744  if (queryResult->hasNext()) {
3745  queryResult->next();
3746 
3747  DataObject value = queryResult->data("value");
3748 
3749  delete queryResult;
3750  queryResult = NULL;
3751 
3752  return value;
3753  } else {
3754  delete queryResult;
3755  throw KeyNotFound(__FILE__, __LINE__, __func__);
3756  }
3757  // silence compiler warning
3758  throw 1;
3759 }
3760 
3761 /**
3762  * Returns socket cost estimation data.
3763  *
3764  * @param valueName Name of the value to fetch.
3765  * @param socketID The ID of the socket entry.
3766  * @param pluginName Name of the cost estimation plugin that owns the data.
3767  * @return The data. Becomes property of the caller.
3768  * @exception KeyNotFound If the HDB does not contain socket cost estimation
3769  * data with the given arguments.
3770  */
3773  const std::string& valueName, RowID socketID,
3774  const std::string& pluginName) const {
3775  RelationalDBQueryResult* queryResult = NULL;
3776  try {
3777  queryResult = dbConnection_->query(
3778  std::string(
3779  "SELECT value "
3780  "FROM cost_estimation_data, cost_function_plugin "
3781  "WHERE plugin_reference = cost_function_plugin.id AND "
3782  "cost_function_plugin.name LIKE('") +
3783  pluginName + "') " +
3784  " AND rf_reference IS NULL " +
3785  " AND bus_reference IS NULL AND " +
3786  " socket_reference = " +
3787  Conversion::toString(socketID) +
3788  " AND cost_estimation_data.name LIKE('" + valueName + "');");
3789  } catch (const Exception& e) {
3790  // should not throw in any case
3791  debugLog(e.errorMessage());
3792  assert(false);
3793  }
3794 
3795  if (queryResult->hasNext()) {
3796 
3797  DataObjectList* data = new DataObjectList;
3798 
3799  while (queryResult->hasNext()) {
3800  queryResult->next();
3801  DataObject value = queryResult->data("value");
3802  data->push_back(value);
3803  }
3804 
3805  delete queryResult;
3806  queryResult = NULL;
3807  return data;
3808  } else {
3809  delete queryResult;
3810  throw KeyNotFound(__FILE__, __LINE__, __func__);
3811  }
3812  // silence compiler warning
3813  throw 1;
3814 }
3815 
3816 /**
3817  * Returns cost estimation data which is not connected to any machine
3818  * implementation id.
3819  *
3820  * This version assumes that there's only one entry with given parameters.
3821  *
3822  * @todo Another version for fetching lists of data.
3823  *
3824  * @param valueName Name of the value to fetch.
3825  * @param pluginName Name of the cost estimation plugin that owns the data.
3826  * @return The data.
3827  * @exception KeyNotFound If the HDB does not contain cost estimation
3828  * data with the given arguments.
3829  */
3830 DataObject
3832  const std::string& valueName, const std::string& pluginName) const {
3833  // make the SQL query to obtain implementation data
3834  RelationalDBQueryResult* queryResult = NULL;
3835  try {
3836  std::string theQuery =
3837  std::string(
3838  "SELECT value "
3839  "FROM cost_estimation_data, cost_function_plugin "
3840  "WHERE plugin_reference = cost_function_plugin.id AND "
3841  "cost_function_plugin.name LIKE('") +
3842  pluginName + "') " +
3843  " AND rf_reference IS NULL " +
3844  " AND fu_reference IS NULL " +
3845  " AND socket_reference IS NULL " +
3846  " AND bus_reference IS NULL " +
3847  " AND cost_estimation_data.name LIKE('" + valueName + "');";
3848  queryResult = dbConnection_->query(theQuery);
3849 
3850  } catch (const Exception& e) {
3851  // should not throw in any case
3852  debugLog(e.errorMessage());
3853  assert(false);
3854  }
3855 
3856  if (queryResult->hasNext()) {
3857  queryResult->next();
3858 
3859  DataObject value = queryResult->data("value");
3860 
3861  delete queryResult;
3862  queryResult = NULL;
3863 
3864  return value;
3865  } else {
3866  delete queryResult;
3867  throw KeyNotFound(__FILE__, __LINE__, __func__);
3868  }
3869  // silence compiler warning
3870  throw 1;
3871 }
3872 
3873 /**
3874  * Returns cost estimation data value with the given id.
3875  *
3876  * @param entryId Id of the cost estimation data entry.
3877  * @return The data.
3878  * @exception KeyNotFound If the HDB does not contain cost estimation
3879  * data with the given arguments.
3880  */
3881 DataObject
3883  // make the SQL query to obtain implementation data
3884  RelationalDBQueryResult* queryResult = NULL;
3885  try {
3886  std::string theQuery =
3887  std::string(
3888  "SELECT value "
3889  "FROM cost_estimation_data "
3890  "WHERE cost_estimation_data.id = ") +
3891  Conversion::toString(entryId);
3892 
3893  queryResult = dbConnection_->query(theQuery);
3894 
3895  } catch (const Exception& e) {
3896  // should not throw in any case
3897  debugLog(e.errorMessage());
3898  assert(false);
3899  }
3900 
3901  if (queryResult->hasNext()) {
3902  queryResult->next();
3903 
3904  DataObject value = queryResult->data("value");
3905 
3906  delete queryResult;
3907  queryResult = NULL;
3908 
3909  return value;
3910  } else {
3911  delete queryResult;
3912  throw KeyNotFound(__FILE__, __LINE__, __func__);
3913  }
3914  // silence compiler warning
3915  throw 1;
3916 }
3917 
3918 /**
3919  * Tells whether the HDB has an FU entry that has the given ID.
3920  *
3921  * @return True if the HDB has the entry, otherwise false.
3922  */
3923 bool
3925 
3926  RelationalDBQueryResult* result;
3927 
3928  try {
3929  result = dbConnection_->query(fuEntryByIDQuery(id));
3930  } catch (const Exception&) {
3931  assert(false);
3932  }
3933 
3934  if (result->hasNext()) {
3935  result->next();
3936  assert(!result->hasNext());
3937  delete result;
3938  return true;
3939  } else {
3940  delete result;
3941  return false;
3942  }
3943 }
3944 
3945 
3946 /**
3947  * Tells whether the HDB has an RF entry that has the given ID.
3948  *
3949  * @return True if the HDB has the entry, otherwise false.
3950  */
3951 bool
3953 
3954  RelationalDBQueryResult* result;
3955 
3956  try {
3957  result = dbConnection_->query(rfEntryByIDQuery(id));
3958  } catch (const Exception&) {
3959  assert(false);
3960  }
3961 
3962  if (result->hasNext()) {
3963  result->next();
3964  assert(!result->hasNext());
3965  delete result;
3966  return true;
3967  } else {
3968  delete result;
3969  return false;
3970  }
3971 }
3972 
3973 
3974 /**
3975  * Tells whether the HDB has an Bus entry that has the given ID.
3976  *
3977  * @return True if the HDB has the entry, otherwise false.
3978  */
3979 bool
3981 
3982  RelationalDBQueryResult* result;
3983 
3984  try {
3985  result = dbConnection_->query(busEntryByIDQuery(id));
3986  } catch (const Exception&) {
3987  assert(false);
3988  }
3989 
3990  if (result->hasNext()) {
3991  result->next();
3992  assert(!result->hasNext());
3993  delete result;
3994  return true;
3995  } else {
3996  delete result;
3997  return false;
3998  }
3999 }
4000 
4001 
4002 /**
4003  * Tells whether the HDB has an Socket entry that has the given ID.
4004  *
4005  * @return True if the HDB has the entry, otherwise false.
4006  */
4007 bool
4009 
4010  RelationalDBQueryResult* result;
4011 
4012  try {
4013  result = dbConnection_->query(socketEntryByIDQuery(id));
4014  } catch (const Exception&) {
4015  assert(false);
4016  }
4017 
4018  if (result->hasNext()) {
4019  result->next();
4020  assert(!result->hasNext());
4021  delete result;
4022  return true;
4023  } else {
4024  delete result;
4025  return false;
4026  }
4027 }
4028 
4029 /**
4030  * Tells whether the HDB has cost estimation data that has the given ID.
4031  *
4032  * @return True if the HDB has the data, otherwise false.
4033  */
4034 bool
4036 
4037  RelationalDBQueryResult* result;
4038  std::string query = "SELECT id FROM cost_estimation_data WHERE id=";
4039  query += Conversion::toString(id) + ";";
4040 
4041  try {
4042  result = dbConnection_->query(query);
4043  } catch (const Exception&) {
4044  assert(false);
4045  }
4046 
4047  if (result->hasNext()) {
4048  result->next();
4049  assert(!result->hasNext());
4050  delete result;
4051  return true;
4052  } else {
4053  delete result;
4054  return false;
4055  }
4056 }
4057 
4058 /**
4059  * Tells whether the HDB has cost function plugin that has the given ID.
4060  *
4061  * @return True if the HDB has the plugin, otherwise false.
4062  */
4063 bool
4065 
4066  RelationalDBQueryResult* result;
4067  std::string query = "SELECT id FROM cost_function_plugin WHERE id=";
4068  query += Conversion::toString(id) + ";";
4069 
4070  try {
4071  result = dbConnection_->query(query);
4072  } catch (const Exception&) {
4073  assert(false);
4074  }
4075 
4076  if (result->hasNext()) {
4077  result->next();
4078  assert(!result->hasNext());
4079  delete result;
4080  return true;
4081  } else {
4082  delete result;
4083  return false;
4084  }
4085 }
4086 
4087 
4088 /**
4089  * Tells whether the FU entry that has the given ID has an architecture.
4090  *
4091  * @param id ID of the FU entry.
4092  * @return True if it has an architecture, otherwise false.
4093  * @exception KeyNotFound If the HDB does not contain a FU entry with the given
4094  * ID.
4095  */
4096 bool
4098  RelationalDBQueryResult* result;
4099  try {
4100  result = dbConnection_->query(
4101  std::string(
4102  "SELECT architecture FROM fu WHERE id=" +
4103  Conversion::toString(id) + ";"));
4104  } catch (const Exception& e) {
4105  debugLog(e.errorMessage());
4106  assert(false);
4107  }
4108 
4109  if (result->hasNext()) {
4110  result->next();
4111  const DataObject& data = result->data(0);
4112  delete result;
4113  return !data.isNull();
4114  } else {
4115  delete result;
4116  throw KeyNotFound(__FILE__, __LINE__, __func__);
4117  }
4118 }
4119 
4120 /**
4121  * Tells whether the RF entry that has the given ID has an architecture.
4122  *
4123  * @param id ID of the RF entry.
4124  * @return True if it has an architecture, otherwise false.
4125  * @exception KeyNotFound If the HDB does not contain a RF entry with the
4126  * given ID.
4127  */
4128 bool
4130  RelationalDBQueryResult* result;
4131  try {
4132  result = dbConnection_->query(
4133  std::string(
4134  "SELECT architecture FROM rf WHERE id=" +
4135  Conversion::toString(id) + ";"));
4136  } catch (const Exception& e) {
4137  debugLog(e.errorMessage());
4138  assert(false);
4139  }
4140 
4141  if (result->hasNext()) {
4142  result->next();
4143  const DataObject& data = result->data(0);
4144  delete result;
4145  return !data.isNull();
4146  } else {
4147  delete result;
4148  throw KeyNotFound(__FILE__, __LINE__, __func__);
4149  }
4150 }
4151 
4152 /**
4153  * Tells whether the HDB contains the given operation in operation table.
4154  *
4155  * @param opName Name of the operation.
4156  * @return True if HDB contains the operation, otherwise false.
4157  */
4158 bool
4159 HDBManager::containsOperation(const std::string& opName) const {
4160  try {
4162  std::string(
4163  "SELECT * FROM operation WHERE lower(name)=lower(\"" + opName
4164  + "\");"));
4165  bool returnValue = result->hasNext();
4166  delete result;
4167  return returnValue;
4168  } catch (const Exception& e) {
4169  debugLog(e.errorMessage());
4170  assert(false);
4171  }
4172 
4173  // dummy return to avoid compiler whining
4174  assert(false);
4175  return false;
4176 }
4177 
4178 
4179 /**
4180  * Tells whether the HDB contains the given block implementation file.
4181  *
4182  * @param pathToFile Full path to the file.
4183  */
4184 bool
4185 HDBManager::containsImplementationFile(const std::string& pathToFile) const {
4186  try {
4188  std::string(
4189  "SELECT * FROM block_source_file WHERE file=\"" +
4190  pathToFile + "\";"));
4191  bool returnValue = result->hasNext();
4192  delete result;
4193  return returnValue;
4194  } catch (const Exception& e) {
4195  debugLog(e.errorMessage());
4196  assert(false);
4197  }
4198 
4199  // dummy return to avoid compiler whining
4200  assert(false);
4201  return false;
4202 }
4203 
4204 
4205 /**
4206  * Tells whether the HDB contains a FU architecture that has the given ID.
4207  *
4208  * @param id The ID.
4209  * @return True if the HDB contains the architecture, otherwise false.
4210  */
4211 bool
4213 
4214  try {
4216  std::string(
4217  "SELECT id FROM fu_architecture WHERE id=" +
4218  Conversion::toString(id) + ";"));
4219  bool returnValue = result->hasNext();
4220  delete result;
4221  return returnValue;
4222  } catch (const Exception& e) {
4223  debugLog(e.errorMessage());
4224  assert(false);
4225  }
4226 
4227  // dummy return to avoid compiler whining
4228  assert(false);
4229  return false;
4230 }
4231 
4232 
4233 /**
4234  * Tells whether the HDB contains a RF architecture with the given ID.
4235  *
4236  * @param id The ID.
4237  * @return True if the HDB contains the architecture, otherwise false.
4238  */
4239 bool
4241  try {
4243  std::string(
4244  "SELECT id FROM rf_architecture WHERE id=" +
4245  Conversion::toString(id) + ";"));
4246  bool returnValue = result->hasNext();
4247  delete result;
4248  return returnValue;
4249  } catch (const Exception& e) {
4250  debugLog(e.errorMessage());
4251  assert(false);
4252  }
4253 
4254  // dummy return to avoid compiler whining
4255  assert(false);
4256  return false;
4257 }
4258 
4259 
4260 /**
4261  * Returns the ID of the architecture of the given FU entry.
4262  *
4263  * @param fuEntryID ID of the FU entry.
4264  * @return ID of the FU architecture.
4265  * @exception NotAvailable If the FU entry does not have an architecture.
4266  */
4267 RowID
4269  RelationalDBQueryResult* result;
4270  try {
4271  result = dbConnection_->query(
4272  std::string(
4273  "SELECT architecture FROM fu WHERE id=" +
4274  Conversion::toString(fuEntryID) + ";"));
4275  } catch (const Exception& e) {
4276  debugLog(e.errorMessage());
4277  assert(false);
4278  }
4279 
4280  if (!result->hasNext()) {
4281  delete result;
4282  throw NotAvailable(__FILE__, __LINE__, __func__);
4283  }
4284 
4285  result->next();
4286  const DataObject& idData = result->data(0);
4287  if (idData.isNull()) {
4288  delete result;
4289  throw NotAvailable(__FILE__, __LINE__, __func__);
4290  } else {
4291  RowID retValue = idData.integerValue();
4292  delete result;
4293  return retValue;
4294  }
4295 }
4296 
4297 /**
4298  * Returns the ID of the architecture of the given RF entry.
4299  *
4300  * @param rfEntryID ID of the RF entry.
4301  * @return ID of the RF architecture.
4302  * @exception NotAvailable If the RF entry does not have an architecture.
4303  */
4304 RowID
4306  RelationalDBQueryResult* result;
4307  try {
4308  result = dbConnection_->query(
4309  std::string(
4310  "SELECT architecture FROM rf WHERE id=" +
4311  Conversion::toString(rfEntryID) + ";"));
4312  } catch (const Exception& e) {
4313  debugLog(e.errorMessage());
4314  assert(false);
4315  }
4316 
4317  if (!result->hasNext()) {
4318  delete result;
4319  throw NotAvailable(__FILE__, __LINE__, __func__);
4320  }
4321 
4322  result->next();
4323  const DataObject& idData = result->data(0);
4324  if (idData.isNull()) {
4325  delete result;
4326  throw NotAvailable(__FILE__, __LINE__, __func__);
4327  } else {
4328  RowID retValue = idData.integerValue();
4329  delete result;
4330  return retValue;
4331  }
4332 }
4333 
4334 /**
4335  * Returns true if a table by name has a column by given name.
4336  *
4337  * @param table The table by name to search the column from.
4338  * @param columnName The name of the column to be searched.
4339  * @return True if the table has the named column.
4340  */
4341 bool
4343  const std::string& table, const std::string& columnName) const {
4344 
4345  std::string table_info_query("PRAGMA table_info(");
4346  table_info_query += table;
4347  table_info_query += ");";
4348 
4349  RelationalDBQueryResult* result;
4350  try {
4351  result = dbConnection_->query(table_info_query);
4352  } catch (const Exception& e) {
4353  debugLog(e.errorMessage());
4354  assert(false);
4355  }
4356 
4357  while(result->hasNext()) {
4358  result->next();
4359  // Second column in result row is column name of the table.
4360  const DataObject& columnData = result->data(1);
4361  std::string columnNameFromTable = columnData.stringValue();
4362 
4363  assert(!columnNameFromTable.empty());
4364  if(columnNameFromTable == columnName) {
4365  return true;
4366  }
4367  }
4368 
4369  return false;
4370 }
4371 
4372 /**
4373  * Inserts a new boolean type column into existing table.
4374  *
4375  * @param table The name of the targeted table.
4376  * @param newColumn The name of the new column.
4377  * @return Number of rows affected by the change.
4378  */
4379 int
4380 HDBManager::addBooleanColumn(const std::string& table,
4381  const std::string& newcolumn) {
4382  std::string add_column_query("ALTER TABLE ");
4383  add_column_query += table + " ADD COLUMN " + newcolumn;
4384  add_column_query += " INTEGER DEFAULT 0;";
4385 
4386  int result = 0;
4387 
4388  try {
4389  result = dbConnection_->updateQuery(add_column_query);
4390  } catch (const Exception& e) {
4391  debugLog(e.errorMessage());
4392  assert(false);
4393  }
4394 
4395  return result;
4396 }
4397 
4398 /**
4399  * Obtains data from HDB and creates ports and operand bindings to the given
4400  * FU architecture that has the given ID in HDB.
4401  *
4402  * @param architecture The FU architecture to which the ports are added.
4403  * @param id ID of the FU architecture in HDB.
4404  */
4405 void
4407  FUArchitecture& architecture,
4408  RowID id) const {
4409 
4410  FunctionUnit& fu = architecture.architecture();
4411 
4412  // make the SQL query to obtain the ports
4413  RelationalDBQueryResult* fuPorts = NULL;
4414  try {
4416  } catch (const Exception& e) {
4418  }
4419  int portIDColumnIndex = fuPorts->column("fu_data_port.id");
4420  int triggersColumnIndex = fuPorts->column("fu_data_port.triggers");
4421  int setsOpcodeColumnIndex = fuPorts->column("fu_data_port.sets_opcode");
4422  int guardSupportColumnIndex = fuPorts->column(
4423  "fu_data_port.guard_support");
4424  int widthColumnIndex = fuPorts->column("fu_data_port.width");
4425  int operationColumnIndex = fuPorts->column("operation.name");
4426  int bindingColumnIndex = fuPorts->column("io_binding.io_number");
4427 
4428  // @fixme Do not assert() inside a library function in case of broken
4429  // user input data!!
4430  assert(portIDColumnIndex != RelationalDBQueryResult::UNKNOWN_INDEX);
4431  assert(triggersColumnIndex != RelationalDBQueryResult::UNKNOWN_INDEX);
4432  assert(setsOpcodeColumnIndex != RelationalDBQueryResult::UNKNOWN_INDEX);
4433  assert(
4434  guardSupportColumnIndex != RelationalDBQueryResult::UNKNOWN_INDEX);
4435  assert(widthColumnIndex != RelationalDBQueryResult::UNKNOWN_INDEX);
4436  assert(operationColumnIndex != RelationalDBQueryResult::UNKNOWN_INDEX);
4437  assert(bindingColumnIndex != RelationalDBQueryResult::UNKNOWN_INDEX);
4438 
4439  if (!fuPorts->hasNext()) {
4440  delete fuPorts;
4441  abortWithError("No row.");
4442  }
4443 
4444  std::map<int, std::string> portIDMap;
4445 
4446  // create ports, operations and bindings to the FU
4447  int name(1);
4448  while (fuPorts->hasNext()) {
4449  fuPorts->next();
4450 
4451  const DataObject& idData = fuPorts->data(portIDColumnIndex);
4452  const DataObject& triggersData = fuPorts->data(triggersColumnIndex);
4453  const DataObject& setsOpcodeData = fuPorts->data(
4454  setsOpcodeColumnIndex);
4455  const DataObject& guardData = fuPorts->data(guardSupportColumnIndex);
4456  const DataObject& widthData = fuPorts->data(widthColumnIndex);
4457  const DataObject& operationData = fuPorts->data(
4458  operationColumnIndex);
4459  const DataObject& bindingData = fuPorts->data(bindingColumnIndex);
4460 
4461  int portID = idData.integerValue();
4462 
4463  // create operation if it is not created yet
4464  string operationName = operationData.stringValue();
4465  if (!fu.hasOperation(operationName)) {
4466  new HWOperation(operationName, fu);
4467  }
4468 
4469  // create port if it is not created yet
4470  if (!MapTools::containsKey(portIDMap, portID)) {
4471  bool triggers = triggersData.boolValue();
4472  bool setsOpcode = setsOpcodeData.boolValue();
4473  string portName = "p" + Conversion::toString(name);
4474 
4475  int width = DEFAULT_PORT_WIDTH;
4476  if (widthData.isNull()) {
4477  architecture.setParameterizedWidth(portName);
4478  } else {
4479  width = widthData.integerValue();
4480  }
4481  new FUPort(portName, width, fu, triggers, setsOpcode);
4482  portIDMap.insert(
4483  std::pair<int, string>(idData.integerValue(), portName));
4484  if (setsOpcode && !triggers)
4485  debugLog(
4486  std::string("Created a suspicious port ") + portName +
4487  " which sets opcode but does not trigger");
4488 
4489  // set guard support
4490  if (guardData.boolValue()) {
4491  architecture.setGuardSupport(portName);
4492  }
4493 
4494  name++;
4495  }
4496 
4497  // create binding
4498  FUPort* portToBind = fu.operationPort(
4499  MapTools::valueForKey<string>(portIDMap, portID));
4500  HWOperation* operation = fu.operation(operationName);
4501  operation->bindPort(bindingData.integerValue(), *portToBind);
4502  }
4503 
4504  delete fuPorts;
4505  fuPorts = NULL;
4506 }
4507 
4508 
4509 /**
4510  * Obtains data from HDB and creates the operation pipelines to the
4511  * given FU architecture.
4512  *
4513  * @param architecture The FU architecture to which the operations are added.
4514  * @param id ID the FU architecture in HDB.
4515  */
4516 void
4518  FUArchitecture& architecture,
4519  RowID id) const {
4520 
4521  FunctionUnit& fu = architecture.architecture();
4522 
4523  // make the SQL query to obtain IO usage data
4524  RelationalDBQueryResult* ioUsageData = NULL;
4525  try {
4526  ioUsageData = dbConnection_->query(ioUsageDataByIDQuery(id));
4527  } catch (const Exception& e) {
4528  assert(false);
4529  }
4530  int operationColumn = ioUsageData->column("operation.name");
4531  int cycleColumn = ioUsageData->column("io_usage.cycle");
4532  int ioColumn = ioUsageData->column("io_usage.io_number");
4533  int actionColumn = ioUsageData->column("io_usage.action");
4534 
4535  while (ioUsageData->hasNext()) {
4536  ioUsageData->next();
4537  const DataObject& operationData = ioUsageData->data(operationColumn);
4538  const DataObject& cycleData = ioUsageData->data(cycleColumn);
4539  const DataObject& ioData = ioUsageData->data(ioColumn);
4540  const DataObject& actionData = ioUsageData->data(actionColumn);
4541 
4542  string operationName = operationData.stringValue();
4543  int cycle = cycleData.integerValue();
4544  int ioNumber = ioData.integerValue();
4545  int action = actionData.boolValue();
4546 
4547  assert(fu.hasOperation(operationName));
4548  HWOperation* operation = fu.operation(operationName);
4549  ExecutionPipeline* pipeline = operation->pipeline();
4550  if (action == READ_ACTION) {
4551  pipeline->addPortRead(ioNumber, cycle, 1);
4552  } else if (action == WRITE_ACTION) {
4553  pipeline->addPortWrite(ioNumber, cycle, 1);
4554  }
4555  }
4556 
4557  delete ioUsageData;
4558  ioUsageData = NULL;
4559 
4560  // add resource usages
4561  RelationalDBQueryResult* resUsageData = NULL;
4562  try {
4563  resUsageData = dbConnection_->query(resourceUsageDataByIDQuery(id));
4564  } catch (const Exception&) {
4565  assert(false);
4566  }
4567  operationColumn = resUsageData->column("operation.name");
4568  cycleColumn = resUsageData->column("pipeline_resource_usage.cycle");
4569  int resourceColumn = resUsageData->column("pipeline_resource.id");
4570 
4571  int resourceName(0);
4572  std::map<int, string> resourceMap;
4573 
4574  while (resUsageData->hasNext()) {
4575  resUsageData->next();
4576  const DataObject& operationData = resUsageData->data(
4577  operationColumn);
4578  const DataObject& cycleData = resUsageData->data(cycleColumn);
4579  const DataObject& resourceData = resUsageData->data(resourceColumn);
4580 
4581  string operationName = operationData.stringValue();
4582  int cycle = cycleData.integerValue();
4583  int resourceID = resourceData.integerValue();
4584 
4585  assert(fu.hasOperation(operationName));
4586  HWOperation* operation = fu.operation(operationName);
4587  ExecutionPipeline* pipeline = operation->pipeline();
4588  if (!MapTools::containsKey(resourceMap, resourceID)) {
4589  resourceMap.insert(
4590  std::pair<int, string>(
4591  resourceID, "res" + Conversion::toString(resourceName)));
4592  resourceName++;
4593  }
4594  pipeline->addResourceUse(
4595  MapTools::valueForKey<string>(
4596  resourceMap, resourceID), cycle, 1);
4597  }
4598 
4599  delete resUsageData;
4600  resUsageData = NULL;
4601 }
4602 
4603 
4604 /**
4605  * Obtains implementation data of the FU that has the given ID and creates an
4606  * FUImplementation instance of it.
4607  *
4608  * @param architecture Architecture of the FU (needed when matching the
4609  * ports in the implementation).
4610  * @param id ID of the FU entry.
4611  * @return The newly created FUImplementation instance or NULL if the FU
4612  * has no implementation.
4613  */
4616  FUArchitecture& architecture,
4617  RowID id) const {
4618 
4619  // make the SQL query to obtain implementation data
4620  RelationalDBQueryResult* implData = NULL;
4621  const std::string queryString = fuImplementationByIDQuery(id);
4622  try {
4623  implData = dbConnection_->query(queryString);
4624  } catch (const Exception& e) {
4625  delete implData;
4626  debugLog(
4627  std::string("query ") + queryString + " threw something: " +
4628  e.errorMessage());
4629  return NULL;
4630  }
4631 
4633 
4634  if (implData->hasNext()) {
4635  implData->next();
4636  assert(!implData->hasNext());
4637 
4638  int idColumn = implData->column("fu_implementation.id");
4639  int nameColumn = implData->column("fu_implementation.name");
4640  int opcodePortColumn = implData->column(
4641  "fu_implementation.opcode_port");
4642  int clkPortColumn = implData->column("fu_implementation.clk_port");
4643  int rstPortColumn = implData->column("fu_implementation.rst_port");
4644  int glockPortColumn = implData->column(
4645  "fu_implementation.glock_port");
4646  int glockReqPortColumn = implData->column(
4647  "fu_implementation.glock_req_port");
4648 
4649  const DataObject& idData = implData->data(idColumn);
4650  const DataObject& nameData = implData->data(nameColumn);
4651  const DataObject& opcodePortData = implData->data(opcodePortColumn);
4652  const DataObject& clkPortData = implData->data(clkPortColumn);
4653  const DataObject& rstPortData = implData->data(rstPortColumn);
4654  const DataObject& glockPortData = implData->data(glockPortColumn);
4655  const DataObject& glockReqPortData = implData->data(
4656  glockReqPortColumn);
4657 
4658  RowID implID = idData.integerValue();
4659  string name = nameData.stringValue();
4660  string opcodePort = opcodePortData.stringValue();
4661  string clkPort = clkPortData.stringValue();
4662  string rstPort = rstPortData.stringValue();
4663  string glockPort = glockPortData.stringValue();
4664  string glockReqPort = glockReqPortData.stringValue();
4665 
4667  name, opcodePort, clkPort, rstPort, glockPort, glockReqPort);
4668  implementation->setID(implID);
4669 
4672  addDataPortsToImplementation(*implementation, architecture, id);
4675  }
4676 
4677  delete implData;
4678  implData = NULL;
4679  return implementation;
4680 }
4681 
4682 /**
4683  * Obtains the cost function data of the FU that has the given ID and creates
4684  * a CostFunctionPlugin instance of it.
4685  *
4686  * @param id ID of the FU entry.
4687  * @return The newly created FUImplementation instance or NULL if the FU
4688  * has no cost function.
4689  */
4692 
4693  // make the SQL query to obtain implementation data
4694  RelationalDBQueryResult* queryResult = NULL;
4695  try {
4696  queryResult = dbConnection_->query(
4697  "SELECT cost_function_plugin.id AS id, "
4698  " cost_function_plugin.description AS description,"
4699  " cost_function_plugin.name AS name, "
4700  " cost_function_plugin.plugin_file_path AS plugin_file_path "
4701  "FROM cost_function_plugin, fu "
4702  "WHERE fu.id = " + Conversion::toString(id) +
4703  " AND cost_function_plugin.id = fu.cost_function;");
4704  } catch (const Exception& e) {
4705  delete queryResult;
4706  debugLog(e.errorMessage());
4707  return NULL;
4708  }
4709 
4710  CostFunctionPlugin* costFunction = NULL;
4711 
4712  if (queryResult->hasNext()) {
4713  queryResult->next();
4714 
4715  const DataObject& pluginIdData =
4716  queryResult->data("id");
4717  const DataObject& descriptionData =
4718  queryResult->data("description");
4719  const DataObject& nameData =
4720  queryResult->data("name");
4721  const DataObject& pluginFilePathData =
4722  queryResult->data("plugin_file_path");
4723 
4724  int pluginId = -1;
4725  string description = "";
4726  string name = "";
4727  string pluginFilePath = "";
4728  try {
4729  if (!pluginIdData.isNull()) {
4730  pluginId = pluginIdData.integerValue();
4731  }
4732  description = descriptionData.stringValue();
4733  name = nameData.stringValue();
4734  pluginFilePath = pluginFilePathData.stringValue();
4735  } catch (const Exception& e) {
4736  debugLog(
4737  std::string("Something wrong with conversion: ") +
4738  e.errorMessage());
4739  delete queryResult;
4740  queryResult = NULL;
4741  return NULL;
4742  }
4743 
4744  costFunction = new CostFunctionPlugin(
4745  pluginId, description, name, pluginFilePath,
4747  }
4748 
4749  delete queryResult;
4750  queryResult = NULL;
4751  return costFunction;
4752 }
4753 
4754 /**
4755  * Obtains the cost function data of the RF that has the given ID and creates
4756  * a CostFunctionPlugin instance of it.
4757  *
4758  * @param id ID of the RF entry.
4759  * @return The newly created FUImplementation instance or NULL if the RF
4760  * has no cost function.
4761  */
4764 
4765  // make the SQL query to obtain implementation data
4766  RelationalDBQueryResult* queryResult = NULL;
4767  try {
4768  queryResult = dbConnection_->query(
4769  "SELECT cost_function_plugin.id AS id, "
4770  " cost_function_plugin.description AS description,"
4771  " cost_function_plugin.name AS name, "
4772  " cost_function_plugin.plugin_file_path AS plugin_file_path "
4773  "FROM cost_function_plugin, rf "
4774  "WHERE rf.id = " + Conversion::toString(id) +
4775  " AND cost_function_plugin.id = rf.cost_function;");
4776  } catch (const Exception& e) {
4777  delete queryResult;
4778  debugLog(e.errorMessage());
4779  return NULL;
4780  }
4781 
4782  CostFunctionPlugin* costFunction = NULL;
4783 
4784  if (queryResult->hasNext()) {
4785  queryResult->next();
4786 
4787  const DataObject& pluginIdData =
4788  queryResult->data("id");
4789  const DataObject& descriptionData =
4790  queryResult->data("description");
4791  const DataObject& nameData =
4792  queryResult->data("name");
4793  const DataObject& pluginFilePathData =
4794  queryResult->data("plugin_file_path");
4795 
4796  int pluginId = -1;
4797  string description = "";
4798  string name = "";
4799  string pluginFilePath = "";
4800  try {
4801  if (!pluginIdData.isNull()) {
4802  pluginId = pluginIdData.integerValue();
4803  }
4804  description = descriptionData.stringValue();
4805  name = nameData.stringValue();
4806  pluginFilePath = pluginFilePathData.stringValue();
4807  } catch (const Exception& e) {
4808  debugLog(
4809  std::string("Something wrong with conversion: ") +
4810  e.errorMessage());
4811  delete queryResult;
4812  queryResult = NULL;
4813  return NULL;
4814  }
4815 
4816  costFunction = new CostFunctionPlugin(
4817  pluginId, description, name, pluginFilePath,
4819  }
4820 
4821  delete queryResult;
4822  queryResult = NULL;
4823  return costFunction;
4824 }
4825 
4826 
4827 
4828 /**
4829  * Obtains implementation data of the RF that has the given ID and creates
4830  * an RFImplementation instance of it.
4831  *
4832  * @param id ID of the RF entry.
4833  * @return The newly created RFImplementation instance or NULL if the RF
4834  * has no implementation.
4835  */
4838 
4839  RelationalDBQueryResult* implementationData = NULL;
4840  try {
4841  if(hasColumn("rf_implementation", "sac_param")) {
4842  // Use new query.
4843  implementationData = dbConnection_->query(
4845  } else {
4846  // Use fallback query.
4847  implementationData = dbConnection_->query(
4849  }
4850  } catch (const Exception& e) {
4851  assert(false);
4852  }
4853 
4855 
4856  if (implementationData->hasNext()) {
4857  implementationData->next();
4858  assert(!implementationData->hasNext());
4859  int idColumn = implementationData->column("id");
4860  int nameColumn = implementationData->column("name");
4861  int sizeParamColumn = implementationData->column("size_param");
4862  int widthParamColumn = implementationData->column("width_param");
4863  int sacParamColumn = implementationData->column("sac_param");
4864  int clkPortColumn = implementationData->column("clk_port");
4865  int rstPortColumn = implementationData->column("rst_port");
4866  int glockPortColumn = implementationData->column("glock_port");
4867  int guardPortColumn = implementationData->column("guard_port");
4868 
4869  const DataObject& idData = implementationData->data(idColumn);
4870  const DataObject& nameData = implementationData->data(nameColumn);
4871  const DataObject& sizeParamData = implementationData->data(
4872  sizeParamColumn);
4873  const DataObject& widthParamData = implementationData->data(
4874  widthParamColumn);
4875  const DataObject& clkPortData = implementationData->data(
4876  clkPortColumn);
4877  const DataObject& rstPortData = implementationData->data(
4878  rstPortColumn);
4879  const DataObject& glockPortData = implementationData->data(
4880  glockPortColumn);
4881  const DataObject& guardPortData = implementationData->data(
4882  guardPortColumn);
4883  const DataObject& sacParamData = implementationData->data(
4884  sacParamColumn);
4885 
4886  string sizeParam = sizeParamData.stringValue();
4887  string widthParam = widthParamData.stringValue();
4888  string guardPort = guardPortData.stringValue();
4889  bool sacParam =
4890  (sacParamColumn != RelationalDBQueryResult::UNKNOWN_INDEX) ?
4891  sacParamData.boolValue() :
4892  false;
4893 
4895  nameData.stringValue(), clkPortData.stringValue(),
4896  rstPortData.stringValue(), glockPortData.stringValue(),
4897  sizeParam, widthParam, guardPort, sacParam);
4898  implementation->setID(idData.integerValue());
4899 
4904  }
4905 
4906  delete implementationData;
4907  implementationData = NULL;
4908  return implementation;
4909 }
4910 
4911 
4912 /**
4913  * Resolves what is the architectural port corresponding to the given
4914  * implemented port.
4915  *
4916  * @param architecture The architecture of the FU.
4917  * @param id ID of the FU entry in the database.
4918  * @param implementedPort Name of the implemented port to resolve.
4919  * @return Name of the corresponding port in the FU architecture.
4920  */
4921 std::string
4923  const FUArchitecture& architecture,
4924  RowID entryID,
4925  const std::string& implementedPort) const {
4926 
4927  RelationalDBQueryResult* bindingData = NULL;
4928  try {
4929  bindingData = dbConnection_->query(
4930  fuPortBindingByNameQuery(entryID, implementedPort));
4931  } catch (const Exception&) {
4932  assert(false);
4933  }
4934 
4935  int operationColumn = bindingData->column("operation.name");
4936  int ioColumn = bindingData->column("io_binding.io_number");
4937  assert(operationColumn != RelationalDBQueryResult::UNKNOWN_INDEX);
4939 
4940  FunctionUnit& fu = architecture.architecture();
4941  string portName = "";
4942 
4943  while (bindingData->hasNext()) {
4944  bindingData->next();
4945  const DataObject& operationData = bindingData->data(operationColumn);
4946  const DataObject& ioData = bindingData->data(ioColumn);
4947  string operationName = operationData.stringValue();
4948  int io = ioData.integerValue();
4949  assert(fu.hasOperation(operationName));
4950  HWOperation* operation = fu.operation(operationName);
4951  FUPort* port = operation->port(io);
4952  assert(portName == "" || portName == port->name());
4953  portName = port->name();
4954  }
4955 
4956  delete bindingData;
4957  bindingData = NULL;
4958 
4959  return portName;
4960 }
4961 
4962 
4963 /**
4964  * Adds the operation codes to the given FU implementation which is the
4965  * implementation of the FU entry that has the given ID.
4966  *
4967  * @param implementation The FU implementation.
4968  * @param entryID ID of the FU entry.
4969  */
4970 void
4973  RowID entryID) const {
4974 
4975  RelationalDBQueryResult* opcodeData = NULL;
4976  try {
4977  opcodeData = dbConnection_->query(opcodesByIDQuery(entryID));
4978  } catch (const Exception&) {
4979  assert(false);
4980  }
4981  int operationColumn = opcodeData->column("operation.name");
4982  int opcodeColumn = opcodeData->column("opcode_map.opcode");
4983  while (opcodeData->hasNext()) {
4984  opcodeData->next();
4985  const DataObject& operationData = opcodeData->data(
4986  operationColumn);
4987  const DataObject& opcodeDataObject = opcodeData->data(
4988  opcodeColumn);
4989  implementation.setOpcode(
4990  operationData.stringValue(), opcodeDataObject.integerValue());
4991  }
4992  delete opcodeData;
4993  opcodeData = NULL;
4994 }
4995 
4996 
4997 /**
4998  * Adds data ports to the given FU implementation which is the implementation
4999  * of the FU entry that has the given ID.
5000  *
5001  * @param implementation The implementation.
5002  * @param architecture The corresponding architecture.
5003  * @param entryID ID of the FU entry.
5004  */
5005 void
5008  FUArchitecture& architecture,
5009  RowID entryID) const {
5010 
5011  RelationalDBQueryResult* portData = NULL;
5012  try {
5013  portData = dbConnection_->query(
5015  } catch (const Exception& e) {
5016  assert(false);
5017  }
5018  int portNameColumn = portData->column("fu_port_map.name");
5019  int widthFormulaColumn = portData->column("fu_port_map.width_formula");
5020  int loadPortColumn = portData->column("fu_port_map.load_port");
5021  int guardPortColumn = portData->column("fu_port_map.guard_port");
5022 
5023  while (portData->hasNext()) {
5024  portData->next();
5025  const DataObject& portNameData = portData->data(portNameColumn);
5026  const DataObject& widthFormulaData = portData->data(
5027  widthFormulaColumn);
5028  const DataObject& loadPortData = portData->data(loadPortColumn);
5029  const DataObject& guardPortData = portData->data(guardPortColumn);
5030 
5031  string portName = portNameData.stringValue();
5032  string widthFormula = widthFormulaData.stringValue();
5033  string loadPort = loadPortData.stringValue();
5034  string guardPort = guardPortData.stringValue();
5035  string architecturePort = resolveArchitecturePort(
5036  architecture, entryID, portName);
5038  portName, architecturePort, widthFormula, loadPort, guardPort,
5039  implementation);
5040  }
5041 
5042  delete portData;
5043  portData = NULL;
5044 }
5045 
5046 
5047 /**
5048  * Adds external ports to the given FU implementation which is the
5049  * implementation of the FU entry that has the given ID.
5050  *
5051  * @param implementation The implementation.
5052  * @param entryID ID of the FU entry.
5053  */
5054 void
5057  RowID entryID) const {
5058 
5059  RelationalDBQueryResult* extPortData = NULL;
5060  try {
5061  extPortData = dbConnection_->query(fuExternalPortsByIDQuery(entryID));
5062  } catch (const Exception& e) {
5063  assert(false);
5064  }
5065 
5066  int extPortNameColumn = extPortData->column("fu_external_port.name");
5067  int directionColumn = extPortData->column(
5068  "fu_external_port.direction");
5069  int extPortWidthFormulaColumn = extPortData->column(
5070  "fu_external_port.width_formula");
5071  int descriptionColumn = extPortData->column(
5072  "fu_external_port.description");
5073 
5074  while (extPortData->hasNext()) {
5075  extPortData->next();
5076  const DataObject& nameData = extPortData->data(
5077  extPortNameColumn);
5078  const DataObject& directionData = extPortData->data(
5079  directionColumn);
5080  const DataObject& widthFormulaData = extPortData->data(
5081  extPortWidthFormulaColumn);
5082  const DataObject& descriptionData = extPortData->data(
5083  descriptionColumn);
5084 
5085  string name = nameData.stringValue();
5086  string widthFormula = widthFormulaData.stringValue();
5087  string description = descriptionData.stringValue();
5088 
5089  Direction direction;
5090  if (directionData.stringValue() == IN_DIRECTION) {
5091  direction = IN;
5092  } else if (directionData.stringValue() == OUT_DIRECTION) {
5093  direction = OUT;
5094  } else {
5095  assert(directionData.stringValue() == BIDIR_DIRECTION);
5096  direction = BIDIR;
5097  }
5098 
5099  new FUExternalPort(
5100  name, direction, widthFormula, description, implementation);
5101  }
5102 
5103  delete extPortData;
5104  extPortData = NULL;
5105 
5106  // add parameter dependencies
5107  for (int i = 0; i < implementation.externalPortCount(); i++) {
5108  FUExternalPort& port = implementation.externalPort(i);
5109  try {
5111  std::string(
5112  "SELECT fu_implementation_parameter.name FROM "
5113  "fu_implementation_parameter, fu_external_port, "
5114  "fu_ext_port_parameter_dependency, fu_implementation "
5115  "WHERE fu_implementation.fu=" +
5116  Conversion::toString(entryID) +
5117  " AND fu_external_port.fu_impl=fu_implementation.id AND "
5118  "fu_external_port.name=\"" + port.name() +
5119  "\" AND fu_ext_port_parameter_dependency.port="
5120  "fu_external_port.id AND fu_implementation_parameter.id="
5121  "fu_ext_port_parameter_dependency.parameter;"));
5122  while (result->hasNext()) {
5123  result->next();
5124  const DataObject& paramData = result->data(0);
5125  port.setParameterDependency(paramData.stringValue());
5126  }
5127  delete result;
5128  } catch (const Exception& e) {
5129  debugLog(e.errorMessage());
5130  assert(false);
5131  }
5132  }
5133 }
5134 
5135 /**
5136  * Adds external ports to the given RF implementation which is the
5137  * implementation of the RF entry that has the given ID.
5138  *
5139  * @param implementation The implementation.
5140  * @param entryID ID of the RF implementation entry.
5141  */
5142 void
5145  RowID entryID) const {
5146 
5147  if (!dbConnection_->tableExistsInDB("rf_external_port")) {
5148  return;
5149  }
5150 
5151  RelationalDBQueryResult* extPortData = NULL;
5152  try {
5153  extPortData = dbConnection_->query(rfExternalPortsByIDQuery(entryID));
5154  } catch (const Exception& e) {
5155  assert(false);
5156  }
5157 
5158  int extPortNameColumn = extPortData->column("rf_external_port.name");
5159  int directionColumn = extPortData->column(
5160  "rf_external_port.direction");
5161  int extPortWidthFormulaColumn = extPortData->column(
5162  "rf_external_port.width_formula");
5163  int descriptionColumn = extPortData->column(
5164  "rf_external_port.description");
5165 
5166  while (extPortData->hasNext()) {
5167  extPortData->next();
5168  const DataObject& nameData = extPortData->data(
5169  extPortNameColumn);
5170  const DataObject& directionData = extPortData->data(
5171  directionColumn);
5172  const DataObject& widthFormulaData = extPortData->data(
5173  extPortWidthFormulaColumn);
5174  const DataObject& descriptionData = extPortData->data(
5175  descriptionColumn);
5176 
5177  string name = nameData.stringValue();
5178  string widthFormula = widthFormulaData.stringValue();
5179  string description = descriptionData.stringValue();
5180 
5181  Direction direction;
5182  if (directionData.stringValue() == IN_DIRECTION) {
5183  direction = IN;
5184  } else if (directionData.stringValue() == OUT_DIRECTION) {
5185  direction = OUT;
5186  } else {
5187  assert(directionData.stringValue() == BIDIR_DIRECTION);
5188  direction = BIDIR;
5189  }
5190 
5191  new RFExternalPort(
5192  name, direction, widthFormula, description, implementation);
5193  }
5194 
5195  delete extPortData;
5196  extPortData = NULL;
5197 
5198  // add parameter dependencies
5199  if (!dbConnection_->tableExistsInDB("rf_ext_port_parameter_dependency")) {
5200  return;
5201  }
5202 
5203  for (int i = 0; i < implementation.externalPortCount(); i++) {
5204  RFExternalPort& port = implementation.externalPort(i);
5205  try {
5207  std::string(
5208  "SELECT rf_implementation_parameter.name FROM "
5209  "rf_implementation_parameter, rf_external_port, "
5210  "rf_ext_port_parameter_dependency, rf_implementation "
5211  "WHERE rf_implementation.rf=" +
5212  Conversion::toString(entryID) +
5213  " AND rf_external_port.rf_impl=rf_implementation.id AND "
5214  "rf_external_port.name=\"" + port.name() +
5215  "\" AND rf_ext_port_parameter_dependency.port="
5216  "rf_external_port.id AND rf_implementation_parameter.id="
5217  "rf_ext_port_parameter_dependency.parameter;"));
5218  while (result->hasNext()) {
5219  result->next();
5220  const DataObject& paramData = result->data(0);
5221  port.setParameterDependency(paramData.stringValue());
5222  }
5223  delete result;
5224  } catch (const Exception& e) {
5225  debugLog(e.errorMessage());
5226  assert(false);
5227  }
5228  }
5229 }
5230 
5231 
5232 /**
5233  * Adds parameters to the given FU implementation which is the implementation
5234  * of the FU entry that has the given ID.
5235  *
5236  * @param implementation The implementation.
5237  * @param entryID ID of the FU entry.
5238  */
5239 void
5242  RowID entryID) const {
5243 
5244  RelationalDBQueryResult* result = NULL;
5245  try {
5246  result = dbConnection_->query(
5248  } catch (const Exception&) {
5249  assert(false);
5250  }
5251 
5252  while (result->hasNext()) {
5253  result->next();
5254  const DataObject& nameData = result->data("name");
5255  const DataObject& typeData = result->data("type");
5256  const DataObject& valueData = result->data("value");
5257  string name = nameData.stringValue();
5258  string type = typeData.stringValue();
5259  string value = valueData.stringValue();
5260  implementation.addParameter(name, type, value);
5261  }
5262  delete result;
5263 }
5264 
5265 
5266 /**
5267  * Adds parameters to the given RF implementation which is the implementation
5268  * of the RF entry that has the given ID.
5269  *
5270  * @param implementation The implementation.
5271  * @param entryID ID of the RF entry.
5272  */
5273 void
5276  RowID entryID) const {
5277 
5278  if (!dbConnection_->tableExistsInDB("rf_implementation_parameter")) {
5279  // Add implicit parameters: size and width parameters if older
5280  // hdb is opened.
5281  if (implementation.widthParameter() != "") {
5282  implementation.addParameter(implementation.widthParameter(),
5283  "integer", "");
5284  }
5285  if (implementation.sizeParameter() != "") {
5286  implementation.addParameter(implementation.sizeParameter(),
5287  "integer", "");
5288  }
5289  return;
5290  }
5291 
5292  RelationalDBQueryResult* result = NULL;
5293  try {
5294  result = dbConnection_->query(
5296  } catch (const Exception&) {
5297  assert(false);
5298  }
5299 
5300  while (result->hasNext()) {
5301  result->next();
5302  const DataObject& nameData = result->data("name");
5303  const DataObject& typeData = result->data("type");
5304  const DataObject& valueData = result->data("value");
5305  string name = nameData.stringValue();
5306  string type = typeData.stringValue();
5307  string value = valueData.stringValue();
5308  implementation.addParameter(name, type, value);
5309  }
5310 
5311  // If RF implementation's size and width parameter dependencies do not have
5312  // parameter defined, add default parameters for them.
5313  if (implementation.widthParameter() != "" &&
5314  !implementation.hasParameter(implementation.widthParameter())) {
5315  implementation.addParameter(implementation.widthParameter(),
5316  "integer", "");
5317  implementation.addParameter(implementation.sizeParameter(),
5318  "integer", "");
5319  }
5320  if (implementation.sizeParameter() != "" &&
5321  !implementation.hasParameter(implementation.sizeParameter())) {
5322  implementation.addParameter(implementation.sizeParameter(),
5323  "integer", "");
5324  }
5325  delete result;
5326 }
5327 
5328 
5329 /**
5330  * Adds the block implementation files to the given FU implementation which
5331  * is the implementation of the FU entry that has the given ID.
5332  *
5333  * @param implementation The implementation.
5334  * @param entryID ID of the FU entry.
5335  */
5336 void
5339  RowID entryID) const {
5340 
5341  RelationalDBQueryResult* sourceFileData = NULL;
5342  try {
5343  sourceFileData = dbConnection_->query(
5344  fuSourceFilesByIDQuery(entryID));
5345  } catch (const Exception&) {
5346  assert(false);
5347  }
5348 
5349  int fileColumn = sourceFileData->column("block_source_file.file");
5350  int formatColumn = sourceFileData->column("format.format");
5351 
5352  while (sourceFileData->hasNext()) {
5353  sourceFileData->next();
5354  const DataObject& fileData = sourceFileData->data(fileColumn);
5355  const DataObject& formatData = sourceFileData->data(
5356  formatColumn);
5358  formatData.stringValue());
5360  fileData.stringValue(), format);
5361  implementation.addImplementationFile(file);
5362  }
5363 
5364  delete sourceFileData;
5365  sourceFileData = NULL;
5366 }
5367 
5368 
5369 /**
5370  * Adds data ports to the given RF implementation which is the implementation
5371  * of the RF entry that has the given ID.
5372  *
5373  * @param implementation The implementation.
5374  * @param entryID ID of the RF entry.
5375  */
5376 void
5379  RowID entryID) const {
5380 
5381  // obtain port data from HDB and add ports to RF implementation
5382  RelationalDBQueryResult* portData = NULL;
5383  try {
5384  portData = dbConnection_->query(
5386  } catch (const Exception& e) {
5387  debugLog(e.errorMessage());
5388  assert(false);
5389  }
5390 
5391  int portNameColumn = portData->column("name");
5392  int directionColumn = portData->column("direction");
5393  int loadPortColumn = portData->column("load_port");
5394  int opcodePortColumn = portData->column("opcode_port");
5395  int opcodePortFormulaColumn = portData->column(
5396  "opcode_port_width_formula");
5398  assert(directionColumn != RelationalDBQueryResult::UNKNOWN_INDEX);
5400  assert(opcodePortColumn != RelationalDBQueryResult::UNKNOWN_INDEX);
5401  assert(
5402  opcodePortFormulaColumn != RelationalDBQueryResult::UNKNOWN_INDEX);
5403 
5404  while (portData->hasNext()) {
5405  portData->next();
5406  const DataObject& portNameData = portData->data(portNameColumn);
5407  const DataObject& directionData = portData->data(
5408  directionColumn);
5409  const DataObject& loadPortData = portData->data(loadPortColumn);
5410  const DataObject& opcodePortData = portData->data(
5411  opcodePortColumn);
5412  const DataObject& opcodePortFormulaData = portData->data(
5413  opcodePortFormulaColumn);
5414  Direction direction;
5415  if (directionData.stringValue() == IN_DIRECTION) {
5416  direction = IN;
5417  } else if (directionData.stringValue() == OUT_DIRECTION) {
5418  direction = OUT;
5419  } else if (directionData.stringValue() == BIDIR_DIRECTION) {
5420  direction = BIDIR;
5421  } else {
5422  assert(false);
5423  }
5425  portNameData.stringValue(), direction,
5426  loadPortData.stringValue(), opcodePortData.stringValue(),
5427  opcodePortFormulaData.stringValue(), implementation);
5428  }
5429 
5430  delete portData;
5431  portData = NULL;
5432 }
5433 
5434 
5435 /**
5436  * Adds the block implementation files to the given RF implementation which
5437  * is the implementation of the RF entry that has the given ID.
5438  *
5439  * @param implementation The implementation.
5440  * @param entryID ID of the RF entry.
5441  */
5442 void
5445  RowID entryID) const {
5446 
5447  RelationalDBQueryResult* result = NULL;
5448  try {
5449  result = dbConnection_->query(rfSourceFilesByIDQuery(entryID));
5450  } catch (const Exception&) {
5451  assert(false);
5452  }
5453 
5454  int fileColumn = result->column("block_source_file.file");
5455  int formatColumn = result->column("format.format");
5456 
5457  while (result->hasNext()) {
5458  result->next();
5459  const DataObject& fileData = result->data(fileColumn);
5460  const DataObject& formatData = result->data(formatColumn);
5462  formatData.stringValue());
5464  fileData.stringValue(), format);
5465  implementation.addImplementationFile(file);
5466  }
5467 
5468  delete result;
5469  result = NULL;
5470 }
5471 
5472 
5473 /**
5474  * Removes the cost estimation data that has the given ID.
5475  *
5476  * @param id ID of the cost estimation data.
5477  */
5478 void
5480  try {
5482  std::string(
5483  "DELETE FROM cost_estimation_data "
5484  "WHERE id=" + Conversion::toString(id) + ";"));
5485  } catch (const Exception& e) {
5486  debugLog(e.errorMessage());
5487  assert(false);
5488  }
5489 }
5490 
5491 
5492 /**
5493  * Adds the given block implementation file to the HDB.
5494  *
5495  * @param file The file to add.
5496  */
5497 void
5499  const BlockImplementationFile& file) const {
5500  if (!containsImplementationFile(file.pathToFile())) {
5502  std::string(
5503  "INSERT INTO block_source_file(id,file,format) "
5504  "VALUES(NULL,\"" + file.pathToFile() +
5505  "\",(SELECT id FROM format WHERE format=\"" +
5506  formatString(file.format()) + "\"));"));
5507  }
5508 }
5509 
5510 /**
5511  * Checks whether the given FU has a mathing architecture with the given FU
5512  * architecture instance.
5513  *
5514  * @param fu The function unit.
5515  * @param arch The FU architecture.
5516  * @return True if the architectures match, otherwise false.
5517  */
5518 bool
5520  const TTAMachine::FunctionUnit& fu,
5521  const FUArchitecture& arch) {
5522 
5523  if (fu.operationCount() != arch.architecture().operationCount()) {
5524  return false;
5525  }
5526 
5527  std::map<const FUPort*, const FUPort*> portMap;
5528  for (int i = 0; i < fu.operationPortCount(); i++) {
5529  portMap.insert(
5530  std::pair<const FUPort*, const FUPort*>(
5531  fu.operationPort(i), NULL));
5532  }
5533 
5534  PipelineElementUsageTable plineElementUsages;
5535 
5536  for (int i = 0; i < fu.operationCount(); i++) {
5537  HWOperation* operation = fu.operation(i);
5538  if (!arch.architecture().hasOperation(operation->name())) {
5539  return false;
5540  }
5541  HWOperation* archOp = arch.architecture().operation(
5542  operation->name());
5543  if (operation->latency() != archOp->latency()) {
5544  return false;
5545  }
5546 
5547  // check operand bindings
5548  for (int i = 0; i < fu.operationPortCount(); i++) {
5549  FUPort* port = fu.operationPort(i);
5550  if (operation->isBound(*port)) {
5551  int io = operation->io(*port);
5552  FUPort* samePort = archOp->port(io);
5553  if (samePort == NULL) {
5554  return false;
5555  }
5556  const FUPort* existingSamePort =
5557  MapTools::valueForKey<const FUPort*>(portMap, port);
5558  if (existingSamePort != NULL &&
5559  existingSamePort != samePort) {
5560  return false;
5561  }
5562 
5563  // check the width of the ports
5564  if (!arch.hasParameterizedWidth(samePort->name()) &&
5565  samePort->width() != port->width()) {
5566  return false;
5567  }
5568 
5569  if (port->isOpcodeSetting() != samePort->isOpcodeSetting() ||
5570  port->isTriggering() != samePort->isTriggering()) {
5571  return false;
5572  }
5573  portMap.erase(port);
5574  portMap.insert(
5575  std::pair<const FUPort*, const FUPort*>(port, samePort));
5576  }
5577  }
5578 
5579  // check operation pipeline
5580  ExecutionPipeline* opPipeline = operation->pipeline();
5581  ExecutionPipeline* archOpPipeline = archOp->pipeline();
5582  for (int cycle = 0; cycle < operation->latency(); cycle++) {
5583  ExecutionPipeline::OperandSet written1 =
5584  opPipeline->writtenOperands(cycle);
5585  ExecutionPipeline::OperandSet written2 =
5586  archOpPipeline->writtenOperands(cycle);
5587  if (written1 != written2) {
5588  return false;
5589  }
5591  opPipeline->readOperands(cycle);
5593  archOpPipeline->readOperands(cycle);
5594  if (read1 != read2) {
5595  return false;
5596  }
5597 
5598  PipelineElementUsage usage;
5599  for (int i = 0; i < fu.pipelineElementCount(); i++) {
5600  const PipelineElement* elem = fu.pipelineElement(i);
5601  if (opPipeline->isResourceUsed(elem->name(),cycle)) {
5602  usage.usage1.insert(elem);
5603  }
5604  }
5605 
5606  for (int i = 0; i < arch.architecture().pipelineElementCount();
5607  i++) {
5608  const PipelineElement* elem =
5609  arch.architecture().pipelineElement(i);
5610  if (archOpPipeline->isResourceUsed(elem->name(), cycle)) {
5611  usage.usage2.insert(elem);
5612  }
5613  }
5614 
5615  plineElementUsages.push_back(usage);
5616  }
5617  }
5618 
5619  return areCompatiblePipelines(plineElementUsages);
5620 }
5621 
5622 
5623 /**
5624  * Checks whether the pipeline element usages of the given table are
5625  * compatible.
5626  *
5627  * They are compatible if the first pipeline is more restrictive or
5628  * equal to the second pipeline.
5629  *
5630  * @param table The table that describes the pipeline usages.
5631  * @return True if the pipelines are compatible, otherwise false.
5632  */
5633 bool
5635 
5636  for (size_t i = 0; i < table.size(); i++) {
5637  std::set<const PipelineElement*> usedResources1 = table[i].usage1;
5638  // create a set of vector indices which mean what stages cannot be
5639  // executed at the same time
5640  std::set<size_t> illegalStages1;
5641  for (size_t usageIndex = 0; usageIndex < table.size();
5642  usageIndex++) {
5643  if (usageIndex == i) {
5644  continue;
5645  }
5646  std::set<const PipelineElement*> resources =
5647  table[usageIndex].usage1;
5648  std::set<const PipelineElement*> intersect;
5649  SetTools::intersection(usedResources1, resources, intersect);
5650  if (!intersect.empty()) {
5651  illegalStages1.insert(usageIndex);
5652  }
5653  }
5654 
5655  // create a similar vector of the other pipeline
5656  std::set<const PipelineElement*> usedResources2 = table[i].usage2;
5657  std::set<size_t> illegalStages2;
5658  for (size_t usageIndex = 0; usageIndex < table.size();
5659  usageIndex++) {
5660  if (usageIndex == i) {
5661  continue;
5662  }
5663  std::set<const PipelineElement*> resources =
5664  table[usageIndex].usage2;
5665  std::set<const PipelineElement*> intersect;
5666  SetTools::intersection(usedResources2, resources, intersect);
5667  if (!intersect.empty()) {
5668  illegalStages2.insert(usageIndex);
5669  }
5670  }
5671 
5672  std::set<size_t> difference;
5673  AssocTools::difference(illegalStages2, illegalStages1, difference);
5674  if (!difference.empty()) {
5675  return false;
5676  }
5677  }
5678 
5679  return true;
5680 }
5681 
5682 
5683 /**
5684  * Inserts the supported formats to the format table.
5685  *
5686  * @param connection The connection used when inserting the formats.
5687  */
5688 void
5690  try {
5691  connection.updateQuery(
5692  std::string(
5693  "INSERT INTO format(id,format) VALUES(1,\"" +
5694  VHDL_FORMAT + "\");"));
5695  connection.updateQuery(
5696  std::string(
5697  "INSERT INTO format(id,format) VALUES(2,\"" +
5698  VERILOG_FORMAT + "\");"));
5699  } catch (const Exception& e) {
5700  debugLog(e.errorMessage());
5701  assert(false);
5702  }
5703 }
5704 
5705 
5706 /**
5707  * Returns the format corresponding to the given string which is stored in
5708  * the database.
5709  *
5710  * @param formatString The format string stored in the database.
5711  * @return The format.
5712  */
5714 HDBManager::fileFormat(const std::string& formatString) {
5715  if (formatString == VHDL_FORMAT) {
5717  } else if (formatString == VERILOG_FORMAT) {
5719  } else if (formatString == VHDL_SIM_FORMAT) {
5721  } else if (formatString == VERILOG_SIM_FORMAT) {
5723  }
5724  assert(false);
5725  // dummy return to avoid whining with some compilers
5727 }
5728 
5729 
5730 /**
5731  * Returns the string used to represent the given file format in HDB.
5732  *
5733  * @param format The format.
5734  * @return The string.
5735  */
5736 std::string
5738  if (format == BlockImplementationFile::VHDL) {
5739  return VHDL_FORMAT;
5740  } else if (format == BlockImplementationFile::Verilog) {
5741  return VERILOG_FORMAT;
5742  } else if (format == BlockImplementationFile::VHDLsim) {
5743  return VHDL_SIM_FORMAT;
5744  } else if (format == BlockImplementationFile::Verilogsim) {
5745  return VERILOG_SIM_FORMAT;
5746  }
5747 
5748  // dummy return to avoid compiler whining
5749  assert(false);
5750  return "";
5751 }
5752 
5753 
5754 /**
5755  * Returns the string used to represent the given direction in HDB.
5756  *
5757  * @param direction The direction.
5758  * @return The string.
5759  */
5760 std::string
5762  if (direction == HDB::IN) {
5763  return IN_DIRECTION;
5764  } else if (direction == HDB::OUT) {
5765  return OUT_DIRECTION;
5766  } else {
5767  return BIDIR_DIRECTION;
5768  }
5769 }
5770 
5771 
5772 /**
5773  * Creates an SQL query for getting the FU entry that has the given ID.
5774  *
5775  * The result set has fields {id, architecture, cost_function}.
5776  *
5777  * @param id ID of the entry.
5778  * @return The SQL query.
5779  */
5780 std::string
5782  string idString = Conversion::toString(id);
5783  string query =
5784  "SELECT * "
5785  "FROM fu "
5786  "WHERE fu.id=" + idString + ";";
5787  return query;
5788 }
5789 
5790 
5791 /**
5792  * Creates an SQL query for getting the RF entry that has the given ID.
5793  *
5794  * The result set has fields {id, architecture, cost_function}.
5795  *
5796  * @param id ID of the entry.
5797  * @return The SQL query.
5798  */
5799 std::string
5801  string idString = Conversion::toString(id);
5802  string query =
5803  "SELECT * "
5804  "FROM rf "
5805  "WHERE rf.id=" + idString + ";";
5806  return query;
5807 }
5808 
5809 
5810 /**
5811  * Creates an SQL query for getting the Bus entry that has the given ID.
5812  *
5813  * The result set has fields {id}.
5814  *
5815  * @param id ID of the entry.
5816  * @return The SQL query.
5817  */
5818 std::string
5820  string idString = Conversion::toString(id);
5821  string query =
5822  "SELECT * "
5823  "FROM bus "
5824  "WHERE bus.id=" + idString + ";";
5825  return query;
5826 }
5827 
5828 
5829 /**
5830  * Creates an SQL query for getting the Socket entry that has the given ID.
5831  *
5832  * The result set has fields {id}.
5833  *
5834  * @param id ID of the entry.
5835  * @return The SQL query.
5836  */
5837 std::string
5839  string idString = Conversion::toString(id);
5840  string query =
5841  "SELECT * "
5842  "FROM socket "
5843  "WHERE socket.id=" + idString + ";";
5844  return query;
5845 }
5846 
5847 
5848 /**
5849  * Creates an SQL query for getting the architecture of the FU entry that
5850  * has the given ID.
5851  *
5852  * The result set has all the fields of fu_architecture.
5853  *
5854  * @param id ID of the FU entry.
5855  */
5856 std::string
5858  string idString = Conversion::toString(id);
5859  string query =
5860  "SELECT * "
5861  "FROM fu, fu_architecture "
5862  "WHERE fu.id=" + idString + " AND"
5863  " fu_architecture.id = fu.architecture;";
5864  return query;
5865 }
5866 
5867 
5868 /**
5869  * Creates an SQL query for getting the architectural ports and their
5870  * operand bindings of the FU architecture that has the given ID.
5871  *
5872  * The result table has fields {fu_data_port.id, fu_data_port.triggers,
5873  * fu_data_port.sets-opcode, fu_data_port.guard_support,
5874  * fu_data_port.width, operation.name,
5875  * io_binding.io_number}
5876  *
5877  * @param id The ID of the FU architecture.
5878  */
5879 std::string
5881  string idString = Conversion::toString(id);
5882  string query =
5883  "SELECT fu_data_port.id AS 'fu_data_port.id',"
5884  " fu_data_port.triggers AS 'fu_data_port.triggers',"
5885  " fu_data_port.sets_opcode AS 'fu_data_port.sets_opcode',"
5886  " fu_data_port.guard_support AS 'fu_data_port.guard_support',"
5887  " fu_data_port.width AS 'fu_data_port.width',"
5888  " operation.name AS 'operation.name',"
5889  " io_binding.io_number AS 'io_binding.io_number' "
5890  "FROM fu_data_port, io_binding, operation "
5891  "WHERE fu_data_port.fu_arch=" + idString + " AND"
5892  " io_binding.port=fu_data_port.id AND"
5893  " io_binding.operation=operation.id;";
5894  return query;
5895 }
5896 
5897 
5898 /**
5899  * Creates an SQL query for getting the IO usage data of pipelines of
5900  * operations contained in the FU architecture that has the given ID.
5901  *
5902  * The result table has fields {operation.name, io_usage.cycle,
5903  * io_usage.io_number, io_usage.action}.
5904  *
5905  * @param id ID of the FU architecture in HDB.
5906  */
5907 std::string
5909  string idString = Conversion::toString(id);
5910  string query =
5911  "SELECT operation.name AS 'operation.name',"
5912  " io_usage.cycle AS 'io_usage.cycle',"
5913  " io_usage.io_number AS 'io_usage.io_number',"
5914  " io_usage.action AS 'io_usage.action' "
5915  "FROM operation_pipeline, io_usage, operation "
5916  "WHERE operation_pipeline.fu_arch=" + idString + " AND"
5917  " io_usage.pipeline=operation_pipeline.id AND"
5918  " operation.id=operation_pipeline.operation;";
5919  return query;
5920 }
5921 
5922 
5923 /**
5924  * Creates an SQL query for getting resource usage data of pipelines
5925  * of the FU architecture that has the given ID.
5926  *
5927  * The result table has fields {operation.name,
5928  * pipeline_resource_usage.cycle, pipeline_resource.id}
5929  *
5930  * @param id ID of the FU architecture in HDB.
5931  */
5932 std::string
5934  string idString = Conversion::toString(id);
5935  string query =
5936  "SELECT operation.name AS 'operation.name',"
5937  " pipeline_resource_usage.cycle AS "
5938  " 'pipeline_resource_usage.cycle',"
5939  " pipeline_resource.id AS 'pipeline_resource.id' "
5940  "FROM pipeline_resource_usage, pipeline_resource, operation,"
5941  " operation_pipeline "
5942  "WHERE operation_pipeline.fu_arch=" + idString + " AND"
5943  " pipeline_resource_usage.pipeline=operation_pipeline.id AND"
5944  " pipeline_resource.id = pipeline_resource_usage.resource AND"
5945  " operation.id=operation_pipeline.operation;";
5946  return query;
5947 }
5948 
5949 
5950 /**
5951  * Creates an SQL query for getting FU implementation data of the FU that has
5952  * the given ID.
5953  *
5954  * The result table has fields {fu_implementation.id, fu_implementation.name,
5955  * fu_implementation.opcode_port, fu_implementation.clk_port,
5956  * fu_implementation.rst_port, fu_implementation.glock_port,
5957  * fu_implementation.glock_req_port}.
5958  *
5959  * @param id ID of the FU entry in HDB.
5960  */
5961 std::string
5963  string idString = Conversion::toString(id);
5964  string query =
5965  "SELECT fu_implementation.id AS 'fu_implementation.id',"
5966  " fu_implementation.name AS 'fu_implementation.name',"
5967  " fu_implementation.opcode_port AS "
5968  "'fu_implementation.opcode_port',"
5969  " fu_implementation.clk_port AS 'fu_implementation.clk_port',"
5970  " fu_implementation.rst_port AS 'fu_implementation.rst_port',"
5971  " fu_implementation.glock_port AS "
5972  " 'fu_implementation.glock_port',"
5973  " fu_implementation.glock_req_port AS "
5974  " 'fu_implementation.glock_req_port' "
5975  "FROM fu, fu_implementation "
5976  "WHERE fu.id=" + idString + " AND"
5977  " fu_implementation.fu=fu.id;";
5978  return query;
5979 }
5980 
5981 
5982 /**
5983  * Creates an SQL query for getting operation code data of the FU that has the
5984  * given ID.
5985  *
5986  * The result table has fields {operation.name, opcode_map.opcode}.
5987  *
5988  * @param id ID of the FU entry in HDB.
5989  */
5990 std::string
5992  string idString = Conversion::toString(id);
5993  string query =
5994  "SELECT operation.name AS 'operation.name',"
5995  " opcode_map.opcode AS 'opcode_map.opcode' "
5996  "FROM fu, fu_implementation, operation, opcode_map "
5997  "WHERE fu.id=" + idString + " AND"
5998  " fu_implementation.fu=fu.id AND"
5999  " opcode_map.fu_impl=fu_implementation.id AND"
6000  " operation.id=opcode_map.operation;";
6001  return query;
6002 }
6003 
6004 
6005 /**
6006  * Creates an SQL qury for getting data port data of implementation of
6007  * the FU that has the given ID.
6008  *
6009  * The result table has fields {fu_port_map.name,
6010  * fu_port_map.width_formula, fu_port_map.load_port,
6011  * fu_port_map.guard_port}
6012  *
6013  * @param id ID of the FU entry in HDB.
6014  */
6015 std::string
6017  string idString = Conversion::toString(id);
6018  string query =
6019  "SELECT fu_port_map.name AS 'fu_port_map.name',"
6020  " fu_port_map.width_formula AS 'fu_port_map.width_formula',"
6021  " fu_port_map.load_port AS 'fu_port_map.load_port',"
6022  " fu_port_map.guard_port AS 'fu_port_map.guard_port' "
6023  "FROM fu, fu_port_map, fu_implementation "
6024  "WHERE fu.id=" + idString + " AND"
6025  " fu_implementation.fu=fu.id AND"
6026  " fu_port_map.fu_impl=fu_implementation.id;";
6027  return query;
6028 }
6029 
6030 
6031 /**
6032  * Creates an SQL query for getting external port data of implementation of
6033  * the FU that has the given ID.
6034  *
6035  * The result table has fields {fu_external_port.name,
6036  * fu_external_port.direction, fu_external_port.width_formula,
6037  * fu_external_port.description}.
6038  *
6039  * @param id ID of the FU entry in HDB.
6040  * @return The SQL query.
6041  */
6042 std::string
6044  string idString = Conversion::toString(id);
6045  string query =
6046  "SELECT fu_external_port.name AS 'fu_external_port.name',"
6047  " fu_external_port.direction AS 'fu_external_port.direction',"
6048  " fu_external_port.width_formula AS "
6049  " 'fu_external_port.width_formula',"
6050  " fu_external_port.description AS "
6051  " 'fu_external_port.description' "
6052  "FROM fu, fu_implementation, fu_external_port "
6053  "WHERE fu.id=" + idString + " AND"
6054  " fu_implementation.fu=fu.id AND"
6055  " fu_external_port.fu_impl=fu_implementation.id;";
6056  return query;
6057 }
6058 
6059 
6060 /**
6061  * Creates an SQL query for getting external port data of implementation of
6062  * the RF that has the given ID.
6063  *
6064  * The result table has fields {rf_external_port.name,
6065  * rf_external_port.direction, rf_external_port.width_formula,
6066  * rf_external_port.description}.
6067  *
6068  * @param id ID of the RF entry in HDB.
6069  * @return The SQL query.
6070  */
6071 std::string
6073  string idString = Conversion::toString(id);
6074  string query =
6075  "SELECT rf_external_port.name AS 'rf_external_port.name',"
6076  " rf_external_port.direction AS 'rf_external_port.direction',"
6077  " rf_external_port.width_formula AS "
6078  " 'rf_external_port.width_formula',"
6079  " rf_external_port.description AS "
6080  " 'rf_external_port.description' "
6081  "FROM rf, rf_implementation, rf_external_port "
6082  "WHERE rf.id=" + idString + " AND"
6083  " rf_implementation.rf=rf.id AND"
6084  " rf_external_port.rf_impl=rf_implementation.id;";
6085  return query;
6086 }
6087 
6088 
6089 /**
6090  * Creates an SQL query for getting the parameters of the implementation
6091  * of the FU that has the given ID.
6092  *
6093  * The result table has fields {name, type, value}.
6094  *
6095  * @param id ID of the FU implementation entry.
6096  * @return The SQL query.
6097  */
6098 std::string
6100  string idString = Conversion::toString(id);
6101  string query =
6102  "SELECT fu_implementation_parameter.name AS 'name',"
6103  " fu_implementation_parameter.type AS 'type',"
6104  " fu_implementation_parameter.value AS 'value' "
6105  "FROM fu_implementation, fu_implementation_parameter "
6106  "WHERE fu_implementation.fu=" + idString + " AND"
6107  " fu_implementation_parameter.fu_impl=fu_implementation.id;";
6108  return query;
6109 }
6110 
6111 
6112 /**
6113  * Creates an SQL query for getting the parameters of the implementation
6114  * of the RF that has the given ID.
6115  *
6116  * The result table has fields {name, type, value}.
6117  *
6118  * @param id ID of the RF entry.
6119  * @return The SQL query.
6120  */
6121 std::string
6123  string idString = Conversion::toString(id);
6124  string query =
6125  "SELECT rf_implementation_parameter.name AS 'name',"
6126  " rf_implementation_parameter.type AS 'type',"
6127  " rf_implementation_parameter.value AS 'value' "
6128  "FROM rf_implementation, rf_implementation_parameter "
6129  "WHERE rf_implementation.rf=" + idString + " AND"
6130  " rf_implementation_parameter.rf_impl=rf_implementation.id;";
6131  return query;
6132 }
6133 
6134 
6135 /**
6136  * Creates an SQL query for getting io binding data of port that has
6137  * the given name.
6138  *
6139  * The result table has fields {operation.name, io_binding.io_number}.
6140  *
6141  * @param fuID ID of the FU entry.
6142  * @param portName Name of the implemented port.
6143  * @return The SQL query.
6144  */
6145 std::string
6147  RowID fuID,
6148  const std::string& portName) {
6149 
6150  string idString = Conversion::toString(fuID);
6151  string query =
6152  "SELECT operation.name AS 'operation.name',"
6153  " io_binding.io_number AS 'io_binding.io_number' "
6154  "FROM operation, io_binding, fu_port_map, fu_implementation "
6155  "WHERE fu_implementation.fu=" + idString + " AND"
6156  " fu_port_map.fu_impl=fu_implementation.id AND"
6157  " fu_port_map.name='" + portName + "' AND"
6158  " io_binding.port=fu_port_map.arch_port AND"
6159  " operation.id=io_binding.operation;";
6160  return query;
6161 }
6162 
6163 
6164 /**
6165  * Creates an SQL query for getting the block source files of the FU
6166  * entry that has the given ID.
6167  *
6168  * The result table has fields {block_source_file.file, format.format}.
6169  *
6170  * @param id ID of the FU entry.
6171  * @return The SQL query.
6172  */
6173 std::string
6175  string idString = Conversion::toString(id);
6176  string query =
6177  "SELECT block_source_file.file AS 'block_source_file.file',"
6178  " format.format AS 'format.format' "
6179  "FROM block_source_file, fu_source_file, fu_implementation, format "
6180  "WHERE fu_implementation.fu=" + idString + " AND"
6181  " fu_source_file.fu_impl=fu_implementation.id AND"
6182  " block_source_file.id=fu_source_file.file AND"
6183  " format.id=block_source_file.format;";
6184  return query;
6185 }
6186 
6187 
6188 /**
6189  * Creates an SQL query for getting the architecture data of the RF
6190  * architecture that has the given ID.
6191  *
6192  * The result table has all the fields of rf_architecture table.
6193  *
6194  * @param id ID of the RF architecture.
6195  * @return The SQL query.
6196  */
6197 std::string
6199  string idString = Conversion::toString(id);
6200  string query =
6201  "SELECT * "
6202  "FROM rf_architecture "
6203  "WHERE id=" + idString + ";";
6204  return query;
6205 }
6206 
6207 
6208 /**
6209  * Creates an SQL query for getting the implementation of the RF entry that
6210  * has the given ID.
6211  *
6212  * The result table has fields {id, name, size_param, width_param,
6213  * clk_port, rst_port, glock_port, guard_port}.
6214  *
6215  * @param id The ID of the RF entry.
6216  * @return The SQL query.
6217  */
6218 std::string
6220  string idString = Conversion::toString(id);
6221  string query =
6222  "SELECT id,"
6223  " name,"
6224  " size_param,"
6225  " width_param,"
6226  " clk_port,"
6227  " rst_port,"
6228  " glock_port,"
6229  " guard_port "
6230  "FROM rf_implementation "
6231  "WHERE rf_implementation.rf=" + idString + ";";
6232  return query;
6233 }
6234 
6235 /**
6236  * Same as rfImplementationByIDQuery() bus has additional field for separate
6237  * address cycle.
6238  *
6239  * The result table has fields {id, name, size_param, width_param,
6240  * clk_port, rst_port, glock_port, guard_port, sac_param}.
6241  *
6242  * @param id The ID of the RF entry.
6243  * @return The SQL query.
6244  */
6245 std::string
6247  string idString = Conversion::toString(id);
6248  string query =
6249  "SELECT id,"
6250  " name,"
6251  " size_param,"
6252  " width_param,"
6253  " clk_port,"
6254  " rst_port,"
6255  " glock_port,"
6256  " guard_port, "
6257  " sac_param "
6258  "FROM rf_implementation "
6259  "WHERE rf_implementation.rf=" + idString + ";";
6260  return query;
6261 }
6262 
6263 /**
6264  * Creates an SQL query for getting the data ports of the implementation of
6265  * the RF entry that has the given ID.
6266  *
6267  * The result table has fields {name, direction, load_port, opcode_port,
6268  * opcode_port_width_formula}.
6269  *
6270  * @param id ID of the RF entry.
6271  * @return The SQL query.
6272  */
6273 std::string
6275  string idString = Conversion::toString(id);
6276  string query =
6277  "SELECT rf_data_port.name AS 'name',"
6278  " rf_data_port.direction AS 'direction',"
6279  " rf_data_port.load_port AS 'load_port',"
6280  " rf_data_port.opcode_port AS 'opcode_port',"
6281  " rf_data_port.opcode_port_width_formula AS "
6282  " 'opcode_port_width_formula' "
6283  "FROM rf_data_port, rf_implementation "
6284  "WHERE rf_implementation.rf=" + idString + " AND"
6285  " rf_data_port.rf_impl=rf_implementation.id;";
6286  return query;
6287 }
6288 
6289 
6290 /**
6291  * Creates an SQL query for getting the block implementation files of the
6292  * RF entry that has the given ID.
6293  *
6294  * The result table has fields {block_source_file.file, format.format}.
6295  *
6296  * @param id ID of the RF entry.
6297  * @return The SQL query.
6298  */
6299 std::string
6301  string idString = Conversion::toString(id);
6302  string query =
6303  "SELECT block_source_file.file AS 'block_source_file.file',"
6304  " format.format AS 'format.format' "
6305  "FROM block_source_file, format, rf_implementation, rf_source_file "
6306  "WHERE rf_implementation.rf=" + idString + " AND"
6307  " rf_source_file.rf_impl=rf_implementation.id AND"
6308  " block_source_file.id=rf_source_file.file AND"
6309  " format.id=block_source_file.format;";
6310  return query;
6311 }
6312 
6313 
6314 /**
6315  * Returns cost estimation data with the given id.
6316  *
6317  * @param entryId Id of the cost estimation data entry.
6318  * @return The data.
6319  * @exception KeyNotFound If the HDB does not contain cost estimation
6320  * data with the given arguments.
6321  */
6324  // make the SQL query to obtain implementation data
6325  RelationalDBQueryResult* queryResult = NULL;
6326  try {
6327  std::string theQuery =
6328  std::string(
6329  "SELECT value, cost_estimation_data.name AS data_name, "
6330  " cost_function_plugin.id AS plugin_id, "
6331  " fu_reference, rf_reference, bus_reference, "
6332  " socket_reference "
6333  "FROM cost_estimation_data, cost_function_plugin "
6334  "WHERE cost_estimation_data.plugin_reference="
6335  " cost_function_plugin.id AND "
6336  " cost_estimation_data.id = ") +
6337  Conversion::toString(entryId);
6338 
6339  queryResult = dbConnection_->query(theQuery);
6340 
6341  } catch (const Exception& e) {
6342  // should not throw in any case
6343  debugLog(e.errorMessage());
6344  assert(false);
6345  }
6346 
6347  if (queryResult->hasNext()) {
6348  queryResult->next();
6349 
6350  std::string name = queryResult->data("data_name").stringValue();
6351 
6352  CostEstimationData data;
6353  data.setName(name);
6354  data.setValue(queryResult->data("value"));
6355  data.setPluginID(queryResult->data("plugin_id").integerValue());
6356 
6357  if (!queryResult->data("fu_reference").isNull()) {
6358  data.setFUReference(queryResult->data("fu_reference").integerValue());
6359  }
6360  if (!queryResult->data("rf_reference").isNull()) {
6361  data.setRFReference(queryResult->data("rf_reference").integerValue());
6362  }
6363  if (!queryResult->data("bus_reference").isNull()) {
6364  data.setBusReference(queryResult->data("bus_reference").integerValue());
6365  }
6366  if (!queryResult->data("socket_reference").isNull()) {
6367  data.setSocketReference(
6368  queryResult->data("socket_reference").integerValue());
6369  }
6370 
6371  delete queryResult;
6372  queryResult = NULL;
6373 
6374  return data;
6375  } else {
6376  delete queryResult;
6377  throw KeyNotFound(__FILE__, __LINE__, __func__);
6378  }
6379  // silence compiler warning
6380  throw 1;
6381 }
6382 
6383 /**
6384  * Returns a set of cost estimation data IDs which reference the give FU
6385  * implementation.
6386  *
6387  * @param fuImplID ID of the FU implementation.
6388  * @return Set of cost estimation data IDs.
6389  */
6390 std::set<RowID>
6392 
6393  // make the SQL query to obtain IDs.
6394  RelationalDBQueryResult* queryResult = NULL;
6395  try {
6396  std::string theQuery =
6397  std::string(
6398  "SELECT id "
6399  "FROM cost_estimation_data "
6400  "WHERE fu_reference = ") +
6401  Conversion::toString(fuImplID);
6402 
6403  queryResult = dbConnection_->query(theQuery);
6404 
6405  } catch (const Exception& e) {
6406  // should not throw in any case
6407  debugLog(e.errorMessage());
6408  assert(false);
6409  }
6410 
6411  std::set<RowID> ids;
6412 
6413  while (queryResult->hasNext()) {
6414  queryResult->next();
6415 
6416  ids.insert(queryResult->data("id").integerValue());
6417  }
6418 
6419  delete queryResult;
6420  queryResult = NULL;
6421  return ids;
6422 }
6423 
6424 /**
6425  * Returns a set of cost estimation data IDs which reference the give RF
6426  * implementation.
6427  *
6428  * @param rfImplID ID of the RF implementation.
6429  * @return Set of cost estimation data IDs.
6430  */
6431 std::set<RowID>
6433 
6434  // make the SQL query to obtain IDs.
6435  RelationalDBQueryResult* queryResult = NULL;
6436  try {
6437  std::string theQuery =
6438  std::string(
6439  "SELECT id "
6440  "FROM cost_estimation_data "
6441  "WHERE rf_reference = ") +
6442  Conversion::toString(rfImplID);
6443 
6444  queryResult = dbConnection_->query(theQuery);
6445 
6446  } catch (const Exception& e) {
6447  // should not throw in any case
6448  debugLog(e.errorMessage());
6449  assert(false);
6450  }
6451 
6452  std::set<RowID> ids;
6453 
6454  while (queryResult->hasNext()) {
6455  queryResult->next();
6456 
6457  ids.insert(queryResult->data("id").integerValue());
6458  }
6459 
6460  delete queryResult;
6461  queryResult = NULL;
6462  return ids;
6463 }
6464 
6465 /**
6466  * Returns a set of cost estimation data IDs which reference the given
6467  * socket entry.
6468  *
6469  * @param socketID ID of the socket entry.
6470  * @return Set of cost estimation data IDs.
6471  */
6472 std::set<RowID>
6474 
6475  // make the SQL query to obtain IDs.
6476  RelationalDBQueryResult* queryResult = NULL;
6477  try {
6478  std::string theQuery =
6479  std::string(
6480  "SELECT id "
6481  "FROM cost_estimation_data "
6482  "WHERE socket_reference = ") +
6483  Conversion::toString(socketID);
6484 
6485  queryResult = dbConnection_->query(theQuery);
6486 
6487  } catch (const Exception& e) {
6488  // should not throw in any case
6489  debugLog(e.errorMessage());
6490  assert(false);
6491  }
6492 
6493  std::set<RowID> ids;
6494 
6495  while (queryResult->hasNext()) {
6496  queryResult->next();
6497 
6498  ids.insert(queryResult->data("id").integerValue());
6499  }
6500 
6501  delete queryResult;
6502  queryResult = NULL;
6503  return ids;
6504 }
6505 
6506 /**
6507  * Returns a set of cost estimation data IDs which reference the given
6508  * bus entry.
6509  *
6510  * @param busID ID of the bus entry.
6511  * @return Set of cost estimation data IDs.
6512  */
6513 std::set<RowID>
6515 
6516  // make the SQL query to obtain IDs.
6517  RelationalDBQueryResult* queryResult = NULL;
6518  try {
6519  std::string theQuery =
6520  std::string(
6521  "SELECT id "
6522  "FROM cost_estimation_data "
6523  "WHERE bus_reference = ") +
6524  Conversion::toString(busID);
6525 
6526  queryResult = dbConnection_->query(theQuery);
6527 
6528  } catch (const Exception& e) {
6529  // should not throw in any case
6530  debugLog(e.errorMessage());
6531  assert(false);
6532  }
6533 
6534  std::set<RowID> ids;
6535 
6536  while (queryResult->hasNext()) {
6537  queryResult->next();
6538 
6539  ids.insert(queryResult->data("id").integerValue());
6540  }
6541 
6542  delete queryResult;
6543  queryResult = NULL;
6544  return ids;
6545 }
6546 
6547 /**
6548  * Returns RowIDs of cost fucntion plugins in the HDB.
6549  *
6550  * @return All cost function plugin IDs.
6551  */
6552 std::set<RowID>
6554 
6555  // make the SQL query to obtain IDs.
6556  RelationalDBQueryResult* queryResult = NULL;
6557  try {
6558  std::string theQuery =
6559  "SELECT id FROM cost_function_plugin";
6560 
6561  queryResult = dbConnection_->query(theQuery);
6562 
6563  } catch (const Exception& e) {
6564  // should not throw in any case
6565  debugLog(e.errorMessage());
6566  assert(false);
6567  }
6568 
6569  std::set<RowID> ids;
6570 
6571  while (queryResult->hasNext()) {
6572  queryResult->next();
6573 
6574  ids.insert(queryResult->data("id").integerValue());
6575  }
6576 
6577  delete queryResult;
6578  queryResult = NULL;
6579  return ids;
6580 }
6581 
6582 /**
6583  * Returns cost estimation data IDs related to the given cost function plugin.
6584  *
6585  * @param pluginID ID of the cost function plugin.
6586  * @return IDs of the cost function plugin estimation data.
6587  */
6588 std::set<RowID>
6590 
6591  // make the SQL query to obtain IDs.
6592  RelationalDBQueryResult* queryResult = NULL;
6593  try {
6594  std::string theQuery =
6595  std::string(
6596  "SELECT id "
6597  "FROM cost_estimation_data "
6598  "WHERE plugin_reference = ") +
6599  Conversion::toString(pluginID);
6600 
6601  queryResult = dbConnection_->query(theQuery);
6602 
6603  } catch (const Exception& e) {
6604  // should not throw in any case
6605  debugLog(e.errorMessage());
6606  assert(false);
6607  }
6608 
6609  std::set<RowID> ids;
6610 
6611  while (queryResult->hasNext()) {
6612  queryResult->next();
6613 
6614  ids.insert(queryResult->data("id").integerValue());
6615  }
6616 
6617  delete queryResult;
6618  queryResult = NULL;
6619  return ids;
6620 }
6621 
6622 /**
6623  * Returns cost function plugin with the given ID.
6624  *
6625  * @param pluginID ID of the cost function plugin.
6626  * @return Cost function plugin with the given ID.
6627  * @exception Exception Throws if pluginID not found (KeyNotFound) or
6628  * illegal cost_function_plugin row found.
6629  */
6632  RelationalDBQueryResult* pluginData;
6633 
6634  std::string pluginDataQuery =
6635  "SELECT id, description, name, plugin_file_path, type "
6636  " FROM cost_function_plugin WHERE id = ";
6637 
6638  pluginDataQuery += Conversion::toString(pluginID);
6639 
6640  try {
6641  pluginData = dbConnection_->query(pluginDataQuery);
6642  } catch (const Exception& e) {
6643  debugLog(e.errorMessage());
6644  assert(false);
6645  }
6646 
6647  if (pluginData->hasNext()) {
6648  pluginData->next();
6649 
6650  int id = pluginData->data("id").integerValue();
6651  std::string name = pluginData->data("name").stringValue();
6652  std::string desc = pluginData->data("description").stringValue();
6653  std::string path = pluginData->data("plugin_file_path").stringValue();
6654  std::string typeStr = pluginData->data("type").stringValue();
6655 
6658  if (typeStr == COST_PLUGIN_TYPE_FU) {
6660  } else if (typeStr == COST_PLUGIN_TYPE_RF) {
6662  } else if (typeStr == COST_PLUGIN_TYPE_DECOMP) {
6664  } else if (typeStr == COST_PLUGIN_TYPE_ICDEC) {
6666  } else {
6667  delete pluginData;
6668  InvalidData ex(
6669  __FILE__, __LINE__, __func__,
6670  (boost::format("Illegal cost_function_plugin type %d.") %
6671  type).str());
6672  throw ex;
6673  }
6674 
6675  delete pluginData;
6676  return new CostFunctionPlugin(id, desc, name, path, type);
6677 
6678  } else {
6679  delete pluginData;
6680  throw KeyNotFound(
6681  __FILE__, __LINE__, __func__,
6682  (boost::format("Cost function plugin with id %d not found.") %
6683  pluginID).str());
6684  }
6685 }
6686 
6687 /**
6688  * Adds cost estimation data to the HDB.
6689  *
6690  * @param data Cost estimation data to add.
6691  * @return Row ID of the added cost data.
6692  */
6693 RowID
6695  if (!data.hasName() || !data.hasValue() || !data.hasPluginID()) {
6696  throw InvalidData(__FILE__, __LINE__, __func__);
6697  }
6698 
6699  std::string query =
6700  std::string("INSERT INTO cost_estimation_data"
6701  " (id, name, value, plugin_reference, "
6702  " fu_reference, rf_reference, "
6703  " bus_reference, socket_reference) VALUES (") +
6704  "NULL, '" + data.name() + "', '" +
6705  data.value().stringValue() + "', " +
6706  Conversion::toString(data.pluginID()) + ", ";
6707 
6708  // FU Reference
6709  if (data.hasFUReference()) {
6710  if (!hasFUEntry(data.fuReference())) {
6711  throw KeyNotFound(__FILE__, __LINE__, __func__);
6712  }
6713  query += Conversion::toString(data.fuReference());
6714  query += ", ";
6715  } else {
6716  query += "NULL, ";
6717  }
6718 
6719  // RF Reference
6720  if (data.hasRFReference()) {
6721  if (!hasRFEntry(data.rfReference())) {
6722  throw KeyNotFound(__FILE__, __LINE__, __func__);
6723  }
6724  query += Conversion::toString(data.rfReference());
6725  query += ", ";
6726  } else {
6727  query += "NULL, ";
6728  }
6729 
6730  // Bus Reference
6731  if (data.hasBusReference()) {
6732  if (!hasBusEntry(data.busReference())) {
6733  throw KeyNotFound(__FILE__, __LINE__, __func__);
6734  }
6735  query += Conversion::toString(data.busReference());
6736  query += ", ";
6737  } else {
6738  query += "NULL, ";
6739  }
6740 
6741  // Socket Reference
6742  if (data.hasSocketReference()) {
6743  if (!hasSocketEntry(data.socketReference())) {
6744  throw KeyNotFound(__FILE__, __LINE__, __func__);
6745  }
6746  query += Conversion::toString(data.socketReference());
6747  query += ");";
6748  } else {
6749  query += "NULL);";
6750  }
6751 
6752  try {
6753  dbConnection_->updateQuery(query);
6754  return dbConnection_->lastInsertRowID();
6755  } catch (const Exception& e) {
6756  debugLog(e.errorMessage());
6757  assert(false);
6758  }
6759 
6760  // dummy return to avoid compiler whining
6761  assert(false);
6762  return 0;
6763 }
6764 
6765 /**
6766  * Function for querying cost estimation data from the HDB.
6767  *
6768  * Returns set of cost estiamtion data Row IDs that match the given
6769  * datas attributes that are set.
6770  *
6771  * @param match CostEstimationData which is matched to the HDB data.
6772  * @param useCompiledQueries if true use a compiled query instead of making a
6773  * new one.
6774  * @param compiledQuery Pointer to a prepared query to be used.
6775  * @return Set of cost estimation data row IDs that match the query.
6776  */
6777 std::set<RowID>
6779  const CostEstimationData& match,
6780  bool /*useCompiledQueries*/,
6781  RelationalDBQueryResult* compiledQuery) const {
6782 
6783  std::string query = "";
6784  if (!compiledQuery) {
6785  createCostEstimatioDataIdsQuery(match, &query);
6786  } else {
6787  // only bind query variables
6788  createCostEstimatioDataIdsQuery(match, NULL, compiledQuery, NULL);
6789  }
6790 
6791  RelationalDBQueryResult* result = NULL;
6792 
6793  if (compiledQuery) {
6794  result = compiledQuery;
6795  } else {
6796  try {
6797  result = dbConnection_->query(query);
6798  } catch (const Exception& e) {
6799  debugLog(query);
6800  debugLog(e.errorMessage());
6801  assert(false);
6802  }
6803  }
6804 
6805  std::set<RowID> dataIDs;
6806  while (result->hasNext()) {
6807  result->next();
6808  dataIDs.insert(result->data(0).integerValue());
6809  }
6810 
6811  if (!compiledQuery) {
6812  delete result;
6813  } else {
6814  compiledQuery->reset();
6815  }
6816 
6817  return dataIDs;
6818 }
6819 
6820 
6821 /**
6822  * Creates or prepares the query for cost estimation data ids.
6823  *
6824  * @param match CostEstimationData which is matched to the HDB data.
6825  * @param query String variable where query is stored, null if no query is to
6826  * be created.
6827  * @param compiledQuery Pointer to a prepared query to be used, null if not to
6828  * be used.
6829  * @param queryHash Pointer to unique id variable to be created for the
6830  * query, null if not to be created.
6831  * @param createBindableQuery If true query of a kind where variables can be
6832  * binded is created, if false normal query with values is created.
6833  */
6834 void
6836  const CostEstimationData& match,
6837  std::string* query,
6838  RelationalDBQueryResult* compiledQuery,
6839  short int* queryHash,
6840  bool createBindableQuery) const {
6841 
6842  if (queryHash) {
6843  *queryHash = 0;
6844  }
6845  bool firstMatch = true;
6846  unsigned int count = 0;
6847 
6848  if (query) {
6849  *query = "SELECT id FROM cost_estimation_data WHERE ";
6850  }
6851 
6852  if (match.hasName()) {
6853  if (queryHash) {
6854  *queryHash |= 1;
6855  }
6856 
6857  if (compiledQuery) {
6858  compiledQuery->bindString(++count, match.name());
6859  }
6860 
6861  if (query) {
6862  firstMatch = false;
6863  *query += "name='";
6864  *query += createBindableQuery ? "?" : match.name();
6865  *query += "'";
6866  }
6867  }
6868 
6869  if (match.hasValue()) {
6870  if (queryHash) {
6871  *queryHash |= 2;
6872  }
6873 
6874  if (compiledQuery) {
6875  compiledQuery->bindString(++count, match.name());
6876  }
6877 
6878  if (query) {
6879  if (!firstMatch) *query += " AND ";
6880  firstMatch = false;
6881  *query += "value='";
6882  *query += createBindableQuery ? "?" : match.name();
6883  *query += "'";
6884  }
6885  }
6886 
6887  if (match.hasPluginID()) {
6888  if (queryHash) {
6889  *queryHash |= 4;
6890  }
6891 
6892  if (compiledQuery) {
6893  compiledQuery->bindInt(++count, match.pluginID());
6894  }
6895 
6896  if (query) {
6897  if (!firstMatch) *query += " AND ";
6898  firstMatch = false;
6899  *query += "plugin_reference = ";
6900  *query += createBindableQuery ? "?" :
6901  Conversion::toString(match.pluginID());
6902  }
6903  }
6904 
6905  if (match.hasFUReference()) {
6906  if (queryHash) {
6907  *queryHash |= 8;
6908  }
6909 
6910  if (compiledQuery) {
6911  compiledQuery->bindInt(++count, match.fuReference());
6912  }
6913 
6914  if (query) {
6915  if (!firstMatch) *query += " AND ";
6916  firstMatch = false;
6917  *query += "fu_reference = ";
6918  *query += createBindableQuery ? "?" :
6920  }
6921  }
6922 
6923  if (match.hasRFReference()) {
6924  if (queryHash) {
6925  *queryHash |= 16;
6926  }
6927 
6928  if (compiledQuery) {
6929  compiledQuery->bindInt(++count, match.rfReference());
6930  }
6931 
6932  if (query) {
6933  if (!firstMatch) *query += " AND ";
6934  firstMatch = false;
6935  *query += "rf_reference = ";
6936  *query += createBindableQuery ? "?" :
6938  }
6939  }
6940 
6941  if (match.hasBusReference()) {
6942  if (queryHash) {
6943  *queryHash |= 32;
6944  }
6945 
6946  if (compiledQuery) {
6947  compiledQuery->bindInt(++count, match.rfReference());
6948  }
6949 
6950  if (query) {
6951  if (!firstMatch) *query += " AND ";
6952  firstMatch = false;
6953  *query += "bus_reference = ";
6954  *query += createBindableQuery ? "?" :
6956  }
6957  }
6958 
6959  if (match.hasSocketReference()) {
6960  if (queryHash) {
6961  *queryHash |= 64;
6962  }
6963 
6964  if (compiledQuery) {
6965  compiledQuery->bindInt(++count, match.rfReference());
6966  }
6967 
6968  if (query) {
6969  if (!firstMatch) *query += " AND ";
6970  firstMatch = false;
6971  *query += "socket_reference = ";
6972  *query += createBindableQuery ? "?" :
6974  }
6975  }
6976 
6977  if (query) {
6978  *query += ";";
6979  }
6980 }
6981 
6982 
6983 /**
6984  * Returns used database connection.
6985  */
6988  return dbConnection_;
6989 }
6990 
6991 
6992 /**
6993  * Updates cost estimation data in the HDB.
6994  *
6995  * @param id Row ID of the data to update.
6996  * @param data Updated data.
6997  */
6998 void
7000  if (!data.hasName() || !data.hasValue() || !data.hasPluginID()) {
7001  throw InvalidData(__FILE__, __LINE__, __func__);
7002  }
7003 
7004  if (!hasCostEstimationDataByID(id)) {
7005  throw KeyNotFound(__FILE__, __LINE__, __func__);
7006  }
7007 
7008  std::string query =
7009  std::string("UPDATE cost_estimation_data SET ") +
7010  " name='" + data.name() +
7011  "', value='" + data.value().stringValue() +
7012  "', plugin_reference=" + Conversion::toString(data.pluginID());
7013 
7014  // FU entry reference.
7015  if (data.hasFUReference()) {
7016  if (!hasFUEntry(data.fuReference())) {
7017  throw KeyNotFound(__FILE__, __LINE__, __func__);
7018  }
7019  query += ", fu_reference=";
7020  query += Conversion::toString(data.fuReference());
7021  } else {
7022  query += ", fu_reference=NULL";
7023  }
7024 
7025  // RF entry reference.
7026  if (data.hasRFReference()) {
7027  if (!hasRFEntry(data.rfReference())) {
7028  throw KeyNotFound(__FILE__, __LINE__, __func__);
7029  }
7030  query += ", rf_reference=";
7031  query += Conversion::toString(data.rfReference());
7032  } else {
7033  query += ", rf_reference=NULL";
7034  }
7035 
7036  // Bus entry reference
7037  if (data.hasBusReference()) {
7038  if (!hasBusEntry(data.busReference())) {
7039  throw KeyNotFound(__FILE__, __LINE__, __func__);
7040  }
7041  query += ", bus_reference=";
7042  query += Conversion::toString(data.busReference());
7043  } else {
7044  query += ", bus_reference=NULL";
7045  }
7046 
7047  // Socket entry reference.
7048  if (data.hasSocketReference()) {
7049  if (!hasSocketEntry(data.socketReference())) {
7050  throw KeyNotFound(__FILE__, __LINE__, __func__);
7051  }
7052  query += ", socket_reference=";
7053  query += Conversion::toString(data.socketReference());
7054  } else {
7055  query += ", socket_reference=NULL";
7056  }
7057 
7058  query += " WHERE id=";
7059  query += Conversion::toString(id);
7060  query += ";";
7061 
7062  try {
7063  dbConnection_->updateQuery(query);
7064  } catch (const Exception& e) {
7065  debugLog(e.errorMessage());
7066  assert(false);
7067  }
7068 }
7069 
7070 /**
7071  * Modifies cost estimation function plugin attributes.
7072  *
7073  * @param id RowID of the plugin to modify.
7074  * @param plugin Modified plugin (ID is ignored).
7075  * @exception InvalidData Throws if the given plugin was invalid.
7076  * @exception KeyNotFound Throws if no cost function plugin was found with
7077  * given RowID.
7078  */
7079 void
7081  RowID id, const CostFunctionPlugin& plugin) {
7082  if (plugin.name() == "") {
7083  throw InvalidData(__FILE__, __LINE__, __func__);
7084  }
7085 
7086  if (!hasCostFunctionPluginByID(id)) {
7087  throw KeyNotFound(__FILE__, __LINE__, __func__);
7088  }
7089 
7090  string type = "";
7091  switch (plugin.type()) {
7093  type = COST_PLUGIN_TYPE_FU;
7094  break;
7096  type = COST_PLUGIN_TYPE_RF;
7097  break;
7099  type = COST_PLUGIN_TYPE_DECOMP;
7100  break;
7102  type = COST_PLUGIN_TYPE_ICDEC;
7103  break;
7104  default:
7105  InvalidData ex(
7106  __FILE__, __LINE__, __func__,
7107  (boost::format("Illegal cost_function_plugin type %d.") %
7108  type).str());
7109  throw ex;
7110  break;
7111  }
7112 
7113  std::string query =
7114  std::string("UPDATE cost_function_plugin SET ") +
7115  " name='" + plugin.name() +
7116  "', description='" + plugin.description() +
7117  "', plugin_file_path='" + plugin.pluginFilePath() +
7118  "', type='" + type + "'";
7119 
7120  query += " WHERE id=";
7121  query += Conversion::toString(id);
7122  query += ";";
7123 
7124  try {
7125  dbConnection_->updateQuery(query);
7126  } catch (const Exception& e) {
7127  debugLog(e.errorMessage());
7128  assert(false);
7129  }
7130 }
7131 
7132 /**
7133  * Returns block source file names
7134  *
7135  * @return List of block source file names.
7136  */
7137 std::list<std::string>
7139 
7140  RelationalDBQueryResult* queryResult;
7141  try {
7142  queryResult = dbConnection_->query(
7143  std::string("SELECT * FROM block_source_file"));
7144  } catch (const Exception& e) {
7145  debugLog(e.errorMessage());
7146  assert(false);
7147  }
7148 
7149  std::list<std::string> files;
7150  while (queryResult->hasNext()) {
7151  queryResult->next();
7152  files.push_back(queryResult->data(1).stringValue());
7153  }
7154 
7155  delete queryResult;
7156  return files;
7157 }
7158 
7159 } // namespace HDB
HDB::HDBEntry::hasID
bool hasID() const
Definition: HDBEntry.cc:62
HDB::HDBManager::formatString
static std::string formatString(BlockImplementationFile::Format format)
Definition: HDBManager.cc:5737
HDB::FUArchitecture
Definition: FUArchitecture.hh:55
RelationalDBConnection::rollback
virtual void rollback()=0
Definition: RelationalDBConnection.cc:101
HDB::FUEntry
Definition: FUEntry.hh:49
CQ_OPERATION_IMPLEMENTATION_VARIABLE
const string CQ_OPERATION_IMPLEMENTATION_VARIABLE
Definition: HDBManager.cc:374
HDB::FUExternalPort
Definition: FUExternalPort.hh:52
HDB::HDBManager::addPortsAndBindingsToFUArchitecture
void addPortsAndBindingsToFUArchitecture(FUArchitecture &architecture, RowID id) const
Definition: HDBManager.cc:4406
HDB::HDBManager::removeOperationImplementationResource
void removeOperationImplementationResource(RowID id)
Definition: HDBManager.cc:2658
VERILOG_SIM_FORMAT
const string VERILOG_SIM_FORMAT
Definition: HDBManager.cc:91
CostEstimationData::rfReference
RowID rfReference() const
Definition: CostEstimationData.cc:118
HDB::HWBlockImplementation::clkPort
std::string clkPort() const
Definition: HWBlockImplementation.cc:175
HDB::HWBlockImplementation::file
BlockImplementationFile & file(int index) const
Definition: HWBlockImplementation.cc:267
CostEstimationData::setName
void setName(const std::string &name)
RelationalDBConnection
Definition: RelationalDBConnection.hh:48
HDB::OperationImplementation::initialImplFileVerilog
std::string initialImplFileVerilog
Definition: OperationImplementation.hh:55
CQ_OPERATION
const string CQ_OPERATION
Definition: HDBManager.cc:138
HDB::OperationImplementation::latency
int latency
Definition: OperationImplementation.hh:49
HDB::RFPortImplementation::opcodePortWidthFormula
std::string opcodePortWidthFormula() const
Definition: RFPortImplementation.cc:132
AssocTools::difference
static void difference(const ContainerType &firstContainer, const ContainerType &secondContainer, ContainerType &difference)
FUValidator::checkOperandBindings
static void checkOperandBindings(const TTAMachine::FunctionUnit &fu, MachineValidatorResults &results)
Definition: FUValidator.cc:54
CQ_RF_IMPL_ENTRY_INDEX
const string CQ_RF_IMPL_ENTRY_INDEX
Definition: HDBManager.cc:337
HDB::HDBManager::createCostEstimatioDataIdsQuery
void createCostEstimatioDataIdsQuery(const CostEstimationData &match, std::string *query, RelationalDBQueryResult *compiledQuery=NULL, short int *queryHash=NULL, bool createBindableQuery=false) const
Definition: HDBManager.cc:6835
HDB::RFArchitecture::maxReads
int maxReads() const
Definition: RFArchitecture.cc:447
HDB::HDBManager::fuArchitectureByID
virtual FUArchitecture * fuArchitectureByID(RowID id) const
Definition: HDBManager.cc:2940
RelationalDBConnection::lastInsertRowID
virtual RowID lastInsertRowID()=0
HDB::HDBManager::fuImplementationByIDQuery
static std::string fuImplementationByIDQuery(RowID id)
Definition: HDBManager.cc:5962
VERILOG_FORMAT
const string VERILOG_FORMAT
Definition: HDBManager.cc:89
HDB::HDBManager::addCostFunctionPlugin
RowID addCostFunctionPlugin(const CostFunctionPlugin &plugin) const
Definition: HDBManager.cc:626
HDB::OperationImplementationResource::id
int id
Definition: OperationImplementationResource.hh:39
HDB::HDBManager::addFUImplementation
RowID addFUImplementation(const FUEntry &entry) const
Definition: HDBManager.cc:1112
CQ_RF_DATA_PORT
const string CQ_RF_DATA_PORT
Definition: HDBManager.cc:270
RelationalDBConnection::updateQuery
virtual int updateQuery(const std::string &queryString)=0
Definition: RelationalDBConnection.cc:54
FileNotFound
Definition: Exception.hh:224
HDB::HDBManager::addFUCostEstimationData
RowID addFUCostEstimationData(RowID fuID, const std::string &valueName, const std::string &value, RowID pluginID) const
Definition: HDBManager.cc:3210
HDB::CostFunctionPlugin::CostFunctionPluginType
CostFunctionPluginType
all supported cost function plugin types
Definition: CostFunctionPlugin.hh:46
CQ_PIPELINE_RESOURCE
const string CQ_PIPELINE_RESOURCE
Definition: HDBManager.cc:112
DEFAULT_PORT_WIDTH
const int DEFAULT_PORT_WIDTH
Definition: HDBManager.cc:93
CostEstimationData::name
std::string name() const
Definition: CostEstimationData.cc:58
HDB::HDBManager::busCostEstimationDataList
DataObjectList * busCostEstimationDataList(const std::string &valueName, RowID implementationId, const std::string &pluginName) const
Definition: HDBManager.cc:3556
HDB::RFEntry::hasImplementation
virtual bool hasImplementation() const
Definition: RFEntry.cc:74
HDB::HDBManager::fuExternalPortsByIDQuery
static std::string fuExternalPortsByIDQuery(RowID id)
Definition: HDBManager.cc:6043
HDB::FUArchitecture::hasParameterizedWidth
bool hasParameterizedWidth(const std::string &port) const
Definition: FUArchitecture.cc:86
HDB::FUImplementation::hasOpcode
bool hasOpcode(const std::string &operation) const
Definition: FUImplementation.cc:227
HDB::HDBManager::rfImplementationDataPortsByIDQuery
static std::string rfImplementationDataPortsByIDQuery(RowID id)
Definition: HDBManager.cc:6274
HDB
Definition: CostDatabase.hh:49
HDB::HDBManager::hasSocketEntry
bool hasSocketEntry(RowID id) const
Definition: HDBManager.cc:4008
HDB::OperationImplementation::id
int id
Definition: OperationImplementation.hh:48
UnreachableStream
Definition: Exception.hh:171
RelationalDBQueryResult.hh
HDB::HDBManager::rfSourceFilesByIDQuery
static std::string rfSourceFilesByIDQuery(RowID id)
Definition: HDBManager.cc:6300
HDB::HDBManager::directionString
static std::string directionString(HDB::Direction direction)
Definition: HDBManager.cc:5761
HDB::HDBManager::removeFUEntry
virtual void removeFUEntry(RowID id) const
Definition: HDBManager.cc:1039
HDB::CostFunctionPlugin::description
std::string description() const
Definition: CostFunctionPlugin.cc:74
RelationalDBException
Definition: Exception.hh:692
TTAMachine::FUPort::isOpcodeSetting
virtual bool isOpcodeSetting() const
Definition: FUPort.cc:195
TTAMachine::HWOperation
Definition: HWOperation.hh:52
HDB::HDBManager::dbConnection_
RelationalDBConnection * dbConnection_
Handle to the database connection.
Definition: HDBManager.hh:402
HDB::HDBManager::busEntryByIDQuery
static std::string busEntryByIDQuery(RowID id)
Definition: HDBManager.cc:5819
ExecutionPipeline.hh
HDB::RFEntry::setArchitecture
void setArchitecture(RFArchitecture *architecture)
Definition: RFEntry.cc:130
HDB::HDBManager::rfImplementationByIDQuery2
static std::string rfImplementationByIDQuery2(RowID id)
Definition: HDBManager.cc:6246
implementation
IDF::MachineImplementation * implementation
the implementation definition of the estimated processor
Definition: EstimatorCmdLineUI.cc:61
DataObject
Definition: DataObject.hh:50
TTAMachine::HWOperation::bindPort
virtual void bindPort(int operand, const FUPort &port)
Definition: HWOperation.cc:269
FUArchitecture.hh
HDB::RFArchitecture::latency
int latency() const
Definition: RFArchitecture.cc:497
DataObject::stringValue
virtual std::string stringValue() const
Definition: DataObject.cc:344
HDB::HDBEntry::id
RowID id() const
Definition: HDBEntry.cc:85
CQ_OPERATION_IMPLEMENTATION_RESOURCE_SOURCE_FILE
const string CQ_OPERATION_IMPLEMENTATION_RESOURCE_SOURCE_FILE
Definition: HDBManager.cc:340
CostEstimationData::pluginID
RowID pluginID() const
Definition: CostEstimationData.cc:88
HDB::OperationImplementation::initialImplFileVhdl
std::string initialImplFileVhdl
Definition: OperationImplementation.hh:56
HDB::HDBManager::addRFArchitecture
RowID addRFArchitecture(const RFArchitecture &architecture) const
Definition: HDBManager.cc:1461
HDB::HDBManager::costFunctionPluginIDs
std::set< RowID > costFunctionPluginIDs() const
Definition: HDBManager.cc:6553
CQ_FU_PORT_MAP
const string CQ_FU_PORT_MAP
Definition: HDBManager.cc:177
RelationalDBQueryResult::data
virtual const DataObject & data(std::size_t column) const =0
Definition: RelationalDBQueryResult.cc:96
HDB::HDBManager::addSocketEntry
RowID addSocketEntry() const
Definition: HDBManager.cc:3606
HDB::HDBManager::removeOperationImplementation
void removeOperationImplementation(RowID id)
Definition: HDBManager.cc:2622
HDB::BlockImplementationFile::VHDL
@ VHDL
VHDL file.
Definition: BlockImplementationFile.hh:48
CQ_IO_BINDING
const string CQ_IO_BINDING
Definition: HDBManager.cc:152
HDB::FUPortImplementation
Definition: FUPortImplementation.hh:46
CostEstimationData::hasSocketReference
bool hasSocketReference() const
MapTools.hh
HDB::RFArchitecture::zeroRegister
bool zeroRegister() const
Definition: RFArchitecture.cc:541
RelationalDBQueryResult::reset
virtual void reset()
Definition: RelationalDBQueryResult.cc:163
HDB::HDBManager::costFunctionPluginDataIDs
std::set< RowID > costFunctionPluginDataIDs(RowID pluginID) const
Definition: HDBManager.cc:6589
HDB::ExternalPort::setParameterDependency
bool setParameterDependency(const std::string &parameter)
Definition: ExternalPort.cc:162
HDB::RFEntry
Definition: RFEntry.hh:47
HDB::HWBlockImplementation::implementationFileCount
int implementationFileCount() const
Definition: HWBlockImplementation.cc:254
HDB::HDBManager::PipelineElementUsageTable
std::vector< PipelineElementUsage > PipelineElementUsageTable
Definition: HDBManager.hh:297
HDB::BlockImplementationFile::Format
Format
Format of the file.
Definition: BlockImplementationFile.hh:47
HDB::HDBManager::removeBusEntry
virtual void removeBusEntry(RowID id) const
Definition: HDBManager.cc:3418
HDB::HDBManager::addFUArchitecture
RowID addFUArchitecture(const FUArchitecture &architecture) const
Definition: HDBManager.cc:717
RelationalDBQueryResult::UNKNOWN_INDEX
static const int UNKNOWN_INDEX
Definition: RelationalDBQueryResult.hh:50
HDB::OperationImplementationResource::count
int count
Definition: OperationImplementationResource.hh:40
HDB::HDBManager::rfExternalPortsByIDQuery
static std::string rfExternalPortsByIDQuery(RowID id)
Definition: HDBManager.cc:6072
IN_DIRECTION
const string IN_DIRECTION
Definition: HDBManager.cc:85
HDB::FUArchitecture::architecture
TTAMachine::FunctionUnit & architecture() const
Definition: FUArchitecture.cc:131
HDB::HDBManager::fuPortsAndBindingsByIDQuery
static std::string fuPortsAndBindingsByIDQuery(RowID id)
Definition: HDBManager.cc:5880
HDB::HDBManager::removeRFEntry
virtual void removeRFEntry(RowID id) const
Definition: HDBManager.cc:1583
HDB::OperationImplementation::postOpImplFileVerilog
std::string postOpImplFileVerilog
Definition: OperationImplementation.hh:54
CQ_BUS
const string CQ_BUS
Definition: HDBManager.cc:304
HDB::HDBManager::removeFUImplementation
virtual void removeFUImplementation(RowID implementationID) const
Definition: HDBManager.cc:1325
HDB::RFPortImplementation::direction
Direction direction() const
Definition: RFPortImplementation.cc:88
HDB::CostFunctionPlugin::COST_DECOMP
@ COST_DECOMP
decompressor cost estimator
Definition: CostFunctionPlugin.hh:49
COST_PLUGIN_TYPE_ICDEC
const std::string COST_PLUGIN_TYPE_ICDEC
Definition: HDBManager.cc:99
CQ_FU
const string CQ_FU
Definition: HDBManager.cc:102
HDB::HDBManager::addRFCostEstimationData
RowID addRFCostEstimationData(RowID rfID, const std::string &valueName, const std::string &value, RowID pluginID) const
Definition: HDBManager.cc:3246
RowID
int RowID
Type definition of row ID in relational databases.
Definition: DBTypes.hh:37
HDB::FUImplementation::externalPort
FUExternalPort & externalPort(int index) const
Definition: FUImplementation.cc:390
HDB::HDBManager::hasCostFunctionPluginByID
bool hasCostFunctionPluginByID(RowID id) const
Definition: HDBManager.cc:4064
HDB::Variable
Definition: OperationImplementation.hh:40
CostEstimationData::setFUReference
void setFUReference(RowID fuEntryID)
RelationalDBConnection::commit
virtual void commit()=0
Definition: RelationalDBConnection.cc:110
CostEstimationData::setRFReference
void setRFReference(RowID rfEntryID)
HDB::HDBManager::addOperationImplementation
void addOperationImplementation(const OperationImplementation &operation)
Definition: HDBManager.cc:2541
HDB::HDBManager::socketCostEstimationDataList
DataObjectList * socketCostEstimationDataList(const std::string &valueName, RowID implementationID, const std::string &pluginName) const
Definition: HDBManager.cc:3772
MachineValidatorResults.hh
VHDL_FORMAT
const string VHDL_FORMAT
Definition: HDBManager.cc:88
HDB::HDBManager::addBusCostEstimationData
RowID addBusCostEstimationData(RowID busID, const std::string &valueName, const std::string &value, RowID pluginID) const
Definition: HDBManager.cc:3465
CQ_RF_IMPLEMENTATION
const string CQ_RF_IMPLEMENTATION
Definition: HDBManager.cc:257
CostEstimationData::hasFUReference
bool hasFUReference() const
HDB::HDBManager::OperationImplementationResourceByID
OperationImplementationResource OperationImplementationResourceByID(RowID id) const
Definition: HDBManager.cc:2410
HDB::HDBManager::addRFEntry
RowID addRFEntry() const
Definition: HDBManager.cc:1557
TTAMachine::ExecutionPipeline::writtenOperands
OperandSet writtenOperands(int cycle) const
Definition: ExecutionPipeline.cc:429
HDB::RFArchitecture::hasParameterizedSize
bool hasParameterizedSize() const
Definition: RFArchitecture.cc:282
HDB::HDBManager::socketCostEstimationData
DataObject socketCostEstimationData(const std::string &valueName, RowID socketID, const std::string &pluginName) const
Definition: HDBManager.cc:3718
FUPortImplementation.hh
COST_PLUGIN_TYPE_RF
const std::string COST_PLUGIN_TYPE_RF
Definition: HDBManager.cc:97
TTAMachine::PipelineElement::name
const std::string & name() const
TTAMachine::ExecutionPipeline::readOperands
OperandSet readOperands(int cycle) const
Definition: ExecutionPipeline.cc:408
HDB::FUImplementation::opcodePort
std::string opcodePort() const
Definition: FUImplementation.cc:135
READ_ACTION
const bool READ_ACTION
Definition: HDBManager.cc:82
HDB::HDBManager::hasColumn
bool hasColumn(const std::string &table, const std::string &columnName) const
Definition: HDBManager.cc:4342
HDB::HDBManager::addBlockImplementationFileToHDB
void addBlockImplementationFileToHDB(const BlockImplementationFile &file) const
Definition: HDBManager.cc:5498
TTAMachine::FUPort::isTriggering
virtual bool isTriggering() const
Definition: FUPort.cc:182
HDB::HDBManager::costEstimationData
CostEstimationData costEstimationData(RowID id) const
Definition: HDBManager.cc:6323
CQ_RF_EXT_PORT_PARAMETER_DEPENDENCY
const string CQ_RF_EXT_PORT_PARAMETER_DEPENDENCY
Definition: HDBManager.cc:230
HDB::HDBManager::costFunctionPluginByID
CostFunctionPlugin * costFunctionPluginByID(RowID pluginID) const
Definition: HDBManager.cc:6631
FileSystem::absolutePathOf
static std::string absolutePathOf(const std::string &pathName)
Definition: FileSystem.cc:303
CostEstimationData::hasValue
bool hasValue() const
MachineValidatorResults
Definition: MachineValidatorResults.hh:45
HDB::HDBManager::hasCostEstimationDataByID
bool hasCostEstimationDataByID(RowID id) const
Definition: HDBManager.cc:4035
HDB::OperationImplementationResource::ipxact
std::string ipxact
Definition: OperationImplementationResource.hh:42
HDB::HDBManager::containsImplementationFile
bool containsImplementationFile(const std::string &pathToFile) const
Definition: HDBManager.cc:4185
HDB::OperationImplementation::postOpImplFileVhdl
std::string postOpImplFileVhdl
Definition: OperationImplementation.hh:53
HDB::BlockImplementationFile
Definition: BlockImplementationFile.hh:44
CostEstimationData::setValue
void setValue(const DataObject &value)
Conversion::toString
static std::string toString(const T &source)
HDB::HDBManager::unsetCostFunctionPluginForFU
void unsetCostFunctionPluginForFU(RowID fuID) const
Definition: HDBManager.cc:1971
CQ_FU_DATA_PORT
const string CQ_FU_DATA_PORT
Definition: HDBManager.cc:143
RelationalDBQueryResult::hasNext
virtual bool hasNext()=0
Definition: RelationalDBQueryResult.cc:126
NotAvailable
Definition: Exception.hh:728
SQLite::connect
virtual RelationalDBConnection & connect(const std::string &database, const std::string &login="", const std::string &password="", bool readOnly=false)
Definition: SQLite.cc:69
HDB::RFArchitecture::width
int width() const
Definition: RFArchitecture.cc:343
HDB::HDBManager::hdbFile_
std::string hdbFile_
The HDB file to manager.
Definition: HDBManager.hh:404
HDB::HDBManager::fuArchitectureIDsByOperationSet
std::set< RowID > fuArchitectureIDsByOperationSet(const std::set< std::string > &operationNames) const
Definition: HDBManager.cc:2684
HDB::HDBManager::removeSocketEntry
virtual void removeSocketEntry(RowID id) const
Definition: HDBManager.cc:3631
HDB::OperationImplementation::verilogVariables
std::vector< Variable > verilogVariables
Definition: OperationImplementation.hh:60
BIDIR_DIRECTION
const string BIDIR_DIRECTION
Definition: HDBManager.cc:87
FileSystem::fileIsCreatable
static bool fileIsCreatable(const std::string fileName)
Definition: FileSystem.cc:123
HDB::HDBManager::rfEntryIDOfImplementation
RowID rfEntryIDOfImplementation(RowID implID) const
Definition: HDBManager.cc:2796
HDB::HWBlockImplementation::rstPort
std::string rstPort() const
Definition: HWBlockImplementation.cc:197
HDB::HDBEntry::setID
void setID(RowID id)
Definition: HDBEntry.cc:73
HDB::HDBManager::busCostEstimationData
DataObject busCostEstimationData(const std::string &valueName, RowID busID, const std::string &pluginName) const
Definition: HDBManager.cc:3506
HDB::HDBManager::containsOperation
bool containsOperation(const std::string &opName) const
Definition: HDBManager.cc:4159
HDB::HDBManager::rfCostEstimationData
DataObject rfCostEstimationData(const std::string &valueName, RowID implementationId, const std::string &pluginName) const
Definition: HDBManager.cc:3345
HDB::FUImplementation::glockReqPort
std::string glockReqPort() const
Definition: FUImplementation.cc:157
HDB::CostFunctionPlugin::COST_FU
@ COST_FU
function unit cost estimator
Definition: CostFunctionPlugin.hh:47
RelationalDBConnection::version
virtual int version()=0
Definition: RelationalDBConnection.cc:146
HDB::OperationImplementationResource::synFiles
std::vector< std::string > synFiles
Definition: OperationImplementationResource.hh:45
assert
#define assert(condition)
Definition: Application.hh:86
TTAMachine::FunctionUnit
Definition: FunctionUnit.hh:55
HDB::FUImplementation::parameterCount
int parameterCount() const
Definition: FUImplementation.cc:443
HDB::HDBManager::hasBusEntry
bool hasBusEntry(RowID id) const
Definition: HDBManager.cc:3980
TTAMachine::HWOperation::port
virtual FUPort * port(int operand) const
Definition: HWOperation.cc:320
HDB::CostFunctionPlugin::COST_ICDEC
@ COST_ICDEC
interconnection network & decoder cost estimator
Definition: CostFunctionPlugin.hh:50
HDB::HDBManager::modifyCostEstimationData
virtual void modifyCostEstimationData(RowID id, const CostEstimationData &data)
Definition: HDBManager.cc:6999
CQ_OPERATION_IMPLEMENTATION_RESOURCE
const string CQ_OPERATION_IMPLEMENTATION_RESOURCE
Definition: HDBManager.cc:354
DataObject::integerValue
virtual int integerValue() const
Definition: DataObject.cc:204
CQ_OPERATION_PIPELINE
const string CQ_OPERATION_PIPELINE
Definition: HDBManager.cc:117
TTAMachine::FUPort
Definition: FUPort.hh:46
CostEstimationData::hasName
bool hasName() const
HDB::HDBManager::addBlockImplementationFiles
void addBlockImplementationFiles(FUImplementation &implementation, RowID entryID) const
Definition: HDBManager.cc:5337
HDB::HDBManager::createCostFunctionOfFU
CostFunctionPlugin * createCostFunctionOfFU(RowID id) const
Definition: HDBManager.cc:4691
HDB::RFExternalPort
Definition: RFExternalPort.hh:41
HDB::HDBManager::addSocketCostEstimationData
RowID addSocketCostEstimationData(RowID socketID, const std::string &valueName, const std::string &value, RowID pluginID) const
Definition: HDBManager.cc:3678
HDB::HDBEntry::setCostFunction
void setCostFunction(CostFunctionPlugin *costFunction)
Definition: HDBEntry.cc:127
HDB::HDBManager::resolveArchitecturePort
std::string resolveArchitecturePort(const FUArchitecture &architecture, RowID entryID, const std::string &implementedPort) const
Definition: HDBManager.cc:4922
CQ_OPERATION_IMPLEMENTATION_SOURCE_FILE
const string CQ_OPERATION_IMPLEMENTATION_SOURCE_FILE
Definition: HDBManager.cc:347
HDB::HDBManager::OperationImplementationResourceIDs
std::set< RowID > OperationImplementationResourceIDs() const
Definition: HDBManager.cc:2221
RelationalDBConnection::updateVersion
virtual void updateVersion(int version)=0
Definition: RelationalDBConnection.cc:156
HDB::OperationImplementation::verilogGlobalSignals
std::vector< Variable > verilogGlobalSignals
Definition: OperationImplementation.hh:62
HDB::HDBManager::insertFileFormats
static void insertFileFormats(RelationalDBConnection &connection)
Definition: HDBManager.cc:5689
CostEstimationData::busReference
RowID busReference() const
Definition: CostEstimationData.cc:133
TTAMachine::ExecutionPipeline::addResourceUse
void addResourceUse(const std::string &name, int start, int duration)
Definition: ExecutionPipeline.cc:112
HDB::RFImplementation
Definition: RFImplementation.hh:50
HDB::HDBManager::unsetArchitectureForRF
void unsetArchitectureForRF(RowID rfID) const
Definition: HDBManager.cc:1930
HDB::FUArchitecture::setParameterizedWidth
void setParameterizedWidth(const std::string &port)
Definition: FUArchitecture.cc:97
TTAMachine::HWOperation::io
int io(const FUPort &port) const
Definition: HWOperation.cc:364
abortWithError
#define abortWithError(message)
Definition: Application.hh:72
HDB::FUArchitecture::hasGuardSupport
bool hasGuardSupport(const std::string &port) const
Definition: FUArchitecture.cc:109
HDB::FUEntry::hasArchitecture
virtual bool hasArchitecture() const
Definition: FUEntry.cc:117
HWOperation.hh
HDB::HDBManager::fuArchitectureIDs
std::set< RowID > fuArchitectureIDs() const
Definition: HDBManager.cc:2163
TTAMachine::HWOperation::name
const std::string & name() const
Definition: HWOperation.cc:141
WRITE_ACTION
const bool WRITE_ACTION
Definition: HDBManager.cc:83
InvalidData
Definition: Exception.hh:149
CostEstimationData::setBusReference
void setBusReference(RowID busEntryID)
HDB::HDBManager::addOperationImplementationResource
void addOperationImplementationResource(const OperationImplementationResource &resource)
Definition: HDBManager.cc:2482
RelationalDBQueryResult::next
virtual bool next()=0
Definition: RelationalDBQueryResult.cc:138
HDB::OperationImplementationResource::simFormats
std::vector< std::string > simFormats
Definition: OperationImplementationResource.hh:44
CQ_FU_EXTERNAL_PORT
const string CQ_FU_EXTERNAL_PORT
Definition: HDBManager.cc:188
HDB::HDBManager::addBooleanColumn
int addBooleanColumn(const std::string &table, const std::string &newcolumn)
Definition: HDBManager.cc:4380
RFImplementation.hh
TTAMachine::FunctionUnit::pipelineElement
virtual PipelineElement * pipelineElement(int index) const
Definition: FunctionUnit.cc:523
HDB::HDBManager::PipelineElementUsage
Definition: HDBManager.hh:291
CQ_PIPELINE_RESOURCE_USAGE
const string CQ_PIPELINE_RESOURCE_USAGE
Definition: HDBManager.cc:123
HDB::HDBManager::canRemoveFUArchitecture
bool canRemoveFUArchitecture(RowID archID) const
Definition: HDBManager.cc:904
HDB::HDBManager::setArchitectureForRF
void setArchitectureForRF(RowID rfID, RowID archID) const
Definition: HDBManager.cc:1895
HDB::RFArchitecture::maxWrites
int maxWrites() const
Definition: RFArchitecture.cc:472
Conversion.hh
HDB::OperationImplementation::implFileVerilog
std::string implFileVerilog
Definition: OperationImplementation.hh:52
RelationalDBQueryResult::bindString
virtual void bindString(unsigned int position, const std::string &value)
Definition: RelationalDBQueryResult.cc:154
HDB::HDBManager::fuEntryIDs
std::set< RowID > fuEntryIDs() const
Definition: HDBManager.cc:2035
HDB::OperationImplementationResource::simFiles
std::vector< std::string > simFiles
Definition: OperationImplementationResource.hh:46
HDB::HDBManager::resourceUsageDataByIDQuery
static std::string resourceUsageDataByIDQuery(RowID id)
Definition: HDBManager.cc:5933
HDB::ExternalPort::parameterDependency
std::string parameterDependency(int index) const
Definition: ExternalPort.cc:203
HDB::HDBManager::hasFUEntry
bool hasFUEntry(RowID id) const
Definition: HDBManager.cc:3924
HDB::Direction
Direction
Direction of port.
Definition: HDBTypes.hh:40
HDB::HDBManager::costEstimationDataValue
virtual DataObject costEstimationDataValue(const std::string &valueName, const std::string &pluginName) const
Definition: HDBManager.cc:3831
HDB::BIDIR
@ BIDIR
Bidirectional port.
Definition: HDBTypes.hh:43
HDB::FUEntry::architecture
FUArchitecture & architecture() const
Definition: FUEntry.cc:129
Application.hh
FUEntry.hh
HDB::HDBManager::addFUParametersToImplementation
void addFUParametersToImplementation(FUImplementation &implementation, RowID entryID) const
Definition: HDBManager.cc:5240
HDB::HDBManager::createNew
static void createNew(const std::string &file)
Definition: HDBManager.cc:548
HDB::HDBManager::rfArchitectureByID
virtual RFArchitecture * rfArchitectureByID(RowID id) const
Definition: HDBManager.cc:2963
DataObject::isNull
virtual bool isNull() const
Definition: DataObject.cc:491
HDB::HDBManager::fuImplementationParametersByIDQuery
static std::string fuImplementationParametersByIDQuery(RowID id)
Definition: HDBManager.cc:6099
HDB::HDBManager::hasRFEntry
bool hasRFEntry(RowID id) const
Definition: HDBManager.cc:3952
TTAMachine::HWOperation::isBound
bool isBound(const FUPort &port) const
Definition: HWOperation.cc:338
RelationalDBQueryResult
Definition: RelationalDBQueryResult.hh:46
CQ_FU_ARCHITECTURE
const string CQ_FU_ARCHITECTURE
Definition: HDBManager.cc:108
__func__
#define __func__
Definition: Application.hh:67
TTAMachine::ExecutionPipeline::addPortRead
void addPortRead(int operand, int start, int duration)
Definition: ExecutionPipeline.cc:141
HDB::HDBManager::fuEntryByIDQuery
static std::string fuEntryByIDQuery(RowID id)
Definition: HDBManager.cc:5781
HDB::HDBManager::addRFExternalPortsToImplementation
void addRFExternalPortsToImplementation(RFImplementation &implementation, RowID entryID) const
Definition: HDBManager.cc:5143
HDB::HDBManager::socketEntryIDs
std::set< RowID > socketEntryIDs() const
Definition: HDBManager.cc:2131
CQ_FU_IMPLEMENTATION_PARAMETER
const string CQ_FU_IMPLEMENTATION_PARAMETER
Definition: HDBManager.cc:208
RFPortImplementation.hh
HDB::Parameter::type
std::string type
Type of the parameter.
Definition: HDBTypes.hh:48
HDB::HDBManager::fuEntriesByArchitecture
std::set< RowID > fuEntriesByArchitecture(const TTAMachine::FunctionUnit &fu) const
Definition: HDBManager.cc:3040
HDB::HDBManager::rfEntriesByArchitecture
std::set< RowID > rfEntriesByArchitecture(int readPorts, int writePorts, int bidirPorts, int maxReads, int maxWrites, int latency, bool guardSupport, int guardLatency=0, int width=0, int size=0, bool zeroRegister=false) const
Definition: HDBManager.cc:3133
TTAMachine::FunctionUnit::operationCount
virtual int operationCount() const
Definition: FunctionUnit.cc:419
HDB::HDBManager::fuEntryIDOfImplementation
RowID fuEntryIDOfImplementation(RowID implID) const
Definition: HDBManager.cc:2765
RFArchitecture.hh
HDB::RFArchitecture::hasParameterizedWidth
bool hasParameterizedWidth() const
Definition: RFArchitecture.cc:271
HDB::HDBManager::createCostFunctionOfRF
CostFunctionPlugin * createCostFunctionOfRF(RowID id) const
Definition: HDBManager.cc:4763
HDB::OperationImplementation::name
std::string name
Definition: OperationImplementation.hh:50
CQ_OPERATION_IMPLEMENTATION
const string CQ_OPERATION_IMPLEMENTATION
Definition: HDBManager.cc:360
RelationalDBConnection::query
virtual RelationalDBQueryResult * query(const std::string &queryString, bool init=true)=0
Definition: RelationalDBConnection.cc:80
FUValidator::checkOperations
static void checkOperations(const TTAMachine::FunctionUnit &fu, MachineValidatorResults &results)
Definition: FUValidator.cc:100
HDB::HDBManager::rfEntryByIDQuery
static std::string rfEntryByIDQuery(RowID id)
Definition: HDBManager.cc:5800
HDB::OperationImplementationResource
Definition: OperationImplementationResource.hh:38
CostEstimationData::socketReference
RowID socketReference() const
Definition: CostEstimationData.cc:148
TTAMachine::FunctionUnit::hasOperation
virtual bool hasOperation(const std::string &name) const
Definition: FunctionUnit.cc:330
MachineValidatorResults::errorCount
int errorCount() const
Definition: MachineValidatorResults.cc:56
HDB::PortImplementation::loadPort
std::string loadPort() const
Definition: PortImplementation.cc:96
HDB::RFArchitecture::setWidth
void setWidth(int width)
Definition: RFArchitecture.cc:294
HDB::RFArchitecture::guardLatency
int guardLatency() const
Definition: RFArchitecture.cc:551
Exception
Definition: Exception.hh:54
HDB::FUArchitecture::setGuardSupport
void setGuardSupport(const std::string &port)
Definition: FUArchitecture.cc:120
HDB::BlockImplementationFile::pathToFile
std::string pathToFile() const
Definition: BlockImplementationFile.cc:61
HDB::HDBManager::socketEntryByIDQuery
static std::string socketEntryByIDQuery(RowID id)
Definition: HDBManager.cc:5838
HDB::HDBManager::setCostFunctionPluginForFU
void setCostFunctionPluginForFU(RowID fuID, RowID pluginID) const
Definition: HDBManager.cc:1950
HDB::BlockImplementationFile::Verilog
@ Verilog
Verilog file.
Definition: BlockImplementationFile.hh:49
TTAMachine::ExecutionPipeline::OperandSet
std::set< int > OperandSet
Set for operand indexes.
Definition: ExecutionPipeline.hh:58
TTAMachine::FunctionUnit::operationPortCount
virtual int operationPortCount() const
Definition: FunctionUnit.cc:182
DataObject.hh
HDB::HDBManager::containsRFArchitecture
bool containsRFArchitecture(RowID id) const
Definition: HDBManager.cc:4240
HDB::HDBManager::busCostEstimationDataIDs
std::set< RowID > busCostEstimationDataIDs(RowID busID) const
Definition: HDBManager.cc:6514
CQ_RF_IMPLEMENTATION_PARAMETER
const string CQ_RF_IMPLEMENTATION_PARAMETER
Definition: HDBManager.cc:216
HDB::HDBManager::addBusEntry
RowID addBusEntry() const
Definition: HDBManager.cc:3393
HDB::RFEntry::setImplementation
void setImplementation(RFImplementation *implementation)
Definition: RFEntry.cc:87
CostEstimationData
Definition: CostEstimationData.hh:42
CQ_RF_ARCHITECTURE
const string CQ_RF_ARCHITECTURE
Definition: HDBManager.cc:242
HDB::HDBManager::DataObjectList
std::list< DataObject > DataObjectList
Definition: HDBManager.hh:86
RelationalDBConnection::beginTransaction
virtual void beginTransaction()=0
Definition: RelationalDBConnection.cc:92
FUImplementation.hh
HDB::HDBManager::busEntryIDs
std::set< RowID > busEntryIDs() const
Definition: HDBManager.cc:2099
CostEstimationData::value
DataObject value() const
Definition: CostEstimationData.cc:73
Exception::errorMessage
std::string errorMessage() const
Definition: Exception.cc:123
SQLite::close
virtual void close(const RelationalDBConnection &connection)
Definition: SQLite.cc:100
HDB::HDBManager::PipelineElementUsage::usage1
std::set< const TTAMachine::PipelineElement * > usage1
Definition: HDBManager.hh:292
TTAMachine::FunctionUnit::pipelineElementCount
virtual int pipelineElementCount() const
Definition: FunctionUnit.cc:507
CostEstimationData::hasPluginID
bool hasPluginID() const
HDB::OperationImplementation::resources
std::vector< OperationImplementationResource > resources
Definition: OperationImplementation.hh:58
HDB::HDBManager::addRFParametersToImplementation
void addRFParametersToImplementation(RFImplementation &implementation, RowID entryID) const
Definition: HDBManager.cc:5274
HDB::HDBManager::addOperationPipelinesToFUArchitecture
void addOperationPipelinesToFUArchitecture(FUArchitecture &architecture, RowID id) const
Definition: HDBManager.cc:4517
HDB::HDBManager::OperationImplementationIDs
std::set< RowID > OperationImplementationIDs() const
Definition: HDBManager.cc:2193
HDB::OperationImplementation::vhdlVariables
std::vector< Variable > vhdlVariables
Definition: OperationImplementation.hh:59
HDB::CostFunctionPlugin::COST_RF
@ COST_RF
register file cost estimator
Definition: CostFunctionPlugin.hh:48
HDB::HDBManager::rfArchitectureID
RowID rfArchitectureID(RowID rfEntryID) const
Definition: HDBManager.cc:4305
HDB::HDBManager::rfEntryIDs
std::set< RowID > rfEntryIDs() const
Definition: HDBManager.cc:2067
HWBlockArchitecture::id
RowID id() const
Definition: HWBlockArchitecture.cc:79
HDB::HDBManager::addFUEntry
RowID addFUEntry() const
Definition: HDBManager.cc:1014
HDB::HDBManager::addRFImplementation
RowID addRFImplementation(const RFImplementation &implementation, RowID rfEntryID)
Definition: HDBManager.cc:1640
HDB::OperationImplementation::absBusDefFile
std::string absBusDefFile
Definition: OperationImplementation.hh:57
CQ_RF
const string CQ_RF
Definition: HDBManager.cc:236
TTAMachine::FunctionUnit::hasOperationPort
virtual bool hasOperationPort(const std::string &name) const
Definition: FunctionUnit.cc:204
CQ_SOCKET
const string CQ_SOCKET
Definition: HDBManager.cc:308
HDB::HDBManager::rfArchitectureIDs
std::set< RowID > rfArchitectureIDs() const
Definition: HDBManager.cc:2734
HDB::RFArchitecture::hasGuardSupport
bool hasGuardSupport() const
Definition: RFArchitecture.cc:519
CostEstimationData::hasBusReference
bool hasBusReference() const
HDB::HDBManager::fuEntryHasArchitecture
bool fuEntryHasArchitecture(RowID id) const
Definition: HDBManager.cc:4097
HDB::Parameter::name
std::string name
Name of the parameter.
Definition: HDBTypes.hh:47
HDB::HDBManager::removeCostFunctionPlugin
virtual void removeCostFunctionPlugin(RowID pluginID) const
Definition: HDBManager.cc:684
HDB::HDBManager::fileName
std::string fileName() const
Definition: HDBManager.cc:612
SetTools::intersection
static void intersection(const std::set< ValueType > &firstContainer, const std::set< ValueType > &secondContainer, std::set< ValueType > &intersection)
HDB::FUImplementation
Definition: FUImplementation.hh:53
HDB::RFArchitecture
Definition: RFArchitecture.hh:50
HWBlockArchitecture::setID
void setID(RowID id)
Definition: HWBlockArchitecture.cc:67
CQ_FU_EXT_PORT_PARAMETER_DEPENDENCY
const string CQ_FU_EXT_PORT_PARAMETER_DEPENDENCY
Definition: HDBManager.cc:224
HDB::RFPortImplementation
Definition: RFPortImplementation.hh:43
CQ_FORMAT
const string CQ_FORMAT
Definition: HDBManager.cc:299
CQ_FU_IMPLEMENTATION
const string CQ_FU_IMPLEMENTATION
Definition: HDBManager.cc:159
HDB::HDBManager::opcodesByIDQuery
static std::string opcodesByIDQuery(RowID id)
Definition: HDBManager.cc:5991
HDB::FUImplementation::opcode
int opcode(const std::string &operation) const
Definition: FUImplementation.cc:242
HDB::HDBManager::costEstimationDataIDs
virtual std::set< RowID > costEstimationDataIDs(const CostEstimationData &match, bool useCompiledQueries=false, RelationalDBQueryResult *compiledQuery=NULL) const
Definition: HDBManager.cc:6778
MapTools::containsKey
static bool containsKey(const MapType &aMap, const KeyType &aKey)
OUT_DIRECTION
const string OUT_DIRECTION
Definition: HDBManager.cc:86
HDB::HDBManager::socketCostEstimationDataIDs
std::set< RowID > socketCostEstimationDataIDs(RowID socketID) const
Definition: HDBManager.cc:6473
HDB::HDBManager::db_
SQLite * db_
Handle to the database.
Definition: HDBManager.hh:400
HDB::FUPortImplementation::architecturePort
std::string architecturePort() const
Definition: FUPortImplementation.cc:93
FUExternalPort.hh
RelationalDBConnection::DDLQuery
virtual void DDLQuery(const std::string &queryString)=0
Definition: RelationalDBConnection.cc:69
SetTools.hh
HDB::HDBManager::getDBConnection
RelationalDBConnection * getDBConnection() const
Definition: HDBManager.cc:6987
HDB::HDBManager::OperationImplementationByID
OperationImplementation OperationImplementationByID(RowID id) const
Definition: HDBManager.cc:2248
TTAMachine::PipelineElement
Definition: PipelineElement.hh:46
HDB::PortImplementation::name
std::string name() const
Definition: PortImplementation.cc:74
RelationalDBConnection::tableExistsInDB
virtual bool tableExistsInDB(const std::string &tableName)=0
Definition: RelationalDBConnection.cc:122
CQ_FU_IMPL_ENTRY_INDEX
const string CQ_FU_IMPL_ENTRY_INDEX
Definition: HDBManager.cc:334
CQ_IO_USAGE
const string CQ_IO_USAGE
Definition: HDBManager.cc:130
CQ_FU_SOURCE_FILE
const string CQ_FU_SOURCE_FILE
Definition: HDBManager.cc:293
BlockImplementationFile.hh
CostEstimationData::fuReference
RowID fuReference() const
Definition: CostEstimationData.cc:103
HDB::BlockImplementationFile::Verilogsim
@ Verilogsim
Verilog simulation file.
Definition: BlockImplementationFile.hh:51
HDB::HDBManager::fuSourceFilesByIDQuery
static std::string fuSourceFilesByIDQuery(RowID id)
Definition: HDBManager.cc:6174
CostEstimationData::setPluginID
void setPluginID(RowID pluginID)
RelationalDBQueryResult::column
virtual int column(const std::string &name) const
Definition: RelationalDBQueryResult.cc:64
FileSystem::fileExists
static bool fileExists(const std::string fileName)
HDB::HDBManager::addCostEstimationData
RowID addCostEstimationData(const CostEstimationData &data) const
Definition: HDBManager.cc:6694
AssocTools.hh
TTAMachine::Port::name
virtual std::string name() const
Definition: Port.cc:141
HDB::CostFunctionPlugin::pluginFilePath
std::string pluginFilePath() const
Definition: CostFunctionPlugin.cc:94
RelationalDBQueryResult::bindInt
virtual void bindInt(unsigned int position, int value)
Definition: RelationalDBQueryResult.cc:146
HDB::FUImplementation::parameter
Parameter parameter(int index) const
Definition: FUImplementation.cc:457
HDB::HDBManager::removeCostEstimationData
virtual void removeCostEstimationData(RowID id) const
Definition: HDBManager.cc:5479
HDB::RFPortImplementation::opcodePort
std::string opcodePort() const
Definition: RFPortImplementation.cc:110
CQ_COST_ESTIMATION_DATA
const string CQ_COST_ESTIMATION_DATA
type: {'fu'|'rf'|'decomp'|'icdec'}
Definition: HDBManager.cc:320
HDB::BlockImplementationFile::format
Format format() const
Definition: BlockImplementationFile.cc:70
FUPort.hh
HDB::HDBManager::createImplementationOfFU
virtual FUImplementation * createImplementationOfFU(FUArchitecture &architecture, RowID id) const
Definition: HDBManager.cc:4615
HDB::HDBManager::rfImplementationParametersByIDQuery
static std::string rfImplementationParametersByIDQuery(RowID id)
Definition: HDBManager.cc:6122
HDB::HDBManager::rfCostEstimationDataIDs
std::set< RowID > rfCostEstimationDataIDs(RowID rfImplID) const
Definition: HDBManager.cc:6432
HDB::FUImplementation::architecturePortCount
int architecturePortCount() const
Definition: FUImplementation.cc:326
HDB::HDBManager::~HDBManager
virtual ~HDBManager()
Definition: HDBManager.cc:534
CQ_RF_EXTERNAL_PORT
const string CQ_RF_EXTERNAL_PORT
Definition: HDBManager.cc:198
CostEstimationData::hasRFReference
bool hasRFReference() const
HDB::OperationImplementationResource::name
std::string name
Definition: OperationImplementationResource.hh:41
HDB::RFArchitecture::readPortCount
int readPortCount() const
Definition: RFArchitecture.cc:372
HDB::FUEntry::setImplementation
void setImplementation(FUImplementation *implementation)
Definition: FUEntry.cc:103
PipelineElement.hh
HDB::IN
@ IN
Input port.
Definition: HDBTypes.hh:41
HDB::HDBManager::removeRFImplementation
virtual void removeRFImplementation(RowID implID) const
Definition: HDBManager.cc:1808
HDB::HDBManager::unsetCostFunctionPluginForRF
void unsetCostFunctionPluginForRF(RowID rfID) const
Definition: HDBManager.cc:2014
HDB::RFArchitecture::size
int size() const
Definition: RFArchitecture.cc:326
HDB::HDBManager::rfEntryHasArchitecture
bool rfEntryHasArchitecture(RowID id) const
Definition: HDBManager.cc:4129
HDB::HDBManager::rfArchitectureByIDQuery
static std::string rfArchitectureByIDQuery(RowID id)
Definition: HDBManager.cc:6198
COST_PLUGIN_TYPE_DECOMP
const std::string COST_PLUGIN_TYPE_DECOMP
Definition: HDBManager.cc:98
TTAMachine::HWOperation::pipeline
ExecutionPipeline * pipeline() const
Definition: HWOperation.cc:201
HDB::Parameter::value
std::string value
Value of the parameter.
Definition: HDBTypes.hh:49
CostEstimationData::setSocketReference
void setSocketReference(RowID socketEntryID)
TTAMachine::ExecutionPipeline
Definition: ExecutionPipeline.hh:55
HDB::HDBManager::addOpcodesToImplementation
void addOpcodesToImplementation(FUImplementation &implementation, RowID entryID) const
Definition: HDBManager.cc:4971
HDB::HDBManager::fuCostEstimationData
DataObject fuCostEstimationData(const std::string &valueName, RowID implementationId, const std::string &pluginName) const
Definition: HDBManager.cc:3289
HDB::HDBManager::fuPortBindingByNameQuery
static std::string fuPortBindingByNameQuery(RowID fuID, const std::string &portName)
Definition: HDBManager.cc:6146
HDB::HDBManager::PipelineElementUsage::usage2
std::set< const TTAMachine::PipelineElement * > usage2
Definition: HDBManager.hh:293
TTAMachine::ExecutionPipeline::addPortWrite
void addPortWrite(int operand, int start, int duration)
Definition: ExecutionPipeline.cc:167
CostFunctionPlugin.hh
RFEntry.hh
HDB::Parameter
Definition: HDBTypes.hh:46
FUValidator.hh
KeyNotFound
Definition: Exception.hh:285
CQ_OPCODE_MAP
const string CQ_OPCODE_MAP
Definition: HDBManager.cc:170
HDB::HWBlockImplementation::moduleName
std::string moduleName() const
Definition: HWBlockImplementation.cc:153
TTAMachine::FunctionUnit::operation
virtual HWOperation * operation(const std::string &name) const
Definition: FunctionUnit.cc:363
CQ_OPERATION_IMPLEMENTATION_RESOURCES
const string CQ_OPERATION_IMPLEMENTATION_RESOURCES
Definition: HDBManager.cc:366
TTAMachine::HWOperation::latency
int latency() const
Definition: HWOperation.cc:216
IOException
Definition: Exception.hh:130
HDB::ExternalPort::description
std::string description() const
Definition: ExternalPort.cc:150
HDB::HDBManager::addFUExternalPortsToImplementation
void addFUExternalPortsToImplementation(FUImplementation &implementation, RowID entryID) const
Definition: HDBManager.cc:5055
HDB::ExternalPort::name
std::string name() const
Definition: ExternalPort.cc:84
HDB::HDBManager::fuCostEstimationDataIDs
std::set< RowID > fuCostEstimationDataIDs(RowID fuImplID) const
Definition: HDBManager.cc:6391
TTAMachine::FunctionUnit::operationPort
virtual FUPort * operationPort(const std::string &name) const
Definition: FunctionUnit.cc:224
HDB::HDBManager::canRemoveRFArchitecture
bool canRemoveRFArchitecture(RowID archID) const
Definition: HDBManager.cc:1508
HDB::RFArchitecture::bidirPortCount
int bidirPortCount() const
Definition: RFArchitecture.cc:422
HDB::FUEntry::setArchitecture
void setArchitecture(FUArchitecture *architecture)
Definition: FUEntry.cc:146
HDB::FUEntry::hasImplementation
virtual bool hasImplementation() const
Definition: FUEntry.cc:74
CQ_RF_SOURCE_FILE
const string CQ_RF_SOURCE_FILE
Definition: HDBManager.cc:287
HDB::CostFunctionPlugin::type
CostFunctionPluginType type() const
Definition: CostFunctionPlugin.cc:104
TTAMachine
Definition: Assembler.hh:48
DataObject::boolValue
virtual bool boolValue() const
Definition: DataObject.cc:470
HDB::FUEntry::implementation
FUImplementation & implementation() const
Definition: FUEntry.cc:86
HDB::HDBManager::removeFUArchitecture
virtual void removeFUArchitecture(RowID archID) const
Definition: HDBManager.cc:941
HDB::HWBlockImplementation::glockPort
std::string glockPort() const
Definition: HWBlockImplementation.cc:219
HDBManager.hh
COST_PLUGIN_TYPE_FU
const std::string COST_PLUGIN_TYPE_FU
Possible cost function plugin types.
Definition: HDBManager.cc:96
HDB::OperationImplementation::vhdlGlobalSignals
std::vector< Variable > vhdlGlobalSignals
Definition: OperationImplementation.hh:61
HDB::FUPortImplementation::guardPort
std::string guardPort() const
Definition: FUPortImplementation.cc:115
FileSystem::fileIsReadable
static bool fileIsReadable(const std::string fileName)
HDB::HDBManager::containsFUArchitecture
bool containsFUArchitecture(RowID id) const
Definition: HDBManager.cc:4212
VHDL_SIM_FORMAT
const string VHDL_SIM_FORMAT
Definition: HDBManager.cc:90
HDB::HDBManager::fuArchitectureID
RowID fuArchitectureID(RowID fuEntryID) const
Definition: HDBManager.cc:4268
debugLog
#define debugLog(text)
Definition: Application.hh:95
TTAMachine::ExecutionPipeline::latency
int latency() const
Definition: ExecutionPipeline.cc:482
HDB::HDBManager::fuImplementationDataPortsByIDQuery
static std::string fuImplementationDataPortsByIDQuery(RowID id)
Definition: HDBManager.cc:6016
HDB::HDBManager::fuByEntryID
FUEntry * fuByEntryID(RowID id) const
Definition: HDBManager.cc:2828
SQLite.hh
HDB::HDBManager::blockSourceFile
std::list< std::string > blockSourceFile()
Definition: HDBManager.cc:7138
HDB::ExternalPort::direction
Direction direction() const
Definition: ExternalPort.cc:106
HDB::HDBManager::fileFormat
static BlockImplementationFile::Format fileFormat(const std::string &formatString)
Definition: HDBManager.cc:5714
SQLite
Definition: SQLite.hh:45
HDB::HDBManager::modifyCostFunctionPlugin
virtual void modifyCostFunctionPlugin(RowID id, const CostFunctionPlugin &plugin)
Definition: HDBManager.cc:7080
HDB::RFArchitecture::setSize
void setSize(int size)
Definition: RFArchitecture.cc:310
HDB::FUImplementation::architecturePort
FUPortImplementation & architecturePort(int index) const
Definition: FUImplementation.cc:351
HDB::CostFunctionPlugin::name
std::string name() const
Definition: CostFunctionPlugin.cc:84
HDB::ExternalPort::widthFormula
std::string widthFormula() const
Definition: ExternalPort.cc:128
HDB::HDBManager::ioUsageDataByIDQuery
static std::string ioUsageDataByIDQuery(RowID id)
Definition: HDBManager.cc:5908
CQ_COST_FUNCTION_PLUGIN
const string CQ_COST_FUNCTION_PLUGIN
Definition: HDBManager.cc:312
HDB::OUT
@ OUT
Output port.
Definition: HDBTypes.hh:42
HDB::RFEntry::hasArchitecture
virtual bool hasArchitecture() const
Definition: RFEntry.cc:117
HDB::HDBManager::removeRFArchitecture
virtual void removeRFArchitecture(RowID archID) const
Definition: HDBManager.cc:1535
HDB::CostFunctionPlugin
Definition: CostFunctionPlugin.hh:43
HDB::HDBManager::unsetArchitectureForFU
void unsetArchitectureForFU(RowID fuID) const
Definition: HDBManager.cc:1432
HDB::HDBEntry::setHDBFile
void setHDBFile(const std::string &file)
Definition: HDBEntry.cc:152
HDB::HDBManager::rfImplementationByIDQuery
static std::string rfImplementationByIDQuery(RowID id)
Definition: HDBManager.cc:6219
HDB::HDBManager::addDataPortsToImplementation
void addDataPortsToImplementation(FUImplementation &implementation, FUArchitecture &architecture, RowID entryID) const
Definition: HDBManager.cc:5006
HDB::FUImplementation::externalPortCount
int externalPortCount() const
Definition: FUImplementation.cc:337
RFExternalPort.hh
HDB::ExternalPort::parameterDependencyCount
int parameterDependencyCount() const
Definition: ExternalPort.cc:189
HDB::OperationImplementation
Definition: OperationImplementation.hh:47
HDB::HDBManager::isMatchingArchitecture
static bool isMatchingArchitecture(const TTAMachine::FunctionUnit &fu, const FUArchitecture &arch)
Definition: HDBManager.cc:5519
HDB::OperationImplementationResource::synFormats
std::vector< std::string > synFormats
Definition: OperationImplementationResource.hh:43
TTAMachine::BaseFUPort::width
virtual int width() const
Definition: BaseFUPort.cc:109
HDB::RFArchitecture::writePortCount
int writePortCount() const
Definition: RFArchitecture.cc:397
TTAMachine::ExecutionPipeline::isResourceUsed
bool isResourceUsed(const std::string &name, int cycle) const
Definition: ExecutionPipeline.cc:300
HDB::OperationImplementation::implFileVhdl
std::string implFileVhdl
Definition: OperationImplementation.hh:51
CQ_BLOCK_SOURCE_FILE
const string CQ_BLOCK_SOURCE_FILE
Definition: HDBManager.cc:281
HDB::HDBManager::setCostFunctionPluginForRF
void setCostFunctionPluginForRF(RowID rfID, RowID pluginID) const
Definition: HDBManager.cc:1993
HDB::HDBManager::areCompatiblePipelines
static bool areCompatiblePipelines(const PipelineElementUsageTable &table)
Definition: HDBManager.cc:5634
FunctionUnit.hh
HDB::BlockImplementationFile::VHDLsim
@ VHDLsim
VHDL simulation file.
Definition: BlockImplementationFile.hh:50
HDB::HDBManager::rfByEntryID
RFEntry * rfByEntryID(RowID id) const
Definition: HDBManager.cc:2885
MachineValidatorResults::error
Error error(int index) const
Definition: MachineValidatorResults.cc:70
HDB::FUPortImplementation::widthFormula
std::string widthFormula() const
Definition: FUPortImplementation.cc:137
HDB::HDBManager::createImplementationOfRF
virtual RFImplementation * createImplementationOfRF(RowID id) const
Definition: HDBManager.cc:4837
CQ_FU_PORT_MAP_ARCH_INDEX
const string CQ_FU_PORT_MAP_ARCH_INDEX
Definition: HDBManager.cc:331
HDB::HDBManager::setArchitectureForFU
void setArchitectureForFU(RowID fuID, RowID archID) const
Definition: HDBManager.cc:1401
HDB::HDBManager::fuArchitectureByIDQuery
static std::string fuArchitectureByIDQuery(RowID id)
Definition: HDBManager.cc:5857