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

daisytuner / sdfglib / 18952417028

30 Oct 2025 07:15PM UTC coverage: 62.285% (+0.002%) from 62.283%
18952417028

push

github

web-flow
Merge pull request #317 from daisytuner/recursive-ext

fixes code generated for recursive calls

5 of 6 new or added lines in 4 files covered. (83.33%)

1 existing line in 1 file now uncovered.

10122 of 16251 relevant lines covered (62.29%)

102.89 hits per line

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

0.0
/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
    bool offloadable
15
)
16
    : LibraryNode(
×
17
          element_id,
×
18
          debug_info,
×
19
          vertex,
×
20
          parent,
×
21
          LibraryNodeType_Call,
22
          outputs,
×
23
          inputs,
×
24
          true,
25
          data_flow::ImplementationType_NONE
26
      ),
27
      callee_name_(callee_name), offloadable_(offloadable) {}
×
28

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

31
bool CallNode::offloadable() const { return this->offloadable_; }
×
32

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

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

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

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

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

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

74
void CallNode::replace(const symbolic::Expression old_expression, const symbolic::Expression new_expression) {}
×
75

76
nlohmann::json CallNodeSerializer::serialize(const data_flow::LibraryNode& library_node) {
×
77
    const CallNode& node = static_cast<const CallNode&>(library_node);
×
78

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

85
    return j;
×
86
}
×
87

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

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

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

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

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

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

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

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

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

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

148
        // Cast callee to function pointer type
149
        std::string func_ptr_type;
×
150

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

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

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

190
} // namespace data_flow
191
} // 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