• 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

82.61
/src/codegen/code_generators/c_code_generator.cpp
1
#include "sdfg/codegen/code_generators/c_code_generator.h"
2

3
#include "sdfg/analysis/analysis.h"
4
#include "sdfg/analysis/users.h"
5
#include "sdfg/codegen/dispatchers/node_dispatcher_registry.h"
6
#include "sdfg/codegen/instrumentation/capture_var_plan.h"
7
#include "sdfg/codegen/instrumentation/instrumentation_plan.h"
8

9
namespace sdfg {
10
namespace codegen {
11

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

21
    return "extern void " + sdfg_.name() + "(" + arglist.str() + ")";
1✔
22
};
1✔
23

24
void CCodeGenerator::emit_capture_context_init(std::ostream& ofs_source) const {
1✔
25
    std::string name = sdfg_.name();
1✔
26

27
    ofs_source << "static void* __capture_ctx;" << std::endl;
1✔
28
    ofs_source << "static void __attribute__((constructor(1000))) __capture_ctx_init(void) {" << std::endl;
1✔
29
    ofs_source << "\t__capture_ctx = __daisy_capture_init(\"" << name << "\");" << std::endl;
1✔
30
    ofs_source << "}" << std::endl;
1✔
31
    ofs_source << std::endl;
1✔
32
}
1✔
33

34
void CCodeGenerator::dispatch_includes() {
4✔
35
    this->includes_stream_ << "#include <math.h>" << std::endl;
4✔
36
    this->includes_stream_ << "#include <cblas.h>" << std::endl;
4✔
37
    this->includes_stream_ << "#include <stdbool.h>" << std::endl;
4✔
38
    this->includes_stream_ << "#include <stdlib.h>" << std::endl;
4✔
39
    this->includes_stream_ << "#include <daisy_rtl/daisy_rtl.h>" << std::endl;
4✔
40
};
4✔
41

42
void CCodeGenerator::dispatch_structures() {
4✔
43
    // Forward declarations
44
    for (auto& structure : sdfg_.structures()) {
7✔
45
        this->classes_stream_ << "typedef struct " << structure << " " << structure << ";" << std::endl;
3✔
46
    }
47

48
    // Generate topology-sorted structure definitions
49
    typedef boost::adjacency_list<boost::vecS, boost::vecS, boost::bidirectionalS> structures_graph;
50
    typedef boost::graph_traits<structures_graph>::vertex_descriptor Vertex;
51
    std::vector<std::string> names;
4✔
52
    for (auto& structure : sdfg_.structures()) {
7✔
53
        names.push_back(structure);
3✔
54
    }
55
    structures_graph graph(names.size());
4✔
56

57
    for (auto& structure : names) {
7✔
58
        auto& definition = sdfg_.structure(structure);
3✔
59
        for (size_t i = 0; i < definition.num_members(); i++) {
6✔
60
            auto member_type = &definition.member_type(symbolic::integer(i));
3✔
61
            while (dynamic_cast<const types::Array*>(member_type)) {
3✔
UNCOV
62
                auto array_type = static_cast<const types::Array*>(member_type);
×
UNCOV
63
                member_type = &array_type->element_type();
×
64
            }
65

66
            if (auto member_structure = dynamic_cast<const sdfg::types::Structure*>(member_type)) {
3✔
67
                boost::add_edge(
1✔
68
                    std::find(names.begin(), names.end(), member_structure->name()) - names.begin(),
1✔
69
                    std::find(names.begin(), names.end(), structure) - names.begin(),
1✔
70
                    graph
71
                );
72
            }
1✔
73
        }
3✔
74
    }
75

76
    std::list<Vertex> order;
4✔
77
    std::unordered_map<Vertex, boost::default_color_type> vertex_colors;
4✔
78
    boost::topological_sort(
4✔
79
        graph, std::back_inserter(order), boost::color_map(boost::make_assoc_property_map(vertex_colors))
4✔
80
    );
81
    order.reverse();
4✔
82

83
    for (auto& structure_index : order) {
7✔
84
        std::string structure = names.at(structure_index);
3✔
85
        auto& definition = sdfg_.structure(structure);
3✔
86
        this->classes_stream_ << "typedef struct ";
3✔
87
        if (definition.is_packed()) {
3✔
UNCOV
88
            this->classes_stream_ << "__attribute__((packed)) ";
×
UNCOV
89
        }
×
90
        this->classes_stream_ << structure << std::endl;
3✔
91
        this->classes_stream_ << "{\n";
3✔
92

93
        for (size_t i = 0; i < definition.num_members(); i++) {
6✔
94
            auto& member_type = definition.member_type(symbolic::integer(i));
3✔
95
            if (auto pointer_type = dynamic_cast<const sdfg::types::Pointer*>(&member_type)) {
3✔
NEW
96
                if (pointer_type->has_pointee_type() &&
×
NEW
97
                    dynamic_cast<const sdfg::types::Structure*>(&pointer_type->pointee_type())) {
×
UNCOV
98
                    this->classes_stream_ << "struct ";
×
UNCOV
99
                }
×
UNCOV
100
            }
×
101
            this->classes_stream_
6✔
102
                << language_extension_.declaration("member_" + std::to_string(i), member_type, false, true);
3✔
103
            this->classes_stream_ << ";" << std::endl;
3✔
104
        }
3✔
105

106
        this->classes_stream_ << "} " << structure << ";" << std::endl;
3✔
107
    }
3✔
108
};
4✔
109

110
void CCodeGenerator::dispatch_globals() {
4✔
111
    // Externals are pointers. However, we need to declare them as the base type.
112
    for (auto& container : sdfg_.externals()) {
5✔
113
        auto& type = dynamic_cast<const types::Pointer&>(sdfg_.type(container));
1✔
114
        assert(type.has_pointee_type() && "Externals must have a pointee type");
2✔
115
        auto& base_type = type.pointee_type();
1✔
116
        this->globals_stream_ << "extern " << language_extension_.declaration(container, base_type) << ";" << std::endl;
1✔
117
    }
118
};
4✔
119

120
void CCodeGenerator::dispatch_schedule() {
4✔
121
    // Declare transient containers
122
    for (auto& container : sdfg_.containers()) {
5✔
123
        if (!sdfg_.is_transient(container)) {
1✔
124
            continue;
1✔
125
        }
126

UNCOV
127
        std::string val = this->language_extension_.declaration(container, sdfg_.type(container), false, true);
×
UNCOV
128
        if (!val.empty()) {
×
UNCOV
129
            this->main_stream_ << val;
×
UNCOV
130
            this->main_stream_ << ";" << std::endl;
×
UNCOV
131
        }
×
UNCOV
132
    }
×
133

134
    auto dispatcher = create_dispatcher(language_extension_, sdfg_, sdfg_.root(), instrumentation_plan_);
4✔
135
    dispatcher->dispatch(this->main_stream_, this->globals_stream_, this->library_snippet_factory_);
4✔
136
};
4✔
137

138
} // namespace codegen
139
} // 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