Skip to content

Commit

Permalink
adds get function for instance metadata (#1002)
Browse files Browse the repository at this point in the history
* adds get function for instance metadata

* Update src/coreir-c/coreir-c.cpp

Co-authored-by: rsetaluri <[email protected]>
  • Loading branch information
rdaly525 and rsetaluri authored Apr 8, 2021
1 parent 4020734 commit c70b115
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 0 deletions.
1 change: 1 addition & 0 deletions include/coreir-c/coreir.h
Original file line number Diff line number Diff line change
Expand Up @@ -216,6 +216,7 @@ extern void COREModuleAddMetaDataStr(

// This returns a malloc'd string that should be freed by the user
extern const char* COREModuleGetMetaData(COREModule* module);
extern const char* COREInstanceGetMetaData(COREWireable* module);

// BEGIN : directedview
extern const char** COREDirectedConnectionGetSrc(
Expand Down
11 changes: 11 additions & 0 deletions src/coreir-c/coreir-c.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -455,6 +455,17 @@ const char* COREModuleGetMetaData(COREModule* core_mod) {
return cstr;
}

const char* COREInstanceGetMetaData(COREWireable* core_inst) {
auto w = rcast<Wireable*>(core_inst);
ASSERT(isa<Instance>(w), "Wireable needs to be an instnace");
Instance* inst = cast<Instance>(w);
std::string metadata = inst->getMetaData().dump();
auto copy = static_cast<char*>(
w->getContext()->getScratchMemory(metadata.size() + 1));
strcpy(copy, metadata.c_str());
return copy;
}

const char* COREModuleGetName(COREModule* module) {
return rcast<Module*>(module)->getName().c_str();
}
Expand Down

0 comments on commit c70b115

Please sign in to comment.