• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

tudasc / TypeART / 13528988609

25 Feb 2025 07:06PM UTC coverage: 88.854% (-1.9%) from 90.735%
13528988609

Pull #163

github

web-flow
Merge e4a2d80f6 into d2e14acc5
Pull Request #163: LLVM 18 support

974 of 1122 new or added lines in 38 files covered. (86.81%)

30 existing lines in 6 files now uncovered.

4201 of 4728 relevant lines covered (88.85%)

190054.62 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

23.4
/lib/passes/configuration/FileConfiguration.cpp
1
// TypeART library
2
//
3
// Copyright (c) 2017-2025 TypeART Authors
4
// Distributed under the BSD 3-Clause license.
5
// (See accompanying file LICENSE.txt or copy at
6
// https://opensource.org/licenses/BSD-3-Clause)
7
//
8
// Project home: https://github.com/tudasc/TypeART
9
//
10
// SPDX-License-Identifier: BSD-3-Clause
11
//
12

13
#include "FileConfiguration.h"
14

15
#include "Configuration.h"
16
#include "TypeARTConfiguration.h"
17
#include "TypeARTOptions.h"
18
#include "analysis/MemInstFinder.h"
19
#include "typegen/TypeGenerator.h"
20

21
#include "llvm/ADT/StringMap.h"
22
#include "llvm/ADT/StringRef.h"
23
#include "llvm/Support/FileSystem.h"
24
#include "llvm/Support/MemoryBuffer.h"
25
#include "llvm/Support/YAMLTraits.h"
26

27
#include <optional>
28
#include <string_view>
29
#include <type_traits>
30

31
using namespace llvm;
32

33
namespace typeart::config::file {
34

35
std::string write_file_configuration_as_text(const FileOptions& file_options);
36

37
class YamlFileConfiguration final : public FileOptions {
38
 private:
39
  OptionsMap mapping_;
40

41
 public:
42
  explicit YamlFileConfiguration(const TypeARTConfigOptions& conf_file);
43

44
  [[nodiscard]] std::optional<config::OptionValue> getValue(std::string_view opt_path) const override;
45

46
  [[nodiscard]] OptionsMap getConfiguration() const override;
47

48
  [[nodiscard]] std::string getConfigurationAsString() const override;
49

50
  ~YamlFileConfiguration() override = default;
4,700✔
51
};
52

53
YamlFileConfiguration::YamlFileConfiguration(const TypeARTConfigOptions& conf_file)
4,004✔
54
    : mapping_(helper::options_to_map(conf_file)) {
4,004✔
55
}
2,350✔
56

57
std::optional<typeart::config::OptionValue> YamlFileConfiguration::getValue(std::string_view opt_path) const {
179,932✔
58
  auto key = llvm::StringRef(opt_path.data());
179,932✔
59
  if (mapping_.count(key) != 0U) {
179,932✔
60
    return mapping_.lookup(key);
179,932✔
61
  }
NEW
62
  return {};
×
63
}
179,932✔
64

NEW
65
OptionsMap YamlFileConfiguration::getConfiguration() const {
×
NEW
66
  return this->mapping_;
×
67
}
68

NEW
69
std::string YamlFileConfiguration::getConfigurationAsString() const {
×
NEW
70
  return write_file_configuration_as_text(*this);
×
71
}
72

73
namespace compat {
NEW
74
auto open_flag() {
×
75
#if LLVM_VERSION_MAJOR < 13
76
  return llvm::sys::fs::OpenFlags::F_Text;
77
#else
NEW
78
  return llvm::sys::fs::OpenFlags::OF_Text;
×
79
#endif
80
}
81
}  // namespace compat
82

NEW
83
[[maybe_unused]] llvm::ErrorOr<std::unique_ptr<FileOptions>> make_file_configuration(std::string_view file_path) {
×
84
  using namespace llvm;
85

NEW
86
  ErrorOr<std::unique_ptr<MemoryBuffer>> memBuffer = MemoryBuffer::getFile(file_path.data());
×
87

NEW
88
  if (std::error_code error = memBuffer.getError(); error) {
×
NEW
89
    LOG_WARNING("Warning while loading configuration file \'" << file_path.data() << "\'. Reason: " << error.message());
×
NEW
90
    return error;
×
91
  }
92

NEW
93
  llvm::yaml::Input input_yaml(memBuffer.get()->getMemBufferRef());
×
NEW
94
  const auto file_content = io::yaml::yaml_read_file(input_yaml);
×
95

NEW
96
  return std::make_unique<YamlFileConfiguration>(file_content);
×
NEW
97
}
×
98

NEW
99
llvm::ErrorOr<std::unique_ptr<FileOptions>> make_default_file_configuration() {
×
NEW
100
  TypeARTConfigOptions options;
×
NEW
101
  return std::make_unique<YamlFileConfiguration>(options);
×
NEW
102
}
×
103

104
llvm::ErrorOr<std::unique_ptr<FileOptions>> make_from_configuration(const TypeARTConfigOptions& options) {
2,350✔
105
  return std::make_unique<YamlFileConfiguration>(options);
2,350✔
NEW
106
}
×
107

NEW
108
llvm::ErrorOr<bool> write_file_configuration(llvm::raw_ostream& out_stream, const FileOptions& options) {
×
109
  using namespace llvm;
110

NEW
111
  llvm::yaml::Output out(out_stream);
×
112

NEW
113
  auto data = options.getConfiguration();
×
114

NEW
115
  auto conf_file = helper::map_to_options(options.getConfiguration());
×
NEW
116
  io::yaml::yaml_output_file(out, conf_file);
×
117

NEW
118
  return true;
×
NEW
119
}
×
120

NEW
121
std::string write_file_configuration_as_text(const FileOptions& file_options) {
×
NEW
122
  std::string config_text;
×
NEW
123
  llvm::raw_string_ostream sstream(config_text);
×
NEW
124
  if (!write_file_configuration(sstream, file_options)) {
×
NEW
125
    LOG_WARNING("Could not write config file to string stream.")
×
NEW
126
  }
×
NEW
127
  return sstream.str();
×
NEW
128
}
×
129

130
}  // namespace typeart::config::file
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc