char const *WebCLArguments::getInput(int argc, char const **argv, bool createOutput) { if (!areArgumentsOk(argc, argv)) return NULL; // Create output file for the next tool. if (createOutput) { int fd = -1; char const *name = createEmptyTemporaryFile(fd); if (!name) return NULL; files_.push_back(TemporaryFile(-1, name)); close(fd); outputs_.push_back(name); } return argv[1]; }
void start_group (FILE **StartFile, int ***auts, struct pga_vars *pga, struct pcp_vars *pcp) { register int *y = y_address; int retain; int ***central; *StartFile = TemporaryFile (); save_pcp (*StartFile, pcp); retain = pcp->lastg; pcp->lastg = y[pcp->clend + pcp->cc - 1]; pga->nmr_stabilisers = pga->m; pga->nmr_centrals = 0; pga->final_stage = TRUE; set_values (pga, pcp); save_pga (*StartFile, central, auts, pga, pcp); RESET(*StartFile); pcp->lastg = retain; }
const char* GetFile(const char* category, const char* extension) { tempFiles.push_back(TemporaryFile(category, extension)); return tempFiles.back().filename; }
WebCLArguments::WebCLArguments(const std::string &inputSource, int argc, char const *argv[]) : preprocessorArgc_(0) , preprocessorArgv_(NULL) , validatorArgc_(0) , validatorArgv_(NULL) , matcherArgv_() , files_() , builtinDeclFilename_(NULL) , outputs_() { int inputDescriptor = -1; char const *inputFilename = createFullTemporaryFile(inputDescriptor, &inputSource[0], inputSource.size()); if (!inputFilename) return; files_.push_back(TemporaryFile(-1, inputFilename)); close(inputDescriptor); char const *buffer = reinterpret_cast<char const*>(kernel_endlfix_cl); size_t length = kernel_endlfix_cl_len; int headerDescriptor = -1; char const *headerFilename = createFullTemporaryFile(headerDescriptor, buffer, length); if (!headerFilename) return; files_.push_back(TemporaryFile(-1, headerFilename)); close(headerDescriptor); int builtinDeclDescriptor = -1; builtinDeclFilename_ = createEmptyTemporaryFile(builtinDeclDescriptor); if (!builtinDeclFilename_) return; files_.push_back(TemporaryFile(-1, builtinDeclFilename_)); close(builtinDeclDescriptor); // TODO: add -Dcl_khr_fp16 etc definitions to preprocessor options // based on extensions passed to clvValidate() char const *preprocessorInvocation[] = { "libclv", inputFilename, "--" }; const int preprocessorInvocationSize = sizeof(preprocessorInvocation) / sizeof(preprocessorInvocation[0]); char const *preprocessorOptions[] = { "-E", "-x", "cl", "-fno-builtin", "-ffreestanding" }; const int numPreprocessorOptions = sizeof(preprocessorOptions) / sizeof(preprocessorOptions[0]); char const *validatorInvocation[] = { "libclv", NULL, "--" }; const int validatorInvocationSize = sizeof(validatorInvocation) / sizeof(validatorInvocation[0]); char const *validatorOptions[] = { "-x", "cl", "-include", headerFilename, // has to be early (provides utility macros) "-include", builtinDeclFilename_ // has to be late (uses utility macros) }; const int numValidatorOptions = sizeof(validatorOptions) / sizeof(validatorOptions[0]); std::set<char const *> userDefines; for (int i = 0; i < argc; ++i) { char const *option = argv[i]; if (!std::string(option).substr(0, 2).compare("-D")) userDefines.insert(option); } preprocessorArgc_ = preprocessorInvocationSize + userDefines.size() + numPreprocessorOptions + 1; validatorArgc_ = validatorInvocationSize + argc + numValidatorOptions + 3; preprocessorArgv_ = new char const *[preprocessorArgc_]; if (!preprocessorArgv_) { std::cerr << "Internal error. Can't create argument list for preprocessor." << std::endl; return; } validatorArgv_ = new char const *[validatorArgc_]; if (!validatorArgv_) { std::cerr << "Internal error. Can't create argument list for validator." << std::endl; return; } // preprocessor arguments std::copy(preprocessorInvocation, preprocessorInvocation + preprocessorInvocationSize, preprocessorArgv_); std::copy(userDefines.begin(), userDefines.end(), preprocessorArgv_ + preprocessorInvocationSize); std::copy(preprocessorOptions, preprocessorOptions + numPreprocessorOptions, preprocessorArgv_ + preprocessorInvocationSize + userDefines.size()); preprocessorArgv_[preprocessorArgc_ - 1] = "-ferror-limit=0"; // validator arguments std::copy(validatorInvocation, validatorInvocation + validatorInvocationSize, validatorArgv_); std::copy(argv, argv + argc, validatorArgv_ + validatorInvocationSize); std::copy(validatorOptions, validatorOptions + numValidatorOptions, validatorArgv_ + validatorInvocationSize + argc); validatorArgv_[validatorArgc_ - 1] = "-ferror-limit=0"; validatorArgv_[validatorArgc_ - 2] = "-fno-builtin"; validatorArgv_[validatorArgc_ - 3] = "-ffreestanding"; }
static int WriteTemporaryFile(const char* records) { const int fd = TemporaryFile(); write(fd, records, strlen(records)); lseek(fd, 0, SEEK_SET); return fd; }
void setup_reps (int *reps, int nmr_of_reps, int *orbit_length, int **perms, int *a, int *b, char *c, int ***auts, FILE *descendant_file, FILE *covers_file, struct pga_vars *pga, struct pcp_vars *pcp) { char *d; /* used in stabiliser computation */ FILE * tmp_file; struct pga_vars original; /* copy of pga structure */ register int i; Logical soluble_group; /* indicates that stabilisers may be computed using soluble machinery */ #ifdef HAVE_GMP MP_INT original_aut; /* copy of automorphism order */ #endif soluble_group = (pga->soluble || pga->Degree == 1 || pga->nmr_of_perms == 0); tmp_file = TemporaryFile (); save_pcp (tmp_file, pcp); if (soluble_group) { d = find_permutation (b, c, pga); if (pga->print_stabiliser_array) { printf ("The array D is \n"); print_chars (d, 1, pga->nmr_subgroups + 1); } } #ifdef HAVE_GMP /* first record current automorphism group order */ mpz_init_set (&original_aut, &pga->aut_order); mpz_clear (&pga->aut_order); #endif /* keep copy of pga */ original = *pga; #ifdef HAVE_GMP /* now reset automorphism order in pga */ mpz_init_set (&pga->aut_order, &original_aut); #endif for (i = 1; i <= nmr_of_reps; ++i) { pga->fixed = pga->s; if (pga->final_stage) { ++original.nmr_of_descendants; update_name (pcp->ident, original.nmr_of_descendants, pga->s); } process_rep (perms, a, b, c, d, auts, reps[i], orbit_length[i], tmp_file, descendant_file, covers_file, pga, pcp); if (pga->final_stage && pga->capable) { ++original.nmr_of_capables; if (pga->trace) printf ("Capable group #%d\n", original.nmr_of_capables); } /* revert to original pga structure */ if (!StandardPresentation) { #ifdef HAVE_GMP mpz_clear (&pga->aut_order); #endif *pga = original; #ifdef HAVE_GMP mpz_init_set (&pga->aut_order, &original_aut); #endif } } if (soluble_group) free (++d); #ifdef HAVE_GMP mpz_clear (&original_aut); #endif CloseFile (tmp_file); }
WebCLArguments::WebCLArguments(int argc, char const *argv[]) : preprocessorArgc_(0) , preprocessorArgv_(NULL) , validatorArgc_(0) , validatorArgv_(NULL) , matcherArgv_() , files_() , outputs_() { char const *commandName = argv[0]; char const *inputFilename = argv[1]; const int userOptionOffset = 2; const int numUserOptions = argc - userOptionOffset; assert((argc >= userOptionOffset) && "Expected at least executable name and input file in argv."); char const *buffer = reinterpret_cast<char const*>(kernel_endlfix_cl); size_t length = kernel_endlfix_cl_len; int headerDescriptor = -1; char const *headerFilename = createFullTemporaryFile(headerDescriptor, buffer, length); if (!headerFilename) return; files_.push_back(TemporaryFile(-1, headerFilename)); close(headerDescriptor); char const *preprocessorInvocation[] = { commandName, inputFilename, "--" }; const int preprocessorInvocationSize = sizeof(preprocessorInvocation) / sizeof(preprocessorInvocation[0]); char const *preprocessorOptions[] = { "-E", "-x", "cl" }; const int numPreprocessorOptions = sizeof(preprocessorOptions) / sizeof(preprocessorOptions[0]); char const *validatorInvocation[] = { commandName, NULL, "--" }; const int validatorInvocationSize = sizeof(validatorInvocation) / sizeof(validatorInvocation[0]); char const *validatorOptions[] = { "-x", "cl", "-ffake-address-space-map", "-include", headerFilename }; const int numValidatorOptions = sizeof(validatorOptions) / sizeof(validatorOptions[0]); preprocessorArgc_ = preprocessorInvocationSize + numPreprocessorOptions; validatorArgc_ = validatorInvocationSize + numUserOptions + numValidatorOptions; preprocessorArgv_ = new char const *[preprocessorArgc_]; if (!preprocessorArgv_) { std::cerr << "Internal error. Can't create argument list for preprocessor." << std::endl; return; } validatorArgv_ = new char const *[validatorArgc_]; if (!validatorArgv_) { std::cerr << "Internal error. Can't create argument list for validator." << std::endl; return; } // preprocessor arguments std::copy(preprocessorInvocation, preprocessorInvocation + preprocessorInvocationSize, preprocessorArgv_); std::copy(preprocessorOptions, preprocessorOptions + numPreprocessorOptions, preprocessorArgv_ + preprocessorInvocationSize); // validator arguments std::copy(validatorInvocation, validatorInvocation + validatorInvocationSize, validatorArgv_); std::copy(argv + userOptionOffset, argv + userOptionOffset + numUserOptions, validatorArgv_ + validatorInvocationSize); std::copy(validatorOptions, validatorOptions + numValidatorOptions, validatorArgv_ + validatorInvocationSize + numUserOptions); }