================ @@ -0,0 +1,192 @@ +//===- StaticLibrary.cpp --------------------------------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +#include "JSONFormatImpl.h" + +#include "clang/ScalableStaticAnalysis/Core/EntityLinker/StaticLibrary.h" +#include "clang/ScalableStaticAnalysis/Core/EntityLinker/TUSummaryEncoding.h" +#include "llvm/TargetParser/Triple.h" + +namespace clang::ssaf { + +//---------------------------------------------------------------------------- +// StaticLibrary +//---------------------------------------------------------------------------- + +llvm::Expected<StaticLibrary> +JSONFormat::readStaticLibrary(llvm::StringRef Path) { + auto ExpectedJSON = readJSON(Path); + if (!ExpectedJSON) { + return ErrorBuilder::wrap(ExpectedJSON.takeError()) + .context(ErrorMessages::ReadingFromFile, "StaticLibrary", Path) + .build(); + } + + Object *RootObjectPtr = ExpectedJSON->getAsObject(); + if (!RootObjectPtr) { + return ErrorBuilder::create(std::errc::invalid_argument, + ErrorMessages::FailedToReadObject, + "StaticLibrary", "object") + .context(ErrorMessages::ReadingFromFile, "StaticLibrary", Path) + .build(); + } + + if (auto Err = checkSummaryType(*RootObjectPtr, JSONTypeValueStaticLibrary)) { + return ErrorBuilder::wrap(std::move(Err)) + .context(ErrorMessages::ReadingFromFile, "StaticLibrary", Path) + .build(); + } + + auto ExpectedStaticLibrary = readStaticLibraryFromObject(*RootObjectPtr); + if (!ExpectedStaticLibrary) { + return ErrorBuilder::wrap(ExpectedStaticLibrary.takeError()) + .context(ErrorMessages::ReadingFromFile, "StaticLibrary", Path) + .build(); + } + + return std::move(*ExpectedStaticLibrary); +} + +llvm::Expected<StaticLibrary> +JSONFormat::readStaticLibraryFromObject(const Object &RootObject) { + auto OptTargetTriple = RootObject.getString("target_triple"); ---------------- aviralg wrote:
Good point. I will create a separate PR to address this since `target_triple` is being used in: - Core/Serialization/JSONFormat/StaticLibrary.cpp - Core/Serialization/JSONFormat/TUSummary.cpp - Core/Serialization/JSONFormat/TUSummaryEncoding.cpp - Core/Serialization/JSONFormat/LUSummary.cpp - Core/Serialization/JSONFormat/LUSummaryEncoding.cpp https://github.com/llvm/llvm-project/pull/205946 _______________________________________________ cfe-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
