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

tudasc / TypeART / 13955121336

19 Mar 2025 07:30PM UTC coverage: 88.842%. First build
13955121336

push

github

web-flow
Merge PR #167 from tudasc/devel

1174 of 1361 new or added lines in 49 files covered. (86.26%)

4212 of 4741 relevant lines covered (88.84%)

261950.04 hits per line

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

93.55
/lib/runtime/Runtime.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 "Runtime.h"
14

15
#include "AccessCountPrinter.h"
16
#include "AccessCounter.h"
17
#include "RuntimeData.h"
18
#include "TypeIO.h"
19
#include "TypeInterface.h"
20
#include "support/ConfigurationBase.h"
21
#include "support/Logger.h"
22
// #include "llvm/Support/raw_ostream.h"
23

24
#include <cstdlib>
25
#include <iostream>
26
#include <set>
27
#include <sstream>
28
#include <unordered_map>
29
#include <vector>
30

31
namespace typeart {
32

33
namespace debug {
34

35
std::string toString(const void* memAddr, int typeId, size_t count, size_t typeSize, const void* calledFrom,
441,291✔
36
                     bool heap) {
37
  std::string buf;
441,291✔
38
  llvm::raw_string_ostream s(buf);
441,291✔
39
  const auto name = typeart::RuntimeSystem::get().typeResolution.db().getTypeName(typeId);
441,291✔
40
  if ((typeId == TYPEART_VOID) && heap) {
441,287✔
NEW
41
    count /= typeSize;
×
NEW
42
  }
×
43
  s << memAddr << " " << typeId << " " << name << " " << typeSize << " " << count << " (" << calledFrom << ")";
441,287✔
44
  return s.str();
441,370✔
45
}
441,651✔
46

47
std::string toString(const void* memAddr, int typeId, size_t count, const void* calledFrom, bool heap) {
441,368✔
48
  const auto typeSize = typeart::RuntimeSystem::get().typeResolution.db().getTypeSize(typeId);
441,368✔
49
  return toString(memAddr, typeId, count, typeSize, calledFrom, heap);
441,368✔
50
}
441,368✔
51

52
std::string toString(const void* addr, const PointerInfo& info, bool heap) {
210,481✔
53
  return toString(addr, info.typeId, info.count, info.debug, heap);
210,481✔
54
}
55

56
inline void printTraceStart() {
778✔
57
  LOG_TRACE("TypeART Runtime Trace");
1,184✔
58
  LOG_TRACE("*********************");
778✔
59
  LOG_TRACE("Operation  Address   Type   Size   Count   (CallAddr)   Stack/Heap/Global");
778✔
60
  LOG_TRACE("-------------------------------------------------------------------------");
1,184✔
61
}
778✔
62

63
}  // namespace debug
64

65
static constexpr const char* defaultTypeFileName = config::ConfigStdArgValues::types;
66

67
RuntimeSystem::RuntimeSystem() : rtScopeInit(), typeResolution(typeDB, recorder), allocTracker(typeDB, recorder) {
790✔
68
  debug::printTraceStart();
790✔
69

70
  auto loadTypes = [this](const std::string& file, std::error_code& ec) -> bool {
1,568✔
71
    auto loaded = io::load(&typeDB, file);
778✔
72
    ec          = loaded.getError();
778✔
73
    return !static_cast<bool>(ec);
778✔
74
  };
1,190✔
75

76
  std::error_code error;
790✔
77
  // Try to load types from specified file first.
78
  // Then look at default location.
79
  const char* type_file = std::getenv(config::EnvironmentStdArgs::types);
790✔
80
  if (type_file == nullptr) {
790✔
81
    // FIXME Deprecated name
82
    type_file = std::getenv("TYPEART_TYPE_FILE");
778✔
83
    if (type_file != nullptr) {
778✔
84
      LOG_WARNING("Use of deprecated env var TYPEART_TYPE_FILE.");
12✔
85
    }
12✔
86
  }
778✔
87
  if (type_file != nullptr) {
790✔
88
    if (!loadTypes(type_file, error)) {
24✔
89
      LOG_FATAL("Failed to load recorded types from " << config::EnvironmentStdArgs::types << "=" << type_file
24✔
90
                                                      << " .Reason: " << error.message());
91
      std::exit(EXIT_FAILURE);  // TODO: Error handling
×
92
    }
93
  } else {
×
94
    if (!loadTypes(defaultTypeFileName, error)) {
766✔
95
      LOG_WARNING(
24✔
96
          "No type file with default name \""
97
          << defaultTypeFileName
98
          << "\" in current directory. Using default built-in types only. To specify a different file, edit the "
99
             "TYPEART_TYPE_FILE environment variable. Reason: "
100
          << error.message());
101
    }
24✔
102
  }
103

104
  std::stringstream ss;
766✔
105
  const auto& typeList = typeDB.getStructList();
766✔
106
  for (const auto& structInfo : typeList) {
4,663✔
107
    ss << structInfo.name << ", ";
3,897✔
108
  }
3,897✔
109
  recorder.incUDefTypes(typeList.size());
766✔
110
  LOG_INFO("Recorded types: " << ss.str());
766✔
111
  rtScopeInit.reset();
766✔
112
}
430✔
113

114
RuntimeSystem::~RuntimeSystem() {
766✔
115
  rtScope = true;
766✔
116

117
  //  std::string stats;
118
  //  llvm::raw_string_ostream stream(stats);
119

120
  std::ostringstream stream;
766✔
121
  softcounter::serialize(recorder, stream);
766✔
122
  if (!stream.str().empty()) {
766✔
123
    // llvm::errs/LOG will crash with virtual call error
124
    std::cerr << stream.str();
766✔
125
  }
766✔
126
}
766✔
127

128
// This is initially set to true in order to prevent tracking anything before the runtime library is properly set up.
129
thread_local bool RuntimeSystem::rtScope = false;
130

131
}  // namespace typeart
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