int main(int argc, const char * argv[]) { char filename[MAX_LENGTH]; node_t * nodes[MAX_NODES]; FILE * file; int count; int i; //check that there is correct number of arguments if (argc != 2) { printf("graphexec requires 2 arguments.\n"); return -1; } //open file and check that it was sucessful file = fopen(argv[1], "r"); if (!file) { printf("The file specified does not exist or could not be opened.\n"); } //if things check out, proceed to read and process file else { count = read_file(file, nodes, MAX_NODES); bool finished; while (!finished) { finished = true; determine_eligible(nodes, count); //iterate through and run nodes that are marked READY for (i = 0; i < count; i++) { if (nodes[i]->status != FINISHED) { finished = false; if (nodes[i]->status == READY) { printf("Node %i Status: Running", i); if(run_node(nodes[i]) == FINISHED && run_node(nodes[i]) != -1) { printf(" >> Finished!\n"); } else perror("Error running node"); } } } } //cleanup free_array(nodes, count); if (fclose(file) == -1) perror("Failed to close file"); } return 0; }
static PyObject * run_err_node(node *n, char *filename, PyObject *globals, PyObject *locals) { if (n == NULL) return NULL; return run_node(n, filename, globals, locals); }
int run_node(node_t* n, uint64_t lg2_pin_size, uint64_t pin_offs, void* pins) { #define PIN(x) ((((x)+pin_offs)<<lg2_pin_size)+pins) const uint64_t pin_size = 1<<lg2_pin_size; int i; if(n->output_constant) { for(i=n->output0;i<n->outputN;i++) { memcpy(PIN(i),n->output_constant,pin_size); } return 0; } else if (n->function) { void* inputs = PIN(n->input0); void* outputs = PIN(n->output0); n->function(inputs,outputs); } else if (n->subnodes) { pin_offs+=n->input0; node_t* subnode; for(i=0, subnode=n->subnodes; i<n->k; i++, subnode++) { run_node(subnode,lg2_pin_size,pin_offs,pins); } struct connection* cxn; for(i=0, cxn=n->cxn; i<n->ncxn; i++, cxn++) { memcpy(PIN(cxn->to_pin),PIN(cxn->from_pin),pin_size); } } else { return -2; } #undef PIN }
int main(int argc, const char * argv[]) { char input_file_name[MAX_FILENAME_SIZE]; node_t * node_array[50];//array to store address of nodes FILE * input_file; int node_count; int i; if (argc == 2) { // If there are 2 arguments, the second one will be the input file strcpy(input_file_name, argv[1]); } else { // If there are not 2 arguments, print usage message and exit printf("usage: graphexec inputfile\n"); exit(EXIT_STATUS_BAD_INPUT); } input_file = fopen(input_file_name, "r"); if (!input_file) { printf("The file %s does not exist or could not be opened.\n",input_file_name); } else { node_count = file_to_node_array(input_file,node_array,MAX_NODES); bool all_finished; do { all_finished = true; update_graph_eligibility(node_array, node_count); for (i = 0; i < node_count; i++) { if (node_array[i]->status != FINISHED) { all_finished=false; if (node_array[i]->status == READY) { //print_node_info(node_array[i]); printf("Running node %i...",i); run_node(node_array[i]); if (node_array[i]->return_value != 0) { printf("Node returned %d, aborting graph.\n",node_array[i]->return_value); exit(EXIT_STATUS_NODE_RETURNED_NONZERO); } printf("Done!\n"); } } } } while (!all_finished); // House-keeping free_node_array(node_array, node_count); fclose(input_file); } return 0; }
int PyRun_InteractiveOne(FILE *fp, char *filename) { PyObject *m, *d, *v, *w; node *n; perrdetail err; char *ps1 = "", *ps2 = ""; v = PySys_GetObject("ps1"); if (v != NULL) { v = PyObject_Str(v); if (v == NULL) PyErr_Clear(); else if (PyString_Check(v)) ps1 = PyString_AsString(v); } w = PySys_GetObject("ps2"); if (w != NULL) { w = PyObject_Str(w); if (w == NULL) PyErr_Clear(); else if (PyString_Check(w)) ps2 = PyString_AsString(w); } n = PyParser_ParseFile(fp, filename, &_PyParser_Grammar, Py_single_input, ps1, ps2, &err); Py_XDECREF(v); Py_XDECREF(w); if (n == NULL) { if (err.error == E_EOF) { if (err.text) PyMem_DEL(err.text); return E_EOF; } err_input(&err); PyErr_Print(); return err.error; } m = PyImport_AddModule("__main__"); if (m == NULL) return -1; d = PyModule_GetDict(m); v = run_node(n, filename, d, d); if (v == NULL) { PyErr_Print(); return -1; } Py_DECREF(v); if (Py_FlushLine()) PyErr_Clear(); return 0; }
const TypeData *TypeInferer::get_type (Node *node) { run_node (node); return node->type_; }
int run_circuit(node_t* n) { return run_node(n,n->lg2_pin_size,0,n->pins); }