Wiki Roadmap Timeline Tickets New Ticket Source Search Help / Guide About Trac Login

Changeset 580:7824c21a58e3

Show
Ignore:
Timestamp:
09/06/08 06:27:27 (4 months ago)
Author:
Christian Kamm <kamm incasoftware de>
branch:
default
Message:

Restructure path handling a bit. Fixes #66.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • dmd/mars.c

    r572 r580  
    456456            break; 
    457457 
    458             case 'q': 
    459             if (p[3]) 
    460                 goto Lerror; 
    461             global.params.fqnPaths = 1; 
    462             break; 
     458           case 'q': 
     459           if (p[3]) 
     460               goto Lerror; 
     461           global.params.fqnNames = 1; 
     462           break; 
    463463 
    464464            case 0: 
     
    983983    m = new Module((char *) files.data[i], id, global.params.doDocComments, global.params.doHdrGeneration); 
    984984    modules.push(m); 
    985  
    986     global.params.objfiles->push(m->objfile->name->str); 
    987985    } 
    988986 
     
    996994        Module::rootModule = m; 
    997995    m->importedFrom = m; 
    998     m->deleteObjFile(); 
    999996    m->read(0); 
    1000997    m->parse(); 
     998    m->buildTargetFiles(); 
     999    m->deleteObjFile(); 
    10011000    if (m->isDocFile) 
    10021001    { 
     
    10061005        modules.remove(i); 
    10071006        i--; 
    1008  
    1009         // Remove m's object file from list of object files 
    1010         for (int j = 0; j < global.params.objfiles->dim; j++) 
    1011         { 
    1012         if (m->objfile->name->str == global.params.objfiles->data[j]) 
    1013         { 
    1014             global.params.objfiles->remove(j); 
    1015             break; 
    1016         } 
    1017         } 
    1018  
    1019         if (global.params.objfiles->dim == 0) 
    1020         global.params.link = 0; 
    10211007    } 
    10221008    } 
     
    11211107        printf("code      %s\n", m->toChars()); 
    11221108    if (global.params.obj) 
     1109    { 
    11231110        m->genobjfile(0); 
     1111        global.params.objfiles->push(m->objfile->name->str); 
     1112    } 
    11241113    if (global.errors) 
    11251114        m->deleteObjFile(); 
  • dmd/mars.h

    r568 r580  
    149149    char llvmAnnotate; 
    150150    char useInlineAsm; 
    151     char fqnPaths; // use fully qualified object names 
     151    char fqnNames; // use fully qualified object names 
    152152}; 
    153153 
  • dmd/module.c

    r550 r580  
    5959{ 
    6060    FileName *srcfilename; 
    61     FileName *cfilename; 
    62     FileName *hfilename; 
    63     FileName *objfilename; 
    64     FileName *llfilename; 
    65     FileName *bcfilename; 
    66     FileName *symfilename; 
    6761 
    6862//    printf("Module::Module(filename = '%s', ident = '%s')\n", filename, ident->toChars()); 
     
    9690    importedFrom = NULL; 
    9791    srcfile = NULL; 
     92    objfile = NULL; 
    9893    docfile = NULL; 
     94    hdrfile = NULL; 
    9995 
    10096    debuglevel = 0; 
     
    125121    } 
    126122    } 
    127  
    128     char *argobj; 
    129     if (global.params.objname) 
    130     argobj = global.params.objname; 
    131     else if (global.params.preservePaths) 
    132     argobj = filename; 
    133     else 
    134     argobj = FileName::name(filename); 
    135     if (!FileName::absolute(argobj)) 
    136     { 
    137     argobj = FileName::combine(global.params.objdir, argobj); 
    138     } 
    139  
    140     if (global.params.objname) 
    141     objfilename = new FileName(argobj, 0); 
    142     else 
    143     objfilename = FileName::forceExt(argobj, global.obj_ext); 
    144  
    145     llfilename = FileName::forceExt(argobj, global.ll_ext); 
    146     bcfilename = FileName::forceExt(argobj, global.bc_ext); 
    147  
    148     symfilename = FileName::forceExt(filename, global.sym_ext); 
    149  
    150123    srcfile = new File(srcfilename); 
    151124 
    152     if (doDocComment) 
    153     { 
    154     setDocfile(); 
    155     } 
    156  
    157     if (doHdrGen) 
    158     { 
    159     setHdrfile(); 
    160     } 
    161  
    162     objfile = new File(objfilename); 
    163     bcfile = new File(bcfilename); 
    164     llfile = new File(llfilename); 
    165     symfile = new File(symfilename); 
    166      
    167125    // LLVMDC 
    168126    llvmForceLogging = false; 
    169127} 
    170128 
    171 void Module::setDocfile() 
    172 
    173     FileName *docfilename; 
    174     char *argdoc; 
    175  
    176     if (global.params.docname) 
    177     argdoc = global.params.docname; 
    178     else if (global.params.preservePaths) 
    179     argdoc = (char *)arg; 
     129File* Module::buildFilePath(char* forcename, char* path, char* ext) 
     130
     131    char *argobj; 
     132    if (forcename) 
     133    argobj = forcename; 
    180134    else 
    181     argdoc = FileName::name((char *)arg); 
    182     if (!FileName::absolute(argdoc)) 
    183     {   //FileName::ensurePathExists(global.params.docdir); 
    184     argdoc = FileName::combine(global.params.docdir, argdoc); 
    185     } 
    186     if (global.params.docname) 
    187     docfilename = new FileName(argdoc, 0); 
     135    { 
     136    if (global.params.preservePaths) 
     137        argobj = (char*)this->arg; 
     138    else 
     139        argobj = FileName::name((char*)this->arg); 
     140 
     141    if (global.params.fqnNames) 
     142        if(md) 
     143        argobj = FileName::replaceName(argobj, md->toChars()); 
     144        else 
     145        argobj = FileName::replaceName(argobj, toChars()); 
     146 
     147    int clen = strlen(argobj); 
     148    char* tmp = (char *)alloca(clen + 2); 
     149    memcpy(tmp, argobj, clen); 
     150    tmp[clen] = '.'; 
     151    tmp[clen+1] = 0; 
     152    argobj = tmp; 
     153    } 
     154 
     155    if (!FileName::absolute(argobj)) 
     156    { 
     157    argobj = FileName::combine(path, argobj); 
     158    } 
     159 
     160    FileName::ensurePathExists(FileName::path(argobj)); 
     161 
     162    if (global.params.objname) 
     163    return new File(argobj); 
    188164    else 
    189     docfilename = FileName::forceExt(argdoc, global.doc_ext); 
    190  
    191     if (docfilename->equals(srcfile->name)) 
    192     {   error("Source file and documentation file have same name '%s'", srcfile->name->str); 
    193     fatal(); 
    194     } 
    195  
    196     docfile = new File(docfilename); 
    197 
    198  
    199 void Module::setHdrfile() 
    200 
    201     FileName *hdrfilename; 
    202     char *arghdr; 
    203  
    204     if (global.params.hdrname) 
    205     arghdr = global.params.hdrname; 
    206     else if (global.params.preservePaths) 
    207     arghdr = (char *)arg; 
    208     else 
    209     arghdr = FileName::name((char *)arg); 
    210     if (!FileName::absolute(arghdr)) 
    211     {   //FileName::ensurePathExists(global.params.hdrdir); 
    212     arghdr = FileName::combine(global.params.hdrdir, arghdr); 
    213     } 
    214     if (global.params.hdrname) 
    215     hdrfilename = new FileName(arghdr, 0); 
    216     else 
    217     hdrfilename = FileName::forceExt(arghdr, global.hdr_ext); 
    218  
    219     if (hdrfilename->equals(srcfile->name)) 
    220     {   error("Source file and 'header' file have same name '%s'", srcfile->name->str); 
    221     fatal(); 
    222     } 
    223  
    224     hdrfile = new File(hdrfilename); 
     165    return new File(FileName::forceExt(argobj, ext)); 
     166
     167 
     168void Module::buildTargetFiles() 
     169
     170    if(objfile && docfile && hdrfile) 
     171    return; 
     172 
     173    objfile = Module::buildFilePath(global.params.objname, global.params.objdir, global.bc_ext); 
     174    docfile = Module::buildFilePath(global.params.docname, global.params.docdir, global.doc_ext); 
     175    hdrfile = Module::buildFilePath(global.params.hdrname, global.params.hdrdir, global.hdr_ext); 
    225176} 
    226177 
     
    230181    objfile->remove(); 
    231182    //if (global.params.llvmBC) 
    232     bcfile->remove(); 
     183    //bcfile->remove(); 
    233184    if (docfile) 
    234185    docfile->remove(); 
     
    576527    comment = buf + 4; 
    577528    isDocFile = 1; 
    578     if (!docfile) 
    579         setDocfile(); 
    580529    return; 
    581530    } 
     
    773722 */ 
    774723 
     724// is this used anywhere? 
     725/* 
    775726void Module::gensymfile() 
    776727{ 
     
    794745 
    795746    symfile->writev(); 
    796 } 
     747}*/ 
    797748 
    798749/********************************** 
  • dmd/module.h

    r486 r580  
    6666    ModuleDeclaration *md; // if !NULL, the contents of the ModuleDeclaration declaration 
    6767    File *srcfile;  // input source file 
    68     File *objfile;  // output .obj file 
     68 
     69    File *objfile; // output object file 
     70    File *docfile; // output doc file 
     71    File *hdrfile; // output hdr file 
    6972     
    70     // LLVMDC 
    71     File *bcfile;  // output .bc file 
    72     File *llfile;  // output .ll file 
    73  
    74     File *hdrfile;  // 'header' file 
    75     File *symfile;  // output symbol file 
    76     File *docfile;  // output documentation file 
    7773    unsigned errors;    // if any errors in file 
    7874    unsigned numlines;  // number of lines in source file 
     
    122118    void toCBuffer(OutBuffer *buf, HdrGenState *hgs); 
    123119    const char *kind(); 
    124     void setDocfile();  // set docfile member 
    125120    void read(Loc loc); // read file 
    126121#if IN_GCC 
     
    133128    void semantic3();   // pass 3 semantic analysis 
    134129    void inlineScan();  // scan for functions to inline 
    135     void setHdrfile();  // set hdrfile member 
    136130#ifdef _DH 
    137131    void genhdrfile();  // generate D import file 
    138132#endif 
    139133    void genobjfile(int multiobj); 
    140     void gensymfile(); 
     134//    void gensymfile(); 
    141135    void gendocfile(); 
    142136    int needModuleInfo(); 
     
    174168 
    175169    // LLVMDC 
     170    void buildTargetFiles(); 
     171    File* buildFilePath(char* forcename, char* path, char* ext); 
    176172    Module *isModule() { return this; } 
    177173     
  • gen/toobj.cpp

    r565 r580  
    165165    // eventually do our own path stuff, dmd's is a bit strange. 
    166166    typedef llvm::sys::Path LLPath; 
    167     LLPath bcpath; 
    168     LLPath llpath; 
    169  
    170     if (global.params.fqnPaths) 
    171     { 
    172         bcpath = LLPath(mname); 
    173         bcpath.appendSuffix("bc"); 
    174  
    175         llpath = LLPath(mname); 
    176         llpath.appendSuffix("ll"); 
    177     } 
    178     else 
    179     { 
    180         bcpath = LLPath(bcfile->name->toChars()); 
    181         llpath = LLPath(llfile->name->toChars()); 
    182     } 
     167    LLPath bcpath = LLPath(objfile->name->toChars()); 
     168    LLPath llpath = bcpath; 
     169    llpath.eraseSuffix(); 
     170    llpath.appendSuffix(std::string(global.ll_ext)); 
    183171 
    184172    // write bytecode 
     
    191179    // disassemble ? 
    192180    if (global.params.disassemble) { 
    193         Logger::println("Writing LLVM asm to: %s\n", llfile->name->toChars()); 
     181        Logger::println("Writing LLVM asm to: %s\n", llpath.c_str()); 
    194182        std::ofstream aos(llpath.c_str()); 
    195183        ir.module->print(aos, NULL); 
Copyright © 2008, LDC Development Team.