OID: Use new TypeGraph CodeGen when requested

This adds a new feature flag, "type-graph", which controls whether to
use legacy OICodeGen or the new TypeGraph-based CodeGen.
This commit is contained in:
Alastair Robertson 2023-05-24 03:04:06 -07:00 committed by Alastair Robertson
parent e01b3fd327
commit 27c6ee10c3
2 changed files with 16 additions and 4 deletions

View File

@ -24,6 +24,7 @@
X(PackStructs, "pack-structs") \
X(GenPaddingStats, "gen-padding-stats") \
X(CaptureThriftIsset, "capture-thrift-isset") \
X(TypeGraph, "type-graph") \
X(PolymorphicInheritance, "polymorphic-inheritance")
namespace ObjectIntrospection {

View File

@ -44,6 +44,7 @@ extern "C" {
#include <glog/logging.h>
#include "oi/CodeGen.h"
#include "oi/ContainerInfo.h"
#include "oi/Headers.h"
#include "oi/Metrics.h"
@ -51,6 +52,7 @@ extern "C" {
#include "oi/OIUtils.h"
#include "oi/PaddingHunter.h"
#include "oi/Syscall.h"
#include "oi/type_graph/TypeGraph.h"
#ifndef OSS_ENABLE
#include "cea/object-introspection/internal/GobsService.h"
@ -2918,15 +2920,24 @@ std::optional<std::string> OIDebugger::generateCode(const irequest& req) {
return std::nullopt;
}
if (auto sourcePath = cache.getPath(req, OICache::Entity::Source)) {
std::ofstream(*sourcePath) << code;
}
typeInfos.emplace(
req,
std::make_tuple(RootInfo{rootInfo.varName, codegen->getRootType()},
codegen->getTypeHierarchy(), codegen->getPaddingInfo()));
if (generatorConfig.features[Feature::TypeGraph]) {
type_graph::TypeGraph typeGraph;
CodeGen codegen2(typeGraph, generatorConfig, *symbols);
codegen2.loadConfig(generatorConfig.containerConfigPaths);
if (!codegen2.generate(root->type.type, code)) {
return nullopt;
}
}
if (auto sourcePath = cache.getPath(req, OICache::Entity::Source)) {
std::ofstream(*sourcePath) << code;
}
if (!customCodeFile.empty()) {
auto ifs = std::ifstream(customCodeFile);
code.assign(std::istreambuf_iterator<char>(ifs),