Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -390,3 +390,11 @@ path = "tests/compute_ring_invariants.rs"
[[test]]
name = "mesh_protocol_stack_ttl"
path = "tests/mesh_protocol_stack_ttl.rs"

[[test]]
name = "gen_rust_corpus_compiles"
path = "tests/gen_rust_corpus_compiles.rs"

[[test]]
name = "gen_rust_value_params"
path = "tests/gen_rust_value_params.rs"
2 changes: 1 addition & 1 deletion gen/c/api_documenter.c
Original file line number Diff line number Diff line change
Expand Up @@ -337,7 +337,7 @@ uint32_t validate_documentation(t27_arr_uint32_t_64 func_docs, uint32_t func_cou
}

uint32_t generate_documentation_report(t27_arr_uint32_t_64 func_docs, uint32_t func_count, t27_arr_uint32_t_64 xrefs, uint32_t xref_count) {
t27_arr_uint32_t_16 empty_params = { .v = { [0 ... (MAX_PARAMETERS) - 1] = 0 } };
t27_arr_uint32_t_16 empty_params = { .v = { [0 ... (16) - 1] = 0 } };
uint32_t doc_summary = generate_api_documentation(func_docs, func_count, empty_params, 0);
uint32_t documented_funcs = ((doc_summary >> 24) & 0xFF);
uint32_t coverage = calculate_documentation_coverage(documented_funcs, func_count);
Expand Down
31 changes: 17 additions & 14 deletions gen/c/auto_config.c
Original file line number Diff line number Diff line change
Expand Up @@ -133,13 +133,14 @@ uint32_t get_config_value(t27_arr_uint32_t_16 config, uint32_t param_id) {
}

uint32_t set_config_value(t27_arr_uint32_t_16 config, uint32_t param_id, uint32_t new_value) {
t27_arr_uint32_t_16 cfg = config;
uint32_t i = 0;
while ((i < MAX_PARAMS)) {
uint32_t current_param_id = get_param_id(config.v[i]);
uint32_t current_param_id = get_param_id(cfg.v[i]);
if ((current_param_id == param_id)) {
uint32_t scope = get_param_scope(config.v[i]);
uint32_t scope = get_param_scope(cfg.v[i]);
uint32_t status = STATUS_PENDING;
config.v[i] = create_config_param(param_id, new_value, scope, status);
cfg.v[i] = create_config_param(param_id, new_value, scope, status);
return 1;
}
i = (i + 1);
Expand Down Expand Up @@ -174,14 +175,15 @@ uint32_t discover_network_params(uint32_t node_count, uint32_t interference_leve
}

uint32_t apply_config(t27_arr_uint32_t_16 config, uint32_t param_id) {
t27_arr_uint32_t_16 cfg = config;
uint32_t i = 0;
while ((i < MAX_PARAMS)) {
uint32_t current_param_id = get_param_id(config.v[i]);
uint32_t current_param_id = get_param_id(cfg.v[i]);
if ((current_param_id == param_id)) {
uint32_t value = get_param_value(config.v[i]);
uint32_t scope = get_param_scope(config.v[i]);
uint32_t value = get_param_value(cfg.v[i]);
uint32_t scope = get_param_scope(cfg.v[i]);
uint32_t success = 1;
config.v[i] = create_config_param(param_id, value, scope, STATUS_APPLIED);
cfg.v[i] = create_config_param(param_id, value, scope, STATUS_APPLIED);
return success;
}
i = (i + 1);
Expand All @@ -208,19 +210,19 @@ uint32_t apply_all_pending(t27_arr_uint32_t_16 config) {
uint32_t validate_config(t27_arr_uint32_t_16 config, uint32_t param_id) {
uint32_t value = get_config_value(config, param_id);
if ((param_id == PARAM_TX_POWER)) {
if (((value >= 0) && (value <= 100))) {
if ((value <= 100)) {
return 1;
}
} else if ((param_id == PARAM_CHANNEL)) {
if (((value >= 0) && (value <= 11))) {
if ((value <= 11)) {
return 1;
}
} else if ((param_id == PARAM_DATA_RATE)) {
if (((value >= 0) && (value <= 3))) {
if ((value <= 3)) {
return 1;
}
} else if ((param_id == PARAM_RETRY_LIMIT)) {
if (((value >= 0) && (value <= 7))) {
if ((value <= 7)) {
return 1;
}
} else if ((param_id == PARAM_HELLO_INTERVAL)) {
Expand All @@ -236,7 +238,7 @@ uint32_t validate_config(t27_arr_uint32_t_16 config, uint32_t param_id) {
return 1;
}
} else if ((param_id == PARAM_SECURITY_LEVEL)) {
if (((value >= 0) && (value <= 3))) {
if ((value <= 3)) {
return 1;
}
}
Expand Down Expand Up @@ -298,6 +300,7 @@ break;
}

uint32_t rollback_config(t27_arr_uint32_t_16 config, t27_arr_uint32_t_16 backup_config) {
t27_arr_uint32_t_16 cfg = config;
uint32_t rolled_back = 0;
uint32_t i = 0;
while ((i < MAX_PARAMS)) {
Expand All @@ -306,9 +309,9 @@ uint32_t rollback_config(t27_arr_uint32_t_16 config, t27_arr_uint32_t_16 backup_
uint32_t backup_scope = get_param_scope(backup_config.v[i]);
uint32_t j = 0;
while ((j < MAX_PARAMS)) {
uint32_t local_param_id = get_param_id(config.v[j]);
uint32_t local_param_id = get_param_id(cfg.v[j]);
if ((local_param_id == backup_param_id)) {
config.v[j] = create_config_param(backup_param_id, backup_value, backup_scope, STATUS_PENDING);
cfg.v[j] = create_config_param(backup_param_id, backup_value, backup_scope, STATUS_PENDING);
rolled_back = (rolled_back + 1);
break;
}
Expand Down
11 changes: 6 additions & 5 deletions gen/c/bandwidth_allocator.c
Original file line number Diff line number Diff line change
Expand Up @@ -155,13 +155,14 @@ uint32_t update_flow_bandwidth(uint32_t flow_req, uint32_t new_bw) {
int flow_id = get_flow_id(flow_req);
int priority = get_flow_priority(flow_req);
int min_bw = get_min_bandwidth(flow_req);
if ((new_bw < min_bw)) {
new_bw = min_bw;
uint32_t bw = new_bw;
if ((bw < min_bw)) {
bw = min_bw;
}
if ((new_bw > MAX_BANDWIDTH)) {
new_bw = MAX_BANDWIDTH;
if ((bw > MAX_BANDWIDTH)) {
bw = MAX_BANDWIDTH;
}
return create_flow_requirement(flow_id, priority, min_bw, new_bw);
return create_flow_requirement(flow_id, priority, min_bw, bw);
}

uint32_t count_active_flows(t27_arr_uint32_t_8 flow_array) {
Expand Down
43 changes: 24 additions & 19 deletions gen/c/cache_management.c
Original file line number Diff line number Diff line change
Expand Up @@ -133,32 +133,34 @@ uint32_t get_entry(t27_arr_uint32_t_16 cache, uint32_t data_id) {
}

uint32_t add_entry(t27_arr_uint32_t_16 cache, uint32_t current_size, uint32_t data_id, uint32_t size) {
uint32_t existing_index = find_entry(cache, data_id);
t27_arr_uint32_t_16 slots = cache;
uint32_t used = current_size;
uint32_t existing_index = find_entry(slots, data_id);
if ((existing_index < MAX_ENTRIES)) {
return current_size;
return used;
}
uint32_t empty_index = MAX_ENTRIES;
uint32_t i = 0;
while ((i < MAX_ENTRIES)) {
if ((get_data_id(cache.v[i]) == 0)) {
if ((get_data_id(slots.v[i]) == 0)) {
empty_index = i;
break;
}
i = (i + 1);
}
if ((empty_index == MAX_ENTRIES)) {
empty_index = find_eviction_candidate(cache);
empty_index = find_eviction_candidate(slots);
if ((empty_index == MAX_ENTRIES)) {
return current_size;
return used;
}
uint32_t evicted_size = get_entry_size(cache.v[empty_index]);
current_size = (current_size - evicted_size);
uint32_t evicted_size = get_entry_size(slots.v[empty_index]);
used = (used - evicted_size);
}
if (((current_size + size) > MAX_CACHE_SIZE)) {
return current_size;
if (((used + size) > MAX_CACHE_SIZE)) {
return used;
}
cache.v[empty_index] = create_cache_entry(data_id, 1, 0, size);
return (current_size + size);
slots.v[empty_index] = create_cache_entry(data_id, 1, 0, size);
return (used + size);
}

uint32_t find_eviction_candidate(t27_arr_uint32_t_16 cache) {
Expand All @@ -183,34 +185,37 @@ uint32_t find_eviction_candidate(t27_arr_uint32_t_16 cache) {
}

uint32_t remove_entry(t27_arr_uint32_t_16 cache, uint32_t current_size, uint32_t data_id) {
uint32_t entry_index = find_entry(cache, data_id);
t27_arr_uint32_t_16 slots = cache;
uint32_t entry_index = find_entry(slots, data_id);
if ((entry_index < MAX_ENTRIES)) {
uint32_t entry_size = get_entry_size(cache.v[entry_index]);
cache.v[entry_index] = 0;
uint32_t entry_size = get_entry_size(slots.v[entry_index]);
slots.v[entry_index] = 0;
return (current_size - entry_size);
} else {
return current_size;
}
}

uint32_t access_cache(t27_arr_uint32_t_16 cache, uint32_t data_id) {
uint32_t entry_index = find_entry(cache, data_id);
t27_arr_uint32_t_16 slots = cache;
uint32_t entry_index = find_entry(slots, data_id);
if ((entry_index < MAX_ENTRIES)) {
cache.v[entry_index] = update_access_count(cache.v[entry_index]);
cache.v[entry_index] = update_age(cache.v[entry_index], 0);
slots.v[entry_index] = update_access_count(slots.v[entry_index]);
slots.v[entry_index] = update_age(slots.v[entry_index], 0);
return 1;
} else {
return 0;
}
}

void age_cache(t27_arr_uint32_t_16 cache) {
t27_arr_uint32_t_16 slots = cache;
uint32_t i = 0;
while ((i < MAX_ENTRIES)) {
uint32_t entry = cache.v[i];
uint32_t entry = slots.v[i];
uint32_t age = get_age(entry);
if ((age < 255)) {
cache.v[i] = update_age(entry, (age + 1));
slots.v[i] = update_age(entry, (age + 1));
}
i = (i + 1);
}
Expand Down
3 changes: 2 additions & 1 deletion gen/c/compression_engine.c
Original file line number Diff line number Diff line change
Expand Up @@ -277,8 +277,9 @@ uint32_t calculate_total_savings(t27_arr_uint32_t_16 blocks, uint32_t count) {
}

uint32_t update_dictionary(t27_arr_uint32_t_8 dictionary, uint32_t new_entry, uint32_t index) {
t27_arr_uint32_t_8 dict = dictionary;
if ((index < DICTIONARY_SIZE)) {
dictionary.v[index] = new_entry;
dict.v[index] = new_entry;
return 1;
} else {
return 0;
Expand Down
17 changes: 10 additions & 7 deletions gen/c/integration_framework.c
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
#define INTEGRATION_VERSION 1
#define TYPE_NETWORK 0
#define TYPE_TESTING 1
#define type_documentation 2
#define TYPE_DOCUMENTATION 2
#define TYPE_VISUALIZATION 3
#define TYPE_SIMULATION 4
#define TYPE_PROFILING 5
Expand Down Expand Up @@ -208,11 +208,12 @@ uint32_t get_event_data(uint32_t event) {
}

uint32_t subscribe_to_event(uint32_t module_id, uint32_t event_type, t27_arr_uint32_t_64 subscriptions) {
t27_arr_uint32_t_64 subs = subscriptions;
uint32_t subscription_id = ((module_id * 10) + event_type);
uint32_t i = 0;
while ((i < MAX_EVENTS)) {
if ((subscriptions.v[i] == 0)) {
subscriptions.v[i] = create_event(subscription_id, event_type, module_id, 0);
if ((subs.v[i] == 0)) {
subs.v[i] = create_event(subscription_id, event_type, module_id, 0);
return 1;
}
i = (i + 1);
Expand Down Expand Up @@ -322,10 +323,11 @@ uint32_t propagate_error(uint32_t err_word, t27_arr_uint32_t_16 modules, uint32_
}

uint32_t load_module(uint32_t module_id, uint32_t module_type, uint32_t priority, t27_arr_uint32_t_16 modules) {
t27_arr_uint32_t_16 mods = modules;
uint32_t i = 0;
while ((i < MAX_MODULES)) {
if ((get_registered_module_id(modules.v[i]) == 0)) {
modules.v[i] = create_module_registration(module_id, module_type, priority, STATUS_IDLE);
if ((get_registered_module_id(mods.v[i]) == 0)) {
mods.v[i] = create_module_registration(module_id, module_type, priority, STATUS_IDLE);
return 1;
}
i = (i + 1);
Expand All @@ -334,11 +336,12 @@ uint32_t load_module(uint32_t module_id, uint32_t module_type, uint32_t priority
}

uint32_t unload_module(uint32_t module_id, t27_arr_uint32_t_16 modules) {
t27_arr_uint32_t_16 mods = modules;
uint32_t i = 0;
while ((i < MAX_MODULES)) {
uint32_t registered_id = get_registered_module_id(modules.v[i]);
uint32_t registered_id = get_registered_module_id(mods.v[i]);
if ((registered_id == module_id)) {
modules.v[i] = 0;
mods.v[i] = 0;
return 1;
}
i = (i + 1);
Expand Down
10 changes: 6 additions & 4 deletions gen/c/network_simulator.c
Original file line number Diff line number Diff line change
Expand Up @@ -248,15 +248,16 @@ uint32_t advance_simulation(uint32_t state, uint32_t time_delta) {
}

uint32_t process_event(uint32_t event, t27_arr_uint32_t_32 node_states, t27_arr_uint32_t_32 link_states) {
t27_arr_uint32_t_32 states = node_states;
uint32_t event_type = get_event_type(event);
uint32_t node_id = get_event_node_id(event);
if ((event_type == EVENT_PACKET_SEND)) {
return 1;
} else if ((event_type == EVENT_PACKET_RECV)) {
return 1;
} else if ((event_type == EVENT_NODE_FAILURE)) {
uint32_t current_state = node_states.v[node_id];
node_states.v[node_id] = update_node_status(current_state, NODE_FAILED);
uint32_t current_state = states.v[node_id];
states.v[node_id] = update_node_status(current_state, NODE_FAILED);
return 1;
} else if ((event_type == EVENT_LINK_FAILURE)) {
return 1;
Expand Down Expand Up @@ -316,9 +317,10 @@ uint32_t create_topology(uint32_t node_count, uint32_t density) {
}

uint32_t inject_fault(uint32_t fault_type, uint32_t target_id, t27_arr_uint32_t_32 node_states) {
t27_arr_uint32_t_32 states = node_states;
if ((fault_type == EVENT_NODE_FAILURE)) {
uint32_t current_state = node_states.v[target_id];
node_states.v[target_id] = update_node_status(current_state, NODE_FAILED);
uint32_t current_state = states.v[target_id];
states.v[target_id] = update_node_status(current_state, NODE_FAILED);
return 1;
} else if ((fault_type == EVENT_LINK_FAILURE)) {
return 1;
Expand Down
5 changes: 3 additions & 2 deletions gen/c/performance_profiler.c
Original file line number Diff line number Diff line change
Expand Up @@ -230,10 +230,11 @@ uint32_t get_allocation_pool(uint32_t alloc) {
}

uint32_t track_allocation(t27_arr_uint32_t_64 allocations, uint32_t alloc_id, uint32_t size, uint32_t pool) {
t27_arr_uint32_t_64 allocs = allocations;
uint32_t i = 0;
while ((i < MAX_SAMPLES)) {
if ((get_allocation_id(allocations.v[i]) == 0)) {
allocations.v[i] = create_allocation(alloc_id, size, 255, pool);
if ((get_allocation_id(allocs.v[i]) == 0)) {
allocs.v[i] = create_allocation(alloc_id, size, 255, pool);
return 1;
}
i = (i + 1);
Expand Down
14 changes: 8 additions & 6 deletions gen/c/topology_visualizer.c
Original file line number Diff line number Diff line change
Expand Up @@ -233,6 +233,7 @@ uint32_t calculate_force_layout(t27_arr_uint32_t_32 nodes, t27_arr_uint32_t_64 e
}

uint32_t calculate_circular_layout(t27_arr_uint32_t_32 nodes, uint32_t node_count) {
t27_arr_uint32_t_32 vnodes = nodes;
uint32_t center_x = (CANVAS_SIZE / 2);
uint32_t center_y = (CANVAS_SIZE / 2);
uint32_t radius = (CANVAS_SIZE / 3);
Expand All @@ -241,15 +242,16 @@ uint32_t calculate_circular_layout(t27_arr_uint32_t_32 nodes, uint32_t node_coun
uint32_t angle = ((i * 360) / node_count);
uint32_t x = (center_x + ((radius * angle) / 360));
uint32_t y = (center_y + ((radius * angle) / 360));
uint32_t node_id = get_viz_node_id(nodes.v[i]);
uint32_t status = get_node_visual_status(nodes.v[i]);
nodes.v[i] = create_visual_node(node_id, x, y, status);
uint32_t node_id = get_viz_node_id(vnodes.v[i]);
uint32_t status = get_node_visual_status(vnodes.v[i]);
vnodes.v[i] = create_visual_node(node_id, x, y, status);
i = (i + 1);
}
return node_count;
}

uint32_t calculate_hierarchical_layout(t27_arr_uint32_t_32 nodes, t27_arr_uint32_t_64 edges, uint32_t node_count, uint32_t edge_count) {
t27_arr_uint32_t_32 vnodes = nodes;
uint32_t level_count = 4;
uint32_t nodes_per_level = (node_count / level_count);
uint32_t i = 0;
Expand All @@ -258,9 +260,9 @@ uint32_t calculate_hierarchical_layout(t27_arr_uint32_t_32 nodes, t27_arr_uint32
while ((i < node_count)) {
uint32_t y = ((current_level * CANVAS_SIZE) / level_count);
uint32_t x = ((nodes_in_level * CANVAS_SIZE) / nodes_per_level);
uint32_t node_id = get_viz_node_id(nodes.v[i]);
uint32_t status = get_node_visual_status(nodes.v[i]);
nodes.v[i] = create_visual_node(node_id, x, y, status);
uint32_t node_id = get_viz_node_id(vnodes.v[i]);
uint32_t status = get_node_visual_status(vnodes.v[i]);
vnodes.v[i] = create_visual_node(node_id, x, y, status);
nodes_in_level = (nodes_in_level + 1);
if ((nodes_in_level >= nodes_per_level)) {
nodes_in_level = 0;
Expand Down
Loading
Loading