Xplace_for_ICCAD/cpp_to_py/common/db/Database.h

226 lines
7.1 KiB
C
Raw Normal View History

2022-10-20 22:46:17 +08:00
#pragma once
#include "DatabaseClass.h"
2022-10-20 22:46:17 +08:00
#include "Setting.h"
2025-05-02 14:18:01 +08:00
#include "common/lib/Helper.h"
2025-05-02 13:21:19 +08:00
std::string validate_token(std::string& name);
2022-10-20 22:46:17 +08:00
namespace db {
#define CLEAR_POINTER_LIST(list) \
{ \
for (auto obj : list) { \
delete obj; \
} \
list.clear(); \
}
#define CLEAR_POINTER_MAP(map) \
{ \
for (auto p : map) { \
delete p.second; \
} \
map.clear(); \
}
class Database {
public:
enum IssueType {
E_ROW_EXCEED_DIE,
E_OVERLAP_ROWS,
W_NON_UNIFORM_SITE_WIDTH,
W_NON_HORIZONTAL_ROW,
E_MULTIPLE_NET_DRIVING_PIN,
E_NO_NET_DRIVING_PIN
};
2023-04-06 13:34:26 +08:00
robin_hood::unordered_map<string, CellType*> name_celltypes;
robin_hood::unordered_map<string, Cell*> name_cells;
robin_hood::unordered_map<string, Net*> name_nets;
robin_hood::unordered_map<string, IOPin*> name_iopins;
robin_hood::unordered_map<string, ViaType*> name_viatypes;
2025-05-02 13:21:19 +08:00
robin_hood::unordered_map<string, Layer*> name_layers;
2025-05-02 14:18:01 +08:00
bool lef_read = false;
bool def_read = false;
bool liberty_read = false;
2025-05-02 13:21:19 +08:00
bool verilog_read = false;
string module_name = "";
VerilogParser* verilog_parser = nullptr;
2022-10-20 22:46:17 +08:00
2025-05-02 14:18:01 +08:00
array<std::shared_ptr<gt::CellLib>, 2> cell_libs_;
2022-10-20 22:46:17 +08:00
vector<Layer> layers;
vector<Site*> lefsites;
2022-10-20 22:46:17 +08:00
vector<ViaType*> viatypes;
vector<CellType*> celltypes;
vector<Cell*> cells;
vector<IOPin*> iopins;
vector<Net*> nets;
vector<Row*> rows;
vector<Region*> regions;
std::map<string, NDR*> ndrs;
2022-10-20 22:46:17 +08:00
vector<SNet*> snets;
vector<Track*> tracks;
vector<Geometry> routeBlockages;
vector<Rectangle> placeBlockages;
PowerNet* powerNet = nullptr;
2022-10-20 22:46:17 +08:00
private:
static const size_t _bufferCapacity = 128 * 1024;
size_t _bufferSize = 0;
char* _buffer = nullptr;
public:
unsigned siteW = 0;
int siteH = 0;
unsigned nSitesX = 0;
unsigned nSitesY = 0;
SiteMap* siteMap = nullptr;
GCellGrid* gcellgrid = nullptr;
2022-10-20 22:46:17 +08:00
BsRouteInfo* bsRouteInfo = nullptr;
EdgeTypes* edgetypes = nullptr;
2022-10-20 22:46:17 +08:00
int dieLX, dieLY, dieHX, dieHY;
int coreLX, coreLY, coreHX, coreHY;
double maxDensity = 0;
double maxDisp = 0;
int LefConvertFactor;
double DBU_Micron;
double version;
string designName;
vector<IssueType> dbIssues;
public:
Database();
~Database();
void clear();
void clearTechnology();
void clearLibrary();
2022-10-20 22:46:17 +08:00
void clearDesign();
Layer& addLayer(const string& name, const char type = 'x');
Site* addSite(const string& name, const string& siteClassName, const int w, const int h);
2022-10-20 22:46:17 +08:00
ViaType* addViaType(const string& name, bool isDef);
ViaType* addViaType(const string& name) { return addViaType(name, false); }
2022-10-20 22:46:17 +08:00
CellType* addCellType(const string& name, unsigned libcell);
void reserveCells(const size_t n) { cells.reserve(n); }
Cell* addCell(const string& name, CellType* type = nullptr);
IOPin* addIOPin(const string& name = "", const string& netName = "", const char direction = 'x');
void reserveNets(const size_t n) { nets.reserve(n); }
Net* addNet(const string& name = "", const NDR* ndr = nullptr);
Row* addRow(const string& name,
const string& macro,
const int x,
const int y,
const unsigned xNum = 0,
const unsigned yNum = 0,
const int orient = 0,
2022-10-20 22:46:17 +08:00
const bool flip = false,
const unsigned xStep = 0,
const unsigned yStep = 0);
Track* addTrack(char direction, double start, double num, double step);
Region* addRegion(const string& name = "", const char type = 'x');
NDR* addNDR(const string& name, const bool hardSpacing);
void reserveSNets(const size_t n) { snets.reserve(n); }
SNet* addSNet(const string& name);
Layer* getRLayer(const int index);
const Layer* getCLayer(const unsigned index) const;
Layer* getLayer(const string& name);
CellType* getCellType(const string& name);
Cell* getCell(const string& name);
Net* getNet(const string& name);
Region* getRegion(const string& name);
Region* getRegion(const unsigned char id);
NDR* getNDR(const string& name) const;
IOPin* getIOPin(const string& name) const;
ViaType* getViaType(const string& name) const;
SNet* getSNet(const string& name);
unsigned getNumRLayers() const;
unsigned getNumCLayers() const;
unsigned getNumLayers() const;
unsigned getNumCells() const { return cells.size(); }
unsigned getNumNets() const { return nets.size(); }
unsigned getNumRegions() const { return regions.size(); }
unsigned getNumIOPins() const { return iopins.size(); }
unsigned getNumCellTypes() const { return celltypes.size(); }
int getCellTypeSpace(const CellType* L, const CellType* R) const;
int getCellTypeSpace(const Cell* L, const Cell* R) const;
2022-10-20 22:46:17 +08:00
int getContainedSites(
const int lx, const int ly, const int hx, const int hy, int& slx, int& sly, int& shx, int& shy) const;
int getOverlappedSites(
const int lx, const int ly, const int hx, const int hy, int& slx, int& sly, int& shx, int& shy) const;
long long getHPWL();
long long getCellArea(Region* region = nullptr) const;
long long getFreeArea(Region* region = nullptr) const;
bool placed();
bool globalRouted();
bool detailedRouted();
void errorCheck(bool autoFix = true);
void checkPlaceError();
void checkDRCError();
void load();
void setup(); // call after read
void reset();
void save(const std::string& given_prefix);
/* defined in io/file_lefdef_db.cpp */
public:
bool readLEF(const std::string& file);
bool readDEF(const std::string& file);
bool readDEFPG(const string& file);
bool writeDEF(const std::string& file);
bool writeICCAD2017(const string& inputDef, const string& outputDef);
bool writeICCAD2017(const string& outputDef);
bool writeComponents(std::ofstream& ofs);
2025-05-02 13:21:19 +08:00
bool writeNets(std::ofstream& ofs);
bool writeBuffer(std::ofstream& ofs, const string& line);
void writeBufferFlush(std::ofstream& ofs);
2022-10-20 22:46:17 +08:00
bool readBSAux(const std::string& auxFile, const std::string& plFile);
bool readBSNodes(const std::string& file);
bool readBSNets(const std::string& file);
bool readBSScl(const std::string& file);
bool readBSRoute(const std::string& file);
bool readBSShapes(const std::string& file);
bool readBSWts(const std::string& file);
bool readBSPl(const std::string& file);
bool writeBSPl(const std::string& file);
bool readVerilog(const std::string& file);
2025-05-02 13:21:19 +08:00
bool readVerilog_yy(const std::string &file);
2022-10-20 22:46:17 +08:00
bool readLiberty(const std::string& file);
2025-05-02 13:21:19 +08:00
bool write_verilog(const std::string& file);
2022-10-20 22:46:17 +08:00
bool readConstraints(const std::string& file);
bool readSize(const std::string& file);
private:
void SetupLayers();
void SetupCellLibrary();
void SetupFloorplan();
void SetupRegions();
void SetupSiteMap();
void SetupRows();
void SetupRowSegments();
};
} // namespace db