(* 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" -- compiles the file "base.c" to produce "base.o". *) val compile : string -> unit (* link "base" -- links base.o with the Diderot runtime to produce the executable * "base". *) val link : string -> unit end = struct (* FIXME: control flags that should go somewhere else *) val debug = ref false val verbose = ref true fun system cmd = ( if !verbose then print(cmd ^ "\n") else (); if OS.Process.isSuccess(OS.Process.system cmd) then () else raise Fail "error compiling/linking") fun compile baseName = let val cFile = OS.Path.joinBaseExt{base=baseName, ext=SOME"c"} val cflags = if !debug then Paths.cflags else String.concatWith " " ["-DNDEBUG", Paths.cflags] val cmd = String.concatWith " " [ Paths.cc, "-c", cflags, "-I" ^ Paths.diderotInclude, "-I" ^ Paths.teemInclude, cFile ] in PhaseTimer.withTimer Timers.timeCC system cmd end fun link baseName = let val objFile = OS.Path.joinBaseExt{base=baseName, ext=SOME"o"} val exeFile = baseName val cmd = String.concatWith " " ([ Paths.cc, "-o", exeFile, objFile, OS.Path.concat(Paths.diderotLib, "diderot-lib.o") ] @ Paths.teemLinkFlags @ [Paths.extraLibs]) in PhaseTimer.withTimer Timers.timeCC system cmd end end