SCM Repository
Annotation of /trunk/src/compiler/common/log.sml
Parent Directory
|
Revision Log
Revision 3349 - (view) (download)
1 : | jhr | 237 | (* log.sml |
2 : | * | ||
3 : | jhr | 3349 | * This code is part of the Diderot Project (http://diderot-language.cs.uchicago.edu) |
4 : | * | ||
5 : | * COPYRIGHT (c) 2015 The University of Chicago | ||
6 : | jhr | 237 | * All rights reserved. |
7 : | *) | ||
8 : | |||
9 : | structure Log : sig | ||
10 : | |||
11 : | jhr | 340 | val enabled : unit -> bool |
12 : | |||
13 : | jhr | 237 | val init : string -> unit |
14 : | |||
15 : | val logFile : unit -> TextIO.outstream | ||
16 : | |||
17 : | val msg : string -> unit | ||
18 : | |||
19 : | jhr | 1116 | val reportTiming : PhaseTimer.timer -> unit |
20 : | |||
21 : | jhr | 237 | end = struct |
22 : | |||
23 : | jhr | 340 | val enabledFlg = ref false |
24 : | jhr | 237 | val logStrm : TextIO.outstream option ref = ref NONE |
25 : | |||
26 : | jhr | 340 | fun enabled () = !enabledFlg |
27 : | |||
28 : | jhr | 237 | fun init file = (case !logStrm |
29 : | of NONE => let | ||
30 : | val outS = TextIO.openOut file | ||
31 : | in | ||
32 : | jhr | 340 | enabledFlg := true; |
33 : | jhr | 237 | (* turn off buffering *) |
34 : | TextIO.StreamIO.setBufferMode (TextIO.getOutstream outS, IO.NO_BUF); | ||
35 : | logStrm := SOME outS | ||
36 : | end | ||
37 : | | SOME strm => raise Fail "multiple initialization of log file" | ||
38 : | (* end case *)) | ||
39 : | |||
40 : | fun logFile () = (case !logStrm | ||
41 : | jhr | 340 | of NONE => (init "/dev/null"; enabledFlg := false; logFile()) |
42 : | jhr | 237 | | SOME outS => outS |
43 : | (* end case *)) | ||
44 : | |||
45 : | jhr | 340 | fun msg s = if !enabledFlg then TextIO.output(logFile(), s) else (); |
46 : | jhr | 237 | |
47 : | jhr | 1116 | fun reportTiming timer = PhaseTimer.report (logFile(), timer) |
48 : | |||
49 : | jhr | 237 | end |
50 : | jhr | 340 |
root@smlnj-gforge.cs.uchicago.edu | ViewVC Help |
Powered by ViewVC 1.0.0 |