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

#include "llvm/DebugInfo/DWARFFormValue.h"
#include "DWARFCompileUnit.h"
#include "DWARFContext.h"
#include "llvm/ADT/ArrayRef.h"
#include "llvm/ADT/StringRef.h"
#include "llvm/Support/Debug.h"
#include "llvm/Support/Dwarf.h"
#include "llvm/Support/Format.h"
#include "llvm/Support/raw_ostream.h"
#include <cassert>
using namespace llvm;
using namespace dwarf;

namespace {
template <uint8_t AddrSize, uint8_t RefAddrSize> struct FixedFormSizes {
  static const uint8_t sizes[];
};
}

template <uint8_t AddrSize, uint8_t RefAddrSize>
const uint8_t FixedFormSizes<AddrSize, RefAddrSize>::sizes[] = {
  0,           // 0x00 unused
  AddrSize,    // 0x01 DW_FORM_addr
  0,           // 0x02 unused
  0,           // 0x03 DW_FORM_block2
  0,           // 0x04 DW_FORM_block4
  2,           // 0x05 DW_FORM_data2
  4,           // 0x06 DW_FORM_data4
  8,           // 0x07 DW_FORM_data8
  0,           // 0x08 DW_FORM_string
  0,           // 0x09 DW_FORM_block
  0,           // 0x0a DW_FORM_block1
  1,           // 0x0b DW_FORM_data1
  1,           // 0x0c DW_FORM_flag
  0,           // 0x0d DW_FORM_sdata
  4,           // 0x0e DW_FORM_strp
  0,           // 0x0f DW_FORM_udata
  RefAddrSize, // 0x10 DW_FORM_ref_addr
  1,           // 0x11 DW_FORM_ref1
  2,           // 0x12 DW_FORM_ref2
  4,           // 0x13 DW_FORM_ref4
  8,           // 0x14 DW_FORM_ref8
  0,           // 0x15 DW_FORM_ref_udata
  0,           // 0x16 DW_FORM_indirect
  4,           // 0x17 DW_FORM_sec_offset
  0,           // 0x18 DW_FORM_exprloc
  0,           // 0x19 DW_FORM_flag_present
  8,           // 0x20 DW_FORM_ref_sig8
};

static uint8_t getRefAddrSize(uint8_t AddrSize, uint16_t Version) {
  // FIXME: Support DWARF64.
  return (Version == 2) ? AddrSize : 4;
}

ArrayRef<uint8_t> DWARFFormValue::getFixedFormSizes(uint8_t AddrSize,
                                                    uint16_t Version) {
  uint8_t RefAddrSize = getRefAddrSize(AddrSize, Version);
  if (AddrSize == 4 && RefAddrSize == 4)
    return FixedFormSizes<4, 4>::sizes;
  if (AddrSize == 4 && RefAddrSize == 8)
    return FixedFormSizes<4, 8>::sizes;
  if (AddrSize == 8 && RefAddrSize == 4)
    return FixedFormSizes<8, 4>::sizes;
  if (AddrSize == 8 && RefAddrSize == 8)
    return FixedFormSizes<8, 8>::sizes;
  return None;
}

static const DWARFFormValue::FormClass DWARF4FormClasses[] = {
  DWARFFormValue::FC_Unknown,       // 0x0
  DWARFFormValue::FC_Address,       // 0x01 DW_FORM_addr
  DWARFFormValue::FC_Unknown,       // 0x02 unused
  DWARFFormValue::FC_Block,         // 0x03 DW_FORM_block2
  DWARFFormValue::FC_Block,         // 0x04 DW_FORM_block4
  DWARFFormValue::FC_Constant,      // 0x05 DW_FORM_data2
  // --- These can be FC_SectionOffset in DWARF3 and below:
  DWARFFormValue::FC_Constant,      // 0x06 DW_FORM_data4
  DWARFFormValue::FC_Constant,      // 0x07 DW_FORM_data8
  // ---
  DWARFFormValue::FC_String,        // 0x08 DW_FORM_string
  DWARFFormValue::FC_Block,         // 0x09 DW_FORM_block
  DWARFFormValue::FC_Block,         // 0x0a DW_FORM_block1
  DWARFFormValue::FC_Constant,      // 0x0b DW_FORM_data1
  DWARFFormValue::FC_Flag,          // 0x0c DW_FORM_flag
  DWARFFormValue::FC_Constant,      // 0x0d DW_FORM_sdata
  DWARFFormValue::FC_String,        // 0x0e DW_FORM_strp
  DWARFFormValue::FC_Constant,      // 0x0f DW_FORM_udata
  DWARFFormValue::FC_Reference,     // 0x10 DW_FORM_ref_addr
  DWARFFormValue::FC_Reference,     // 0x11 DW_FORM_ref1
  DWARFFormValue::FC_Reference,     // 0x12 DW_FORM_ref2
  DWARFFormValue::FC_Reference,     // 0x13 DW_FORM_ref4
  DWARFFormValue::FC_Reference,     // 0x14 DW_FORM_ref8
  DWARFFormValue::FC_Reference,     // 0x15 DW_FORM_ref_udata
  DWARFFormValue::FC_Indirect,      // 0x16 DW_FORM_indirect<commit_msg>DWARFFormValue.cpp: Appease gcc to give explicit constructors.<commit_after>//===-- DWARFFormValue.cpp ------------------------------------------------===//
//
//                     The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//

#include "llvm/DebugInfo/DWARFFormValue.h"
#include "DWARFCompileUnit.h"
#include "DWARFContext.h"
#include "llvm/ADT/ArrayRef.h"
#include "llvm/ADT/StringRef.h"
#include "llvm/Support/Debug.h"
#include "llvm/Support/Dwarf.h"
#include "llvm/Support/Format.h"
#include "llvm/Support/raw_ostream.h"
#include <cassert>
using namespace llvm;
using namespace dwarf;

namespace {
template <uint8_t AddrSize, uint8_t RefAddrSize> struct FixedFormSizes {
  static const uint8_t sizes[];
};
}

template <uint8_t AddrSize, uint8_t RefAddrSize>
const uint8_t FixedFormSizes<AddrSize, RefAddrSize>::sizes[] = {
  0,           // 0x00 unused
  AddrSize,    // 0x01 DW_FORM_addr
  0,           // 0x02 unused
  0,           // 0x03 DW_FORM_block2
  0,           // 0x04 DW_FORM_block4
  2,           // 0x05 DW_FORM_data2
  4,           // 0x06 DW_FORM_data4
  8,           // 0x07 DW_FORM_data8
  0,           // 0x08 DW_FORM_string
  0,           // 0x09 DW_FORM_block
  0,           // 0x0a DW_FORM_block1
  1,           // 0x0b DW_FORM_data1
  1,           // 0x0c DW_FORM_flag
  0,           // 0x0d DW_FORM_sdata
  4,           // 0x0e DW_FORM_strp
  0,           // 0x0f DW_FORM_udata
  RefAddrSize, // 0x10 DW_FORM_ref_addr
  1,           // 0x11 DW_FORM_ref1
  2,           // 0x12 DW_FORM_ref2
  4,           // 0x13 DW_FORM_ref4
  8,           // 0x14 DW_FORM_ref8
  0,           // 0x15 DW_FORM_ref_udata
  0,           // 0x16 DW_FORM_indirect
  4,           // 0x17 DW_FORM_sec_offset
  0,           // 0x18 DW_FORM_exprloc
  0,           // 0x19 DW_FORM_flag_present
  8,           // 0x20 DW_FORM_ref_sig8
};

static uint8_t getRefAddrSize(uint8_t AddrSize, uint16_t Version) {
  // FIXME: Support DWARF64.
  return (Version == 2) ? AddrSize : 4;
}

ArrayRef<uint8_t> DWARFFormValue::getFixedFormSizes(uint8_t AddrSize,
                                                    uint16_t Version) {
  uint8_t RefAddrSize = getRefAddrSize(AddrSize, Version);
  if (AddrSize == 4 && RefAddrSize == 4)
    return ArrayRef<uint8_t>(FixedFormSizes<4, 4>::sizes);
  if (AddrSize == 4 && RefAddrSize == 8)
    return ArrayRef<uint8_t>(FixedFormSizes<4, 8>::sizes);
  if (AddrSize == 8 && RefAddrSize == 4)
    return ArrayRef<uint8_t>(FixedFormSizes<8, 4>::sizes);
  if (AddrSize == 8 && RefAddrSize == 8)
    return ArrayRef<uint8_t>(FixedFormSizes<8, 8>::sizes);
  return None;
}

static const DWARFFormValue::FormClass DWARF4FormClasses[] = {
  DWARFFormValue::FC_Unknown,       // 0x0
  DWARFFormValue::FC_Address,       // 0x01 DW_FORM_addr
  DWARFFormValue::FC_Unknown,       // 0x02 unused
  DWARFFormValue::FC_Block,         // 0x03 DW_FORM_block2
  DWARFFormValue::FC_Block,         // 0x04 DW_FORM_block4
  DWARFFormValue::FC_Constant,      // 0x05 DW_FORM_data2
  // --- These can be FC_SectionOffset in DWARF3 and below:
  DWARFFormValue::FC_Constant,      // 0x06 DW_FORM_data4
  DWARFFormValue::FC_Constant,      // 0x07 DW_FORM_data8
  // ---
  DWARFFormValue::FC_String,        // 0x08 DW_FORM_string
  DWARFFormValue::FC_Block,         // 0x09 DW_FORM_block
  DWARFFormValue::FC_Block,         // 0x0a DW_FORM_block1
  DWARFFormValue::FC_Constant,      // 0x0b DW_FORM_data1
  DWARFFormValue::FC_Flag,          // 0x0c DW_FORM_flag
  DWARFFormValue::FC_Constant,      // 0x0d DW_FORM_sdata
  DWARFFormValue::FC_String,        // 0x0e DW_FORM_strp
  DWARFFormValue::FC_Constant,      // 0x0f DW_FORM_udata
  DWARFFormValue::FC_Reference,     // 0x10 DW_FORM_ref_addr
  DWARFFormValue::FC_Reference,     // 0x11 DW_FORM_ref1
  DWARFFormValue::FC_Reference,     // 0x12 DW_FORM_ref2
  DWARFFormValue::FC_Reference,     // 0x13 DW_FORM_ref4
  DWARFFormValue::FC_Reference,     // 0x14 DW_FORM_ref8
  DWARFFormValue::FC_Reference,     // 0x15 DW_FORM_ref_udata
  DWARFFormValue::FC_Indirect,      // 0x16 DW_FORM_indirect
{'fraction_non_alphanumeric': 0.13133006105590805, 'fraction_numerical': 0.05363342511672453, 'mean_word_length': 2.3058963197467355, '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': 4, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '104337', 'n_tokens_mistral': 3365, 'n_tokens_neox': 3065, 'n_words': 579}