-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathApplication.java
55 lines (43 loc) · 1.77 KB
/
Application.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
package org.bw.tl;
import org.bw.tl.util.CompileUtilities;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.util.Map;
public class Application {
public static void main(final String[] args) throws IOException {
if (args.length < 2) {
System.out.println("Usage: titonc <src_dir> <out_dir>");
System.exit(1);
}
final String[] classpath = {
"C:\\Users\\brad\\IdeaProjects\\test-lang\\triton-stdlib\\target\\triton-stdlib-1.0-SNAPSHOT.jar"
};
final Map<String, byte[]> classes = CompileUtilities.compile(args[0], classpath);
if (classes == null) {
System.err.println("Compilation Failed!");
System.exit(1);
} else {
final File parent = new File(args[1]);
if (!parent.exists()) {
if (!parent.mkdirs()) {
System.err.println("Cannot create folder: " + parent);
System.exit(1);
}
}
for (final Map.Entry<String, byte[]> entry : classes.entrySet()) {
final File classFile = new File(parent, entry.getKey().replace(".", "//") + ".class");
if (!classFile.getParentFile().exists()) {
if (!classFile.getParentFile().mkdirs()) {
System.err.println("Cannot create folder: " + classFile.getParentFile());
System.exit(1);
}
}
final FileOutputStream fos = new FileOutputStream(classFile);
fos.write(entry.getValue());
fos.close();
}
System.out.printf("%d files successfully compiled!", classes.size());
}
}
}