| 1 |
module ptrace; |
|---|
| 2 |
|
|---|
| 3 |
import tango.io.FileConduit; |
|---|
| 4 |
import tango.io.File; |
|---|
| 5 |
import tango.io.Stdout; |
|---|
| 6 |
import tango.text.convert.Integer; |
|---|
| 7 |
import tango.core.Array; |
|---|
| 8 |
import tango.stdc.ctype; |
|---|
| 9 |
import tango.util.Arguments; |
|---|
| 10 |
import tango.text.stream.LineIterator; |
|---|
| 11 |
import tango.sys.Process; |
|---|
| 12 |
import tango.sys.Environment; |
|---|
| 13 |
import tango.stdc.stdio; |
|---|
| 14 |
import Regex = tango.text.Regex; |
|---|
| 15 |
import Util = tango.text.Util; |
|---|
| 16 |
import ConvertFloat = tango.text.convert.Float; |
|---|
| 17 |
|
|---|
| 18 |
|
|---|
| 19 |
|
|---|
| 20 |
enum SymbolMode { FQN, SEP, SYM } |
|---|
| 21 |
|
|---|
| 22 |
SymbolMode timingsMode = SymbolMode.SEP; |
|---|
| 23 |
SymbolMode graphMode = SymbolMode.SEP; |
|---|
| 24 |
|
|---|
| 25 |
char[] sourceFile; |
|---|
| 26 |
char[] targetFile; |
|---|
| 27 |
char[] targetTimingsFile; |
|---|
| 28 |
char[] targetGraphFile; |
|---|
| 29 |
|
|---|
| 30 |
bool showHelp = false; |
|---|
| 31 |
bool onePass = false; |
|---|
| 32 |
|
|---|
| 33 |
enum ParseMode |
|---|
| 34 |
{ |
|---|
| 35 |
Full, |
|---|
| 36 |
QualifiedName |
|---|
| 37 |
} |
|---|
| 38 |
|
|---|
| 39 |
ParseMode mode = ParseMode.QualifiedName; |
|---|
| 40 |
char[] helpTxt = |
|---|
| 41 |
" usage: ptrace [file] [options]\n" |
|---|
| 42 |
" -t=<target> write to target, must be with d extension for dmd\n" |
|---|
| 43 |
" -s=<mode> specifies how to write symbols, <mode> can be of one:\n" |
|---|
| 44 |
" FQN fully qualified name\n" |
|---|
| 45 |
" SYM identifier only, not type information\n" |
|---|
| 46 |
" SEP seperate columns for type and identifier\n" |
|---|
| 47 |
" -h this help text\n" |
|---|
| 48 |
" -t=<target> write to target, must be with d extension for dmd\n" |
|---|
| 49 |
" -f do not ask for permission to overwrite existing files\n" |
|---|
| 50 |
" -x eXecute dmd and generate html instead of ddoc code\n\n" |
|---|
| 51 |
" if no source file has been given, trace.log is assumed\n" |
|---|
| 52 |
" if no target file has been given, -x is assumed\n"; |
|---|
| 53 |
|
|---|
| 54 |
|
|---|
| 55 |
/* TODO: implement these options correctly |
|---|
| 56 |
" -st=<mode> idem, but only for timings\n" |
|---|
| 57 |
" -sg=<mode> idem, but only for graph\n" |
|---|
| 58 |
" -tt=<target> write only timings to target, must be with d extension for dmd\n" |
|---|
| 59 |
" -tg=<target> write only call graph to target, must be with d extension for dmd\n" |
|---|
| 60 |
*/ |
|---|
| 61 |
|
|---|
| 62 |
bool parseArgs(char[][] args) |
|---|
| 63 |
{ |
|---|
| 64 |
bool force = false; |
|---|
| 65 |
|
|---|
| 66 |
auto arguments = new Arguments(args, ["source"]); |
|---|
| 67 |
if (arguments["source"].length == 1) |
|---|
| 68 |
sourceFile = arguments["source"][0]; |
|---|
| 69 |
else if (arguments["source"].length > 1) |
|---|
| 70 |
{ |
|---|
| 71 |
Stdout("wrong number of source files").newline; |
|---|
| 72 |
showHelp = true; |
|---|
| 73 |
} |
|---|
| 74 |
else |
|---|
| 75 |
sourceFile = "trace.log"; |
|---|
| 76 |
|
|---|
| 77 |
with(arguments) |
|---|
| 78 |
{ |
|---|
| 79 |
addValidation("h", false, false); |
|---|
| 80 |
addValidation("s", false, true); |
|---|
| 81 |
addValidation("t", false, true); |
|---|
| 82 |
addValidation("f", false, false); |
|---|
| 83 |
addValidation("x", false, false); |
|---|
| 84 |
} |
|---|
| 85 |
|
|---|
| 86 |
if ("h" in arguments) |
|---|
| 87 |
showHelp = true; |
|---|
| 88 |
|
|---|
| 89 |
if ("x" in arguments) |
|---|
| 90 |
onePass = true; |
|---|
| 91 |
|
|---|
| 92 |
if ("f" in arguments) |
|---|
| 93 |
force = true; |
|---|
| 94 |
|
|---|
| 95 |
if ("s" in arguments) |
|---|
| 96 |
{ |
|---|
| 97 |
switch(arguments["s"][0]) |
|---|
| 98 |
{ |
|---|
| 99 |
case "FQN": graphMode = timingsMode = SymbolMode.FQN; break; |
|---|
| 100 |
case "SYM": graphMode = timingsMode = SymbolMode.SYM; break; |
|---|
| 101 |
case "SEP": graphMode = timingsMode = SymbolMode.SEP; break; |
|---|
| 102 |
default: showHelp = true; break; |
|---|
| 103 |
} |
|---|
| 104 |
} |
|---|
| 105 |
if (arguments["t"].length) |
|---|
| 106 |
targetFile = arguments["t"][0]; |
|---|
| 107 |
else |
|---|
| 108 |
{ |
|---|
| 109 |
targetFile = "ddoc_" ~ sourceFile ~ ".d"; |
|---|
| 110 |
onePass = true; |
|---|
| 111 |
} |
|---|
| 112 |
|
|---|
| 113 |
if( (new FilePath(targetFile)).exists() && !force) |
|---|
| 114 |
{ |
|---|
| 115 |
char response; |
|---|
| 116 |
while (true) |
|---|
| 117 |
{ |
|---|
| 118 |
Stdout.format("Are you sure you want to overwrite {} (y/n)?", targetFile).newline; |
|---|
| 119 |
response = getchar(); |
|---|
| 120 |
if (response == 'n' || response == 'N') |
|---|
| 121 |
return false; |
|---|
| 122 |
else if (response == 'y' || response == 'Y') |
|---|
| 123 |
break; |
|---|
| 124 |
} |
|---|
| 125 |
} |
|---|
| 126 |
|
|---|
| 127 |
return true; |
|---|
| 128 |
} |
|---|
| 129 |
|
|---|
| 130 |
|
|---|
| 131 |
int main(char[][] args) |
|---|
| 132 |
{ |
|---|
| 133 |
Stdout("Ptrace. Utility to prettify trace.log files. ptrace -h for help.\n"); |
|---|
| 134 |
if (!parseArgs(args)) |
|---|
| 135 |
return 0; |
|---|
| 136 |
if (showHelp) |
|---|
| 137 |
{ |
|---|
| 138 |
Stdout(helpTxt); |
|---|
| 139 |
return 0; |
|---|
| 140 |
} |
|---|
| 141 |
|
|---|
| 142 |
//Stdout.format("Reading from {0} and writing to {1}", sourceFile, targetFile).newline; |
|---|
| 143 |
|
|---|
| 144 |
auto reader = new TraceReader(sourceFile, new TraceParser); |
|---|
| 145 |
|
|---|
| 146 |
reader.read; |
|---|
| 147 |
|
|---|
| 148 |
auto output = new FileConduit(targetFile, FileConduit.ReadWriteCreate); |
|---|
| 149 |
|
|---|
| 150 |
char[] header() |
|---|
| 151 |
{ |
|---|
| 152 |
switch (timingsMode) |
|---|
| 153 |
{ |
|---|
| 154 |
case SymbolMode.FQN: return " $(HEADER_FUNCTION_NAME symbol)\n"; |
|---|
| 155 |
case SymbolMode.SYM: return " $(HEADER_FUNCTION_NAME identifier)\n"; |
|---|
| 156 |
case SymbolMode.SEP: return " $(HEADER_FUNCTION_NAME identifier) $(HEADER_FUNCTION_NAME type) \n"; |
|---|
| 157 |
default: assert(false); break; |
|---|
| 158 |
} |
|---|
| 159 |
} |
|---|
| 160 |
|
|---|
| 161 |
Stdout("writing output to " ~ targetFile ~ "...").newline; |
|---|
| 162 |
output.output.write("Ddoc\n"); |
|---|
| 163 |
|
|---|
| 164 |
if (onePass) |
|---|
| 165 |
{ |
|---|
| 166 |
output.output.write(macros); |
|---|
| 167 |
} |
|---|
| 168 |
|
|---|
| 169 |
output.output.write("\n$(TIMINGS $(HEADER_CALLS Num calls) $(HEADER_TREE Tree Time)" |
|---|
| 170 |
"$(HEADER_FUNC Func Time) $(HEADER_CALL Per Call)" ~ header() ); |
|---|
| 171 |
|
|---|
| 172 |
char[] functionName(char[] mangled) |
|---|
| 173 |
{ |
|---|
| 174 |
switch(timingsMode) |
|---|
| 175 |
{ |
|---|
| 176 |
case SymbolMode.SYM: return " $(FUNCTION_NAME " ~ reader.getSYM(mangled) ~ ") )\n"; |
|---|
| 177 |
case SymbolMode.FQN: return " $(FUNCTION_NAME " ~ reader.getFQN(mangled) ~ ") )\n"; |
|---|
| 178 |
case SymbolMode.SEP: return " $(FUNCTION_NAME " ~ reader.getSYM(mangled) ~ ") " |
|---|
| 179 |
" $(FUNCTION_NAME " ~ reader.getTYPE(mangled) ~ ") )\n"; |
|---|
| 180 |
default: assert(false); break; |
|---|
| 181 |
} |
|---|
| 182 |
} |
|---|
| 183 |
|
|---|
| 184 |
foreach(timing; reader.timings) |
|---|
| 185 |
output.output.write( " $(TIMING $(CALLS " ~ toString(timing.calls) ~ ")" |
|---|
| 186 |
" $(TREE " ~ toString(timing.tree) ~ ") $(FUNC " ~ toString(timing.func) ~ ")" |
|---|
| 187 |
" $(CALL " ~ toString(timing.call) ~ ")" ~ functionName(timing.mangled) ); |
|---|
| 188 |
|
|---|
| 189 |
output.output.write(")\n $(CALL_GRAPH \n"); |
|---|
| 190 |
|
|---|
| 191 |
/* |
|---|
| 192 |
TODO: |
|---|
| 193 |
make call graph output fqn/sym/type of symbol correctly: specifify colspan in trace.ddoc macro's |
|---|
| 194 |
|
|---|
| 195 |
*/ |
|---|
| 196 |
|
|---|
| 197 |
foreach(node; reader.parser.nodes) |
|---|
| 198 |
{ |
|---|
| 199 |
output.output.write("$(CALL_SEP )\n"); |
|---|
| 200 |
foreach(fun; node.fan_in) |
|---|
| 201 |
output.output.write("$(FAN $(FAN_FUNC " ~ reader.getFQN(fun.mangled) ~ ") $(FAN_CALLS " ~ toString(fun.numCalls) ~ "))\n"); |
|---|
| 202 |
|
|---|
| 203 |
output.output.write("$(CALL_FUN $(CALL_FUN_NAME 2, " ~ reader.getFQN(node.mangled) ~ |
|---|
| 204 |
") $(CALL_FUN_TREE " ~ ConvertFloat.toString(cast(real)node.tree / reader.freq, 2, false ) ~ ")" |
|---|
| 205 |
" $(CALL_FUN_FUNC " ~ ConvertFloat.toString(cast(real)node.func / reader.freq, 2, false) ~ ")" |
|---|
| 206 |
" $(CALL_FUN_CALLS " ~ toString(node.count) ~ ") )\n" ); |
|---|
| 207 |
|
|---|
| 208 |
foreach(fun; node.fan_out) |
|---|
| 209 |
output.output.write("$(FAN $(FAN_FUNC " ~ reader.demangleSymbol(fun.mangled) ~ ") $(FAN_CALLS " ~ toString(fun.numCalls) ~ ") )\n"); |
|---|
| 210 |
|
|---|
| 211 |
} |
|---|
| 212 |
output.output.write(")\n"); |
|---|
| 213 |
output.close; |
|---|
| 214 |
|
|---|
| 215 |
if (onePass) |
|---|
| 216 |
{ |
|---|
| 217 |
Stdout("generating html...").newline; |
|---|
| 218 |
Process dmd = new Process(Environment.exePath("dmd").toString, "-D"[], targetFile, null); |
|---|
| 219 |
dmd.execute(); |
|---|
| 220 |
auto result = dmd.wait(); |
|---|
| 221 |
Stdout("removing temporary files...").newline; |
|---|
| 222 |
(new FilePath(targetFile)).remove(); |
|---|
| 223 |
return result.status; |
|---|
| 224 |
} |
|---|
| 225 |
return 0; |
|---|
| 226 |
} |
|---|
| 227 |
|
|---|
| 228 |
struct FuncCall |
|---|
| 229 |
{ |
|---|
| 230 |
char[] mangled; |
|---|
| 231 |
uint numCalls; |
|---|
| 232 |
} |
|---|
| 233 |
|
|---|
| 234 |
struct CallNode |
|---|
| 235 |
{ |
|---|
| 236 |
char[] mangled; |
|---|
| 237 |
FuncCall[] fan_in; |
|---|
| 238 |
FuncCall[] fan_out; |
|---|
| 239 |
ulong count; |
|---|
| 240 |
ulong tree; |
|---|
| 241 |
ulong func; |
|---|
| 242 |
} |
|---|
| 243 |
|
|---|
| 244 |
struct Timing |
|---|
| 245 |
{ |
|---|
| 246 |
char[] mangled; |
|---|
| 247 |
ulong calls; |
|---|
| 248 |
// timings: |
|---|
| 249 |
ulong tree; |
|---|
| 250 |
ulong func; |
|---|
| 251 |
ulong call; |
|---|
| 252 |
} |
|---|
| 253 |
|
|---|
| 254 |
class TraceParser |
|---|
| 255 |
{ |
|---|
| 256 |
void processCall(char[][] fan_in, char[] func, char[][] fan_out) |
|---|
| 257 |
{ |
|---|
| 258 |
auto isSpace = &Util.isSpace!(char); |
|---|
| 259 |
nodes.length = nodes.length + 1; |
|---|
| 260 |
|
|---|
| 261 |
void parseFan(ref FuncCall[] calls, ref char[][] data) |
|---|
| 262 |
{ |
|---|
| 263 |
foreach (line; data) |
|---|
| 264 |
{ |
|---|
| 265 |
int numcalls; |
|---|
| 266 |
|
|---|
| 267 |
int index = findIf(line, &Util.isSpace!(char)); |
|---|
| 268 |
|
|---|
| 269 |
if (index > 0) |
|---|
| 270 |
numcalls = toLong(line[0..index]); |
|---|
| 271 |
|
|---|
| 272 |
index = rfindIf(line, isSpace); |
|---|
| 273 |
if (index > 0) |
|---|
| 274 |
{ |
|---|
| 275 |
calls ~= FuncCall(Util.trim(line[index..$]), numcalls); |
|---|
| 276 |
} |
|---|
| 277 |
} |
|---|
| 278 |
} |
|---|
| 279 |
|
|---|
| 280 |
parseFan(nodes[$-1].fan_in, fan_in); |
|---|
| 281 |
parseFan(nodes[$-1].fan_out, fan_out); |
|---|
| 282 |
|
|---|
| 283 |
// function symbol |
|---|
| 284 |
int index = findIf(func, isSpace); |
|---|
| 285 |
if (index > 0) |
|---|
| 286 |
nodes[$-1].mangled = Util.trim(func[0..index]).dup; |
|---|
| 287 |
|
|---|
| 288 |
// tree time |
|---|
| 289 |
func = Util.trim(func[index..$]); |
|---|
| 290 |
index = findIf(func, isSpace); |
|---|
| 291 |
|
|---|
| 292 |
if (index > 0) |
|---|
| 293 |
nodes[$-1].count = toLong(func[0..index]); |
|---|
| 294 |
|
|---|
| 295 |
// function time |
|---|
| 296 |
func = Util.trim(func[index..$]); |
|---|
| 297 |
index = rfindIf(func, isSpace); |
|---|
| 298 |
if (index > 0) |
|---|
| 299 |
nodes[$-1].tree = toLong(func[0..index]); |
|---|
| 300 |
|
|---|
| 301 |
// number of calls |
|---|
| 302 |
nodes[$-1].func = toLong(Util.trim(func[index..$])); |
|---|
| 303 |
} |
|---|
| 304 |
|
|---|
| 305 |
CallNode[] nodes; |
|---|
| 306 |
} |
|---|
| 307 |
|
|---|
| 308 |
|
|---|
| 309 |
Words words(char[] str) |
|---|
| 310 |
{ |
|---|
| 311 |
return Words.iter(str); |
|---|
| 312 |
} |
|---|
| 313 |
|
|---|
| 314 |
struct Words |
|---|
| 315 |
{ |
|---|
| 316 |
private char[] src; |
|---|
| 317 |
|
|---|
| 318 |
static Words iter(char[] str) |
|---|
| 319 |
{ |
|---|
| 320 |
Words result; |
|---|
| 321 |
result.src = str; |
|---|
| 322 |
return result; |
|---|
| 323 |
} |
|---|
| 324 |
|
|---|
| 325 |
int opApply (int delegate (ref char[] token) dg) |
|---|
| 326 |
{ |
|---|
| 327 |
int result; |
|---|
| 328 |
uint start = 0; |
|---|
| 329 |
enum : ubyte |
|---|
| 330 |
{ |
|---|
| 331 |
WORD, |
|---|
| 332 |
SPACE |
|---|
| 333 |
} |
|---|
| 334 |
ubyte state = SPACE; |
|---|
| 335 |
|
|---|
| 336 |
char[] token; |
|---|
| 337 |
|
|---|
| 338 |
foreach (index, elem; src) |
|---|
| 339 |
{ |
|---|
| 340 |
if(state == SPACE) |
|---|
| 341 |
{ |
|---|
| 342 |
if (!Util.isSpace(elem)) |
|---|
| 343 |
{ |
|---|
| 344 |
state = WORD; |
|---|
| 345 |
start = index; |
|---|
| 346 |
} |
|---|
| 347 |
} |
|---|
| 348 |
else if (Util.isSpace(elem)) |
|---|
| 349 |
{ |
|---|
| 350 |
token = src[start..index]; |
|---|
| 351 |
dg(token); |
|---|
| 352 |
state = SPACE; |
|---|
| 353 |
} |
|---|
| 354 |
|
|---|
| 355 |
} |
|---|
| 356 |
if (state == WORD && start < src.length) |
|---|
| 357 |
{ |
|---|
| 358 |
token = src[start..$]; |
|---|
| 359 |
dg(token); |
|---|
| 360 |
} |
|---|
| 361 |
return result; |
|---|
| 362 |
} |
|---|
| 363 |
} |
|---|
| 364 |
|
|---|
| 365 |
class ParseException : Exception |
|---|
| 366 |
{ |
|---|
| 367 |
this(char[] msg) |
|---|
| 368 |
{ |
|---|
| 369 |
super(msg); |
|---|
| 370 |
} |
|---|
| 371 |
} |
|---|
| 372 |
|
|---|
| 373 |
class TraceReader |
|---|
| 374 |
{ |
|---|
| 375 |
this(char[] filename, TraceParser parser) |
|---|
| 376 |
{ |
|---|
| 377 |
this.fileName = filename; |
|---|
| 378 |
this.parser = parser; |
|---|
| 379 |
} |
|---|
| 380 |
|
|---|
| 381 |
void read() |
|---|
| 382 |
{ |
|---|
| 383 |
timings.length = 0; |
|---|
| 384 |
auto contents = new FileConduit(fileName); |
|---|
| 385 |
auto lines = new LineIterator!(char)(contents); |
|---|
| 386 |
bool pastGraph = false; |
|---|
| 387 |
char[] line; |
|---|
| 388 |
|
|---|
| 389 |
if (lines.next) |
|---|
| 390 |
{ |
|---|
| 391 |
line = Util.trim(lines.get); |
|---|
| 392 |
if (line.length) |
|---|
| 393 |
{ |
|---|
| 394 |
if (line[0] != '-') |
|---|
| 395 |
throw new ParseException("unexpected format of trace log file"); |
|---|
| 396 |
} |
|---|
| 397 |
else |
|---|
| 398 |
throw new ParseException("empty file"); |
|---|
| 399 |
} |
|---|
| 400 |
|
|---|
| 401 |
char[][] fanInLines; |
|---|
| 402 |
char[][] fanOutLines; |
|---|
| 403 |
char[] callLine; |
|---|
| 404 |
bool pastCall = false; |
|---|
| 405 |
uint count = 0; |
|---|
| 406 |
|
|---|
| 407 |
|
|---|
| 408 |
while(lines.next && !pastGraph) |
|---|
| 409 |
{ |
|---|
| 410 |
count++; |
|---|
| 411 |
|
|---|
| 412 |
line = Util.trim(lines.get); |
|---|
| 413 |
|
|---|
| 414 |
if(!line.length) |
|---|
| 415 |
continue; |
|---|
| 416 |
else if(line[0] == '-' || line[0] == '=') |
|---|
| 417 |
{ |
|---|
| 418 |
parser.processCall(fanInLines, callLine, fanOutLines); |
|---|
| 419 |
fanInLines.length = 0; |
|---|
| 420 |
fanOutLines.length = 0; |
|---|
| 421 |
callLine.length = 0; |
|---|
| 422 |
pastCall = false; |
|---|
| 423 |
if (line[0] == '=') |
|---|
| 424 |
pastGraph = true; |
|---|
| 425 |
else |
|---|
| 426 |
continue; |
|---|
| 427 |
} |
|---|
| 428 |
else |
|---|
| 429 |
{ |
|---|
| 430 |
if (line[0] == '_') |
|---|
| 431 |
{ |
|---|
| 432 |
pastCall = true; |
|---|
| 433 |
callLine = line.dup; |
|---|
| 434 |
} |
|---|
| 435 |
else if(!pastCall) // fan_in |
|---|
| 436 |
fanInLines ~= line.dup; |
|---|
| 437 |
else if(pastCall) // fan_Out |
|---|
| 438 |
fanOutLines ~= line.dup; |
|---|
| 439 |
} |
|---|
| 440 |
} |
|---|
| 441 |
|
|---|
| 442 |
auto freqString = Regex.search(line, r"[\d]+").match(0); |
|---|
| 443 |
if(freqString !is null) |
|---|
| 444 |
freq = ConvertFloat.toFloat(freqString) / 1000000.0; |
|---|
| 445 |
|
|---|
| 446 |
if (lines.next()) |
|---|
| 447 |
line = lines.get; |
|---|
| 448 |
|
|---|
| 449 |
char[][] values; |
|---|
| 450 |
|
|---|
| 451 |
while(lines.next) |
|---|
| 452 |
{ |
|---|
| 453 |
values.length = 0; |
|---|
| 454 |
foreach(inout word; (lines.get()).words()) |
|---|
| 455 |
values ~= word.dup; |
|---|
| 456 |
|
|---|
| 457 |
if (values.length == 5) |
|---|
| 458 |
timings ~= Timing(values[4].dup, toInt(values[0]), toInt(values[1]), toInt(values[2]), toInt(values[3])); |
|---|
| 459 |
} |
|---|
| 460 |
} |
|---|
| 461 |
|
|---|
| 462 |
/+char[] demangleSymbol(char[] mangledName) |
|---|
| 463 |
{ |
|---|
| 464 |
auto ptr = mangledName in symbolTable; |
|---|
| 465 |
|
|---|
| 466 |
if (ptr) |
|---|
| 467 |
return *ptr; |
|---|
| 468 |
char[] result; |
|---|
| 469 |
try |
|---|
| 470 |
{ |
|---|
| 471 |
result = demangle(mangledName); |
|---|
| 472 |
symbolTable[mangledName] = result; |
|---|
| 473 |
} |
|---|
| 474 |
catch(Object error) |
|---|
| 475 |
{ |
|---|
| 476 |
Stdout("demangle error (ignored): ")(error.toString).newline; |
|---|
| 477 |
return mangledName; |
|---|
| 478 |
} |
|---|
| 479 |
|
|---|
| 480 |
return result; |
|---|
| 481 |
|
|---|
| 482 |
}+/ |
|---|
| 483 |
alias getFQN demangleSymbol; |
|---|
| 484 |
|
|---|
| 485 |
|
|---|
| 486 |
//TODO: catch appropiate exception to not choke on invalid string-8 symbols but instead ignore them |
|---|
| 487 |
char[] getFQN(char[] mangledName) |
|---|
| 488 |
{ |
|---|
| 489 |
return cachedLookup(mangledName, fqnMap, { |
|---|
| 490 |
fqnMap[mangledName] = demangle(mangledName); |
|---|
| 491 |
return fqnMap[mangledName]; |
|---|
| 492 |
}); |
|---|
| 493 |
} |
|---|
| 494 |
|
|---|
| 495 |
char[] getSYM(char[] mangledName) |
|---|
| 496 |
{ |
|---|
| 497 |
return cachedLookup(mangledName, symMap, { |
|---|
| 498 |
char[] s; |
|---|
| 499 |
char[] t; |
|---|
| 500 |
s = demangle(mangledName, t); |
|---|
| 501 |
symMap[mangledName] = s; |
|---|
| 502 |
typeMap[mangledName] = t; |
|---|
| 503 |
return s; |
|---|
| 504 |
}); |
|---|
| 505 |
} |
|---|
| 506 |
|
|---|
| 507 |
char[] getTYPE(char[] mangledName) |
|---|
| 508 |
{ |
|---|
| 509 |
return cachedLookup(mangledName, typeMap, { |
|---|
| 510 |
char[] s; |
|---|
| 511 |
char[] t; |
|---|
| 512 |
s = demangle(mangledName, t); |
|---|
| 513 |
symMap[mangledName] = s; |
|---|
| 514 |
typeMap[mangledName] = t; |
|---|
| 515 |
return t; |
|---|
| 516 |
} ); |
|---|
| 517 |
} |
|---|
| 518 |
|
|---|
| 519 |
private |
|---|
| 520 |
{ |
|---|
| 521 |
char[] cachedLookup(char[] key, ref char[][char[]] map, char[] delegate() create) |
|---|
| 522 |
{ |
|---|
| 523 |
auto ptr = key in map; |
|---|
| 524 |
if (ptr) |
|---|
| 525 |
return *ptr; |
|---|
| 526 |
return create(); |
|---|
| 527 |
} |
|---|
| 528 |
|
|---|
| 529 |
real freq = 0; |
|---|
| 530 |
char[] fileName; |
|---|
| 531 |
TraceParser parser; |
|---|
| 532 |
Timing[] timings; |
|---|
| 533 |
char[][char[]] fqnMap; |
|---|
| 534 |
char[][char[]] symMap; |
|---|
| 535 |
char[][char[]] typeMap; |
|---|
| 536 |
} |
|---|
| 537 |
} |
|---|
| 538 |
|
|---|
| 539 |
private class MangleException : Exception |
|---|
| 540 |
{ |
|---|
| 541 |
this() |
|---|
| 542 |
{ |
|---|
| 543 |
super("MangleException"); |
|---|
| 544 |
} |
|---|
| 545 |
} |
|---|
| 546 |
|
|---|
| 547 |
const char[] macros = |
|---|
| 548 |
` |
|---|
| 549 |
macros: |
|---|
| 550 |
TABLE = <table border="4" rules="none" cellpadding="6" cellspacing="6">$0</table> |
|---|
| 551 |
TDR = <td align="right">$0</td> |
|---|
| 552 |
TD_CSPAN = <td colspan="$1">$+</td> |
|---|
| 553 |
|
|---|
| 554 |
TIMINGS = <h1> Timings (in microseconds) </h1>$(TABLE $0) |
|---|
| 555 |
TIMING = <tr>$0</tr> |
|---|
| 556 |
FUNCTION_NAME = <td>$0</td> |
|---|
| 557 |
CALLS = <td align="right">$0</td> |
|---|
| 558 |
TREE = <td align="right">$0</td> |
|---|
| 559 |
FUNC = <td align="right">$0</td> |
|---|
| 560 |
CALL = <td align="right">$0</td> |
|---|
| 561 |
|
|---|
| 562 |
HEADER_FUNCTION_NAME = <th>$0</th> |
|---|
| 563 |
HEADER_CALLS = <th>$0</th> |
|---|
| 564 |
HEADER_TREE = <th>$0</th> |
|---|
| 565 |
HEADER_FUNC = <th>$0</th> |
|---|
| 566 |
HEADER_CALL = <th>$0</th> |
|---|
| 567 |
|
|---|
| 568 |
CALL_GRAPH = |
|---|
| 569 |
<br> |
|---|
| 570 |
<br> |
|---|
| 571 |
$(P <h1> Call Graph, times are in microseconds</h1> |
|---|
| 572 |
$(TABLE |
|---|
| 573 |
|
|---|
| 574 |
<tr><td>Functions that call <i>measured function</i> (fan in)</td> |
|---|
| 575 |
<td>Num calls</td> |
|---|
| 576 |
</tr> |
|---|
| 577 |
<tr><td colspan="2"><b>Measured function symbol</b></td> |
|---|
| 578 |
<td align="right">Tree Time</td> |
|---|
| 579 |
<td align="right">Func Time</td> |
|---|
| 580 |
<td align="right">Num Calls</td> |
|---|
| 581 |
</tr> |
|---|
| 582 |
<tr><td>Functions called by <i>measured function</i> (fan out)</td> |
|---|
| 583 |
<td>Num calls</td> |
|---|
| 584 |
</tr> |
|---|
| 585 |
$(CALL_SEP) |
|---|
| 586 |
$0) ) |
|---|
| 587 |
CALL_SEP = <tr><td> </td></tr> |
|---|
| 588 |
CALL_FUN = <tr>$0</tr> |
|---|
| 589 |
CALL_FUN_NAME = $(TD_CSPAN $1, $(B $+)) |
|---|
| 590 |
CALL_FUN_TREE = <td align="right">$0</td> |
|---|
| 591 |
CALL_FUN_FUNC = <td align="right">$0</td> |
|---|
| 592 |
CALL_FUN_CALLS = <td align="right">$0</td> |
|---|
| 593 |
FAN = <tr>$0</tr> |
|---|
| 594 |
FAN_FUNC = <td>$0</td> |
|---|
| 595 |
FAN_CALLS = <td>$0</td> |
|---|
| 596 |
|
|---|
| 597 |
DDOC = <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd"> |
|---|
| 598 |
<html><head> |
|---|
| 599 |
<META http-equiv="content-type" content="text/html; charset=utf-8"> |
|---|
| 600 |
<link rel="stylesheet" type="text/css" href="style.css"> |
|---|
| 601 |
</head><body> |
|---|
| 602 |
$(BODY) |
|---|
| 603 |
</body></html> |
|---|
| 604 |
`; |
|---|
| 605 |
|
|---|
| 606 |
char[] demangle(char[] name) |
|---|
| 607 |
{ |
|---|
| 608 |
char[] dummy; |
|---|
| 609 |
return demangle(name, dummy, ParseMode.Full); |
|---|
| 610 |
} |
|---|
| 611 |
|
|---|
| 612 |
/* This function is taken from phobos and ported to tango.*/ |
|---|
| 613 |
char[] demangle(char[] name, ref char[] type, ParseMode pMode = ParseMode.QualifiedName) |
|---|
| 614 |
{ |
|---|
| 615 |
|
|---|
| 616 |
size_t ni = 2; |
|---|
| 617 |
char[] delegate() fparseTemplateInstanceName; |
|---|
| 618 |
|
|---|
| 619 |
static void error() |
|---|
| 620 |
{ |
|---|
| 621 |
throw new MangleException(); |
|---|
| 622 |
} |
|---|
| 623 |
|
|---|
| 624 |
static ubyte ascii2hex(char c) |
|---|
| 625 |
{ |
|---|
| 626 |
if (!isxdigit(c)) |
|---|
| 627 |
error(); |
|---|
| 628 |
return cast(ubyte) |
|---|
| 629 |
( (c >= 'a') ? c - 'a' + 10 : |
|---|
| 630 |
(c >= 'A') ? c - 'A' + 10 : |
|---|
| 631 |
c - '0' |
|---|
| 632 |
); |
|---|
| 633 |
} |
|---|
| 634 |
|
|---|
| 635 |
size_t parseNumber() |
|---|
| 636 |
{ |
|---|
| 637 |
size_t result; |
|---|
| 638 |
|
|---|
| 639 |
while (ni < name.length && isdigit(name[ni])) |
|---|
| 640 |
{ |
|---|
| 641 |
int i = name[ni] - '0'; |
|---|
| 642 |
if (result > (size_t.max - i) / 10) |
|---|
| 643 |
error(); |
|---|
| 644 |
result = result * 10 + i; |
|---|
| 645 |
ni++; |
|---|
| 646 |
} |
|---|
| 647 |
return result; |
|---|
| 648 |
} |
|---|
| 649 |
|
|---|
| 650 |
char[] parseSymbolName() |
|---|
| 651 |
{ |
|---|
| 652 |
size_t i = parseNumber(); |
|---|
| 653 |
if (ni + i > name.length) |
|---|
| 654 |
error(); |
|---|
| 655 |
char[] result; |
|---|
| 656 |
if (i >= 5 && |
|---|
| 657 |
name[ni] == '_' && |
|---|
| 658 |
name[ni + 1] == '_' && |
|---|
| 659 |
name[ni + 2] == 'T') |
|---|
| 660 |
{ |
|---|
| 661 |
size_t nisave = ni; |
|---|
| 662 |
bool err; |
|---|
| 663 |
ni += 3; |
|---|
| 664 |
try |
|---|
| 665 |
{ |
|---|
| 666 |
result = fparseTemplateInstanceName(); |
|---|
| 667 |
if (ni != nisave + i) |
|---|
| 668 |
err = true; |
|---|
| 669 |
} |
|---|
| 670 |
catch (MangleException me) |
|---|
| 671 |
{ |
|---|
| 672 |
err = true; |
|---|
| 673 |
} |
|---|
| 674 |
ni = nisave; |
|---|
| 675 |
if (err) |
|---|
| 676 |
goto L1; |
|---|
| 677 |
goto L2; |
|---|
| 678 |
} |
|---|
| 679 |
L1: |
|---|
| 680 |
result = name[ni .. ni + i]; |
|---|
| 681 |
L2: |
|---|
| 682 |
ni += i; |
|---|
| 683 |
return result; |
|---|
| 684 |
} |
|---|
| 685 |
|
|---|
| 686 |
char[] parseQualifiedName() |
|---|
| 687 |
{ |
|---|
| 688 |
char[] result; |
|---|
| 689 |
|
|---|
| 690 |
while (ni < name.length && isdigit(name[ni])) |
|---|
| 691 |
{ |
|---|
| 692 |
if (result.length) |
|---|
| 693 |
result ~= "."; |
|---|
| 694 |
result ~= parseSymbolName(); |
|---|
| 695 |
} |
|---|
| 696 |
return result; |
|---|
| 697 |
} |
|---|
| 698 |
|
|---|
| 699 |
char[] parseType(char[] identifier = null) |
|---|
| 700 |
{ |
|---|
| 701 |
int isdelegate = 0; |
|---|
| 702 |
bool hasthisptr = false; /// For function/delegate types: expects a 'this' pointer as last argument |
|---|
| 703 |
Lagain: |
|---|
| 704 |
if (ni >= name.length) |
|---|
| 705 |
error(); |
|---|
| 706 |
char[] p; |
|---|
| 707 |
switch (name[ni++]) |
|---|
| 708 |
{ |
|---|
| 709 |
case 'v': p = "void"; goto L1; |
|---|
| 710 |
case 'b': p = "bool"; goto L1; |
|---|
| 711 |
case 'g': p = "byte"; goto L1; |
|---|
| 712 |
case 'h': p = "ubyte"; goto L1; |
|---|
| 713 |
case 's': p = "short"; goto L1; |
|---|
| 714 |
case 't': p = "ushort"; goto L1; |
|---|
| 715 |
case 'i': p = "int"; goto L1; |
|---|
| 716 |
case 'k': p = "uint"; goto L1; |
|---|
| 717 |
case 'l': p = "long"; goto L1; |
|---|
| 718 |
case 'm': p = "ulong"; goto L1; |
|---|
| 719 |
case 'f': p = "float"; goto L1; |
|---|
| 720 |
case 'd': p = "double"; goto L1; |
|---|
| 721 |
case 'e': p = "real"; goto L1; |
|---|
| 722 |
case 'o': p = "ifloat"; goto L1; |
|---|
| 723 |
case 'p': p = "idouble"; goto L1; |
|---|
| 724 |
case 'j': p = "ireal"; goto L1; |
|---|
| 725 |
case 'q': p = "cfloat"; goto L1; |
|---|
| 726 |
case 'r': p = "cdouble"; goto L1; |
|---|
| 727 |
case 'c': p = "creal"; goto L1; |
|---|
| 728 |
case 'a': p = "char"; goto L1; |
|---|
| 729 |
case 'u': p = "wchar"; goto L1; |
|---|
| 730 |
case 'w': p = "dchar"; goto L1; |
|---|
| 731 |
|
|---|
| 732 |
case 'A': // dynamic array |
|---|
| 733 |
p = parseType() ~ "[]"; |
|---|
| 734 |
goto L1; |
|---|
| 735 |
|
|---|
| 736 |
// case 'M': // needs this* |
|---|
| 737 |
// p = parseType() ~ " class"; |
|---|
| 738 |
// goto L1; |
|---|
| 739 |
|
|---|
| 740 |
case 'P': // pointer |
|---|
| 741 |
p = parseType() ~ "*"; |
|---|
| 742 |
goto L1; |
|---|
| 743 |
|
|---|
| 744 |
case 'G': // static array |
|---|
| 745 |
{ size_t ns = ni; |
|---|
| 746 |
parseNumber(); |
|---|
| 747 |
size_t ne = ni; |
|---|
| 748 |
p = parseType() ~ "[" ~ name[ns .. ne] ~ "]"; |
|---|
| 749 |
goto L1; |
|---|
| 750 |
} |
|---|
| 751 |
|
|---|
| 752 |
case 'H': // associative array |
|---|
| 753 |
p = parseType(); |
|---|
| 754 |
p = parseType() ~ "[" ~ p ~ "]"; |
|---|
| 755 |
goto L1; |
|---|
| 756 |
|
|---|
| 757 |
case 'D': // delegate |
|---|
| 758 |
isdelegate = 1; |
|---|
| 759 |
goto Lagain; |
|---|
| 760 |
|
|---|
| 761 |
case 'M': |
|---|
| 762 |
hasthisptr = true; |
|---|
| 763 |
goto Lagain; |
|---|
| 764 |
|
|---|
| 765 |
case 'F': // D function |
|---|
| 766 |
case 'U': // C function |
|---|
| 767 |
case 'W': // Windows function |
|---|
| 768 |
case 'V': // Pascal function |
|---|
| 769 |
case 'R': // C++ function |
|---|
| 770 |
{ char mc = name[ni - 1]; |
|---|
| 771 |
char[] args; |
|---|
| 772 |
|
|---|
| 773 |
while (1) |
|---|
| 774 |
{ |
|---|
| 775 |
if (ni >= name.length) |
|---|
| 776 |
error(); |
|---|
| 777 |
char c = name[ni]; |
|---|
| 778 |
if (c == 'Z') |
|---|
| 779 |
break; |
|---|
| 780 |
if (c == 'X') |
|---|
| 781 |
{ |
|---|
| 782 |
args ~= " ..."; |
|---|
| 783 |
break; |
|---|
| 784 |
} |
|---|
| 785 |
if (args.length) |
|---|
| 786 |
args ~= ", "; |
|---|
| 787 |
switch (c) |
|---|
| 788 |
{ |
|---|
| 789 |
case 'J': |
|---|
| 790 |
args ~= "out "; |
|---|
| 791 |
ni++; |
|---|
| 792 |
goto default; |
|---|
| 793 |
|
|---|
| 794 |
case 'K': |
|---|
| 795 |
args ~= "inout "; |
|---|
| 796 |
ni++; |
|---|
| 797 |
goto default; |
|---|
| 798 |
|
|---|
| 799 |
case 'L': |
|---|
| 800 |
args ~= "lazy "; |
|---|
| 801 |
ni++; |
|---|
| 802 |
goto default; |
|---|
| 803 |
|
|---|
| 804 |
default: |
|---|
| 805 |
args ~= parseType(); |
|---|
| 806 |
continue; |
|---|
| 807 |
|
|---|
| 808 |
case 'Y': |
|---|
| 809 |
args ~= "..."; |
|---|
| 810 |
break; |
|---|
| 811 |
} |
|---|
| 812 |
break; |
|---|
| 813 |
} |
|---|
| 814 |
if (hasthisptr || isdelegate) |
|---|
| 815 |
{ |
|---|
| 816 |
// add implicit 'this'/context pointer |
|---|
| 817 |
if (args.length) |
|---|
| 818 |
args ~= ", "; |
|---|
| 819 |
args ~= "void*"; |
|---|
| 820 |
} |
|---|
| 821 |
ni++; |
|---|
| 822 |
if (!isdelegate && identifier.length) |
|---|
| 823 |
{ |
|---|
| 824 |
switch (mc) |
|---|
| 825 |
{ |
|---|
| 826 |
case 'F': p = null; break; // D function |
|---|
| 827 |
case 'U': p = "extern (C) "; break; // C function |
|---|
| 828 |
case 'W': p = "extern (Windows) "; break; // Windows function |
|---|
| 829 |
case 'V': p = "extern (Pascal) "; break; // Pascal function |
|---|
| 830 |
default: assert(0); |
|---|
| 831 |
} |
|---|
| 832 |
p ~= parseType() ~ " " ~ identifier ~ "(" ~ args ~ ")"; |
|---|
| 833 |
return p; |
|---|
| 834 |
} |
|---|
| 835 |
p = parseType() ~ |
|---|
| 836 |
(isdelegate ? " delegate(" : " function(") ~ |
|---|
| 837 |
args ~ |
|---|
| 838 |
")"; |
|---|
| 839 |
isdelegate = 0; |
|---|
| 840 |
goto L1; |
|---|
| 841 |
} |
|---|
| 842 |
|
|---|
| 843 |
case 'C': p = "class "; goto L2; |
|---|
| 844 |
case 'S': p = "struct "; goto L2; |
|---|
| 845 |
case 'E': p = "enum "; goto L2; |
|---|
| 846 |
case 'T': p = "typedef "; goto L2; |
|---|
| 847 |
|
|---|
| 848 |
L2: p ~= parseQualifiedName(); |
|---|
| 849 |
goto L1; |
|---|
| 850 |
|
|---|
| 851 |
L1: |
|---|
| 852 |
if (isdelegate) |
|---|
| 853 |
error(); // 'D' must be followed by function |
|---|
| 854 |
if (identifier.length) |
|---|
| 855 |
p ~= " " ~ identifier; |
|---|
| 856 |
return p; |
|---|
| 857 |
|
|---|
| 858 |
default: |
|---|
| 859 |
size_t i = ni - 1; |
|---|
| 860 |
ni = name.length; |
|---|
| 861 |
p = name[i .. length]; |
|---|
| 862 |
goto L1; |
|---|
| 863 |
} |
|---|
| 864 |
assert(0); |
|---|
| 865 |
} |
|---|
| 866 |
|
|---|
| 867 |
char[] parseTemplateInstanceName() |
|---|
| 868 |
{ |
|---|
| 869 |
char[] result = parseSymbolName() ~ "!("; |
|---|
| 870 |
int nargs; |
|---|
| 871 |
|
|---|
| 872 |
while (1) |
|---|
| 873 |
{ size_t i; |
|---|
| 874 |
|
|---|
| 875 |
if (ni >= name.length) |
|---|
| 876 |
error(); |
|---|
| 877 |
if (nargs && name[ni] != 'Z') |
|---|
| 878 |
result ~= ", "; |
|---|
| 879 |
nargs++; |
|---|
| 880 |
switch (name[ni++]) |
|---|
| 881 |
{ |
|---|
| 882 |
case 'T': |
|---|
| 883 |
result ~= parseType(); |
|---|
| 884 |
continue; |
|---|
| 885 |
|
|---|
| 886 |
case 'V': |
|---|
| 887 |
|
|---|
| 888 |
void getReal() |
|---|
| 889 |
{ |
|---|
| 890 |
real r; |
|---|
| 891 |
ubyte *p = cast(ubyte *)&r; |
|---|
| 892 |
|
|---|
| 893 |
if (ni + 10 * 2 > name.length) |
|---|
| 894 |
error(); |
|---|
| 895 |
for (i = 0; i < 10; i++) |
|---|
| 896 |
{ |
|---|
| 897 |
ubyte b; |
|---|
| 898 |
|
|---|
| 899 |
b = cast(ubyte) |
|---|
| 900 |
( |
|---|
| 901 |
(ascii2hex(name[ni + i * 2]) << 4) + |
|---|
| 902 |
ascii2hex(name[ni + i * 2 + 1]) |
|---|
| 903 |
); |
|---|
| 904 |
p[i] = b; |
|---|
| 905 |
} |
|---|
| 906 |
result ~= ConvertFloat.toString(r); |
|---|
| 907 |
ni += 10 * 2; |
|---|
| 908 |
} |
|---|
| 909 |
|
|---|
| 910 |
result ~= parseType() ~ " "; |
|---|
| 911 |
if (ni >= name.length) |
|---|
| 912 |
error(); |
|---|
| 913 |
switch (name[ni++]) |
|---|
| 914 |
{ |
|---|
| 915 |
case '0': case '1': case '2': case '3': case '4': |
|---|
| 916 |
case '5': case '6': case '7': case '8': case '9': |
|---|
| 917 |
i = ni - 1; |
|---|
| 918 |
while (ni < name.length && isdigit(name[ni])) |
|---|
| 919 |
ni++; |
|---|
| 920 |
result ~= name[i .. ni]; |
|---|
| 921 |
break; |
|---|
| 922 |
|
|---|
| 923 |
case 'N': |
|---|
| 924 |
i = ni; |
|---|
| 925 |
while (ni < name.length && isdigit(name[ni])) |
|---|
| 926 |
ni++; |
|---|
| 927 |
if (i == ni) |
|---|
| 928 |
error(); |
|---|
| 929 |
result ~= "-" ~ name[i .. ni]; |
|---|
| 930 |
break; |
|---|
| 931 |
|
|---|
| 932 |
case 'n': |
|---|
| 933 |
result ~= "null"; |
|---|
| 934 |
break; |
|---|
| 935 |
|
|---|
| 936 |
case 'e': |
|---|
| 937 |
getReal(); |
|---|
| 938 |
break; |
|---|
| 939 |
|
|---|
| 940 |
case 'c': |
|---|
| 941 |
getReal(); |
|---|
| 942 |
result ~= '+'; |
|---|
| 943 |
getReal(); |
|---|
| 944 |
result ~= 'i'; |
|---|
| 945 |
break; |
|---|
| 946 |
|
|---|
| 947 |
case 'a': |
|---|
| 948 |
case 'w': |
|---|
| 949 |
case 'd': |
|---|
| 950 |
{ char m = name[ni - 1]; |
|---|
| 951 |
if (m == 'a') |
|---|
| 952 |
m = 'c'; |
|---|
| 953 |
size_t n = parseNumber(); |
|---|
| 954 |
if (ni >= name.length || name[ni++] != '_' || |
|---|
| 955 |
ni + n * 2 > name.length) |
|---|
| 956 |
error(); |
|---|
| 957 |
result ~= '"'; |
|---|
| 958 |
for (i = 0; i < n; i++) |
|---|
| 959 |
{ char c; |
|---|
| 960 |
|
|---|
| 961 |
c = (ascii2hex(name[ni + i * 2]) << 4) + |
|---|
| 962 |
ascii2hex(name[ni + i * 2 + 1]); |
|---|
| 963 |
result ~= c; |
|---|
| 964 |
} |
|---|
| 965 |
ni += n * 2; |
|---|
| 966 |
result ~= '"'; |
|---|
| 967 |
result ~= m; |
|---|
| 968 |
break; |
|---|
| 969 |
} |
|---|
| 970 |
|
|---|
| 971 |
default: |
|---|
| 972 |
error(); |
|---|
| 973 |
break; |
|---|
| 974 |
} |
|---|
| 975 |
continue; |
|---|
| 976 |
|
|---|
| 977 |
case 'S': |
|---|
| 978 |
result ~= parseSymbolName(); |
|---|
| 979 |
continue; |
|---|
| 980 |
|
|---|
| 981 |
case 'Z': |
|---|
| 982 |
break; |
|---|
| 983 |
|
|---|
| 984 |
default: |
|---|
| 985 |
error(); |
|---|
| 986 |
} |
|---|
| 987 |
break; |
|---|
| 988 |
} |
|---|
| 989 |
result ~= ")"; |
|---|
| 990 |
return result; |
|---|
| 991 |
} |
|---|
| 992 |
|
|---|
| 993 |
if (name.length < 3 || |
|---|
| 994 |
name[0] != '_' || |
|---|
| 995 |
name[1] != 'D' || |
|---|
| 996 |
!isdigit(name[2])) |
|---|
| 997 |
{ |
|---|
| 998 |
goto Lnot; |
|---|
| 999 |
} |
|---|
| 1000 |
|
|---|
| 1001 |
fparseTemplateInstanceName = &parseTemplateInstanceName; |
|---|
| 1002 |
|
|---|
| 1003 |
try |
|---|
| 1004 |
{ |
|---|
| 1005 |
/+ |
|---|
| 1006 |
auto result = parseQualifiedName(); |
|---|
| 1007 |
|
|---|
| 1008 |
result = parseType(result); |
|---|
| 1009 |
|
|---|
| 1010 |
while(ni < name.length) |
|---|
| 1011 |
{ |
|---|
| 1012 |
result ~= " . " ~ parseType(parseQualifiedName()); |
|---|
| 1013 |
} |
|---|
| 1014 |
|
|---|
| 1015 |
if (ni != name.length) |
|---|
| 1016 |
goto Lnot; |
|---|
| 1017 |
return result; |
|---|
| 1018 |
+/ |
|---|
| 1019 |
|
|---|
| 1020 |
if (pMode == ParseMode.Full) |
|---|
| 1021 |
{ |
|---|
| 1022 |
auto result = parseQualifiedName(); |
|---|
| 1023 |
|
|---|
| 1024 |
|
|---|
| 1025 |
result = parseType(result); |
|---|
| 1026 |
|
|---|
| 1027 |
while(ni < name.length) |
|---|
| 1028 |
{ |
|---|
| 1029 |
result ~= " . " ~ parseType(parseQualifiedName()); |
|---|
| 1030 |
} |
|---|
| 1031 |
|
|---|
| 1032 |
if (ni != name.length) |
|---|
| 1033 |
goto Lnot; |
|---|
| 1034 |
return result; |
|---|
| 1035 |
} |
|---|
| 1036 |
else |
|---|
| 1037 |
{ |
|---|
| 1038 |
auto result = parseQualifiedName(); |
|---|
| 1039 |
|
|---|
| 1040 |
|
|---|
| 1041 |
type ~= parseType(); |
|---|
| 1042 |
|
|---|
| 1043 |
while(ni < name.length) |
|---|
| 1044 |
{ |
|---|
| 1045 |
result ~= " . " ~ parseQualifiedName(); |
|---|
| 1046 |
type ~= " . " ~ parseType(); |
|---|
| 1047 |
} |
|---|
| 1048 |
|
|---|
| 1049 |
if (ni != name.length) |
|---|
| 1050 |
goto Lnot; |
|---|
| 1051 |
return result; |
|---|
| 1052 |
} |
|---|
| 1053 |
} |
|---|
| 1054 |
catch (MangleException e) |
|---|
| 1055 |
{ |
|---|
| 1056 |
} |
|---|
| 1057 |
|
|---|
| 1058 |
|
|---|
| 1059 |
Lnot: |
|---|
| 1060 |
// Not a recognized D mangled name; so return original |
|---|
| 1061 |
return name; |
|---|
| 1062 |
} |
|---|