<commit_before>//===-- BenchmarkResult.cpp -------------------------------------*- C++ -*-===//
//
//                     The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//

#include "BenchmarkResult.h"
#include "llvm/ADT/STLExtras.h"
#include "llvm/ADT/StringRef.h"
#include "llvm/ObjectYAML/YAML.h"
#include "llvm/Support/FileOutputBuffer.h"
#include "llvm/Support/FileSystem.h"
#include "llvm/Support/Format.h"
#include "llvm/Support/raw_ostream.h"

static constexpr const char kIntegerFormat[] = "i_0x%" PRId64 "x";
static constexpr const char kDoubleFormat[] = "f_%la";

static void serialize(const exegesis::BenchmarkResultContext &Context,
                      const llvm::MCOperand &MCOperand, llvm::raw_ostream &OS) {
  if (MCOperand.isReg()) {
    OS << Context.getRegName(MCOperand.getReg());
  } else if (MCOperand.isImm()) {
    OS << llvm::format(kIntegerFormat, MCOperand.getImm());
  } else if (MCOperand.isFPImm()) {
    OS << llvm::format(kDoubleFormat, MCOperand.getFPImm());
  } else {
    OS << "INVALID";
  }
}

static void serialize(const exegesis::BenchmarkResultContext &Context,
                      const llvm::MCInst &MCInst, llvm::raw_ostream &OS) {
  OS << Context.getInstrName(MCInst.getOpcode());
  for (const auto &Op : MCInst) {
    OS << ' ';
    serialize(Context, Op, OS);
  }
}

static llvm::MCOperand
deserialize(const exegesis::BenchmarkResultContext &Context,
            llvm::StringRef String) {
  assert(!String.empty());
  int64_t IntValue = 0;
  double DoubleValue = 0;
  if (sscanf(String.data(), kIntegerFormat, &IntValue) == 1)
    return llvm::MCOperand::createImm(IntValue);
  if (sscanf(String.data(), kDoubleFormat, &DoubleValue) == 1)
    return llvm::MCOperand::createFPImm(DoubleValue);
  if (unsigned RegNo = Context.getRegNo(String)) // Returns 0 if invalid.
    return llvm::MCOperand::createReg(RegNo);
  return {};
}

static llvm::StringRef
deserialize(const exegesis::BenchmarkResultContext &Context,
            llvm::StringRef String, llvm::MCInst &Value) {
  llvm::SmallVector<llvm::StringRef, 8> Pieces;
  String.split(Pieces, " ");
  if (Pieces.empty())
    return "Invalid Instruction";
  bool ProcessOpcode = true;
  for (llvm::StringRef Piece : Pieces) {
    if (ProcessOpcode) {
      ProcessOpcode = false;
      Value.setOpcode(Context.getInstrOpcode(Piece));
      if (Value.getOpcode() == 0)
        return "Unknown Opcode Name";<commit_msg>[llvm-exegesis] Ignore double spaced separators in asm strings<commit_after>//===-- BenchmarkResult.cpp -------------------------------------*- C++ -*-===//
//
//                     The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//

#include "BenchmarkResult.h"
#include "llvm/ADT/STLExtras.h"
#include "llvm/ADT/StringRef.h"
#include "llvm/ObjectYAML/YAML.h"
#include "llvm/Support/FileOutputBuffer.h"
#include "llvm/Support/FileSystem.h"
#include "llvm/Support/Format.h"
#include "llvm/Support/raw_ostream.h"

static constexpr const char kIntegerFormat[] = "i_0x%" PRId64 "x";
static constexpr const char kDoubleFormat[] = "f_%la";

static void serialize(const exegesis::BenchmarkResultContext &Context,
                      const llvm::MCOperand &MCOperand, llvm::raw_ostream &OS) {
  if (MCOperand.isReg()) {
    OS << Context.getRegName(MCOperand.getReg());
  } else if (MCOperand.isImm()) {
    OS << llvm::format(kIntegerFormat, MCOperand.getImm());
  } else if (MCOperand.isFPImm()) {
    OS << llvm::format(kDoubleFormat, MCOperand.getFPImm());
  } else {
    OS << "INVALID";
  }
}

static void serialize(const exegesis::BenchmarkResultContext &Context,
                      const llvm::MCInst &MCInst, llvm::raw_ostream &OS) {
  OS << Context.getInstrName(MCInst.getOpcode());
  for (const auto &Op : MCInst) {
    OS << ' ';
    serialize(Context, Op, OS);
  }
}

static llvm::MCOperand
deserialize(const exegesis::BenchmarkResultContext &Context,
            llvm::StringRef String) {
  assert(!String.empty());
  int64_t IntValue = 0;
  double DoubleValue = 0;
  if (sscanf(String.data(), kIntegerFormat, &IntValue) == 1)
    return llvm::MCOperand::createImm(IntValue);
  if (sscanf(String.data(), kDoubleFormat, &DoubleValue) == 1)
    return llvm::MCOperand::createFPImm(DoubleValue);
  if (unsigned RegNo = Context.getRegNo(String)) // Returns 0 if invalid.
    return llvm::MCOperand::createReg(RegNo);
  return {};
}

static llvm::StringRef
deserialize(const exegesis::BenchmarkResultContext &Context,
            llvm::StringRef String, llvm::MCInst &Value) {
  llvm::SmallVector<llvm::StringRef, 8> Pieces;
  String.split(Pieces, " ", /* MaxSplit */ -1, /* KeepEmpty */ false);
  if (Pieces.empty())
    return "Invalid Instruction";
  bool ProcessOpcode = true;
  for (llvm::StringRef Piece : Pieces) {
    if (ProcessOpcode) {
      ProcessOpcode = false;
      Value.setOpcode(Context.getInstrOpcode(Piece));
      if (Value.getOpcode() == 0)
        return "Unknown Opcode Name";
{'fraction_non_alphanumeric': 0.18363876818439448, 'fraction_numerical': 0.004723219346306443, 'mean_word_length': 3.2419871794871793, 'pattern_counts': {'":': 0, '<': 29, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6027263', 'n_tokens_mistral': 1725, 'n_tokens_neox': 1702, 'n_words': 368}