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

SCM Repository

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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1166 - (view) (download)
Original Path: trunk/src/compiler/c-target/run-cc.sml

1 : jhr 1115 (* run-cc.sml
2 :     *
3 :     * COPYRIGHT (c) 2011 The Diderot Project (http://diderot-language.cs.uchicago.edu)
4 :     * All rights reserved.
5 :     *
6 :     * Support for running the C compiler to compile and link the generated code.
7 :     *)
8 :    
9 :     structure RunCC : sig
10 :    
11 :     (* compile "base" -- compiles the file "base.c" to produce "base.o". *)
12 :     val compile : string -> unit
13 :    
14 :     (* link "base" -- links base.o with the Diderot runtime to produce the executable
15 :     * "base".
16 :     *)
17 :     val link : string -> unit
18 :    
19 :     end = struct
20 :    
21 :     (* FIXME: control flags that should go somewhere else *)
22 :     val debug = ref false
23 :     val verbose = ref true
24 :    
25 :     fun system cmd = (
26 :     if !verbose
27 : jhr 1166 then Log.msg(cmd ^ "\n")
28 : jhr 1115 else ();
29 :     if OS.Process.isSuccess(OS.Process.system cmd)
30 :     then ()
31 :     else raise Fail "error compiling/linking")
32 :    
33 :     fun compile baseName = let
34 :     val cFile = OS.Path.joinBaseExt{base=baseName, ext=SOME"c"}
35 :     val cflags = if !debug
36 :     then Paths.cflags
37 :     else String.concatWith " " ["-DNDEBUG", Paths.cflags]
38 :     val cmd = String.concatWith " " [
39 :     Paths.cc, "-c", cflags,
40 :     "-I" ^ Paths.diderotInclude, "-I" ^ Paths.teemInclude,
41 :     cFile
42 :     ]
43 :     in
44 :     PhaseTimer.withTimer Timers.timeCC system cmd
45 :     end
46 :    
47 :     fun link baseName = let
48 :     val objFile = OS.Path.joinBaseExt{base=baseName, ext=SOME"o"}
49 :     val exeFile = baseName
50 :     val cmd = String.concatWith " " ([
51 :     Paths.cc, "-o", exeFile, objFile,
52 :     OS.Path.concat(Paths.diderotLib, "diderot-lib.o")
53 :     ] @ Paths.teemLinkFlags @ [Paths.extraLibs])
54 :     in
55 :     PhaseTimer.withTimer Timers.timeCC system cmd
56 :     end
57 :    
58 :     end

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