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

SCM Repository

[diderot] View of /branches/pure-cfg/src/compiler/c-target/run-cc.sml
ViewVC logotype

View of /branches/pure-cfg/src/compiler/c-target/run-cc.sml

Parent Directory Parent Directory | Revision Log Revision Log


Revision 987 - (download) (annotate)
Tue Apr 26 21:43:17 2011 UTC (8 years, 2 months ago) by jhr
File size: 1626 byte(s)
  Split code to compile and link C code into its own module.
(* 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
	      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,
		    "-Wl,-rpath=" ^ Paths.teemLib,	(* so that dynamic loading works *)
		    "-L" ^ Paths.teemLib, "-lteem",
		    OS.Path.concat(Paths.diderotLib, "diderot-lib.o")
		  ]
	    in
	      system cmd
	    end

  end

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