Changeset 35
- Timestamp:
- 10/23/05 19:30:36 (3 years ago)
- Files:
-
- trunk/test.d (modified) (1 diff)
- trunk/test/test8.d (added)
- trunk/test/test9.d (added)
- trunk/test/testmodule.d (added)
- trunk/utils/ddlinfo.d (modified) (5 diffs)
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 */ 25 module test.test9; 26 1 27 private import ddl.all; 2 28 3 import std.stdio;4 import std.c.windows.windows;29 private import std.stdio; 30 private import std.moduleinit; 5 31 6 static uint cafebabe = 0xDECAFBAD; 32 alias uint function(uint a,uint b) AddFunction; 33 char[] addFunctionSignature = "_D10testmodule3addFkkZk"; 34 35 alias void function() HelloWorldFunction; 36 char[] helloWorldFunctionSignature = "_D10testmodule10helloWorldFZv"; 37 38 char[] testmoduleModuleInfo = "__ModuleInfo_10testmodule"; 39 40 // first attempt at fully-dynamic linking 7 41 8 42 void 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"); 10 45 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"); 12 51 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)(); 14 73 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 } 17 86 } trunk/utils/ddlinfo.d
r31 r35 50 50 51 51 -e<ext> interpret the file as type 'ext' instead. 52 -r raw output instead of friendly names/symbols. 52 53 "; 53 54 … … 75 76 76 77 // pick through the options (if any) 78 bit rawOutput = false; 77 79 char[] extension = originalExtension; 78 80 … … 84 86 return value.length; 85 87 }); 88 89 parser.bind("r",delegate void(){ 90 rawOutput=true; 91 }); 86 92 87 93 parser.parse(args[2..$]); … … 115 121 foreach(char[] dep; mod.getDependencies){ 116 122 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 } 118 129 } 119 130 … … 121 132 foreach(ExportSymbol sym; mod.getExports()){ 122 133 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 } 124 140 } 125 141 }
