예제 #1
0
int main(int argc, char* argv[]) {
	if (argc < 4 || argc > 6) {
		std::cout << "Usage: embedfile [-wx] [-text] <inout> <output> <fieldname>" << std::endl;

		return error_invalidargs;
	}

	bool wxWidgets_image = false;
	bool text_content = false;

	int argc_offset = 1;

	if (casecmp(argv[argc_offset], "-wx")) {
		wxWidgets_image = true;

		argc_offset++;
	}

	if (casecmp(argv[argc_offset], "-text")) {
		text_content = true;

		argc_offset++;
	}

	std::string input_file(argv[argc_offset]);
	std::string output_basename(argv[argc_offset + 1]);
	std::string field_name(argv[argc_offset + 2]);

	std::ios::openmode mode = std::ios::in;
	if (!text_content) {
		mode |= std::ios::binary;
	}

	std::ifstream file_in(input_file.c_str(), mode);
	if (file_in.bad()) {
		std::cout << "ERROR: Error opening input file: " << input_file << std::endl;
		return error_cantopenfile;
	}

	// Get the size of the input stream
	size_t input_size;
	file_in.seekg(0, std::ios::end);

	if ((int) file_in.tellg() != -1) {
		input_size = (size_t) file_in.tellg();
	}
	else {
		std::cout << "ERROR: Failed to get size of input file: " << input_file << std::endl;
		file_in.close();
		return error_ioerror;
	}

	file_in.seekg(0, std::ios::beg);

	// Generates two files, one header and one source file
	std::string headerName = output_basename + ".h";
	std::string sourceName = output_basename + ".cpp";

	std::ofstream source_out(sourceName.c_str());
	if (source_out.bad()) {
		std::cout << "ERROR: Error opening output file: " << sourceName << std::endl;
		return error_cantoutputfile;
	}

	std::ofstream header_out(headerName.c_str());
	if (header_out.bad()) {
		std::cout << "ERROR: Error opening output file: " << headerName << std::endl;
		return error_cantoutputfile;
	}

	if (text_content) {
		do_text_content(file_in, source_out, field_name, input_size);
	}
	else {
		do_binary_content(file_in, source_out, field_name, input_size, wxWidgets_image);
	}

	write_header(header_out, field_name, text_content, wxWidgets_image);

	file_in.close();

	source_out.close();
	header_out.close();

	return error_none;
}
예제 #2
0
  void ISPCATBuilder::processCFG(WorkSpace *ws, CFG *cfg) {
    ISPProblem problem(_isp_size);
    DefaultListener<ISPProblem> listener(ws, problem,true);
    DefaultFixPoint<DefaultListener<ISPProblem> > fixpoint(listener);
    HalfAbsInt<DefaultFixPoint<DefaultListener<ISPProblem> > > halfabsint(fixpoint, *ws);
    halfabsint.solve();
	
    for(CFG::BBIterator bb(cfg); bb; bb++) {
      if (bb->isEntry() || bb->isExit())
	continue;
      FunctionBlock *fb = FUNCTION_BLOCK(bb);
      if (fb) {
	ISPProblem::Domain dom(*listener.results[cfg->number()][bb->number()]); 
	bool may, must;
	dom.contains(fb, &may, &must);
	
	if (must) {
	  ISP_CATEGORY(bb) = ISP_ALWAYS_HIT;
	} 
	else {
	  if (!may) {
	    ISP_CATEGORY(bb) = ISP_ALWAYS_MISS;
	  } 
	  else {
	    BasicBlock *pers_header = NULL;
	    BasicBlock *loop_header = ENCLOSING_LOOP_HEADER(bb);
 	    while (loop_header){
	      bool pers_entering, pers_back = true;
 	      for (BasicBlock::InIterator edge(loop_header) ; edge && pers_back; edge++){
		BasicBlock * source = edge->source();
		ISPProblem::Domain source_out(*listener.results_out[cfg->number()][source->number()]); 
		bool pers_may, pers_must;
		source_out.contains(fb, &pers_may, &pers_must);
 		if (!Dominance::isBackEdge(edge)){  // edge thats enters the loop
		  pers_entering = pers_must;
		}
		else { // backedge
		  if (!pers_must)
		    pers_back = false;
		}
	      }
	      if (pers_back){
		pers_header = loop_header;
		if (pers_entering)
		  loop_header = ENCLOSING_LOOP_HEADER(loop_header);
		else
		  loop_header = NULL;
	      }
	      else
		loop_header = NULL;
	    }
		  
	    if (pers_header){
	      ISP_CATEGORY(bb) = ISP_PERSISTENT; 
	      ISP_HEADER(bb) = pers_header;
	    }
	    else
	      ISP_CATEGORY(bb) = ISP_NOT_CLASSIFIED; 
	  }
	}
      }
    }
  }
예제 #3
0
파일: clc.cpp 프로젝트: greyhill/libghp
int main(int argc, char *argv[]) {
  namespace po = boost::program_options;
  namespace fs = boost::filesystem;

  po::options_description desc("Allowed options");
  desc.add_options()
      ("input,i", po::value<std::string>(), "input file")
      ("output,o", po::value<std::string>(), "output file")
      ("cpp,x", "produce cpp/header file on successful compilation")
      ("platform,p", po::value<unsigned>(), "set platform")
      ("device,d", po::value<unsigned>(), "set device")
      ("options,c", po::value<std::string>(), "compile options")
      ("help,h", "print this help message")
      ("list,l", "list platforms and devices");

  po::positional_options_description pos;
  pos.add("input", 1);
  pos.add("output", 1);

  po::variables_map vm;
  try {
    po::store(
        po::command_line_parser(argc, argv).options(desc)
            .positional(pos).run(), vm);
  } catch(std::exception &e) {
    std::cerr << "options parsing error.\n" << desc << std::endl;
    return EXIT_FAILURE;
  }
  po::notify(vm);

  if(vm.count("help")) {
    std::cout << desc << std::endl;
    return EXIT_FAILURE;
  }

  if(vm.count("list")) {
    std::cout << "Accessible platforms:\n";
    std::vector<cl::platform_ref> platforms;
    cl::platform_ref::get_platforms(platforms);
    for(unsigned i=0; i<platforms.size(); ++i) {
      cl::platform_ref p = platforms[i];
      std::cout << i << ") " << p.name() << "\n";

      std::cout << "\tAssociated devices:\n";
      std::vector<cl::device_ref> devices;
      p.get_devices(devices);
      for(unsigned j=0; j<devices.size(); ++j) {
        cl::device_ref d = devices[j];
        std::cout << "\t" << j << ") " << d.name() << "\n";
      }
    }
    return EXIT_SUCCESS;
  }

  std::string input_path;
  std::string output_path;
  std::string options;
  bool do_output = false;
  unsigned platform_id = 0;
  unsigned device_id = 0;

  if(vm.count("input")) {
    input_path = vm["input"].as<std::string>();
  } else {
    std::cout << "must provide input file.\n";
    return EXIT_FAILURE;
  }
  if(vm.count("output")) {
    output_path = vm["output"].as<std::string>();
    do_output = true;
  }
  if(vm.count("platform")) {
    platform_id = vm["platform"].as<unsigned>();
  }
  if(vm.count("device")) {
    device_id = vm["device"].as<unsigned>();
  }
  if(vm.count("options")) {
    options = vm["options"].as<std::string>();
  }

  std::stringstream ss;
  std::ifstream in(input_path.c_str());
  std::string line;
  while(std::getline(in, line)) {
    ss << line << "\n";
  }

  std::vector<cl::platform_ref> platforms;
  std::vector<cl::device_ref> devices;
  cl::platform_ref::get_platforms(platforms);

  if(platform_id >= platforms.size()) {
    std::cerr << "invalid platform id\n";
    return EXIT_FAILURE;
  }
  cl::platform_ref platform = platforms[platform_id];
  platform.get_devices(devices);

  if(device_id >= devices.size()) {
    std::cerr << "invalid device id\n";
    return EXIT_FAILURE;
  }
  cl::device_ref device = devices[device_id];

  cl::context_ref context(platform, device);
  cl::program_ref program(context, ss.str());
  std::cout << "context is " << platform.name() << "/"
    << device.name() << "\n";
  std::cout << "OpenCL compiler options: " << options << "\n";
  try {
    program.build(options);
    std::cout << "build successful!\n";

    if(vm.count("cpp")) {
      fs::path input_path_obj(input_path);
      // older versions of boost don't have this method
      //std::string file_base = input_path_obj.stem();
      std::size_t start = input_path.find_last_of('/');
      if(start == std::string::npos) {
        start = 0;
      } else {
        ++start;
      }
      std::string file_base = input_path.substr(start, 
          input_path.find_last_of('.')-start);
      std::string file_base_upper = file_base;
      boost::to_upper(file_base_upper);
  
      // write header
      std::stringstream filess;
      filess << input_path << ".hpp";
      std::ofstream header_out(filess.str().c_str());
      filess.str("");
      filess << "#ifndef _" << file_base_upper << "_OPENCL_HPP_" << "\n";
      filess << "#define _" << file_base_upper << "_OPENCL_HPP_" << "\n";
      filess << "\n";
      filess << "extern const char *" << file_base << "_opencl_source;" << "\n";
      filess << "\n";
      filess << "#endif\n\n";
      header_out << filess.str();
      header_out.close();
  
      // write cpp file
      boost::regex rx;
      rx.assign(
        "(\\\\)|"
        "(\")");
      const char *format = 
        "(?1\\\\\\\\)"
        "(?2\\\\\")";

      filess.str("");
      filess << input_path << ".cpp";
      std::ofstream source_out(filess.str().c_str());
      std::ifstream source_in(input_path.c_str());
      filess.str("");
      filess << "const char *" << file_base << "_opencl_source = " << "\n";
      while(getline(source_in, line)) {
        std::string sanitized_line = 
          boost::regex_replace(line, rx, format, 
            boost::match_default | boost::format_all);
        filess << "\t\"" << sanitized_line << "\\n\"\n";
      }
      filess << ";";
      source_out << filess.str();
      source_out.close();
    }
  } catch(const cl::cl_error &c) {
    std::cout << "error building program\n";
  }

  std::cout << "build log:\n" << program.get_build_log(device)
    << "\n";

  return EXIT_SUCCESS;
}