• 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

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

3
namespace sdfg {
4
namespace data_flow {
5

6
InvokeNode::InvokeNode(
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(
×
16
          element_id,
×
17
          debug_info,
×
18
          vertex,
×
19
          parent,
×
20
          LibraryNodeType_Invoke,
×
21
          outputs,
×
22
          inputs,
×
23
          true,
×
24
          data_flow::ImplementationType_NONE
×
25
      ),
×
26
      callee_name_(callee_name) {
×
27
    this->outputs_.push_back("_unwind"); // Add unwind output
×
28
}
×
29

30
const std::string& InvokeNode::callee_name() const { return this->callee_name_; }
×
31

32
bool InvokeNode::is_void(const Function& sdfg) const { return outputs_.size() == 1 || outputs_.at(0) != "_ret"; }
×
33

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

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

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

66
symbolic::SymbolSet InvokeNode::symbols() const { return {symbolic::symbol(this->callee_name_)}; }
×
67

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

73
void InvokeNode::replace(const symbolic::Expression old_expression, const symbolic::Expression new_expression) {}
×
74

75
nlohmann::json InvokeNodeSerializer::serialize(const data_flow::LibraryNode& library_node) {
×
76
    const InvokeNode& node = static_cast<const InvokeNode&>(library_node);
×
77

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

84
    return j;
×
85
}
×
86

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

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

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

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

108
    return builder.add_library_node<InvokeNode>(parent, debug_info, callee_name, outputs, inputs);
×
109
}
×
110

111
InvokeNodeDispatcher::InvokeNodeDispatcher(
112
    codegen::LanguageExtension& language_extension,
113
    const Function& function,
114
    const data_flow::DataFlowGraph& data_flow_graph,
115
    const InvokeNode& node
116
)
117
    : codegen::LibraryNodeDispatcher(language_extension, function, data_flow_graph, node) {}
×
118

119
void InvokeNodeDispatcher::dispatch_code(
120
    codegen::PrettyPrinter& stream,
121
    codegen::PrettyPrinter& globals_stream,
122
    codegen::CodeSnippetFactory& library_snippet_factory
123
) {
×
124
    auto& node = static_cast<const InvokeNode&>(node_);
×
125

126
    stream << "try {" << std::endl;
×
127
    stream.setIndent(stream.indent() + 4);
×
128

129
    if (!node.is_void(function_)) {
×
130
        stream << node.outputs().at(0) << " = ";
×
131
    }
×
132
    if (node.is_indirect_call(function_)) {
×
133
        auto& graph = node.get_parent();
×
134

135
        // Collect return memlet
136
        const data_flow::Memlet* ret_memlet = nullptr;
×
137
        for (auto& oedge : graph.out_edges(node)) {
×
138
            if (oedge.src_conn() == "_ret") {
×
139
                ret_memlet = &oedge;
×
140
                break;
×
141
            }
×
142
        }
×
143

144
        // Collect input memlets
145
        std::unordered_map<std::string, const data_flow::Memlet*> input_memlets;
×
146
        for (auto& iedge : graph.in_edges(node)) {
×
147
            input_memlets[iedge.dst_conn()] = &iedge;
×
148
        }
×
149

150
        // Cast callee to function pointer type
151
        std::string func_ptr_type;
×
152

153
        // Return type
154
        if (ret_memlet) {
×
155
            auto& ret_type = ret_memlet->result_type(function_);
×
156
            func_ptr_type = language_extension_.declaration("", ret_type) + " (*)";
×
157
        } else {
×
158
            func_ptr_type = "void (*)";
×
159
        }
×
160

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

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

191
    stream << node_.outputs().at(node.outputs().size() - 1) << " = false;" << std::endl;
×
192
    stream.setIndent(stream.indent() - 4);
×
193
    stream << "} catch (...) {" << std::endl;
×
194
    stream.setIndent(stream.indent() + 4);
×
195
    stream << node_.outputs().at(node.outputs().size() - 1) << " = true;" << std::endl;
×
196
    stream.setIndent(stream.indent() - 4);
×
197
    stream << "}" << std::endl;
×
198
}
×
199

200
} // namespace data_flow
201
} // 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