Skip to content

Commit

Permalink
container regex matching
Browse files Browse the repository at this point in the history
  • Loading branch information
JakeHillion committed Dec 21, 2022
1 parent abec0dc commit 2dc5479
Show file tree
Hide file tree
Showing 7 changed files with 17 additions and 12 deletions.
9 changes: 9 additions & 0 deletions src/ContainerInfo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,14 @@ std::unique_ptr<ContainerInfo> ContainerInfo::loadFromFile(
return nullptr;
}

std::regex matcher;
if (std::optional<std::string> str =
(*info)["matcher"].value<std::string>()) {
matcher = std::regex(*str, std::regex_constants::grep);
} else {
matcher = std::regex("^" + typeName, std::regex_constants::grep);
}

std::optional<size_t> numTemplateParams =
(*info)["numTemplateParams"].value<size_t>();

Expand Down Expand Up @@ -122,6 +130,7 @@ std::unique_ptr<ContainerInfo> ContainerInfo::loadFromFile(

return std::unique_ptr<ContainerInfo>(new ContainerInfo{
std::move(typeName),
std::move(matcher),
numTemplateParams,
ctype,
std::move(header),
Expand Down
2 changes: 2 additions & 0 deletions src/ContainerInfo.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
#pragma once
#include <filesystem>
#include <optional>
#include <regex>
#include <string>
#include <vector>

Expand Down Expand Up @@ -73,6 +74,7 @@ const char *containerTypeEnumToStr(ContainerTypeEnum ty);

struct ContainerInfo {
std::string typeName;
std::regex matcher;
std::optional<size_t> numTemplateParams;
ContainerTypeEnum ctype = UNKNOWN_TYPE;
std::string header;
Expand Down
13 changes: 2 additions & 11 deletions src/OICodeGen.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -166,20 +166,11 @@ std::optional<ContainerInfo> OICodeGen::getContainerInfo(
return std::nullopt;
}

std::string nameStr = std::string(*name);
for (auto it = containerInfoList.rbegin(); it != containerInfoList.rend();
it++) {
const auto &info = *it;
if (name->starts_with(info->typeName)) {
// Blob must match exactly. Otherwise it also matches BlobsMap
if (info->ctype == CAFFE2_BLOB_TYPE && *name != "caffe2::Blob") {
return std::nullopt;
}

// IOBuf must also match exactly, or it also matches IOBufQueue
if (info->ctype == FOLLY_IOBUF_TYPE && *name != "folly::IOBuf") {
continue;
}

if (std::regex_search(nameStr, info->matcher)) {
return *info;
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/Serialize.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
BOOST_CLASS_VERSION(Type, version)

DEFINE_TYPE_VERSION(PaddingInfo, 120, 3)
DEFINE_TYPE_VERSION(ContainerInfo, 168, 4)
DEFINE_TYPE_VERSION(ContainerInfo, 200, 5)
DEFINE_TYPE_VERSION(struct drgn_location_description, 32, 2)
DEFINE_TYPE_VERSION(struct drgn_object_locator, 72, 2)
DEFINE_TYPE_VERSION(FuncDesc::Arg, 128, 2)
Expand Down
1 change: 1 addition & 0 deletions types/caffe2_blob_type.toml
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
[info]
typeName = "caffe2::Blob"
matcher = "^caffe2::Blob$"
numTemplateParams = 0
ctype = "CAFFE2_BLOB_TYPE"
header = "caffe2/core/blob.h"
Expand Down
1 change: 1 addition & 0 deletions types/folly_iobuf_queue_type.toml
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
[info]
typeName = "folly::IOBufQueue"
matcher = "^folly::IOBufQueue$"
numTemplateParams = 0
ctype = "FOLLY_IOBUFQUEUE_TYPE"
header = "folly/io/IOBufQueue.h"
Expand Down
1 change: 1 addition & 0 deletions types/folly_iobuf_type.toml
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
[info]
typeName = "folly::IOBuf"
matcher = "^folly::IOBuf$"
numTemplateParams = 0
ctype = "FOLLY_IOBUF_TYPE"
header = "folly/io/IOBuf.h"
Expand Down

0 comments on commit 2dc5479

Please sign in to comment.