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

daisytuner / sdfglib / 15519619127

08 Jun 2025 02:47PM UTC coverage: 61.731% (+0.08%) from 61.652%
15519619127

push

github

web-flow
Merge pull request #66 from daisytuner/libnodes-serialization

Adds custom serialization for library nodes

37 of 56 new or added lines in 6 files covered. (66.07%)

2 existing lines in 2 files now uncovered.

7259 of 11759 relevant lines covered (61.73%)

123.38 hits per line

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

83.09
/src/serializer/json_serializer.cpp
1
#include "sdfg/serializer/json_serializer.h"
2

3
#include <cassert>
4
#include <memory>
5
#include <unordered_map>
6
#include <utility>
7
#include <vector>
8

9
#include "sdfg/builder/structured_sdfg_builder.h"
10
#include "sdfg/data_flow/library_node.h"
11
#include "sdfg/element.h"
12
#include "sdfg/structured_control_flow/block.h"
13
#include "sdfg/structured_control_flow/for.h"
14
#include "sdfg/structured_control_flow/if_else.h"
15
#include "sdfg/structured_control_flow/return.h"
16
#include "sdfg/structured_control_flow/sequence.h"
17
#include "sdfg/structured_control_flow/while.h"
18
#include "sdfg/structured_sdfg.h"
19
#include "sdfg/symbolic/symbolic.h"
20
#include "sdfg/types/function.h"
21
#include "sdfg/types/scalar.h"
22
#include "sdfg/types/type.h"
23
#include "symengine/expression.h"
24
#include "symengine/logic.h"
25
#include "symengine/symengine_rcp.h"
26

27
namespace sdfg {
28
namespace serializer {
29

30
/*
31
 * * JSONSerializer class
32
 * * Serialization logic
33
 */
34

35
nlohmann::json JSONSerializer::serialize(std::unique_ptr<sdfg::StructuredSDFG>& sdfg) {
3✔
36
    nlohmann::json j;
3✔
37

38
    j["name"] = sdfg->name();
3✔
39
    j["type"] = std::string(sdfg->type().value());
3✔
40

41
    j["structures"] = nlohmann::json::array();
3✔
42
    for (const auto& structure_name : sdfg->structures()) {
3✔
43
        const auto& structure = sdfg->structure(structure_name);
×
44
        nlohmann::json structure_json;
×
45
        structure_definition_to_json(structure_json, structure);
×
46
        j["structures"].push_back(structure_json);
×
47
    }
×
48

49
    j["containers"] = nlohmann::json::object();
3✔
50
    for (const auto& container : sdfg->containers()) {
8✔
51
        nlohmann::json desc;
5✔
52
        type_to_json(desc, sdfg->type(container));
5✔
53
        j["containers"][container] = desc;
5✔
54
    }
5✔
55

56
    j["arguments"] = nlohmann::json::array();
3✔
57
    for (const auto& argument : sdfg->arguments()) {
5✔
58
        j["arguments"].push_back(argument);
2✔
59
    }
60

61
    j["externals"] = nlohmann::json::array();
3✔
62
    for (const auto& external : sdfg->externals()) {
3✔
63
        j["externals"].push_back(external);
×
64
    }
65

66
    j["metadata"] = nlohmann::json::object();
3✔
67
    for (const auto& entry : sdfg->metadata()) {
4✔
68
        j["metadata"][entry.first] = entry.second;
1✔
69
    }
70

71
    // Walk the SDFG
72
    nlohmann::json root_json;
3✔
73
    sequence_to_json(root_json, sdfg->root());
3✔
74
    j["root"] = root_json;
3✔
75

76
    return j;
3✔
77
}
3✔
78

79
void JSONSerializer::dataflow_to_json(nlohmann::json& j, const data_flow::DataFlowGraph& dataflow) {
20✔
80
    j["type"] = "dataflow";
20✔
81
    j["nodes"] = nlohmann::json::array();
20✔
82
    j["edges"] = nlohmann::json::array();
20✔
83

84
    for (auto& node : dataflow.nodes()) {
40✔
85
        nlohmann::json node_json;
20✔
86
        node_json["element_id"] = node.element_id();
20✔
87

88
        node_json["debug_info"] = nlohmann::json::object();
20✔
89
        debug_info_to_json(node_json["debug_info"], node.debug_info());
20✔
90

91
        if (auto tasklet = dynamic_cast<const data_flow::Tasklet*>(&node)) {
20✔
92
            node_json["type"] = "tasklet";
5✔
93
            node_json["code"] = tasklet->code();
5✔
94
            node_json["inputs"] = nlohmann::json::array();
5✔
95
            for (auto& input : tasklet->inputs()) {
15✔
96
                nlohmann::json input_json;
10✔
97
                nlohmann::json type_json;
10✔
98
                type_to_json(type_json, input.second);
10✔
99
                input_json["type"] = type_json;
10✔
100
                input_json["name"] = input.first;
10✔
101
                node_json["inputs"].push_back(input_json);
10✔
102
            }
10✔
103
            node_json["output"] = nlohmann::json::object();
5✔
104
            node_json["output"]["name"] = tasklet->output().first;
5✔
105
            nlohmann::json type_json;
5✔
106
            type_to_json(type_json, tasklet->output().second);
5✔
107
            node_json["output"]["type"] = type_json;
5✔
108
            // node_json["conditional"] = tasklet->is_conditional();
109
            // if (tasklet->is_conditional()) {
110
            //     node_json["condition"] = dumps_expression(tasklet->condition());
111
            // }
112
        } else if (auto lib_node = dynamic_cast<const data_flow::LibraryNode*>(&node)) {
20✔
113
            auto serializer_fn =
NEW
114
                LibraryNodeSerializerRegistry::instance().get_library_node_serializer(
×
NEW
115
                    lib_node->code().value());
×
NEW
116
            if (serializer_fn == nullptr) {
×
NEW
117
                throw std::runtime_error("Unknown library node code: " +
×
NEW
118
                                         std::string(lib_node->code().value()));
×
119
            }
NEW
120
            auto serializer = serializer_fn();
×
NEW
121
            auto lib_node_json = serializer->serialize(*lib_node);
×
NEW
122
            node_json.merge_patch(lib_node_json);
×
123
        } else if (auto code_node = dynamic_cast<const data_flow::AccessNode*>(&node)) {
15✔
124
            node_json["type"] = "access_node";
15✔
125
            node_json["data"] = code_node->data();
15✔
126
        } else {
15✔
127
            throw std::runtime_error("Unknown node type");
×
128
        }
129

130
        j["nodes"].push_back(node_json);
20✔
131
    }
20✔
132

133
    for (auto& edge : dataflow.edges()) {
35✔
134
        nlohmann::json edge_json;
15✔
135
        edge_json["element_id"] = edge.element_id();
15✔
136

137
        edge_json["debug_info"] = nlohmann::json::object();
15✔
138
        debug_info_to_json(edge_json["debug_info"], edge.debug_info());
15✔
139

140
        edge_json["src"] = edge.src().element_id();
15✔
141
        edge_json["dst"] = edge.dst().element_id();
15✔
142

143
        edge_json["src_conn"] = edge.src_conn();
15✔
144
        edge_json["dst_conn"] = edge.dst_conn();
15✔
145

146
        edge_json["subset"] = nlohmann::json::array();
15✔
147
        for (auto& subset : edge.subset()) {
21✔
148
            edge_json["subset"].push_back(expression(subset));
6✔
149
        }
150

151
        j["edges"].push_back(edge_json);
15✔
152
    }
15✔
153
}
20✔
154

155
void JSONSerializer::block_to_json(nlohmann::json& j, const structured_control_flow::Block& block) {
18✔
156
    j["type"] = "block";
18✔
157
    j["element_id"] = block.element_id();
18✔
158

159
    j["debug_info"] = nlohmann::json::object();
18✔
160
    debug_info_to_json(j["debug_info"], block.debug_info());
18✔
161

162
    nlohmann::json dataflow_json;
18✔
163
    dataflow_to_json(dataflow_json, block.dataflow());
18✔
164
    j["dataflow"] = dataflow_json;
18✔
165
}
18✔
166

167
void JSONSerializer::for_to_json(nlohmann::json& j, const structured_control_flow::For& for_node) {
2✔
168
    j["type"] = "for";
2✔
169
    j["element_id"] = for_node.element_id();
2✔
170

171
    j["debug_info"] = nlohmann::json::object();
2✔
172
    debug_info_to_json(j["debug_info"], for_node.debug_info());
2✔
173

174
    j["indvar"] = expression(for_node.indvar());
2✔
175
    j["init"] = expression(for_node.init());
2✔
176
    j["condition"] = expression(for_node.condition());
2✔
177
    j["update"] = expression(for_node.update());
2✔
178

179
    nlohmann::json body_json;
2✔
180
    sequence_to_json(body_json, for_node.root());
2✔
181
    j["root"] = body_json;
2✔
182
}
2✔
183

184
void JSONSerializer::if_else_to_json(nlohmann::json& j,
2✔
185
                                     const structured_control_flow::IfElse& if_else_node) {
186
    j["type"] = "if_else";
2✔
187
    j["element_id"] = if_else_node.element_id();
2✔
188

189
    j["debug_info"] = nlohmann::json::object();
2✔
190
    debug_info_to_json(j["debug_info"], if_else_node.debug_info());
2✔
191

192
    j["branches"] = nlohmann::json::array();
2✔
193
    for (size_t i = 0; i < if_else_node.size(); i++) {
6✔
194
        nlohmann::json branch_json;
4✔
195
        branch_json["condition"] = expression(if_else_node.at(i).second);
4✔
196
        nlohmann::json body_json;
4✔
197
        sequence_to_json(body_json, if_else_node.at(i).first);
4✔
198
        branch_json["root"] = body_json;
4✔
199
        j["branches"].push_back(branch_json);
4✔
200
    }
4✔
201
}
2✔
202

203
void JSONSerializer::while_node_to_json(nlohmann::json& j,
5✔
204
                                        const structured_control_flow::While& while_node) {
205
    j["type"] = "while";
5✔
206
    j["element_id"] = while_node.element_id();
5✔
207

208
    j["debug_info"] = nlohmann::json::object();
5✔
209
    debug_info_to_json(j["debug_info"], while_node.debug_info());
5✔
210

211
    nlohmann::json body_json;
5✔
212
    sequence_to_json(body_json, while_node.root());
5✔
213
    j["root"] = body_json;
5✔
214
}
5✔
215

216
void JSONSerializer::break_node_to_json(nlohmann::json& j,
2✔
217
                                        const structured_control_flow::Break& break_node) {
218
    j["type"] = "break";
2✔
219
    j["element_id"] = break_node.element_id();
2✔
220

221
    j["debug_info"] = nlohmann::json::object();
2✔
222
    debug_info_to_json(j["debug_info"], break_node.debug_info());
2✔
223
}
2✔
224

225
void JSONSerializer::continue_node_to_json(nlohmann::json& j,
2✔
226
                                           const structured_control_flow::Continue& continue_node) {
227
    j["type"] = "continue";
2✔
228
    j["element_id"] = continue_node.element_id();
2✔
229

230
    j["debug_info"] = nlohmann::json::object();
2✔
231
    debug_info_to_json(j["debug_info"], continue_node.debug_info());
2✔
232
}
2✔
233

234
void JSONSerializer::map_to_json(nlohmann::json& j, const structured_control_flow::Map& map_node) {
2✔
235
    j["type"] = "map";
2✔
236
    j["element_id"] = map_node.element_id();
2✔
237

238
    j["debug_info"] = nlohmann::json::object();
2✔
239
    debug_info_to_json(j["debug_info"], map_node.debug_info());
2✔
240

241
    j["indvar"] = expression(map_node.indvar());
2✔
242
    j["num_iterations"] = expression(map_node.num_iterations());
2✔
243
    j["schedule_type"] = std::string(map_node.schedule_type().value());
2✔
244

245
    nlohmann::json body_json;
2✔
246
    sequence_to_json(body_json, map_node.root());
2✔
247
    j["root"] = body_json;
2✔
248
}
2✔
249

250
void JSONSerializer::return_node_to_json(nlohmann::json& j,
2✔
251
                                         const structured_control_flow::Return& return_node) {
252
    j["type"] = "return";
2✔
253
    j["element_id"] = return_node.element_id();
2✔
254

255
    j["debug_info"] = nlohmann::json::object();
2✔
256
    debug_info_to_json(j["debug_info"], return_node.debug_info());
2✔
257
}
2✔
258

259
void JSONSerializer::sequence_to_json(nlohmann::json& j,
19✔
260
                                      const structured_control_flow::Sequence& sequence) {
261
    j["type"] = "sequence";
19✔
262
    j["element_id"] = sequence.element_id();
19✔
263

264
    j["debug_info"] = nlohmann::json::object();
19✔
265
    debug_info_to_json(j["debug_info"], sequence.debug_info());
19✔
266

267
    j["children"] = nlohmann::json::array();
19✔
268
    j["transitions"] = nlohmann::json::array();
19✔
269

270
    for (size_t i = 0; i < sequence.size(); i++) {
39✔
271
        nlohmann::json child_json;
20✔
272
        auto& child = sequence.at(i).first;
20✔
273
        auto& transition = sequence.at(i).second;
20✔
274

275
        if (auto block = dynamic_cast<const structured_control_flow::Block*>(&child)) {
20✔
276
            block_to_json(child_json, *block);
16✔
277
        } else if (auto for_node = dynamic_cast<const structured_control_flow::For*>(&child)) {
20✔
278
            for_to_json(child_json, *for_node);
×
279
        } else if (auto sequence_node =
4✔
280
                       dynamic_cast<const structured_control_flow::Sequence*>(&child)) {
4✔
281
            sequence_to_json(child_json, *sequence_node);
×
282
        } else if (auto condition_node =
4✔
283
                       dynamic_cast<const structured_control_flow::IfElse*>(&child)) {
4✔
284
            if_else_to_json(child_json, *condition_node);
×
285
        } else if (auto while_node = dynamic_cast<const structured_control_flow::While*>(&child)) {
4✔
286
            while_node_to_json(child_json, *while_node);
×
287
        } else if (auto return_node =
4✔
288
                       dynamic_cast<const structured_control_flow::Return*>(&child)) {
4✔
289
            return_node_to_json(child_json, *return_node);
×
290
        } else if (auto break_node = dynamic_cast<const structured_control_flow::Break*>(&child)) {
4✔
291
            break_node_to_json(child_json, *break_node);
2✔
292
        } else if (auto continue_node =
4✔
293
                       dynamic_cast<const structured_control_flow::Continue*>(&child)) {
2✔
294
            continue_node_to_json(child_json, *continue_node);
2✔
295
        } else if (auto map_node = dynamic_cast<const structured_control_flow::Map*>(&child)) {
2✔
296
            map_to_json(child_json, *map_node);
×
297
        } else {
×
298
            throw std::runtime_error("Unknown child type");
×
299
        }
300

301
        j["children"].push_back(child_json);
20✔
302

303
        // Add transition information
304
        nlohmann::json transition_json;
20✔
305
        transition_json["type"] = "transition";
20✔
306
        transition_json["element_id"] = transition.element_id();
20✔
307

308
        transition_json["debug_info"] = nlohmann::json::object();
20✔
309
        debug_info_to_json(transition_json["debug_info"], transition.debug_info());
20✔
310

311
        transition_json["assignments"] = nlohmann::json::array();
20✔
312
        for (const auto& assignment : transition.assignments()) {
22✔
313
            nlohmann::json assignment_json;
2✔
314
            assignment_json["symbol"] = expression(assignment.first);
2✔
315
            assignment_json["expression"] = expression(assignment.second);
2✔
316
            transition_json["assignments"].push_back(assignment_json);
2✔
317
        }
2✔
318

319
        j["transitions"].push_back(transition_json);
20✔
320
    }
20✔
321
}
19✔
322

323
void JSONSerializer::type_to_json(nlohmann::json& j, const types::IType& type) {
43✔
324
    if (auto scalar_type = dynamic_cast<const types::Scalar*>(&type)) {
43✔
325
        j["type"] = "scalar";
33✔
326
        j["primitive_type"] = scalar_type->primitive_type();
33✔
327
        j["storage_type"] = std::string(scalar_type->storage_type().value());
33✔
328
        j["initializer"] = scalar_type->initializer();
33✔
329
        j["alignment"] = scalar_type->alignment();
33✔
330
    } else if (auto array_type = dynamic_cast<const types::Array*>(&type)) {
43✔
331
        j["type"] = "array";
3✔
332
        nlohmann::json element_type_json;
3✔
333
        type_to_json(element_type_json, array_type->element_type());
3✔
334
        j["element_type"] = element_type_json;
3✔
335
        j["num_elements"] = expression(array_type->num_elements());
3✔
336
        j["storage_type"] = std::string(array_type->storage_type().value());
3✔
337
        j["initializer"] = array_type->initializer();
3✔
338
        j["alignment"] = array_type->alignment();
3✔
339
    } else if (auto pointer_type = dynamic_cast<const types::Pointer*>(&type)) {
10✔
340
        j["type"] = "pointer";
3✔
341
        nlohmann::json pointee_type_json;
3✔
342
        type_to_json(pointee_type_json, pointer_type->pointee_type());
3✔
343
        j["pointee_type"] = pointee_type_json;
3✔
344
        j["storage_type"] = std::string(pointer_type->storage_type().value());
3✔
345
        j["initializer"] = pointer_type->initializer();
3✔
346
        j["alignment"] = pointer_type->alignment();
3✔
347
    } else if (auto structure_type = dynamic_cast<const types::Structure*>(&type)) {
7✔
348
        j["type"] = "structure";
2✔
349
        j["name"] = structure_type->name();
2✔
350
        j["storage_type"] = std::string(structure_type->storage_type().value());
2✔
351
        j["initializer"] = structure_type->initializer();
2✔
352
        j["alignment"] = structure_type->alignment();
2✔
353
    } else if (auto function_type = dynamic_cast<const types::Function*>(&type)) {
4✔
354
        j["type"] = "function";
2✔
355
        nlohmann::json return_type_json;
2✔
356
        type_to_json(return_type_json, function_type->return_type());
2✔
357
        j["return_type"] = return_type_json;
2✔
358
        j["params"] = nlohmann::json::array();
2✔
359
        for (size_t i = 0; i < function_type->num_params(); i++) {
5✔
360
            nlohmann::json param_json;
3✔
361
            type_to_json(param_json, function_type->param_type(symbolic::integer(i)));
3✔
362
            j["params"].push_back(param_json);
3✔
363
        }
3✔
364
        j["is_var_arg"] = function_type->is_var_arg();
2✔
365
        j["storage_type"] = std::string(function_type->storage_type().value());
2✔
366
        j["initializer"] = function_type->initializer();
2✔
367
        j["alignment"] = function_type->alignment();
2✔
368
    } else {
2✔
369
        throw std::runtime_error("Unknown type");
×
370
    }
371
}
43✔
372

373
void JSONSerializer::structure_definition_to_json(nlohmann::json& j,
1✔
374
                                                  const types::StructureDefinition& definition) {
375
    j["name"] = definition.name();
1✔
376
    j["members"] = nlohmann::json::array();
1✔
377
    for (size_t i = 0; i < definition.num_members(); i++) {
3✔
378
        nlohmann::json member_json;
2✔
379
        type_to_json(member_json, definition.member_type(symbolic::integer(i)));
2✔
380
        j["members"].push_back(member_json);
2✔
381
    }
2✔
382
    j["is_packed"] = definition.is_packed();
1✔
383
}
1✔
384

385
void JSONSerializer::debug_info_to_json(nlohmann::json& j, const DebugInfo& debug_info) {
109✔
386
    j["has"] = debug_info.has();
109✔
387
    j["filename"] = debug_info.filename();
109✔
388
    j["start_line"] = debug_info.start_line();
109✔
389
    j["start_column"] = debug_info.start_column();
109✔
390
    j["end_line"] = debug_info.end_line();
109✔
391
    j["end_column"] = debug_info.end_column();
109✔
392
}
109✔
393

394
/*
395
 * * Deserialization logic
396
 */
397

398
std::unique_ptr<StructuredSDFG> JSONSerializer::deserialize(nlohmann::json& j) {
3✔
399
    assert(j.contains("name"));
3✔
400
    assert(j["name"].is_string());
3✔
401
    assert(j.contains("type"));
3✔
402
    assert(j["type"].is_string());
3✔
403

404
    FunctionType type{"Unknown"};
3✔
405
    if (j["type"] == FunctionType_CPU.value()) {
3✔
406
        type = FunctionType_CPU;
3✔
407
    } else if (j["type"] == FunctionType_NV_GLOBAL.value()) {
3✔
408
        type = FunctionType_NV_GLOBAL;
×
409
    } else {
×
410
        throw std::runtime_error("Unknown function type");
×
411
    }
412
    builder::StructuredSDFGBuilder builder(j["name"], type);
3✔
413

414
    // deserialize structures
415
    assert(j.contains("structures"));
3✔
416
    assert(j["structures"].is_array());
3✔
417
    for (const auto& structure : j["structures"]) {
3✔
418
        assert(structure.contains("name"));
×
419
        assert(structure["name"].is_string());
×
420
        json_to_structure_definition(structure, builder);
×
421
    }
422

423
    nlohmann::json& containers = j["containers"];
3✔
424

425
    // deserialize externals
426
    for (const auto& name : j["externals"]) {
3✔
427
        auto& type_desc = containers.at(name.get<std::string>());
×
428
        auto type = json_to_type(type_desc);
×
429
        builder.add_container(name, *type, false, true);
×
430
    }
×
431

432
    // deserialize arguments
433
    for (const auto& name : j["arguments"]) {
5✔
434
        auto& type_desc = containers.at(name.get<std::string>());
2✔
435
        auto type = json_to_type(type_desc);
2✔
436
        builder.add_container(name, *type, true, false);
2✔
437
    }
2✔
438

439
    // deserialize transients
440
    for (const auto& entry : containers.items()) {
8✔
441
        if (builder.subject().is_argument(entry.key())) {
5✔
442
            continue;
2✔
443
        }
444
        if (builder.subject().is_external(entry.key())) {
3✔
445
            continue;
×
446
        }
447
        auto type = json_to_type(entry.value());
3✔
448
        builder.add_container(entry.key(), *type, false, false);
3✔
449
    }
3✔
450

451
    // deserialize root node
452
    assert(j.contains("root"));
3✔
453
    auto& root = builder.subject().root();
3✔
454
    json_to_sequence(j["root"], builder, root);
3✔
455

456
    // deserialize metadata
457
    assert(j.contains("metadata"));
3✔
458
    assert(j["metadata"].is_object());
3✔
459
    for (const auto& entry : j["metadata"].items()) {
4✔
460
        builder.subject().add_metadata(entry.key(), entry.value());
1✔
461
    }
462

463
    return builder.move();
3✔
464
}
3✔
465

466
void JSONSerializer::json_to_structure_definition(const nlohmann::json& j,
1✔
467
                                                  builder::StructuredSDFGBuilder& builder) {
468
    assert(j.contains("name"));
1✔
469
    assert(j["name"].is_string());
1✔
470
    assert(j.contains("members"));
1✔
471
    assert(j["members"].is_array());
1✔
472
    assert(j.contains("is_packed"));
1✔
473
    assert(j["is_packed"].is_boolean());
1✔
474
    auto is_packed = j["is_packed"];
1✔
475
    auto& definition = builder.add_structure(j["name"], is_packed);
1✔
476
    for (const auto& member : j["members"]) {
3✔
477
        nlohmann::json member_json;
2✔
478
        auto member_type = json_to_type(member);
2✔
479
        definition.add_member(*member_type);
2✔
480
    }
2✔
481
}
1✔
482

483
std::vector<std::pair<std::string, types::Scalar>> JSONSerializer::json_to_arguments(
4✔
484
    const nlohmann::json& j) {
485
    std::vector<std::pair<std::string, types::Scalar>> arguments;
4✔
486
    for (const auto& argument : j) {
12✔
487
        assert(argument.contains("name"));
8✔
488
        assert(argument["name"].is_string());
8✔
489
        assert(argument.contains("type"));
8✔
490
        assert(argument["type"].is_object());
8✔
491
        std::string name = argument["name"];
8✔
492
        auto type = json_to_type(argument["type"]);
8✔
493
        arguments.emplace_back(name, *dynamic_cast<types::Scalar*>(type.get()));
8✔
494
    }
8✔
495
    return arguments;
4✔
496
}
4✔
497

498
void JSONSerializer::json_to_dataflow(const nlohmann::json& j,
10✔
499
                                      builder::StructuredSDFGBuilder& builder,
500
                                      structured_control_flow::Block& parent) {
501
    std::unordered_map<std::string, data_flow::DataFlowNode&> nodes_map;
10✔
502

503
    assert(j.contains("nodes"));
10✔
504
    assert(j["nodes"].is_array());
10✔
505
    for (const auto& node : j["nodes"]) {
26✔
506
        assert(node.contains("type"));
16✔
507
        assert(node["type"].is_string());
16✔
508
        assert(node.contains("element_id"));
16✔
509
        assert(node["element_id"].is_string());
16✔
510
        std::string type = node["type"];
16✔
511
        if (type == "tasklet") {
16✔
512
            assert(node.contains("code"));
4✔
513
            assert(node["code"].is_number_integer());
4✔
514
            assert(node.contains("inputs"));
4✔
515
            assert(node["inputs"].is_array());
4✔
516
            assert(node.contains("output"));
4✔
517
            assert(node["output"].is_object());
4✔
518
            assert(node["output"].contains("name"));
4✔
519
            assert(node["output"].contains("type"));
4✔
520
            auto inputs = json_to_arguments(node["inputs"]);
4✔
521

522
            auto output_name = node["output"]["name"];
4✔
523
            auto output_type = json_to_type(node["output"]["type"]);
4✔
524
            auto& output_type_scalar = dynamic_cast<types::Scalar&>(*output_type);
4✔
525

526
            auto& tasklet =
4✔
527
                builder.add_tasklet(parent, node["code"], {output_name, output_type_scalar}, inputs,
8✔
528
                                    json_to_debug_info(node["debug_info"]));
4✔
529
            tasklet.element_id_ = node["element_id"];
4✔
530
            nodes_map.insert({node["element_id"], tasklet});
4✔
531
        } else if (type == "library_node") {
16✔
532
            assert(node.contains("code"));
×
533
            assert(node.contains("inputs"));
×
534
            assert(node["inputs"].is_array());
×
535
            assert(node.contains("outputs"));
×
536
            assert(node["outputs"].is_array());
×
537
            data_flow::LibraryNodeCode code(node["code"].get<std::string_view>());
×
538

539
            auto serializer_fn =
NEW
540
                LibraryNodeSerializerRegistry::instance().get_library_node_serializer(code.value());
×
NEW
541
            if (serializer_fn == nullptr) {
×
NEW
542
                throw std::runtime_error("Unknown library node code: " + std::string(code.value()));
×
543
            }
NEW
544
            auto serializer = serializer_fn();
×
NEW
545
            auto& lib_node = serializer->deserialize(node, builder, parent);
×
546
            lib_node.element_id_ = node["element_id"];
×
547
            nodes_map.insert({node["element_id"], lib_node});
×
548
        } else if (type == "access_node") {
12✔
549
            assert(node.contains("data"));
12✔
550
            auto& access_node =
12✔
551
                builder.add_access(parent, node["data"], json_to_debug_info(node["debug_info"]));
12✔
552
            access_node.element_id_ = node["element_id"];
12✔
553
            nodes_map.insert({node["element_id"], access_node});
12✔
554
        } else {
12✔
555
            throw std::runtime_error("Unknown node type");
×
556
        }
557
    }
16✔
558

559
    assert(j.contains("edges"));
10✔
560
    assert(j["edges"].is_array());
10✔
561
    for (const auto& edge : j["edges"]) {
22✔
562
        assert(edge.contains("src"));
12✔
563
        assert(edge["src"].is_string());
12✔
564
        assert(edge.contains("dst"));
12✔
565
        assert(edge["dst"].is_string());
12✔
566
        assert(edge.contains("src_conn"));
12✔
567
        assert(edge["src_conn"].is_string());
12✔
568
        assert(edge.contains("dst_conn"));
12✔
569
        assert(edge["dst_conn"].is_string());
12✔
570
        assert(edge.contains("subset"));
12✔
571
        assert(edge["subset"].is_array());
12✔
572

573
        assert(nodes_map.find(edge["src"]) != nodes_map.end());
12✔
574
        assert(nodes_map.find(edge["dst"]) != nodes_map.end());
12✔
575
        auto& source = nodes_map.at(edge["src"]);
12✔
576
        auto& target = nodes_map.at(edge["dst"]);
12✔
577

578
        assert(edge.contains("subset"));
12✔
579
        assert(edge["subset"].is_array());
12✔
580
        std::vector<symbolic::Expression> subset;
12✔
581
        for (const auto& subset_str : edge["subset"]) {
16✔
582
            assert(subset_str.is_string());
4✔
583
            SymEngine::Expression subset_expr(subset_str);
4✔
584
            subset.push_back(subset_expr);
4✔
585
        }
4✔
586
        auto& memlet =
12✔
587
            builder.add_memlet(parent, source, edge["src_conn"], target, edge["dst_conn"], subset,
24✔
588
                               json_to_debug_info(edge["debug_info"]));
12✔
589
        memlet.element_id_ = edge["element_id"];
12✔
590
    }
12✔
591
}
10✔
592

593
void JSONSerializer::json_to_sequence(const nlohmann::json& j,
12✔
594
                                      builder::StructuredSDFGBuilder& builder,
595
                                      structured_control_flow::Sequence& sequence) {
596
    assert(j.contains("type"));
12✔
597
    assert(j["type"].is_string());
12✔
598
    assert(j.contains("children"));
12✔
599
    assert(j["children"].is_array());
12✔
600
    assert(j.contains("transitions"));
12✔
601
    assert(j["transitions"].is_array());
12✔
602
    assert(j["transitions"].size() == j["children"].size());
12✔
603

604
    sequence.element_id_ = j["element_id"];
12✔
605
    sequence.debug_info_ = json_to_debug_info(j["debug_info"]);
12✔
606

607
    std::string type = j["type"];
12✔
608
    if (type == "sequence") {
12✔
609
        for (size_t i = 0; i < j["children"].size(); i++) {
22✔
610
            auto& child = j["children"][i];
10✔
611
            auto& transition = j["transitions"][i];
10✔
612
            assert(child.contains("type"));
10✔
613
            assert(child["type"].is_string());
10✔
614

615
            assert(transition.contains("type"));
10✔
616
            assert(transition["type"].is_string());
10✔
617
            assert(transition.contains("assignments"));
10✔
618
            assert(transition["assignments"].is_array());
10✔
619
            symbolic::Assignments assignments;
10✔
620
            for (const auto& assignment : transition["assignments"]) {
11✔
621
                assert(assignment.contains("symbol"));
1✔
622
                assert(assignment["symbol"].is_string());
1✔
623
                assert(assignment.contains("expression"));
1✔
624
                assert(assignment["expression"].is_string());
1✔
625
                SymEngine::Expression expr(assignment["expression"]);
1✔
626
                assignments.insert({symbolic::symbol(assignment["symbol"]), expr});
1✔
627
            }
1✔
628

629
            if (child["type"] == "block") {
10✔
630
                json_to_block_node(child, builder, sequence, assignments);
8✔
631
            } else if (child["type"] == "for") {
10✔
632
                json_to_for_node(child, builder, sequence, assignments);
×
633
            } else if (child["type"] == "if_else") {
2✔
634
                json_to_if_else_node(child, builder, sequence, assignments);
×
635
            } else if (child["type"] == "while") {
2✔
636
                json_to_while_node(child, builder, sequence, assignments);
×
637
            } else if (child["type"] == "break") {
2✔
638
                json_to_break_node(child, builder, sequence, assignments);
1✔
639
            } else if (child["type"] == "continue") {
2✔
640
                json_to_continue_node(child, builder, sequence, assignments);
1✔
641
            } else if (child["type"] == "return") {
1✔
642
                json_to_return_node(child, builder, sequence, assignments);
×
643
            } else if (child["type"] == "map") {
×
644
                json_to_map_node(child, builder, sequence, assignments);
×
645
            } else if (child["type"] == "sequence") {
×
646
                auto& subseq = builder.add_sequence(sequence, assignments,
×
647
                                                    json_to_debug_info(child["debug_info"]));
×
648
                json_to_sequence(child, builder, subseq);
×
649
            } else {
×
650
                throw std::runtime_error("Unknown child type");
×
651
            }
652

653
            sequence.at(i).second.debug_info_ = json_to_debug_info(transition["debug_info"]);
10✔
654
            sequence.at(i).second.element_id_ = transition["element_id"];
10✔
655
        }
10✔
656
    } else {
12✔
657
        throw std::runtime_error("expected sequence type");
×
658
    }
659
}
12✔
660

661
void JSONSerializer::json_to_block_node(const nlohmann::json& j,
9✔
662
                                        builder::StructuredSDFGBuilder& builder,
663
                                        structured_control_flow::Sequence& parent,
664
                                        symbolic::Assignments& assignments) {
665
    assert(j.contains("type"));
9✔
666
    assert(j["type"].is_string());
9✔
667
    assert(j.contains("dataflow"));
9✔
668
    assert(j["dataflow"].is_object());
9✔
669
    auto& block = builder.add_block(parent, assignments, json_to_debug_info(j["debug_info"]));
9✔
670
    block.element_id_ = j["element_id"];
9✔
671
    assert(j["dataflow"].contains("type"));
9✔
672
    assert(j["dataflow"]["type"].is_string());
9✔
673
    std::string type = j["dataflow"]["type"];
9✔
674
    if (type == "dataflow") {
9✔
675
        json_to_dataflow(j["dataflow"], builder, block);
9✔
676
    } else {
9✔
677
        throw std::runtime_error("Unknown dataflow type");
×
678
    }
679
}
9✔
680

681
void JSONSerializer::json_to_for_node(const nlohmann::json& j,
1✔
682
                                      builder::StructuredSDFGBuilder& builder,
683
                                      structured_control_flow::Sequence& parent,
684
                                      symbolic::Assignments& assignments) {
685
    assert(j.contains("type"));
1✔
686
    assert(j["type"].is_string());
1✔
687
    assert(j.contains("indvar"));
1✔
688
    assert(j["indvar"].is_string());
1✔
689
    assert(j.contains("init"));
1✔
690
    assert(j["init"].is_string());
1✔
691
    assert(j.contains("condition"));
1✔
692
    assert(j["condition"].is_string());
1✔
693
    assert(j.contains("update"));
1✔
694
    assert(j["update"].is_string());
1✔
695
    assert(j.contains("root"));
1✔
696
    assert(j["root"].is_object());
1✔
697

698
    symbolic::Symbol indvar = symbolic::symbol(j["indvar"]);
1✔
699
    SymEngine::Expression init(j["init"]);
1✔
700
    SymEngine::Expression condition_expr(j["condition"]);
1✔
701
    assert(!SymEngine::rcp_static_cast<const SymEngine::Boolean>(condition_expr.get_basic())
1✔
702
                .is_null());
703
    symbolic::Condition condition =
704
        SymEngine::rcp_static_cast<const SymEngine::Boolean>(condition_expr.get_basic());
1✔
705
    SymEngine::Expression update(j["update"]);
1✔
706
    auto& for_node = builder.add_for(parent, indvar, condition, init, update, assignments,
2✔
707
                                     json_to_debug_info(j["debug_info"]));
1✔
708
    for_node.element_id_ = j["element_id"];
1✔
709

710
    assert(j["root"].contains("type"));
1✔
711
    assert(j["root"]["type"].is_string());
1✔
712
    assert(j["root"]["type"] == "sequence");
1✔
713
    json_to_sequence(j["root"], builder, for_node.root());
1✔
714
}
1✔
715

716
void JSONSerializer::json_to_if_else_node(const nlohmann::json& j,
1✔
717
                                          builder::StructuredSDFGBuilder& builder,
718
                                          structured_control_flow::Sequence& parent,
719
                                          symbolic::Assignments& assignments) {
720
    assert(j.contains("type"));
1✔
721
    assert(j["type"].is_string());
1✔
722
    assert(j["type"] == "if_else");
1✔
723
    assert(j.contains("branches"));
1✔
724
    assert(j["branches"].is_array());
1✔
725
    auto& if_else_node =
1✔
726
        builder.add_if_else(parent, assignments, json_to_debug_info(j["debug_info"]));
1✔
727
    if_else_node.element_id_ = j["element_id"];
1✔
728
    for (const auto& branch : j["branches"]) {
3✔
729
        assert(branch.contains("condition"));
2✔
730
        assert(branch["condition"].is_string());
2✔
731
        assert(branch.contains("root"));
2✔
732
        assert(branch["root"].is_object());
2✔
733
        SymEngine::Expression condition_expr(branch["condition"]);
2✔
734
        assert(!SymEngine::rcp_static_cast<const SymEngine::Boolean>(condition_expr.get_basic())
2✔
735
                    .is_null());
736
        symbolic::Condition condition =
737
            SymEngine::rcp_static_cast<const SymEngine::Boolean>(condition_expr.get_basic());
2✔
738
        auto& branch_node = builder.add_case(if_else_node, condition);
2✔
739
        assert(branch["root"].contains("type"));
2✔
740
        assert(branch["root"]["type"].is_string());
2✔
741
        std::string type = branch["root"]["type"];
2✔
742
        if (type == "sequence") {
2✔
743
            json_to_sequence(branch["root"], builder, branch_node);
2✔
744
        } else {
2✔
745
            throw std::runtime_error("Unknown child type");
×
746
        }
747
    }
2✔
748
}
1✔
749

750
void JSONSerializer::json_to_while_node(const nlohmann::json& j,
3✔
751
                                        builder::StructuredSDFGBuilder& builder,
752
                                        structured_control_flow::Sequence& parent,
753
                                        symbolic::Assignments& assignments) {
754
    assert(j.contains("type"));
3✔
755
    assert(j["type"].is_string());
3✔
756
    assert(j["type"] == "while");
3✔
757
    assert(j.contains("root"));
3✔
758
    assert(j["root"].is_object());
3✔
759

760
    auto& while_node = builder.add_while(parent, assignments, json_to_debug_info(j["debug_info"]));
3✔
761
    while_node.element_id_ = j["element_id"];
3✔
762

763
    assert(j["root"]["type"] == "sequence");
3✔
764
    json_to_sequence(j["root"], builder, while_node.root());
3✔
765
}
3✔
766

767
void JSONSerializer::json_to_break_node(const nlohmann::json& j,
1✔
768
                                        builder::StructuredSDFGBuilder& builder,
769
                                        structured_control_flow::Sequence& parent,
770
                                        symbolic::Assignments& assignments) {
771
    assert(j.contains("type"));
1✔
772
    assert(j["type"].is_string());
1✔
773
    assert(j["type"] == "break");
1✔
774
    auto& node = builder.add_break(parent, assignments, json_to_debug_info(j["debug_info"]));
1✔
775
    node.element_id_ = j["element_id"];
1✔
776
}
1✔
777

778
void JSONSerializer::json_to_continue_node(const nlohmann::json& j,
1✔
779
                                           builder::StructuredSDFGBuilder& builder,
780
                                           structured_control_flow::Sequence& parent,
781
                                           symbolic::Assignments& assignments) {
782
    assert(j.contains("type"));
1✔
783
    assert(j["type"].is_string());
1✔
784
    assert(j["type"] == "continue");
1✔
785
    auto& node = builder.add_continue(parent, assignments, json_to_debug_info(j["debug_info"]));
1✔
786
    node.element_id_ = j["element_id"];
1✔
787
}
1✔
788

789
void JSONSerializer::json_to_map_node(const nlohmann::json& j,
1✔
790
                                      builder::StructuredSDFGBuilder& builder,
791
                                      structured_control_flow::Sequence& parent,
792
                                      symbolic::Assignments& assignments) {
793
    assert(j.contains("type"));
1✔
794
    assert(j["type"].is_string());
1✔
795
    assert(j["type"] == "map");
1✔
796
    assert(j.contains("indvar"));
1✔
797
    assert(j["indvar"].is_string());
1✔
798
    assert(j.contains("num_iterations"));
1✔
799
    assert(j["num_iterations"].is_string());
1✔
800
    assert(j.contains("root"));
1✔
801
    assert(j["root"].is_object());
1✔
802
    assert(j.contains("schedule_type"));
1✔
803
    assert(j["schedule_type"].is_string());
1✔
804
    structured_control_flow::ScheduleType schedule_type{j["schedule_type"].get<std::string_view>()};
1✔
805
    symbolic::Symbol indvar = symbolic::symbol(j["indvar"]);
1✔
806
    SymEngine::Expression num_iterations(j["num_iterations"]);
1✔
807

808
    auto& map_node = builder.add_map(parent, indvar, num_iterations, schedule_type, assignments,
2✔
809
                                     json_to_debug_info(j["debug_info"]));
1✔
810
    map_node.element_id_ = j["element_id"];
1✔
811

812
    assert(j["root"].contains("type"));
1✔
813
    assert(j["root"]["type"].is_string());
1✔
814
    assert(j["root"]["type"] == "sequence");
1✔
815
    json_to_sequence(j["root"], builder, map_node.root());
1✔
816
}
1✔
817

818
void JSONSerializer::json_to_return_node(const nlohmann::json& j,
1✔
819
                                         builder::StructuredSDFGBuilder& builder,
820
                                         structured_control_flow::Sequence& parent,
821
                                         symbolic::Assignments& assignments) {
822
    assert(j.contains("type"));
1✔
823
    assert(j["type"].is_string());
1✔
824
    assert(j["type"] == "return");
1✔
825

826
    auto& node = builder.add_return(parent, assignments, json_to_debug_info(j["debug_info"]));
1✔
827
    node.element_id_ = j["element_id"];
1✔
828
}
1✔
829

830
std::unique_ptr<types::IType> JSONSerializer::json_to_type(const nlohmann::json& j) {
31✔
831
    if (j.contains("type")) {
31✔
832
        if (j["type"] == "scalar") {
31✔
833
            // Deserialize scalar type
834
            assert(j.contains("primitive_type"));
25✔
835
            types::PrimitiveType primitive_type = j["primitive_type"];
25✔
836
            assert(j.contains("storage_type"));
25✔
837
            types::StorageType storage_type{j["storage_type"].get<std::string_view>()};
25✔
838
            assert(j.contains("initializer"));
25✔
839
            std::string initializer = j["initializer"];
25✔
840
            assert(j.contains("alignment"));
25✔
841
            size_t alignment = j["alignment"];
25✔
842
            return std::make_unique<types::Scalar>(storage_type, alignment, initializer,
25✔
843
                                                   primitive_type);
844
        } else if (j["type"] == "array") {
31✔
845
            // Deserialize array type
846
            assert(j.contains("element_type"));
2✔
847
            std::unique_ptr<types::IType> member_type = json_to_type(j["element_type"]);
2✔
848
            assert(j.contains("num_elements"));
2✔
849
            std::string num_elements_str = j["num_elements"];
2✔
850
            // Convert num_elements_str to symbolic::Expression
851
            SymEngine::Expression num_elements(num_elements_str);
2✔
852
            assert(j.contains("storage_type"));
2✔
853
            types::StorageType storage_type{j["storage_type"].get<std::string_view>()};
2✔
854
            assert(j.contains("initializer"));
2✔
855
            std::string initializer = j["initializer"];
2✔
856
            assert(j.contains("alignment"));
2✔
857
            size_t alignment = j["alignment"];
2✔
858
            return std::make_unique<types::Array>(storage_type, alignment, initializer,
2✔
859
                                                  *member_type, num_elements);
2✔
860
        } else if (j["type"] == "pointer") {
6✔
861
            // Deserialize pointer type
862
            assert(j.contains("pointee_type"));
2✔
863
            std::unique_ptr<types::IType> pointee_type = json_to_type(j["pointee_type"]);
2✔
864
            assert(j.contains("storage_type"));
2✔
865
            types::StorageType storage_type{j["storage_type"].get<std::string_view>()};
2✔
866
            assert(j.contains("initializer"));
2✔
867
            std::string initializer = j["initializer"];
2✔
868
            assert(j.contains("alignment"));
2✔
869
            size_t alignment = j["alignment"];
2✔
870
            return std::make_unique<types::Pointer>(storage_type, alignment, initializer,
2✔
871
                                                    *pointee_type);
2✔
872
        } else if (j["type"] == "structure") {
4✔
873
            // Deserialize structure type
874
            assert(j.contains("name"));
1✔
875
            std::string name = j["name"];
1✔
876
            assert(j.contains("storage_type"));
1✔
877
            types::StorageType storage_type{j["storage_type"].get<std::string_view>()};
1✔
878
            assert(j.contains("initializer"));
1✔
879
            std::string initializer = j["initializer"];
1✔
880
            assert(j.contains("alignment"));
1✔
881
            size_t alignment = j["alignment"];
1✔
882
            return std::make_unique<types::Structure>(storage_type, alignment, initializer, name);
1✔
883
        } else if (j["type"] == "function") {
2✔
884
            // Deserialize function type
885
            assert(j.contains("return_type"));
1✔
886
            std::unique_ptr<types::IType> return_type = json_to_type(j["return_type"]);
1✔
887
            assert(j.contains("params"));
1✔
888
            std::vector<std::unique_ptr<types::IType>> params;
1✔
889
            for (const auto& param : j["params"]) {
3✔
890
                params.push_back(json_to_type(param));
2✔
891
            }
892
            assert(j.contains("is_var_arg"));
1✔
893
            bool is_var_arg = j["is_var_arg"];
1✔
894
            assert(j.contains("storage_type"));
1✔
895
            types::StorageType storage_type{j["storage_type"].get<std::string_view>()};
1✔
896
            assert(j.contains("initializer"));
1✔
897
            std::string initializer = j["initializer"];
1✔
898
            assert(j.contains("alignment"));
1✔
899
            size_t alignment = j["alignment"];
1✔
900
            auto function = std::make_unique<types::Function>(storage_type, alignment, initializer,
1✔
901
                                                              *return_type, is_var_arg);
1✔
902
            for (const auto& param : params) {
3✔
903
                function->add_param(*param);
2✔
904
            }
905
            return function->clone();
1✔
906

907
        } else {
1✔
908
            throw std::runtime_error("Unknown type");
×
909
        }
910
    } else {
911
        throw std::runtime_error("Type not found");
×
912
    }
913
}
31✔
914

915
DebugInfo JSONSerializer::json_to_debug_info(const nlohmann::json& j) {
68✔
916
    assert(j.contains("has"));
68✔
917
    assert(j["has"].is_boolean());
68✔
918
    if (!j["has"]) {
68✔
919
        return DebugInfo();
68✔
920
    }
921
    assert(j.contains("filename"));
×
922
    assert(j["filename"].is_string());
×
923
    std::string filename = j["filename"];
×
924
    assert(j.contains("start_line"));
×
925
    assert(j["start_line"].is_number_integer());
×
926
    size_t start_line = j["start_line"];
×
927
    assert(j.contains("start_column"));
×
928
    assert(j["start_column"].is_number_integer());
×
929
    size_t start_column = j["start_column"];
×
930
    assert(j.contains("end_line"));
×
931
    assert(j["end_line"].is_number_integer());
×
932
    size_t end_line = j["end_line"];
×
933
    assert(j.contains("end_column"));
×
934
    assert(j["end_column"].is_number_integer());
×
935
    size_t end_column = j["end_column"];
×
936
    return DebugInfo(filename, start_line, start_column, end_line, end_column);
×
937
}
68✔
938

939
std::string JSONSerializer::expression(const symbolic::Expression& expr) {
29✔
940
    JSONSymbolicPrinter printer;
29✔
941
    return printer.apply(expr);
29✔
942
};
29✔
943

944
void JSONSymbolicPrinter::bvisit(const SymEngine::Equality& x) {
×
945
    str_ = apply(x.get_args()[0]) + " == " + apply(x.get_args()[1]);
×
946
    str_ = parenthesize(str_);
×
947
};
×
948

949
void JSONSymbolicPrinter::bvisit(const SymEngine::Unequality& x) {
×
950
    str_ = apply(x.get_args()[0]) + " != " + apply(x.get_args()[1]);
×
951
    str_ = parenthesize(str_);
×
952
};
×
953

954
void JSONSymbolicPrinter::bvisit(const SymEngine::LessThan& x) {
×
955
    str_ = apply(x.get_args()[0]) + " <= " + apply(x.get_args()[1]);
×
956
    str_ = parenthesize(str_);
×
957
};
×
958

959
void JSONSymbolicPrinter::bvisit(const SymEngine::StrictLessThan& x) {
2✔
960
    str_ = apply(x.get_args()[0]) + " < " + apply(x.get_args()[1]);
2✔
961
    str_ = parenthesize(str_);
2✔
962
};
2✔
963

964
void JSONSymbolicPrinter::bvisit(const SymEngine::Min& x) {
×
965
    std::ostringstream s;
×
966
    auto container = x.get_args();
×
967
    if (container.size() == 1) {
×
968
        s << apply(*container.begin());
×
969
    } else {
×
970
        s << "min(";
×
971
        s << apply(*container.begin());
×
972

973
        // Recursively apply __daisy_min to the arguments
974
        SymEngine::vec_basic subargs;
×
975
        for (auto it = ++(container.begin()); it != container.end(); ++it) {
×
976
            subargs.push_back(*it);
×
977
        }
×
978
        auto submin = SymEngine::min(subargs);
×
979
        s << ", " << apply(submin);
×
980

981
        s << ")";
×
982
    }
×
983

984
    str_ = s.str();
×
985
};
×
986

987
void JSONSymbolicPrinter::bvisit(const SymEngine::Max& x) {
×
988
    std::ostringstream s;
×
989
    auto container = x.get_args();
×
990
    if (container.size() == 1) {
×
991
        s << apply(*container.begin());
×
992
    } else {
×
993
        s << "max(";
×
994
        s << apply(*container.begin());
×
995

996
        // Recursively apply __daisy_max to the arguments
997
        SymEngine::vec_basic subargs;
×
998
        for (auto it = ++(container.begin()); it != container.end(); ++it) {
×
999
            subargs.push_back(*it);
×
1000
        }
×
1001
        auto submax = SymEngine::max(subargs);
×
1002
        s << ", " << apply(submax);
×
1003

1004
        s << ")";
×
1005
    }
×
1006

1007
    str_ = s.str();
×
1008
};
×
1009

1010
}  // namespace serializer
1011
}  // 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