Home My Page Projects Code Snippets Project Openings diderot
Summary Activity Tracker Tasks SCM

SCM Repository

[diderot] Annotation of /branches/vis12/src/compiler/common/log.sml
ViewVC logotype

Annotation of /branches/vis12/src/compiler/common/log.sml

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1685 - (view) (download)

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

root@smlnj-gforge.cs.uchicago.edu
ViewVC Help
Powered by ViewVC 1.0.0