Changeset 35

Show
Ignore:
Timestamp:
10/23/05 19:30:36 (3 years ago)
Author:
pragma
Message:

- Updated project organization: utils are now in their own subdirectory away from the project root.
- Added test9 - primitive runtime linking example

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/test.d

    r33 r35  
     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: 
     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*/ 
     25module test.test9; 
     26 
    127private import ddl.all; 
    228 
    3 import std.stdio; 
    4 import std.c.windows.windows
     29private import std.stdio; 
     30private import std.moduleinit
    531 
    6 static uint cafebabe = 0xDECAFBAD; 
     32alias uint function(uint a,uint b) AddFunction; 
     33char[] addFunctionSignature = "_D10testmodule3addFkkZk"; 
     34 
     35alias void function() HelloWorldFunction; 
     36char[] helloWorldFunctionSignature = "_D10testmodule10helloWorldFZv"; 
     37 
     38char[] testmoduleModuleInfo = "__ModuleInfo_10testmodule"; 
     39 
     40// first attempt at fully-dynamic linking 
    741 
    842void main(){ 
    9     DynamicLibrary lib = loadDDL("test.map"); 
     43    // pull in the in situ module (all the currently compiled-in support) 
     44    DynamicLibrary insitu = loadDDL("this.ddl"); 
    1045     
    11     assert(lib); 
     46    // pull in the phobos runtime 
     47    //DynamicLibrary phobos = loadDDL("phobos.ddl"); 
     48         
     49    // load in the test module 
     50    DynamicLibrary testModule = loadDDL("testmodule.ddl"); 
    1251     
    13     writefln("%d exports total",lib.getExports.length); 
     52    // resolve outstanding dependencies 
     53    foreach(DynamicModule mod; testModule.getModules){ 
     54        //brain-dead approach to resolution 
     55        mod.resolveDependencies(insitu.getExports()); 
     56    } 
     57         
     58    // ensure everything is resolved 
     59    foreach(DynamicModule mod; testModule.getModules){ 
     60        if(!mod.isResolved()){ 
     61            char[] dump; 
     62            foreach(char[] dep; mod.getDependencies){ 
     63                dump ~= "\n" ~ dep; 
     64            } 
     65            throw new Exception("module: " ~ mod.getName ~ " cannot be fully resolved." ~ dump); 
     66        } 
     67        mod.resolveDependencies(insitu.getExports()); 
     68    } 
     69         
     70    // run module constructor 
     71    ModuleInfo moduleInfo = cast(ModuleInfo)(testModule.getExport(testmoduleModuleInfo).address); 
     72    (*moduleInfo.ctor)(); 
    1473     
    15     ExportSymbol exp = lib.getExport("_D4test8cafebabek"); 
    16     writefln("%s (%0.8X) == %0.8X",demangleSymbol(exp.name),exp.address,*cast(uint*)(exp.address)); 
     74    // add test 
     75    AddFunction addFunc = cast(AddFunction)(testModule.getExport(addFunctionSignature).address); 
     76    writefln("add: 42+69 = %d",addFunc(42,69)); 
     77     
     78    // hello world test 
     79    HelloWorldFunction helloWorld = cast(HelloWorldFunction)(testModule.getExport(helloWorldFunctionSignature).address); 
     80    helloWorld(); 
     81     
     82    // run module destructor 
     83    if(moduleInfo.dtor){ 
     84        (*moduleInfo.dtor)(); 
     85    } 
    1786} 
  • trunk/utils/ddlinfo.d

    r31 r35  
    5050   
    5151  -e<ext>  interpret the file as type 'ext' instead. 
     52  -r       raw output instead of friendly names/symbols. 
    5253"; 
    5354 
     
    7576         
    7677    // pick through the options (if any) 
     78    bit rawOutput = false; 
    7779    char[] extension = originalExtension; 
    7880     
     
    8486        return value.length; 
    8587    }); 
     88     
     89    parser.bind("r",delegate void(){ 
     90        rawOutput=true; 
     91    });  
    8692     
    8793    parser.parse(args[2..$]);    
     
    115121        foreach(char[] dep; mod.getDependencies){ 
    116122            debug writefln("%s",dep); 
    117             writefln("%s",demangleSymbol(dep)); 
     123            if(rawOutput){ 
     124                writefln("%s",dep); 
     125            } 
     126            else{ 
     127                writefln("%s",demangleSymbol(dep)); 
     128            } 
    118129        } 
    119130         
     
    121132        foreach(ExportSymbol sym; mod.getExports()){ 
    122133            debug writefln("%s",sym.name); 
    123             writefln("%s",demangleSymbol(sym.name)); 
     134            if(rawOutput){ 
     135                writefln("%s",sym.name); 
     136            } 
     137            else{ 
     138                writefln("%s",demangleSymbol(sym.name)); 
     139            } 
    124140        }            
    125141    }