/** * Main * Calling with no arguments should return a service description string that the server can parse and use to advertise the service. * @param argc argument count * @param argv argument array * @return boolean success or failure */ int main( int argc, const char* argv[] ) { char* functionName; functionName = parse_function_name(argv[0]); char returnType[] = "arr"; int numArgs = 3; // No args. if( argc < 2 ) { //get the function name from the filepath printf("SERVICE/INFO&%s,%d,%s\n", functionName, numArgs, returnType); return 0; } else if( argc != (numArgs+1)) { printf("SERVICE/MISMATCH&%d\nSERVICE/INFO&%s,%d,%s\n", (argc - 1), functionName, numArgs, returnType); return 0; } else { printf("SERVICE/RESULT&arr&1&42\n"); return 0; } }
bool DDDG::build_initial_dddg(gzFile trace_file) { std::cerr << "-------------------------------" << std::endl; std::cerr << " Generating DDDG " << std::endl; std::cerr << "-------------------------------" << std::endl; char buffer[256]; std::string first_function; bool seen_first_line = false; bool first_function_returned = false; while (trace_file && !gzeof(trace_file)) { if (gzgets(trace_file, buffer, sizeof(buffer)) == NULL) { continue; } std::string wholeline(buffer); size_t pos_end_tag = wholeline.find(","); if (pos_end_tag == std::string::npos) { if (first_function_returned) break; continue; } std::string tag = wholeline.substr(0, pos_end_tag); std::string line_left = wholeline.substr(pos_end_tag + 1); if (tag.compare("0") == 0) { if (!seen_first_line) { seen_first_line = true; first_function = parse_function_name(line_left); } first_function_returned = is_function_returned(line_left, first_function); parse_instruction_line(line_left); } else if (tag.compare("r") == 0) { parse_result(line_left); } else if (tag.compare("f") == 0) { parse_forward(line_left); } else { parse_parameter(line_left, atoi(tag.c_str())); } } output_dddg(); std::cerr << "-------------------------------" << std::endl; std::cerr << "Num of Nodes: " << datapath->getNumOfNodes() << std::endl; std::cerr << "Num of Edges: " << datapath->getNumOfEdges() << std::endl; std::cerr << "Num of Reg Edges: " << num_of_register_dependency() << std::endl; std::cerr << "Num of MEM Edges: " << num_of_memory_dependency() << std::endl; std::cerr << "-------------------------------" << std::endl; return 0; }
result_type operator() (stream_type& strm, value_type const& value) const { if (value.type == attributes::named_scope_entry::function) { const char* begin = value.scope_name.c_str(); const char* end = begin + value.scope_name.size(); if (parse_function_name(begin, end, m_include_scope)) { strm.write(begin, end - begin); return; } } strm << value.scope_name; }
/** * Main * Calling with no arguments should return a service description string that the server can parse and use to advertise the service. * @param argc argument count * @param argv argument array * @return boolean success or failure */ int main( int argc, const char* argv[] ) { char* functionName; functionName = parse_function_name(argv[0]); char returnType[] = "arr"; int numArgs = 2; // No args. if( argc < 2 ) { //get the function name from the filepath printf("SERVICE/INFO&%s,%d,%s\n", functionName, numArgs, returnType); return 0; } else if( argc != (numArgs+1)) { printf("SERVICE/MISMATCH&%d\nSERVICE/INFO&%s,%d,%s\n", (argc - 1), functionName, numArgs, returnType); return 0; } else { char outputBuffer[1024]; memset(outputBuffer, '\0', sizeof(outputBuffer)); char resultHeader[255]; char curVal[10]; int start = atoi(argv[1]); int end = atoi(argv[2]); int range = end - start; int curFib = 0; int prevFib = 0; int prevFib2 = 0; int i = 0; int fibCount = 0; while(curFib < end) { if(i < 2) { prevFib2 = prevFib; prevFib = curFib; curFib = i; } else { prevFib2 = prevFib; prevFib = curFib; curFib = prevFib + prevFib2; } if( (curFib > start) && (curFib < end) ) { sprintf(curVal, "%d,", curFib); strcat(outputBuffer, curVal); fibCount++; } i++; } outputBuffer[ (strlen(outputBuffer)-1) ] = '\0'; sprintf(resultHeader, "SERVICE/RESULT&arr&%d&", fibCount); printf("%s%s\n", resultHeader, outputBuffer); return 0; } }
Machine::Machine(const ExpressionEngine::Specification &spec, const char *source) { // Set up the registers const size_t temp_register_count = 10; registers.resize(spec.registers.size() + temp_register_count); program.reserve(64); // Parse the program while (*source) { Instruction i; // Skip whitespace while (*source && (*source == ' ' || *source == '\t' || *source == '\n' || *source == '\r')) source++; if (!*source) break; // First see if it can be read as a number constant { char *tmp = 0; double v = strtod(source, &tmp); if (tmp && source != tmp) { // Could be read, so we have a constant here source = tmp; i.op = INST_PUSH_CONST; i.vd = v; program.push_back(i); continue; } } // Not a number constant // Check for arithmetic operator if (*source == '+') { source++; i.op = INST_ADD; program.push_back(i); } else if (*source == '-') { source++; i.op = INST_SUB; program.push_back(i); } else if (*source == '*') { source++; i.op = INST_MUL; program.push_back(i); } else if (*source == '/') { source++; i.op = INST_DIV; program.push_back(i); } else if (*source == '^') { source++; i.op = INST_POW; program.push_back(i); } else if (*source == '~') { source++; i.op = INST_UNM; program.push_back(i); } // Check for assignment else if (*source == '=') { i.op = INST_STORE; const char *tmp = parse_register_name(source+1, spec.registers, i.vu); if (!tmp) throw source; // No register name found, error source = tmp; program.push_back(i); } // Register push or function call else { const char *tmp = parse_register_name(source, spec.registers, i.vu); if (tmp) { // Register push i.op = INST_PUSH_REG; source = tmp; program.push_back(i); } else { tmp = parse_function_name(source, spec.functions, i.vf, i.vfd); if (tmp) { // Function call i.op = INST_CALL; source = tmp; program.push_back(i); } else { // Nothing, error throw source; } } } } /* end while */ } /* end Machine::Machine() */