diff --git a/Cargo.toml b/Cargo.toml index 9ef22f50..5a6f0d73 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -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" diff --git a/gen/c/api_documenter.c b/gen/c/api_documenter.c index 8a73a6d1..1e74b309 100644 --- a/gen/c/api_documenter.c +++ b/gen/c/api_documenter.c @@ -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); diff --git a/gen/c/auto_config.c b/gen/c/auto_config.c index 8f586f37..02510d33 100644 --- a/gen/c/auto_config.c +++ b/gen/c/auto_config.c @@ -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); @@ -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); @@ -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)) { @@ -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; } } @@ -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)) { @@ -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; } diff --git a/gen/c/bandwidth_allocator.c b/gen/c/bandwidth_allocator.c index a89a681c..bdaa36de 100644 --- a/gen/c/bandwidth_allocator.c +++ b/gen/c/bandwidth_allocator.c @@ -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) { diff --git a/gen/c/cache_management.c b/gen/c/cache_management.c index 1dd82a7f..9f5b45c5 100644 --- a/gen/c/cache_management.c +++ b/gen/c/cache_management.c @@ -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) { @@ -183,10 +185,11 @@ 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; @@ -194,10 +197,11 @@ uint32_t remove_entry(t27_arr_uint32_t_16 cache, uint32_t current_size, uint32_t } 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; @@ -205,12 +209,13 @@ uint32_t access_cache(t27_arr_uint32_t_16 cache, uint32_t data_id) { } 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); } diff --git a/gen/c/compression_engine.c b/gen/c/compression_engine.c index b7e81f7c..05cb223b 100644 --- a/gen/c/compression_engine.c +++ b/gen/c/compression_engine.c @@ -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; diff --git a/gen/c/integration_framework.c b/gen/c/integration_framework.c index 1fe92195..078958ff 100644 --- a/gen/c/integration_framework.c +++ b/gen/c/integration_framework.c @@ -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 @@ -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); @@ -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); @@ -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); diff --git a/gen/c/network_simulator.c b/gen/c/network_simulator.c index 0f6df73c..bd689760 100644 --- a/gen/c/network_simulator.c +++ b/gen/c/network_simulator.c @@ -248,6 +248,7 @@ 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)) { @@ -255,8 +256,8 @@ uint32_t process_event(uint32_t event, t27_arr_uint32_t_32 node_states, t27_arr_ } 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; @@ -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; diff --git a/gen/c/performance_profiler.c b/gen/c/performance_profiler.c index 60a26042..681f585a 100644 --- a/gen/c/performance_profiler.c +++ b/gen/c/performance_profiler.c @@ -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); diff --git a/gen/c/topology_visualizer.c b/gen/c/topology_visualizer.c index 5abde5e3..6788759f 100644 --- a/gen/c/topology_visualizer.c +++ b/gen/c/topology_visualizer.c @@ -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); @@ -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; @@ -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; diff --git a/gen/c/traffic_animator.c b/gen/c/traffic_animator.c index ad0b8c22..5bb69836 100644 --- a/gen/c/traffic_animator.c +++ b/gen/c/traffic_animator.c @@ -308,20 +308,21 @@ uint32_t calculate_packet_position(uint32_t source_x, uint32_t source_y, uint32_ } uint32_t update_animation_packets(t27_arr_uint32_t_64 packets, uint32_t packet_count, uint32_t speed) { + t27_arr_uint32_t_64 pkts = packets; uint32_t updated_count = 0; uint32_t completed_count = 0; uint32_t i = 0; while ((i < packet_count)) { - uint32_t progress = get_anim_packet_progress(packets.v[i]); + uint32_t progress = get_anim_packet_progress(pkts.v[i]); if ((progress < 100)) { uint32_t new_progress = (progress + speed); if ((new_progress > 100)) { new_progress = 100; } - uint32_t packet_id = get_anim_packet_id(packets.v[i]); - uint32_t source = get_anim_packet_source(packets.v[i]); - uint32_t dest = get_anim_packet_dest(packets.v[i]); - packets.v[i] = create_anim_packet(packet_id, source, dest, new_progress); + uint32_t packet_id = get_anim_packet_id(pkts.v[i]); + uint32_t source = get_anim_packet_source(pkts.v[i]); + uint32_t dest = get_anim_packet_dest(pkts.v[i]); + pkts.v[i] = create_anim_packet(packet_id, source, dest, new_progress); updated_count = (updated_count + 1); } else { completed_count = (completed_count + 1); diff --git a/gen/rust/api_documenter.rs b/gen/rust/api_documenter.rs index b4d96247..d15abe08 100644 --- a/gen/rust/api_documenter.rs +++ b/gen/rust/api_documenter.rs @@ -9,8 +9,15 @@ pub const MAX_EXAMPLES: u32 = 8; pub const MAX_DESCRIPTIONS: u32 = 32; -pub fn create_function_doc(func_id: u32, param_count: u32, return_type: u32, complexity: u32) -> u32 { - return (((((func_id & 0xFF) << 24) | ((param_count & 0xF) << 20)) | ((return_type & 0xF) << 16)) | (complexity & 0xFFFF)); +pub fn create_function_doc( + func_id: u32, + param_count: u32, + return_type: u32, + complexity: u32, +) -> u32 { + return (((((func_id & 0xFF) << 24) | ((param_count & 0xF) << 20)) + | ((return_type & 0xF) << 16)) + | (complexity & 0xFFFF)); } pub fn get_doc_function_id(doc: u32) -> u32 { @@ -30,7 +37,9 @@ pub fn get_doc_complexity(doc: u32) -> u32 { } pub fn create_param_doc(param_id: u32, param_type: u32, direction: u32, desc_id: u32) -> u32 { - return (((((param_id & 0xFF) << 24) | ((param_type & 0xF) << 20)) | ((direction & 0x3) << 18)) | (desc_id & 0x3FFFF)); + return (((((param_id & 0xFF) << 24) | ((param_type & 0xF) << 20)) + | ((direction & 0x3) << 18)) + | (desc_id & 0x3FFFF)); } pub fn get_param_doc_id(param_doc: u32) -> u32 { @@ -70,7 +79,8 @@ pub fn extract_parameter_info(param_line: u32, param_index: u32) -> u32 { } pub fn create_function_example(func_id: u32, input: u32, output: u32, explanation: u32) -> u32 { - return (((((func_id & 0xFF) << 24) | ((input & 0xFF) << 16)) | ((output & 0xFF) << 8)) | (explanation & 0xFF)); + return (((((func_id & 0xFF) << 24) | ((input & 0xFF) << 16)) | ((output & 0xFF) << 8)) + | (explanation & 0xFF)); } pub fn get_example_function_id(example: u32) -> u32 { @@ -100,7 +110,8 @@ pub fn generate_function_example(func_doc: u32) -> u32 { } pub fn create_description_text(desc_id: u32, length: u32, importance: u32, category: u32) -> u32 { - return (((((desc_id & 0xFF) << 24) | ((length & 0xFF) << 16)) | ((importance & 0xF) << 12)) | (category & 0xFFF)); + return (((((desc_id & 0xFF) << 24) | ((length & 0xFF) << 16)) | ((importance & 0xF) << 12)) + | (category & 0xFFF)); } pub fn get_description_id(desc: u32) -> u32 { @@ -133,7 +144,8 @@ pub fn generate_function_description(func_doc: u32, complexity: u32) -> u32 { } pub fn create_cross_reference(source: u32, target: u32, ref_type: u32, strength: u32) -> u32 { - return (((((source & 0xFF) << 24) | ((target & 0xFF) << 16)) | ((ref_type & 0xF) << 12)) | (strength & 0xFFF)); + return (((((source & 0xFF) << 24) | ((target & 0xFF) << 16)) | ((ref_type & 0xF) << 12)) + | (strength & 0xFFF)); } pub fn get_xref_source(xref: u32) -> u32 { @@ -164,8 +176,15 @@ pub fn detect_function_call(caller: u32, callee: u32) -> u32 { return create_cross_reference(caller, callee, XREF_CALLS, 100); } -pub fn create_module_doc(module_id: u32, func_count: u32, total_complexity: u32, description: u32) -> u32 { - return (((((module_id & 0xFF) << 24) | ((func_count & 0xFF) << 16)) | ((total_complexity & 0xFF) << 8)) | (description & 0xFF)); +pub fn create_module_doc( + module_id: u32, + func_count: u32, + total_complexity: u32, + description: u32, +) -> u32 { + return (((((module_id & 0xFF) << 24) | ((func_count & 0xFF) << 16)) + | ((total_complexity & 0xFF) << 8)) + | (description & 0xFF)); } pub fn get_module_doc_id(module_doc: u32) -> u32 { @@ -184,7 +203,10 @@ pub fn get_module_description(module_doc: u32) -> u32 { return (module_doc & 0xFF); } -pub fn calculate_average_complexity(func_docs: [u32; MAX_FUNCTIONS as usize], func_count: u32) -> u32 { +pub fn calculate_average_complexity( + func_docs: [u32; MAX_FUNCTIONS as usize], + func_count: u32, +) -> u32 { let mut total_complexity: u32 = 0; let mut i: u32 = 0; while (i < func_count) { @@ -198,20 +220,28 @@ pub fn calculate_average_complexity(func_docs: [u32; MAX_FUNCTIONS as usize], fu } } -pub fn generate_api_documentation(func_docs: [u32; MAX_FUNCTIONS as usize], func_count: u32, param_docs: [u32; MAX_PARAMETERS as usize], param_count: u32) -> u32 { +pub fn generate_api_documentation( + func_docs: [u32; MAX_FUNCTIONS as usize], + func_count: u32, + param_docs: [u32; MAX_PARAMETERS as usize], + param_count: u32, +) -> u32 { let mut total_complexity: u32 = 0; let mut documented_funcs: u32 = 0; let mut i: u32 = 0; while (i < func_count) { let func_doc: u32 = func_docs[(i) as usize]; total_complexity = (total_complexity + get_doc_complexity(func_doc)); - let description: u32 = generate_function_description(func_doc, get_doc_complexity(func_doc)); + let description: u32 = + generate_function_description(func_doc, get_doc_complexity(func_doc)); let example: u32 = generate_function_example(func_doc); documented_funcs = (documented_funcs + 1); i = (i + 1); } let avg_complexity: u32 = calculate_average_complexity(func_docs, func_count); - return (((((documented_funcs & 0xFF) << 24) | ((total_complexity & 0xFF) << 16)) | ((avg_complexity & 0xFF) << 8)) | (param_count & 0xFF)); + return (((((documented_funcs & 0xFF) << 24) | ((total_complexity & 0xFF) << 16)) + | ((avg_complexity & 0xFF) << 8)) + | (param_count & 0xFF)); } pub fn calculate_documentation_coverage(documented_funcs: u32, total_funcs: u32) -> u32 { @@ -245,7 +275,9 @@ pub fn create_dependency_graph(xrefs: [u32; MAX_FUNCTIONS as usize], xref_count: if (total_connections > 0) { avg_strength = (strong_connections / total_connections); } - return (((((total_connections & 0xFF) << 24) | ((strong_connections & 0xFF) << 16)) | ((avg_strength & 0xFF) << 8)) | (xref_count & 0xFF)); + return (((((total_connections & 0xFF) << 24) | ((strong_connections & 0xFF) << 16)) + | ((avg_strength & 0xFF) << 8)) + | (xref_count & 0xFF)); } pub fn validate_documentation(func_docs: [u32; MAX_FUNCTIONS as usize], func_count: u32) -> u32 { @@ -269,11 +301,18 @@ pub fn validate_documentation(func_docs: [u32; MAX_FUNCTIONS as usize], func_cou if (quality_score > 100) { quality_score = 100; } - return (((((missing_descriptions & 0xFF) << 24) | ((missing_examples & 0xFF) << 16)) | ((missing_params & 0xFF) << 8)) | (quality_score & 0xFF)); -} - -pub fn generate_documentation_report(func_docs: [u32; MAX_FUNCTIONS as usize], func_count: u32, xrefs: [u32; MAX_FUNCTIONS as usize], xref_count: u32) -> u32 { - let empty_params: [u32; MAX_PARAMETERS as usize] = [0; MAX_PARAMETERS]; + return (((((missing_descriptions & 0xFF) << 24) | ((missing_examples & 0xFF) << 16)) + | ((missing_params & 0xFF) << 8)) + | (quality_score & 0xFF)); +} + +pub fn generate_documentation_report( + func_docs: [u32; MAX_FUNCTIONS as usize], + func_count: u32, + xrefs: [u32; MAX_FUNCTIONS as usize], + xref_count: u32, +) -> u32 { + let empty_params: [u32; MAX_PARAMETERS as usize] = [0; 16]; let doc_summary: u32 = generate_api_documentation(func_docs, func_count, empty_params, 0); let documented_funcs: u32 = ((doc_summary >> 24) & 0xFF); let coverage: u32 = calculate_documentation_coverage(documented_funcs, func_count); @@ -281,6 +320,7 @@ pub fn generate_documentation_report(func_docs: [u32; MAX_FUNCTIONS as usize], f let quality_score: u32 = (validation & 0xFF); let dependency_graph: u32 = create_dependency_graph(xrefs, xref_count); let doc_complexity: u32 = ((doc_summary >> 8) & 0xFF); - return (((((coverage & 0xFF) << 24) | ((quality_score & 0xFF) << 16)) | ((doc_complexity & 0xFF) << 8)) | (xref_count & 0xFF)); + return (((((coverage & 0xFF) << 24) | ((quality_score & 0xFF) << 16)) + | ((doc_complexity & 0xFF) << 8)) + | (xref_count & 0xFF)); } - diff --git a/gen/rust/auto_config.rs b/gen/rust/auto_config.rs index d09171cb..d5f0576f 100644 --- a/gen/rust/auto_config.rs +++ b/gen/rust/auto_config.rs @@ -10,7 +10,8 @@ pub const CONFIG_VERSION: u32 = 1; pub const AUTO_DISCOVERY_INTERVAL: u32 = 1000; pub fn create_config_param(param_id: u32, value: u32, scope: u32, status: u32) -> u32 { - return (((((param_id & 0xFF) << 24) | ((value & 0xFFFF) << 8)) | ((scope & 0xF) << 4)) | (status & 0xF)); + return (((((param_id & 0xFF) << 24) | ((value & 0xFFFF) << 8)) | ((scope & 0xF) << 4)) + | (status & 0xF)); } pub fn get_param_id(param: u32) -> u32 { @@ -102,13 +103,14 @@ pub fn get_config_value(config: [u32; MAX_PARAMS as usize], param_id: u32) -> u3 } pub fn set_config_value(config: [u32; MAX_PARAMS as usize], param_id: u32, new_value: u32) -> u32 { + let mut cfg: [u32; MAX_PARAMS as usize] = config; let mut i: u32 = 0; while (i < MAX_PARAMS) { - let current_param_id: u32 = get_param_id(config[(i) as usize]); + let current_param_id: u32 = get_param_id(cfg[(i) as usize]); if (current_param_id == param_id) { - let scope: u32 = get_param_scope(config[(i) as usize]); + let scope: u32 = get_param_scope(cfg[(i) as usize]); let status: u32 = STATUS_PENDING; - config[(i) as usize] = create_config_param(param_id, new_value, scope, status); + cfg[(i) as usize] = create_config_param(param_id, new_value, scope, status); return 1; } i = (i + 1); @@ -117,7 +119,24 @@ pub fn set_config_value(config: [u32; MAX_PARAMS as usize], param_id: u32, new_v } pub fn discover_network_params(node_count: u32, interference_level: u32) -> u32 { - let config: [u32; MAX_PARAMS as usize] = [default_config_at(0),default_config_at(1),default_config_at(2),default_config_at(3),default_config_at(4),default_config_at(5),default_config_at(6),default_config_at(7),0,0,0,0,0,0,0,0]; + let config: [u32; MAX_PARAMS as usize] = [ + default_config_at(0), + default_config_at(1), + default_config_at(2), + default_config_at(3), + default_config_at(4), + default_config_at(5), + default_config_at(6), + default_config_at(7), + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + ]; let mut tx_power: u32 = 50; if (node_count < 4) { tx_power = 30; @@ -149,14 +168,15 @@ pub fn discover_network_params(node_count: u32, interference_level: u32) -> u32 } pub fn apply_config(config: [u32; MAX_PARAMS as usize], param_id: u32) -> u32 { + let mut cfg: [u32; MAX_PARAMS as usize] = config; let mut i: u32 = 0; while (i < MAX_PARAMS) { - let current_param_id: u32 = get_param_id(config[(i) as usize]); + let current_param_id: u32 = get_param_id(cfg[(i) as usize]); if (current_param_id == param_id) { - let value: u32 = get_param_value(config[(i) as usize]); - let scope: u32 = get_param_scope(config[(i) as usize]); + let value: u32 = get_param_value(cfg[(i) as usize]); + let scope: u32 = get_param_scope(cfg[(i) as usize]); let success: u32 = 1; - config[(i) as usize] = create_config_param(param_id, value, scope, STATUS_APPLIED); + cfg[(i) as usize] = create_config_param(param_id, value, scope, STATUS_APPLIED); return success; } i = (i + 1); @@ -183,22 +203,22 @@ pub fn apply_all_pending(config: [u32; MAX_PARAMS as usize]) -> u32 { pub fn validate_config(config: [u32; MAX_PARAMS as usize], param_id: u32) -> u32 { let value: u32 = 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 { @@ -218,7 +238,7 @@ pub fn validate_config(config: [u32; MAX_PARAMS as usize], param_id: u32) -> u32 } } else { if (param_id == PARAM_SECURITY_LEVEL) { - if ((value >= 0) && (value <= 3)) { + if (value <= 3) { return 1; } } @@ -232,7 +252,11 @@ pub fn validate_config(config: [u32; MAX_PARAMS as usize], param_id: u32) -> u32 return 0; } -pub fn optimize_config(config: [u32; MAX_PARAMS as usize], network_load: u32, error_rate: u32) -> u32 { +pub fn optimize_config( + config: [u32; MAX_PARAMS as usize], + network_load: u32, + error_rate: u32, +) -> u32 { let mut optimizations: u32 = 0; if (network_load > 80) { let current_retries: u32 = get_config_value(config, PARAM_RETRY_LIMIT); @@ -258,7 +282,10 @@ pub fn optimize_config(config: [u32; MAX_PARAMS as usize], network_load: u32, er return optimizations; } -pub fn sync_config(local_config: [u32; MAX_PARAMS as usize], remote_config: [u32; MAX_PARAMS as usize]) -> u32 { +pub fn sync_config( + local_config: [u32; MAX_PARAMS as usize], + remote_config: [u32; MAX_PARAMS as usize], +) -> u32 { let mut synced_count: u32 = 0; let mut i: u32 = 0; while (i < MAX_PARAMS) { @@ -286,7 +313,11 @@ pub fn sync_config(local_config: [u32; MAX_PARAMS as usize], remote_config: [u32 return synced_count; } -pub fn rollback_config(config: [u32; MAX_PARAMS as usize], backup_config: [u32; MAX_PARAMS as usize]) -> u32 { +pub fn rollback_config( + config: [u32; MAX_PARAMS as usize], + backup_config: [u32; MAX_PARAMS as usize], +) -> u32 { + let mut cfg: [u32; MAX_PARAMS as usize] = config; let mut rolled_back: u32 = 0; let mut i: u32 = 0; while (i < MAX_PARAMS) { @@ -295,9 +326,14 @@ pub fn rollback_config(config: [u32; MAX_PARAMS as usize], backup_config: [u32; let backup_scope: u32 = get_param_scope(backup_config[(i) as usize]); let mut j: u32 = 0; while (j < MAX_PARAMS) { - let local_param_id: u32 = get_param_id(config[(j) as usize]); + let local_param_id: u32 = get_param_id(cfg[(j) as usize]); if (local_param_id == backup_param_id) { - config[(j) as usize] = create_config_param(backup_param_id, backup_value, backup_scope, STATUS_PENDING); + cfg[(j) as usize] = create_config_param( + backup_param_id, + backup_value, + backup_scope, + STATUS_PENDING, + ); rolled_back = (rolled_back + 1); break; } @@ -309,10 +345,13 @@ pub fn rollback_config(config: [u32; MAX_PARAMS as usize], backup_config: [u32; } pub fn backup_element(config: [u32; MAX_PARAMS as usize], index: u32) -> u32 { - return config[((index as usize)) as usize]; + return config[(index as usize) as usize]; } -pub fn calculate_config_drift(config1: [u32; MAX_PARAMS as usize], config2: [u32; MAX_PARAMS as usize]) -> u32 { +pub fn calculate_config_drift( + config1: [u32; MAX_PARAMS as usize], + config2: [u32; MAX_PARAMS as usize], +) -> u32 { let mut drift_count: u32 = 0; let mut total_params: u32 = 0; let mut i: u32 = 0; @@ -366,4 +405,3 @@ pub fn assign_node_role(node_id: u32, capabilities: u32) -> u32 { } return role; } - diff --git a/gen/rust/bandwidth_allocator.rs b/gen/rust/bandwidth_allocator.rs index 6e0fa734..62982fdc 100644 --- a/gen/rust/bandwidth_allocator.rs +++ b/gen/rust/bandwidth_allocator.rs @@ -16,7 +16,8 @@ pub const PRIORITY_MEDIUM: u32 = 2; pub const PRIORITY_HIGH: u32 = 3; pub fn create_flow_requirement(flow_id: u32, priority: u32, min_bw: u32, current_bw: u32) -> u32 { - return (((((flow_id & 0xFF) << 24) | ((priority & 0x3) << 22)) | ((min_bw & 0x3FF) << 12)) | (current_bw & 0xFFF)); + return (((((flow_id & 0xFF) << 24) | ((priority & 0x3) << 22)) | ((min_bw & 0x3FF) << 12)) + | (current_bw & 0xFFF)); } pub fn get_flow_id(req: u32) -> u32 { @@ -35,8 +36,15 @@ pub fn get_current_bandwidth(req: u32) -> u32 { return (req & 0xFFF); } -pub fn create_allocation_state(allocated: u32, pending: u32, fair_share: u32, last_update: u32) -> u32 { - return (((((allocated & 0x7FF) << 21) | ((pending & 0xFF) << 13)) | ((fair_share & 0x1FF) << 4)) | (last_update & 0xF)); +pub fn create_allocation_state( + allocated: u32, + pending: u32, + fair_share: u32, + last_update: u32, +) -> u32 { + return (((((allocated & 0x7FF) << 21) | ((pending & 0xFF) << 13)) + | ((fair_share & 0x1FF) << 4)) + | (last_update & 0xF)); } pub fn get_allocated_bw(state: u32) -> u32 { @@ -55,8 +63,17 @@ pub fn get_last_update(state: u32) -> u32 { return (state & 0xF); } -pub fn create_flow_array(f0: u32, f1: u32, f2: u32, f3: u32, f4: u32, f5: u32, f6: u32, f7: u32) -> [u32; 8] { - return [f0,f1,f2,f3,f4,f5,f6,f7]; +pub fn create_flow_array( + f0: u32, + f1: u32, + f2: u32, + f3: u32, + f4: u32, + f5: u32, + f6: u32, + f7: u32, +) -> [u32; 8] { + return [f0, f1, f2, f3, f4, f5, f6, f7]; } pub fn get_flow_req(array: [u32; 8], index: u32) -> u32 { @@ -113,13 +130,14 @@ pub fn update_flow_bandwidth(flow_req: u32, new_bw: u32) -> u32 { let flow_id = get_flow_id(flow_req); let priority = get_flow_priority(flow_req); let min_bw = get_min_bandwidth(flow_req); - if (new_bw < min_bw) { - new_bw = min_bw; + let mut bw: u32 = 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); } pub fn count_active_flows(flow_array: [u32; 8]) -> u32 { @@ -194,6 +212,14 @@ pub fn prioritize_bandwidth(flow_array: [u32; 8], available_bw: u32) -> [u32; 8] let f5 = get_flow_req(flow_array, 5); let f6 = get_flow_req(flow_array, 6); let f7 = get_flow_req(flow_array, 7); - return create_flow_array(update_flow_bandwidth(f0, calculate_fair_share(remaining_bw, 8)), update_flow_bandwidth(f1, calculate_fair_share(remaining_bw, 8)), update_flow_bandwidth(f2, calculate_fair_share(remaining_bw, 8)), update_flow_bandwidth(f3, calculate_fair_share(remaining_bw, 8)), update_flow_bandwidth(f4, calculate_fair_share(remaining_bw, 8)), update_flow_bandwidth(f5, calculate_fair_share(remaining_bw, 8)), update_flow_bandwidth(f6, calculate_fair_share(remaining_bw, 8)), update_flow_bandwidth(f7, calculate_fair_share(remaining_bw, 8))); + return create_flow_array( + update_flow_bandwidth(f0, calculate_fair_share(remaining_bw, 8)), + update_flow_bandwidth(f1, calculate_fair_share(remaining_bw, 8)), + update_flow_bandwidth(f2, calculate_fair_share(remaining_bw, 8)), + update_flow_bandwidth(f3, calculate_fair_share(remaining_bw, 8)), + update_flow_bandwidth(f4, calculate_fair_share(remaining_bw, 8)), + update_flow_bandwidth(f5, calculate_fair_share(remaining_bw, 8)), + update_flow_bandwidth(f6, calculate_fair_share(remaining_bw, 8)), + update_flow_bandwidth(f7, calculate_fair_share(remaining_bw, 8)), + ); } - diff --git a/gen/rust/cache_management.rs b/gen/rust/cache_management.rs index ae28d10a..87dc894a 100644 --- a/gen/rust/cache_management.rs +++ b/gen/rust/cache_management.rs @@ -10,7 +10,8 @@ pub const CACHE_HIT_THRESHOLD: u32 = 2; pub const EVICTION_AGE: u32 = 1000; pub fn create_cache_entry(data_id: u32, access_count: u32, age: u32, size: u32) -> u32 { - return (((((data_id & 0xFF) << 24) | ((access_count & 0xFF) << 16)) | ((age & 0xFF) << 8)) | (size & 0xFF)); + return (((((data_id & 0xFF) << 24) | ((access_count & 0xFF) << 16)) | ((age & 0xFF) << 8)) + | (size & 0xFF)); } pub fn get_data_id(entry: u32) -> u32 { @@ -77,33 +78,40 @@ pub fn get_entry(cache: [u32; MAX_ENTRIES as usize], data_id: u32) -> u32 { } } -pub fn add_entry(cache: [u32; MAX_ENTRIES as usize], current_size: u32, data_id: u32, size: u32) -> u32 { - let existing_index: u32 = find_entry(cache, data_id); +pub fn add_entry( + cache: [u32; MAX_ENTRIES as usize], + current_size: u32, + data_id: u32, + size: u32, +) -> u32 { + let mut slots: [u32; MAX_ENTRIES as usize] = cache; + let mut used: u32 = current_size; + let existing_index: u32 = find_entry(slots, data_id); if (existing_index < MAX_ENTRIES) { - return current_size; + return used; } let mut empty_index: u32 = MAX_ENTRIES; let mut i: u32 = 0; while (i < MAX_ENTRIES) { - if (get_data_id(cache[(i) as usize]) == 0) { + if (get_data_id(slots[(i) as usize]) == 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; } - let evicted_size: u32 = get_entry_size(cache[(empty_index) as usize]); - current_size = (current_size - evicted_size); + let evicted_size: u32 = get_entry_size(slots[(empty_index) as usize]); + used = (used - evicted_size); } - if ((current_size + size) > MAX_CACHE_SIZE) { - return current_size; + if ((used + size) > MAX_CACHE_SIZE) { + return used; } - cache[(empty_index) as usize] = create_cache_entry(data_id, 1, 0, size); - return (current_size + size); + slots[(empty_index) as usize] = create_cache_entry(data_id, 1, 0, size); + return (used + size); } pub fn find_eviction_candidate(cache: [u32; MAX_ENTRIES as usize]) -> u32 { @@ -128,10 +136,11 @@ pub fn find_eviction_candidate(cache: [u32; MAX_ENTRIES as usize]) -> u32 { } pub fn remove_entry(cache: [u32; MAX_ENTRIES as usize], current_size: u32, data_id: u32) -> u32 { - let entry_index: u32 = find_entry(cache, data_id); + let mut slots: [u32; MAX_ENTRIES as usize] = cache; + let entry_index: u32 = find_entry(slots, data_id); if (entry_index < MAX_ENTRIES) { - let entry_size: u32 = get_entry_size(cache[(entry_index) as usize]); - cache[(entry_index) as usize] = 0; + let entry_size: u32 = get_entry_size(slots[(entry_index) as usize]); + slots[(entry_index) as usize] = 0; return (current_size - entry_size); } else { return current_size; @@ -139,10 +148,11 @@ pub fn remove_entry(cache: [u32; MAX_ENTRIES as usize], current_size: u32, data_ } pub fn access_cache(cache: [u32; MAX_ENTRIES as usize], data_id: u32) -> u32 { - let entry_index: u32 = find_entry(cache, data_id); + let mut slots: [u32; MAX_ENTRIES as usize] = cache; + let entry_index: u32 = find_entry(slots, data_id); if (entry_index < MAX_ENTRIES) { - cache[(entry_index) as usize] = update_access_count(cache[(entry_index) as usize]); - cache[(entry_index) as usize] = update_age(cache[(entry_index) as usize], 0); + slots[(entry_index) as usize] = update_access_count(slots[(entry_index) as usize]); + slots[(entry_index) as usize] = update_age(slots[(entry_index) as usize], 0); return 1; } else { return 0; @@ -150,12 +160,13 @@ pub fn access_cache(cache: [u32; MAX_ENTRIES as usize], data_id: u32) -> u32 { } pub fn age_cache(cache: [u32; MAX_ENTRIES as usize]) -> () { + let mut slots: [u32; MAX_ENTRIES as usize] = cache; let mut i: u32 = 0; while (i < MAX_ENTRIES) { - let entry: u32 = cache[(i) as usize]; + let entry: u32 = slots[(i) as usize]; let age: u32 = get_age(entry); if (age < 255) { - cache[(i) as usize] = update_age(entry, (age + 1)); + slots[(i) as usize] = update_age(entry, (age + 1)); } i = (i + 1); } @@ -231,7 +242,8 @@ pub fn calculate_efficiency(hits: u32, total_accesses: u32, current_size: u32) - } pub fn create_cache_stats(hits: u32, misses: u32, size: u32, evictions: u32) -> u32 { - return (((((hits & 0xFF) << 24) | ((misses & 0xFF) << 16)) | ((size & 0xFF) << 8)) | (evictions & 0xFF)); + return (((((hits & 0xFF) << 24) | ((misses & 0xFF) << 16)) | ((size & 0xFF) << 8)) + | (evictions & 0xFF)); } pub fn get_hits(stats: u32) -> u32 { @@ -265,4 +277,3 @@ pub fn update_stats(stats: u32, hit: u32, evicted: u32) -> u32 { } return create_cache_stats(hits, misses, size, evictions); } - diff --git a/gen/rust/compression_engine.rs b/gen/rust/compression_engine.rs index d63688a3..fd200661 100644 --- a/gen/rust/compression_engine.rs +++ b/gen/rust/compression_engine.rs @@ -10,7 +10,8 @@ pub const COMPRESSION_THRESHOLD: u32 = 8; pub const DICTIONARY_SIZE: u32 = 8; pub fn create_block_info(orig_size: u32, comp_size: u32, method: u32, quality: u32) -> u32 { - return (((((orig_size & 0xFF) << 24) | ((comp_size & 0xFF) << 16)) | ((method & 0x3) << 14)) | (quality & 0x3FFF)); + return (((((orig_size & 0xFF) << 24) | ((comp_size & 0xFF) << 16)) | ((method & 0x3) << 14)) + | (quality & 0x3FFF)); } pub fn get_original_size(info: u32) -> u32 { @@ -162,7 +163,11 @@ pub fn decompress_delta(encoded: u32, previous: u32) -> u32 { } } -pub fn choose_compression_method(data: u32, previous: u32, dictionary: [u32; DICTIONARY_SIZE as usize]) -> u32 { +pub fn choose_compression_method( + data: u32, + previous: u32, + dictionary: [u32; DICTIONARY_SIZE as usize], +) -> u32 { let data_nibbles: u32 = 8; let rle_compressed: u32 = compress_rle(data, data_nibbles); let rle_ratio: u32 = calculate_compression_ratio(data_nibbles, rle_compressed); @@ -189,7 +194,11 @@ pub fn choose_compression_method(data: u32, previous: u32, dictionary: [u32; DIC } } -pub fn compress_block(data: u32, previous: u32, dictionary: [u32; DICTIONARY_SIZE as usize]) -> u32 { +pub fn compress_block( + data: u32, + previous: u32, + dictionary: [u32; DICTIONARY_SIZE as usize], +) -> u32 { let method: u32 = choose_compression_method(data, previous, dictionary); let mut compressed: u32 = 0; let mut compressed_size: u32 = 8; @@ -216,7 +225,12 @@ pub fn compress_block(data: u32, previous: u32, dictionary: [u32; DICTIONARY_SIZ return create_block_info(8, compressed_size, method, compressed_size); } -pub fn decompress_block(compressed_data: u32, method: u32, previous: u32, dictionary: [u32; DICTIONARY_SIZE as usize]) -> u32 { +pub fn decompress_block( + compressed_data: u32, + method: u32, + previous: u32, + dictionary: [u32; DICTIONARY_SIZE as usize], +) -> u32 { if (method == METHOD_RLE) { return decompress_rle(compressed_data); } else { @@ -248,9 +262,14 @@ pub fn calculate_total_savings(blocks: [u32; MAX_BLOCKS as usize], count: u32) - } } -pub fn update_dictionary(dictionary: [u32; DICTIONARY_SIZE as usize], new_entry: u32, index: u32) -> u32 { +pub fn update_dictionary( + dictionary: [u32; DICTIONARY_SIZE as usize], + new_entry: u32, + index: u32, +) -> u32 { + let mut dict: [u32; DICTIONARY_SIZE as usize] = dictionary; if (index < DICTIONARY_SIZE) { - dictionary[(index) as usize] = new_entry; + dict[(index) as usize] = new_entry; return 1; } else { return 0; @@ -277,4 +296,3 @@ pub fn calculate_compression_speed(original_size: u32, compressed_size: u32, tim return 0; } } - diff --git a/gen/rust/integration_framework.rs b/gen/rust/integration_framework.rs index 9964570a..c07a2085 100644 --- a/gen/rust/integration_framework.rs +++ b/gen/rust/integration_framework.rs @@ -9,8 +9,15 @@ pub const MAX_EVENTS: u32 = 64; pub const INTEGRATION_VERSION: u32 = 1; -pub fn create_module_registration(module_id: u32, module_type: u32, priority: u32, status: u32) -> u32 { - return (((((module_id & 0xFF) << 24) | ((module_type & 0xF) << 20)) | ((priority & 0xF) << 16)) | (status & 0xFFFF)); +pub fn create_module_registration( + module_id: u32, + module_type: u32, + priority: u32, + status: u32, +) -> u32 { + return (((((module_id & 0xFF) << 24) | ((module_type & 0xF) << 20)) + | ((priority & 0xF) << 16)) + | (status & 0xFFFF)); } pub fn get_registered_module_id(registration: u32) -> u32 { @@ -33,7 +40,7 @@ pub const TYPE_NETWORK: u32 = 0; pub const TYPE_TESTING: u32 = 1; -pub const type_documentation: u32 = 2; +pub const TYPE_DOCUMENTATION: u32 = 2; pub const TYPE_VISUALIZATION: u32 = 3; @@ -52,7 +59,8 @@ pub const STATUS_ERROR: u32 = 3; pub const STATUS_OFFLINE: u32 = 4; pub fn create_integration_message(msg_id: u32, source: u32, dest: u32, msg_type: u32) -> u32 { - return (((((msg_id & 0xFF) << 24) | ((source & 0xFF) << 16)) | ((dest & 0xFF) << 8)) | (msg_type & 0xFF)); + return (((((msg_id & 0xFF) << 24) | ((source & 0xFF) << 16)) | ((dest & 0xFF) << 8)) + | (msg_type & 0xFF)); } pub fn get_integration_message_id(message: u32) -> u32 { @@ -100,7 +108,11 @@ pub fn send_message(modules: [u32; MAX_MODULES as usize], message: u32) -> u32 { return 0; } -pub fn receive_message(messages: [u32; MAX_MESSAGES as usize], message_count: u32, module_id: u32) -> u32 { +pub fn receive_message( + messages: [u32; MAX_MESSAGES as usize], + message_count: u32, + module_id: u32, +) -> u32 { let mut i: u32 = 0; while (i < message_count) { let dest: u32 = get_integration_message_dest(messages[(i) as usize]); @@ -113,7 +125,8 @@ pub fn receive_message(messages: [u32; MAX_MESSAGES as usize], message_count: u3 } pub fn create_event(event_id: u32, event_type: u32, source: u32, data: u32) -> u32 { - return (((((event_id & 0xFF) << 24) | ((event_type & 0xF) << 20)) | ((source & 0xFF) << 12)) | (data & 0xFFF)); + return (((((event_id & 0xFF) << 24) | ((event_type & 0xF) << 20)) | ((source & 0xFF) << 12)) + | (data & 0xFFF)); } pub fn get_event_id(event: u32) -> u32 { @@ -142,12 +155,17 @@ pub const EVENT_SIMULATION_STEP: u32 = 3; pub const EVENT_VISUALIZATION_UPDATE: u32 = 4; -pub fn subscribe_to_event(module_id: u32, event_type: u32, subscriptions: [u32; MAX_EVENTS as usize]) -> u32 { +pub fn subscribe_to_event( + module_id: u32, + event_type: u32, + subscriptions: [u32; MAX_EVENTS as usize], +) -> u32 { + let mut subs: [u32; MAX_EVENTS as usize] = subscriptions; let subscription_id: u32 = ((module_id * 10) + event_type); let mut i: u32 = 0; while (i < MAX_EVENTS) { - if (subscriptions[(i) as usize] == 0) { - subscriptions[(i) as usize] = create_event(subscription_id, event_type, module_id, 0); + if (subs[(i) as usize] == 0) { + subs[(i) as usize] = create_event(subscription_id, event_type, module_id, 0); return 1; } i = (i + 1); @@ -155,7 +173,11 @@ pub fn subscribe_to_event(module_id: u32, event_type: u32, subscriptions: [u32; return 0; } -pub fn publish_event(event: u32, subscriptions: [u32; MAX_EVENTS as usize], modules: [u32; MAX_MODULES as usize]) -> u32 { +pub fn publish_event( + event: u32, + subscriptions: [u32; MAX_EVENTS as usize], + modules: [u32; MAX_MODULES as usize], +) -> u32 { let event_type: u32 = get_event_type(event); let mut notified_count: u32 = 0; let mut i: u32 = 0; @@ -174,8 +196,15 @@ pub fn publish_event(event: u32, subscriptions: [u32; MAX_EVENTS as usize], modu return notified_count; } -pub fn create_state_sync(module_id: u32, state_version: u32, state_data: u32, checksum: u32) -> u32 { - return (((((module_id & 0xFF) << 24) | ((state_version & 0xFF) << 16)) | ((state_data & 0xFF) << 8)) | (checksum & 0xFF)); +pub fn create_state_sync( + module_id: u32, + state_version: u32, + state_data: u32, + checksum: u32, +) -> u32 { + return (((((module_id & 0xFF) << 24) | ((state_version & 0xFF) << 16)) + | ((state_data & 0xFF) << 8)) + | (checksum & 0xFF)); } pub fn get_sync_module_id(sync: u32) -> u32 { @@ -194,7 +223,11 @@ pub fn get_sync_checksum(sync: u32) -> u32 { return (sync & 0xFF); } -pub fn synchronize_states(modules: [u32; MAX_MODULES as usize], module_count: u32, sync_requests: u32) -> u32 { +pub fn synchronize_states( + modules: [u32; MAX_MODULES as usize], + module_count: u32, + sync_requests: u32, +) -> u32 { let mut synced_count: u32 = 0; let mut i: u32 = 0; while (i < module_count) { @@ -212,8 +245,15 @@ pub fn synchronize_states(modules: [u32; MAX_MODULES as usize], module_count: u3 return synced_count; } -pub fn create_error_propagation(source_id: u32, error_code: u32, severity: u32, timestamp: u32) -> u32 { - return (((((source_id & 0xFF) << 24) | ((error_code & 0xFF) << 16)) | ((severity & 0xF) << 12)) | (timestamp & 0xFFF)); +pub fn create_error_propagation( + source_id: u32, + error_code: u32, + severity: u32, + timestamp: u32, +) -> u32 { + return (((((source_id & 0xFF) << 24) | ((error_code & 0xFF) << 16)) + | ((severity & 0xF) << 12)) + | (timestamp & 0xFFF)); } pub fn get_error_source(err_word: u32) -> u32 { @@ -240,7 +280,11 @@ pub const SEVERITY_ERROR: u32 = 2; pub const SEVERITY_CRITICAL: u32 = 3; -pub fn propagate_error(err_word: u32, modules: [u32; MAX_MODULES as usize], module_count: u32) -> u32 { +pub fn propagate_error( + err_word: u32, + modules: [u32; MAX_MODULES as usize], + module_count: u32, +) -> u32 { let severity: u32 = get_error_severity(err_word); let mut notified_count: u32 = 0; let mut i: u32 = 0; @@ -266,11 +310,18 @@ pub fn propagate_error(err_word: u32, modules: [u32; MAX_MODULES as usize], modu return notified_count; } -pub fn load_module(module_id: u32, module_type: u32, priority: u32, modules: [u32; MAX_MODULES as usize]) -> u32 { +pub fn load_module( + module_id: u32, + module_type: u32, + priority: u32, + modules: [u32; MAX_MODULES as usize], +) -> u32 { + let mut mods: [u32; MAX_MODULES as usize] = modules; let mut i: u32 = 0; while (i < MAX_MODULES) { - if (get_registered_module_id(modules[(i) as usize]) == 0) { - modules[(i) as usize] = create_module_registration(module_id, module_type, priority, STATUS_IDLE); + if (get_registered_module_id(mods[(i) as usize]) == 0) { + mods[(i) as usize] = + create_module_registration(module_id, module_type, priority, STATUS_IDLE); return 1; } i = (i + 1); @@ -279,11 +330,12 @@ pub fn load_module(module_id: u32, module_type: u32, priority: u32, modules: [u3 } pub fn unload_module(module_id: u32, modules: [u32; MAX_MODULES as usize]) -> u32 { + let mut mods: [u32; MAX_MODULES as usize] = modules; let mut i: u32 = 0; while (i < MAX_MODULES) { - let registered_id: u32 = get_registered_module_id(modules[(i) as usize]); + let registered_id: u32 = get_registered_module_id(mods[(i) as usize]); if (registered_id == module_id) { - modules[(i) as usize] = 0; + mods[(i) as usize] = 0; return 1; } i = (i + 1); @@ -291,8 +343,15 @@ pub fn unload_module(module_id: u32, modules: [u32; MAX_MODULES as usize]) -> u3 return 0; } -pub fn create_dependency(module_id: u32, depends_on: u32, dependency_type: u32, required: u32) -> u32 { - return (((((module_id & 0xFF) << 24) | ((depends_on & 0xFF) << 16)) | ((dependency_type & 0xF) << 12)) | (required & 0xFFF)); +pub fn create_dependency( + module_id: u32, + depends_on: u32, + dependency_type: u32, + required: u32, +) -> u32 { + return (((((module_id & 0xFF) << 24) | ((depends_on & 0xFF) << 16)) + | ((dependency_type & 0xF) << 12)) + | (required & 0xFFF)); } pub fn get_dependency_module_id(dep: u32) -> u32 { @@ -311,7 +370,12 @@ pub fn get_dependency_required(dep: u32) -> u32 { return (dep & 0xFFF); } -pub fn check_dependencies(module_id: u32, dependencies: [u32; MAX_MODULES as usize], loaded_modules: [u32; MAX_MODULES as usize], module_count: u32) -> u32 { +pub fn check_dependencies( + module_id: u32, + dependencies: [u32; MAX_MODULES as usize], + loaded_modules: [u32; MAX_MODULES as usize], + module_count: u32, +) -> u32 { let mut satisfied: u32 = 1; let mut i: u32 = 0; while (i < MAX_MODULES) { @@ -340,8 +404,15 @@ pub fn check_dependencies(module_id: u32, dependencies: [u32; MAX_MODULES as usi return satisfied; } -pub fn create_resource_request(module_id: u32, resource_type: u32, amount: u32, priority: u32) -> u32 { - return (((((module_id & 0xFF) << 24) | ((resource_type & 0xF) << 20)) | ((amount & 0xFF) << 12)) | (priority & 0xFFF)); +pub fn create_resource_request( + module_id: u32, + resource_type: u32, + amount: u32, + priority: u32, +) -> u32 { + return (((((module_id & 0xFF) << 24) | ((resource_type & 0xF) << 20)) + | ((amount & 0xFF) << 12)) + | (priority & 0xFFF)); } pub fn get_resource_request_module(req: u32) -> u32 { @@ -368,7 +439,11 @@ pub const RESOURCE_BANDWIDTH: u32 = 2; pub const RESOURCE_STORAGE: u32 = 3; -pub fn allocate_resources(requests: [u32; MAX_MESSAGES as usize], request_count: u32, available_resources: u32) -> u32 { +pub fn allocate_resources( + requests: [u32; MAX_MESSAGES as usize], + request_count: u32, + available_resources: u32, +) -> u32 { let mut total_requested: u32 = 0; let mut allocated_count: u32 = 0; let mut i: u32 = 0; @@ -395,11 +470,25 @@ pub fn allocate_resources(requests: [u32; MAX_MESSAGES as usize], request_count: } } -pub fn create_integration_report(loaded_modules: u32, active_messages: u32, events_processed: u32, errors_handled: u32) -> u32 { - return (((((loaded_modules & 0xFF) << 24) | ((active_messages & 0xFF) << 16)) | ((events_processed & 0xFF) << 8)) | (errors_handled & 0xFF)); -} - -pub fn generate_integration_stats(modules: [u32; MAX_MODULES as usize], module_count: u32, messages: [u32; MAX_MESSAGES as usize], message_count: u32, events: [u32; MAX_EVENTS as usize], event_count: u32) -> u32 { +pub fn create_integration_report( + loaded_modules: u32, + active_messages: u32, + events_processed: u32, + errors_handled: u32, +) -> u32 { + return (((((loaded_modules & 0xFF) << 24) | ((active_messages & 0xFF) << 16)) + | ((events_processed & 0xFF) << 8)) + | (errors_handled & 0xFF)); +} + +pub fn generate_integration_stats( + modules: [u32; MAX_MODULES as usize], + module_count: u32, + messages: [u32; MAX_MESSAGES as usize], + message_count: u32, + events: [u32; MAX_EVENTS as usize], + event_count: u32, +) -> u32 { let mut active_modules: u32 = 0; let mut active_messages: u32 = 0; let mut events_processed: u32 = 0; @@ -422,7 +511,12 @@ pub fn generate_integration_stats(modules: [u32; MAX_MODULES as usize], module_c events_processed = (events_processed + 1); k = (k + 1); } - return create_integration_report(active_modules, active_messages, events_processed, errors_handled); + return create_integration_report( + active_modules, + active_messages, + events_processed, + errors_handled, + ); } pub fn validate_integration_health(modules: [u32; MAX_MODULES as usize], module_count: u32) -> u32 { @@ -446,4 +540,3 @@ pub fn validate_integration_health(modules: [u32; MAX_MODULES as usize], module_ } return (((active_percentage & 0xFF) << 24) | ((error_count & 0xFF) << 16)); } - diff --git a/gen/rust/network_simulator.rs b/gen/rust/network_simulator.rs index 4524d459..00984173 100644 --- a/gen/rust/network_simulator.rs +++ b/gen/rust/network_simulator.rs @@ -10,7 +10,9 @@ pub const MAX_PACKETS: u32 = 64; pub const SIMULATION_TICK_MS: u32 = 10; pub fn create_sim_event(event_id: u32, timestamp: u32, event_type: u32, node_id: u32) -> u32 { - return (((((event_id & 0xFF) << 24) | ((timestamp & 0xFFFF) << 8)) | ((event_type & 0xF) << 4)) | (node_id & 0xF)); + return (((((event_id & 0xFF) << 24) | ((timestamp & 0xFFFF) << 8)) + | ((event_type & 0xF) << 4)) + | (node_id & 0xF)); } pub fn get_event_id(event: u32) -> u32 { @@ -42,7 +44,8 @@ pub const EVENT_TIMER_EXPIRE: u32 = 4; pub const EVENT_STATE_CHANGE: u32 = 5; pub fn create_node_state(node_id: u32, status: u32, energy: u32, position: u32) -> u32 { - return (((((node_id & 0xF) << 28) | ((status & 0xF) << 24)) | ((energy & 0xFF) << 16)) | (position & 0xFFFF)); + return (((((node_id & 0xF) << 28) | ((status & 0xF) << 24)) | ((energy & 0xFF) << 16)) + | (position & 0xFFFF)); } pub fn get_node_id(state: u32) -> u32 { @@ -95,7 +98,8 @@ pub fn update_node_energy(state: u32, energy_delta: u32) -> u32 { } pub fn create_link_state(source: u32, dest: u32, quality: u32, latency: u32) -> u32 { - return (((((source & 0xF) << 28) | ((dest & 0xF) << 24)) | ((quality & 0xFF) << 16)) | (latency & 0xFFFF)); + return (((((source & 0xF) << 28) | ((dest & 0xF) << 24)) | ((quality & 0xFF) << 16)) + | (latency & 0xFFFF)); } pub fn get_link_source(link: u32) -> u32 { @@ -131,7 +135,9 @@ pub fn is_link_operational(link: u32) -> u32 { } pub fn create_packet(packet_id: u32, source: u32, dest: u32, size: u32, sequence: u32) -> u32 { - return ((((((packet_id & 0xFF) << 24) | ((source & 0xF) << 20)) | ((dest & 0xF) << 16)) | ((size & 0xFF) << 8)) | (sequence & 0xFF)); + return ((((((packet_id & 0xFF) << 24) | ((source & 0xF) << 20)) | ((dest & 0xF) << 16)) + | ((size & 0xFF) << 8)) + | (sequence & 0xFF)); } pub fn get_packet_id(packet: u32) -> u32 { @@ -185,7 +191,12 @@ pub fn advance_simulation(state: u32, time_delta: u32) -> u32 { return create_sim_state(new_time, event_count, node_count); } -pub fn process_event(event: u32, node_states: [u32; MAX_NODES as usize], link_states: [u32; MAX_NODES as usize]) -> u32 { +pub fn process_event( + event: u32, + node_states: [u32; MAX_NODES as usize], + link_states: [u32; MAX_NODES as usize], +) -> u32 { + let mut states: [u32; MAX_NODES as usize] = node_states; let event_type: u32 = get_event_type(event); let node_id: u32 = get_event_node_id(event); if (event_type == EVENT_PACKET_SEND) { @@ -195,8 +206,8 @@ pub fn process_event(event: u32, node_states: [u32; MAX_NODES as usize], link_st return 1; } else { if (event_type == EVENT_NODE_FAILURE) { - let current_state: u32 = node_states[(node_id) as usize]; - node_states[(node_id) as usize] = update_node_status(current_state, NODE_FAILED); + let current_state: u32 = states[(node_id) as usize]; + states[(node_id) as usize] = update_node_status(current_state, NODE_FAILED); return 1; } else { if (event_type == EVENT_LINK_FAILURE) { @@ -214,7 +225,8 @@ pub fn process_event(event: u32, node_states: [u32; MAX_NODES as usize], link_st } pub fn create_sim_stats(sent: u32, recv: u32, dropped: u32, latency: u32) -> u32 { - return (((((sent & 0xFF) << 24) | ((recv & 0xFF) << 16)) | ((dropped & 0xFF) << 8)) | (latency & 0xFF)); + return (((((sent & 0xFF) << 24) | ((recv & 0xFF) << 16)) | ((dropped & 0xFF) << 8)) + | (latency & 0xFF)); } pub fn get_packets_sent(stats: u32) -> u32 { @@ -261,10 +273,15 @@ pub fn create_topology(node_count: u32, density: u32) -> u32 { return link_count; } -pub fn inject_fault(fault_type: u32, target_id: u32, node_states: [u32; MAX_NODES as usize]) -> u32 { +pub fn inject_fault( + fault_type: u32, + target_id: u32, + node_states: [u32; MAX_NODES as usize], +) -> u32 { + let mut states: [u32; MAX_NODES as usize] = node_states; if (fault_type == EVENT_NODE_FAILURE) { - let current_state: u32 = node_states[(target_id) as usize]; - node_states[(target_id) as usize] = update_node_status(current_state, NODE_FAILED); + let current_state: u32 = states[(target_id) as usize]; + states[(target_id) as usize] = update_node_status(current_state, NODE_FAILED); return 1; } else { if (fault_type == EVENT_LINK_FAILURE) { @@ -275,7 +292,13 @@ pub fn inject_fault(fault_type: u32, target_id: u32, node_states: [u32; MAX_NODE } } -pub fn run_simulation_step(state: u32, events: [u32; MAX_EVENTS as usize], event_count: u32, node_states: [u32; MAX_NODES as usize], link_states: [u32; MAX_NODES as usize]) -> u32 { +pub fn run_simulation_step( + state: u32, + events: [u32; MAX_EVENTS as usize], + event_count: u32, + node_states: [u32; MAX_NODES as usize], + link_states: [u32; MAX_NODES as usize], +) -> u32 { let current_time: u32 = get_sim_time(state); let mut processed_count: u32 = 0; let mut i: u32 = 0; @@ -288,12 +311,17 @@ pub fn run_simulation_step(state: u32, events: [u32; MAX_EVENTS as usize], event i = (i + 1); } let new_state: u32 = advance_simulation(state, SIMULATION_TICK_MS); - return create_sim_state(get_sim_time(new_state), (get_sim_event_count(new_state) - processed_count), get_sim_node_count(new_state)); + return create_sim_state( + get_sim_time(new_state), + (get_sim_event_count(new_state) - processed_count), + get_sim_node_count(new_state), + ); } pub fn generate_simulation_report(stats: u32, duration: u32, node_count: u32) -> u32 { let delivery_ratio: u32 = calculate_delivery_ratio(stats); let avg_latency: u32 = calculate_average_latency(stats); - return (((((delivery_ratio & 0xFF) << 24) | ((avg_latency & 0xFF) << 16)) | ((duration & 0xFF) << 8)) | (node_count & 0xFF)); + return (((((delivery_ratio & 0xFF) << 24) | ((avg_latency & 0xFF) << 16)) + | ((duration & 0xFF) << 8)) + | (node_count & 0xFF)); } - diff --git a/gen/rust/performance_profiler.rs b/gen/rust/performance_profiler.rs index 3840f113..1a22c19c 100644 --- a/gen/rust/performance_profiler.rs +++ b/gen/rust/performance_profiler.rs @@ -10,7 +10,8 @@ pub const PROFILING_INTERVAL_MS: u32 = 100; pub const OVERHEAD_THRESHOLD: u32 = 5; pub fn create_perf_sample(func_id: u32, cpu: u32, memory: u32, timestamp: u32) -> u32 { - return (((((func_id & 0xFF) << 24) | ((cpu & 0xFF) << 16)) | ((memory & 0xFF) << 8)) | (timestamp & 0xFF)); + return (((((func_id & 0xFF) << 24) | ((cpu & 0xFF) << 16)) | ((memory & 0xFF) << 8)) + | (timestamp & 0xFF)); } pub fn get_sample_function_id(sample: u32) -> u32 { @@ -46,7 +47,8 @@ pub fn get_profile_total_cpu(profile: u32) -> u32 { } pub fn create_hotspot(func_id: u32, score: u32, rank: u32, impact: u32) -> u32 { - return (((((func_id & 0xFF) << 24) | ((score & 0xFF) << 16)) | ((rank & 0xFF) << 8)) | (impact & 0xFF)); + return (((((func_id & 0xFF) << 24) | ((score & 0xFF) << 16)) | ((rank & 0xFF) << 8)) + | (impact & 0xFF)); } pub fn get_hotspot_function_id(hotspot: u32) -> u32 { @@ -65,7 +67,11 @@ pub fn get_hotspot_impact(hotspot: u32) -> u32 { return (hotspot & 0xFF); } -pub fn calculate_average_cpu(samples: [u32; MAX_SAMPLES as usize], sample_count: u32, func_id: u32) -> u32 { +pub fn calculate_average_cpu( + samples: [u32; MAX_SAMPLES as usize], + sample_count: u32, + func_id: u32, +) -> u32 { let mut total_cpu: u32 = 0; let mut matching_samples: u32 = 0; let mut i: u32 = 0; @@ -83,7 +89,11 @@ pub fn calculate_average_cpu(samples: [u32; MAX_SAMPLES as usize], sample_count: } } -pub fn calculate_average_memory(samples: [u32; MAX_SAMPLES as usize], sample_count: u32, func_id: u32) -> u32 { +pub fn calculate_average_memory( + samples: [u32; MAX_SAMPLES as usize], + sample_count: u32, + func_id: u32, +) -> u32 { let mut total_memory: u32 = 0; let mut matching_samples: u32 = 0; let mut i: u32 = 0; @@ -141,7 +151,8 @@ pub fn is_overhead_acceptable(overhead_percentage: u32) -> u32 { } pub fn create_allocation(alloc_id: u32, size: u32, lifetime: u32, pool: u32) -> u32 { - return (((((alloc_id & 0xFF) << 24) | ((size & 0xFF) << 16)) | ((lifetime & 0xFF) << 8)) | (pool & 0xFF)); + return (((((alloc_id & 0xFF) << 24) | ((size & 0xFF) << 16)) | ((lifetime & 0xFF) << 8)) + | (pool & 0xFF)); } pub fn get_allocation_id(alloc: u32) -> u32 { @@ -160,11 +171,17 @@ pub fn get_allocation_pool(alloc: u32) -> u32 { return (alloc & 0xFF); } -pub fn track_allocation(allocations: [u32; MAX_SAMPLES as usize], alloc_id: u32, size: u32, pool: u32) -> u32 { +pub fn track_allocation( + allocations: [u32; MAX_SAMPLES as usize], + alloc_id: u32, + size: u32, + pool: u32, +) -> u32 { + let mut allocs: [u32; MAX_SAMPLES as usize] = allocations; let mut i: u32 = 0; while (i < MAX_SAMPLES) { - if (get_allocation_id(allocations[(i) as usize]) == 0) { - allocations[(i) as usize] = create_allocation(alloc_id, size, 255, pool); + if (get_allocation_id(allocs[(i) as usize]) == 0) { + allocs[(i) as usize] = create_allocation(alloc_id, size, 255, pool); return 1; } i = (i + 1); @@ -183,7 +200,11 @@ pub fn calculate_total_memory(allocations: [u32; MAX_SAMPLES as usize], sample_c return total_memory; } -pub fn detect_memory_leak(allocations: [u32; MAX_SAMPLES as usize], current_count: u32, previous_count: u32) -> u32 { +pub fn detect_memory_leak( + allocations: [u32; MAX_SAMPLES as usize], + current_count: u32, + previous_count: u32, +) -> u32 { if (current_count > previous_count) { let growth: u32 = (current_count - previous_count); if (growth > 5) { @@ -194,7 +215,8 @@ pub fn detect_memory_leak(allocations: [u32; MAX_SAMPLES as usize], current_coun } pub fn create_call_stack_entry(depth: u32, func_id: u32, parent_id: u32, cpu_contrib: u32) -> u32 { - return (((((depth & 0xFF) << 24) | ((func_id & 0xFF) << 16)) | ((parent_id & 0xFF) << 8)) | (cpu_contrib & 0xFF)); + return (((((depth & 0xFF) << 24) | ((func_id & 0xFF) << 16)) | ((parent_id & 0xFF) << 8)) + | (cpu_contrib & 0xFF)); } pub fn get_stack_depth(entry: u32) -> u32 { @@ -233,8 +255,15 @@ pub fn analyze_call_tree(call_stack: [u32; MAX_SAMPLES as usize], stack_size: u3 return ((((max_depth & 0xFF) << 24) | ((total_cpu & 0xFF) << 16)) | ((avg_cpu & 0xFF) << 8)); } -pub fn create_performance_report(total_cpu: u32, total_mem: u32, hotspots: u32, overhead: u32) -> u32 { - return (((((total_cpu & 0xFF) << 24) | ((total_mem & 0xFF) << 16)) | ((hotspots & 0xFF) << 8)) | (overhead & 0xFF)); +pub fn create_performance_report( + total_cpu: u32, + total_mem: u32, + hotspots: u32, + overhead: u32, +) -> u32 { + return (((((total_cpu & 0xFF) << 24) | ((total_mem & 0xFF) << 16)) + | ((hotspots & 0xFF) << 8)) + | (overhead & 0xFF)); } pub fn get_report_total_cpu(report: u32) -> u32 { @@ -270,7 +299,9 @@ pub fn generate_recommendations(report: u32, hotspot: u32) -> u32 { if (overhead > OVERHEAD_THRESHOLD) { rec_reduce_overhead = 1; } - return (((((rec_optimize_cpu & 0x1) << 3) | ((rec_optimize_memory & 0x1) << 2)) | ((rec_reduce_overhead & 0x1) << 1)) | (rec_parallelize & 0x1)); + return (((((rec_optimize_cpu & 0x1) << 3) | ((rec_optimize_memory & 0x1) << 2)) + | ((rec_reduce_overhead & 0x1) << 1)) + | (rec_parallelize & 0x1)); } pub fn calculate_improvement_opportunity(current_performance: u32, target_performance: u32) -> u32 { @@ -281,4 +312,3 @@ pub fn calculate_improvement_opportunity(current_performance: u32, target_perfor let opportunity: u32 = ((gap * 100) / target_performance); return opportunity; } - diff --git a/gen/rust/topology_visualizer.rs b/gen/rust/topology_visualizer.rs index 1eb3ce5e..5d7172eb 100644 --- a/gen/rust/topology_visualizer.rs +++ b/gen/rust/topology_visualizer.rs @@ -10,7 +10,8 @@ pub const MAX_LAYERS: u32 = 8; pub const CANVAS_SIZE: u32 = 1024; pub fn create_visual_node(node_id: u32, x: u32, y: u32, status: u32) -> u32 { - return (((((node_id & 0xFF) << 24) | ((x & 0xFF) << 16)) | ((y & 0xFF) << 8)) | (status & 0xFF)); + return (((((node_id & 0xFF) << 24) | ((x & 0xFF) << 16)) | ((y & 0xFF) << 8)) + | (status & 0xFF)); } pub fn get_viz_node_id(node: u32) -> u32 { @@ -38,7 +39,8 @@ pub const STATUS_FAILED: u32 = 2; pub const STATUS_WARNING: u32 = 3; pub fn create_visual_edge(source: u32, dest: u32, quality: u32, edge_type: u32) -> u32 { - return (((((source & 0xFF) << 24) | ((dest & 0xFF) << 16)) | ((quality & 0xFF) << 8)) | (edge_type & 0xFF)); + return (((((source & 0xFF) << 24) | ((dest & 0xFF) << 16)) | ((quality & 0xFF) << 8)) + | (edge_type & 0xFF)); } pub fn get_viz_edge_source(edge: u32) -> u32 { @@ -111,8 +113,15 @@ pub fn get_status_color(status: u32) -> u32 { } } -pub fn create_layout_params(algorithm: u32, iterations: u32, temperature: u32, cooling: u32) -> u32 { - return (((((algorithm & 0xFF) << 24) | ((iterations & 0xFF) << 16)) | ((temperature & 0xFF) << 8)) | (cooling & 0xFF)); +pub fn create_layout_params( + algorithm: u32, + iterations: u32, + temperature: u32, + cooling: u32, +) -> u32 { + return (((((algorithm & 0xFF) << 24) | ((iterations & 0xFF) << 16)) + | ((temperature & 0xFF) << 8)) + | (cooling & 0xFF)); } pub fn get_layout_algorithm(params: u32) -> u32 { @@ -139,7 +148,13 @@ pub const ALGORITHM_HIERARCHICAL: u32 = 2; pub const ALGORITHM_GRID: u32 = 3; -pub fn calculate_force_layout(nodes: [u32; MAX_NODES as usize], edges: [u32; MAX_EDGES as usize], node_count: u32, edge_count: u32, params: u32) -> u32 { +pub fn calculate_force_layout( + nodes: [u32; MAX_NODES as usize], + edges: [u32; MAX_EDGES as usize], + node_count: u32, + edge_count: u32, + params: u32, +) -> u32 { let iterations: u32 = get_layout_iterations(params); let mut temperature: u32 = get_layout_temperature(params); let mut placed_nodes: u32 = 0; @@ -178,8 +193,7 @@ pub fn calculate_force_layout(nodes: [u32; MAX_NODES as usize], edges: [u32; MAX while (l < edge_count) { let source: u32 = get_viz_edge_source(edges[(l) as usize]); let dest: u32 = get_viz_edge_dest(edges[(l) as usize]); - if ((source == node_id) || (dest == node_id)) { - } + if ((source == node_id) || (dest == node_id)) {} l = (l + 1); } j = (j + 1); @@ -194,6 +208,7 @@ pub fn calculate_force_layout(nodes: [u32; MAX_NODES as usize], edges: [u32; MAX } pub fn calculate_circular_layout(nodes: [u32; MAX_NODES as usize], node_count: u32) -> u32 { + let mut vnodes: [u32; MAX_NODES as usize] = nodes; let center_x: u32 = (CANVAS_SIZE / 2); let center_y: u32 = (CANVAS_SIZE / 2); let radius: u32 = (CANVAS_SIZE / 3); @@ -202,15 +217,21 @@ pub fn calculate_circular_layout(nodes: [u32; MAX_NODES as usize], node_count: u let angle: u32 = ((i * 360) / node_count); let x: u32 = (center_x + ((radius * angle) / 360)); let y: u32 = (center_y + ((radius * angle) / 360)); - let node_id: u32 = get_viz_node_id(nodes[(i) as usize]); - let status: u32 = get_node_visual_status(nodes[(i) as usize]); - nodes[(i) as usize] = create_visual_node(node_id, x, y, status); + let node_id: u32 = get_viz_node_id(vnodes[(i) as usize]); + let status: u32 = get_node_visual_status(vnodes[(i) as usize]); + vnodes[(i) as usize] = create_visual_node(node_id, x, y, status); i = (i + 1); } return node_count; } -pub fn calculate_hierarchical_layout(nodes: [u32; MAX_NODES as usize], edges: [u32; MAX_EDGES as usize], node_count: u32, edge_count: u32) -> u32 { +pub fn calculate_hierarchical_layout( + nodes: [u32; MAX_NODES as usize], + edges: [u32; MAX_EDGES as usize], + node_count: u32, + edge_count: u32, +) -> u32 { + let mut vnodes: [u32; MAX_NODES as usize] = nodes; let level_count: u32 = 4; let nodes_per_level: u32 = (node_count / level_count); let mut i: u32 = 0; @@ -219,9 +240,9 @@ pub fn calculate_hierarchical_layout(nodes: [u32; MAX_NODES as usize], edges: [u while (i < node_count) { let y: u32 = ((current_level * CANVAS_SIZE) / level_count); let x: u32 = ((nodes_in_level * CANVAS_SIZE) / nodes_per_level); - let node_id: u32 = get_viz_node_id(nodes[(i) as usize]); - let status: u32 = get_node_visual_status(nodes[(i) as usize]); - nodes[(i) as usize] = create_visual_node(node_id, x, y, status); + let node_id: u32 = get_viz_node_id(vnodes[(i) as usize]); + let status: u32 = get_node_visual_status(vnodes[(i) as usize]); + vnodes[(i) as usize] = 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; @@ -232,7 +253,13 @@ pub fn calculate_hierarchical_layout(nodes: [u32; MAX_NODES as usize], edges: [u return node_count; } -pub fn apply_layout(nodes: [u32; MAX_NODES as usize], edges: [u32; MAX_EDGES as usize], node_count: u32, edge_count: u32, params: u32) -> u32 { +pub fn apply_layout( + nodes: [u32; MAX_NODES as usize], + edges: [u32; MAX_EDGES as usize], + node_count: u32, + edge_count: u32, + params: u32, +) -> u32 { let algorithm: u32 = get_layout_algorithm(params); if (algorithm == ALGORITHM_FORCE_DIRECTED) { return calculate_force_layout(nodes, edges, node_count, edge_count, params); @@ -254,7 +281,8 @@ pub fn render_node(node: u32, size: u32, color: u32) -> u32 { let y: u32 = get_node_y_position(node); let status: u32 = get_node_visual_status(node); let node_color: u32 = get_status_color(status); - return (((((x & 0xFF) << 24) | ((y & 0xFF) << 16)) | ((size & 0xFF) << 8)) | (node_color & 0xFF)); + return (((((x & 0xFF) << 24) | ((y & 0xFF) << 16)) | ((size & 0xFF) << 8)) + | (node_color & 0xFF)); } pub fn render_edge(edge: u32, nodes: [u32; MAX_NODES as usize], thickness: u32) -> u32 { @@ -288,10 +316,16 @@ pub fn render_edge(edge: u32, nodes: [u32; MAX_NODES as usize], thickness: u32) edge_color = COLOR_RED; } } - return (((((source_x & 0xFF) << 24) | ((source_y & 0xFF) << 16)) | ((dest_x & 0xFF) << 8)) | (dest_y & 0xFF)); + return (((((source_x & 0xFF) << 24) | ((source_y & 0xFF) << 16)) | ((dest_x & 0xFF) << 8)) + | (dest_y & 0xFF)); } -pub fn create_visualization_frame(nodes: [u32; MAX_NODES as usize], edges: [u32; MAX_EDGES as usize], node_count: u32, edge_count: u32) -> u32 { +pub fn create_visualization_frame( + nodes: [u32; MAX_NODES as usize], + edges: [u32; MAX_EDGES as usize], + node_count: u32, + edge_count: u32, +) -> u32 { let mut frame_size: u32 = 0; let mut i: u32 = 0; while (i < node_count) { @@ -325,12 +359,19 @@ pub fn optimize_rendering(node_count: u32, edge_count: u32, target_fps: u32) -> } } -pub fn generate_topology_visualization(nodes: [u32; MAX_NODES as usize], edges: [u32; MAX_EDGES as usize], node_count: u32, edge_count: u32, layout_params: u32) -> u32 { +pub fn generate_topology_visualization( + nodes: [u32; MAX_NODES as usize], + edges: [u32; MAX_EDGES as usize], + node_count: u32, + edge_count: u32, + layout_params: u32, +) -> u32 { let layout_result: u32 = apply_layout(nodes, edges, node_count, edge_count, layout_params); let frame: u32 = create_visualization_frame(nodes, edges, node_count, edge_count); let fps: u32 = 30; let detail_level: u32 = optimize_rendering(node_count, edge_count, fps); let complexity: u32 = calculate_viz_complexity(node_count, edge_count); - return (((((layout_result & 0xFF) << 24) | ((frame & 0xFF) << 16)) | ((detail_level & 0xFF) << 8)) | (complexity & 0xFF)); + return (((((layout_result & 0xFF) << 24) | ((frame & 0xFF) << 16)) + | ((detail_level & 0xFF) << 8)) + | (complexity & 0xFF)); } - diff --git a/gen/rust/traffic_animator.rs b/gen/rust/traffic_animator.rs index 658a3ef2..123ee1e4 100644 --- a/gen/rust/traffic_animator.rs +++ b/gen/rust/traffic_animator.rs @@ -10,7 +10,8 @@ pub const ANIMATION_FPS: u32 = 30; pub const MAX_FRAMES: u32 = 1200; pub fn create_anim_packet(packet_id: u32, source: u32, dest: u32, progress: u32) -> u32 { - return (((((packet_id & 0xFF) << 24) | ((source & 0xFF) << 16)) | ((dest & 0xFF) << 8)) | (progress & 0xFF)); + return (((((packet_id & 0xFF) << 24) | ((source & 0xFF) << 16)) | ((dest & 0xFF) << 8)) + | (progress & 0xFF)); } pub fn get_anim_packet_id(packet: u32) -> u32 { @@ -41,8 +42,15 @@ pub fn update_packet_progress(packet: u32, delta: u32) -> u32 { return create_anim_packet(packet_id, source, dest, new_progress); } -pub fn create_animation_path(path_id: u32, node_count: u32, current_pos: u32, path_type: u32) -> u32 { - return (((((path_id & 0xFF) << 24) | ((node_count & 0xFF) << 16)) | ((current_pos & 0xFF) << 8)) | (path_type & 0xFF)); +pub fn create_animation_path( + path_id: u32, + node_count: u32, + current_pos: u32, + path_type: u32, +) -> u32 { + return (((((path_id & 0xFF) << 24) | ((node_count & 0xFF) << 16)) + | ((current_pos & 0xFF) << 8)) + | (path_type & 0xFF)); } pub fn get_anim_path_id(path: u32) -> u32 { @@ -69,8 +77,15 @@ pub const PATH_BROADCAST: u32 = 2; pub const PATH_GATHER: u32 = 3; -pub fn create_animation_frame(frame_id: u32, timestamp: u32, packet_count: u32, duration: u32) -> u32 { - return (((((frame_id & 0xFF) << 24) | ((timestamp & 0xFF) << 16)) | ((packet_count & 0xFF) << 8)) | (duration & 0xFF)); +pub fn create_animation_frame( + frame_id: u32, + timestamp: u32, + packet_count: u32, + duration: u32, +) -> u32 { + return (((((frame_id & 0xFF) << 24) | ((timestamp & 0xFF) << 16)) + | ((packet_count & 0xFF) << 8)) + | (duration & 0xFF)); } pub fn get_anim_frame_id(frame: u32) -> u32 { @@ -90,7 +105,8 @@ pub fn get_anim_frame_duration(frame: u32) -> u32 { } pub fn create_traffic_stats(total_packets: u32, bytes: u32, dropped: u32, latency: u32) -> u32 { - return (((((total_packets & 0xFF) << 24) | ((bytes & 0xFF) << 16)) | ((dropped & 0xFF) << 8)) | (latency & 0xFF)); + return (((((total_packets & 0xFF) << 24) | ((bytes & 0xFF) << 16)) | ((dropped & 0xFF) << 8)) + | (latency & 0xFF)); } pub fn get_traffic_total_packets(stats: u32) -> u32 { @@ -110,7 +126,8 @@ pub fn get_traffic_avg_latency(stats: u32) -> u32 { } pub fn create_packet_color(ptype: u32, priority: u32, size: u32, color: u32) -> u32 { - return (((((ptype & 0xF) << 28) | ((priority & 0xF) << 24)) | ((size & 0xFF) << 16)) | (color & 0xFFFF)); + return (((((ptype & 0xF) << 28) | ((priority & 0xF) << 24)) | ((size & 0xFF) << 16)) + | (color & 0xFFFF)); } pub fn get_packet_color_type(color: u32) -> u32 { @@ -158,7 +175,8 @@ pub fn get_packet_visual_color(packet_type: u32, priority: u32) -> u32 { } pub fn create_animation_timeline(current: u32, total: u32, loops: u32, speed: u32) -> u32 { - return (((((current & 0xFF) << 24) | ((total & 0xFF) << 16)) | ((loops & 0xFF) << 8)) | (speed & 0xFF)); + return (((((current & 0xFF) << 24) | ((total & 0xFF) << 16)) | ((loops & 0xFF) << 8)) + | (speed & 0xFF)); } pub fn get_timeline_current_frame(timeline: u32) -> u32 { @@ -191,8 +209,15 @@ pub fn advance_animation_frame(timeline: u32) -> u32 { return create_animation_timeline(new_current, total, new_loops, speed); } -pub fn create_traffic_pattern(pattern_id: u32, burst_size: u32, interval: u32, duration: u32) -> u32 { - return (((((pattern_id & 0xFF) << 24) | ((burst_size & 0xFF) << 16)) | ((interval & 0xFF) << 8)) | (duration & 0xFF)); +pub fn create_traffic_pattern( + pattern_id: u32, + burst_size: u32, + interval: u32, + duration: u32, +) -> u32 { + return (((((pattern_id & 0xFF) << 24) | ((burst_size & 0xFF) << 16)) + | ((interval & 0xFF) << 8)) + | (duration & 0xFF)); } pub fn get_pattern_id(pattern: u32) -> u32 { @@ -223,7 +248,13 @@ pub fn generate_traffic_burst(pattern: u32, source: u32, dest: u32) -> u32 { return packet_count; } -pub fn calculate_packet_position(source_x: u32, source_y: u32, dest_x: u32, dest_y: u32, progress: u32) -> u32 { +pub fn calculate_packet_position( + source_x: u32, + source_y: u32, + dest_x: u32, + dest_y: u32, + progress: u32, +) -> u32 { let mut current_x: u32 = source_x; if (dest_x >= source_x) { current_x = (source_x + (((dest_x - source_x) * progress) / 100)); @@ -239,31 +270,43 @@ pub fn calculate_packet_position(source_x: u32, source_y: u32, dest_x: u32, dest return (((current_x & 0xFF) << 24) | ((current_y & 0xFF) << 16)); } -pub fn update_animation_packets(packets: [u32; MAX_PACKETS as usize], packet_count: u32, speed: u32) -> u32 { +pub fn update_animation_packets( + packets: [u32; MAX_PACKETS as usize], + packet_count: u32, + speed: u32, +) -> u32 { + let mut pkts: [u32; MAX_PACKETS as usize] = packets; let mut updated_count: u32 = 0; let mut completed_count: u32 = 0; let mut i: u32 = 0; while (i < packet_count) { - let progress: u32 = get_anim_packet_progress(packets[(i) as usize]); + let progress: u32 = get_anim_packet_progress(pkts[(i) as usize]); if (progress < 100) { let mut new_progress: u32 = (progress + speed); if (new_progress > 100) { new_progress = 100; } - let packet_id: u32 = get_anim_packet_id(packets[(i) as usize]); - let source: u32 = get_anim_packet_source(packets[(i) as usize]); - let dest: u32 = get_anim_packet_dest(packets[(i) as usize]); - packets[(i) as usize] = create_anim_packet(packet_id, source, dest, new_progress); + let packet_id: u32 = get_anim_packet_id(pkts[(i) as usize]); + let source: u32 = get_anim_packet_source(pkts[(i) as usize]); + let dest: u32 = get_anim_packet_dest(pkts[(i) as usize]); + pkts[(i) as usize] = create_anim_packet(packet_id, source, dest, new_progress); updated_count = (updated_count + 1); } else { completed_count = (completed_count + 1); } i = (i + 1); } - return ((((updated_count & 0xFF) << 24) | ((completed_count & 0xFF) << 16)) | ((packet_count & 0xFF) << 8)); + return ((((updated_count & 0xFF) << 24) | ((completed_count & 0xFF) << 16)) + | ((packet_count & 0xFF) << 8)); } -pub fn render_animation_frame(packets: [u32; MAX_PACKETS as usize], packet_count: u32, paths: [u32; MAX_PATHS as usize], path_count: u32, frame_id: u32) -> u32 { +pub fn render_animation_frame( + packets: [u32; MAX_PACKETS as usize], + packet_count: u32, + paths: [u32; MAX_PATHS as usize], + path_count: u32, + frame_id: u32, +) -> u32 { let timestamp: u32 = (frame_id * (1000 / ANIMATION_FPS)); let duration: u32 = (1000 / ANIMATION_FPS); return create_animation_frame(frame_id, timestamp, packet_count, duration); @@ -285,7 +328,11 @@ pub fn optimize_animation_performance(packet_count: u32, target_fps: u32) -> u32 } } -pub fn generate_traffic_heat_map(packets: [u32; MAX_PACKETS as usize], packet_count: u32, node_count: u32) -> u32 { +pub fn generate_traffic_heat_map( + packets: [u32; MAX_PACKETS as usize], + packet_count: u32, + node_count: u32, +) -> u32 { let mut traffic_counts: [u32; 32] = [0; 32]; let mut max_traffic: u32 = 0; let mut i: u32 = 0; @@ -320,10 +367,18 @@ pub fn generate_traffic_heat_map(packets: [u32; MAX_PACKETS as usize], packet_co if (total_active > 0) { avg_traffic = (total_traffic / total_active); } - return ((((max_traffic & 0xFF) << 24) | ((total_active & 0xFF) << 16)) | ((avg_traffic & 0xFF) << 8)); -} - -pub fn generate_traffic_animation(packets: [u32; MAX_PACKETS as usize], packet_count: u32, paths: [u32; MAX_PATHS as usize], path_count: u32, node_count: u32, duration_frames: u32) -> u32 { + return ((((max_traffic & 0xFF) << 24) | ((total_active & 0xFF) << 16)) + | ((avg_traffic & 0xFF) << 8)); +} + +pub fn generate_traffic_animation( + packets: [u32; MAX_PACKETS as usize], + packet_count: u32, + paths: [u32; MAX_PATHS as usize], + path_count: u32, + node_count: u32, + duration_frames: u32, +) -> u32 { let total_frames: u32 = duration_frames; let current_frame: u32 = 0; let complexity: u32 = calculate_animation_complexity(packet_count, path_count, node_count); @@ -332,11 +387,20 @@ pub fn generate_traffic_animation(packets: [u32; MAX_PACKETS as usize], packet_c let timeline: u32 = create_animation_timeline(0, total_frames, 0, 1); let heat_map: u32 = generate_traffic_heat_map(packets, actual_packet_count, node_count); let max_traffic: u32 = ((heat_map >> 24) & 0xFF); - return (((((total_frames & 0xFF) << 24) | ((complexity & 0xFF) << 16)) | ((actual_packet_count & 0xFF) << 8)) | (max_traffic & 0xFF)); + return (((((total_frames & 0xFF) << 24) | ((complexity & 0xFF) << 16)) + | ((actual_packet_count & 0xFF) << 8)) + | (max_traffic & 0xFF)); } -pub fn create_animation_controls(play_pause: u32, step_forward: u32, step_backward: u32, reset: u32) -> u32 { - return (((((play_pause & 0x1) << 3) | ((step_forward & 0x1) << 2)) | ((step_backward & 0x1) << 1)) | (reset & 0x1)); +pub fn create_animation_controls( + play_pause: u32, + step_forward: u32, + step_backward: u32, + reset: u32, +) -> u32 { + return (((((play_pause & 0x1) << 3) | ((step_forward & 0x1) << 2)) + | ((step_backward & 0x1) << 1)) + | (reset & 0x1)); } pub fn process_animation_control(control: u32, timeline: u32) -> u32 { @@ -371,4 +435,3 @@ pub fn calculate_animation_stats(frames: [u32; MAX_FRAMES as usize], frame_count } return create_traffic_stats(total_packets, total_bytes, 0, avg_latency); } - diff --git a/gen/zig/api_documenter.zig b/gen/zig/api_documenter.zig index b7b55a44..c672fa5d 100644 --- a/gen/zig/api_documenter.zig +++ b/gen/zig/api_documenter.zig @@ -249,7 +249,7 @@ fn validate_documentation(func_docs: [MAX_FUNCTIONS]u32, func_count: u32) u32 { return ((((missing_descriptions & 0xFF) << 24) | 0) | ((missing_params & 0xFF) << 8)) | (quality_score & 0xFF); } fn generate_documentation_report(func_docs: [MAX_FUNCTIONS]u32, func_count: u32, xrefs: [MAX_FUNCTIONS]u32, xref_count: u32) u32 { - const empty_params: [MAX_PARAMETERS]u32 = .{ 0 } ** MAX_PARAMETERS; + const empty_params: [MAX_PARAMETERS]u32 = .{ 0 } ** 16; const doc_summary: u32 = generate_api_documentation(func_docs, func_count, empty_params, 0); const documented_funcs: u32 = (doc_summary >> 24) & 0xFF; const coverage: u32 = calculate_documentation_coverage(documented_funcs, func_count); diff --git a/gen/zig/auto_config.zig b/gen/zig/auto_config.zig index 56bd1298..169e40b0 100644 --- a/gen/zig/auto_config.zig +++ b/gen/zig/auto_config.zig @@ -79,16 +79,17 @@ fn get_config_value(config: [MAX_PARAMS]u32, param_id: u32) u32 { } return 0; } -fn set_config_value(config_arg: [MAX_PARAMS]u32, param_id: u32, new_value: u32) u32 { - var config = config_arg; +fn set_config_value(config: [MAX_PARAMS]u32, param_id: u32, new_value: u32) u32 { + var cfg: [MAX_PARAMS]u32 = config; + _ = &cfg; var i: u32 = 0; _ = &i; while (i < MAX_PARAMS) { - const current_param_id: u32 = get_param_id(config[i]); + const current_param_id: u32 = get_param_id(cfg[i]); if (current_param_id == param_id) { - const scope: u32 = get_param_scope(config[i]); + const scope: u32 = get_param_scope(cfg[i]); const status: u32 = STATUS_PENDING; - config[i] = create_config_param(param_id, new_value, scope, status); + cfg[i] = create_config_param(param_id, new_value, scope, status); return 1; } i = i + 1; @@ -123,17 +124,18 @@ fn discover_network_params(node_count: u32, interference_level: u32) u32 { set_config_value(config, PARAM_HELLO_INTERVAL, hello_interval); return 1; } -fn apply_config(config_arg: [MAX_PARAMS]u32, param_id: u32) u32 { - var config = config_arg; +fn apply_config(config: [MAX_PARAMS]u32, param_id: u32) u32 { + var cfg: [MAX_PARAMS]u32 = config; + _ = &cfg; var i: u32 = 0; _ = &i; while (i < MAX_PARAMS) { - const current_param_id: u32 = get_param_id(config[i]); + const current_param_id: u32 = get_param_id(cfg[i]); if (current_param_id == param_id) { - const value: u32 = get_param_value(config[i]); - const scope: u32 = get_param_scope(config[i]); + const value: u32 = get_param_value(cfg[i]); + const scope: u32 = get_param_scope(cfg[i]); const success: u32 = 1; - config[i] = create_config_param(param_id, value, scope, STATUS_APPLIED); + cfg[i] = create_config_param(param_id, value, scope, STATUS_APPLIED); return success; } i = i + 1; @@ -160,19 +162,19 @@ fn apply_all_pending(config: [MAX_PARAMS]u32) u32 { fn validate_config(config: [MAX_PARAMS]u32, param_id: u32) u32 { const value: u32 = get_config_value(config, param_id); if (param_id == PARAM_TX_POWER) { - if ((value >= 0) and (value <= 100)) { + if (value <= 100) { return 1; } } else if (param_id == PARAM_CHANNEL) { - if ((value >= 0) and (value <= 11)) { + if (value <= 11) { return 1; } } else if (param_id == PARAM_DATA_RATE) { - if ((value >= 0) and (value <= 3)) { + if (value <= 3) { return 1; } } else if (param_id == PARAM_RETRY_LIMIT) { - if ((value >= 0) and (value <= 7)) { + if (value <= 7) { return 1; } } else if (param_id == PARAM_HELLO_INTERVAL) { @@ -188,7 +190,7 @@ fn validate_config(config: [MAX_PARAMS]u32, param_id: u32) u32 { return 1; } } else if (param_id == PARAM_SECURITY_LEVEL) { - if ((value >= 0) and (value <= 3)) { + if (value <= 3) { return 1; } } @@ -251,8 +253,9 @@ break; } return synced_count; } -fn rollback_config(config_arg: [MAX_PARAMS]u32, backup_config: [MAX_PARAMS]u32) u32 { - var config = config_arg; +fn rollback_config(config: [MAX_PARAMS]u32, backup_config: [MAX_PARAMS]u32) u32 { + var cfg: [MAX_PARAMS]u32 = config; + _ = &cfg; var rolled_back: u32 = 0; _ = &rolled_back; var i: u32 = 0; @@ -264,9 +267,9 @@ fn rollback_config(config_arg: [MAX_PARAMS]u32, backup_config: [MAX_PARAMS]u32) var j: u32 = 0; _ = &j; while (j < MAX_PARAMS) { - const local_param_id: u32 = get_param_id(config[j]); + const local_param_id: u32 = get_param_id(cfg[j]); if (local_param_id == backup_param_id) { - config[j] = create_config_param(backup_param_id, backup_value, backup_scope, STATUS_PENDING); + cfg[j] = create_config_param(backup_param_id, backup_value, backup_scope, STATUS_PENDING); rolled_back = rolled_back + 1; break; } @@ -349,7 +352,8 @@ test "default_table_values_survive" { if (!(get_param_value(default_config_at(0)) == 50)) @panic("tx power"); } test "config_lookup_finds_param" { - const cfg: [16]u32 = .{ default_config_at(0), default_config_at(1), default_config_at(2), default_config_at(3), default_config_at(4), default_config_at(5), default_config_at(6), default_config_at(7), 0, 0, 0, 0, 0, 0, 0, 0 }; + var cfg: [16]u32 = .{ default_config_at(0), default_config_at(1), default_config_at(2), default_config_at(3), default_config_at(4), default_config_at(5), default_config_at(6), default_config_at(7), 0, 0, 0, 0, 0, 0, 0, 0 }; + _ = &cfg; if (!(get_config_value(cfg, PARAM_RETRY_LIMIT) == 3)) @panic("retry limit found"); if (!(get_config_value(cfg, 99) == 0)) @panic("unknown param yields 0"); } diff --git a/gen/zig/bandwidth_allocator.zig b/gen/zig/bandwidth_allocator.zig index a8d47d82..5740a136 100644 --- a/gen/zig/bandwidth_allocator.zig +++ b/gen/zig/bandwidth_allocator.zig @@ -90,18 +90,19 @@ fn needs_more_bandwidth(flow_req: u32) bool { const min_bw = get_min_bandwidth(flow_req); return current < min_bw; } -fn update_flow_bandwidth(flow_req: u32, new_bw_arg: u32) u32 { - var new_bw = new_bw_arg; +fn update_flow_bandwidth(flow_req: u32, new_bw: u32) u32 { const flow_id = get_flow_id(flow_req); const priority = get_flow_priority(flow_req); const min_bw = get_min_bandwidth(flow_req); - if (new_bw < min_bw) { - new_bw = min_bw; + var bw: u32 = new_bw; + _ = &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); } fn count_active_flows(flow_array: [8]u32) u32 { var count: u32 = 0; diff --git a/gen/zig/cache_management.zig b/gen/zig/cache_management.zig index 5089b19a..c9b47ad9 100644 --- a/gen/zig/cache_management.zig +++ b/gen/zig/cache_management.zig @@ -69,37 +69,39 @@ fn get_entry(cache: [MAX_ENTRIES]u32, data_id: u32) u32 { return 0; } } -fn add_entry(cache_arg: [MAX_ENTRIES]u32, current_size_arg: u32, data_id: u32, size: u32) u32 { - var cache = cache_arg; - var current_size = current_size_arg; - const existing_index: u32 = find_entry(cache, data_id); +fn add_entry(cache: [MAX_ENTRIES]u32, current_size: u32, data_id: u32, size: u32) u32 { + var slots: [MAX_ENTRIES]u32 = cache; + _ = &slots; + var used: u32 = current_size; + _ = &used; + const existing_index: u32 = find_entry(slots, data_id); if (existing_index < MAX_ENTRIES) { - return current_size; + return used; } var empty_index: u32 = MAX_ENTRIES; _ = &empty_index; var i: u32 = 0; _ = &i; while (i < MAX_ENTRIES) { - if (get_data_id(cache[i]) == 0) { + if (get_data_id(slots[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; } - const evicted_size: u32 = get_entry_size(cache[empty_index]); - current_size = current_size - evicted_size; + const evicted_size: u32 = get_entry_size(slots[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[empty_index] = create_cache_entry(data_id, 1, 0, size); - return current_size + size; + slots[empty_index] = create_cache_entry(data_id, 1, 0, size); + return used + size; } fn find_eviction_candidate(cache: [MAX_ENTRIES]u32) u32 { var worst_score: u32 = 0xFFFFFFFF; @@ -124,37 +126,40 @@ fn find_eviction_candidate(cache: [MAX_ENTRIES]u32) u32 { } return candidate; } -fn remove_entry(cache_arg: [MAX_ENTRIES]u32, current_size: u32, data_id: u32) u32 { - var cache = cache_arg; - const entry_index: u32 = find_entry(cache, data_id); +fn remove_entry(cache: [MAX_ENTRIES]u32, current_size: u32, data_id: u32) u32 { + var slots: [MAX_ENTRIES]u32 = cache; + _ = &slots; + const entry_index: u32 = find_entry(slots, data_id); if (entry_index < MAX_ENTRIES) { - const entry_size: u32 = get_entry_size(cache[entry_index]); - cache[entry_index] = 0; + const entry_size: u32 = get_entry_size(slots[entry_index]); + slots[entry_index] = 0; return current_size - entry_size; } else { return current_size; } } -fn access_cache(cache_arg: [MAX_ENTRIES]u32, data_id: u32) u32 { - var cache = cache_arg; - const entry_index: u32 = find_entry(cache, data_id); +fn access_cache(cache: [MAX_ENTRIES]u32, data_id: u32) u32 { + var slots: [MAX_ENTRIES]u32 = cache; + _ = &slots; + const entry_index: u32 = find_entry(slots, data_id); if (entry_index < MAX_ENTRIES) { - cache[entry_index] = update_access_count(cache[entry_index]); - cache[entry_index] = update_age(cache[entry_index], 0); + slots[entry_index] = update_access_count(slots[entry_index]); + slots[entry_index] = update_age(slots[entry_index], 0); return 1; } else { return 0; } } -fn age_cache(cache_arg: [MAX_ENTRIES]u32) void { - var cache = cache_arg; +fn age_cache(cache: [MAX_ENTRIES]u32) void { + var slots: [MAX_ENTRIES]u32 = cache; + _ = &slots; var i: u32 = 0; _ = &i; while (i < MAX_ENTRIES) { - const entry: u32 = cache[i]; + const entry: u32 = slots[i]; const age: u32 = get_age(entry); if (age < 255) { - cache[i] = update_age(entry, age + 1); + slots[i] = update_age(entry, age + 1); } i = i + 1; } diff --git a/gen/zig/compression_engine.zig b/gen/zig/compression_engine.zig index 4a3128e0..2090e6a5 100644 --- a/gen/zig/compression_engine.zig +++ b/gen/zig/compression_engine.zig @@ -233,10 +233,11 @@ fn calculate_total_savings(blocks: [MAX_BLOCKS]u32, count: u32) u32 { return 0; } } -fn update_dictionary(dictionary_arg: [DICTIONARY_SIZE]u32, new_entry: u32, index: u32) u32 { - var dictionary = dictionary_arg; +fn update_dictionary(dictionary: [DICTIONARY_SIZE]u32, new_entry: u32, index: u32) u32 { + var dict: [DICTIONARY_SIZE]u32 = dictionary; + _ = &dict; if (index < DICTIONARY_SIZE) { - dictionary[index] = new_entry; + dict[index] = new_entry; return 1; } else { return 0; diff --git a/gen/zig/integration_framework.zig b/gen/zig/integration_framework.zig index 8c0e2663..c582fd92 100644 --- a/gen/zig/integration_framework.zig +++ b/gen/zig/integration_framework.zig @@ -26,7 +26,7 @@ fn get_registered_module_status(registration: u32) u32 { } const TYPE_NETWORK: u32 = 0; const TYPE_TESTING: u32 = 1; -const type_documentation: u32 = 2; +const TYPE_DOCUMENTATION: u32 = 2; const TYPE_VISUALIZATION: u32 = 3; const TYPE_SIMULATION: u32 = 4; const TYPE_PROFILING: u32 = 5; @@ -107,14 +107,15 @@ const EVENT_MODULE_UNLOADED: u32 = 1; const EVENT_TEST_COMPLETED: u32 = 2; const EVENT_SIMULATION_STEP: u32 = 3; const EVENT_VISUALIZATION_UPDATE: u32 = 4; -fn subscribe_to_event(module_id: u32, event_type: u32, subscriptions_arg: [MAX_EVENTS]u32) u32 { - var subscriptions = subscriptions_arg; +fn subscribe_to_event(module_id: u32, event_type: u32, subscriptions: [MAX_EVENTS]u32) u32 { + var subs: [MAX_EVENTS]u32 = subscriptions; + _ = &subs; const subscription_id: u32 = (module_id * 10) + event_type; var i: u32 = 0; _ = &i; while (i < MAX_EVENTS) { - if (subscriptions[i] == 0) { - subscriptions[i] = create_event(subscription_id, event_type, module_id, 0); + if (subs[i] == 0) { + subs[i] = create_event(subscription_id, event_type, module_id, 0); return 1; } i = i + 1; @@ -220,27 +221,29 @@ fn propagate_error(err_word: u32, modules: [MAX_MODULES]u32, module_count: u32) } return notified_count; } -fn load_module(module_id: u32, module_type: u32, priority: u32, modules_arg: [MAX_MODULES]u32) u32 { - var modules = modules_arg; +fn load_module(module_id: u32, module_type: u32, priority: u32, modules: [MAX_MODULES]u32) u32 { + var mods: [MAX_MODULES]u32 = modules; + _ = &mods; var i: u32 = 0; _ = &i; while (i < MAX_MODULES) { - if (get_registered_module_id(modules[i]) == 0) { - modules[i] = create_module_registration(module_id, module_type, priority, STATUS_IDLE); + if (get_registered_module_id(mods[i]) == 0) { + mods[i] = create_module_registration(module_id, module_type, priority, STATUS_IDLE); return 1; } i = i + 1; } return 0; } -fn unload_module(module_id: u32, modules_arg: [MAX_MODULES]u32) u32 { - var modules = modules_arg; +fn unload_module(module_id: u32, modules: [MAX_MODULES]u32) u32 { + var mods: [MAX_MODULES]u32 = modules; + _ = &mods; var i: u32 = 0; _ = &i; while (i < MAX_MODULES) { - const registered_id: u32 = get_registered_module_id(modules[i]); + const registered_id: u32 = get_registered_module_id(mods[i]); if (registered_id == module_id) { - modules[i] = 0; + mods[i] = 0; return 1; } i = i + 1; @@ -412,7 +415,8 @@ test "module_registration_roundtrip" { if (!(get_registered_module_status(m) == 50000)) @panic("status"); } test "send_message_requires_active_destination" { - const mods: [16]u32 = .{ create_module_registration(1,0,1,STATUS_ACTIVE), create_module_registration(2,0,1,0), 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }; + var mods: [16]u32 = .{ create_module_registration(1,0,1,STATUS_ACTIVE), create_module_registration(2,0,1,0), 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }; + _ = &mods; const msg_ok = create_integration_message(1, 5, 1, 0); if (!(send_message(mods, msg_ok) == 1)) @panic("active destination accepts"); const msg_down = create_integration_message(2, 5, 2, 0); diff --git a/gen/zig/network_simulator.zig b/gen/zig/network_simulator.zig index a28a0a05..c29875bb 100644 --- a/gen/zig/network_simulator.zig +++ b/gen/zig/network_simulator.zig @@ -146,9 +146,10 @@ fn advance_simulation(state: u32, time_delta: u32) u32 { const new_time: u32 = current_time + time_delta; return create_sim_state(new_time, event_count, node_count); } -fn process_event(event: u32, node_states_arg: [MAX_NODES]u32, link_states: [MAX_NODES]u32) u32 { - var node_states = node_states_arg; +fn process_event(event: u32, node_states: [MAX_NODES]u32, link_states: [MAX_NODES]u32) u32 { _ = link_states; // unused by the spec body + var states: [MAX_NODES]u32 = node_states; + _ = &states; const event_type: u32 = get_event_type(event); const node_id: u32 = get_event_node_id(event); if (event_type == EVENT_PACKET_SEND) { @@ -156,8 +157,8 @@ fn process_event(event: u32, node_states_arg: [MAX_NODES]u32, link_states: [MAX_ } else if (event_type == EVENT_PACKET_RECV) { return 1; } else if (event_type == EVENT_NODE_FAILURE) { - const current_state: u32 = node_states[node_id]; - node_states[node_id] = update_node_status(current_state, NODE_FAILED); + const current_state: u32 = states[node_id]; + states[node_id] = update_node_status(current_state, NODE_FAILED); return 1; } else if (event_type == EVENT_LINK_FAILURE) { return 1; @@ -208,11 +209,12 @@ fn create_topology(node_count: u32, density: u32) u32 { } return link_count; } -fn inject_fault(fault_type: u32, target_id: u32, node_states_arg: [MAX_NODES]u32) u32 { - var node_states = node_states_arg; +fn inject_fault(fault_type: u32, target_id: u32, node_states: [MAX_NODES]u32) u32 { + var states: [MAX_NODES]u32 = node_states; + _ = &states; if (fault_type == EVENT_NODE_FAILURE) { - const current_state: u32 = node_states[target_id]; - node_states[target_id] = update_node_status(current_state, NODE_FAILED); + const current_state: u32 = states[target_id]; + states[target_id] = update_node_status(current_state, NODE_FAILED); return 1; } else if (fault_type == EVENT_LINK_FAILURE) { return 1; diff --git a/gen/zig/performance_profiler.zig b/gen/zig/performance_profiler.zig index ea291ca6..56f1c652 100644 --- a/gen/zig/performance_profiler.zig +++ b/gen/zig/performance_profiler.zig @@ -148,13 +148,14 @@ fn get_allocation_lifetime(alloc: u32) u32 { fn get_allocation_pool(alloc: u32) u32 { return alloc & 0xFF; } -fn track_allocation(allocations_arg: [MAX_SAMPLES]u32, alloc_id: u32, size: u32, pool: u32) u32 { - var allocations = allocations_arg; +fn track_allocation(allocations: [MAX_SAMPLES]u32, alloc_id: u32, size: u32, pool: u32) u32 { + var allocs: [MAX_SAMPLES]u32 = allocations; + _ = &allocs; var i: u32 = 0; _ = &i; while (i < MAX_SAMPLES) { - if (get_allocation_id(allocations[i]) == 0) { - allocations[i] = create_allocation(alloc_id, size, 255, pool); + if (get_allocation_id(allocs[i]) == 0) { + allocs[i] = create_allocation(alloc_id, size, 255, pool); return 1; } i = i + 1; diff --git a/gen/zig/topology_visualizer.zig b/gen/zig/topology_visualizer.zig index 7c4a8ef6..692bcc4b 100644 --- a/gen/zig/topology_visualizer.zig +++ b/gen/zig/topology_visualizer.zig @@ -159,9 +159,10 @@ fn calculate_force_layout(nodes: [MAX_NODES]u32, edges: [MAX_EDGES]u32, node_cou } return placed_nodes; } -fn calculate_circular_layout(nodes_arg: [MAX_NODES]u32, node_count: u32) u32 { - var nodes = nodes_arg; +fn calculate_circular_layout(nodes: [MAX_NODES]u32, node_count: u32) u32 { const _cse1 = CANVAS_SIZE / 2; + var vnodes: [MAX_NODES]u32 = nodes; + _ = &vnodes; const center_x: u32 = CANVAS_SIZE / 2; const center_y: u32 = _cse1; const radius: u32 = CANVAS_SIZE / 3; @@ -171,17 +172,18 @@ fn calculate_circular_layout(nodes_arg: [MAX_NODES]u32, node_count: u32) u32 { const angle: u32 = (i * 360) / node_count; const x: u32 = center_x + ((radius * angle) / 360); const y: u32 = center_y + ((radius * angle) / 360); - const node_id: u32 = get_viz_node_id(nodes[i]); - const status: u32 = get_node_visual_status(nodes[i]); - nodes[i] = create_visual_node(node_id, x, y, status); + const node_id: u32 = get_viz_node_id(vnodes[i]); + const status: u32 = get_node_visual_status(vnodes[i]); + vnodes[i] = create_visual_node(node_id, x, y, status); i = i + 1; } return node_count; } -fn calculate_hierarchical_layout(nodes_arg: [MAX_NODES]u32, edges: [MAX_EDGES]u32, node_count: u32, edge_count: u32) u32 { - var nodes = nodes_arg; +fn calculate_hierarchical_layout(nodes: [MAX_NODES]u32, edges: [MAX_EDGES]u32, node_count: u32, edge_count: u32) u32 { _ = edges; // unused by the spec body _ = edge_count; // unused by the spec body + var vnodes: [MAX_NODES]u32 = nodes; + _ = &vnodes; const level_count: u32 = 4; _ = level_count; // dead after const-inlining const nodes_per_level: u32 = node_count / 4; @@ -194,9 +196,9 @@ fn calculate_hierarchical_layout(nodes_arg: [MAX_NODES]u32, edges: [MAX_EDGES]u3 while (i < node_count) { const y: u32 = (current_level * CANVAS_SIZE) / 4; const x: u32 = (nodes_in_level * CANVAS_SIZE) / nodes_per_level; - const node_id: u32 = get_viz_node_id(nodes[i]); - const status: u32 = get_node_visual_status(nodes[i]); - nodes[i] = create_visual_node(node_id, x, y, status); + const node_id: u32 = get_viz_node_id(vnodes[i]); + const status: u32 = get_node_visual_status(vnodes[i]); + vnodes[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; diff --git a/gen/zig/traffic_animator.zig b/gen/zig/traffic_animator.zig index bf77d46f..6d78c85b 100644 --- a/gen/zig/traffic_animator.zig +++ b/gen/zig/traffic_animator.zig @@ -195,8 +195,9 @@ fn calculate_packet_position(source_x: u32, source_y: u32, dest_x: u32, dest_y: } return ((current_x & 0xFF) << 24) | ((current_y & 0xFF) << 16); } -fn update_animation_packets(packets_arg: [MAX_PACKETS]u32, packet_count: u32, speed: u32) u32 { - var packets = packets_arg; +fn update_animation_packets(packets: [MAX_PACKETS]u32, packet_count: u32, speed: u32) u32 { + var pkts: [MAX_PACKETS]u32 = packets; + _ = &pkts; var updated_count: u32 = 0; _ = &updated_count; var completed_count: u32 = 0; @@ -204,17 +205,17 @@ fn update_animation_packets(packets_arg: [MAX_PACKETS]u32, packet_count: u32, sp var i: u32 = 0; _ = &i; while (i < packet_count) { - const progress: u32 = get_anim_packet_progress(packets[i]); + const progress: u32 = get_anim_packet_progress(pkts[i]); if (progress < 100) { var new_progress: u32 = progress + speed; _ = &new_progress; if (new_progress > 100) { new_progress = 100; } - const packet_id: u32 = get_anim_packet_id(packets[i]); - const source: u32 = get_anim_packet_source(packets[i]); - const dest: u32 = get_anim_packet_dest(packets[i]); - packets[i] = create_anim_packet(packet_id, source, dest, new_progress); + const packet_id: u32 = get_anim_packet_id(pkts[i]); + const source: u32 = get_anim_packet_source(pkts[i]); + const dest: u32 = get_anim_packet_dest(pkts[i]); + pkts[i] = create_anim_packet(packet_id, source, dest, new_progress); updated_count = updated_count + 1; } else { completed_count = completed_count + 1; diff --git a/specs/api_documenter.t27 b/specs/api_documenter.t27 index 439654c2..e4a93824 100644 --- a/specs/api_documenter.t27 +++ b/specs/api_documenter.t27 @@ -355,7 +355,10 @@ module api_documenter { // The old call passed func_docs ([u32; MAX_FUNCTIONS]) where a // [u32; MAX_PARAMETERS] belongs -- a type mismatch the C backend's // nominal array structs surfaced. No parameter docs exist here. - let empty_params: [u32; MAX_PARAMETERS] = [0; MAX_PARAMETERS]; + // The repeat count is a literal: the pinned Rust emitter copies a + // u32 constant count verbatim, and rustc requires usize (#399). + // The declared [u32; MAX_PARAMETERS] type still fixes the length. + let empty_params: [u32; MAX_PARAMETERS] = [0; 16]; let doc_summary: u32 = generate_api_documentation(func_docs, func_count, empty_params, 0); let documented_funcs: u32 = (doc_summary >> 24) & 0xFF; let coverage: u32 = calculate_documentation_coverage(documented_funcs, func_count); diff --git a/specs/auto_config.t27 b/specs/auto_config.t27 index d382709a..43b4d5c2 100644 --- a/specs/auto_config.t27 +++ b/specs/auto_config.t27 @@ -91,14 +91,15 @@ module auto_config { // Set configuration value fn set_config_value(config: [u32; MAX_PARAMS], param_id: u32, new_value: u32) -> u32 { + var cfg: [u32; MAX_PARAMS] = config; // value parameter (#399) let i: u32 = 0; while (i < MAX_PARAMS) { - let current_param_id: u32 = get_param_id(config[i]); + let current_param_id: u32 = get_param_id(cfg[i]); if (current_param_id == param_id) { - let scope: u32 = get_param_scope(config[i]); + let scope: u32 = get_param_scope(cfg[i]); let status: u32 = STATUS_PENDING; - config[i] = create_config_param(param_id, new_value, scope, status); + cfg[i] = create_config_param(param_id, new_value, scope, status); return 1; } i = i + 1; @@ -147,17 +148,18 @@ module auto_config { // Apply configuration fn apply_config(config: [u32; MAX_PARAMS], param_id: u32) -> u32 { + var cfg: [u32; MAX_PARAMS] = config; // value parameter (#399) let i: u32 = 0; while (i < MAX_PARAMS) { - let current_param_id: u32 = get_param_id(config[i]); + let current_param_id: u32 = get_param_id(cfg[i]); if (current_param_id == param_id) { - let value: u32 = get_param_value(config[i]); - let scope: u32 = get_param_scope(config[i]); + let value: u32 = get_param_value(cfg[i]); + let scope: u32 = get_param_scope(cfg[i]); // Apply configuration based on scope let success: u32 = 1; // assume success - config[i] = create_config_param(param_id, value, scope, STATUS_APPLIED); + cfg[i] = create_config_param(param_id, value, scope, STATUS_APPLIED); return success; } i = i + 1; @@ -186,23 +188,24 @@ module auto_config { } // Validate configuration + // value is u32, so each lower bound of zero holds by type (#399). fn validate_config(config: [u32; MAX_PARAMS], param_id: u32) -> u32 { let value: u32 = 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) { @@ -218,7 +221,7 @@ module auto_config { return 1; } } else if (param_id == PARAM_SECURITY_LEVEL) { - if (value >= 0 && value <= 3) { + if (value <= 3) { return 1; } } @@ -301,6 +304,7 @@ module auto_config { // Rollback configuration fn rollback_config(config: [u32; MAX_PARAMS], backup_config: [u32; MAX_PARAMS]) -> u32 { + var cfg: [u32; MAX_PARAMS] = config; // value parameter (#399) let rolled_back: u32 = 0; let i: u32 = 0; @@ -312,9 +316,9 @@ module auto_config { // Restore from backup let j: u32 = 0; while (j < MAX_PARAMS) { - let local_param_id: u32 = get_param_id(config[j]); + let local_param_id: u32 = get_param_id(cfg[j]); if (local_param_id == backup_param_id) { - config[j] = create_config_param(backup_param_id, backup_value, backup_scope, STATUS_PENDING); + cfg[j] = create_config_param(backup_param_id, backup_value, backup_scope, STATUS_PENDING); rolled_back = rolled_back + 1; break; } @@ -418,7 +422,7 @@ module auto_config { } test config_lookup_finds_param { - let cfg: [u32; 16] = [ + var cfg: [u32; 16] = [ default_config_at(0), default_config_at(1), default_config_at(2), default_config_at(3), default_config_at(4), default_config_at(5), default_config_at(6), default_config_at(7), 0, 0, 0, 0, 0, 0, 0, 0 diff --git a/specs/bandwidth_allocator.t27 b/specs/bandwidth_allocator.t27 index e59292a2..853d8e84 100644 --- a/specs/bandwidth_allocator.t27 +++ b/specs/bandwidth_allocator.t27 @@ -131,11 +131,14 @@ module BandwidthAllocator { let flow_id = get_flow_id(flow_req); let priority = get_flow_priority(flow_req); let min_bw = get_min_bandwidth(flow_req); - - if (new_bw < min_bw) { new_bw = min_bw; } - if (new_bw > MAX_BANDWIDTH) { new_bw = MAX_BANDWIDTH; } - - return create_flow_requirement(flow_id, priority, min_bw, new_bw); + // Clamp a local copy: parameters are values (#399), and the + // pinned Rust emitter does not make an assigned argument mutable. + var bw: u32 = new_bw; + + if (bw < min_bw) { bw = min_bw; } + if (bw > MAX_BANDWIDTH) { bw = MAX_BANDWIDTH; } + + return create_flow_requirement(flow_id, priority, min_bw, bw); } // Count active flows (flows with allocated bandwidth) diff --git a/specs/cache_management.t27 b/specs/cache_management.t27 index 9773480b..59a02437 100644 --- a/specs/cache_management.t27 +++ b/specs/cache_management.t27 @@ -96,10 +96,15 @@ module cache_management { // Add entry to cache fn add_entry(cache: [u32; MAX_ENTRIES], current_size: u32, data_id: u32, size: u32) -> u32 { + // Work on local copies: parameters are values (#399), and the + // pinned Rust emitter does not make an assigned argument mutable. + var slots: [u32; MAX_ENTRIES] = cache; + var used: u32 = current_size; + // Check if already exists - let existing_index: u32 = find_entry(cache, data_id); + let existing_index: u32 = find_entry(slots, data_id); if (existing_index < MAX_ENTRIES) { - return current_size; // already cached + return used; // already cached } // Find empty slot @@ -107,7 +112,7 @@ module cache_management { let i: u32 = 0; while (i < MAX_ENTRIES) { - if (get_data_id(cache[i]) == 0) { + if (get_data_id(slots[i]) == 0) { empty_index = i; break; } @@ -116,25 +121,25 @@ module cache_management { // If no empty slot, need to evict 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; // cache full, can't add + return used; // cache full, can't add } // Remove evicted entry size - let evicted_size: u32 = get_entry_size(cache[empty_index]); - current_size = current_size - evicted_size; + let evicted_size: u32 = get_entry_size(slots[empty_index]); + used = used - evicted_size; } // Check if enough space - if (current_size + size > MAX_CACHE_SIZE) { - return current_size; // not enough space + if (used + size > MAX_CACHE_SIZE) { + return used; // not enough space } // Add new entry - cache[empty_index] = create_cache_entry(data_id, 1, 0, size); + slots[empty_index] = create_cache_entry(data_id, 1, 0, size); - return current_size + size; + return used + size; } // Find eviction candidate (LRU with low access count) @@ -170,11 +175,12 @@ module cache_management { // Remove entry from cache fn remove_entry(cache: [u32; MAX_ENTRIES], current_size: u32, data_id: u32) -> u32 { - let entry_index: u32 = find_entry(cache, data_id); + var slots: [u32; MAX_ENTRIES] = cache; // value parameter (#399) + let entry_index: u32 = find_entry(slots, data_id); if (entry_index < MAX_ENTRIES) { - let entry_size: u32 = get_entry_size(cache[entry_index]); - cache[entry_index] = 0; // clear entry + let entry_size: u32 = get_entry_size(slots[entry_index]); + slots[entry_index] = 0; // clear entry return current_size - entry_size; } else { return current_size; @@ -183,12 +189,13 @@ module cache_management { // Access cache entry fn access_cache(cache: [u32; MAX_ENTRIES], data_id: u32) -> u32 { - let entry_index: u32 = find_entry(cache, data_id); + var slots: [u32; MAX_ENTRIES] = cache; // value parameter (#399) + let entry_index: u32 = find_entry(slots, data_id); if (entry_index < MAX_ENTRIES) { // Update access count and reset age - cache[entry_index] = update_access_count(cache[entry_index]); - cache[entry_index] = update_age(cache[entry_index], 0); + slots[entry_index] = update_access_count(slots[entry_index]); + slots[entry_index] = update_age(slots[entry_index], 0); return 1; // cache hit } else { return 0; // cache miss @@ -197,14 +204,15 @@ module cache_management { // Age all cache entries fn age_cache(cache: [u32; MAX_ENTRIES]) { + var slots: [u32; MAX_ENTRIES] = cache; // value parameter (#399) let i: u32 = 0; while (i < MAX_ENTRIES) { - let entry: u32 = cache[i]; + let entry: u32 = slots[i]; let age: u32 = get_age(entry); if (age < 255) { - cache[i] = update_age(entry, age + 1); + slots[i] = update_age(entry, age + 1); } i = i + 1; diff --git a/specs/compression_engine.t27 b/specs/compression_engine.t27 index cd99e96b..449e72e6 100644 --- a/specs/compression_engine.t27 +++ b/specs/compression_engine.t27 @@ -288,8 +288,9 @@ module compression_engine { // Update compression dictionary fn update_dictionary(dictionary: [u32; DICTIONARY_SIZE], new_entry: u32, index: u32) -> u32 { + var dict: [u32; DICTIONARY_SIZE] = dictionary; // value parameter (#399) if (index < DICTIONARY_SIZE) { - dictionary[index] = new_entry; + dict[index] = new_entry; return 1; } else { return 0; diff --git a/specs/integration_framework.t27 b/specs/integration_framework.t27 index 4498f4ec..2bd3c324 100644 --- a/specs/integration_framework.t27 +++ b/specs/integration_framework.t27 @@ -36,7 +36,7 @@ module integration_framework { // Module types const TYPE_NETWORK: u32 = 0; const TYPE_TESTING: u32 = 1; - const type_documentation: u32 = 2; + const TYPE_DOCUMENTATION: u32 = 2; const TYPE_VISUALIZATION: u32 = 3; const TYPE_SIMULATION: u32 = 4; const TYPE_PROFILING: u32 = 5; @@ -157,13 +157,14 @@ module integration_framework { // Subscribe to events fn subscribe_to_event(module_id: u32, event_type: u32, subscriptions: [u32; MAX_EVENTS]) -> u32 { + var subs: [u32; MAX_EVENTS] = subscriptions; // value parameter (#399) let subscription_id: u32 = module_id * 10 + event_type; // Create subscription record let i: u32 = 0; while (i < MAX_EVENTS) { - if (subscriptions[i] == 0) { - subscriptions[i] = create_event(subscription_id, event_type, module_id, 0); + if (subs[i] == 0) { + subs[i] = create_event(subscription_id, event_type, module_id, 0); return 1; // subscription successful } i = i + 1; @@ -312,11 +313,12 @@ module integration_framework { // Module lifecycle management fn load_module(module_id: u32, module_type: u32, priority: u32, modules: [u32; MAX_MODULES]) -> u32 { + var mods: [u32; MAX_MODULES] = modules; // value parameter (#399) // Find empty slot let i: u32 = 0; while (i < MAX_MODULES) { - if (get_registered_module_id(modules[i]) == 0) { - modules[i] = create_module_registration(module_id, module_type, priority, STATUS_IDLE); + if (get_registered_module_id(mods[i]) == 0) { + mods[i] = create_module_registration(module_id, module_type, priority, STATUS_IDLE); return 1; // success } i = i + 1; @@ -327,12 +329,13 @@ module integration_framework { // Unload module fn unload_module(module_id: u32, modules: [u32; MAX_MODULES]) -> u32 { + var mods: [u32; MAX_MODULES] = modules; // value parameter (#399) let i: u32 = 0; while (i < MAX_MODULES) { - let registered_id: u32 = get_registered_module_id(modules[i]); + let registered_id: u32 = get_registered_module_id(mods[i]); if (registered_id == module_id) { - modules[i] = 0; // clear slot + mods[i] = 0; // clear slot return 1; // success } @@ -553,7 +556,7 @@ module integration_framework { } test send_message_requires_active_destination { - let mods: [u32; 16] = [ + var mods: [u32; 16] = [ create_module_registration(1, 0, 1, STATUS_ACTIVE), create_module_registration(2, 0, 1, 0), 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 diff --git a/specs/network_simulator.t27 b/specs/network_simulator.t27 index 55250396..3e7a0753 100644 --- a/specs/network_simulator.t27 +++ b/specs/network_simulator.t27 @@ -219,6 +219,7 @@ module network_simulator { // Process simulation event fn process_event(event: u32, node_states: [u32; MAX_NODES], link_states: [u32; MAX_NODES]) -> u32 { + var states: [u32; MAX_NODES] = node_states; // value parameter (#399) let event_type: u32 = get_event_type(event); let node_id: u32 = get_event_node_id(event); @@ -230,8 +231,8 @@ module network_simulator { return 1; } else if (event_type == EVENT_NODE_FAILURE) { // Update node status to failed - let current_state: u32 = node_states[node_id]; - node_states[node_id] = update_node_status(current_state, NODE_FAILED); + let current_state: u32 = states[node_id]; + states[node_id] = update_node_status(current_state, NODE_FAILED); return 1; } else if (event_type == EVENT_LINK_FAILURE) { // Process link failure @@ -306,9 +307,10 @@ module network_simulator { // Inject fault into simulation fn inject_fault(fault_type: u32, target_id: u32, node_states: [u32; MAX_NODES]) -> u32 { + var states: [u32; MAX_NODES] = node_states; // value parameter (#399) if (fault_type == EVENT_NODE_FAILURE) { - let current_state: u32 = node_states[target_id]; - node_states[target_id] = update_node_status(current_state, NODE_FAILED); + let current_state: u32 = states[target_id]; + states[target_id] = update_node_status(current_state, NODE_FAILED); return 1; } else if (fault_type == EVENT_LINK_FAILURE) { // Link failure injection would require link state modification diff --git a/specs/performance_profiler.t27 b/specs/performance_profiler.t27 index a8ef15d7..8537a603 100644 --- a/specs/performance_profiler.t27 +++ b/specs/performance_profiler.t27 @@ -194,11 +194,12 @@ module performance_profiler { // Track memory allocation fn track_allocation(allocations: [u32; MAX_SAMPLES], alloc_id: u32, size: u32, pool: u32) -> u32 { + var allocs: [u32; MAX_SAMPLES] = allocations; // value parameter (#399) // Find empty slot let i: u32 = 0; while (i < MAX_SAMPLES) { - if (get_allocation_id(allocations[i]) == 0) { - allocations[i] = create_allocation(alloc_id, size, 255, pool); + if (get_allocation_id(allocs[i]) == 0) { + allocs[i] = create_allocation(alloc_id, size, 255, pool); return 1; } i = i + 1; diff --git a/specs/topology_visualizer.t27 b/specs/topology_visualizer.t27 index 34814e95..b04bb0b6 100644 --- a/specs/topology_visualizer.t27 +++ b/specs/topology_visualizer.t27 @@ -220,6 +220,7 @@ module topology_visualizer { // Calculate circular layout fn calculate_circular_layout(nodes: [u32; MAX_NODES], node_count: u32) -> u32 { + var vnodes: [u32; MAX_NODES] = nodes; // value parameter (#399) let center_x: u32 = CANVAS_SIZE / 2; let center_y: u32 = CANVAS_SIZE / 2; let radius: u32 = CANVAS_SIZE / 3; @@ -233,9 +234,9 @@ module topology_visualizer { let y: u32 = center_y + ((radius * angle) / 360); // Update node position - let node_id: u32 = get_viz_node_id(nodes[i]); - let status: u32 = get_node_visual_status(nodes[i]); - nodes[i] = create_visual_node(node_id, x, y, status); + let node_id: u32 = get_viz_node_id(vnodes[i]); + let status: u32 = get_node_visual_status(vnodes[i]); + vnodes[i] = create_visual_node(node_id, x, y, status); i = i + 1; } @@ -246,6 +247,7 @@ module topology_visualizer { // Calculate hierarchical layout fn calculate_hierarchical_layout(nodes: [u32; MAX_NODES], edges: [u32; MAX_EDGES], node_count: u32, edge_count: u32) -> u32 { + var vnodes: [u32; MAX_NODES] = nodes; // value parameter (#399) let level_count: u32 = 4; let nodes_per_level: u32 = node_count / level_count; @@ -257,9 +259,9 @@ module topology_visualizer { let y: u32 = (current_level * CANVAS_SIZE) / level_count; let x: u32 = ((nodes_in_level * CANVAS_SIZE) / nodes_per_level); - let node_id: u32 = get_viz_node_id(nodes[i]); - let status: u32 = get_node_visual_status(nodes[i]); - nodes[i] = create_visual_node(node_id, x, y, status); + let node_id: u32 = get_viz_node_id(vnodes[i]); + let status: u32 = get_node_visual_status(vnodes[i]); + vnodes[i] = create_visual_node(node_id, x, y, status); nodes_in_level = nodes_in_level + 1; if (nodes_in_level >= nodes_per_level) { diff --git a/specs/traffic_animator.t27 b/specs/traffic_animator.t27 index f46a192f..5a185b9e 100644 --- a/specs/traffic_animator.t27 +++ b/specs/traffic_animator.t27 @@ -280,12 +280,13 @@ module traffic_animator { // Update all packets in animation fn update_animation_packets(packets: [u32; MAX_PACKETS], packet_count: u32, speed: u32) -> u32 { + var pkts: [u32; MAX_PACKETS] = packets; // value parameter (#399) let updated_count: u32 = 0; let completed_count: u32 = 0; let i: u32 = 0; while (i < packet_count) { - let progress: u32 = get_anim_packet_progress(packets[i]); + let progress: u32 = get_anim_packet_progress(pkts[i]); if (progress < 100) { let new_progress: u32 = progress + speed; @@ -293,11 +294,11 @@ module traffic_animator { new_progress = 100; } - let packet_id: u32 = get_anim_packet_id(packets[i]); - let source: u32 = get_anim_packet_source(packets[i]); - let dest: u32 = get_anim_packet_dest(packets[i]); + let packet_id: u32 = get_anim_packet_id(pkts[i]); + let source: u32 = get_anim_packet_source(pkts[i]); + let dest: u32 = get_anim_packet_dest(pkts[i]); - packets[i] = create_anim_packet(packet_id, source, dest, new_progress); + pkts[i] = create_anim_packet(packet_id, source, dest, new_progress); updated_count = updated_count + 1; } else { completed_count = completed_count + 1; diff --git a/tests/gen_rust_corpus_compiles.rs b/tests/gen_rust_corpus_compiles.rs new file mode 100644 index 00000000..3f8e2897 --- /dev/null +++ b/tests/gen_rust_corpus_compiles.rs @@ -0,0 +1,184 @@ +// Persistent compile gate for the whole generated Rust corpus (#399). +// +// The drift check proves that gen/rust/.rs equals the pinned t27c +// output for specs/.t27. It does not prove that the output is valid +// Rust: most gen/rust modules are not reachable from any Cargo target, so a +// matching but uncompilable artifact passed every gate. This test compiles +// every committed gen/rust/*.rs as its own library crate with +// `-D warnings`, under the generated-module policy used by the crate +// (`allow(clippy::all, unused)`), and fails on any error. +// +// Negative controls run first through the same compile path: the defect +// classes that #399 found must be rejected, so a gate that silently accepts +// everything cannot pass. + +use std::fs; +use std::path::{Path, PathBuf}; +use std::process::Command; +use std::sync::atomic::{AtomicUsize, Ordering}; +use std::sync::Mutex; +use std::thread; + +/// Number of committed gen/rust artifacts. Raise it when a spec gains a Rust +/// artifact; a lower count fails, so coverage cannot shrink silently. +const CORPUS_FLOOR: usize = 102; + +const WRAPPER_POLICY: &str = "#![allow(clippy::all, unused)]\n"; + +fn rustc() -> String { + std::env::var("RUSTC").unwrap_or_else(|_| "rustc".to_string()) +} + +fn scratch_dir(name: &str) -> PathBuf { + let dir = Path::new(env!("CARGO_TARGET_TMPDIR")) + .join("gen_rust_corpus") + .join(name); + fs::create_dir_all(&dir).expect("create scratch directory"); + dir +} + +/// Compile `module` as a library crate wrapped in the generated-module +/// policy. Returns the compiler diagnostics on failure. +fn compile_module(module: &Path, out_dir: &Path, crate_name: &str) -> Result<(), String> { + let wrapper = out_dir.join(format!("{crate_name}_wrapper.rs")); + let module = module.canonicalize().expect("canonical module path"); + let source = format!( + "{WRAPPER_POLICY}#[path = {:?}]\nmod generated;\n", + module.to_string_lossy() + ); + fs::write(&wrapper, source).expect("write wrapper crate"); + let output = Command::new(rustc()) + .args(["--edition=2021", "--crate-type=lib", "-D", "warnings"]) + .arg("--crate-name") + .arg(crate_name) + .arg("--out-dir") + .arg(out_dir) + .arg(&wrapper) + .output() + .expect("run rustc"); + if output.status.success() { + Ok(()) + } else { + Err(String::from_utf8_lossy(&output.stderr).into_owned()) + } +} + +fn first_errors(diagnostics: &str) -> String { + diagnostics + .lines() + .filter(|line| line.starts_with("error") || line.trim_start().starts_with("-->")) + .take(8) + .collect::>() + .join("\n") +} + +#[test] +fn negative_controls_are_rejected() { + let dir = scratch_dir("controls"); + let controls = [ + ( + "assigned_value_argument", + "pub fn clamp(limit: u32, value: u32) -> u32 {\n if value > limit {\n value = limit;\n }\n value\n}\n", + "E0384", + ), + ( + "written_array_argument", + "pub fn clear(slots: [u32; 4], index: u32) -> u32 {\n slots[index as usize] = 0;\n 1\n}\n", + "E0594", + ), + ( + "u32_repeat_count", + "pub const COUNT: u32 = 4;\npub fn zeros() -> [u32; COUNT as usize] {\n [0; COUNT]\n}\n", + "E0308", + ), + ( + "useless_unsigned_comparison", + "pub fn non_negative(value: u32) -> bool {\n value >= 0\n}\n", + "unused_comparisons", + ), + ( + "lowercase_constant", + "pub const type_documentation: u32 = 2;\n", + "non_upper_case_globals", + ), + ]; + for (name, body, expected) in controls { + let module = dir.join(format!("{name}.rs")); + fs::write(&module, body).expect("write control module"); + match compile_module(&module, &dir, name) { + Ok(()) => panic!("negative control {name} compiled; the gate accepts {expected}"), + Err(diagnostics) => assert!( + diagnostics.contains(expected), + "negative control {name} failed without {expected}:\n{diagnostics}" + ), + } + } + // Positive control: the same path accepts a valid module, so the + // rejections above come from the defects, not from the harness. + let valid = dir.join("valid_control.rs"); + fs::write( + &valid, + "pub fn clamp(limit: u32, value: u32) -> u32 {\n let mut v = value;\n if v > limit {\n v = limit;\n }\n v\n}\n", + ) + .expect("write positive control"); + if let Err(diagnostics) = compile_module(&valid, &dir, "valid_control") { + panic!("positive control failed to compile:\n{diagnostics}"); + } +} + +#[test] +fn every_generated_rust_module_compiles() { + let root = Path::new(env!("CARGO_MANIFEST_DIR")); + let mut modules: Vec = fs::read_dir(root.join("gen/rust")) + .expect("read gen/rust") + .map(|entry| entry.expect("gen/rust entry").path()) + .filter(|path| path.extension().is_some_and(|ext| ext == "rs")) + .collect(); + modules.sort(); + assert!( + modules.len() >= CORPUS_FLOOR, + "gen/rust has {} modules, below the floor of {CORPUS_FLOOR}", + modules.len() + ); + + let dir = scratch_dir("corpus"); + let next = AtomicUsize::new(0); + let failures = Mutex::new(Vec::new()); + let workers = thread::available_parallelism().map_or(2, |n| n.get().min(8)); + thread::scope(|scope| { + for _ in 0..workers { + scope.spawn(|| loop { + let index = next.fetch_add(1, Ordering::Relaxed); + let Some(module) = modules.get(index) else { + break; + }; + let stem = module + .file_stem() + .expect("module stem") + .to_string_lossy() + .into_owned(); + let crate_name = format!("gen_{stem}"); + if let Err(diagnostics) = compile_module(module, &dir, &crate_name) { + failures.lock().expect("failure list").push(format!( + "gen/rust/{stem}.rs:\n{}", + first_errors(&diagnostics) + )); + } + }); + } + }); + + let mut failures = failures.into_inner().expect("failure list"); + failures.sort(); + println!( + "gen/rust corpus: {} of {} modules compile", + modules.len() - failures.len(), + modules.len() + ); + assert!( + failures.is_empty(), + "{} generated Rust module(s) do not compile with -D warnings:\n\n{}", + failures.len(), + failures.join("\n\n") + ); +} diff --git a/tests/gen_rust_value_params.rs b/tests/gen_rust_value_params.rs new file mode 100644 index 00000000..8bb61ba4 --- /dev/null +++ b/tests/gen_rust_value_params.rs @@ -0,0 +1,236 @@ +// Behaviour of the ten generated Rust modules that compile since #399. +// +// Their specs now copy assigned value parameters into local `var` +// bindings (or, in api_documenter, use a literal repeat count). Parameters +// are values in every backend: the generated C passes arrays as structs by +// value and the generated Zig shadows them, so a write never reaches the +// caller. These tests pin the returned values and that caller contract. + +#[allow(unused, clippy::all)] +#[path = "../gen/rust/api_documenter.rs"] +mod api_documenter; +#[allow(unused, clippy::all)] +#[path = "../gen/rust/auto_config.rs"] +mod auto_config; +#[allow(unused, clippy::all)] +#[path = "../gen/rust/bandwidth_allocator.rs"] +mod bandwidth_allocator; +#[allow(unused, clippy::all)] +#[path = "../gen/rust/cache_management.rs"] +mod cache_management; +#[allow(unused, clippy::all)] +#[path = "../gen/rust/compression_engine.rs"] +mod compression_engine; +#[allow(unused, clippy::all)] +#[path = "../gen/rust/integration_framework.rs"] +mod integration_framework; +#[allow(unused, clippy::all)] +#[path = "../gen/rust/network_simulator.rs"] +mod network_simulator; +#[allow(unused, clippy::all)] +#[path = "../gen/rust/performance_profiler.rs"] +mod performance_profiler; +#[allow(unused, clippy::all)] +#[path = "../gen/rust/topology_visualizer.rs"] +mod topology_visualizer; +#[allow(unused, clippy::all)] +#[path = "../gen/rust/traffic_animator.rs"] +mod traffic_animator; + +#[test] +fn flow_bandwidth_is_clamped_between_minimum_and_maximum() { + use bandwidth_allocator::*; + let flow = create_flow_requirement(5, PRIORITY_HIGH, 50, 100); + for (requested, granted) in [ + (0, 50), + (49, 50), + (50, 50), + (70, 70), + (500, 500), + (501, 500), + ] { + let updated = update_flow_bandwidth(flow, requested); + assert_eq!( + get_current_bandwidth(updated), + granted, + "request {requested}" + ); + assert_eq!(get_flow_id(updated), 5); + assert_eq!(get_flow_priority(updated), PRIORITY_HIGH); + assert_eq!(get_min_bandwidth(updated), 50); + } +} + +fn full_cache() -> [u32; 16] { + // Data ids 1..=16, size 10 each; slot 4 is the only cold entry. + std::array::from_fn(|i| { + let access_count = if i == 4 { 1 } else { 5 }; + cache_management::create_cache_entry(i as u32 + 1, access_count, 0, 10) + }) +} + +#[test] +fn cache_operations_return_sizes_and_leave_the_caller_cache_unchanged() { + use cache_management::*; + let empty = [0u32; 16]; + let mut one = empty; + one[3] = create_cache_entry(7, 1, 0, 30); + let full = full_cache(); + let snapshots = (empty, one, full); + + // Empty slot: the new size is added. + assert_eq!(add_entry(empty, 0, 7, 30), 30); + // Already cached: the size is unchanged. + assert_eq!(add_entry(one, 30, 7, 10), 30); + // Not enough room: the size is unchanged. + assert_eq!(add_entry(empty, 250, 9, 10), 250); + // Full: the cold entry (size 10) is evicted, then 20 is added. + assert_eq!(find_eviction_candidate(full), 4); + assert_eq!(add_entry(full, 160, 99, 20), 170); + + assert_eq!(remove_entry(full, 160, 3), 150); + assert_eq!(remove_entry(full, 160, 99), 160); + assert_eq!(access_cache(full, 3), 1); + assert_eq!(access_cache(full, 99), 0); + age_cache(full); + + assert_eq!((empty, one, full), snapshots, "a value argument changed"); +} + +#[test] +fn config_bounds_accept_zero_and_the_upper_limit() { + use auto_config::*; + let with = |param_id: u32, value: u32| { + let mut config = [0u32; 16]; + config[0] = create_config_param(param_id, value, 0, STATUS_APPLIED); + config + }; + for (param_id, limit) in [ + (PARAM_TX_POWER, 100), + (PARAM_CHANNEL, 11), + (PARAM_DATA_RATE, 3), + (PARAM_RETRY_LIMIT, 7), + (PARAM_SECURITY_LEVEL, 3), + ] { + assert_eq!(validate_config(with(param_id, 0), param_id), 1); + assert_eq!(validate_config(with(param_id, limit), param_id), 1); + assert_eq!(validate_config(with(param_id, limit + 1), param_id), 0); + } + + let config = with(PARAM_CHANNEL, 6); + let before = config; + assert_eq!(set_config_value(config, PARAM_CHANNEL, 9), 1); + assert_eq!(set_config_value(config, 200, 9), 0); + assert_eq!(apply_config(config, PARAM_CHANNEL), 1); + assert_eq!(apply_config(config, 200), 0); + assert_eq!(config, before, "a value argument changed"); + // The caller still sees the old value. + assert_eq!(get_config_value(config, PARAM_CHANNEL), 6); + + // Backup ids: 1 matches, 5 does not, and fourteen empty ids (0) match + // the empty local entries. + let mut local = [0u32; 16]; + local[0] = create_config_param(1, 10, 0, STATUS_APPLIED); + local[1] = create_config_param(2, 20, 0, STATUS_APPLIED); + let mut backup = [0u32; 16]; + backup[0] = create_config_param(1, 11, 0, STATUS_APPLIED); + backup[1] = create_config_param(5, 50, 0, STATUS_APPLIED); + assert_eq!(rollback_config(local, backup), 15); +} + +#[test] +fn table_writes_report_success_without_touching_the_caller() { + let dictionary = [9u32; 8]; + assert_eq!(compression_engine::update_dictionary(dictionary, 1, 7), 1); + assert_eq!(compression_engine::update_dictionary(dictionary, 1, 8), 0); + assert_eq!(dictionary, [9u32; 8]); + + use integration_framework::*; + assert_eq!(TYPE_DOCUMENTATION, 2); + let free = [0u32; 64]; + let busy = [1u32; 64]; + assert_eq!(subscribe_to_event(1, 2, free), 1); + assert_eq!(subscribe_to_event(1, 2, busy), 0); + let mut modules = [0u32; 16]; + modules[5] = create_module_registration(42, TYPE_TESTING, 1, STATUS_ACTIVE); + let before = modules; + assert_eq!(load_module(43, TYPE_NETWORK, 1, modules), 1); + let crowded: [u32; 16] = + std::array::from_fn(|i| create_module_registration(i as u32 + 1, 0, 0, 0)); + assert_eq!(load_module(43, TYPE_NETWORK, 1, crowded), 0); + assert_eq!(unload_module(42, modules), 1); + assert_eq!(unload_module(44, modules), 0); + assert_eq!(modules, before); + + let allocations = [0u32; 64]; + let exhausted: [u32; 64] = + std::array::from_fn(|i| performance_profiler::create_allocation(i as u32 + 1, 4, 1, 0)); + assert_eq!( + performance_profiler::track_allocation(allocations, 7, 16, 0), + 1 + ); + assert_eq!( + performance_profiler::track_allocation(exhausted, 7, 16, 0), + 0 + ); + assert_eq!(allocations, [0u32; 64]); +} + +#[test] +fn simulation_and_layout_results_are_unchanged() { + use network_simulator::*; + let states = [0u32; 32]; + let failure = (EVENT_NODE_FAILURE << 4) | 3; + assert_eq!(process_event(failure, states, states), 1); + assert_eq!(process_event(9 << 4, states, states), 0); + assert_eq!(inject_fault(EVENT_NODE_FAILURE, 31, states), 1); + assert_eq!(inject_fault(EVENT_LINK_FAILURE, 0, states), 1); + assert_eq!(inject_fault(7, 0, states), 0); + assert_eq!(states, [0u32; 32]); + + let nodes = [0x0102_0304u32; 32]; + let edges = [0u32; 64]; + for count in [0, 1, 7, 32] { + assert_eq!( + topology_visualizer::calculate_circular_layout(nodes, count), + count + ); + } + for count in [4, 9, 32] { + assert_eq!( + topology_visualizer::calculate_hierarchical_layout(nodes, edges, count, 0), + count + ); + } + assert_eq!(nodes, [0x0102_0304u32; 32]); +} + +#[test] +fn animation_counts_updated_and_completed_packets() { + use traffic_animator::*; + let mut packets = [0u32; 64]; + packets[0] = create_anim_packet(1, 2, 3, 40); + packets[1] = create_anim_packet(2, 2, 3, 100); + packets[2] = create_anim_packet(3, 2, 3, 95); + let before = packets; + // Three packets: two in flight are updated, one is already complete. + assert_eq!( + update_animation_packets(packets, 3, 10), + (2 << 24) | (1 << 16) | (3 << 8) + ); + assert_eq!(update_animation_packets(packets, 0, 10), 0); + assert_eq!(packets, before); +} + +#[test] +fn documentation_report_coverage_and_reference_count() { + use api_documenter::*; + let docs: [u32; 64] = std::array::from_fn(|i| create_function_doc(i as u32, 2, 1, 1000)); + let xrefs = [0u32; 64]; + for (functions, references) in [(0, 0), (1, 3), (64, 64)] { + let report = generate_documentation_report(docs, functions, xrefs, references); + // Every listed function is documented, so coverage is 100 percent. + assert_eq!(report >> 24, 100); + assert_eq!(report & 0xFF, references); + } +}