Hello Abdelraouf,

> I'm working on the latest version of CIL (1.3.7) and I would like to
> use it with some avr embedded code. I've found that you have already a
> patch for an earlier version. Can you help me finding how to do the
> same parch for CIL 1.3.7.

CIL 1.3.7 improved support (or maybe it was always complete?) for
configuring the target architecture at runtime using the Cil.envMachine
variable.  No more need to build architecture specific versions.  Yay!

I've attached a trivial CIL program and wrapper script demonstrating how
to set this information up from the command line.  The basic approach
is:

- Set the CIL_MACHINE environment variable to describe the target
  architecture as documented at http://www.eecs.berkeley.edu/~necula/cil/
- Add the envmachine flag to your application to trigger the function
  setting Cil.envMachine using the data in CIL_MACHINE
- Add a function to read the data from CIL_MACHINE into Cil.envMachine

Also attached is a Makefile to build the application.  You can take the
full set for a test run using:

----
export CILPATH=/path/to/installation/of/cil-1.3.7
make
sh null.sh infile.i outfile.i avr
----

Hope that helps,
-Roy
open Cil

let doFile outChannel fileName =

  let cilFile = Frontc.parse fileName () in

  (* Perform no transformation.  Simply dump the file back out. *)
    match outChannel with
      | None -> dumpFile !printerForMaincil stdout cilFile.fileName cilFile
      | Some c -> dumpFile !printerForMaincil c cilFile.fileName cilFile
;;


(* Load a machine model using the CIL_MACHINE enviornment variable. *)
let loadEnv _ =
  let _ =
    try
      let machineModel = Sys.getenv "CIL_MACHINE" in
        Cil.envMachine := Some (Machdepenv.modelParse machineModel);
    with
        Not_found ->
          ignore (Errormsg.error "CIL_MACHINE environment variable is not set")
      | Failure msg ->
          ignore (Errormsg.error "CIL_MACHINE machine model is invalid: %s" msg)
  in
    ()
;;


let mainFunction () =

  let usageMsg = "Usage: null <options> source-file" in
  let fileNames : string list ref = ref [] in

  let recordFile fname =
    fileNames := fname :: (!fileNames)
  in

  let outFile = ref "" in

  let argDescr = [
    ("--out", Arg.Set_string outFile, "Name of the output CIL file");
    ("--envmachine", Arg.Unit loadEnv, "Specify machine model using CIL_MACHINE environment variable");
  ] in

  let _ = Arg.parse argDescr recordFile usageMsg in

  let outChannel =
    try Some (open_out !outFile)
    with
        Sys_error _ when !outFile = "" -> None
      | Sys_error _ -> raise (Arg.Bad ("Cannot open output file " ^ !outFile))
  in

    Cil.initCIL ();
    List.iter (doFile outChannel) !fileNames;
;;

(* Do stuff *)
mainFunction ();;

Attachment: null.sh
Description: Bourne shell script

Attachment: Makefile
Description: Binary data

------------------------------------------------------------------------------
Start uncovering the many advantages of virtual appliances
and start using them to simplify application deployment and
accelerate your shift to cloud computing.
http://p.sf.net/sfu/novell-sfdev2dev
_______________________________________________
CIL-users mailing list
CIL-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/cil-users

Reply via email to