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

daisytuner / docc / 23547730132

25 Mar 2026 02:58PM UTC coverage: 64.345% (+0.001%) from 64.344%
23547730132

push

github

web-flow
Merge pull request #610 from daisytuner/pytorch-static-flops

Introduce StdlibNode as base class for all Stdlib LibNodes.

7 of 12 new or added lines in 11 files covered. (58.33%)

1 existing line in 1 file now uncovered.

26716 of 41520 relevant lines covered (64.34%)

405.71 hits per line

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

0.0
/sdfg/src/data_flow/library_nodes/stdlib/assert.cpp
1
#include "sdfg/data_flow/library_nodes/stdlib/assert.h"
2

3
#include <cassert>
4
#include <cstddef>
5
#include <cstdio>
6
#include <memory>
7
#include <nlohmann/json_fwd.hpp>
8
#include <string>
9

10
#include "sdfg/builder/structured_sdfg_builder.h"
11
#include "sdfg/codegen/code_snippet_factory.h"
12
#include "sdfg/codegen/dispatchers/block_dispatcher.h"
13
#include "sdfg/codegen/language_extension.h"
14
#include "sdfg/codegen/utils.h"
15
#include "sdfg/data_flow/data_flow_graph.h"
16
#include "sdfg/data_flow/data_flow_node.h"
17
#include "sdfg/data_flow/library_node.h"
18
#include "sdfg/element.h"
19
#include "sdfg/exceptions.h"
20
#include "sdfg/function.h"
21
#include "sdfg/graph/graph.h"
22
#include "sdfg/structured_control_flow/block.h"
23
#include "sdfg/symbolic/symbolic.h"
24

25
namespace sdfg {
26
namespace stdlib {
27

28
AssertNode::AssertNode(
29
    size_t element_id,
30
    const DebugInfo& debug_info,
31
    const graph::Vertex vertex,
32
    data_flow::DataFlowGraph& parent,
33
    std::string message
34
)
NEW
35
    : StdlibNode(
×
36
          element_id,
×
37
          debug_info,
×
38
          vertex,
×
39
          parent,
×
40
          LibraryNodeType_Assert,
×
41
          {},
×
42
          {"_arg"},
×
43
          true,
×
44
          data_flow::ImplementationType_NONE
×
45
      ),
×
46
      message_(message) {}
×
47

48
std::string& AssertNode::message() { return this->message_; }
×
49

50
const std::string& AssertNode::message() const { return this->message_; }
×
51

52
std::string AssertNode::toStr() const {
×
53
    if (this->message_.empty()) {
×
54
        return "assert(_arg)";
×
55
    } else {
×
56
        return "assert(_arg && " + this->message_ + ")";
×
57
    }
×
58
}
×
59

60
symbolic::SymbolSet AssertNode::symbols() const { return {}; }
×
61

62
std::unique_ptr<data_flow::DataFlowNode> AssertNode::
UNCOV
63
    clone(size_t element_id, const graph::Vertex vertex, data_flow::DataFlowGraph& parent) const {
×
64
    return std::make_unique<AssertNode>(element_id, this->debug_info(), vertex, parent, this->message());
×
65
}
×
66

67
void AssertNode::replace(const symbolic::Expression old_expression, const symbolic::Expression new_expression) {}
×
68

69
nlohmann::json AssertNodeSerializer::serialize(const data_flow::LibraryNode& library_node) {
×
70
    const auto& assert_node = static_cast<const AssertNode&>(library_node);
×
71

72
    nlohmann::json j;
×
73
    j["code"] = assert_node.code().value();
×
74

75
    j["message"] = assert_node.message();
×
76

77
    return j;
×
78
}
×
79

80
data_flow::LibraryNode& AssertNodeSerializer::deserialize(
81
    const nlohmann::json& j, builder::StructuredSDFGBuilder& builder, structured_control_flow::Block& parent
82
) {
×
83
    assert(j.contains("code"));
×
84
    assert(j.contains("debug_info"));
×
85
    assert(j.contains("message"));
×
86

87
    auto code = j["code"].get<std::string>();
×
88
    if (code != LibraryNodeType_Assert.value()) {
×
89
        throw InvalidSDFGException("Invalid library node code");
×
90
    }
×
91

92
    sdfg::serializer::JSONSerializer serializer;
×
93
    DebugInfo debug_info = serializer.json_to_debug_info(j["debug_info"]);
×
94

95
    auto message = j["message"].get<std::string>();
×
96

97
    return builder.add_library_node<AssertNode>(parent, debug_info, message);
×
98
}
×
99

100
void AssertNodeDispatcher::escape_message(codegen::PrettyPrinter& stream, const std::string& message) {
×
101
    stream << "\"";
×
102
    for (unsigned char c : message) {
×
103
        switch (c) {
×
104
            case '\\':
×
105
                stream << "\\\\";
×
106
                break;
×
107
            case '\"':
×
108
                stream << "\\\"";
×
109
                break;
×
110
            case '\n':
×
111
                stream << "\\n";
×
112
                break;
×
113
            case '\r':
×
114
                stream << "\\r";
×
115
                break;
×
116
            case '\t':
×
117
                stream << "\\t";
×
118
                break;
×
119
            case '\v':
×
120
                stream << "\\v";
×
121
                break;
×
122
            case '\f':
×
123
                stream << "\\f";
×
124
                break;
×
125
            case '\b':
×
126
                stream << "\\b";
×
127
                break;
×
128
            case '\a':
×
129
                stream << "\\a";
×
130
                break;
×
131
            default:
×
132
                if (c < 0x20 || c == 0x7F) {
×
133
                    char buf[5];
×
134
                    std::snprintf(buf, sizeof(buf), "\\x%02X", (unsigned) c);
×
135
                    stream << buf;
×
136
                } else {
×
137
                    stream << static_cast<char>(c);
×
138
                }
×
139
        }
×
140
    }
×
141
    stream << "\"";
×
142
}
×
143

144
AssertNodeDispatcher::AssertNodeDispatcher(
145
    codegen::LanguageExtension& language_extension,
146
    const Function& function,
147
    const data_flow::DataFlowGraph& data_flow_graph,
148
    const data_flow::LibraryNode& node
149
)
150
    : codegen::LibraryNodeDispatcher(language_extension, function, data_flow_graph, node) {}
×
151

152
void AssertNodeDispatcher::dispatch_code(
153
    codegen::PrettyPrinter& stream,
154
    codegen::PrettyPrinter& globals_stream,
155
    codegen::CodeSnippetFactory& library_snippet_factory
156
) {
×
157
    auto& node = static_cast<const AssertNode&>(this->node_);
×
158

159
#ifndef __APPLE__
×
160
    std::string bool_cast = "";
×
161
#endif
×
162
    // Should be in include stream. Change when include handling is reworked!
163
    if (this->language_extension_.language() == "C") {
×
164
        globals_stream << "#include <assert.h>" << std::endl;
×
165
    } else {
×
166
        globals_stream << "#include <cassert>" << std::endl;
×
167
#ifndef __APPLE__
×
168
        bool_cast = "static_cast<bool>";
×
169
#endif
×
170
    }
×
171

172
#ifdef __APPLE__
173
    stream << "(__builtin_expect(!bool(" << node.input(0) << "), 0) ? __assert_rtn(__func__, __FILE__, __LINE__, \""
174
           << node.input(0) << "\"";
175
#else
176
    stream << "(" << bool_cast << "(" << node.input(0) << ") ? void (0) : __assert_fail(\"" << node.input(0) << "\"";
×
177
#endif
×
178
    if (!node.message().empty()) {
×
179
        stream << " \" && \" ";
×
180
        this->escape_message(stream, node.message());
×
181
    }
×
182
#ifdef __APPLE__
183
    stream << ") : (void) 0);" << std::endl;
184
#else
185
    stream << ", __FILE__, __LINE__, __extension__ __PRETTY_FUNCTION__));" << std::endl;
×
186
#endif
×
187
}
×
188

189
} // namespace stdlib
190
} // namespace sdfg
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