Mercurial > projects > ldc
comparison tester.d @ 50:6fcc08a4d406 trunk
[svn r54] Added support for nested delegates referencing parent's stack variables.
Replaced tester.sh with a version written in D.
A few bugfixes.
author | lindquist |
---|---|
date | Mon, 22 Oct 2007 15:40:56 +0200 |
parents | |
children | 1700239cab2e |
comparison
equal
deleted
inserted
replaced
49:e5c4bece7fa1 | 50:6fcc08a4d406 |
---|---|
1 module tester; | |
2 | |
3 import std.file; | |
4 import std.path; | |
5 import std.process; | |
6 import std.stdio; | |
7 import std.string; | |
8 | |
9 void printUsage(string cmd) | |
10 { | |
11 writefln("Usage:"); | |
12 writefln(" ",cmd," %%name %%cmd %%..."); | |
13 writefln("%%name:"); | |
14 writefln(" name of test without path or extension. eg: bug1"); | |
15 writefln("%%cmd:"); | |
16 writefln(" c = compile module"); | |
17 writefln(" gdb = same as 'c' but launches compiler in gdb"); | |
18 writefln(" ll = compile module and print the disassemled bitcode"); | |
19 writefln(" llo = compile and optimize module, then print the disassemled bitcode"); | |
20 writefln("%%..."); | |
21 writefln(" the rest of the command line options are passed directly to llvmdc"); | |
22 } | |
23 | |
24 string testFileName(string test, string ext="") | |
25 { | |
26 return "test/"~test~ext; | |
27 } | |
28 | |
29 // couldnt get execvp to work | |
30 int execute(string cmd) | |
31 { | |
32 return system(cmd); | |
33 } | |
34 int execute(string cmd, string[] args) | |
35 { | |
36 char[] c = cmd.dup; | |
37 foreach(v; args) { | |
38 c ~= ' '; | |
39 c ~= v; | |
40 } | |
41 writefln(c); | |
42 return system(c); | |
43 } | |
44 | |
45 void compileTest(string test, string[] args) | |
46 { | |
47 args = [testFileName(test,".d")] ~ args; | |
48 if (execute("llvmdc", args) != 0) { | |
49 throw new Exception("Failed to compile test: "~test); | |
50 } | |
51 } | |
52 | |
53 void disassembleTest(string test, bool print) | |
54 { | |
55 string[] args = ["-f",testFileName(test,".bc")]; | |
56 if (execute("llvm-dis", args) != 0) { | |
57 throw new Exception("Failed to disassemble test: "~test); | |
58 } | |
59 if (print) { | |
60 execute("cat "~testFileName(test,".ll")); | |
61 } | |
62 } | |
63 | |
64 void debugTest(string test, string[] common) | |
65 { | |
66 string[] args = ["--args", "llvmdc", testFileName(test,".d")]; | |
67 args ~= common; | |
68 if (execute("gdb", args) != 0) { | |
69 throw new Exception("Failed to compile test: '"~test~"' for debugging"); | |
70 } | |
71 } | |
72 | |
73 void optimizeTest(string test) | |
74 { | |
75 string bc = testFileName(test,".bc"); | |
76 if (execute("opt -std-compile-opts -f -o="~bc~" "~bc)) { | |
77 throw new Exception("Failed to optimize test: "~test); | |
78 } | |
79 } | |
80 | |
81 void runTest(string test) | |
82 { | |
83 if (execute(testFileName(test))) { | |
84 throw new Exception("Failed to run test: "~test); | |
85 } | |
86 } | |
87 | |
88 int main(string[] args) | |
89 { | |
90 if (args.length < 3) { | |
91 printUsage(args[0]); | |
92 return 1; | |
93 } | |
94 | |
95 string test = args[1]; | |
96 string kind = args[2]; | |
97 | |
98 string[] compilelink = ["-Itest","-odtest"]; | |
99 compilelink ~= args[3..$]; | |
100 string[] compileonly = compilelink.dup; | |
101 | |
102 compileonly ~= "-c"; | |
103 compilelink ~= "-of"~testFileName(test); | |
104 | |
105 switch(kind) { | |
106 case "c": | |
107 compileTest(test,compileonly); | |
108 break; | |
109 case "gdb": | |
110 debugTest(test,compileonly); | |
111 break; | |
112 case "ll": | |
113 compileTest(test,compileonly); | |
114 disassembleTest(test,true); | |
115 break; | |
116 case "llo": | |
117 compileTest(test,compileonly); | |
118 optimizeTest(test); | |
119 disassembleTest(test,true); | |
120 break; | |
121 case "run": | |
122 compileTest(test,compilelink); | |
123 runTest(test); | |
124 break; | |
125 default: | |
126 throw new Exception("Invalid command: "~kind); | |
127 } | |
128 return 0; | |
129 } |