Skip to content

Commit

Permalink
odb: for dft, implementing dbScanPin as std::variant
Browse files Browse the repository at this point in the history
Signed-off-by: Felipe Garay <[email protected]>
  • Loading branch information
fgaray committed Dec 9, 2023
1 parent dcc6099 commit a75d2c2
Show file tree
Hide file tree
Showing 4 changed files with 116 additions and 4 deletions.
6 changes: 6 additions & 0 deletions src/odb/include/odb/db.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
#include <map>
#include <set>
#include <string>
#include <variant>
#include <vector>

#include "dbMatrix.h"
Expand Down Expand Up @@ -7649,6 +7650,11 @@ class dbScanPartition : public dbObject
class dbScanPin : public dbObject
{
public:
// User Code Begin dbScanPin
std::variant<dbBTerm*, dbITerm*> getPin() const;
void setPin(dbBTerm* bterm);
void setPin(dbITerm* iterm);
// User Code End dbScanPin
};

class dbTechLayer : public dbObject
Expand Down
5 changes: 5 additions & 0 deletions src/odb/src/codeGenerator/schema/scan/dbScanPin.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,10 @@
"name": "dbScanPin",
"type": "dbObject",
"fields": [
],
"h_includes": [
"dbBTerm.h",
"dbITerm.h",
"dbBlock.h"
]
}
93 changes: 89 additions & 4 deletions src/odb/src/db/dbScanPin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,11 +44,24 @@ template class dbTable<_dbScanPin>;

bool _dbScanPin::operator==(const _dbScanPin& rhs) const
{
// User Code Begin ==
if (pin_ != rhs.pin_) {
return false;
}
// User Code End ==
return true;
}

bool _dbScanPin::operator<(const _dbScanPin& rhs) const
{
// User Code Begin <
return std::visit(
[rhs](auto&& pin) {
return std::visit([&pin](auto&& rhs_pin) { return pin < rhs_pin; },
rhs.pin_);
},
pin_);
// User Code End <
return true;
}

Expand All @@ -57,29 +70,68 @@ void _dbScanPin::differences(dbDiff& diff,
const _dbScanPin& rhs) const
{
DIFF_BEGIN
// User Code Begin Differences
std::visit(
[&diff, rhs](auto&& pin) {
std::visit(
[&diff, &pin](auto&& rhs_pin) { diff.diff("pin_", pin, rhs_pin); },
rhs.pin_);
},
pin_);
// User Code End Differences
DIFF_END
}

void _dbScanPin::out(dbDiff& diff, char side, const char* field) const {
DIFF_OUT_BEGIN
void _dbScanPin::out(dbDiff& diff, char side, const char* field) const
{
DIFF_OUT_BEGIN

DIFF_END}
// User Code Begin Out
std::visit([&diff, side](auto&& ptr) { diff.out(side, "pin_", ptr); }, pin_);
// User Code End Out
DIFF_END
}

_dbScanPin::_dbScanPin(_dbDatabase* db)
{
}

_dbScanPin::_dbScanPin(_dbDatabase* db, const _dbScanPin& r)
{
// User Code Begin CopyConstructor
pin_ = r.pin_;
// User Code End CopyConstructor
}

dbIStream& operator>>(dbIStream& stream, _dbScanPin& obj)
{
// User Code Begin >>
int index = 0;
stream >> index;
if (index == 0) {
dbId<_dbBTerm> bterm;
stream >> bterm;
obj.pin_ = bterm;
} else if (index == 1) {
dbId<_dbITerm> iterm;
stream >> iterm;
obj.pin_ = iterm;
}
// User Code End >>
return stream;
}

dbOStream& operator<<(dbOStream& stream, const _dbScanPin& obj)
{
// User Code Begin <<
int index = obj.pin_.index();
stream << index;
if (index == 0) {
stream << std::get<0>(obj.pin_);
} else if (index == 1) {
stream << std::get<1>(obj.pin_);
}
// User Code End <<
return stream;
}

Expand All @@ -89,5 +141,38 @@ dbOStream& operator<<(dbOStream& stream, const _dbScanPin& obj)
//
////////////////////////////////////////////////////////////////////

// User Code Begin dbScanPinPublicMethods
std::variant<dbBTerm*, dbITerm*> dbScanPin::getPin() const
{
const _dbScanPin* scan_pin = (_dbScanPin*) this;
const _dbBlock* block = (_dbBlock*) scan_pin->getOwner();

return std::visit(
[block](auto&& pin) {
using T = std::decay_t<decltype(pin)>;
if constexpr (std::is_same_v<T, dbId<_dbBTerm>>) {
return (dbBTerm*) block->_bterm_tbl->getPtr(pin);
} else if constexpr (std::is_same_v<T, dbId<_dbITerm>>) {
return (dbBTerm*) block->_iterm_tbl->getPtr(pin);
} else {
static_assert(always_false_v<T>, "non-exhaustive visitor!");
}
},
scan_pin->pin_);
}

void dbScanPin::setPin(dbBTerm* bterm)
{
_dbScanPin* scan_pin = (_dbScanPin*) this;
scan_pin->pin_.emplace<dbId<_dbBTerm>>(((_dbBTerm*) this)->getId());
}

void dbScanPin::setPin(dbITerm* iterm)
{
_dbScanPin* scan_pin = (_dbScanPin*) this;
scan_pin->pin_.emplace<dbId<_dbITerm>>(((_dbITerm*) this)->getId());
}

// User Code End dbScanPinPublicMethods
} // namespace odb
// Generator Code End Cpp
// Generator Code End Cpp
16 changes: 16 additions & 0 deletions src/odb/src/db/dbScanPin.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,14 +33,26 @@
// Generator Code Begin Header
#pragma once

#include "dbBTerm.h"
#include "dbBlock.h"
#include "dbCore.h"
#include "dbITerm.h"
#include "odb.h"
// User Code Begin Includes
#include <variant>
// User Code End Includes

namespace odb {
class dbIStream;
class dbOStream;
class dbDiff;
class _dbDatabase;
// User Code Begin Classes
namespace {
template <class>
inline constexpr bool always_false_v = false;
} // namespace
// User Code End Classes

class _dbScanPin : public _dbObject
{
Expand All @@ -57,6 +69,10 @@ class _dbScanPin : public _dbObject
const char* field,
const _dbScanPin& rhs) const;
void out(dbDiff& diff, char side, const char* field) const;

// User Code Begin Fields
std::variant<dbId<_dbBTerm>, dbId<_dbITerm>> pin_;
// User Code End Fields
};
dbIStream& operator>>(dbIStream& stream, _dbScanPin& obj);
dbOStream& operator<<(dbOStream& stream, const _dbScanPin& obj);
Expand Down

0 comments on commit a75d2c2

Please sign in to comment.