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

daisytuner / sdfglib / 16779684622

06 Aug 2025 02:21PM UTC coverage: 64.3% (-1.0%) from 65.266%
16779684622

push

github

web-flow
Merge pull request #172 from daisytuner/opaque-pointers

Opaque pointers, typed memlets, untyped tasklet connectors

330 of 462 new or added lines in 38 files covered. (71.43%)

382 existing lines in 30 files now uncovered.

8865 of 13787 relevant lines covered (64.3%)

116.73 hits per line

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

80.46
/src/codegen/code_generators/cpp_code_generator.cpp
1
#include "sdfg/codegen/code_generators/cpp_code_generator.h"
2

3
#include "sdfg/codegen/dispatchers/node_dispatcher_registry.h"
4
#include "sdfg/codegen/instrumentation/instrumentation_plan.h"
5

6
namespace sdfg {
7
namespace codegen {
8

9
std::string CPPCodeGenerator::function_definition() {
1✔
10
    /********** Arglist **********/
11
    std::vector<std::string> args;
1✔
12
    for (auto& container : sdfg_.arguments()) {
1✔
UNCOV
13
        args.push_back(language_extension_.declaration(container, sdfg_.type(container)));
×
14
    }
15
    std::stringstream arglist;
1✔
16
    arglist << sdfg::helpers::join(args, ", ");
1✔
17

18
    return "extern \"C\" void " + sdfg_.name() + "(" + arglist.str() + ")";
1✔
19
};
1✔
20

UNCOV
21
void CPPCodeGenerator::emit_capture_context_init(std::ostream& ofs_source) const {
×
22
    std::string name = sdfg_.name();
×
23

UNCOV
24
    ofs_source << "static void* __capture_ctx;" << std::endl;
×
25
    ofs_source << "static void __attribute__((constructor(1000))) __capture_ctx_init(void) {" << std::endl;
×
26
    ofs_source << "\t__capture_ctx = __daisy_capture_init(\"" << name << "\");" << std::endl;
×
27
    ofs_source << "}" << std::endl;
×
28
    ofs_source << std::endl;
×
29
}
×
30

31
void CPPCodeGenerator::dispatch_includes() {
5✔
32
    this->includes_stream_ << "#include <cmath>" << std::endl;
5✔
33
    this->includes_stream_ << "#include <cblas.h>" << std::endl;
5✔
34
    this->includes_stream_ << "#include <daisy_rtl/daisy_rtl.h>" << std::endl;
5✔
35
};
5✔
36

37
void CPPCodeGenerator::dispatch_structures() {
5✔
38
    // Forward declarations
39
    for (auto& structure : sdfg_.structures()) {
9✔
40
        this->classes_stream_ << "struct " << structure << ";" << std::endl;
4✔
41
    }
42

43
    // Generate topology-sorted structure definitions
44
    typedef boost::adjacency_list<boost::vecS, boost::vecS, boost::bidirectionalS> structures_graph;
45
    typedef boost::graph_traits<structures_graph>::vertex_descriptor Vertex;
46
    std::vector<std::string> names;
5✔
47
    for (auto& structure : sdfg_.structures()) {
9✔
48
        names.push_back(structure);
4✔
49
    }
50
    structures_graph graph(names.size());
5✔
51

52
    for (auto& structure : names) {
9✔
53
        auto& definition = sdfg_.structure(structure);
4✔
54
        for (size_t i = 0; i < definition.num_members(); i++) {
8✔
55
            auto member_type = &definition.member_type(symbolic::integer(i));
4✔
56
            while (dynamic_cast<const types::Array*>(member_type)) {
4✔
UNCOV
57
                auto array_type = static_cast<const types::Array*>(member_type);
×
UNCOV
58
                member_type = &array_type->element_type();
×
59
            }
60

61
            if (auto member_structure = dynamic_cast<const sdfg::types::Structure*>(member_type)) {
4✔
62
                boost::add_edge(
1✔
63
                    std::find(names.begin(), names.end(), member_structure->name()) - names.begin(),
1✔
64
                    std::find(names.begin(), names.end(), structure) - names.begin(),
1✔
65
                    graph
66
                );
67
            }
1✔
68
        }
4✔
69
    }
70

71
    std::list<Vertex> order;
5✔
72
    std::unordered_map<Vertex, boost::default_color_type> vertex_colors;
5✔
73
    boost::topological_sort(
5✔
74
        graph, std::back_inserter(order), boost::color_map(boost::make_assoc_property_map(vertex_colors))
5✔
75
    );
76
    order.reverse();
5✔
77

78
    for (auto& structure_index : order) {
9✔
79
        std::string structure = names.at(structure_index);
4✔
80
        auto& definition = sdfg_.structure(structure);
4✔
81
        this->classes_stream_ << "struct ";
4✔
82
        if (definition.is_packed()) {
4✔
83
            this->classes_stream_ << "__attribute__((packed)) ";
1✔
84
        }
1✔
85
        this->classes_stream_ << structure << std::endl;
4✔
86
        this->classes_stream_ << "{\n";
4✔
87

88
        for (size_t i = 0; i < definition.num_members(); i++) {
8✔
89
            auto& member_type = definition.member_type(symbolic::integer(i));
4✔
90
            if (dynamic_cast<const sdfg::types::Structure*>(&member_type)) {
4✔
91
                this->classes_stream_ << "struct ";
1✔
92
            }
1✔
93
            this->classes_stream_
8✔
94
                << language_extension_.declaration("member_" + std::to_string(i), member_type, false, true);
4✔
95
            this->classes_stream_ << ";" << std::endl;
4✔
96
        }
4✔
97

98
        this->classes_stream_ << "};" << std::endl;
4✔
99
    }
4✔
100
};
5✔
101

102
void CPPCodeGenerator::dispatch_globals() {
5✔
103
    // Externals are pointers. However, we need to declare them as the base type.
104
    for (auto& container : sdfg_.externals()) {
6✔
105
        auto& type = dynamic_cast<const types::Pointer&>(sdfg_.type(container));
1✔
106
        assert(type.has_pointee_type() && "Externals must have a pointee type");
2✔
107
        auto& base_type = type.pointee_type();
1✔
108
        this->globals_stream_ << "extern " << language_extension_.declaration(container, base_type) << ";" << std::endl;
1✔
109
    }
110
};
5✔
111

112
void CPPCodeGenerator::dispatch_schedule() {
5✔
113
    // Declare transient containers
114
    for (auto& container : sdfg_.containers()) {
6✔
115
        if (!sdfg_.is_transient(container)) {
1✔
116
            continue;
1✔
117
        }
118

UNCOV
119
        std::string val = this->language_extension_.declaration(container, sdfg_.type(container), false, true);
×
UNCOV
120
        if (!val.empty()) {
×
UNCOV
121
            this->main_stream_ << val;
×
UNCOV
122
            this->main_stream_ << ";" << std::endl;
×
UNCOV
123
        }
×
124
    }
×
125

126
    auto dispatcher = create_dispatcher(language_extension_, sdfg_, sdfg_.root(), instrumentation_plan_);
5✔
127
    dispatcher->dispatch(this->main_stream_, this->globals_stream_, this->library_snippet_factory_);
5✔
128
};
5✔
129

130
} // namespace codegen
131
} // 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