Skip to content

Commit

Permalink
InstalledDir fix
Browse files Browse the repository at this point in the history
  • Loading branch information
f0xeri committed Mar 8, 2024
1 parent 77e61c9 commit dd407c2
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 6 deletions.
5 changes: 2 additions & 3 deletions CompilerOptions.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,20 +8,19 @@
#include <string>
#include <filesystem>
#include "llvm/Support/CommandLine.h"
#include "common.hpp"

using namespace llvm;

namespace Slangc {

enum OptLevel {
O0, O1, O2, O3
};

class CompilerOptions {
public:
CompilerOptions(int argc, char **argv) {
std::filesystem::path program_path(argv[0]);
std::filesystem::path current_directory = program_path.parent_path();
std::filesystem::path current_directory = getCurrentProcessDirectory();
llvm::cl::OptionCategory options("Compiler options");

llvm::cl::opt<std::string> OutputFileName(
Expand Down
43 changes: 40 additions & 3 deletions common.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,45 @@
#include <algorithm>
#include <functional>
#include <utility>
#include <filesystem>

#ifdef _WIN32
#include <windows.h>
#undef min
#undef max
namespace Slangc {
static std::filesystem::path getCurrentProcessDirectory() {
wchar_t buffer[MAX_PATH];
GetModuleFileName(NULL, buffer, sizeof(buffer));
return std::filesystem::path(buffer).parent_path();
}
}
#elif __linux__
namespace Slangc {
static std::filesystem::path getCurrentProcessDirectory() {
char result[PATH_MAX];
ssize_t count = readlink("/proc/self/exe", result, PATH_MAX);
return std::filesystem::path(std::string(result, (count > 0) ? count : 0)).parent_path();
}
}
#elif __APPLE__
#include <mach-o/dyld.h>
namespace Slangc {
static std::filesystem::path getCurrentProcessDirectory() {
char buffer[PATH_MAX];
uint32_t size = sizeof(buffer);
if (_NSGetExecutablePath(buffer, &size) == 0) {
return std::filesystem::path(buffer).parent_path();
}
return std::filesystem::path();
}
}
#endif

namespace Slangc {
struct SourceLoc {
SourceLoc(std::uint64_t line, std::uint64_t column) : line(line), column(column) {}

std::uint64_t line;
std::uint64_t column;

Expand All @@ -30,8 +65,10 @@ namespace Slangc {
bool isWarning = false;
bool internal = false;

ErrorMessage(std::string sourceFile, std::string message, SourceLoc location, bool isWarning = false, bool internal = false)
: message(std::move(message)), sourceFile(std::move(sourceFile)), location(location), isWarning(isWarning), internal(internal) {}
ErrorMessage(std::string sourceFile, std::string message, SourceLoc location, bool isWarning = false,
bool internal = false)
: message(std::move(message)), sourceFile(std::move(sourceFile)), location(location),
isWarning(isWarning), internal(internal) {}

void print(auto &stream) const {
stream << sourceFile;
Expand Down Expand Up @@ -90,7 +127,7 @@ namespace Slangc {
}

static void printErrorMessages(std::vector<ErrorMessage> &errors, auto &stream, bool warnings = true) {
for (auto &error : errors) {
for (auto &error: errors) {
if (error.isWarning && !warnings) continue;
error.print(stream);
}
Expand Down

0 comments on commit dd407c2

Please sign in to comment.