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

SCM Repository

[diderot] View of /trunk/src/compiler/c-util/run-cc.sml
ViewVC logotype

View of /trunk/src/compiler/c-util/run-cc.sml

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1372 - (download) (annotate)
Wed Jun 22 21:24:17 2011 UTC (7 years, 11 months ago) by jhr
File size: 1195 byte(s)
  merging changes from pure-cfg
(* run-cc.sml
 *
 * COPYRIGHT (c) 2011 The Diderot Project (http://diderot-language.cs.uchicago.edu)
 * All rights reserved.
 *
 * Support for running the C compiler to compile and link the generated code.
 *)

structure RunCC : sig

  (* compile ("base", cflags) -- compiles the file "base.c" to produce "base.o". *)
    val compile : string * string list -> unit

  (* link ("base", opts) -- links base.o using the given options (libraries, etc.) *)
    val link : string * string list -> unit

  end = struct

    fun system cmd = (
	  Log.msg(cmd ^ "\n");
	  if OS.Process.isSuccess(OS.Process.system cmd)
	    then ()
	    else raise Fail "error compiling/linking")

    fun compile (baseName, cflags) = let
	  val cFile = OS.Path.joinBaseExt{base=baseName, ext=SOME"c"}
	  val cmd = String.concatWith " " ([Paths.cc, "-c"] @ cflags @ [cFile])
	  in
	    PhaseTimer.withTimer Timers.timeCC system cmd
	  end

    fun link (baseName, ldOpts) = let
	  val objFile = OS.Path.joinBaseExt{base=baseName, ext=SOME"o"}
	  val exeFile = baseName
	  val cmd = String.concatWith " " ([Paths.cc, "-o", exeFile, objFile] @ ldOpts)
	  in
	    PhaseTimer.withTimer Timers.timeCC system cmd
	  end

  end

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