<commit_before>//===- xray-extract.cc - XRay Instrumentation Map Extraction --------------===//
//
//                     The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
//
// Implementation of the xray-extract.h interface.
//
// FIXME: Support other XRay-instrumented binary formats other than ELF.
//
//===----------------------------------------------------------------------===//

#include <type_traits>
#include <unistd.h>
#include <utility>

#include "xray-extract.h"

#include "xray-registry.h"
#include "xray-sleds.h"
#include "llvm/Object/ELF.h"
#include "llvm/Object/ObjectFile.h"
#include "llvm/Support/CommandLine.h"
#include "llvm/Support/DataExtractor.h"
#include "llvm/Support/ELF.h"
#include "llvm/Support/Error.h"
#include "llvm/Support/FileSystem.h"
#include "llvm/Support/Format.h"
#include "llvm/Support/YAMLTraits.h"
#include "llvm/Support/raw_ostream.h"

using namespace llvm;
using namespace llvm::xray;
using namespace llvm::yaml;

// llvm-xray extract
// ----------------------------------------------------------------------------
static cl::SubCommand Extract("extract", "Extract instrumentation maps");
static cl::opt<std::string> ExtractInput(cl::Positional,
                                         cl::desc("<input file>"), cl::Required,
                                         cl::sub(Extract));
static cl::opt<std::string>
    ExtractOutput("output", cl::value_desc("output file"), cl::init("-"),
                  cl::desc("output file; use '-' for stdout"),
                  cl::sub(Extract));
static cl::alias ExtractOutput2("o", cl::aliasopt(ExtractOutput),
                                cl::desc("Alias for -output"),
                                cl::sub(Extract));

struct YAMLXRaySledEntry {
  int32_t FuncId;
  Hex64 Address;
  Hex64 Function;
  SledEntry::FunctionKinds Kind;
  bool AlwaysInstrument;
};

template <> struct ScalarEnumerationTraits<SledEntry::FunctionKinds> {
  static void enumeration(IO &IO, SledEntry::FunctionKinds &Kind) {
    IO.enumCase(Kind, "function-enter", SledEntry::FunctionKinds::ENTRY);
    IO.enumCase(Kind, "function-exit", SledEntry::FunctionKinds::EXIT);
    IO.enumCase(Kind, "tail-exit", SledEntry::FunctionKinds::TAIL);
  }
};

template <> struct MappingTraits<YAMLXRaySledEntry> {
  static void mapping(IO &IO, YAMLXRaySledEntry &Entry) {
    IO.mapRequired("id", Entry.FuncId);
    IO.mapRequired("address", Entry.Address);
    IO.mapRequired("function", Entry.Function);
    IO.mapRequired("kind", Entry.Kind);
    IO.mapRequired("always-instrument", Entry.AlwaysInstrument);
  }

  static constexpr bool flow = true;
};

LLVM_YAML_IS_SEQUENCE_VECTOR(YAMLXRaySledEntry);

namespace {

llvm::Error LoadBinaryInstrELF(
    StringRef Filename, std::deque<SledEntry> &OutputSleds,
    InstrumentationMapExtractor::FunctionAddressMap &InstrMap,<commit_msg>[XRay] Remove extra `;` to make -wpedantic happy<commit_after>//===- xray-extract.cc - XRay Instrumentation Map Extraction --------------===//
//
//                     The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
//
// Implementation of the xray-extract.h interface.
//
// FIXME: Support other XRay-instrumented binary formats other than ELF.
//
//===----------------------------------------------------------------------===//

#include <type_traits>
#include <unistd.h>
#include <utility>

#include "xray-extract.h"

#include "xray-registry.h"
#include "xray-sleds.h"
#include "llvm/Object/ELF.h"
#include "llvm/Object/ObjectFile.h"
#include "llvm/Support/CommandLine.h"
#include "llvm/Support/DataExtractor.h"
#include "llvm/Support/ELF.h"
#include "llvm/Support/Error.h"
#include "llvm/Support/FileSystem.h"
#include "llvm/Support/Format.h"
#include "llvm/Support/YAMLTraits.h"
#include "llvm/Support/raw_ostream.h"

using namespace llvm;
using namespace llvm::xray;
using namespace llvm::yaml;

// llvm-xray extract
// ----------------------------------------------------------------------------
static cl::SubCommand Extract("extract", "Extract instrumentation maps");
static cl::opt<std::string> ExtractInput(cl::Positional,
                                         cl::desc("<input file>"), cl::Required,
                                         cl::sub(Extract));
static cl::opt<std::string>
    ExtractOutput("output", cl::value_desc("output file"), cl::init("-"),
                  cl::desc("output file; use '-' for stdout"),
                  cl::sub(Extract));
static cl::alias ExtractOutput2("o", cl::aliasopt(ExtractOutput),
                                cl::desc("Alias for -output"),
                                cl::sub(Extract));

struct YAMLXRaySledEntry {
  int32_t FuncId;
  Hex64 Address;
  Hex64 Function;
  SledEntry::FunctionKinds Kind;
  bool AlwaysInstrument;
};

template <> struct ScalarEnumerationTraits<SledEntry::FunctionKinds> {
  static void enumeration(IO &IO, SledEntry::FunctionKinds &Kind) {
    IO.enumCase(Kind, "function-enter", SledEntry::FunctionKinds::ENTRY);
    IO.enumCase(Kind, "function-exit", SledEntry::FunctionKinds::EXIT);
    IO.enumCase(Kind, "tail-exit", SledEntry::FunctionKinds::TAIL);
  }
};

template <> struct MappingTraits<YAMLXRaySledEntry> {
  static void mapping(IO &IO, YAMLXRaySledEntry &Entry) {
    IO.mapRequired("id", Entry.FuncId);
    IO.mapRequired("address", Entry.Address);
    IO.mapRequired("function", Entry.Function);
    IO.mapRequired("kind", Entry.Kind);
    IO.mapRequired("always-instrument", Entry.AlwaysInstrument);
  }

  static constexpr bool flow = true;
};

LLVM_YAML_IS_SEQUENCE_VECTOR(YAMLXRaySledEntry)

namespace {

llvm::Error LoadBinaryInstrELF(
    StringRef Filename, std::deque<SledEntry> &OutputSleds,
    InstrumentationMapExtractor::FunctionAddressMap &InstrMap,
{'fraction_non_alphanumeric': 0.21172798948751642, 'fraction_numerical': 0.0022996057818659658, 'mean_word_length': 2.657057057057057, 'pattern_counts': {'":': 0, '<': 25, '<?xml version=': 0, '>': 25, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 8, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3374941', 'n_tokens_mistral': 1820, 'n_tokens_neox': 1778, 'n_words': 365}