Merge "Support loading VNDK ABI dump in JSON format"

am: 868cdf5cb2

Change-Id: Ifa88bd74b3500bab01386be447dd3decf4a97621
This commit is contained in:
Hsin-Yi Chen
2018-09-20 22:42:36 -07:00
committed by android-build-merger
5 changed files with 613 additions and 22 deletions

View File

@@ -84,6 +84,15 @@ enum LinkableMessageKind {
GlobalVarKind GlobalVarKind
}; };
template <typename K, typename V>
std::map<V, K> CreateInverseMap(const std::map<K, V> &m) {
std::map<V, K> inverse_map;
for (auto it : m) {
inverse_map[it.second] = it.first;
}
return inverse_map;
}
class LinkableMessageIR { class LinkableMessageIR {
public: public:
const std::string &GetLinkerSetKey() const { const std::string &GetLinkerSetKey() const {
@@ -1066,6 +1075,9 @@ class TextFormatToIRReader {
std::make_move_iterator(addend.end())); std::make_move_iterator(addend.end()));
} }
bool IsLinkableMessageInExportedHeaders(
const LinkableMessageIR *linkable_message) const;
AbiElementList<RecordTypeIR> record_types_list_; AbiElementList<RecordTypeIR> record_types_list_;
AbiElementMap<FunctionIR> functions_; AbiElementMap<FunctionIR> functions_;
AbiElementMap<GlobalVarIR> global_variables_; AbiElementMap<GlobalVarIR> global_variables_;

View File

@@ -103,6 +103,157 @@ class JsonIRDumper : public IRDumper, public IRToJsonConverter {
JsonObject translation_unit_; JsonObject translation_unit_;
}; };
template <typename T> class JsonArrayRef;
// This class loads values from a read-only JSON object.
class JsonObjectRef {
public:
// The constructor sets ok to false if json_value is not an object.
JsonObjectRef(const Json::Value &json_value, bool &ok);
// This method gets a value from the object and checks the type.
// If the type mismatches, it sets ok_ to false and returns default value.
// If the key doesn't exist, it doesn't change ok_ and returns default value.
// Default to false.
bool GetBool(const std::string &key) const;
// Default to 0.
int64_t GetInt(const std::string &key) const;
// Default to 0.
uint64_t GetUint(const std::string &key) const;
// Default to "".
std::string GetString(const std::string &key) const;
// Default to {}.
JsonObjectRef GetObject(const std::string &key) const;
// Default to [].
JsonArrayRef<JsonObjectRef> GetObjects(const std::string &key) const;
JsonArrayRef<std::string> GetStrings(const std::string &key) const;
private:
typedef bool (Json::Value::*IsExpectedJsonType)() const;
const Json::Value &Get(const std::string &key,
const Json::Value &default_value,
IsExpectedJsonType is_expected_type) const;
const Json::Value &object_;
bool &ok_;
};
// This class loads elements as type T from a read-only JSON array.
template <typename T> class JsonArrayRef {
public:
class Iterator {
public:
Iterator(const Json::Value &json_value, bool &ok, int index)
: array_(json_value), ok_(ok), index_(index) {}
Iterator &operator++() {
++index_;
return *this;
}
bool operator!=(const Iterator &other) const {
return index_ != other.index_;
}
T operator*() const;
private:
const Json::Value &array_;
bool &ok_;
int index_;
};
// The caller ensures json_value.isArray() == true.
JsonArrayRef(const Json::Value &json_value, bool &ok)
: array_(json_value), ok_(ok) {}
Iterator begin() const { return Iterator(array_, ok_, 0); }
Iterator end() const { return Iterator(array_, ok_, array_.size()); }
private:
const Json::Value &array_;
bool &ok_;
};
template <>
JsonObjectRef JsonArrayRef<JsonObjectRef>::Iterator::operator*() const;
template <> std::string JsonArrayRef<std::string>::Iterator::operator*() const;
class JsonToIRReader : public TextFormatToIRReader {
public:
JsonToIRReader(const std::set<std::string> *exported_headers)
: TextFormatToIRReader(exported_headers) {}
bool ReadDump(const std::string &dump_file) override;
private:
void ReadFunctions(const JsonObjectRef &tu);
void ReadGlobalVariables(const JsonObjectRef &tu);
void ReadEnumTypes(const JsonObjectRef &tu);
void ReadRecordTypes(const JsonObjectRef &tu);
void ReadFunctionTypes(const JsonObjectRef &tu);
void ReadPointerTypes(const JsonObjectRef &tu);
void ReadBuiltinTypes(const JsonObjectRef &tu);
void ReadQualifiedTypes(const JsonObjectRef &tu);
void ReadArrayTypes(const JsonObjectRef &tu);
void ReadLvalueReferenceTypes(const JsonObjectRef &tu);
void ReadRvalueReferenceTypes(const JsonObjectRef &tu);
void ReadElfFunctions(const JsonObjectRef &tu);
void ReadElfObjects(const JsonObjectRef &tu);
static void ReadTemplateInfo(const JsonObjectRef &type_decl,
TemplatedArtifactIR *template_ir);
static void ReadTypeInfo(const JsonObjectRef &type_decl, TypeIR *type_ir);
static void ReadRecordFields(const JsonObjectRef &record_type,
RecordTypeIR *record_ir);
static void ReadBaseSpecifiers(const JsonObjectRef &record_type,
RecordTypeIR *record_ir);
static void ReadVTableLayout(const JsonObjectRef &record_type,
RecordTypeIR *record_ir);
static void ReadTagTypeInfo(const JsonObjectRef &type_decl,
TagTypeIR *tag_type_ir);
static void ReadEnumFields(const JsonObjectRef &enum_type,
EnumTypeIR *enum_ir);
static void ReadFunctionParametersAndReturnType(const JsonObjectRef &function,
CFunctionLikeIR *function_ir);
static FunctionIR FunctionJsonToIR(const JsonObjectRef &function);
static FunctionTypeIR
FunctionTypeJsonToIR(const JsonObjectRef &function_type);
static RecordTypeIR RecordTypeJsonToIR(const JsonObjectRef &record_type);
static EnumTypeIR EnumTypeJsonToIR(const JsonObjectRef &enum_type);
};
} // namespace abi_util } // namespace abi_util
#endif // IR_JSON_ #endif // IR_JSON_

View File

@@ -575,5 +575,14 @@ void TextFormatToIRReader::MergeGraphs(const TextFormatToIRReader &addend) {
MergeGlobalVariable(&global_var_ir.second, addend, &merged_types_cache); MergeGlobalVariable(&global_var_ir.second, addend, &merged_types_cache);
} }
} }
bool TextFormatToIRReader::IsLinkableMessageInExportedHeaders(
const LinkableMessageIR *linkable_message) const {
if (exported_headers_ == nullptr || exported_headers_->empty()) {
return true;
}
return exported_headers_->find(linkable_message->GetSourceFile()) !=
exported_headers_->end();
}
} // namespace abi_util } // namespace abi_util

View File

@@ -14,6 +14,7 @@
#include <ir_representation_json.h> #include <ir_representation_json.h>
#include <json/reader.h>
#include <json/writer.h> #include <json/writer.h>
#include <llvm/Support/raw_ostream.h> #include <llvm/Support/raw_ostream.h>
@@ -31,6 +32,9 @@ static const std::map<AccessSpecifierIR, std::string> access_ir_to_json{
{AccessSpecifierIR::PrivateAccess, "private"}, {AccessSpecifierIR::PrivateAccess, "private"},
}; };
static const std::map<std::string, AccessSpecifierIR>
access_json_to_ir(CreateInverseMap(access_ir_to_json));
static const std::map<RecordTypeIR::RecordKind, std::string> static const std::map<RecordTypeIR::RecordKind, std::string>
record_kind_ir_to_json{ record_kind_ir_to_json{
{RecordTypeIR::RecordKind::struct_kind, "struct"}, {RecordTypeIR::RecordKind::struct_kind, "struct"},
@@ -38,6 +42,9 @@ static const std::map<RecordTypeIR::RecordKind, std::string>
{RecordTypeIR::RecordKind::union_kind, "union"}, {RecordTypeIR::RecordKind::union_kind, "union"},
}; };
static const std::map<std::string, RecordTypeIR::RecordKind>
record_kind_json_to_ir(CreateInverseMap(record_kind_ir_to_json));
static const std::map<VTableComponentIR::Kind, std::string> static const std::map<VTableComponentIR::Kind, std::string>
vtable_component_kind_ir_to_json{ vtable_component_kind_ir_to_json{
{VTableComponentIR::Kind::VCallOffset, "vcall_offset"}, {VTableComponentIR::Kind::VCallOffset, "vcall_offset"},
@@ -50,12 +57,20 @@ static const std::map<VTableComponentIR::Kind, std::string>
{VTableComponentIR::Kind::UnusedFunctionPointer, "unused_function_pointer"}, {VTableComponentIR::Kind::UnusedFunctionPointer, "unused_function_pointer"},
}; };
static const std::map<std::string, VTableComponentIR::Kind>
vtable_component_kind_json_to_ir(
CreateInverseMap(vtable_component_kind_ir_to_json));
static const std::map<ElfSymbolIR::ElfSymbolBinding, std::string> static const std::map<ElfSymbolIR::ElfSymbolBinding, std::string>
elf_symbol_binding_ir_to_json{ elf_symbol_binding_ir_to_json{
{ElfSymbolIR::ElfSymbolBinding::Weak, "weak"}, {ElfSymbolIR::ElfSymbolBinding::Weak, "weak"},
{ElfSymbolIR::ElfSymbolBinding::Global, "global"}, {ElfSymbolIR::ElfSymbolBinding::Global, "global"},
}; };
static const std::map<std::string, ElfSymbolIR::ElfSymbolBinding>
elf_symbol_binding_json_to_ir(
CreateInverseMap(elf_symbol_binding_ir_to_json));
// If m contains k, this function returns the value. // If m contains k, this function returns the value.
// Otherwise, it prints error_msg and exits. // Otherwise, it prints error_msg and exits.
template <typename K, typename V> template <typename K, typename V>
@@ -74,24 +89,47 @@ static inline const std::string &AccessIRToJson(AccessSpecifierIR access) {
"Failed to convert AccessSpecifierIR to JSON"); "Failed to convert AccessSpecifierIR to JSON");
} }
static inline AccessSpecifierIR AccessJsonToIR(const std::string &access) {
return FindInMap(access_json_to_ir, access,
"Failed to convert JSON to AccessSpecifierIR");
}
static inline const std::string & static inline const std::string &
RecordKindIRToJson(RecordTypeIR::RecordKind kind) { RecordKindIRToJson(RecordTypeIR::RecordKind kind) {
return FindInMap(record_kind_ir_to_json, kind, return FindInMap(record_kind_ir_to_json, kind,
"Failed to convert RecordKind to JSON"); "Failed to convert RecordKind to JSON");
} }
static inline RecordTypeIR::RecordKind
RecordKindJsonToIR(const std::string &kind) {
return FindInMap(record_kind_json_to_ir, kind,
"Failed to convert JSON to RecordKind");
}
static inline const std::string & static inline const std::string &
VTableComponentKindIRToJson(VTableComponentIR::Kind kind) { VTableComponentKindIRToJson(VTableComponentIR::Kind kind) {
return FindInMap(vtable_component_kind_ir_to_json, kind, return FindInMap(vtable_component_kind_ir_to_json, kind,
"Failed to convert VTableComponentIR::Kind to JSON"); "Failed to convert VTableComponentIR::Kind to JSON");
} }
static inline VTableComponentIR::Kind
VTableComponentKindJsonToIR(const std::string &kind) {
return FindInMap(vtable_component_kind_json_to_ir, kind,
"Failed to convert JSON to VTableComponentIR::Kind");
}
static inline const std::string & static inline const std::string &
ElfSymbolBindingIRToJson(ElfSymbolIR::ElfSymbolBinding binding) { ElfSymbolBindingIRToJson(ElfSymbolIR::ElfSymbolBinding binding) {
return FindInMap(elf_symbol_binding_ir_to_json, binding, return FindInMap(elf_symbol_binding_ir_to_json, binding,
"Failed to convert ElfSymbolBinding to JSON"); "Failed to convert ElfSymbolBinding to JSON");
} }
static inline ElfSymbolIR::ElfSymbolBinding
ElfSymbolBindingJsonToIR(const std::string &binding) {
return FindInMap(elf_symbol_binding_json_to_ir, binding,
"Failed to convert JSON to ElfSymbolBinding");
}
void IRToJsonConverter::AddTemplateInfo( void IRToJsonConverter::AddTemplateInfo(
JsonObject &type_decl, const TemplatedArtifactIR *template_ir) { JsonObject &type_decl, const TemplatedArtifactIR *template_ir) {
Json::Value &args = type_decl["template_args"]; Json::Value &args = type_decl["template_args"];
@@ -448,4 +486,397 @@ JsonIRDumper::JsonIRDumper(const std::string &dump_path)
} }
} }
static const JsonObject json_empty_object;
static const JsonArray json_empty_array;
static const Json::Value json_0(0);
static const Json::Value json_false(false);
static const Json::Value json_empty_string("");
JsonObjectRef::JsonObjectRef(const Json::Value &json_value, bool &ok)
: object_(json_value.isObject() ? json_value : json_empty_object), ok_(ok) {
if (!json_value.isObject()) {
ok_ = false;
}
}
const Json::Value &
JsonObjectRef::Get(const std::string &key, const Json::Value &default_value,
IsExpectedJsonType is_expected_type) const {
if (!object_.isMember(key)) {
return default_value;
}
const Json::Value &value = object_[key];
if (!(value.*is_expected_type)()) {
ok_ = false;
return default_value;
}
return value;
}
bool JsonObjectRef::GetBool(const std::string &key) const {
return Get(key, json_false, &Json::Value::isBool).asBool();
}
int64_t JsonObjectRef::GetInt(const std::string &key) const {
return Get(key, json_0, &Json::Value::isIntegral).asInt64();
}
uint64_t JsonObjectRef::GetUint(const std::string &key) const {
return Get(key, json_0, &Json::Value::isIntegral).asUInt64();
}
std::string JsonObjectRef::GetString(const std::string &key) const {
return Get(key, json_empty_string, &Json::Value::isString).asString();
}
JsonObjectRef JsonObjectRef::GetObject(const std::string &key) const {
return JsonObjectRef(Get(key, json_empty_object, &Json::Value::isObject),
ok_);
}
JsonArrayRef<JsonObjectRef>
JsonObjectRef::GetObjects(const std::string &key) const {
return JsonArrayRef<JsonObjectRef>(
Get(key, json_empty_array, &Json::Value::isArray), ok_);
}
JsonArrayRef<std::string>
JsonObjectRef::GetStrings(const std::string &key) const {
return JsonArrayRef<std::string>(
Get(key, json_empty_array, &Json::Value::isArray), ok_);
}
template <>
JsonObjectRef JsonArrayRef<JsonObjectRef>::Iterator::operator*() const {
return JsonObjectRef(array_[index_], ok_);
}
template <> std::string JsonArrayRef<std::string>::Iterator::operator*() const {
return array_[index_].asString();
}
bool JsonToIRReader::ReadDump(const std::string &dump_file) {
Json::Value tu_json;
Json::Reader reader;
std::ifstream input(dump_file);
if (!reader.parse(input, tu_json, /* collectComments */ false)) {
llvm::errs() << "Failed to parse JSON: "
<< reader.getFormattedErrorMessages() << "\n";
return false;
}
bool ok = true;
JsonObjectRef tu(tu_json, ok);
if (!ok) {
llvm::errs() << "Translation unit is not an object\n";
return false;
}
ReadFunctions(tu);
ReadGlobalVariables(tu);
ReadEnumTypes(tu);
ReadRecordTypes(tu);
ReadFunctionTypes(tu);
ReadArrayTypes(tu);
ReadPointerTypes(tu);
ReadQualifiedTypes(tu);
ReadBuiltinTypes(tu);
ReadLvalueReferenceTypes(tu);
ReadRvalueReferenceTypes(tu);
ReadElfFunctions(tu);
ReadElfObjects(tu);
if (!ok) {
llvm::errs() << "Failed to convert JSON to IR\n";
return false;
}
return true;
}
void JsonToIRReader::ReadTagTypeInfo(const JsonObjectRef &type_decl,
TagTypeIR *tag_type_ir) {
tag_type_ir->SetUniqueId(type_decl.GetString("unique_id"));
}
void JsonToIRReader::ReadTemplateInfo(const JsonObjectRef &type_decl,
TemplatedArtifactIR *template_ir) {
TemplateInfoIR template_info_ir;
for (auto &&referenced_type : type_decl.GetStrings("template_args")) {
TemplateElementIR template_element_ir(referenced_type);
template_info_ir.AddTemplateElement(std::move(template_element_ir));
}
template_ir->SetTemplateInfo(std::move(template_info_ir));
}
void JsonToIRReader::ReadTypeInfo(const JsonObjectRef &type_decl,
TypeIR *type_ir) {
type_ir->SetLinkerSetKey(type_decl.GetString("linker_set_key"));
type_ir->SetSourceFile(type_decl.GetString("source_file"));
type_ir->SetName(type_decl.GetString("name"));
type_ir->SetReferencedType(type_decl.GetString("referenced_type"));
type_ir->SetSelfType(type_decl.GetString("self_type"));
type_ir->SetSize(type_decl.GetUint("size"));
type_ir->SetAlignment(type_decl.GetUint("alignment"));
}
void JsonToIRReader::ReadRecordFields(const JsonObjectRef &record_type,
RecordTypeIR *record_ir) {
for (auto &&field : record_type.GetObjects("fields")) {
RecordFieldIR record_field_ir(field.GetString("field_name"),
field.GetString("referenced_type"),
field.GetUint("field_offset"),
AccessJsonToIR(field.GetString("access")));
record_ir->AddRecordField(std::move(record_field_ir));
}
}
void JsonToIRReader::ReadBaseSpecifiers(const JsonObjectRef &record_type,
RecordTypeIR *record_ir) {
for (auto &&base_specifier : record_type.GetObjects("base_specifiers")) {
CXXBaseSpecifierIR record_base_ir(
base_specifier.GetString("referenced_type"),
base_specifier.GetBool("is_virtual"),
AccessJsonToIR(base_specifier.GetString("access")));
record_ir->AddCXXBaseSpecifier(std::move(record_base_ir));
}
}
void JsonToIRReader::ReadVTableLayout(const JsonObjectRef &record_type,
RecordTypeIR *record_ir) {
VTableLayoutIR vtable_layout_ir;
for (auto &&vtable_component : record_type.GetObjects("vtable_components")) {
VTableComponentIR vtable_component_ir(
vtable_component.GetString("mangled_component_name"),
VTableComponentKindJsonToIR(vtable_component.GetString("kind")),
vtable_component.GetInt("component_value"),
vtable_component.GetBool("is_pure"));
vtable_layout_ir.AddVTableComponent(std::move(vtable_component_ir));
}
record_ir->SetVTableLayout(std::move(vtable_layout_ir));
}
void JsonToIRReader::ReadEnumFields(const JsonObjectRef &enum_type,
EnumTypeIR *enum_ir) {
for (auto &&field : enum_type.GetObjects("enum_fields")) {
EnumFieldIR enum_field_ir(field.GetString("name"),
field.GetInt("enum_field_value"));
enum_ir->AddEnumField(std::move(enum_field_ir));
}
}
void JsonToIRReader::ReadFunctionParametersAndReturnType(
const JsonObjectRef &function, CFunctionLikeIR *function_ir) {
function_ir->SetReturnType(function.GetString("return_type"));
for (auto &&parameter : function.GetObjects("parameters")) {
ParamIR param_ir(parameter.GetString("referenced_type"),
parameter.GetBool("default_arg"),
parameter.GetBool("is_this_ptr"));
function_ir->AddParameter(std::move(param_ir));
}
}
FunctionIR JsonToIRReader::FunctionJsonToIR(const JsonObjectRef &function) {
FunctionIR function_ir;
function_ir.SetLinkerSetKey(function.GetString("linker_set_key"));
function_ir.SetName(function.GetString("function_name"));
function_ir.SetAccess(AccessJsonToIR(function.GetString("access")));
function_ir.SetSourceFile(function.GetString("source_file"));
ReadFunctionParametersAndReturnType(function, &function_ir);
ReadTemplateInfo(function, &function_ir);
return function_ir;
}
FunctionTypeIR
JsonToIRReader::FunctionTypeJsonToIR(const JsonObjectRef &function_type) {
FunctionTypeIR function_type_ir;
ReadTypeInfo(function_type, &function_type_ir);
ReadFunctionParametersAndReturnType(function_type, &function_type_ir);
return function_type_ir;
}
RecordTypeIR
JsonToIRReader::RecordTypeJsonToIR(const JsonObjectRef &record_type) {
RecordTypeIR record_type_ir;
ReadTypeInfo(record_type, &record_type_ir);
ReadTemplateInfo(record_type, &record_type_ir);
record_type_ir.SetAccess(AccessJsonToIR(record_type.GetString("access")));
ReadVTableLayout(record_type, &record_type_ir);
ReadRecordFields(record_type, &record_type_ir);
ReadBaseSpecifiers(record_type, &record_type_ir);
record_type_ir.SetRecordKind(
RecordKindJsonToIR(record_type.GetString("record_kind")));
record_type_ir.SetAnonymity(record_type.GetBool("is_anonymous"));
ReadTagTypeInfo(record_type, &record_type_ir);
return record_type_ir;
}
EnumTypeIR JsonToIRReader::EnumTypeJsonToIR(const JsonObjectRef &enum_type) {
EnumTypeIR enum_type_ir;
ReadTypeInfo(enum_type, &enum_type_ir);
enum_type_ir.SetUnderlyingType(enum_type.GetString("underlying_type"));
enum_type_ir.SetAccess(AccessJsonToIR(enum_type.GetString("access")));
ReadEnumFields(enum_type, &enum_type_ir);
ReadTagTypeInfo(enum_type, &enum_type_ir);
return enum_type_ir;
}
void JsonToIRReader::ReadGlobalVariables(const JsonObjectRef &tu) {
for (auto &&global_variable : tu.GetObjects("global_vars")) {
GlobalVarIR global_variable_ir;
global_variable_ir.SetName(global_variable.GetString("name"));
global_variable_ir.SetAccess(
AccessJsonToIR(global_variable.GetString("access")));
global_variable_ir.SetSourceFile(global_variable.GetString("source_file"));
global_variable_ir.SetReferencedType(
global_variable.GetString("referenced_type"));
global_variable_ir.SetLinkerSetKey(
global_variable.GetString("linker_set_key"));
if (!IsLinkableMessageInExportedHeaders(&global_variable_ir)) {
continue;
}
global_variables_.insert(
{global_variable_ir.GetLinkerSetKey(), std::move(global_variable_ir)});
}
}
void JsonToIRReader::ReadPointerTypes(const JsonObjectRef &tu) {
for (auto &&pointer_type : tu.GetObjects("pointer_types")) {
PointerTypeIR pointer_type_ir;
ReadTypeInfo(pointer_type, &pointer_type_ir);
if (!IsLinkableMessageInExportedHeaders(&pointer_type_ir)) {
continue;
}
AddToMapAndTypeGraph(std::move(pointer_type_ir), &pointer_types_,
&type_graph_);
}
}
void JsonToIRReader::ReadBuiltinTypes(const JsonObjectRef &tu) {
for (auto &&builtin_type : tu.GetObjects("builtin_types")) {
BuiltinTypeIR builtin_type_ir;
ReadTypeInfo(builtin_type, &builtin_type_ir);
builtin_type_ir.SetSignedness(builtin_type.GetBool("is_unsigned"));
builtin_type_ir.SetIntegralType(builtin_type.GetBool("is_integral"));
AddToMapAndTypeGraph(std::move(builtin_type_ir), &builtin_types_,
&type_graph_);
}
}
void JsonToIRReader::ReadQualifiedTypes(const JsonObjectRef &tu) {
for (auto &&qualified_type : tu.GetObjects("qualified_types")) {
QualifiedTypeIR qualified_type_ir;
ReadTypeInfo(qualified_type, &qualified_type_ir);
qualified_type_ir.SetConstness(qualified_type.GetBool("is_const"));
qualified_type_ir.SetVolatility(qualified_type.GetBool("is_volatile"));
qualified_type_ir.SetRestrictedness(
qualified_type.GetBool("is_restricted"));
if (!IsLinkableMessageInExportedHeaders(&qualified_type_ir)) {
continue;
}
AddToMapAndTypeGraph(std::move(qualified_type_ir), &qualified_types_,
&type_graph_);
}
}
void JsonToIRReader::ReadArrayTypes(const JsonObjectRef &tu) {
for (auto &&array_type : tu.GetObjects("array_types")) {
ArrayTypeIR array_type_ir;
ReadTypeInfo(array_type, &array_type_ir);
if (!IsLinkableMessageInExportedHeaders(&array_type_ir)) {
continue;
}
AddToMapAndTypeGraph(std::move(array_type_ir), &array_types_, &type_graph_);
}
}
void JsonToIRReader::ReadLvalueReferenceTypes(const JsonObjectRef &tu) {
for (auto &&lvalue_reference_type : tu.GetObjects("lvalue_reference_types")) {
LvalueReferenceTypeIR lvalue_reference_type_ir;
ReadTypeInfo(lvalue_reference_type, &lvalue_reference_type_ir);
if (!IsLinkableMessageInExportedHeaders(&lvalue_reference_type_ir)) {
continue;
}
AddToMapAndTypeGraph(std::move(lvalue_reference_type_ir),
&lvalue_reference_types_, &type_graph_);
}
}
void JsonToIRReader::ReadRvalueReferenceTypes(const JsonObjectRef &tu) {
for (auto &&rvalue_reference_type : tu.GetObjects("rvalue_reference_types")) {
RvalueReferenceTypeIR rvalue_reference_type_ir;
ReadTypeInfo(rvalue_reference_type, &rvalue_reference_type_ir);
if (!IsLinkableMessageInExportedHeaders(&rvalue_reference_type_ir)) {
continue;
}
AddToMapAndTypeGraph(std::move(rvalue_reference_type_ir),
&rvalue_reference_types_, &type_graph_);
}
}
void JsonToIRReader::ReadFunctions(const JsonObjectRef &tu) {
for (auto &&function : tu.GetObjects("functions")) {
FunctionIR function_ir = FunctionJsonToIR(function);
if (!IsLinkableMessageInExportedHeaders(&function_ir)) {
continue;
}
functions_.insert({function_ir.GetLinkerSetKey(), std::move(function_ir)});
}
}
void JsonToIRReader::ReadRecordTypes(const JsonObjectRef &tu) {
for (auto &&record_type : tu.GetObjects("record_types")) {
RecordTypeIR record_type_ir = RecordTypeJsonToIR(record_type);
if (!IsLinkableMessageInExportedHeaders(&record_type_ir)) {
continue;
}
auto it = AddToMapAndTypeGraph(std::move(record_type_ir), &record_types_,
&type_graph_);
const std::string &key = GetODRListMapKey(&(it->second));
AddToODRListMap(key, &(it->second));
}
}
void JsonToIRReader::ReadFunctionTypes(const JsonObjectRef &tu) {
for (auto &&function_type : tu.GetObjects("function_types")) {
FunctionTypeIR function_type_ir = FunctionTypeJsonToIR(function_type);
if (!IsLinkableMessageInExportedHeaders(&function_type_ir)) {
continue;
}
auto it = AddToMapAndTypeGraph(std::move(function_type_ir),
&function_types_, &type_graph_);
const std::string &key = GetODRListMapKey(&(it->second));
AddToODRListMap(key, &(it->second));
}
}
void JsonToIRReader::ReadEnumTypes(const JsonObjectRef &tu) {
for (auto &&enum_type : tu.GetObjects("enum_types")) {
EnumTypeIR enum_type_ir = EnumTypeJsonToIR(enum_type);
if (!IsLinkableMessageInExportedHeaders(&enum_type_ir)) {
continue;
}
auto it = AddToMapAndTypeGraph(std::move(enum_type_ir), &enum_types_,
&type_graph_);
AddToODRListMap(it->second.GetUniqueId() + it->second.GetSourceFile(),
(&it->second));
}
}
void JsonToIRReader::ReadElfFunctions(const JsonObjectRef &tu) {
for (auto &&elf_function : tu.GetObjects("elf_functions")) {
ElfFunctionIR elf_function_ir(
elf_function.GetString("name"),
ElfSymbolBindingJsonToIR(elf_function.GetString("binding")));
elf_functions_.insert(
{elf_function_ir.GetName(), std::move(elf_function_ir)});
}
}
void JsonToIRReader::ReadElfObjects(const JsonObjectRef &tu) {
for (auto &&elf_object : tu.GetObjects("elf_objects")) {
ElfObjectIR elf_object_ir(
elf_object.GetString("name"),
ElfSymbolBindingJsonToIR(elf_object.GetString("binding")));
elf_objects_.insert({elf_object_ir.GetName(), std::move(elf_object_ir)});
}
}
} // namespace abi_util } // namespace abi_util

View File

@@ -23,16 +23,6 @@
namespace abi_util { namespace abi_util {
static bool IsPresentInExportedHeaders(
const LinkableMessageIR &linkable_message,
const std::set<std::string> *exported_headers) {
if (exported_headers == nullptr || exported_headers->empty()) {
return true;
}
return exported_headers->find(linkable_message.GetSourceFile())
!= exported_headers->end();
}
void ProtobufTextFormatToIRReader::ReadTypeInfo( void ProtobufTextFormatToIRReader::ReadTypeInfo(
const abi_dump::BasicNamedAndTypedDecl &type_info, const abi_dump::BasicNamedAndTypedDecl &type_info,
TypeIR *typep) { TypeIR *typep) {
@@ -217,7 +207,7 @@ void ProtobufTextFormatToIRReader::ReadGlobalVariables(
global_variable_protobuf.referenced_type()); global_variable_protobuf.referenced_type());
global_variable_ir.SetLinkerSetKey( global_variable_ir.SetLinkerSetKey(
global_variable_protobuf.linker_set_key()); global_variable_protobuf.linker_set_key());
if (!IsPresentInExportedHeaders(global_variable_ir, exported_headers_)) { if (!IsLinkableMessageInExportedHeaders(&global_variable_ir)) {
continue; continue;
} }
global_variables_.insert( global_variables_.insert(
@@ -230,7 +220,7 @@ void ProtobufTextFormatToIRReader::ReadPointerTypes(
for (auto &&pointer_type_protobuf : tu.pointer_types()) { for (auto &&pointer_type_protobuf : tu.pointer_types()) {
PointerTypeIR pointer_type_ir; PointerTypeIR pointer_type_ir;
ReadTypeInfo(pointer_type_protobuf.type_info(), &pointer_type_ir); ReadTypeInfo(pointer_type_protobuf.type_info(), &pointer_type_ir);
if (!IsPresentInExportedHeaders(pointer_type_ir, exported_headers_)) { if (!IsLinkableMessageInExportedHeaders(&pointer_type_ir)) {
continue; continue;
} }
AddToMapAndTypeGraph(std::move(pointer_type_ir), &pointer_types_, AddToMapAndTypeGraph(std::move(pointer_type_ir), &pointer_types_,
@@ -259,7 +249,7 @@ void ProtobufTextFormatToIRReader::ReadQualifiedTypes(
qualified_type_ir.SetVolatility(qualified_type_protobuf.is_volatile()); qualified_type_ir.SetVolatility(qualified_type_protobuf.is_volatile());
qualified_type_ir.SetRestrictedness( qualified_type_ir.SetRestrictedness(
qualified_type_protobuf.is_restricted()); qualified_type_protobuf.is_restricted());
if (!IsPresentInExportedHeaders(qualified_type_ir, exported_headers_)) { if (!IsLinkableMessageInExportedHeaders(&qualified_type_ir)) {
continue; continue;
} }
AddToMapAndTypeGraph(std::move(qualified_type_ir), &qualified_types_, AddToMapAndTypeGraph(std::move(qualified_type_ir), &qualified_types_,
@@ -272,7 +262,7 @@ void ProtobufTextFormatToIRReader::ReadArrayTypes(
for (auto &&array_type_protobuf : tu.array_types()) { for (auto &&array_type_protobuf : tu.array_types()) {
ArrayTypeIR array_type_ir; ArrayTypeIR array_type_ir;
ReadTypeInfo(array_type_protobuf.type_info(), &array_type_ir); ReadTypeInfo(array_type_protobuf.type_info(), &array_type_ir);
if (!IsPresentInExportedHeaders(array_type_ir, exported_headers_)) { if (!IsLinkableMessageInExportedHeaders(&array_type_ir)) {
continue; continue;
} }
AddToMapAndTypeGraph(std::move(array_type_ir), &array_types_, AddToMapAndTypeGraph(std::move(array_type_ir), &array_types_,
@@ -286,8 +276,7 @@ void ProtobufTextFormatToIRReader::ReadLvalueReferenceTypes(
LvalueReferenceTypeIR lvalue_reference_type_ir; LvalueReferenceTypeIR lvalue_reference_type_ir;
ReadTypeInfo(lvalue_reference_type_protobuf.type_info(), ReadTypeInfo(lvalue_reference_type_protobuf.type_info(),
&lvalue_reference_type_ir); &lvalue_reference_type_ir);
if (!IsPresentInExportedHeaders(lvalue_reference_type_ir, if (!IsLinkableMessageInExportedHeaders(&lvalue_reference_type_ir)) {
exported_headers_)) {
continue; continue;
} }
AddToMapAndTypeGraph(std::move(lvalue_reference_type_ir), AddToMapAndTypeGraph(std::move(lvalue_reference_type_ir),
@@ -301,8 +290,7 @@ void ProtobufTextFormatToIRReader::ReadRvalueReferenceTypes(
RvalueReferenceTypeIR rvalue_reference_type_ir; RvalueReferenceTypeIR rvalue_reference_type_ir;
ReadTypeInfo(rvalue_reference_type_protobuf.type_info(), ReadTypeInfo(rvalue_reference_type_protobuf.type_info(),
&rvalue_reference_type_ir); &rvalue_reference_type_ir);
if (!IsPresentInExportedHeaders(rvalue_reference_type_ir, if (!IsLinkableMessageInExportedHeaders(&rvalue_reference_type_ir)) {
exported_headers_)) {
continue; continue;
} }
AddToMapAndTypeGraph(std::move(rvalue_reference_type_ir), AddToMapAndTypeGraph(std::move(rvalue_reference_type_ir),
@@ -314,7 +302,7 @@ void ProtobufTextFormatToIRReader::ReadFunctions(
const abi_dump::TranslationUnit &tu) { const abi_dump::TranslationUnit &tu) {
for (auto &&function_protobuf : tu.functions()) { for (auto &&function_protobuf : tu.functions()) {
FunctionIR function_ir = FunctionProtobufToIR(function_protobuf); FunctionIR function_ir = FunctionProtobufToIR(function_protobuf);
if (!IsPresentInExportedHeaders(function_ir, exported_headers_)) { if (!IsLinkableMessageInExportedHeaders(&function_ir)) {
continue; continue;
} }
functions_.insert({function_ir.GetLinkerSetKey(), std::move(function_ir)}); functions_.insert({function_ir.GetLinkerSetKey(), std::move(function_ir)});
@@ -325,7 +313,7 @@ void ProtobufTextFormatToIRReader::ReadRecordTypes(
const abi_dump::TranslationUnit &tu) { const abi_dump::TranslationUnit &tu) {
for (auto &&record_type_protobuf : tu.record_types()) { for (auto &&record_type_protobuf : tu.record_types()) {
RecordTypeIR record_type_ir = RecordTypeProtobufToIR(record_type_protobuf); RecordTypeIR record_type_ir = RecordTypeProtobufToIR(record_type_protobuf);
if (!IsPresentInExportedHeaders(record_type_ir, exported_headers_)) { if (!IsLinkableMessageInExportedHeaders(&record_type_ir)) {
continue; continue;
} }
auto it = AddToMapAndTypeGraph(std::move(record_type_ir), &record_types_, auto it = AddToMapAndTypeGraph(std::move(record_type_ir), &record_types_,
@@ -340,7 +328,7 @@ void ProtobufTextFormatToIRReader::ReadFunctionTypes(
for (auto &&function_type_protobuf : tu.function_types()) { for (auto &&function_type_protobuf : tu.function_types()) {
FunctionTypeIR function_type_ir = FunctionTypeIR function_type_ir =
FunctionTypeProtobufToIR(function_type_protobuf); FunctionTypeProtobufToIR(function_type_protobuf);
if (!IsPresentInExportedHeaders(function_type_ir, exported_headers_)) { if (!IsLinkableMessageInExportedHeaders(&function_type_ir)) {
continue; continue;
} }
auto it = AddToMapAndTypeGraph(std::move(function_type_ir), auto it = AddToMapAndTypeGraph(std::move(function_type_ir),
@@ -354,7 +342,7 @@ void ProtobufTextFormatToIRReader::ReadEnumTypes(
const abi_dump::TranslationUnit &tu) { const abi_dump::TranslationUnit &tu) {
for (auto &&enum_type_protobuf : tu.enum_types()) { for (auto &&enum_type_protobuf : tu.enum_types()) {
EnumTypeIR enum_type_ir = EnumTypeProtobufToIR(enum_type_protobuf); EnumTypeIR enum_type_ir = EnumTypeProtobufToIR(enum_type_protobuf);
if (!IsPresentInExportedHeaders(enum_type_ir, exported_headers_)) { if (!IsLinkableMessageInExportedHeaders(&enum_type_ir)) {
continue; continue;
} }
auto it = AddToMapAndTypeGraph(std::move(enum_type_ir), &enum_types_, auto it = AddToMapAndTypeGraph(std::move(enum_type_ir), &enum_types_,