-
Notifications
You must be signed in to change notification settings - Fork 233
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #3581 from mtzguido/ocamlc
Introducing --ocamlc and --ocamlc_plugin
- Loading branch information
Showing
11 changed files
with
232 additions
and
78 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
(* | ||
Copyright 2008-2016 Nikhil Swamy and Microsoft Research | ||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
http://www.apache.org/licenses/LICENSE-2.0 | ||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
*) | ||
module FStarC.OCaml | ||
|
||
open FStarC | ||
open FStarC.Compiler | ||
open FStarC.Compiler.Effect | ||
|
||
let shellescape (s:string) : string = | ||
String.list_of_string s |> | ||
List.map (function | ||
| '\'' -> "'\"'\"'" // to escape single quotes we need to put them inside a double quote | ||
| c -> String.make 1 c | ||
) |> | ||
String.concat "" | ||
|
||
let new_ocamlpath () : string = | ||
let ocamldir = Find.locate_ocaml () in | ||
let old_ocamlpath = Util.dflt "" (Util.expand_environment_variable "OCAMLPATH") in | ||
let new_ocamlpath = ocamldir ^ ":" ^ old_ocamlpath in | ||
new_ocamlpath | ||
|
||
let exec_in_ocamlenv #a (cmd : string) (args : list string) : a = | ||
let new_ocamlpath = new_ocamlpath () in | ||
if Platform.system = Platform.Windows then ( | ||
Errors.raise_error0 Errors.Fatal_OptionsNotCompatible [ | ||
Errors.text "--ocamlenv is not supported on Windows (yet?)" | ||
] | ||
); | ||
(* Update OCAMLPATH and run (exec) the command *) | ||
Util.putenv "OCAMLPATH" new_ocamlpath; | ||
Util.execvp cmd (cmd :: args); | ||
failwith "execvp failed" | ||
|
||
(* OCaml Warning 8: this pattern-matching is not exhaustive. | ||
This is usually benign as we check for exhaustivenss via SMT. *) | ||
|
||
let exec_ocamlc args = | ||
exec_in_ocamlenv "ocamlfind" | ||
("opt" :: "-w" :: "-8" :: "-linkpkg" :: "-package" :: "fstar.lib" :: args) | ||
|
||
let exec_ocamlc_plugin args = | ||
exec_in_ocamlenv "ocamlfind" | ||
("opt" :: "-w" :: "-8" :: "-shared" :: "-package" :: "fstar.lib" :: | ||
args) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
(* | ||
Copyright 2008-2016 Nikhil Swamy and Microsoft Research | ||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
http://www.apache.org/licenses/LICENSE-2.0 | ||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
*) | ||
module FStarC.OCaml | ||
|
||
open FStarC.Compiler.Effect | ||
|
||
(* Escape a string for use in a shell command, expecting to be wrapped in SINGLE quotes. *) | ||
val shellescape (s:string) : string | ||
|
||
(* Compute a value for OCAMLPATH taken from the current env + extended with our own library. | ||
This is NOT escaped. *) | ||
val new_ocamlpath () : string | ||
|
||
(* Run a command with the new OCAMLPATH set. The cmd is usually args[0], in Unix convention. | ||
This calls execvp, so it will not return if successful. Raises a Failure if the execvp fails. | ||
It also tries to find the command in the PATH, absolute path is not needed. *) | ||
val exec_in_ocamlenv (#a:Type) (cmd : string) (args : list string) : a | ||
|
||
(* Run ocamlc passing appropriate flags to generate an executable. Expects | ||
the source file and further options as arguments. *) | ||
val exec_ocamlc #a (args : list string) : a | ||
|
||
(* Run ocamlc passing appropriate flags to generate an F* plugin, using | ||
fstar_plugin_lib. Expects the source file and further options as arguments. *) | ||
val exec_ocamlc_plugin #a (args : list string) : a |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,8 +4,3 @@ | |
(libraries fstar.lib) | ||
(modes native) | ||
) | ||
(env | ||
(_ | ||
(bin_annot false) | ||
(flags (:standard -w -A))) | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters