-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathinit.cpp
More file actions
68 lines (48 loc) · 2.5 KB
/
Copy pathinit.cpp
File metadata and controls
68 lines (48 loc) · 2.5 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
@ for group in graph_instance['devices'] | groupby('type')
@ set devices = group.list | sort(attribute='id')
@ set device_type = group.grouper
@ set device_class = get_device_class(device_type)
int {{ get_init_function_name(device_type) }}(std::vector<device_t*> &devices, uint32_t simulation_region) {
@ set state_class = get_state_class(graph_type["id"], device_type)
@ set props_class = get_props_class(graph_type["id"], device_type)
@ set device_class = get_device_class(device_type)
@ set count = group.list | count
@ set device_type_obj = schema.get_device_type(device_type)
@ set scalar_props = device_type_obj['properties']['scalars']
@ set init_msg_t = get_msg_class(graph_type["id"], '__init__')
@ set init_handler = get_receive_handler_name(device_type, '__init__')
@ for prop in scalar_props
@ set property_values = devices | map(attribute='properties') | map(attribute=prop['name']) | list
{{ prop['type'] }} {{ prop['name'] }} [{{ count }}] = {
{{- property_values | join(', ') -}}
};
@ endfor
@ set device_names = devices | map(attribute="id") | list
@ set device_names_str = mformat('"%s"', device_names) | join(', ')
@ set device_regions = schema.get_device_regions(devices)
@ set scalar_prop_names = scalar_props | map(attribute='name') | list
@ set scalar_prop_names_ith = mformat('%s[i]', scalar_prop_names)
const std::string names[] = { {{ device_names_str }} };
const uint32_t regions[] = { {{ device_regions | join(', ') }} };
int local_devices = 0;
for (int i=0; i<{{ devices | count }}; i++) {
{{ device_class }} *new_device = new {{ device_class }};
new_device->name = names[i];
(*new_device).setProperties(
{{- scalar_prop_names_ith | join(', ') -}}
);
new_device->index = devices.size();
new_device->region = regions[i];
active_device = new_device;
// Only initialize devices within simulation region ...
if (regions[i] == simulation_region) {
(*new_device).init();
local_devices++;
cprintf("Device <%s> ({{ device_type }}): ", new_device->name.c_str());
(*new_device).print();
}
devices.push_back((device_t*) new_device);
}
return local_devices;
}
@ endfor