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

SCM Repository

[diderot] View of /trunk/src/compiler/common/log.sml
ViewVC logotype

View of /trunk/src/compiler/common/log.sml

Parent Directory Parent Directory | Revision Log Revision Log


Revision 340 - (download) (annotate)
Mon Sep 13 15:34:36 2010 UTC (9 years, 1 month ago) by jhr
File size: 979 byte(s)
  Working on debugging HighIL optimization
(* log.sml
 *
 * COPYRIGHT (c) 2010 The Diderot Project (http://diderot.cs.uchicago.edu)
 * All rights reserved.
 *)

structure Log : sig

    val enabled : unit -> bool

    val init : string -> unit

    val logFile : unit -> TextIO.outstream

    val msg : string -> unit

  end = struct

    val enabledFlg = ref false
    val logStrm : TextIO.outstream option ref = ref NONE

    fun enabled () = !enabledFlg

    fun init file = (case !logStrm
	   of NONE => let
		val outS = TextIO.openOut file
		in
		  enabledFlg := true;
		(* turn off buffering *)
		  TextIO.StreamIO.setBufferMode (TextIO.getOutstream outS, IO.NO_BUF);
		  logStrm := SOME outS
		end
	    | SOME strm => raise Fail "multiple initialization of log file"
	  (* end case *))

    fun logFile () = (case !logStrm
	   of NONE => (init "/dev/null"; enabledFlg := false; logFile())
	    | SOME outS => outS
	  (* end case *))

    fun msg s = if !enabledFlg then TextIO.output(logFile(), s) else ();

  end


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