Changeset 94

Show
Ignore:
Timestamp:
12/28/05 23:42:42 (3 years ago)
Author:
pragma
Message:

Fixed bugs and reset the test cases

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/ddl/DynamicLibrary.d

    r85 r94  
    3434private import ddl.Mangle; 
    3535 
     36extern(C) Object _d_newclass(ClassInfo ci); 
     37 
    3638/** 
    3739    Abstract base class for all DynamicLibrary types for use with DDL. 
     
    4446    public char[][char[]] getAttributes(); 
    4547     
     48    //TODO: implement 
     49    public bit hasDNamespace(char[] name){ 
     50        return false; 
     51    } 
     52     
     53    //TODO: implement 
     54    public DynamicModule getNamespace(char[] name){ 
     55    }    
     56     
     57    //TODO: implement 
     58    public DynamicModule[] getCModules(){ 
     59        return null; 
     60    } 
     61     
     62    //TODO: implement 
     63    public ubyte[] getResource(char[] name){ 
     64        return null; 
     65    } 
     66     
     67    //TODO: implement 
     68    public bit isCModule(){ 
     69        return true; 
     70    } 
     71             
    4672    public void* getExportAddress(char[] name){ 
    4773        return this.getExport(name).address; 
    4874    } 
    4975     
    50     template getField(T, char[] name) 
    51     { 
    52         T getField() { return cast(T)getExportAddress("_D" ~ mangleText!(name) ~ mangleType!(T)); } 
     76    template getDExport(T, char [] name) { 
     77        static if(T.mangleof[0] == 'P'){ 
     78            typeof(T) getDExport() { return cast(typeof(T))getExportAddress( "_D" ~  mangleText!(name) ~ sliceheadoff!(T.mangleof, 1)); } 
     79        } else{ 
     80            typeof(T) getDExport() { return cast(typeof(T))getExportAddress("_D" ~  mangleText!(name) ~ T.mangleof); } 
     81        } 
     82    } 
     83    /* 
     84    TODO: investigate the proper mangle code for these 
     85     
     86    template getClassInfo(char[] classname){ 
     87        ClassInfo getClassinfo(){ 
     88            return cast(ClassInfo)getExportAddress("__Class_" ~  mangleText!(name)); 
     89        } 
    5390    } 
    5491     
    55     template getFunction(RetT, char [] name) 
    56     { 
    57        RetT function() getFunction() { return cast(RetT function() )getExportAddress("_D" ~ mangleText!(name) ~ "F" ~ "Z" ~ mangleType!(RetT)); } 
     92    template getCtor(Tfn, char[] classname){ 
     93        typeof(Tfn) getCtor(){  
     94            //TODO: hack up the mangleof of Tfn, to replace the return type as the correct type. 
     95            return cast(typeof(Tfn))getExportAddress( "_D" ~  mangleText!(classname) ~ "_ctor" ~ Tfn.mangleof ~  mangleText!(classname));  
     96        } 
    5897    } 
    5998     
    60     template getFunction(RetT, char [] name, P1) 
    61     { 
    62        RetT function(P1) getFunction() { return cast(RetT function(P1))getExportAddress("_D" ~ mangleText!(name) ~ "F" ~ mangleType!(P1) ~ "Z" ~ mangleType!(RetT)); 
    63        } 
    64     } 
    65      
    66     template getFunction(RetT, char [] name, P1, P2) 
    67     { 
    68        RetT function(P1, P2) getFunction() { return cast(RetT function(P1, P2))getExportAddress("_D" ~ 
    69        mangleText!(name) ~ "F" ~ mangleType!(P1) ~ mangleType!(P2) ~ "Z" ~ mangleType!(RetT)); 
    70        } 
    71     }    
     99    template createObject(char[] classname){ 
     100        Object createObject(){ 
     101            auto typeClass = getClassInfo!(classname)(); 
     102            auto objClass = _d_newclass(typeTestClass); 
     103            auto ctorClass = getCtor!(Object function(Object),classname)(); 
     104            return ctorClass(objClass); 
     105        } 
     106    }*/ 
    72107} 
  • trunk/ddl/Linker.d

    r85 r94  
    6161    */ 
    6262    public this(DynamicModule reason){ 
    63         super("LinkException: '" ~ reason.getName ~ "'"); 
     63        super("LinkException: cannot resolve '" ~ reason.getName ~ "'\n" ~ reason.toString()); 
    6464        this.mod = reason; 
    6565    } 
  • trunk/ddl/Mangle.d

    r77 r94  
    3838import meta.strhacks; 
    3939 
    40 // Mangle individual parameters 
    41 template mangleType(T) 
    42 { 
    43 static assert(0); // unsupported type 
    44 } 
    45  
    46 // can't use const char, result might not be known at compile time. 
    47 template mangleType(T: T*) 
    48 { char [] mangleType = "P" ~ .mangleType!(T); 
    49 } 
    50  
    51 // Mangling of fundamental types 
    52  
    53 template mangleType(T : void) 
    54 { const char [] mangleType = "v"; 
    55 } 
    56  
    57 template mangleType(T : bit) 
    58 { const char [] mangleType = "b"; 
    59 } 
    60  
    61 template mangleType(T : byte) 
    62 { const char [] mangleType = "g"; 
    63 } 
    64  
    65 template mangleType(T : ubyte) 
    66 { const char [] mangleType = "h"; 
    67 } 
    68  
    69 template mangleType(T : short) 
    70 { const char [] mangleType = "s"; 
    71 } 
    72  
    73 template mangleType(T : ushort) 
    74 { const char [] mangleType = "t"; 
    75 } 
    76  
    77 template mangleType(T : int) 
    78 { const char [] mangleType = "i"; 
    79 } 
    80  
    81 template mangleType(T : uint) 
    82 { const char [] mangleType = "k"; 
    83 } 
    84  
    85 template mangleType(T : long) 
    86 { const char [] mangleType = "l"; 
    87 } 
    88  
    89 template mangleType(T : ulong) 
    90 { const char [] mangleType = "m"; 
    91 } 
    92  
    93 template mangleType(T : float) 
    94 { const char [] mangleType = "f"; 
    95 } 
    96  
    97 template mangleType(T : double) 
    98 { const char [] mangleType = "d"; 
    99 } 
    100  
    101 template mangleType(T : real) 
    102 { const char [] mangleType = "e"; 
    103 } 
    104  
    105 template mangleType(T : ifloat) 
    106 { const char [] mangleType = "o"; 
    107 } 
    108  
    109 template mangleType(T : idouble) 
    110 { const char [] mangleType = "p"; 
    111 } 
    112  
    113 template mangleType(T : ireal) 
    114 { const char [] mangleType = "j"; 
    115 } 
    116  
    117 template mangleType(T : cfloat) 
    118 { const char [] mangleType = "q"; 
    119 } 
    120  
    121 template mangleType(T : cdouble) 
    122 { const char [] mangleType = "r"; 
    123 } 
    124  
    125 template mangleType(T : creal) 
    126 { const char [] mangleType = "c"; 
    127 } 
    128  
    129 template mangleType(T : char) 
    130 { const char [] mangleType = "a"; 
    131 } 
    132  
    133 template mangleType(T : wchar) 
    134 { const char [] mangleType = "u"; 
    135 } 
    136  
    137 template mangleType(T : dchar) 
    138 { const char [] mangleType = "w"; 
    139 } 
    140  
    14140template mangleText(char[] text, char [] latestword="") 
    14241{ 
  • trunk/ddl/Utils.d

    r92 r94  
    3434    alias writefln debugLog; 
    3535     
     36    //char[] uintToString(uint value){ 
     37    //  return std.string.toString(value); 
     38    //} 
     39     
    3640    struct DDLFile{ 
    3741        ubyte[] buffer; 
     
    5054        void load(char[] filename){ 
    5155            this.filename = filename; 
    52             debugLog(filename); 
     56            debug debugLog("[DDLFile.load]: " ~ filename); 
    5357            assert(std.file.exists(filename)); 
    5458            buffer = cast(ubyte[])std.file.read(filename); 
  • trunk/ddl/coff/COFF.d

    r55 r94  
     1/+ 
     2    Copyright (c) 2005 J Duncan, Eric Anderton 
     3         
     4    Permission is hereby granted, free of charge, to any person 
     5    obtaining a copy of this software and associated documentation 
     6    files (the "Software"), to deal in the Software without 
     7    restriction, including without limitation the rights to use, 
     8    copy, modify, merge, publish, distribute, sublicense, and/or 
     9    sell copies of the Software, and to permit persons to whom the 
     10    Software is furnished to do so, subject to the following 
     11    conditions: 
     12 
     13    The above copyright notice and this permission notice shall be 
     14    included in all copies or substantial portions of the Software. 
     15 
     16    THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 
     17    EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES 
     18    OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 
     19    NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT 
     20    HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, 
     21    WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 
     22    FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR 
     23    OTHER DEALINGS IN THE SOFTWARE. 
     24+/ 
    125module ddl.coff.COFF; 
    226// Microsoft PE-COFF data structures & constants 
  • trunk/ddl/coff/COFFBinary.d

    r55 r94  
     1/+ 
     2    Copyright (c) 2005 J Duncan, Eric Anderton 
     3         
     4    Permission is hereby granted, free of charge, to any person 
     5    obtaining a copy of this software and associated documentation 
     6    files (the "Software"), to deal in the Software without 
     7    restriction, including without limitation the rights to use, 
     8    copy, modify, merge, publish, distribute, sublicense, and/or 
     9    sell copies of the Software, and to permit persons to whom the 
     10    Software is furnished to do so, subject to the following 
     11    conditions: 
     12 
     13    The above copyright notice and this permission notice shall be 
     14    included in all copies or substantial portions of the Software. 
     15 
     16    THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 
     17    EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES 
     18    OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 
     19    NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT 
     20    HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, 
     21    WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 
     22    FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR 
     23    OTHER DEALINGS IN THE SOFTWARE. 
     24+/ 
    125module ddl.coff.COFFBinary; 
    226 
  • trunk/ddl/coff/COFFImage.d

    r85 r94  
     1/+ 
     2    Copyright (c) 2005 J Duncan, Eric Anderton 
     3         
     4    Permission is hereby granted, free of charge, to any person 
     5    obtaining a copy of this software and associated documentation 
     6    files (the "Software"), to deal in the Software without 
     7    restriction, including without limitation the rights to use, 
     8    copy, modify, merge, publish, distribute, sublicense, and/or 
     9    sell copies of the Software, and to permit persons to whom the 
     10    Software is furnished to do so, subject to the following 
     11    conditions: 
     12 
     13    The above copyright notice and this permission notice shall be 
     14    included in all copies or substantial portions of the Software. 
     15 
     16    THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 
     17    EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES 
     18    OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 
     19    NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT 
     20    HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, 
     21    WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 
     22    FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR 
     23    OTHER DEALINGS IN THE SOFTWARE. 
     24+/ 
    125module ddl.coff.COFFImage; 
    226//////////////////////////////////////////////////////////////////////////////////////////////////////////////// 
  • trunk/ddl/coff/COFFLibrary.d

    r85 r94  
     1/+ 
     2    Copyright (c) 2005 J Duncan, Eric Anderton 
     3         
     4    Permission is hereby granted, free of charge, to any person 
     5    obtaining a copy of this software and associated documentation 
     6    files (the "Software"), to deal in the Software without 
     7    restriction, including without limitation the rights to use, 
     8    copy, modify, merge, publish, distribute, sublicense, and/or 
     9    sell copies of the Software, and to permit persons to whom the 
     10    Software is furnished to do so, subject to the following 
     11    conditions: 
     12 
     13    The above copyright notice and this permission notice shall be 
     14    included in all copies or substantial portions of the Software. 
     15 
     16    THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 
     17    EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES 
     18    OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 
     19    NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT 
     20    HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, 
     21    WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 
     22    FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR 
     23    OTHER DEALINGS IN THE SOFTWARE. 
     24+/ 
    125module ddl.coff.COFFLibrary; 
    226 
     
    3862    public this() 
    3963    { 
     64        filename = "<unknown>"; 
    4065    } 
    4166 
     
    7196        if(name in dictionary)  
    7297            return dictionary[name]; 
    73         throw new Exception("Symbol " ~ name ~ " not found in library."); 
     98        throw new Exception("Symbol " ~ name ~ " not found in library " ~ this.filename ~ "."); 
    7499    } 
    75100 
  • trunk/ddl/coff/COFFLoader.d

    r85 r94  
     1/+ 
     2    Copyright (c) 2005 J Duncan, Eric Anderton 
     3         
     4    Permission is hereby granted, free of charge, to any person 
     5    obtaining a copy of this software and associated documentation 
     6    files (the "Software"), to deal in the Software without 
     7    restriction, including without limitation the rights to use, 
     8    copy, modify, merge, publish, distribute, sublicense, and/or 
     9    sell copies of the Software, and to permit persons to whom the 
     10    Software is furnished to do so, subject to the following 
     11    conditions: 
     12 
     13    The above copyright notice and this permission notice shall be 
     14    included in all copies or substantial portions of the Software. 
     15 
     16    THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 
     17    EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES 
     18    OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 
     19    NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT 
     20    HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, 
     21    WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 
     22    FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR 
     23    OTHER DEALINGS IN THE SOFTWARE. 
     24+/ 
    125module ddl.coff.COFFLoader; 
    226 
  • trunk/ddl/coff/COFFModule.d

    r85 r94  
     1/+ 
     2    Copyright (c) 2005 J Duncan, Eric Anderton 
     3         
     4    Permission is hereby granted, free of charge, to any person 
     5    obtaining a copy of this software and associated documentation 
     6    files (the "Software"), to deal in the Software without 
     7    restriction, including without limitation the rights to use, 
     8    copy, modify, merge, publish, distribute, sublicense, and/or 
     9    sell copies of the Software, and to permit persons to whom the 
     10    Software is furnished to do so, subject to the following 
     11    conditions: 
     12 
     13    The above copyright notice and this permission notice shall be 
     14    included in all copies or substantial portions of the Software. 
     15 
     16    THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 
     17    EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES 
     18    OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 
     19    NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT 
     20    HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, 
     21    WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 
     22    FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR 
     23    OTHER DEALINGS IN THE SOFTWARE. 
     24+/ 
    125// COFF Object module class 
    226 
  • trunk/ddl/coff/COFFObject.d

    r85 r94  
     1/+ 
     2    Copyright (c) 2005 J Duncan, Eric Anderton 
     3         
     4    Permission is hereby granted, free of charge, to any person 
     5    obtaining a copy of this software and associated documentation 
     6    files (the "Software"), to deal in the Software without 
     7    restriction, including without limitation the rights to use, 
     8    copy, modify, merge, publish, distribute, sublicense, and/or 
     9    sell copies of the Software, and to permit persons to whom the 
     10    Software is furnished to do so, subject to the following 
     11    conditions: 
     12 
     13    The above copyright notice and this permission notice shall be 
     14    included in all copies or substantial portions of the Software. 
     15 
     16    THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 
     17    EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES 
     18    OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 
     19    NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT 
     20    HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, 
     21    WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 
     22    FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR 
     23    OTHER DEALINGS IN THE SOFTWARE. 
     24+/ 
    125module ddl.coff.COFFObject; 
    226 
  • trunk/ddl/coff/COFFWrite.d

    r85 r94  
     1/+ 
     2    Copyright (c) 2005 J Duncan, Eric Anderton 
     3         
     4    Permission is hereby granted, free of charge, to any person 
     5    obtaining a copy of this software and associated documentation 
     6    files (the "Software"), to deal in the Software without 
     7    restriction, including without limitation the rights to use, 
     8    copy, modify, merge, publish, distribute, sublicense, and/or 
     9    sell copies of the Software, and to permit persons to whom the 
     10    Software is furnished to do so, subject to the following 
     11    conditions: 
     12 
     13    The above copyright notice and this permission notice shall be 
     14    included in all copies or substantial portions of the Software. 
     15 
     16    THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 
     17    EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES 
     18    OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 
     19    NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT 
     20    HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, 
     21    WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 
     22    FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR 
     23    OTHER DEALINGS IN THE SOFTWARE. 
     24+/ 
    125module ddl.coff.COFFWrite; 
    226// utils for writing out PE-COFF data structures 
  • trunk/ddl/coff/cursor.d

    r58 r94  
    11/+ 
    2     Copyright (c) 2005 Eric Anderton 
    3  
     2    Copyright (c) 2005 J Duncan, Eric Anderton 
     3         
    44    Permission is hereby granted, free of charge, to any person 
    55    obtaining a copy of this software and associated documentation 
     
    2323    OTHER DEALINGS IN THE SOFTWARE. 
    2424+/ 
    25  
    2625module ddl.coff.cursor; 
    2726 
  • trunk/ddl/ddl/DDLLibrary.d

    r85 r94  
    5656    public char[][char[]] getAttributes(){ 
    5757        return binary.attributes; 
    58     }           
     58    } 
    5959         
    6060    public ExportSymbol[] getExports(){ 
  • trunk/ddl/insitu/InSituLibrary.d

    r92 r94  
    3131private import ddl.insitu.InSituModule; 
    3232 
     33//TODO: In-Situ should be upgraded to split symbols into a C-level module and a D-level module. 
    3334class InSituLibrary : DynamicLibrary{ 
    3435    DynamicModule[] modules; 
  • trunk/ddl/omf/OMFBinary.d

    r92 r94  
    834834     
    835835    bit isResolved(){ 
    836         debug printf("unresolved fixups: %d\n",unresolvedFixups.length); 
     836        debug debugLog("unresolved fixups: %d\n",unresolvedFixups.length); 
    837837        return this.unresolvedFixups.length == 0; 
    838838    } 
  • trunk/ddl/omf/OMFLibrary.d

    r85 r94  
    3535    DynamicModule[] modules; 
    3636    ExportSymbol[char[]] dictionary; 
     37    char[][char[]] attributes; 
    3738    char[] filename; 
    3839 
    3940    public this(){ 
     41        this.filename = "<unknown>"; 
    4042    } 
    4143     
    4244    public this(DDLFile file){ 
     45        attributes["omf.filename"] = file.filename; 
    4346        this.filename = file.filename; 
    4447        load(file.buffer); 
     
    5053     
    5154    public char[][char[]] getAttributes(){ 
    52         return (char[][char[]]).init; //TODO: support this 
    53     }   
     55        return attributes; 
     56    } 
    5457     
    5558    public ExportSymbol[] getExports(){ 
     
    5962    public ExportSymbol getExport(char[] name){ 
    6063        if(name in dictionary) return dictionary[name]; 
    61         throw new Exception("Symbol " ~ name ~ " not found in library."); 
     64        throw new Exception("Symbol " ~ name ~ " not found in library " ~ this.filename ~ "."); 
    6265    } 
    6366     
  • trunk/test/linktest1.d

    r59 r94  
    1 /* 
    2     Copyright (c) 2005 Eric Anderton 
    3          
    4     Permission is hereby granted, free of charge, to any person 
    5     obtaining a copy of this software and associated documentation 
    6     files (the "Software"), to deal in the Software without 
    7     restriction, including without limitation the rights to use, 
    8     copy, modify, merge, publish, distribute, sublicense, and/or 
    9     sell copies of the Software, and to permit persons to whom the 
    10     Software is furnished to do so, subject to the following 
    11     conditions: 
     1module test.linktest1; 
    122 
    13     The above copyright notice and this permission notice shall be 
    14     included in all copies or substantial portions of the Software. 
     3import ddl.Linker; 
     4import ddl.all; 
    155 
    16     THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 
    17     EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES 
    18     OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 
    19     NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT 
    20     HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, 
    21     WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 
    22     FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR 
    23     OTHER DEALINGS IN THE SOFTWARE. 
     6/** 
     7    Basic Linkage test 
     8    - loads external in-situ module 
     9    - loads phobos 
     10    - loads snn 
     11    - loads the actual test module 
     12    - gets exports for the add function and hello world functions 
     13    - tests those exported handles 
    2414*/ 
    25 module test.test9; 
    26  
    27 private import ddl.all; 
    28 private import ddl.omf.OMFModule; 
    29  
    30 private import std.stdio; 
    31 private import std.moduleinit; 
    32  
    33 alias uint function(uint a,uint b) AddFunction; 
    34 char[] addFunctionSignature = "_D4test10testmodule3addFkkZk"; 
    35  
    36 alias void function() HelloWorldFunction; 
    37 char[] helloWorldFunctionSignature = "_D4test10testmodule10helloWorldFZv"; 
    38  
    39 char[] testmoduleModuleInfo = "__ModuleInfo_4test10testmodule"; 
    40  
    41 void initModule(ModuleInfo m, int skip){ 
    42     if(!m) return; 
    43     if (m.flags & MIctordone) return; 
     15void main(){ 
     16    Stdout.println("Starting."); 
    4417     
    45     debug printf("Module: %.*s %0.8X\n",m.name,m); 
    46     if (m.ctor || m.dtor) 
    47     { 
    48         if (m.flags & MIctorstart) 
    49         {   if (skip) 
    50             return; 
    51         throw new ModuleCtorError(m); 
    52         } 
    53         m.flags |= MIctorstart; 
    54         foreach(ModuleInfo imported; m.importedModules){ 
    55             initModule(imported,0); 
    56         } 
    57         if (m.ctor) 
    58         (*m.ctor)(); 
    59         m.flags &= ~MIctorstart; 
    60         m.flags |= MIctordone; 
    61  
    62         //TODO: Now that construction is done, register the destructor 
    63     } 
    64     else 
    65     { 
    66          
    67         m.flags |= MIctordone; 
    68         foreach(ModuleInfo imported; m.importedModules){ 
    69             initModule(imported,1); 
    70         } 
    71     }     
     18    auto linker = new Linker(new DefaultRegistry()); 
     19    linker.loadAndRegister("test\\linktest1.ddl"); 
     20    linker.loadAndRegister("phobos.lib"); 
     21    linker.loadAndRegister("snn.lib"); 
     22     
     23    Stdout.println("Loading test module"); 
     24    auto testLibrary = linker.loadAndLink("test\\testmodule.obj"); 
     25     
     26    auto addFun = testLibrary.getDExport!(uint function(uint,uint),"test.testmodule.add")(); 
     27    auto helloWorld = testLibrary.getDExport!(void function(),"test.testmodule.helloWorld")(); 
     28     
     29    Stdout.println("add: 42+69 = %d",addFun(42,69)); 
     30    helloWorld(); 
     31     
     32    Stdout.println("Done."); 
    7233} 
    73  
    74 // module cross-reference - provides a lookup for modules by namespace 
    75 DynamicModule[char[]] moduleXRef; 
    76 DynamicModule[char[]] miscModules; 
    77 DynamicModule[char[]] specialModules; // std.object and minit go here 
    78  
    79  
    80 // adds library modules to the cross-reference.  Modules already present have precedence. 
    81 void addLibraryToXRef(DynamicLibrary lib){ 
    82     foreach(DynamicModule mod; lib.getModules){ 
    83         char[] name = mod.getName; 
    84         debug printf("xref: %.*s",name); 
    85         if(name == "internal.minit.asm"){ 
    86             debug printf("Minit: %.*s\n",(cast(OMFModule)mod).toString());   
    87         } 
    88          
    89         // special modules go here 
    90         if(name == "" || name == "std.object" || name == "internal.minit.asm" || (name.length >= 12 && name[0..12] == "std.typeinfo")){ 
    91             if(!(name in moduleXRef)){       
    92                 specialModules[name] = mod; 
    93                 debug printf(" (special)"); 
    94             } 
    95         } 
    96         // d language modules go to the xref 
    97         else if(name[($-2)..$] == ".d"){ 
    98             if(!(name in moduleXRef)){               
    99                 moduleXRef[name] = mod; 
    100                 debug printf(" (Xref)"); 
    101             } 
    102         } 
    103         // everything else goes to the misc category 
    104         else{ 
    105             if(!(name in miscModules)){  
    106                 miscModules[name] = mod; 
    107                 debug printf(" (misc)"); 
    108             } 
    109         } 
    110         debug printf("\n"); 
    111     }    
    112 } 
    113  
    114 bit supportsDependency(DynamicModule src,DynamicModule external){ 
    115     foreach(char[] dep; src.getDependencies){ 
    116         foreach(ExportSymbol sym; external.getExports){ 
    117             if(dep == sym.name){ 
    118                 debug printf("\nmodule '%.*s' supports '%.*s' ('%.*s')\n",external.getName,src.getName,dep); 
    119                  return true; 
    120             } 
    121         } 
    122     } 
    123     return false; 
    124 } 
    125  
    126 // links a new module into the xref 
    127 void linkModule(DynamicModule mod){ 
    128     static int level = 0; 
    129     level++; 
    130     debug printf("[%d] resolving: %.*s\n",level,mod.getName); 
    131     foreach(char[] dep; mod.getDependencies){ 
    132         debug printf("%.*s\n",dep); 
    133     } 
    134  
    135     // always attempt the special modules first 
    136     debug printf("resolving specials..."); 
    137     foreach(DynamicModule externalModule; specialModules.values){ 
    138         if(supportsDependency(mod,externalModule)){ 
    139             if(!externalModule.isResolved){ 
    140                 linkModule(externalModule); 
    141             } 
    142             mod.resolveDependencies(externalModule.getExports); 
    143             if(mod.isResolved) break; 
    144         } 
    145     } 
    146     debug printf("done\n"); 
    147          
    148     // is there still more?  Try the D module imports 
    149     if(!mod.isResolved()){ 
    150         debug printf("resolving d modules..."); 
    151         foreach(char[] dep; mod.getDependencies){ 
    152             if(getSymbolType(dep) == SymbolType.ModuleInfo){ 
    153                 // get a module namespace to work with 
    154                 SymbolType dummy; 
    155                 char[] name = demangleSymbol(dep,dummy); 
    156                 debug printf(" %.*s",name); 
    157                  
    158                 // dig up the referenced external module 
    159                 DynamicModule externalModule = moduleXRef[name~".d"]; 
    160                 if(!externalModule) throw new Exception("cannot find module '" ~ name ~ "'"); 
    161                  
    162                 // recursive linking - only link modules if they are fully resolved 
    163                 if(!externalModule.isResolved){ 
    164                     linkModule(externalModule); 
    165                 } 
    166                  
    167                 // link in this module 
    168                 mod.resolveDependencies(externalModule.getExports); 
    169             } 
    170         } 
    171         debug printf("done\n"); 
    172     } 
    173      
    174     // more? Try everything else 
    175     if(!mod.isResolved()){ 
    176         debug printf("resolving misc modules..."); 
    177         foreach(DynamicModule externalModule; miscModules.values){ 
    178             if(supportsDependency(mod,externalModule)){ 
    179                 if(!externalModule.isResolved) linkModule(externalModule); 
    180                 mod.resolveDependencies(externalModule.getExports); 
    181                 if(mod.isResolved) break; 
    182             } 
    183         } 
    184         debug printf("done.\n"); 
    185     } 
    186      
    187     // did it work? Throw an exception since there's nothing more to be done 
    188     if(!mod.isResolved()){ 
    189         char[] dump; 
    190         foreach(char[] dep; mod.getDependencies){ 
    191             dump ~= "\n" ~ dep; 
    192         } 
    193         throw new Exception("module: " ~ mod.getName ~ " cannot be fully resolved." ~ dump); 
    194     } 
    195      
    196     // brute-force search for the module ctor (if it exists) 
    197     debug printf("ctor search..."); 
    198     foreach(ExportSymbol sym; mod.getExports){ 
    199         if(getSymbolType(sym.name) == SymbolType.ModuleInfo){ 
    200             // found it, now get it and run the constructor 
    201             ModuleInfo moduleInfo = cast(ModuleInfo)(sym.address); 
    202             initModule(moduleInfo,0); 
    203         } 
    204     } 
    205     debug printf("done\n[%d] done resolving %.*s\n",level,mod.getName); 
    206     level--; 
    207 } 
    208  
    209  
    210  
    211 // dynamically link in an entire library 
    212 void linkLibrary(DynamicLibrary lib){ 
    213     foreach(DynamicModule mod; lib.getModules()){ 
    214         if(!mod.isResolved()){ 
    215             linkModule(mod); 
    216         } 
    217     } 
    218 } 
    219  
    220 void main(){     
    221     // pull in the in situ module (all the currently compiled-in support) 
    222     addLibraryToXRef(loadDDL("test.map")); 
    223          
    224     // get runtime libraries 
    225     addLibraryToXRef(loadDDL("phobos.lib")); 
    226     addLibraryToXRef(loadDDL("snn.lib")); 
    227          
    228     // load in the test module 
    229     DynamicLibrary testModule = loadDDL("testmodule.obj"); 
    230  
    231     // perform a dynamic link for this module 
    232     linkLibrary(testModule); 
    233          
    234     // add test 
    235     AddFunction addFunc = cast(AddFunction)(testModule.getExport(addFunctionSignature).address); 
    236     writefln("add: 42+69 = %d",addFunc(42,69)); 
    237      
    238     // hello world test 
    239     HelloWorldFunction helloWorld = cast(HelloWorldFunction)(testModule.getExport(helloWorldFunctionSignature).address); 
    240     helloWorld(); 
    241          
    242     // run module destructor (NOT RECCOMENDED -- leaves class instances stranded, but does work) 
    243     //ModuleInfo moduleInfo = cast(ModuleInfo)(testModule.getExport(testmoduleModuleInfo).address); 
    244     //if(moduleInfo.dtor){ 
    245     //  (*moduleInfo.dtor)(); 
    246     //} 
    247 } 
  • trunk/utils/bless.d

    r91 r94  
    3232private import ddl.ddl.DDLBinary; 
    3333 
    34 private import utils.ddlinfo_bn; 
     34private import utils.bless_bn; 
    3535private import utils.ArgParser; 
    3636 
     
    5252  -n       no-create (for test purposes) 
    5353  -f<file> output to file 'file' (overrides default name) 
    54   -a<attr> adds an attribute name=value) to the ddl 
     54  -a<attr> adds an attribute (name=value) to the ddl 
    5555  -p<file> uses the property file 'file' for attributes 
    5656   
     
    112112     
    113113    void parseAttribute(char[] line){ 
    114         if(line[0] == '#') return; 
     114        if(line.length == 0 || line[0] == '#') return; 
    115115        uint split; 
    116116        for(split=0; split<line.length && line[split] != '='; split++){} // token 
  • trunk/utils/insitu.d

    r91 r94  
    3030 
    3131private import ddl.all; 
     32private import ddl.Utils; 
    3233private import ddl.insitu.all; 
    3334 
    34 private import utils.ddlinfo_bn; 
     35private import utils.insitu_bn; 
    3536private import utils.ArgParser; 
    36  
    3737 
    3838char[] helpText =  
     
    4949   
    5050  -o    Specify output file 
    51   -c    Compression level for data (1-9
     51  -c    Compression level for data (1-9 where 9 is default
    5252   
    5353  When the output file is not specified, a file in the 
     
    5757  by DMD. 
    5858"; 
    59  
    60 //  -d  Create a .d file with a SituLibrary class instead 
     59// -d   Create a .d file with a SituLibrary class instead 
    6160//With the -d switch, <filename>_InSitu.d will be used instead. 
    62    
    6361 
    6462int main(char[][] args){ 
     
    8179    // determine the output file 
    8280    char[] outputFilename = inputFile.getName; 
    83     //bit dOutput = false; 
     81    bit dOutput = false; 
    8482    bit filenameOverride = false; 
    8583     
    86     //TODO: determine the compression level 
    8784    ubyte compressionLevel = 9; 
    8885         
     
    105102    }); 
    106103             
    107    //parser.bind("d",delegate void(){ 
    108    // dOutput = true; 
    109    //}); 
     104// parser.bind("d",delegate void(){ 
     105//    dOutput = true; 
     106// }); 
    110107     
    111108    parser.parse(args[2..$]); 
    112109     
    113110    // load the .map file and get what we need 
    114     //TODO: load via registry instead, and use DynamicLibrary 
    115111    inputFile.load(); 
    116112    InSituMapBinary inputBinary = new InSituMapBinary(); 
     
    124120    outputFile.create(outputFilename);   
    125121         
    126    //if(!dOutput){ 
     122//