void check_route(enum e_route_type route_type, int num_switch, t_ivec ** clb_opins_used_locally) { /* This routine checks that a routing: (1) Describes a properly * * connected path for each net, (2) this path connects all the * * pins spanned by that net, and (3) that no routing resources are * * oversubscribed (the occupancy of everything is recomputed from * * scratch). */ int inet, ipin, max_pins, inode, prev_node; boolean valid, connects; boolean * connected_to_route; /* [0 .. num_rr_nodes-1] */ struct s_trace *tptr; boolean * pin_done; vpr_printf(TIO_MESSAGE_INFO, "\n"); vpr_printf(TIO_MESSAGE_INFO, "Checking to ensure routing is legal...\n"); /* Recompute the occupancy from scratch and check for overuse of routing * * resources. This was already checked in order to determine that this * * is a successful routing, but I want to double check it here. */ recompute_occupancy_from_scratch(clb_opins_used_locally); valid = feasible_routing(); if (valid == FALSE) { vpr_printf(TIO_MESSAGE_ERROR, "Error in check_route -- routing resources are overused.\n"); exit(1); } check_locally_used_clb_opins(clb_opins_used_locally, route_type); connected_to_route = (boolean *) my_calloc(num_rr_nodes, sizeof(boolean)); max_pins = 0; for (inet = 0; inet < num_nets; inet++) max_pins = std::max(max_pins, (clb_net[inet].num_sinks + 1)); pin_done = (boolean *) my_malloc(max_pins * sizeof(boolean)); /* Now check that all nets are indeed connected. */ for (inet = 0; inet < num_nets; inet++) { if (clb_net[inet].is_global || clb_net[inet].num_sinks == 0) /* Skip global nets. */ continue; for (ipin = 0; ipin < (clb_net[inet].num_sinks + 1); ipin++) pin_done[ipin] = FALSE; /* Check the SOURCE of the net. */ tptr = trace_head[inet]; if (tptr == NULL) { vpr_printf(TIO_MESSAGE_ERROR, "in check_route: net %d has no routing.\n", inet); exit(1); } inode = tptr->index; check_node_and_range(inode, route_type); check_switch(tptr, num_switch); connected_to_route[inode] = TRUE; /* Mark as in path. */ check_source(inode, inet); pin_done[0] = TRUE; prev_node = inode; tptr = tptr->next; /* Check the rest of the net */ while (tptr != NULL) { inode = tptr->index; check_node_and_range(inode, route_type); check_switch(tptr, num_switch); if (rr_node[prev_node].type == SINK) { if (connected_to_route[inode] == FALSE) { vpr_printf(TIO_MESSAGE_ERROR, "in check_route: node %d does not link into existing routing for net %d.\n", inode, inet); exit(1); } } else { connects = check_adjacent(prev_node, inode); if (!connects) { vpr_printf(TIO_MESSAGE_ERROR, "in check_route: found non-adjacent segments in traceback while checking net %d.\n", inet); exit(1); } if (connected_to_route[inode] && rr_node[inode].type != SINK) { /* Note: Can get multiple connections to the same logically-equivalent * * SINK in some logic blocks. */ vpr_printf(TIO_MESSAGE_ERROR, "in check_route: net %d routing is not a tree.\n", inet); exit(1); } connected_to_route[inode] = TRUE; /* Mark as in path. */ if (rr_node[inode].type == SINK) check_sink(inode, inet, pin_done); } /* End of prev_node type != SINK */ prev_node = inode; tptr = tptr->next; } /* End while */ if (rr_node[prev_node].type != SINK) { vpr_printf(TIO_MESSAGE_ERROR, "in check_route: net %d does not end with a SINK.\n", inet); exit(1); } for (ipin = 0; ipin < (clb_net[inet].num_sinks + 1); ipin++) { if (pin_done[ipin] == FALSE) { vpr_printf(TIO_MESSAGE_ERROR, "in check_route: net %d does not connect to pin %d.\n", inet, ipin); exit(1); } } reset_flags(inet, connected_to_route); } /* End for each net */ free(pin_done); free(connected_to_route); vpr_printf(TIO_MESSAGE_INFO, "Completed routing consistency check successfully.\n"); vpr_printf(TIO_MESSAGE_INFO, "\n"); }
// May throw stream::read_result try_read_bucket_and_return_(size_type amount) { check_source(); return source_->read(amount); }
/* program to check the source code for errors */ main(int argc, char **argv, char **envp) { check_source(); return 0; }
int main (int argc, char ** argv) { int opts = 0; int delay = 8000; short volume = 4; // Get the arguments while((opts = getopt(argc, argv,"d:v: tt")) != -1) { if (opts == 'd') { delay = atoi(optarg); } else if (opts == 'v') { volume = atoi(optarg); } } // Make sure delay is not negative // Make sure volume scale is at least 1 check_delay(&delay); check_volume(&volume); // Open the files in binary mode to read, or write FILE *source = fopen(argv[optind], "rb"); FILE *dest = fopen(argv[optind+1], "wb"); // Handle incorrect source file input check_source(&source); // READ header from source - first 44 bytes as 11 ints int header[11] = {0}; fread(header, sizeof(int), 11, source); // Change file size in the header header[1] += delay*2; header[10] += delay*2; // WRITE header to output file fwrite(header, sizeof(int), 11, dest); // Allocate mem to store delay number of shorts short *buffer; buffer = malloc((sizeof(short) * delay)); // Copy samples before DELAY num of samples into buffer fseek(source, 44, SEEK_SET); // 44 bytes from start of file fread(buffer, sizeof(short), delay, source); // START READING THE SAMPLES ONE AT A TIME. fseek(source, 44, SEEK_SET); // 44 bytes from start of file short smp = 0; // This will hold the sample being read int s = 0; // Keeps track of the NUMBER OF samples read while (fread(&smp, sizeof(short), 1, source)) { if (s < delay) { // If not at sample number DELAY yet, just write as they are... fwrite(&smp, sizeof(short), 1, dest); } else { // At sample number DELAY, write mixed in buffer[0] scaled by volume short temp = smp + (buffer[0] / volume); fwrite(&temp, sizeof(short), 1, dest); } // START OF BUFFER CODE // Append smp to the buffer AFTER "popping it" int i = 0; for (i = 0; i < delay-1; i++) { buffer[i] = buffer[i+1]; } buffer[delay-1] = smp; // EOF BUFFER CODE s++; // Increment the number of samples } // Write the rest of the buffer scaled by volume to dest int i = 0; for (i = 0; i < delay; i++) { buffer[i] /= volume; } fwrite(buffer, sizeof(short), delay, dest); return 0; }
static int check_command_line(struct modbus_params_t *params, int argc, char **argv) { (void)argc; #if LIBMODBUS_VERSION_MAJOR >= 3 if (params->host == NULL && params->serial == NULL && params->file == NULL) { ERR("Not provided or unable to parse host address/serial port name/filename: %s\n", argv[0]); return RESULT_WRONG_ARG; }; #else if (params->host == NULL && params->file == NULL) { ERR("Not provided or unable to parse host address or filename: %s\n", argv[0]); return RESULT_WRONG_ARG; }; #endif #if LIBMODBUS_VERSION_MAJOR >= 3 if (params->serial != NULL) { if (params->serial_mode != MODBUS_RTU_RS232 && params->serial_mode != MODBUS_RTU_RS485) { ERR("%s: Invalid value of serial port mode parameter!\n", argv[0]); return RESULT_WRONG_ARG; } if (check_serial_parity(params->serial_parity)) { ERR("%s: Invalid value of serial port parity mode parameter!\n", argv[0]); return RESULT_WRONG_ARG; } if (params->serial_data_bits < 5 || params->serial_data_bits > 8) { ERR("%s: Invalid value of serial port mode data length parameter!\n", argv[0]); return RESULT_WRONG_ARG; } if (params->serial_stop_bits < 1 || params->serial_stop_bits > 2) { ERR("%s: Invalid value of serial port stop bits parameter!\n", argv[0]); return RESULT_WRONG_ARG; } } #endif if (params->perf_data && (params->perf_label == NULL)) { ERR("Label parameter is required, when performance data is enabled\n"); return RESULT_WRONG_ARG; } if (params->dump_size > 127) { ERR("The maximal number of registers in one dump is 127\n"); return RESULT_WRONG_ARG; } if (check_swap_inverse(params)) return RESULT_WRONG_ARG; if (check_function_num(params)) return RESULT_WRONG_ARG; if (check_format_type(params)) return RESULT_WRONG_ARG; if (check_source(params)) return RESULT_WRONG_ARG; if (check_dump_param(params)) return RESULT_WRONG_ARG; if (dbg_chk_level(DBG_INFO)) print_settings(stdout, params); return RESULT_OK; }