Skip to content

Commit

Permalink
base default output on filename instead of "a.out"
Browse files Browse the repository at this point in the history
Also choose a target-appropriate default extension for dlls and exes.
  • Loading branch information
jckarter committed Oct 29, 2011
1 parent 41d694f commit dcc1052
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 8 deletions.
3 changes: 3 additions & 0 deletions ChangeLog.txt
Expand Up @@ -100,6 +100,9 @@ Compiler frontend changes:
in the current compilation unit.
* External entry points for the main module are also now always compiled; "-shared"
now only affects the type of file output by the compiler.
* The default output filename for executables and dynamic libraries is now the
basename of the input file instead of "a.out". For instance, "clay hello.clay" will
output an executable named "hello" (or "hello.exe" if compiling for a Windows target).

Planned changes
---------------
Expand Down
30 changes: 24 additions & 6 deletions compiler/src/main.cpp
Expand Up @@ -21,12 +21,8 @@
#include <cstring>

#ifdef WIN32
#define DEFAULT_EXE "a.exe"
#define DEFAULT_DLL "a.dll"
#define PATH_SEPARATORS "/\\"
#else
#define DEFAULT_EXE "a.out"
#define DEFAULT_DLL "a.out"
#define PATH_SEPARATORS "/"
#endif

Expand Down Expand Up @@ -305,6 +301,28 @@ static string basename(const string &fullname)
return fullname.substr(from, length);
}

static string sharedExtensionForTarget(llvm::Triple const &triple) {
if (triple.getOS() == llvm::Triple::Win32
|| triple.getOS() == llvm::Triple::MinGW32
|| triple.getOS() == llvm::Triple::Cygwin) {
return ".dll";
} else if (triple.getOS() == llvm::Triple::Darwin) {
return ".dylib";
} else {
return ".so";
}
}

static string exeExtensionForTarget(llvm::Triple const &triple) {
if (triple.getOS() == llvm::Triple::Win32
|| triple.getOS() == llvm::Triple::MinGW32
|| triple.getOS() == llvm::Triple::Cygwin) {
return ".exe";
} else {
return "";
}
}

int main(int argc, char **argv) {
if (argc == 1) {
usage(argv[0]);
Expand Down Expand Up @@ -711,9 +729,9 @@ int main(int argc, char **argv) {
else if (emitObject)
outputFile = clayFileBasename + ".o";
else if (sharedLib)
outputFile = DEFAULT_DLL;
outputFile = clayFileBasename + sharedExtensionForTarget(llvmTriple);
else
outputFile = DEFAULT_EXE;
outputFile = clayFileBasename + exeExtensionForTarget(llvmTriple);
}
llvm::sys::Path outputFilePath(outputFile);
llvm::sys::RemoveFileOnSignal(outputFilePath);
Expand Down
4 changes: 2 additions & 2 deletions test/runtests.py
Expand Up @@ -116,7 +116,7 @@ def loadTest(self, testfile):
self.testfile = testfile

def cmdline(self, clay) :
return [clay, "-I" + self.path] + self.buildflags + [self.testfile]
return [clay, "-I" + self.path, "-o", "test.exe"] + self.buildflags + [self.testfile]

def pre_build(self) :
pass
Expand Down Expand Up @@ -177,7 +177,7 @@ def name(self):
return os.path.relpath(self.path, testRoot)

def runtest(self):
outfilename = "a.exe" if sys.platform == "win32" else "a.out"
outfilename = "test.exe"
outfilename = os.path.join(".", outfilename)
process = Popen(self.cmdline(compiler), stdout=PIPE, stderr=PIPE)
compilerout, compilererr = process.communicate()
Expand Down

0 comments on commit dcc1052

Please sign in to comment.