forked from jahin07/compiler
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPLPRuntimeLog.java
45 lines (35 loc) · 950 Bytes
/
PLPRuntimeLog.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
package cop5556sp17;
/**
*
* A simple globalLog that can be used to record a trace of
* the PLPRuntime* method calls and output from
* CodeGenUtils.genPrint and CodeGenUtils.getPrintTOS.
* This is required at runtime.
*
* The output can be used for grading and debugging.
*
*/
public class PLPRuntimeLog {
private StringBuffer sb;
public static PLPRuntimeLog globalLog;
public static void initLog() {
globalLog = new PLPRuntimeLog();
globalLog.sb = new StringBuffer();
}
public static void globalLogAddEntry(String entry){
if (globalLog != null) globalLog.addEntry(entry);
}
private void addEntry(String entry) {
sb.append(entry);
}
public static String getString() {
return (globalLog != null) ? globalLog.toString() : "";
}
@Override
public String toString() {
return sb.toString();
}
public static void resetLogToNull() {
globalLog = null;
}
}