-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathArgumentParser.java
More file actions
109 lines (100 loc) · 3.43 KB
/
ArgumentParser.java
File metadata and controls
109 lines (100 loc) · 3.43 KB
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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.PrintStream;
import java.io.InputStream;
public class ArgumentParser {
private String inputFile = null;
private String outputLLVMFile = null;
private String outputOptiFile = null;
private String outputASMFile = null;
private String errFile = null;
private boolean debug = false;
public ArgumentParser(String[] args) {
parseArgs(args);
}
private void parseArgs(String[] args) {
for (int i = 0; i < args.length; i++) {
switch (args[i]) {
case "-i":
case "--input":
if (i + 1 < args.length) {
inputFile = args[++i];
} else {
throw new IllegalArgumentException("Missing input file argument");
}
break;
case "-llvm":
if (i + 1 < args.length) {
outputLLVMFile = args[++i];
} else {
throw new IllegalArgumentException("Missing outputLLVM file argument");
}
break;
case "-asm":
if (i + 1 < args.length) {
outputLLVMFile = args[++i];
} else {
throw new IllegalArgumentException("Missing outputASM file argument");
}
break;
case "-e":
case "--error":
if (i + 1 < args.length) {
errFile = args[++i];
} else {
throw new IllegalArgumentException("Missing error file argument");
}
break;
case "-d":
case "--debug":
debug = true;
inputFile = "test.mx";
outputLLVMFile = "test.ll";
outputOptiFile = "test_opti.ll";
outputASMFile = "test.s";
errFile = "debug.out";
break;
default:
throw new IllegalArgumentException("Unknown argument: " + args[i]);
}
}
}
public InputStream getInputStream() throws Exception {
if (inputFile != null) {
return new FileInputStream(inputFile);
} else {
return System.in;
}
}
public PrintStream getLLVMStream() throws Exception {
if (outputLLVMFile != null) {
return new PrintStream(new FileOutputStream(outputLLVMFile));
} else {
return System.out;
}
}
public PrintStream getOptiStream() throws Exception {
if (outputOptiFile != null) {
return new PrintStream(new FileOutputStream(outputOptiFile));
} else {
return System.out;
}
}
public PrintStream getASMStream() throws Exception {
if (outputASMFile != null) {
return new PrintStream(new FileOutputStream(outputASMFile));
} else {
return System.out;
}
}
public PrintStream getErrorStream() throws Exception {
if (errFile != null) {
return new PrintStream(new FileOutputStream(errFile));
} else {
return System.err;
}
}
public boolean isDebug() {
return debug;
}
}