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

daisytuner / sdfglib / 20770413849

06 Jan 2026 10:50PM UTC coverage: 62.168% (+21.4%) from 40.764%
20770413849

push

github

web-flow
Merge pull request #433 from daisytuner/clang-coverage

updates clang coverage flags

14988 of 24109 relevant lines covered (62.17%)

88.57 hits per line

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

9.38
/src/data_flow/library_nodes/call_node.cpp
1
#include "sdfg/data_flow/library_nodes/call_node.h"
2

3
namespace sdfg {
4
namespace data_flow {
5

6
CallNode::CallNode(
7
    size_t element_id,
8
    const DebugInfo& debug_info,
9
    const graph::Vertex vertex,
10
    data_flow::DataFlowGraph& parent,
11
    const std::string& callee_name,
12
    const std::vector<std::string>& outputs,
13
    const std::vector<std::string>& inputs
14
)
15
    : LibraryNode(
2✔
16
          element_id,
2✔
17
          debug_info,
2✔
18
          vertex,
2✔
19
          parent,
2✔
20
          LibraryNodeType_Call,
2✔
21
          outputs,
2✔
22
          inputs,
2✔
23
          true,
2✔
24
          data_flow::ImplementationType_NONE
2✔
25
      ),
2✔
26
      callee_name_(callee_name) {}
2✔
27

28
const std::string& CallNode::callee_name() const { return this->callee_name_; }
×
29

30
bool CallNode::is_void(const Function& sdfg) const { return outputs_.empty() || outputs_.at(0) != "_ret"; }
×
31

32
bool CallNode::is_indirect_call(const Function& sdfg) const {
×
33
    auto& type = sdfg.type(this->callee_name_);
×
34
    return dynamic_cast<const types::Pointer*>(&type) != nullptr;
×
35
}
×
36

37
void CallNode::validate(const Function& function) const {
×
38
    if (!function.exists(this->callee_name_)) {
×
39
        throw InvalidSDFGException("CallNode: Function '" + this->callee_name_ + "' does not exist.");
×
40
    }
×
41
    auto& type = function.type(this->callee_name_);
×
42
    if (!dynamic_cast<const types::Function*>(&type) && !dynamic_cast<const types::Pointer*>(&type)) {
×
43
        throw InvalidSDFGException("CallNode: '" + this->callee_name_ + "' is not a function or pointer.");
×
44
    }
×
45

46
    if (auto func_type = dynamic_cast<const types::Function*>(&type)) {
×
47
        if (!function.is_external(this->callee_name_)) {
×
48
            throw InvalidSDFGException("CallNode: Function '" + this->callee_name_ + "' must be declared.");
×
49
        }
×
50
        if (!func_type->is_var_arg() && inputs_.size() != func_type->num_params()) {
×
51
            throw InvalidSDFGException(
×
52
                "CallNode: Number of inputs does not match number of function parameters. Expected " +
×
53
                std::to_string(func_type->num_params()) + ", got " + std::to_string(inputs_.size())
×
54
            );
×
55
        }
×
56
        if (!this->is_void(function) && outputs_.size() < 1) {
×
57
            throw InvalidSDFGException(
×
58
                "CallNode: Non-void function must have at least one output to store the return value."
×
59
            );
×
60
        }
×
61
    }
×
62
}
×
63

64
symbolic::SymbolSet CallNode::symbols() const { return {symbolic::symbol(this->callee_name_)}; }
×
65

66
std::unique_ptr<data_flow::DataFlowNode> CallNode::
67
    clone(size_t element_id, const graph::Vertex vertex, data_flow::DataFlowGraph& parent) const {
×
68
    return std::make_unique<CallNode>(element_id, debug_info_, vertex, parent, callee_name_, outputs_, inputs_);
×
69
}
×
70

71
void CallNode::replace(const symbolic::Expression old_expression, const symbolic::Expression new_expression) {}
×
72

73
nlohmann::json CallNodeSerializer::serialize(const data_flow::LibraryNode& library_node) {
×
74
    const CallNode& node = static_cast<const CallNode&>(library_node);
×
75

76
    nlohmann::json j;
×
77
    j["code"] = node.code().value();
×
78
    j["callee_name"] = node.callee_name();
×
79
    j["outputs"] = node.outputs();
×
80
    j["inputs"] = node.inputs();
×
81

82
    return j;
×
83
}
×
84

85
data_flow::LibraryNode& CallNodeSerializer::deserialize(
86
    const nlohmann::json& j, builder::StructuredSDFGBuilder& builder, structured_control_flow::Block& parent
87
) {
×
88
    assert(j.contains("code"));
×
89
    assert(j.contains("callee_name"));
×
90
    assert(j.contains("outputs"));
×
91
    assert(j.contains("inputs"));
×
92
    assert(j.contains("debug_info"));
×
93

94
    auto code = j["code"].get<std::string>();
×
95
    if (code != LibraryNodeType_Call.value()) {
×
96
        throw InvalidSDFGException("Invalid library node code");
×
97
    }
×
98

99
    sdfg::serializer::JSONSerializer serializer;
×
100
    DebugInfo debug_info = serializer.json_to_debug_info(j["debug_info"]);
×
101

102
    std::string callee_name = j["callee_name"].get<std::string>();
×
103
    auto outputs = j["outputs"].get<std::vector<std::string>>();
×
104
    auto inputs = j["inputs"].get<std::vector<std::string>>();
×
105

106
    return builder.add_library_node<CallNode>(parent, debug_info, callee_name, outputs, inputs);
×
107
}
×
108

109
CallNodeDispatcher::CallNodeDispatcher(
110
    codegen::LanguageExtension& language_extension,
111
    const Function& function,
112
    const data_flow::DataFlowGraph& data_flow_graph,
113
    const CallNode& node
114
)
115
    : codegen::LibraryNodeDispatcher(language_extension, function, data_flow_graph, node) {}
×
116

117
void CallNodeDispatcher::dispatch_code(
118
    codegen::PrettyPrinter& stream,
119
    codegen::PrettyPrinter& globals_stream,
120
    codegen::CodeSnippetFactory& library_snippet_factory
121
) {
×
122
    auto& node = static_cast<const CallNode&>(node_);
×
123

124
    if (!node.is_void(function_)) {
×
125
        stream << node.outputs().at(0) << " = ";
×
126
    }
×
127
    if (node.is_indirect_call(function_)) {
×
128
        auto& graph = node.get_parent();
×
129

130
        // Collect return memlet
131
        const data_flow::Memlet* ret_memlet = nullptr;
×
132
        for (auto& oedge : graph.out_edges(node)) {
×
133
            if (oedge.src_conn() == "_ret") {
×
134
                ret_memlet = &oedge;
×
135
                break;
×
136
            }
×
137
        }
×
138

139
        // Collect input memlets
140
        std::unordered_map<std::string, const data_flow::Memlet*> input_memlets;
×
141
        for (auto& iedge : graph.in_edges(node)) {
×
142
            input_memlets[iedge.dst_conn()] = &iedge;
×
143
        }
×
144

145
        // Cast callee to function pointer type
146
        std::string func_ptr_type;
×
147

148
        // Return type
149
        if (ret_memlet) {
×
150
            auto& ret_type = ret_memlet->result_type(function_);
×
151
            func_ptr_type = language_extension_.declaration("", ret_type) + " (*)";
×
152
        } else {
×
153
            func_ptr_type = "void (*)";
×
154
        }
×
155

156
        // Parameters
157
        func_ptr_type += "(";
×
158
        for (size_t i = 0; i < node.inputs().size(); i++) {
×
159
            auto memlet_in = input_memlets.find(node.inputs().at(i));
×
160
            assert(memlet_in != input_memlets.end());
×
161
            auto& in_type = memlet_in->second->result_type(function_);
×
162
            func_ptr_type += language_extension_.declaration("", in_type);
×
163
            if (i < node.inputs().size() - 1) {
×
164
                func_ptr_type += ", ";
×
165
            }
×
166
        }
×
167
        func_ptr_type += ")";
×
168

169
        if (this->language_extension_.language() == "C") {
×
170
            stream << "((" << func_ptr_type << ") " << node.callee_name() << ")" << "(";
×
171
        } else if (this->language_extension_.language() == "C++") {
×
172
            stream << "reinterpret_cast<" << func_ptr_type << ">(" << node.callee_name() << ")" << "(";
×
173
        }
×
174
    } else {
×
175
        stream << this->language_extension_.external_prefix() << node.callee_name() << "(";
×
176
    }
×
177
    for (size_t i = 0; i < node.inputs().size(); ++i) {
×
178
        stream << node.inputs().at(i);
×
179
        if (i < node.inputs().size() - 1) {
×
180
            stream << ", ";
×
181
        }
×
182
    }
×
183
    stream << ")" << ";";
×
184
    stream << std::endl;
×
185
}
×
186

187
} // namespace data_flow
188
} // 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