Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
Signed-off-by: Anna Rift <[email protected]>
  • Loading branch information
riftEmber committed Dec 3, 2024
1 parent cacfa54 commit 221742b
Show file tree
Hide file tree
Showing 11 changed files with 49 additions and 48 deletions.
2 changes: 1 addition & 1 deletion compiler/AST/AstDump.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ bool AstDump::open(const ModuleSymbol* module, const char* passName, int passNum
snprintf(numBuf, 4, "%02d", passNum);

mName = astr(module->name, "_", numBuf, passName, ".ast");
mPath = astr(log_dir, mName);
mPath = astr(log_dir.c_str(), mName);
mFP = fopen(mPath, "w");
mIndent = 0;
mNeedSpace = false;
Expand Down
7 changes: 4 additions & 3 deletions compiler/AST/AstDumpToHtml.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,9 @@ AstDumpToHtml::~AstDumpToHtml() {
}

void AstDumpToHtml::init() {
if (!(sIndexFP = fopen(astr(log_dir, "index.html"), "w"))) {
USR_FATAL("cannot open html index file \"%s\" for writing", astr(log_dir, "index.html"));
if (!(sIndexFP = fopen(astr(log_dir.c_str(), "index.html"), "w"))) {
USR_FATAL("cannot open html index file \"%s\" for writing",
astr(log_dir.c_str(), "index.html"));
}

fprintf(sIndexFP, "<HTML>\n");
Expand Down Expand Up @@ -118,7 +119,7 @@ void AstDumpToHtml::view(const char* passName) {

bool AstDumpToHtml::open(ModuleSymbol* module, const char* passName) {
const char* name = html_file_name(sPassIndex, module->name);
const char* path = astr(log_dir, name);
const char* path = astr(log_dir.c_str(), name);

mFP = fopen(path, "w");

Expand Down
6 changes: 3 additions & 3 deletions compiler/codegen/codegen.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2266,15 +2266,15 @@ static const char* generateFileName(ChainHashMap<char*, StringHashFns, int>& fil
// with case-insensitivity taken into account

// create the lowercase filename
char lowerFilename[FILENAME_MAX];
std::string lowerFilename;
snprintf(lowerFilename, sizeof(lowerFilename), "%s", currentModuleName);
for (unsigned int i=0; i<strlen(lowerFilename); i++) {
lowerFilename[i] = tolower(lowerFilename[i]);
}

// create a filename by bumping a version number until we get a
// filename we haven't seen before
char filename[FILENAME_MAX];
std::string filename;
snprintf(filename, sizeof(filename), "%s", lowerFilename);
int version = 1;
while (filenames.get(filename)) {
Expand Down Expand Up @@ -3143,7 +3143,7 @@ static void codegenPartTwo() {
filename = generateFileName(fileNameHashMap, filename, currentModule->name);
openCFile(&modulefile, filename, "c");
int modulePathLen = strlen(astr(modulefile.pathname));
char path[FILENAME_MAX];
std::string path;
strncpy(path, astr(modulefile.pathname), modulePathLen-2);
path[modulePathLen-2]='\0';
userFileName.push_back(astr(path));
Expand Down
8 changes: 4 additions & 4 deletions compiler/codegen/library.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@

std::map<Symbol*, TypeSymbol*> exportedArrayElementType;

char libDir[FILENAME_MAX + 1] = "";
std::string libDir;
std::string pxdName = "";

// TypeSymbol -> (pxdName, pyxName) Will be "" if the cname should be used
Expand Down Expand Up @@ -428,11 +428,11 @@ void ensureLibDirExists() {
}

void
openLibraryHelperFile(fileinfo* fi, const char* name, const char* ext) {
openLibraryHelperFile(fileinfo* fi, std::string name, const char* ext) {
if (ext)
fi->filename = astr(name, ".", ext);
fi->filename = astr(name.c_str(), ".", ext);
else
fi->filename = astr(name);
fi->filename = astr(name.c_str());

ensureLibDirExists();
fi->pathname = astr(libDir, "/", fi->filename);
Expand Down
10 changes: 5 additions & 5 deletions compiler/include/driver.h
Original file line number Diff line number Diff line change
Expand Up @@ -103,10 +103,10 @@ bool useDefaultEnv(std::string key, bool isCrayPrgEnv);

extern std::map<std::string, const char*> envMap;

extern char CHPL_HOME[FILENAME_MAX+1];
extern char CHPL_RUNTIME_LIB[FILENAME_MAX+1];
extern char CHPL_RUNTIME_INCL[FILENAME_MAX+1];
extern char CHPL_THIRD_PARTY[FILENAME_MAX+1];
extern std::string CHPL_HOME;
extern std::string CHPL_RUNTIME_LIB;
extern std::string CHPL_RUNTIME_INCL;
extern std::string CHPL_THIRD_PARTY;

extern const char* CHPL_HOST_PLATFORM;
extern const char* CHPL_HOST_ARCH;
Expand Down Expand Up @@ -174,7 +174,7 @@ extern bool fParseOnly;
extern bool fDriverDoMonolithic;
extern bool fDriverCompilationPhase;
extern bool fDriverMakeBinaryPhase;
extern char driverTmpDir[FILENAME_MAX];
extern std::string driverTmpDir;
// end compiler driver control flags
extern bool fExitLeaks;
extern bool fPrintAllCandidates;
Expand Down
10 changes: 5 additions & 5 deletions compiler/include/files.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,11 @@
#include <functional>
#include "vec.h"

extern char executableFilename[FILENAME_MAX+1];
extern char libmodeHeadername[FILENAME_MAX+1];
extern char fortranModulename[FILENAME_MAX+1];
extern char pythonModulename[FILENAME_MAX+1];
extern char saveCDir[FILENAME_MAX+1];
extern std::string executableFilename;
extern std::string libmodeHeadername;
extern std::string fortranModulename;
extern std::string pythonModulename;
extern std::string saveCDir;
extern std::string ccflags;
extern std::string ldflags;
extern bool ccwarnings;
Expand Down
4 changes: 2 additions & 2 deletions compiler/include/library.h
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ enum PythonFileType {
// array return type
extern std::map<Symbol*, TypeSymbol*> exportedArrayElementType;

extern char libDir[FILENAME_MAX + 1];
extern std::string libDir;
extern std::map<TypeSymbol*, std::pair<std::string, std::string> > pythonNames;
extern std::map<TypeSymbol*, std::string> fortranKindNames;
extern std::map<TypeSymbol*, std::string> fortranTypeNames;
Expand All @@ -62,7 +62,7 @@ void codegen_make_python_module();

void ensureLibDirExists();
void openLibraryHelperFile(fileinfo* fi,
const char* name,
std::string name,
const char* ext = NULL);
void closeLibraryHelperFile(fileinfo* fi, bool beautifyIt = true);
const char* getLibraryExtension();
Expand Down
16 changes: 8 additions & 8 deletions compiler/include/log.h
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ void logWriteLog(const char* passName, int passNum, char logTag);

bool deletedIdON();

extern char log_dir [FILENAME_MAX + 1];
extern std::string log_dir;
extern std::set<std::string> log_modules;

extern bool fLogDir; // was --log-dir passed?
Expand All @@ -58,13 +58,13 @@ extern bool fLog;
extern bool fLogIds;
extern LogFormat fLogFormat;

extern int fdump_html;
extern char fdump_html_chpl_home[FILENAME_MAX + 1];
extern bool fdump_html_include_system_modules;
extern bool fdump_html_wrap_lines;
extern bool fdump_html_print_block_IDs;
extern int fdump_html;
extern std::string fdump_html_chpl_home;
extern bool fdump_html_include_system_modules;
extern bool fdump_html_wrap_lines;
extern bool fdump_html_print_block_IDs;

extern FILE* deletedIdHandle;
extern char deletedIdFilename[FILENAME_MAX + 1];
extern FILE* deletedIdHandle;
extern std::string deletedIdFilename;

#endif
16 changes: 8 additions & 8 deletions compiler/main/driver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -75,13 +75,13 @@ std::map<std::string, const char*> envMap;
// envMap used as input to getChplEnv
static std::map<std::string, const char*> envMapChplEnvInput;

char CHPL_HOME[FILENAME_MAX+1] = "";
std::string CHPL_HOME;

// These are more specific than CHPL_HOME, to work in
// settings where Chapel is installed.
char CHPL_RUNTIME_LIB[FILENAME_MAX+1] = "";
char CHPL_RUNTIME_INCL[FILENAME_MAX+1] = "";
char CHPL_THIRD_PARTY[FILENAME_MAX+1] = "";
std::string CHPL_RUNTIME_LIB;
std::string CHPL_RUNTIME_INCL;
std::string CHPL_THIRD_PARTY;

const char* CHPL_HOST_PLATFORM = NULL;
const char* CHPL_HOST_ARCH = NULL;
Expand Down Expand Up @@ -135,8 +135,8 @@ const char* CHPL_ROCM_AMDGCN_PATH = NULL;
const char* CHPL_GPU = NULL;
const char* CHPL_GPU_ARCH = NULL;

static char libraryFilename[FILENAME_MAX] = "";
static char incFilename[FILENAME_MAX] = "";
static std::string libraryFilename;
static std::string incFilename;
static bool fBaseline = false;

// Flags that were in commonFlags.h/cpp for awhile
Expand All @@ -152,7 +152,7 @@ bool fDriverMakeBinaryPhase = false;
bool fDriverDoMonolithic = false;
bool driverDebugPhaseSpecified = false;
// Tmp dir path managed by compiler driver
char driverTmpDir[FILENAME_MAX] = "";
std::string driverTmpDir;
bool fExitLeaks = false;
bool fLibraryCompile = false;
bool fLibraryFortran = false;
Expand Down Expand Up @@ -390,7 +390,7 @@ bool fDynoGenStdLib = false;
bool fDynoLibGenOrUse = false; // .dyno file or --dyno-gen-lib/std
size_t fDynoBreakOnHash = 0;
bool fDynoNoBreakError = false;
static char fDynoTimingPath[FILENAME_MAX] = "";
static std::string fDynoTimingPath;

bool fResolveConcreteFns = false;
bool fIdBasedMunging = false;
Expand Down
6 changes: 3 additions & 3 deletions compiler/main/log.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
#include <string>
#include <sys/stat.h>

char log_dir [FILENAME_MAX + 1] = "./log";
std::string log_dir = "./log";
std::set<std::string> log_modules;

bool fLog = false;
Expand All @@ -42,13 +42,13 @@ bool fLogIds = true;
LogFormat fLogFormat = LogFormat::DEFAULT;

int fdump_html = 0;
char fdump_html_chpl_home[FILENAME_MAX + 1] = "";
std::string fdump_html_chpl_home = "";
bool fdump_html_include_system_modules = true;
bool fdump_html_wrap_lines = true;
bool fdump_html_print_block_IDs = false;

FILE* deletedIdHandle = NULL;
char deletedIdFilename[FILENAME_MAX + 1] = "";
std::string deletedIdFilename = "";

// Keeping names of available passes
static bool availableInitialized = false;
Expand Down
12 changes: 6 additions & 6 deletions compiler/util/files.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -61,11 +61,11 @@
#include <sys/stat.h>


char executableFilename[FILENAME_MAX + 1] = "";
char libmodeHeadername[FILENAME_MAX + 1] = "";
char fortranModulename[FILENAME_MAX + 1] = "";
char pythonModulename[FILENAME_MAX + 1] = "";
char saveCDir[FILENAME_MAX + 1] = "";
std::string executableFilename;
std::string libmodeHeadername;
std::string fortranModulename;
std::string pythonModulename;
std::string saveCDir;

const char* additionalFilenamesListFilename = "additionalSourceFiles.tmp";

Expand Down Expand Up @@ -294,8 +294,8 @@ const char* getDirectory(const char* filename) {
if (filenamebase == NULL) {
return astr(".");
} else {
char dir[FILENAME_MAX];
const int len = filenamebase - filename;
char dir[len + 1];
strncpy(dir, filename, len);
dir[len] = '\0';
return astr(dir);
Expand Down

0 comments on commit 221742b

Please sign in to comment.