Esempio n. 1
0
ChunkFile::ChunkFile(const char *filename, bool _read) {
	data=0;
	fn = filename;
	numLevels=0;
	read=_read;
	pos=0;
	didFail=false;

	fastMode = read ? true : false;

	if (fastMode) {
		size_t size;
		data = (uint8_t *)VFSReadFile(filename, &size);
		if (!data) {
			ELOG("Chunkfile fail: %s", filename);
			didFail = true;
			return;
		}
		eof = (int)size;
		return;
	}

	file = openCFile(filename, "wb");
	if (file) {
		didFail = false;
		eof = 0;
	}	else {
		didFail = true;
	}
}
Esempio n. 2
0
// The return is non-const because - why not?
uint8_t *ReadLocalFile(const char *filename, size_t *size) {
	FILE *file = openCFile(filename, "rb");
	if (!file) {
		*size = 0;
		return nullptr;
	}
	fseek(file, 0, SEEK_END);
	size_t f_size = ftell(file);
	if ((long)f_size < 0) {
		*size = 0;
		fclose(file);
		return nullptr;
	}
	fseek(file, 0, SEEK_SET);
	uint8_t *contents = new uint8_t[f_size+1];
	if (fread(contents, 1, f_size, file) != f_size) {
		delete [] contents;
		contents = nullptr;
		*size = 0;
	} else {
		contents[f_size] = 0;
		*size = f_size;
	}
	fclose(file);
	return contents;
}
Esempio n. 3
0
void codegen_makefile(fileinfo* mainfile, const char** tmpbinname, bool skip_compile_link) {
  fileinfo makefile;
  openCFile(&makefile, "Makefile");
  const char* tmpDirName = intDirName;
  const char* strippedExeFilename = stripdirectories(executableFilename);
  const char* exeExt = "";
  const char* tmpbin = "";

  fprintf(makefile.fptr, "CHPL_MAKE_HOME = %s\n\n", CHPL_HOME);
  fprintf(makefile.fptr, "TMPDIRNAME = %s\n", tmpDirName);

  // LLVM builds just use the makefile for the launcher and
  // so want to skip the actual program generation.
  if( skip_compile_link ) {
    fprintf(makefile.fptr, "SKIP_COMPILE_LINK = skip\n");
  }

  if (fLibraryCompile) {
    if (fLinkStyle==LS_DYNAMIC) exeExt = ".so";
    else exeExt = ".a";
  }
  fprintf(makefile.fptr, "BINNAME = %s%s\n\n", executableFilename, exeExt);
  // BLC: This munging is done so that cp won't complain if the source
  // and destination are the same file (e.g., a.out and ./a.out)
  tmpbin = astr(tmpDirName, "/", strippedExeFilename, ".tmp", exeExt);
  if( tmpbinname ) *tmpbinname = tmpbin;
  fprintf(makefile.fptr, "TMPBINNAME = %s\n", tmpbin);
  // BLC: We generate a TMPBINNAME which is the name that will be used
  // by the C compiler in creating the executable, and is in the
  // --savec directory (a /tmp directory by default).  We then copy it
  // over to BINNAME -- the name given by the user, or a.out by
  // default -- after linking is done.  As it turns out, this saves a
  // factor of 5 or so in time in running the test system, as opposed
  // to specifying BINNAME on the C compiler command line.

  fprintf(makefile.fptr, "COMP_GEN_CFLAGS =");
  if (ccwarnings) {
    fprintf(makefile.fptr, " $(WARN_GEN_CFLAGS)");
  }
  if (debugCCode) {
    fprintf(makefile.fptr, " $(DEBUG_CFLAGS)");
  }
  if (optimizeCCode) {
    fprintf(makefile.fptr, " $(OPT_CFLAGS)");
  }
  if (specializeCCode) {
    fprintf(makefile.fptr, " $(SPECIALIZE_CFLAGS)");
  }
  if (fieeefloat) {
    fprintf(makefile.fptr, " $(IEEE_FLOAT_GEN_CFLAGS)");
  } else {
    fprintf(makefile.fptr, " $(NO_IEEE_FLOAT_GEN_CFLAGS)");
  }
  if (fLibraryCompile && (fLinkStyle==LS_DYNAMIC))
    fprintf(makefile.fptr, " $(SHARED_LIB_CFLAGS)");
  forv_Vec(const char*, dirName, incDirs) {
    fprintf(makefile.fptr, " -I%s", dirName);
  }
Esempio n. 4
0
bool readFileToString(bool text_file, const char *filename, std::string &str)
{
    FILE *f = openCFile(filename, text_file ? "r" : "rb");
    if (!f)
        return false;
    size_t len = (size_t)GetSize(f);
    char *buf = new char[len + 1];
    buf[fread(buf, 1, len, f)] = 0;
    str = std::string(buf, len);
    fclose(f);
    delete [] buf;
    return true;
}
Esempio n. 5
0
bool writeDataToFile(bool text_file, const void* data, const unsigned int size, const char *filename)
{
    FILE *f = openCFile(filename, text_file ? "w" : "wb");
    if (!f)
        return false;
    size_t len = size;
    if (len != fwrite(data, 1, len, f))
    {
        fclose(f);
        return false;
    }
    fclose(f);
    return true;
}
Esempio n. 6
0
bool writeStringToFile(bool text_file, const std::string &str, const char *filename)
{
    FILE *f = openCFile(filename, text_file ? "w" : "wb");
    if (!f)
        return false;
    size_t len = str.size();
    if (len != fwrite(str.data(), 1, str.size(), f))
    {
        fclose(f);
        return false;
    }
    fclose(f);
    return true;
}
Esempio n. 7
0
bool readDataFromFile(bool text_file, unsigned char* &data, const unsigned int size, const char *filename)
{
    FILE *f = openCFile(filename, text_file ? "r" : "rb");
    if (!f)
        return false;
    size_t len = (size_t)GetSize(f);
    if(len < size) {
        fclose(f);
        return false;
    }
    data[fread(data, 1, size, f)] = 0;
    fclose(f);
    return true;
}
Esempio n. 8
0
void codegen_makefile(fileinfo* mainfile, const char** tmpbinname, bool skip_compile_link, const std::vector<const char*>& splitFiles) {
  fileinfo makefile;
  openCFile(&makefile, "Makefile");
  const char* tmpDirName = intDirName;
  const char* strippedExeFilename = stripdirectories(executableFilename);
  const char* exeExt = "";
  const char* tmpbin = "";
  std::string chplmakeallvars = "\0";


  fprintf(makefile.fptr, "CHPL_MAKE_HOME = %s\n\n", CHPL_HOME);
  fprintf(makefile.fptr, "CHPL_MAKE_RUNTIME_LIB = %s\n\n", CHPL_RUNTIME_LIB);
  fprintf(makefile.fptr, "CHPL_MAKE_RUNTIME_INCL = %s\n\n", CHPL_RUNTIME_INCL);
  fprintf(makefile.fptr, "CHPL_MAKE_THIRD_PARTY = %s\n\n", CHPL_THIRD_PARTY);
  fprintf(makefile.fptr, "TMPDIRNAME = %s\n\n", tmpDirName);

  // Generate one variable containing all envMap information to pass to printchplenv
  for (std::map<std::string, const char*>::iterator env=envMap.begin(); env!=envMap.end(); ++env)
  {
    const std::string& key = env->first;
    const char* oldPrefix = "CHPL_";
    const char* newPrefix = "CHPL_MAKE_";
    INT_ASSERT(key.substr(0, strlen(oldPrefix)) == oldPrefix);
    std::string keySuffix = key.substr(strlen(oldPrefix), std::string::npos);
    std::string chpl_make_key = newPrefix + keySuffix;
    chplmakeallvars += chpl_make_key + "=" + std::string(env->second) + "|";
  }

  fprintf(makefile.fptr, "\nexport CHPL_MAKE_SETTINGS_NO_NEWLINES := %s\n", chplmakeallvars.c_str());


  // LLVM builds just use the makefile for the launcher and
  // so want to skip the actual program generation.
  if( skip_compile_link ) {
    fprintf(makefile.fptr, "SKIP_COMPILE_LINK = skip\n");
  }

  if (fLibraryCompile) {
    if (fLinkStyle==LS_DYNAMIC) exeExt = ".so";
    else exeExt = ".a";
  }
  fprintf(makefile.fptr, "BINNAME = %s%s\n\n", executableFilename, exeExt);
  // BLC: This munging is done so that cp won't complain if the source
  // and destination are the same file (e.g., myprogram and ./myprogram)
  tmpbin = astr(tmpDirName, "/", strippedExeFilename, ".tmp", exeExt);
  if( tmpbinname ) *tmpbinname = tmpbin;
  fprintf(makefile.fptr, "TMPBINNAME = %s\n", tmpbin);
  // BLC: We generate a TMPBINNAME which is the name that will be used
  // by the C compiler in creating the executable, and is in the
  // --savec directory (a /tmp directory by default).  We then copy it
  // over to BINNAME -- the name given by the user/default module's filename
  // -- after linking is done.  As it turns out, this saves a
  // factor of 5 or so in time in running the test system, as opposed
  // to specifying BINNAME on the C compiler command line.

  fprintf(makefile.fptr, "COMP_GEN_WARN = %i\n", ccwarnings);
  fprintf(makefile.fptr, "COMP_GEN_DEBUG = %i\n", debugCCode);
  fprintf(makefile.fptr, "COMP_GEN_OPT = %i\n", optimizeCCode);
  fprintf(makefile.fptr, "COMP_GEN_SPECIALIZE = %i\n", specializeCCode);
  fprintf(makefile.fptr, "COMP_GEN_FLOAT_OPT = %i\n", ffloatOpt);

  fprintf(makefile.fptr, "COMP_GEN_USER_CFLAGS =");

  if (fLibraryCompile && (fLinkStyle==LS_DYNAMIC))
    fprintf(makefile.fptr, " $(SHARED_LIB_CFLAGS)");
  for_vector(const char, dirName, incDirs) {
    fprintf(makefile.fptr, " -I%s", dirName);
  }
Esempio n. 9
0
void codegen_makefile(fileinfo* mainfile, const char** tmpbinname,
                      bool skip_compile_link,
                      const std::vector<const char*>& splitFiles) {
  const char* tmpDirName = intDirName;
  const char* strippedExeFilename = stripdirectories(executableFilename);
  const char* exeExt = getLibraryExtension();
  const char* server = "";
  const char* tmpserver = "";
  const char* tmpbin = "";
  bool startsWithLib = !strncmp(executableFilename, "lib", 3);
  bool dyn = (fLinkStyle == LS_DYNAMIC);
  std::string makeallvars;
  fileinfo makefile;

  openCFile(&makefile, "Makefile");

  // Capture different compiler directories.
  fprintf(makefile.fptr, "CHPL_MAKE_HOME = %s\n\n", CHPL_HOME);
  fprintf(makefile.fptr, "CHPL_MAKE_RUNTIME_LIB = %s\n\n", CHPL_RUNTIME_LIB);
  fprintf(makefile.fptr, "CHPL_MAKE_RUNTIME_INCL = %s\n\n", CHPL_RUNTIME_INCL);
  fprintf(makefile.fptr, "CHPL_MAKE_THIRD_PARTY = %s\n\n", CHPL_THIRD_PARTY);
  fprintf(makefile.fptr, "TMPDIRNAME = %s\n\n", tmpDirName);

  // Store chapel environment variables in a cache.
  makeallvars = genMakefileEnvCache();
  fprintf(makefile.fptr, "export CHPL_MAKE_CHPLENV_CACHE := %s\n\n",
          makeallvars.c_str());

  //
  // LLVM builds just use the makefile for the launcher and so want to skip
  // the actual program generation.
  //
  if (skip_compile_link) {
    fprintf(makefile.fptr, "SKIP_COMPILE_LINK = skip\n");
  }

  //
  // In --library compilation, put the generated library in the library
  // directory.
  //
  if (fLibraryCompile) {

    ensureLibDirExists();
    fprintf(makefile.fptr, "BINNAME = %s/", libDir);
    if (!startsWithLib) { fprintf(makefile.fptr, "lib"); }
    fprintf(makefile.fptr, "%s%s\n\n", executableFilename, exeExt);

    //
    // Now that the client and launcher are merged, the server name becomes
    // the name of the library without any extension. We munge the server
    // name with a trailing underscore just to guarantee that it's different
    // from the file name.
    //
    if (fMultiLocaleInterop) {
      server = astr(executableFilename, "_server");
      fprintf(makefile.fptr, "SERVERNAME = %s\n\n", server);
    }

  } else {
    fprintf(makefile.fptr, "BINNAME = %s%s\n\n", executableFilename, exeExt);
  }

  //
  // BLC: This munging is done so that cp won't complain if the source
  // and destination are the same file (e.g., myprogram and ./myprogram).
  //
  if (fLibraryCompile) {
    const char* pfx = startsWithLib ? "/" : "/lib";
    tmpbin = astr(tmpDirName, pfx, strippedExeFilename, ".tmp", exeExt);

    if (fMultiLocaleInterop) {
      tmpserver = astr(tmpDirName, "/", strippedExeFilename, "_server");
    }
  } else {
    tmpbin = astr(tmpDirName, "/", strippedExeFilename, ".tmp", exeExt);
  }

  // Write out the temporary filename to the caller if necessary.
  if (tmpbinname) { *tmpbinname = tmpbin; }

  //
  // BLC: We generate a TMPBINNAME which is the name that will be used
  // by the C compiler in creating the executable, and is in the
  // --savec directory (a /tmp directory by default).  We then copy it
  // over to BINNAME -- the name given by the user/default module's filename
  // -- after linking is done.  As it turns out, this saves a
  // factor of 5 or so in time in running the test system, as opposed
  // to specifying BINNAME on the C compiler command line.
  //
  fprintf(makefile.fptr, "TMPBINNAME = %s\n", tmpbin);

  if (fMultiLocaleInterop) {
    fprintf(makefile.fptr, "TMPSERVERNAME = %s\n\n", tmpserver);
  }

  // Bunch of C compiler flags.
  fprintf(makefile.fptr, "COMP_GEN_WARN = %i\n", ccwarnings);
  fprintf(makefile.fptr, "COMP_GEN_DEBUG = %i\n", debugCCode);
  fprintf(makefile.fptr, "COMP_GEN_OPT = %i\n", optimizeCCode);
  fprintf(makefile.fptr, "COMP_GEN_SPECIALIZE = %i\n", specializeCCode);
  fprintf(makefile.fptr, "COMP_GEN_FLOAT_OPT = %i\n", ffloatOpt);

  if (fMultiLocaleInterop) {
    const char* loc = "$(CHPL_MAKE_HOME)/runtime/etc/src";
    fprintf(makefile.fptr, "COMP_GEN_MLI_EXTRA_INCLUDES = -I%s\n", loc);
  }
  
  // Build a string out of include directories, for convenience.
  std::string includedirs;
  for_vector(const char, dirName, incDirs) {
    includedirs += " -I";
    includedirs += dirName;
  }