Changeset 91
- Timestamp:
- 12/21/05 13:20:34 (3 years ago)
- Files:
-
- trunk/ddl/Utils.d (modified) (4 diffs)
- trunk/ddl/insitu/InSituMapBinary.d (modified) (3 diffs)
- trunk/utils/bless.d (modified) (1 diff)
- trunk/utils/insitu.d (modified) (4 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/ddl/Utils.d
r86 r91 31 31 private import std.string; 32 32 private import std.file; 33 33 34 alias writefln debugLog; 35 34 36 struct DDLFile{ 35 37 ubyte[] buffer; … … 172 174 char[] result; 173 175 uint pos; 176 uint next; 174 177 for(pos=position; pos<data.length; pos++){ 175 if(data[pos] == '\ r' || data[pos] == '\n'){176 for(pos=pos; pos<data.length && (data[pos] == '\n' || data[pos] == '\r'); pos++){}178 if(data[pos] == '\n'){ 179 next=pos+2; 177 180 break; 178 181 } 179 } 182 if(data[pos] == '\r'){ 183 next=pos+2; 184 if(pos+1 < data.length && data[pos] == '\n'){ 185 next++; 186 } 187 break; 188 } 189 } 190 //if(data[pos] != '\n') 180 191 result = cast(char[])data[position..pos]; 181 position = pos;192 position = next; 182 193 return result; 183 194 } … … 203 214 protected void allocSpace(uint amount){ 204 215 if(position+amount > data.length){ 205 data ~= new ubyte[AllocSize ];216 data ~= new ubyte[AllocSize < amount ? amount : AllocSize]; 206 217 } 207 218 } … … 242 253 } 243 254 255 public void writeText(char[] value){ 256 write(cast(ubyte[])value); 257 } 258 244 259 public uint getPosition(){ 245 260 return position; trunk/ddl/insitu/InSituMapBinary.d
r85 r91 42 42 parseSegmentDefinitions(cursor); 43 43 parsePublicsByName(cursor); 44 // throw away the publics by address 44 // throw away the publics by address 45 45 } 46 46 … … 72 72 char[] line = cursor.readLine(); 73 73 if(line.length == 0) break; 74 74 75 75 // throw away the address (first nine chars) 76 76 if(line[14..21] == " Imp ") continue; // throw this away! We want the '__imp__' version instead. … … 112 112 sym.address = cast(void*)rva; 113 113 sym.name = symbol; 114 114 115 115 allSymbols[sym.name] = sym; 116 116 trunk/utils/bless.d
r85 r91 33 33 34 34 private import utils.ddlinfo_bn; 35 private import ddl.all;36 35 private import utils.ArgParser; 37 36 trunk/utils/insitu.d
r31 r91 27 27 module utils.insitu; 28 28 29 // DDL blessutility29 // DDL insitu utility 30 30 31 31 private import ddl.all; 32 32 private import ddl.insitu.all; 33 33 34 private import utils.ddlinfo_bn; 34 35 private import utils.ArgParser; 35 36 private import std.string;37 private import std.stdio;38 private import std.stream;39 private import std.file;40 private import std.zlib;41 36 42 37 43 38 char[] helpText = 44 "InSitu - Optimized in situ module generator - V1. 039 "InSitu - Optimized in situ module generator - V1.1 %d 45 40 Copyright (C) 2005 Eric Anderton 46 41 Documentation: http://www.dsource.org/projects/ddl … … 50 45 51 46 Usage: 52 insitu <map file> 53 insitu <map file> <output file> 47 insitu <map file> { -switch } 48 insitu <map file> { -switch } 49 50 -o Specify output file 51 -c Compression level for data (1-9) 54 52 55 53 When the output file is not specified, a file in the 56 form of <filename>.situ will be used instead. 54 form of <filename>.situ will be used by instead. 55 56 Map files are expected to be the same format as provided 57 by DMD. 57 58 "; 58 59 60 // -d Create a .d file with a SituLibrary class instead 61 //With the -d switch, <filename>_InSitu.d will be used instead. 62 63 59 64 int main(char[][] args){ 65 DefaultRegistry registry = new DefaultRegistry(); 66 60 67 if(args.length == 1 || args.length > 3){ 61 writefln("%s",helpText); 68 Stdout.println(helpText,auto_build_number); 69 Stdout.println("Supported Object Types:"); 70 foreach(char[] ext; registry.getSupportedTypes){ 71 Stdout.print("%s ",ext); 72 } 73 Stdout.println(""); 62 74 return 0; 63 75 } 64 76 65 77 // get the filename 66 char[] inputFilename = args[1]; 67 int split = inputFilename.irfind("."); 68 69 char[] originalShortName = inputFilename; 70 char[] originalExtension; 71 72 if(split >= 0){ 73 originalExtension = inputFilename[split+1..$]; 74 originalShortName = inputFilename[0..($-originalExtension.length)-1]; 75 } 78 DDLFile inputFile; 79 inputFile.create(args[1]); 76 80 77 81 // determine the output file 78 char[] outputFilename; 79 80 if(args.length == 2){ 81 outputFilename = originalShortName ~ ".situ"; 82 } 83 else if(args.length == 3){ 84 outputFilename = args[2]; 85 } 82 char[] outputFilename = inputFile.getName; 83 //bit dOutput = false; 84 bit filenameOverride = false; 86 85 87 86 //TODO: determine the compression level … … 90 89 // get dash prefixed args 91 90 ArgParser parser = new ArgParser("-"); 91 92 parser.bind("o",delegate uint(char[] value){ 93 filenameOverride = true; 94 outputFilename = value; 95 return value.length; 96 }); 92 97 93 98 parser.bind("c",delegate uint(char[] value){ … … 99 104 return 1; 100 105 }); 106 107 //parser.bind("d",delegate void(){ 108 // dOutput = true; 109 //}); 101 110 102 parser.parse(args[2..$]); 111 parser.parse(args[2..$]); 103 112 104 113 // load the .map file and get what we need 105 File inputFile = new File(inputFilename); 114 //TODO: load via registry instead, and use DynamicLibrary 115 inputFile.load(); 106 116 InSituMapBinary inputBinary = new InSituMapBinary(); 107 117 inputBinary.load(inputFile); 108 inputFile.close();109 118 110 debug writefln("%d exports total",inputBinary.getAllSymbols().values.length); 111 debug writefln("first export: %s",inputBinary.getAllSymbols().values[0].name); 119 debugLog("%d bytes loaded",inputFile.buffer.length); 112 120 113 // commit the data to the lib-style binary 114 File outputFile = new File(outputFilename,FileMode.OutNew); 115 InSituLibBinary outputBinary = new InSituLibBinary(); 116 outputBinary.setAllSymbols(inputBinary.getAllSymbols()); 117 outputBinary.save(outputFile,compressionLevel); 118 outputFile.close(); 119 121 debugLog("%d exports total",inputBinary.getAllSymbols().values.length); 122 123 DDLFile outputFile; 124 outputFile.create(outputFilename); 125 126 //if(!dOutput){ 127 if(!filenameOverride) outputFile.filename ~= ".situ"; 128 // commit the data to the lib-style binary 129 InSituLibBinary outputBinary = new InSituLibBinary(); 130 outputBinary.setAllSymbols(inputBinary.getAllSymbols()); 131 outputBinary.save(outputFile,compressionLevel); 132 /*} 133 else{ 134 // create .d sourcecode to use instead 135 WriteCursor cursor = new WriteCursor(); 136 137 char[] symbolExterns = ""; 138 char[] symbolPointers = ""; 139 140 // create buffers 141 foreach(ExportSymbol exp; inputBinary.getAllSymbols()){ 142 //NOTE: hack off the first char ('_') to get the correct symbol 143 char[] name = exp.name[1..$]; 144 symbolExterns ~= "\tvoid " ~ name ~ "();\n"; 145 symbolPointers ~= "\t\t{&" ~ name ~ ",\"" ~ exp.name ~ "\"},\n"; 146 } 147 148 char[] dText = 149 "//Auto-generated by the DDL In-Situ tool 150 module " ~ outputFile.filename ~ "_InSitu; 151 import ddl.insitu.InSituStubLibrary; 152 extern(C){ 153 " ~ symbolExterns ~ " 154 } 155 const ExportSymbol[char[]] symbols=[ 156 " ~ symbolPointers ~ " 157 ]; 158 class InSituLibrary : InSituStubLibrary{ 159 public this(){ 160 super(symbols); 161 } 162 }"; 163 cursor.writeText(dText); 164 if(!filenameOverride) outputFile.filename ~= "_InSitu.d"; 165 outputFile.save(cursor.getData()); 166 }*/ 120 167 return 0; 121 168 }
