Restructure path handling a bit. Fixes #66.

This commit is contained in:
Christian Kamm
2008-09-06 12:27:27 +02:00
parent 2f2987371f
commit d44f21687e
5 changed files with 67 additions and 143 deletions

View File

@@ -455,11 +455,11 @@ int main(int argc, char *argv[])
global.params.preservePaths = 1;
break;
case 'q':
if (p[3])
goto Lerror;
global.params.fqnPaths = 1;
break;
case 'q':
if (p[3])
goto Lerror;
global.params.fqnNames = 1;
break;
case 0:
error("-o no longer supported, use -of or -od");
@@ -982,8 +982,6 @@ int main(int argc, char *argv[])
id = new Identifier(name, 0);
m = new Module((char *) files.data[i], id, global.params.doDocComments, global.params.doHdrGeneration);
modules.push(m);
global.params.objfiles->push(m->objfile->name->str);
}
// Read files, parse them
@@ -995,9 +993,10 @@ int main(int argc, char *argv[])
if (!Module::rootModule)
Module::rootModule = m;
m->importedFrom = m;
m->deleteObjFile();
m->read(0);
m->parse();
m->buildTargetFiles();
m->deleteObjFile();
if (m->isDocFile)
{
m->gendocfile();
@@ -1005,19 +1004,6 @@ int main(int argc, char *argv[])
// Remove m from list of modules
modules.remove(i);
i--;
// Remove m's object file from list of object files
for (int j = 0; j < global.params.objfiles->dim; j++)
{
if (m->objfile->name->str == global.params.objfiles->data[j])
{
global.params.objfiles->remove(j);
break;
}
}
if (global.params.objfiles->dim == 0)
global.params.link = 0;
}
}
if (global.errors)
@@ -1120,7 +1106,10 @@ int main(int argc, char *argv[])
if (global.params.verbose)
printf("code %s\n", m->toChars());
if (global.params.obj)
{
m->genobjfile(0);
global.params.objfiles->push(m->objfile->name->str);
}
if (global.errors)
m->deleteObjFile();
else

View File

@@ -148,7 +148,7 @@ struct Param
char llvmInline;
char llvmAnnotate;
char useInlineAsm;
char fqnPaths; // use fully qualified object names
char fqnNames; // use fully qualified object names
};
struct Global

View File

@@ -58,12 +58,6 @@ Module::Module(char *filename, Identifier *ident, int doDocComment, int doHdrGen
: Package(ident)
{
FileName *srcfilename;
FileName *cfilename;
FileName *hfilename;
FileName *objfilename;
FileName *llfilename;
FileName *bcfilename;
FileName *symfilename;
// printf("Module::Module(filename = '%s', ident = '%s')\n", filename, ident->toChars());
this->arg = filename;
@@ -95,7 +89,9 @@ Module::Module(char *filename, Identifier *ident, int doDocComment, int doHdrGen
root = 0;
importedFrom = NULL;
srcfile = NULL;
objfile = NULL;
docfile = NULL;
hdrfile = NULL;
debuglevel = 0;
debugids = NULL;
@@ -124,104 +120,59 @@ Module::Module(char *filename, Identifier *ident, int doDocComment, int doHdrGen
fatal();
}
}
char *argobj;
if (global.params.objname)
argobj = global.params.objname;
else if (global.params.preservePaths)
argobj = filename;
else
argobj = FileName::name(filename);
if (!FileName::absolute(argobj))
{
argobj = FileName::combine(global.params.objdir, argobj);
}
if (global.params.objname)
objfilename = new FileName(argobj, 0);
else
objfilename = FileName::forceExt(argobj, global.obj_ext);
llfilename = FileName::forceExt(argobj, global.ll_ext);
bcfilename = FileName::forceExt(argobj, global.bc_ext);
symfilename = FileName::forceExt(filename, global.sym_ext);
srcfile = new File(srcfilename);
if (doDocComment)
{
setDocfile();
}
if (doHdrGen)
{
setHdrfile();
}
objfile = new File(objfilename);
bcfile = new File(bcfilename);
llfile = new File(llfilename);
symfile = new File(symfilename);
// LLVMDC
llvmForceLogging = false;
}
void Module::setDocfile()
File* Module::buildFilePath(char* forcename, char* path, char* ext)
{
FileName *docfilename;
char *argdoc;
if (global.params.docname)
argdoc = global.params.docname;
else if (global.params.preservePaths)
argdoc = (char *)arg;
char *argobj;
if (forcename)
argobj = forcename;
else
argdoc = FileName::name((char *)arg);
if (!FileName::absolute(argdoc))
{ //FileName::ensurePathExists(global.params.docdir);
argdoc = FileName::combine(global.params.docdir, argdoc);
}
if (global.params.docname)
docfilename = new FileName(argdoc, 0);
else
docfilename = FileName::forceExt(argdoc, global.doc_ext);
{
if (global.params.preservePaths)
argobj = (char*)this->arg;
else
argobj = FileName::name((char*)this->arg);
if (docfilename->equals(srcfile->name))
{ error("Source file and documentation file have same name '%s'", srcfile->name->str);
fatal();
if (global.params.fqnNames)
if(md)
argobj = FileName::replaceName(argobj, md->toChars());
else
argobj = FileName::replaceName(argobj, toChars());
int clen = strlen(argobj);
char* tmp = (char *)alloca(clen + 2);
memcpy(tmp, argobj, clen);
tmp[clen] = '.';
tmp[clen+1] = 0;
argobj = tmp;
}
docfile = new File(docfilename);
if (!FileName::absolute(argobj))
{
argobj = FileName::combine(path, argobj);
}
FileName::ensurePathExists(FileName::path(argobj));
if (global.params.objname)
return new File(argobj);
else
return new File(FileName::forceExt(argobj, ext));
}
void Module::setHdrfile()
void Module::buildTargetFiles()
{
FileName *hdrfilename;
char *arghdr;
if(objfile && docfile && hdrfile)
return;
if (global.params.hdrname)
arghdr = global.params.hdrname;
else if (global.params.preservePaths)
arghdr = (char *)arg;
else
arghdr = FileName::name((char *)arg);
if (!FileName::absolute(arghdr))
{ //FileName::ensurePathExists(global.params.hdrdir);
arghdr = FileName::combine(global.params.hdrdir, arghdr);
}
if (global.params.hdrname)
hdrfilename = new FileName(arghdr, 0);
else
hdrfilename = FileName::forceExt(arghdr, global.hdr_ext);
if (hdrfilename->equals(srcfile->name))
{ error("Source file and 'header' file have same name '%s'", srcfile->name->str);
fatal();
}
hdrfile = new File(hdrfilename);
objfile = Module::buildFilePath(global.params.objname, global.params.objdir, global.bc_ext);
docfile = Module::buildFilePath(global.params.docname, global.params.docdir, global.doc_ext);
hdrfile = Module::buildFilePath(global.params.hdrname, global.params.hdrdir, global.hdr_ext);
}
void Module::deleteObjFile()
@@ -229,7 +180,7 @@ void Module::deleteObjFile()
if (global.params.obj)
objfile->remove();
//if (global.params.llvmBC)
bcfile->remove();
//bcfile->remove();
if (docfile)
docfile->remove();
}
@@ -575,8 +526,6 @@ void Module::parse()
{
comment = buf + 4;
isDocFile = 1;
if (!docfile)
setDocfile();
return;
}
if (isHtml)
@@ -772,6 +721,8 @@ void Module::inlineScan()
/****************************************************
*/
// is this used anywhere?
/*
void Module::gensymfile()
{
OutBuffer buf;
@@ -793,7 +744,7 @@ void Module::gensymfile()
buf.data = NULL;
symfile->writev();
}
}*/
/**********************************
* Determine if we need to generate an instance of ModuleInfo

View File

@@ -65,15 +65,11 @@ struct Module : Package
const char *arg; // original argument name
ModuleDeclaration *md; // if !NULL, the contents of the ModuleDeclaration declaration
File *srcfile; // input source file
File *objfile; // output .obj file
// LLVMDC
File *bcfile; // output .bc file
File *llfile; // output .ll file
File *hdrfile; // 'header' file
File *symfile; // output symbol file
File *docfile; // output documentation file
File *objfile; // output object file
File *docfile; // output doc file
File *hdrfile; // output hdr file
unsigned errors; // if any errors in file
unsigned numlines; // number of lines in source file
int isHtml; // if it is an HTML file
@@ -121,7 +117,6 @@ struct Module : Package
void toCBuffer(OutBuffer *buf, HdrGenState *hgs);
const char *kind();
void setDocfile(); // set docfile member
void read(Loc loc); // read file
#if IN_GCC
void parse(bool dump_source = false); // syntactic parse
@@ -132,12 +127,11 @@ struct Module : Package
void semantic2(); // pass 2 semantic analysis
void semantic3(); // pass 3 semantic analysis
void inlineScan(); // scan for functions to inline
void setHdrfile(); // set hdrfile member
#ifdef _DH
void genhdrfile(); // generate D import file
#endif
void genobjfile(int multiobj);
void gensymfile();
// void gensymfile();
void gendocfile();
int needModuleInfo();
Dsymbol *search(Loc loc, Identifier *ident, int flags);
@@ -173,6 +167,8 @@ struct Module : Package
void genmoduleinfo();
// LLVMDC
void buildTargetFiles();
File* buildFilePath(char* forcename, char* path, char* ext);
Module *isModule() { return this; }
bool llvmForceLogging;

View File

@@ -164,22 +164,10 @@ void Module::genobjfile(int multiobj)
// eventually do our own path stuff, dmd's is a bit strange.
typedef llvm::sys::Path LLPath;
LLPath bcpath;
LLPath llpath;
if (global.params.fqnPaths)
{
bcpath = LLPath(mname);
bcpath.appendSuffix("bc");
llpath = LLPath(mname);
llpath.appendSuffix("ll");
}
else
{
bcpath = LLPath(bcfile->name->toChars());
llpath = LLPath(llfile->name->toChars());
}
LLPath bcpath = LLPath(objfile->name->toChars());
LLPath llpath = bcpath;
llpath.eraseSuffix();
llpath.appendSuffix(std::string(global.ll_ext));
// write bytecode
{
@@ -190,7 +178,7 @@ void Module::genobjfile(int multiobj)
// disassemble ?
if (global.params.disassemble) {
Logger::println("Writing LLVM asm to: %s\n", llfile->name->toChars());
Logger::println("Writing LLVM asm to: %s\n", llpath.c_str());
std::ofstream aos(llpath.c_str());
ir.module->print(aos, NULL);
}