(* 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