Implement '-main'.

This commit is contained in:
David Nadlinger
2013-06-15 23:09:59 +02:00
parent bed6243481
commit 46b6fdd531
2 changed files with 22 additions and 1 deletions

View File

@@ -204,6 +204,10 @@ static cl::list<std::string, StringsAdapter> stringImportPaths("J",
cl::location(strImpPathStore),
cl::Prefix);
static cl::opt<bool, true> addMain("main",
cl::desc("add empty main() (e.g. for unittesting)"),
cl::ZeroOrMore,
cl::location(global.params.addMain));
// -d-debug is a bit messy, it has 3 modes:

View File

@@ -693,6 +693,12 @@ int main(int argc, char** argv)
}
}
if (global.params.addMain)
{
// a dummy name, we never actually look up this file
files.push(const_cast<char*>(global.main_d));
}
// Create Modules
Modules modules;
modules.reserve(files.dim);
@@ -813,7 +819,18 @@ int main(int argc, char** argv)
if (!Module::rootModule)
Module::rootModule = m;
m->importedFrom = m;
m->read(Loc());
if (strcmp(m->srcfile->name->str, global.main_d) == 0)
{
static const char buf[] = "void main(){}";
m->srcfile->setbuffer((void *)buf, sizeof(buf));
m->srcfile->ref = 1;
}
else
{
m->read(Loc());
}
m->parse(global.params.doDocComments);
m->buildTargetFiles(singleObj);
m->deleteObjFile();