Changeset 94
- Timestamp:
- 12/28/05 23:42:42 (3 years ago)
- Files:
-
- trunk/ddl/DynamicLibrary.d (modified) (2 diffs)
- trunk/ddl/Linker.d (modified) (1 diff)
- trunk/ddl/Loader.d (deleted)
- trunk/ddl/Mangle.d (modified) (1 diff)
- trunk/ddl/Utils.d (modified) (2 diffs)
- trunk/ddl/coff/COFF.d (modified) (1 diff)
- trunk/ddl/coff/COFFBinary.d (modified) (1 diff)
- trunk/ddl/coff/COFFImage.d (modified) (1 diff)
- trunk/ddl/coff/COFFLibrary.d (modified) (3 diffs)
- trunk/ddl/coff/COFFLoader.d (modified) (1 diff)
- trunk/ddl/coff/COFFModule.d (modified) (1 diff)
- trunk/ddl/coff/COFFObject.d (modified) (1 diff)
- trunk/ddl/coff/COFFWrite.d (modified) (1 diff)
- trunk/ddl/coff/cursor.d (modified) (2 diffs)
- trunk/ddl/ddl/DDLLibrary.d (modified) (1 diff)
- trunk/ddl/insitu/InSituLibrary.d (modified) (1 diff)
- trunk/ddl/omf/OMFBinary.d (modified) (1 diff)
- trunk/ddl/omf/OMFLibrary.d (modified) (3 diffs)
- trunk/ddl/omf/OMFRecordCursor.d (added)
- trunk/ddl/omf/RecordCursor.d (deleted)
- trunk/test/all.d (deleted)
- trunk/test/linktest1.d (modified) (1 diff)
- trunk/test/linktest2.d (deleted)
- trunk/test/linktest3.d (deleted)
- trunk/test/linktest4.d (deleted)
- trunk/test/mangle.test1.d (deleted)
- trunk/test/test1.d (deleted)
- trunk/test/test2.d (deleted)
- trunk/test/test3.d (deleted)
- trunk/test/test4.d (deleted)
- trunk/test/test5.d (deleted)
- trunk/test/test6.d (deleted)
- trunk/test/test7.d (deleted)
- trunk/test/test8.d (deleted)
- trunk/test/test9.d (deleted)
- trunk/test/testCOFF.cpp (deleted)
- trunk/test/testc.d (deleted)
- trunk/utils/bless.d (modified) (3 diffs)
- trunk/utils/bless_bn.d (added)
- trunk/utils/ddlinfo_bn.d (added)
- trunk/utils/insitu.d (modified) (7 diffs)
- trunk/utils/insitu_bn.d (added)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/ddl/DynamicLibrary.d
r85 r94 34 34 private import ddl.Mangle; 35 35 36 extern(C) Object _d_newclass(ClassInfo ci); 37 36 38 /** 37 39 Abstract base class for all DynamicLibrary types for use with DDL. … … 44 46 public char[][char[]] getAttributes(); 45 47 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 46 72 public void* getExportAddress(char[] name){ 47 73 return this.getExport(name).address; 48 74 } 49 75 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 } 53 90 } 54 91 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 } 58 97 } 59 98 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 }*/ 72 107 } trunk/ddl/Linker.d
r85 r94 61 61 */ 62 62 public this(DynamicModule reason){ 63 super("LinkException: '" ~ reason.getName ~ "'");63 super("LinkException: cannot resolve '" ~ reason.getName ~ "'\n" ~ reason.toString()); 64 64 this.mod = reason; 65 65 } trunk/ddl/Mangle.d
r77 r94 38 38 import meta.strhacks; 39 39 40 // Mangle individual parameters41 template mangleType(T)42 {43 static assert(0); // unsupported type44 }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 types52 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 141 40 template mangleText(char[] text, char [] latestword="") 142 41 { trunk/ddl/Utils.d
r92 r94 34 34 alias writefln debugLog; 35 35 36 //char[] uintToString(uint value){ 37 // return std.string.toString(value); 38 //} 39 36 40 struct DDLFile{ 37 41 ubyte[] buffer; … … 50 54 void load(char[] filename){ 51 55 this.filename = filename; 52 debug Log(filename);56 debug debugLog("[DDLFile.load]: " ~ filename); 53 57 assert(std.file.exists(filename)); 54 58 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 +/ 1 25 module ddl.coff.COFF; 2 26 // 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 +/ 1 25 module ddl.coff.COFFBinary; 2 26 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 +/ 1 25 module ddl.coff.COFFImage; 2 26 //////////////////////////////////////////////////////////////////////////////////////////////////////////////// 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 +/ 1 25 module ddl.coff.COFFLibrary; 2 26 … … 38 62 public this() 39 63 { 64 filename = "<unknown>"; 40 65 } 41 66 … … 71 96 if(name in dictionary) 72 97 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 ~ "."); 74 99 } 75 100 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 +/ 1 25 module ddl.coff.COFFLoader; 2 26 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 +/ 1 25 // COFF Object module class 2 26 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 +/ 1 25 module ddl.coff.COFFObject; 2 26 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 +/ 1 25 module ddl.coff.COFFWrite; 2 26 // utils for writing out PE-COFF data structures trunk/ddl/coff/cursor.d
r58 r94 1 1 /+ 2 Copyright (c) 2005 Eric Anderton3 2 Copyright (c) 2005 J Duncan, Eric Anderton 3 4 4 Permission is hereby granted, free of charge, to any person 5 5 obtaining a copy of this software and associated documentation … … 23 23 OTHER DEALINGS IN THE SOFTWARE. 24 24 +/ 25 26 25 module ddl.coff.cursor; 27 26 trunk/ddl/ddl/DDLLibrary.d
r85 r94 56 56 public char[][char[]] getAttributes(){ 57 57 return binary.attributes; 58 } 58 } 59 59 60 60 public ExportSymbol[] getExports(){ trunk/ddl/insitu/InSituLibrary.d
r92 r94 31 31 private import ddl.insitu.InSituModule; 32 32 33 //TODO: In-Situ should be upgraded to split symbols into a C-level module and a D-level module. 33 34 class InSituLibrary : DynamicLibrary{ 34 35 DynamicModule[] modules; trunk/ddl/omf/OMFBinary.d
r92 r94 834 834 835 835 bit isResolved(){ 836 debug printf("unresolved fixups: %d\n",unresolvedFixups.length);836 debug debugLog("unresolved fixups: %d\n",unresolvedFixups.length); 837 837 return this.unresolvedFixups.length == 0; 838 838 } trunk/ddl/omf/OMFLibrary.d
r85 r94 35 35 DynamicModule[] modules; 36 36 ExportSymbol[char[]] dictionary; 37 char[][char[]] attributes; 37 38 char[] filename; 38 39 39 40 public this(){ 41 this.filename = "<unknown>"; 40 42 } 41 43 42 44 public this(DDLFile file){ 45 attributes["omf.filename"] = file.filename; 43 46 this.filename = file.filename; 44 47 load(file.buffer); … … 50 53 51 54 public char[][char[]] getAttributes(){ 52 return (char[][char[]]).init; //TODO: support this53 } 55 return attributes; 56 } 54 57 55 58 public ExportSymbol[] getExports(){ … … 59 62 public ExportSymbol getExport(char[] name){ 60 63 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 ~ "."); 62 65 } 63 66 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: 1 module test.linktest1; 12 2 13 The above copyright notice and this permission notice shall be 14 included in all copies or substantial portions of the Software. 3 import ddl.Linker; 4 import ddl.all; 15 5 16 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 17 EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES18 OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND19 NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT20 HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,21 WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING22 FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR23 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 24 14 */ 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; 15 void main(){ 16 Stdout.println("Starting."); 44 17 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."); 72 33 } 73 74 // module cross-reference - provides a lookup for modules by namespace75 DynamicModule[char[]] moduleXRef;76 DynamicModule[char[]] miscModules;77 DynamicModule[char[]] specialModules; // std.object and minit go here78 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 here90 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 xref97 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 category104 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 xref127 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 first136 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 imports149 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 with154 SymbolType dummy;155 char[] name = demangleSymbol(dep,dummy);156 debug printf(" %.*s",name);157 158 // dig up the referenced external module159 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 resolved163 if(!externalModule.isResolved){164 linkModule(externalModule);165 }166 167 // link in this module168 mod.resolveDependencies(externalModule.getExports);169 }170 }171 debug printf("done\n");172 }173 174 // more? Try everything else175 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 done188 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 constructor201 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 library212 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 libraries225 addLibraryToXRef(loadDDL("phobos.lib"));226 addLibraryToXRef(loadDDL("snn.lib"));227 228 // load in the test module229 DynamicLibrary testModule = loadDDL("testmodule.obj");230 231 // perform a dynamic link for this module232 linkLibrary(testModule);233 234 // add test235 AddFunction addFunc = cast(AddFunction)(testModule.getExport(addFunctionSignature).address);236 writefln("add: 42+69 = %d",addFunc(42,69));237 238 // hello world test239 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 32 32 private import ddl.ddl.DDLBinary; 33 33 34 private import utils. ddlinfo_bn;34 private import utils.bless_bn; 35 35 private import utils.ArgParser; 36 36 … … 52 52 -n no-create (for test purposes) 53 53 -f<file> output to file 'file' (overrides default name) 54 -a<attr> adds an attribute name=value) to the ddl54 -a<attr> adds an attribute (name=value) to the ddl 55 55 -p<file> uses the property file 'file' for attributes 56 56 … … 112 112 113 113 void parseAttribute(char[] line){ 114 if(line [0] == '#') return;114 if(line.length == 0 || line[0] == '#') return; 115 115 uint split; 116 116 for(split=0; split<line.length && line[split] != '='; split++){} // token trunk/utils/insitu.d
r91 r94 30 30 31 31 private import ddl.all; 32 private import ddl.Utils; 32 33 private import ddl.insitu.all; 33 34 34 private import utils. ddlinfo_bn;35 private import utils.insitu_bn; 35 36 private import utils.ArgParser; 36 37 37 38 38 char[] helpText = … … 49 49 50 50 -o Specify output file 51 -c Compression level for data (1-9 )51 -c Compression level for data (1-9 where 9 is default) 52 52 53 53 When the output file is not specified, a file in the … … 57 57 by DMD. 58 58 "; 59 60 // -d Create a .d file with a SituLibrary class instead 59 // -d Create a .d file with a SituLibrary class instead 61 60 //With the -d switch, <filename>_InSitu.d will be used instead. 62 63 61 64 62 int main(char[][] args){ … … 81 79 // determine the output file 82 80 char[] outputFilename = inputFile.getName; 83 //bit dOutput = false;81 bit dOutput = false; 84 82 bit filenameOverride = false; 85 83 86 //TODO: determine the compression level87 84 ubyte compressionLevel = 9; 88 85 … … 105 102 }); 106 103 107 //parser.bind("d",delegate void(){108 //dOutput = true;109 //});104 // parser.bind("d",delegate void(){ 105 // dOutput = true; 106 // }); 110 107 111 108 parser.parse(args[2..$]); 112 109 113 110 // load the .map file and get what we need 114 //TODO: load via registry instead, and use DynamicLibrary115 111 inputFile.load(); 116 112 InSituMapBinary inputBinary = new InSituMapBinary(); … … 124 120 outputFile.create(outputFilename); 125 121 126 //if(!dOutput){122 //
