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

tudasc / TypeART / 13091819531

01 Feb 2025 07:39PM UTC coverage: 88.36%. First build
13091819531

Pull #155

github

web-flow
Merge 9129593c8 into 904382c9c
Pull Request #155: LLVM 18 testing

83 of 89 new or added lines in 8 files covered. (93.26%)

4031 of 4562 relevant lines covered (88.36%)

112157.1 hits per line

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

87.1
/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/Logger.h"
21

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,
221,110✔
36
                     bool heap) {
37
  std::string buf;
221,110✔
38
  llvm::raw_string_ostream s(buf);
221,110✔
39
  const auto name = typeart::RuntimeSystem::get().typeResolution.db().getTypeName(typeId);
221,110✔
40
  if ((typeId == TYPEART_VOID) && heap) {
221,106✔
NEW
41
    count /= typeSize;
×
NEW
42
  }
×
43
  s << memAddr << " " << typeId << " " << name << " " << typeSize << " " << count << " (" << calledFrom << ")";
221,106✔
44
  return s.str();
221,108✔
45
}
221,144✔
46

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

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

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

63
}  // namespace debug
64

65
static constexpr const char* defaultTypeFileName = "types.yaml";
66

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

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

76
  std::error_code error;
394✔
77
  // Try to load types from specified file first.
78
  // Then look at default location.
79
  const char* type_file = std::getenv("TYPEART_TYPE_FILE");
394✔
80
  if (type_file == nullptr) {
394✔
81
    // FIXME Deprecated name
82
    type_file = std::getenv("TA_TYPE_FILE");
394✔
83
    if (type_file != nullptr) {
394✔
84
      LOG_WARNING("Use of deprecated env var TA_TYPE_FILE.");
×
85
    }
×
86
  }
394✔
87
  if (type_file != nullptr) {
394✔
88
    if (!loadTypes(type_file, error)) {
×
89
      LOG_FATAL("Failed to load recorded types from TYPEART_TYPE_FILE=" << type_file
×
90
                                                                        << ". Reason: " << error.message());
91
      std::exit(EXIT_FAILURE);  // TODO: Error handling
×
92
    }
93
  } else {
×
94
    if (!loadTypes(defaultTypeFileName, error)) {
394✔
95
      LOG_WARNING(
12✔
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
    }
12✔
102
  }
103

104
  std::stringstream ss;
394✔
105
  const auto& typeList = typeDB.getStructList();
394✔
106
  for (const auto& structInfo : typeList) {
2,041✔
107
    ss << structInfo.name << ", ";
1,647✔
108
  }
1,647✔
109
  recorder.incUDefTypes(typeList.size());
394✔
110
  LOG_INFO("Recorded types: " << ss.str());
394✔
111
  rtScopeInit.reset();
394✔
112
}
394✔
113

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

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

120
  std::ostringstream stream;
394✔
121
  softcounter::serialize(recorder, stream);
394✔
122
  if (!stream.str().empty()) {
394✔
123
    // llvm::errs/LOG will crash with virtual call error
124
    std::cerr << stream.str();
394✔
125
  }
394✔
126
}
394✔
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