Permalink
Browse files

Check for required LLVM version or issue warning

This checks that a required LLVM version (i.e. 3.4 or greater) is already
installed in the system when 'to_llvm' flag is used. If that's not the case the
flag is ignored and a warning is issued.
  • Loading branch information...
1 parent c2b4eab commit 60185b5f0c52c483ed0fc10b07e720d39f0cdec3 @yiannist committed Mar 26, 2014
Showing with 32 additions and 1 deletion.
  1. +32 −1 lib/hipe/main/hipe.erl
View
33 lib/hipe/main/hipe.erl
@@ -200,6 +200,7 @@
compile_core/4,
file/1,
file/2,
+ llvm_support_available/0,
load/1,
help/0,
help_hiper/0,
@@ -648,7 +649,17 @@ run_compiler_1(DisasmFun, IcodeFun, Options) ->
%% The full option expansion is not done
%% until the DisasmFun returns.
{Code, CompOpts} = DisasmFun(Options),
- Opts = expand_options(Options ++ CompOpts),
+ Opts0 = expand_options(Options ++ CompOpts),
+ Opts =
+ case proplists:get_bool(to_llvm, Opts0) andalso
+ not llvm_support_available() of
+ true ->
+ ?WARNING_MSG("Ignoring 'to_llvm' because there is no LLVM 3.4 or " ++
+ "greater installed in the system.\n", []),
+ proplists:delete(to_llvm, Opts0);
+ false ->
+ Opts0
+ end,
check_options(Opts),
?when_option(verbose, Options,
?debug_msg("Options: ~p.\n",[Opts])),
@@ -1537,4 +1548,24 @@ check_options(Opts) ->
ok
end.
+-spec llvm_support_available() -> boolean().
+
+llvm_support_available() ->
+ get_llvm_version() >= 3.4.
+
+get_llvm_version() ->
+ OptStr = os:cmd("opt -version"),
+ SubStr = "LLVM version ", N = length(SubStr),
+ case string:str(OptStr, SubStr) of
+ 0 -> % No opt available
+ 0;
+ S ->
+ Version =
+ case string:to_float(string:sub_string(OptStr, S + N)) of
+ {error, _} -> 0; %XXX: Assumes no revision numbers in versioning
+ {Float, _} -> Float
+ end,
+ Version
+ end.
+
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

0 comments on commit 60185b5

Please sign in to comment.