mirror of
https://github.com/xomboverlord/ldc.git
synced 2026-08-01 20:10:04 +02:00
- Updated to DMD frontend 1.041.
- Removed dmd/inifile.c , it's not under a free license, replaced with libconfig based config file.
This commit is contained in:
@@ -469,7 +469,7 @@ static void remap_outargs(std::string& insnt, size_t nargs, size_t idx)
|
||||
needle = prefix + digits[i] + suffix;
|
||||
size_t pos = insnt.find(needle);
|
||||
if(std::string::npos != pos)
|
||||
sprintf(buf, "%" PRIuSIZE, idx++);
|
||||
sprintf(buf, "%lu", idx++);
|
||||
while(std::string::npos != (pos = insnt.find(needle)))
|
||||
insnt.replace(pos, needle.size(), buf);
|
||||
}
|
||||
@@ -494,7 +494,7 @@ static void remap_inargs(std::string& insnt, size_t nargs, size_t idx)
|
||||
needle = prefix + digits[i] + suffix;
|
||||
size_t pos = insnt.find(needle);
|
||||
if(std::string::npos != pos)
|
||||
sprintf(buf, "%" PRIuSIZE, idx++);
|
||||
sprintf(buf, "%lu", idx++);
|
||||
while(std::string::npos != (pos = insnt.find(needle)))
|
||||
insnt.replace(pos, needle.size(), buf);
|
||||
}
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
#include "gen/cl_helpers.h"
|
||||
|
||||
#include "root.h"
|
||||
#include "mem.h"
|
||||
#include "rmem.h"
|
||||
|
||||
#include <cctype> // isupper, tolower
|
||||
#include <algorithm>
|
||||
|
||||
112
gen/configfile.cpp
Normal file
112
gen/configfile.cpp
Normal file
@@ -0,0 +1,112 @@
|
||||
#include <iostream>
|
||||
#include <string>
|
||||
#include <cassert>
|
||||
|
||||
#include "llvm/System/Path.h"
|
||||
|
||||
#include "libconfig.h++"
|
||||
|
||||
#include "gen/configfile.h"
|
||||
|
||||
#include "mars.h"
|
||||
|
||||
namespace sys = llvm::sys;
|
||||
|
||||
ConfigFile::ConfigFile()
|
||||
{
|
||||
cfg = new libconfig::Config;
|
||||
}
|
||||
|
||||
ConfigFile::~ConfigFile()
|
||||
{
|
||||
delete cfg;
|
||||
}
|
||||
|
||||
bool ConfigFile::read(const char* argv0, void* mainAddr, const char* filename)
|
||||
{
|
||||
|
||||
// try to find the config file
|
||||
|
||||
// 1) try the current working dir
|
||||
sys::Path p = sys::Path::GetCurrentDirectory();
|
||||
p.appendComponent(filename);
|
||||
|
||||
if (!p.exists())
|
||||
{
|
||||
// 2) try the user home dir
|
||||
p = sys::Path::GetUserHomeDirectory();
|
||||
p.appendComponent(filename);
|
||||
|
||||
if (!p.exists())
|
||||
{
|
||||
// 3) try the install-prefix/etc
|
||||
p = sys::Path(LDC_INSTALL_PREFIX);
|
||||
p.appendComponent(filename);
|
||||
|
||||
if (!p.exists())
|
||||
{
|
||||
// 4) try next to the executable
|
||||
p = sys::Path::GetMainExecutable(argv0, mainAddr);
|
||||
p.eraseComponent();
|
||||
p.appendComponent(filename);
|
||||
if (!p.exists())
|
||||
{
|
||||
// 5) fail load cfg, users still have the DFLAGS environment var
|
||||
std::cerr << "Error failed to locate the configuration file: " << filename << std::endl;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
// read the cfg
|
||||
cfg->readFile(p.c_str());
|
||||
|
||||
// make sure there's a default group
|
||||
if (!cfg->exists("default"))
|
||||
{
|
||||
std::cerr << "no default settings in configuration file" << std::endl;
|
||||
return false;
|
||||
}
|
||||
libconfig::Setting& root = cfg->lookup("default");
|
||||
if (!root.isGroup())
|
||||
{
|
||||
std::cerr << "default is not a group" << std::endl;
|
||||
return false;
|
||||
}
|
||||
|
||||
// handle switches
|
||||
if (root.exists("switches"))
|
||||
{
|
||||
libconfig::Setting& arr = cfg->lookup("default.switches");
|
||||
int len = arr.getLength();
|
||||
for (int i=0; i<len; i++)
|
||||
{
|
||||
const char* v = arr[i];
|
||||
switches.push_back(v);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
catch(libconfig::FileIOException& fioe)
|
||||
{
|
||||
std::cerr << "Error reading configuration file: " << filename << std::endl;
|
||||
return false;
|
||||
}
|
||||
catch(libconfig::ParseException& pe)
|
||||
{
|
||||
std::cerr << "Error parsing configuration file: " << filename
|
||||
<< "(" << pe.getLine() << "): " << pe.getError() << std::endl;
|
||||
return false;
|
||||
}
|
||||
catch(...)
|
||||
{
|
||||
std::cerr << "Unknown exception caught!" << std::endl;
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
32
gen/configfile.h
Normal file
32
gen/configfile.h
Normal file
@@ -0,0 +1,32 @@
|
||||
#ifndef LDC_CONF_CONFIGFILE_H
|
||||
#define LDC_CONF_CONFIGFILE_H
|
||||
|
||||
#include <vector>
|
||||
|
||||
namespace libconfig
|
||||
{
|
||||
class Config;
|
||||
}
|
||||
|
||||
class ConfigFile
|
||||
{
|
||||
public:
|
||||
typedef std::vector<const char*> s_vector;
|
||||
typedef s_vector::iterator s_iterator;
|
||||
|
||||
public:
|
||||
ConfigFile();
|
||||
~ConfigFile();
|
||||
|
||||
bool read(const char* argv0, void* mainAddr, const char* filename);
|
||||
|
||||
s_iterator switches_begin() { return switches.begin(); }
|
||||
s_iterator switches_end() { return switches.end(); }
|
||||
|
||||
private:
|
||||
libconfig::Config* cfg;
|
||||
|
||||
s_vector switches;
|
||||
};
|
||||
|
||||
#endif // LDC_CONF_CONFIGFILE_H
|
||||
45
gen/main.cpp
45
gen/main.cpp
@@ -21,7 +21,7 @@
|
||||
#include <windows.h>
|
||||
#endif
|
||||
|
||||
#include "mem.h"
|
||||
#include "rmem.h"
|
||||
#include "root.h"
|
||||
|
||||
#include "mars.h"
|
||||
@@ -39,6 +39,8 @@
|
||||
#include "gen/cl_helpers.h"
|
||||
using namespace opts;
|
||||
|
||||
#include "gen/configfile.h"
|
||||
|
||||
extern void getenv_setargv(const char *envvar, int *pargc, char** *pargv);
|
||||
extern void backend_init();
|
||||
extern void backend_term();
|
||||
@@ -144,15 +146,7 @@ int main(int argc, char** argv)
|
||||
VersionCondition::addPredefinedGlobalIdent("D_Version2");
|
||||
#endif
|
||||
|
||||
|
||||
// read the inifile
|
||||
#if DMDV2
|
||||
inifile(global.params.argv0, "ldc2.conf");
|
||||
#else
|
||||
inifile(global.params.argv0, "ldc.conf");
|
||||
#endif
|
||||
|
||||
// merge DFLAGS into argc/argv
|
||||
// merge DFLAGS environment variable into argc/argv
|
||||
getenv_setargv("DFLAGS", &argc, &argv);
|
||||
#if 0
|
||||
for (int i = 0; i < argc; i++)
|
||||
@@ -161,9 +155,38 @@ int main(int argc, char** argv)
|
||||
}
|
||||
#endif
|
||||
|
||||
// build complete fixed up list of command line arguments
|
||||
std::vector<const char*> final_args;
|
||||
final_args.reserve(argc);
|
||||
|
||||
// insert argc + DFLAGS
|
||||
final_args.insert(final_args.end(), &argv[0], &argv[argc]);
|
||||
|
||||
// read the configuration file
|
||||
ConfigFile cfg_file;
|
||||
|
||||
// just ignore errors for now, they are still printed
|
||||
#if DMDV2
|
||||
#define CFG_FILENAME "ldc2.conf"
|
||||
#else
|
||||
#define CFG_FILENAME "ldc.conf"
|
||||
#endif
|
||||
cfg_file.read(global.params.argv0, (void*)main, CFG_FILENAME);
|
||||
#undef CFG_FILENAME
|
||||
|
||||
// insert config file additions to the argument list
|
||||
final_args.insert(final_args.end(), cfg_file.switches_begin(), cfg_file.switches_end());
|
||||
|
||||
#if 0
|
||||
for (size_t i = 0; i < final_args.size(); ++i)
|
||||
{
|
||||
printf("final_args[%zu] = %s\n", i, final_args[i]);
|
||||
}
|
||||
#endif
|
||||
|
||||
// Handle fixed-up arguments!
|
||||
cl::SetVersionPrinter(&printVersion);
|
||||
cl::ParseCommandLineOptions(argc, argv, "LLVM-based D Compiler\n");
|
||||
cl::ParseCommandLineOptions(final_args.size(), (char**)&final_args[0], "LLVM-based D Compiler\n", true);
|
||||
|
||||
global.params.optimize = (global.params.optimizeLevel >= 0);
|
||||
|
||||
|
||||
@@ -9,7 +9,6 @@
|
||||
#include "llvm/Support/CFG.h"
|
||||
|
||||
#include "mars.h"
|
||||
#include "total.h"
|
||||
#include "init.h"
|
||||
#include "mtype.h"
|
||||
#include "hdrgen.h"
|
||||
|
||||
@@ -13,13 +13,14 @@
|
||||
#include "gen/llvm.h"
|
||||
|
||||
#include "attrib.h"
|
||||
#include "total.h"
|
||||
#include "init.h"
|
||||
#include "mtype.h"
|
||||
#include "template.h"
|
||||
#include "hdrgen.h"
|
||||
#include "port.h"
|
||||
#include "mem.h"
|
||||
#include "rmem.h"
|
||||
#include "id.h"
|
||||
#include "enum.h"
|
||||
|
||||
#include "gen/irstate.h"
|
||||
#include "gen/logger.h"
|
||||
|
||||
Reference in New Issue
Block a user