llvm.org GIT mirror llvm / f117506
Remove llvmc and assorted build machinery for it. The problems that llvmc solved have largely been subsumed with the tasks that the clang driver can accomplish, but llvmc lacks flexibility and depends too heavily on the EOL'd llvm-gcc. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@140093 91177308-0d34-0410-b5e6-96231b3b80d8 Eric Christopher 8 years ago
82 changed file(s) with 2 addition(s) and 3115 deletion(s). Raw diff Collapse all Expand all
186186 include/llvm/Config/AsmPrinters.def \
187187 include/llvm/Config/AsmParsers.def \
188188 include/llvm/Config/Disassemblers.def \
189 include/llvm/Support/DataTypes.h \
190 tools/llvmc/src/Base.td
189 include/llvm/Support/DataTypes.h
191190 FilesToConfigPATH := $(addprefix $(LLVM_OBJ_ROOT)/,$(FilesToConfig))
192191
193192 all-local:: $(FilesToConfigPATH)
17551755 AC_CONFIG_FILES([tools/clang/docs/doxygen.cfg])
17561756 fi
17571757
1758 dnl Configure llvmc's Base plugin
1759 AC_CONFIG_FILES([tools/llvmc/src/Base.td])
1760
17611758 dnl Do the first stage of configuration for llvm-config.in.
17621759 AC_CONFIG_FILES([tools/llvm-config/llvm-config.in])
17631760
2160421604
2160521605 fi
2160621606
21607 ac_config_files="$ac_config_files tools/llvmc/src/Base.td"
21608
21609
2161021607 ac_config_files="$ac_config_files tools/llvm-config/llvm-config.in"
2161121608
2161221609
2222622223 "llvm.spec") CONFIG_FILES="$CONFIG_FILES llvm.spec" ;;
2222722224 "docs/doxygen.cfg") CONFIG_FILES="$CONFIG_FILES docs/doxygen.cfg" ;;
2222822225 "tools/clang/docs/doxygen.cfg") CONFIG_FILES="$CONFIG_FILES tools/clang/docs/doxygen.cfg" ;;
22229 "tools/llvmc/src/Base.td") CONFIG_FILES="$CONFIG_FILES tools/llvmc/src/Base.td" ;;
2223022226 "tools/llvm-config/llvm-config.in") CONFIG_FILES="$CONFIG_FILES tools/llvm-config/llvm-config.in" ;;
2223122227 "setup") CONFIG_COMMANDS="$CONFIG_COMMANDS setup" ;;
2223222228 "Makefile") CONFIG_COMMANDS="$CONFIG_COMMANDS Makefile" ;;
+0
-24
test/LLVMC/Alias.td less more
None // Test alias generation.
1 // RUN: tblgen -I %p/../../include --gen-llvmc %s -o %t
2 // RUN: FileCheck -input-file %t %s
3 // RUN: %compile_cxx %t
4 // XFAIL: vg_leak
5
6 include "llvm/CompilerDriver/Common.td"
7
8 def OptList : OptionList<[
9
10 (switch_option "dummy1", (help "none")),
11 // CHECK: cl::alias Alias_dummy2
12 (alias_option "dummy2", "dummy1")
13 ]>;
14
15 def dummy_tool : Tool<[
16 (command "dummy_cmd"),
17 (in_language "dummy_lang"),
18 (out_language "dummy_lang"),
19 (actions (case
20 (switch_on "dummy1"), (forward "dummy1")))
21 ]>;
22
23 def DummyGraph : CompilationGraph<[(edge "root", "dummy_tool")]>;
+0
-29
test/LLVMC/AppendCmdHook.td less more
None // Check that hooks can be invoked from 'append_cmd'.
1 // RUN: tblgen -I %p/../../include --gen-llvmc %s -o %t
2 // RUN: FileCheck -input-file %t %s
3 // RUN: %compile_cxx %t
4 // XFAIL: vg_leak
5
6 include "llvm/CompilerDriver/Common.td"
7
8 // CHECK: std::string MyHook()
9
10 def OptList : OptionList<[
11 (switch_option "dummy1", (help "none")),
12 (switch_option "dummy2", (help "none"))
13 ]>;
14
15 def dummy_tool : Tool<[
16 (command "dummy_cmd"),
17 (in_language "dummy_lang"),
18 (out_language "dummy_lang"),
19 (actions (case
20 // CHECK: , "-arg1"));
21 // CHECK: , "-arg2"));
22 (switch_on "dummy1"), (append_cmd "-arg1 -arg2"),
23 // CHECK: , "-arg3"));
24 // CHECK: hooks::MyHook()
25 (switch_on "dummy2"), (append_cmd "-arg3 $CALL(MyHook)")))
26 ]>;
27
28 def DummyGraph : CompilationGraph<[(edge "root", "dummy_tool")]>;
+0
-5
test/LLVMC/C/dg.exp less more
None load_lib llvm.exp
1
2 if [ llvm_gcc_supports c ] then {
3 RunLLVMTests [lsort [glob -nocomplain $srcdir/$subdir/*.{ll,c,cpp}]]
4 }
+0
-9
test/LLVMC/C/emit-llvm-opt.c less more
None // Check that -emit-llvm [-S] works with -opt.
1
2 // RUN: llvmc -c -opt -emit-llvm -o - %s | llvm-dis | grep "@f0()" | count 1
3 // RUN: llvmc -c -opt -emit-llvm -S -o - %s | grep "@f0()" | count 1
4 // RUN: llvmc --dry-run -c -opt -emit-llvm %s |& grep "^opt"
5 // XFAIL: vg_leak
6
7 int f0(void) {
8 }
+0
-8
test/LLVMC/C/emit-llvm.c less more
None // Check that -emit-llvm [-S] works correctly.
1
2 // RUN: llvmc -c -emit-llvm -o - %s | llvm-dis | grep "@f0()" | count 1
3 // RUN: llvmc -c -emit-llvm -S -o - %s | grep "@f0()" | count 1
4 // XFAIL: vg_leak
5
6 int f0(void) {
7 }
+0
-13
test/LLVMC/C/hello.c less more
None /*
1 * Check that we can compile helloworld
2 * RUN: llvmc %s -o %t
3 * RUN: %abs_tmp | grep hello
4 * XFAIL: vg_leak
5 */
6
7 #include
8
9 int main() {
10 printf("hello\n");
11 return 0;
12 }
+0
-10
test/LLVMC/C/include.c less more
None /*
1 * Check that the 'include' options work.
2 * RUN: echo "int x;\n" > %t1.inc
3 * RUN: llvmc -include %t1.inc -fsyntax-only %s
4 * XFAIL: vg_leak
5 */
6
7 int f0(void) {
8 return x;
9 }
+0
-13
test/LLVMC/C/opt-test.c less more
None /*
1 * Check that the -opt switch works.
2 * RUN: llvmc %s -opt -o %t
3 * RUN: %abs_tmp | grep hello
4 * XFAIL: vg_leak
5 */
6
7 #include
8
9 int main() {
10 printf("hello\n");
11 return 0;
12 }
+0
-13
test/LLVMC/C/sink.c less more
None /*
1 * Check that the 'sink' options work.
2 * RUN: llvmc -v -Wall %s -o %t |& grep "Wall"
3 * RUN: %abs_tmp | grep hello
4 * XFAIL: vg_leak
5 */
6
7 #include
8
9 int main() {
10 printf("hello\n");
11 return 0;
12 }
+0
-13
test/LLVMC/C/wall.c less more
None /*
1 * Check that -Wall works as intended
2 * RUN: llvmc -Wall %s -o %t
3 * RUN: %abs_tmp | grep hello
4 * XFAIL: vg_leak
5 */
6
7 #include
8
9 int main() {
10 printf("hello\n");
11 return 0;
12 }
+0
-10
test/LLVMC/C++/dash-x.cpp less more
None // Test that we can compile .c files as C++ and vice versa
1 // RUN: llvmc %s -x c++ %p/../test_data/false.c -x c %p/../test_data/false.cpp -x lisp -x whatnot -x none %p/../test_data/false2.cpp -o %t
2 // RUN: %abs_tmp | grep hello
3 // XFAIL: vg
4
5 extern int test_main();
6
7 int main() {
8 test_main();
9 }
+0
-5
test/LLVMC/C++/dg.exp less more
None load_lib llvm.exp
1
2 if [ llvm_gcc_supports c++ ] then {
3 RunLLVMTests [lsort [glob -nocomplain $srcdir/$subdir/*.{unk,ll,c,cpp}]]
4 }
+0
-3
test/LLVMC/C++/filelist.cpp less more
None // Test that the -filelist option works correctly with -linker=c++.
1 // RUN: llvmc --dry-run -filelist DUMMY -linker c++ |& grep llvm-g++
2 // XFAIL: vg
+0
-9
test/LLVMC/C++/hello.cpp less more
None // Test that we can compile C++ code.
1 // RUN: llvmc %s -o %t
2 // RUN: %abs_tmp | grep hello
3 // XFAIL: vg
4 #include
5
6 int main() {
7 std::cout << "hello" << '\n';
8 }
+0
-10
test/LLVMC/C++/just-compile.cpp less more
None // Test that the -c flag works.
1 // RUN: llvmc -c %s -o %t.o
2 // RUN: llvmc --linker=c++ %t.o -o %t
3 // RUN: %abs_tmp | grep hello
4 // XFAIL: vg
5 #include
6
7 int main() {
8 std::cout << "hello" << '\n';
9 }
+0
-10
test/LLVMC/C++/together.cpp less more
None // Check that we can compile files of different types together.
1 // RUN: llvmc %s %p/../test_data/together.c -o %t
2 // RUN: %abs_tmp | grep hello
3 // XFAIL: vg
4
5 extern "C" void test();
6
7 int main() {
8 test();
9 }
+0
-9
test/LLVMC/C++/unknown_suffix.unk less more
None // Test that the -x option works for files with unknown suffixes.
1 // RUN: llvmc -x c++ %s -o %t
2 // RUN: %abs_tmp | grep hello
3 // XFAIL: vg
4 #include
5
6 int main() {
7 std::cout << "hello" << '\n';
8 }
+0
-8
test/LLVMC/EmptyCompilationGraph.td less more
None // Check that the compilation graph can be empty.
1 // RUN: tblgen -I %p/../../include --gen-llvmc %s -o %t
2 // RUN: %compile_cxx %t
3 // XFAIL: vg_leak
4
5 include "llvm/CompilerDriver/Common.td"
6
7 def Graph : CompilationGraph<[]>;
+0
-18
test/LLVMC/EnvParentheses.td less more
None // Check the fix for PR4157.
1 // http://llvm.org/bugs/show_bug.cgi?id=4157
2 // RUN: tblgen -I %p/../../include --gen-llvmc %s -o %t
3 // RUN: not grep {FOO")));} %t
4 // RUN: %compile_cxx %t
5 // XFAIL: vg_leak
6
7 include "llvm/CompilerDriver/Common.td"
8
9 def dummy_tool : Tool<[
10 (command "gcc $ENV(FOO)/bar"),
11 (in_language "dummy"),
12 (out_language "dummy")
13 ]>;
14
15 def DummyGraph : CompilationGraph<[(edge "root", "dummy_tool")]>;
16
17 def Graph : CompilationGraph<[]>;
+0
-21
test/LLVMC/ForwardAs.td less more
None // Check the fix for PR4159.
1 // http://llvm.org/bugs/show_bug.cgi?id=4159
2 // RUN: tblgen -I %p/../../include --gen-llvmc %s -o %t
3 // RUN: FileCheck -input-file %t %s
4 // RUN: %compile_cxx %t
5 // XFAIL: vg_leak
6
7 include "llvm/CompilerDriver/Common.td"
8
9 def OptList : OptionList<[(parameter_option "dummy", (help "dummmy"))]>;
10
11 def dummy_tool : Tool<[
12 (command "dummy_cmd"),
13 (in_language "dummy"),
14 (out_language "dummy"),
15 (actions (case
16 // CHECK: "unique_name"));
17 (not_empty "dummy"), (forward_as "dummy", "unique_name")))
18 ]>;
19
20 def DummyGraph : CompilationGraph<[(edge "root", "dummy_tool")]>;
+0
-27
test/LLVMC/ForwardTransformedValue.td less more
None // Check that forward_transformed_value works.
1 // The dummy tool and graph are required to silence warnings.
2 // RUN: tblgen -I %p/../../include --gen-llvmc %s -o %t
3 // RUN: FileCheck -input-file %t %s
4 // RUN: %compile_cxx %t
5 // XFAIL: vg_leak
6
7 include "llvm/CompilerDriver/Common.td"
8
9 def OptList : OptionList<[(parameter_option "a", (help "dummy")),
10 (prefix_list_option "b", (help "dummy"))]>;
11
12 // CHECK: std::string HookA
13 // CHECK: std::string HookB
14
15 def dummy_tool : Tool<[
16 (command "dummy_cmd"),
17 (in_language "dummy"),
18 (out_language "dummy"),
19 (actions (case
20 // CHECK: HookA(autogenerated::Parameter_a
21 (not_empty "a"), (forward_transformed_value "a", "HookA"),
22 // CHECK: HookB(autogenerated::List_b
23 (not_empty "b"), (forward_transformed_value "b", "HookB")))
24 ]>;
25
26 def DummyGraph : CompilationGraph<[(edge "root", "dummy_tool")]>;
+0
-24
test/LLVMC/ForwardValue.td less more
None // Check that forward_value works.
1 // The dummy tool and graph are required to silence warnings.
2 // RUN: tblgen -I %p/../../include --gen-llvmc %s -o %t
3 // RUN: FileCheck -input-file %t %s
4 // RUN: %compile_cxx %t
5 // XFAIL: vg_leak
6
7 include "llvm/CompilerDriver/Common.td"
8
9 def OptList : OptionList<[(parameter_option "a", (help "dummy")),
10 (prefix_list_option "b", (help "dummy"))]>;
11
12 def dummy_tool : Tool<[
13 (command "dummy_cmd"),
14 (in_language "dummy"),
15 (out_language "dummy"),
16 (actions (case
17 // CHECK: , autogenerated::Parameter_a));
18 (not_empty "a"), (forward_value "a"),
19 // CHECK: B = autogenerated::List_b.begin()
20 (not_empty "b"), (forward_value "b")))
21 ]>;
22
23 def DummyGraph : CompilationGraph<[(edge "root", "dummy_tool")]>;
+0
-20
test/LLVMC/HookWithArguments.td less more
None // Check that hooks with arguments work.
1 // RUN: tblgen -I %p/../../include --gen-llvmc %s -o %t
2 // RUN: FileCheck -input-file %t %s
3 // RUN: %compile_cxx %t
4 // XFAIL: vg_leak
5
6 include "llvm/CompilerDriver/Common.td"
7
8 // CHECK: Hook(const char* Arg0, const char* Arg1, const char* Arg2);
9 // CHECK: "/path"
10 // CHECK: std::getenv("VARIABLE")
11 // CHECK: "/2path"
12
13 def dummy_tool : Tool<[
14 (command "$CALL(Hook, 'Arg1', 'Arg2', 'Arg3 Arg3Cont')/path arg1 $ENV(VARIABLE)/2path arg2"),
15 (in_language "dummy"),
16 (out_language "dummy")
17 ]>;
18
19 def DummyGraph : CompilationGraph<[(edge "root", "dummy_tool")]>;
+0
-16
test/LLVMC/HookWithInFile.td less more
None // Check that a hook can be given $INFILE as an argument.
1 // RUN: tblgen -I %p/../../include --gen-llvmc %s -o %t
2 // RUN: FileCheck -input-file %t %s
3 // RUN: %compile_cxx %t
4 // XFAIL: vg_leak
5
6 include "llvm/CompilerDriver/Common.td"
7
8 def dummy_tool : Tool<[
9 // CHECK: Hook(inFile.c_str())
10 (command "$CALL(Hook, '$INFILE')/path"),
11 (in_language "dummy"),
12 (out_language "dummy")
13 ]>;
14
15 def DummyGraph : CompilationGraph<[(edge "root", "dummy_tool")]>;
+0
-25
test/LLVMC/Init.td less more
None // Check that (init true/false) and (init "str") work.
1 // RUN: tblgen -I %p/../../include --gen-llvmc %s -o %t
2 // RUN: FileCheck -input-file %t %s
3 // RUN: %compile_cxx %t
4 // XFAIL: vg_leak
5
6 include "llvm/CompilerDriver/Common.td"
7
8 def OptList : OptionList<[
9 // CHECK: cl::init(true)
10 (switch_option "dummy1", (help "none"), (init true)),
11 // CHECK: cl::init("some-string")
12 (parameter_option "dummy2", (help "none"), (init "some-string"))
13 ]>;
14
15 def dummy_tool : Tool<[
16 (command "dummy_cmd"),
17 (in_language "dummy_lang"),
18 (out_language "dummy_lang"),
19 (actions (case
20 (switch_on "dummy1"), (forward "dummy1"),
21 (not_empty "dummy2"), (forward "dummy2")))
22 ]>;
23
24 def DummyGraph : CompilationGraph<[(edge "root", "dummy_tool")]>;
+0
-29
test/LLVMC/LanguageMap.td less more
None // Check that LanguageMap is processed properly.
1 // RUN: tblgen -I %p/../../include --gen-llvmc %s -o %t
2 // RUN: FileCheck -input-file %t %s
3 // RUN: %compile_cxx %t
4 // XFAIL: vg_leak
5
6 include "llvm/CompilerDriver/Common.td"
7
8 def OptList : OptionList<[
9 (switch_option "dummy1", (help "none"))
10 ]>;
11
12 def dummy_tool : Tool<[
13 (command "dummy_cmd"),
14 (in_language "dummy_lang"),
15 (out_language "dummy_lang"),
16 (actions (case
17 (switch_on "dummy1"), (forward "dummy1")))
18 ]>;
19
20 def lang_map : LanguageMap<[
21 // CHECK: langMap["dummy"] = "dummy_lang"
22 // CHECK: langMap["DUM"] = "dummy_lang"
23 (lang_to_suffixes "dummy_lang", ["dummy", "DUM"]),
24 // CHECK: langMap["DUM2"] = "dummy_lang_2"
25 (lang_to_suffixes "dummy_lang_2", "DUM2")
26 ]>;
27
28 def DummyGraph : CompilationGraph<[(edge "root", "dummy_tool")]>;
+0
-24
test/LLVMC/MultiValuedOption.td less more
None // Check that multivalued options work.
1 // The dummy tool and graph are required to silence warnings.
2 // RUN: tblgen -I %p/../../include --gen-llvmc %s -o %t
3 // RUN: FileCheck -input-file %t %s
4 // RUN: %compile_cxx %t
5 // XFAIL: vg_leak
6
7 include "llvm/CompilerDriver/Common.td"
8
9 def OptList : OptionList<[
10 // CHECK: cl::multi_val(2)
11 (prefix_list_option "foo", (multi_val 2)),
12 (parameter_list_option "baz", (multi_val 2))]>;
13
14 def dummy_tool : Tool<[
15 (command "dummy_cmd"),
16 (in_language "dummy"),
17 (out_language "dummy"),
18 (actions (case
19 (not_empty "foo"), (forward_as "foo", "bar"),
20 (not_empty "baz"), (forward "baz")))
21 ]>;
22
23 def DummyGraph : CompilationGraph<[(edge "root", "dummy_tool")]>;
+0
-10
test/LLVMC/MultipleCompilationGraphs.td less more
None // Check that multiple compilation graphs are allowed.
1 // RUN: tblgen -I %p/../../include --gen-llvmc %s -o %t
2 // RUN: %compile_cxx %t
3 // XFAIL: vg_leak
4
5 include "llvm/CompilerDriver/Common.td"
6
7 def Graph1 : CompilationGraph<[]>;
8 def Graph2 : CompilationGraph<[]>;
9 def Graph3 : CompilationGraph<[]>;
+0
-27
test/LLVMC/MultipleOutputLanguages.td less more
None // Check that multiple output languages work.
1 // RUN: tblgen -I %p/../../include --gen-llvmc %s -o %t
2 // RUN: FileCheck -input-file %t %s
3 // RUN: %compile_cxx %t
4 // XFAIL: vg_leak
5
6 include "llvm/CompilerDriver/Common.td"
7
8 def dummy_tool : Tool<[
9 (command "dummy_cmd"),
10 (in_language "dummy_lang"),
11 (out_language "another_dummy_lang", "yet_another_dummy_lang")
12 ]>;
13
14 def another_dummy_tool : Tool<[
15 (command "another_dummy_cmd"),
16 (in_language "another_dummy_lang", "some_other_dummy_lang"),
17 (out_language "executable"),
18 (join)
19 ]>;
20
21 // CHECK: new SimpleEdge("dummy_tool")
22 // CHECK: new SimpleEdge("another_dummy_tool")
23 def DummyGraph : CompilationGraph<[
24 (edge "root", "dummy_tool"),
25 (edge "dummy_tool", "another_dummy_tool")
26 ]>;
+0
-16
test/LLVMC/NoActions.td less more
None // Check that tools without associated actions are accepted.
1 // RUN: tblgen -I %p/../../include --gen-llvmc %s -o %t
2 // RUN: FileCheck -input-file %t %s
3 // RUN: %compile_cxx %t
4 // XFAIL: vg_leak
5
6 include "llvm/CompilerDriver/Common.td"
7
8 // CHECK: class dummy_tool : public Tool {
9 def dummy_tool : Tool<[
10 (command "dummy_cmd"),
11 (in_language "dummy"),
12 (out_language "dummy")
13 ]>;
14
15 def DummyGraph : CompilationGraph<[(edge "root", "dummy_tool")]>;
+0
-6
test/LLVMC/NoCompilationGraph.td less more
None // Check that the compilation graph is not required.
1 // RUN: tblgen -I %p/../../include --gen-llvmc %s -o %t
2 // RUN: %compile_cxx %t
3 // XFAIL: vg_leak
4
5 include "llvm/CompilerDriver/Common.td"
+0
-5
test/LLVMC/ObjC/dg.exp less more
None load_lib llvm.exp
1
2 if [ llvm_gcc_supports objc ] then {
3 RunLLVMTests [lsort [glob -nocomplain $srcdir/$subdir/*.{m}]]
4 }
+0
-12
test/LLVMC/ObjC/hello.m less more
None /*
1 * Check that we can compile helloworld
2 * RUN: llvmc %s -o %t
3 * RUN: %abs_tmp | grep hello
4 */
5
6 #include
7
8 int main() {
9 printf("hello\n");
10 return 0;
11 }
+0
-5
test/LLVMC/ObjC++/dg.exp less more
None load_lib llvm.exp
1
2 if [ llvm_gcc_supports obj-c++ ] then {
3 RunLLVMTests [lsort [glob -nocomplain $srcdir/$subdir/*.{mm}]]
4 }
+0
-8
test/LLVMC/ObjC++/hello.mm less more
None // Test that we can compile Objective-C++ code.
1 // RUN: llvmc %s -o %t
2 // RUN: %abs_tmp | grep hello
3 #include
4
5 int main() {
6 std::cout << "hello" << '\n';
7 }
+0
-25
test/LLVMC/OneOrMore.td less more
None // Check that (one_or_more) and (zero_or_one) properties work.
1 // The dummy tool and graph are required to silence warnings.
2 // RUN: tblgen -I %p/../../include --gen-llvmc %s -o %t
3 // RUN: FileCheck -input-file %t %s
4 // RUN: %compile_cxx %t
5 // XFAIL: vg_leak
6
7 include "llvm/CompilerDriver/Common.td"
8
9 def OptList : OptionList<[
10 // CHECK: cl::OneOrMore
11 (prefix_list_option "foo", (one_or_more)),
12 // CHECK: cl::Optional
13 (parameter_list_option "baz", (optional))]>;
14
15 def dummy_tool : Tool<[
16 (command "dummy_cmd"),
17 (in_language "dummy"),
18 (out_language "dummy"),
19 (actions (case
20 (not_empty "foo"), (forward_as "foo", "bar"),
21 (not_empty "baz"), (forward "baz")))
22 ]>;
23
24 def DummyGraph : CompilationGraph<[(edge "root", "dummy_tool")]>;
+0
-67
test/LLVMC/OptionPreprocessor.td less more
None // Test for the OptionPreprocessor and related functionality.
1 // RUN: tblgen -I %p/../../include --gen-llvmc %s -o %t
2 // RUN: FileCheck -input-file %t %s
3 // RUN: %compile_cxx %t
4 // XFAIL: vg_leak
5
6 include "llvm/CompilerDriver/Common.td"
7
8 def OptList : OptionList<[
9 (switch_option "foo", (help "dummy")),
10 (switch_option "bar", (help "dummy")),
11 (switch_option "baz", (help "dummy")),
12 (parameter_option "foo_p", (help "dummy")),
13 (parameter_option "bar_p", (help "dummy")),
14 (parameter_option "baz_p", (help "dummy")),
15 (parameter_list_option "foo_l", (help "dummy"))
16 ]>;
17
18 def Preprocess : OptionPreprocessor<
19 (case
20 // CHECK: W1
21 // CHECK: foo = false;
22 // CHECK: foo_p = "";
23 // CHECK: foo_l.clear();
24 (and (switch_on "foo"), (any_switch_on "bar", "baz")),
25 [(warning "W1"), (unset_option "foo"),
26 (unset_option "foo_p"), (unset_option "foo_l")],
27 // CHECK: W2
28 // CHECK: foo = true;
29 // CHECK: bar = true;
30 // CHECK: baz = false;
31 // CHECK: foo_p = "asdf";
32 // CHECK: foo_l.clear();
33 // CHECK: foo_l.push_back("qwert");
34 // CHECK: foo_l.push_back("yuiop");
35 // CHECK: foo_l.push_back("asdf");
36 (and (switch_on "foo", "bar"), (any_empty "foo_p", "bar_p")),
37 [(warning "W2"), (set_option "foo"),
38 (set_option "bar", true),
39 (set_option "baz", false),
40 (set_option "foo_p", "asdf"),
41 (set_option "foo_l", ["qwert", "yuiop", "asdf"])],
42 // CHECK: W3
43 // CHECK: foo = true;
44 // CHECK: bar = true;
45 // CHECK: baz = true;
46 (and (empty "foo_p", "bar_p"), (any_not_empty "baz_p")),
47 [(warning "W3"), (set_option "foo", "bar", "baz")])
48 >;
49
50 // Shut up warnings...
51 def dummy : Tool<
52 [(in_language "dummy"),
53 (out_language "dummy"),
54 (output_suffix "d"),
55 (command "dummy"),
56 (actions (case (switch_on "foo"), (error),
57 (switch_on "bar"), (error),
58 (switch_on "baz"), (error),
59 (not_empty "foo_p"), (error),
60 (not_empty "bar_p"), (error),
61 (not_empty "baz_p"), (error),
62 (not_empty "foo_l"), (error)))
63 ]>;
64
65 def Graph : CompilationGraph<[(edge "root", "dummy")]>;
66
+0
-24
test/LLVMC/OutputSuffixHook.td less more
None // Check that hooks can be invoked from 'output_suffix'.
1 // RUN: tblgen -I %p/../../include --gen-llvmc %s -o %t
2 // RUN: FileCheck -input-file %t %s
3 // RUN: %compile_cxx %t
4 // XFAIL: vg_leak
5
6 include "llvm/CompilerDriver/Common.td"
7
8 // CHECK: std::string MyHook()
9
10 def OptList : OptionList<[
11 (switch_option "dummy1", (help "none"))
12 ]>;
13
14 def dummy_tool : Tool<[
15 (command "dummy_cmd"),
16 (in_language "dummy_lang"),
17 (out_language "dummy_lang"),
18 (actions (case
19 // CHECK: hooks::MyHook()
20 (switch_on "dummy1"), (output_suffix "$CALL(MyHook)")))
21 ]>;
22
23 def DummyGraph : CompilationGraph<[(edge "root", "dummy_tool")]>;
+0
-8
test/LLVMC/TestWarnings.td less more
None // Check that warnings about unused options are really emitted.
1 // This should fail because the output is printed on stderr.
2 // RUN: tblgen -I %p/../../include --gen-llvmc %s |& grep "option '-Wall' has no effect!"
3 // XFAIL: vg_leak
4
5 include "llvm/CompilerDriver/Common.td"
6
7 def OptList : OptionList<[(switch_option "Wall", (help "dummy"))]>;
+0
-3
test/LLVMC/dg.exp less more
None load_lib llvm.exp
1
2 RunLLVMTests [lsort [glob -nocomplain $srcdir/$subdir/*.{td}]]
+0
-10
test/LLVMC/test_data/false.c less more
None #include
1
2 extern "C" void test();
3 extern std::string test2();
4
5 int test_main() {
6 std::cout << "h";
7 test();
8 std::cout << test2() << '\n';
9 }
+0
-16
test/LLVMC/test_data/false.cpp less more
None #include
1
2 /* Make this invalid C++ */
3 typedef struct {
4 int i;
5 char c;
6 } a;
7
8 static a b = { .i = 65, .c = 'r'};
9
10 void test() {
11 b.i = 9;
12 fflush(stdout);
13 printf("el");
14 }
15
+0
-5
test/LLVMC/test_data/false2.cpp less more
None #include
1
2 std::string test2() {
3 return "lo";
4 }
+0
-5
test/LLVMC/test_data/together.c less more
None #include
1
2 void test() {
3 printf("hello\n");
4 }
2424 llvm-ld llvm-prof llvm-link \
2525 lli llvm-extract llvm-mc \
2626 bugpoint llvm-bcanalyzer llvm-stub \
27 llvmc llvm-diff macho-dump llvm-objdump \
27 llvm-diff macho-dump llvm-objdump \
2828 llvm-rtdyld llvm-dwarfdump
2929
3030 # Let users override the set of tools to build from the command line.
+0
-8
tools/llvmc/CMakeLists.txt less more
None add_subdirectory(src)
1
2 # TODO: support plugins and user-configured builds.
3 # See ./doc/LLVMC-Reference.rst "Customizing LLVMC: the compilation graph"
4
5 if( LLVM_INCLUDE_EXAMPLES )
6 add_subdirectory(examples)
7 endif()
+0
-18
tools/llvmc/Makefile less more
None ##===- tools/llvmc/Makefile --------------------------------*- Makefile -*-===##
1 #
2 # The LLVM Compiler Infrastructure
3 #
4 # This file is distributed under the University of Illinois Open
5 # Source License. See LICENSE.TXT for details.
6 #
7 ##===----------------------------------------------------------------------===##
8
9 LEVEL = ../..
10
11 DIRS = src
12
13 ifeq ($(BUILD_EXAMPLES),1)
14 OPTIONAL_DIRS += examples
15 endif
16
17 include $(LEVEL)/Makefile.common
+0
-747
tools/llvmc/doc/LLVMC-Reference.rst less more
None ===================================
1 Customizing LLVMC: Reference Manual
2 ===================================
3 ..
4 This file was automatically generated by rst2html.
5 Please do not edit directly!
6 The ReST source lives in the directory 'tools/llvmc/doc'.
7
8 .. contents::
9
10 .. raw:: html
11
12
13

Written by Mikhail Glushenkov

14
15
16 Introduction
17 ============
18
19 LLVMC is a generic compiler driver, designed to be customizable and
20 extensible. It plays the same role for LLVM as the ``gcc`` program does for
21 GCC - LLVMC's job is essentially to transform a set of input files into a set of
22 targets depending on configuration rules and user options. What makes LLVMC
23 different is that these transformation rules are completely customizable - in
24 fact, LLVMC knows nothing about the specifics of transformation (even the
25 command-line options are mostly not hard-coded) and regards the transformation
26 structure as an abstract graph. The structure of this graph is described in
27 high-level TableGen code, from which an efficient C++ representation is
28 automatically derived. This makes it possible to adapt LLVMC for other
29 purposes - for example, as a build tool for game resources.
30
31 Because LLVMC employs TableGen_ as its configuration language, you
32 need to be familiar with it to customize LLVMC.
33
34 .. _TableGen: http://llvm.org/docs/TableGenFundamentals.html
35
36
37 Compiling with ``llvmc``
38 ========================
39
40 LLVMC tries hard to be as compatible with ``gcc`` as possible,
41 although there are some small differences. Most of the time, however,
42 you shouldn't be able to notice them::
43
44 $ # This works as expected:
45 $ llvmc -O3 -Wall hello.cpp
46 $ ./a.out
47 hello
48
49 One nice feature of LLVMC is that one doesn't have to distinguish between
50 different compilers for different languages (think ``g++`` vs. ``gcc``) - the
51 right toolchain is chosen automatically based on input language names (which
52 are, in turn, determined from file extensions). If you want to force files
53 ending with ".c" to compile as C++, use the ``-x`` option, just like you would
54 do it with ``gcc``::
55
56 $ # hello.c is really a C++ file
57 $ llvmc -x c++ hello.c
58 $ ./a.out
59 hello
60
61 On the other hand, when using LLVMC as a linker to combine several C++
62 object files you should provide the ``--linker`` option since it's
63 impossible for LLVMC to choose the right linker in that case::
64
65 $ llvmc -c hello.cpp
66 $ llvmc hello.o
67 [A lot of link-time errors skipped]
68 $ llvmc --linker=c++ hello.o
69 $ ./a.out
70 hello
71
72 By default, LLVMC uses ``llvm-gcc`` to compile the source code. It is also
73 possible to choose the ``clang`` compiler with the ``-clang`` option.
74
75
76 Predefined options
77 ==================
78
79 LLVMC has some built-in options that can't be overridden in the TableGen code:
80
81 * ``-o FILE`` - Output file name.
82
83 * ``-x LANGUAGE`` - Specify the language of the following input files
84 until the next -x option.
85
86 * ``-v`` - Enable verbose mode, i.e. print out all executed commands.
87
88 * ``--save-temps`` - Write temporary files to the current directory and do not
89 delete them on exit. This option can also take an argument: the
90 ``--save-temps=obj`` switch will write files into the directory specified with
91 the ``-o`` option. The ``--save-temps=cwd`` and ``--save-temps`` switches are
92 both synonyms for the default behaviour.
93
94 * ``--temp-dir DIRECTORY`` - Store temporary files in the given directory. This
95 directory is deleted on exit unless ``--save-temps`` is specified. If
96 ``--save-temps=obj`` is also specified, ``--temp-dir`` is given the
97 precedence.
98
99 * ``--check-graph`` - Check the compilation for common errors like mismatched
100 output/input language names, multiple default edges and cycles. Exit with code
101 zero if no errors were found, and return the number of found errors
102 otherwise. Hidden option, useful for debugging.
103
104 * ``--view-graph`` - Show a graphical representation of the compilation graph
105 and exit. Requires that you have ``dot`` and ``gv`` programs installed. Hidden
106 option, useful for debugging.
107
108 * ``--write-graph`` - Write a ``compilation-graph.dot`` file in the current
109 directory with the compilation graph description in Graphviz format (identical
110 to the file used by the ``--view-graph`` option). The ``-o`` option can be
111 used to set the output file name. Hidden option, useful for debugging.
112
113 * ``--help``, ``--help-hidden``, ``--version`` - These options have
114 their standard meaning.
115
116 Compiling LLVMC-based drivers
117 =============================
118
119 It's easiest to start working on your own LLVMC driver by copying the skeleton
120 project which lives under ``$LLVMC_DIR/examples/Skeleton``::
121
122 $ cd $LLVMC_DIR/examples
123 $ cp -r Skeleton MyDriver
124 $ cd MyDriver
125 $ ls
126 AutoGenerated.td Hooks.cpp Main.cpp Makefile
127
128 As you can see, our basic driver consists of only three files (not counting the
129 build script). ``AutoGenerated.td`` contains TableGen description of the
130 compilation graph; its format is documented in the following
131 sections. ``Hooks.cpp`` is an empty file that should be used for hook
132 definitions (see `below`__). ``Main.cpp`` is just a helper used to compile the
133 auto-generated C++ code produced from TableGen source.
134
135 __ hooks_
136
137 The first thing that you should do is to change the ``LLVMC_BASED_DRIVER``
138 variable in the ``Makefile``::
139
140 LLVMC_BASED_DRIVER=MyDriver
141
142 It can also be a good idea to put your TableGen code into a file with a less
143 generic name::
144
145 $ touch MyDriver.td
146 $ vim AutoGenerated.td
147 [...]
148 include "MyDriver.td"
149
150 If you have more than one TableGen source file, they all should be included from
151 ``AutoGenerated.td``, since this file is used by the build system to generate
152 C++ code.
153
154 To build your driver, just ``cd`` to its source directory and run ``make``. The
155 resulting executable will be put into ``$LLVM_OBJ_DIR/$(BuildMode)/bin``.
156
157 If you're compiling LLVM with different source and object directories, then you
158 must perform the following additional steps before running ``make``::
159
160 # LLVMC_SRC_DIR = $LLVM_SRC_DIR/tools/llvmc/
161 # LLVMC_OBJ_DIR = $LLVM_OBJ_DIR/tools/llvmc/
162 $ mkdir $LLVMC_OBJ_DIR/examples/MyDriver/
163 $ cp $LLVMC_SRC_DIR/examples/MyDriver/Makefile \
164 $LLVMC_OBJ_DIR/examples/MyDriver/
165 $ cd $LLVMC_OBJ_DIR/examples/MyDriver
166 $ make
167
168
169 Customizing LLVMC: the compilation graph
170 ========================================
171
172 Each TableGen configuration file should include the common definitions::
173
174 include "llvm/CompilerDriver/Common.td"
175
176 Internally, LLVMC stores information about possible source transformations in
177 form of a graph. Nodes in this graph represent tools, and edges between two
178 nodes represent a transformation path. A special "root" node is used to mark
179 entry points for the transformations. LLVMC also assigns a weight to each edge
180 (more on this later) to choose between several alternative edges.
181
182 The definition of the compilation graph (see file ``llvmc/src/Base.td`` for an
183 example) is just a list of edges::
184
185 def CompilationGraph : CompilationGraph<[
186 Edge<"root", "llvm_gcc_c">,
187 Edge<"root", "llvm_gcc_assembler">,
188 ...
189
190 Edge<"llvm_gcc_c", "llc">,
191 Edge<"llvm_gcc_cpp", "llc">,
192 ...
193
194 OptionalEdge<"llvm_gcc_c", "opt", (case (switch_on "opt"),
195 (inc_weight))>,
196 OptionalEdge<"llvm_gcc_cpp", "opt", (case (switch_on "opt"),
197 (inc_weight))>,
198 ...
199
200 OptionalEdge<"llvm_gcc_assembler", "llvm_gcc_cpp_linker",
201 (case (input_languages_contain "c++"), (inc_weight),
202 (or (parameter_equals "linker", "g++"),
203 (parameter_equals "linker", "c++")), (inc_weight))>,
204 ...
205
206 ]>;
207
208 As you can see, the edges can be either default or optional, where optional
209 edges are differentiated by an additional ``case`` expression used to calculate
210 the weight of this edge. Notice also that we refer to tools via their names (as
211 strings). This makes it possible to add edges to an existing compilation graph
212 without having to know about all tool definitions used in the graph.
213
214 The default edges are assigned a weight of 1, and optional edges get a weight of
215 0 + 2*N where N is the number of tests that evaluated to true in the ``case``
216 expression. It is also possible to provide an integer parameter to
217 ``inc_weight`` and ``dec_weight`` - in this case, the weight is increased (or
218 decreased) by the provided value instead of the default 2. Default weight of an
219 optional edge can be changed by using the ``default`` clause of the ``case``
220 construct.
221
222 When passing an input file through the graph, LLVMC picks the edge with the
223 maximum weight. To avoid ambiguity, there should be only one default edge
224 between two nodes (with the exception of the root node, which gets a special
225 treatment - there you are allowed to specify one default edge *per language*).
226
227 When multiple compilation graphs are defined, they are merged together. Multiple
228 edges with the same end nodes are not allowed (i.e. the graph is not a
229 multigraph), and will lead to a compile-time error.
230
231 To get a visual representation of the compilation graph (useful for debugging),
232 run ``llvmc --view-graph``. You will need ``dot`` and ``gsview`` installed for
233 this to work properly.
234
235 Describing options
236 ==================
237
238 Command-line options supported by the driver are defined by using an
239 ``OptionList``::
240
241 def Options : OptionList<[
242 (switch_option "E", (help "Help string")),
243 (alias_option "quiet", "q")
244 ...
245 ]>;
246
247 As you can see, the option list is just a list of DAGs, where each DAG is an
248 option description consisting of the option name and some properties. More than
249 one option list can be defined (they are all merged together in the end), which
250 can be handy if one wants to separate option groups syntactically.
251
252 * Possible option types:
253
254 - ``switch_option`` - a simple boolean switch without arguments, for example
255 ``-O2`` or ``-time``. At most one occurrence is allowed by default.
256
257 - ``parameter_option`` - option that takes one argument, for example
258 ``-std=c99``. It is also allowed to use spaces instead of the equality
259 sign: ``-std c99``. At most one occurrence is allowed.
260
261 - ``parameter_list_option`` - same as the above, but more than one option
262 occurrence is allowed.
263
264 - ``prefix_option`` - same as the parameter_option, but the option name and
265 argument do not have to be separated. Example: ``-ofile``. This can be also
266 specified as ``-o file``; however, ``-o=file`` will be parsed incorrectly
267 (``=file`` will be interpreted as option value). At most one occurrence is
268 allowed.
269
270 - ``prefix_list_option`` - same as the above, but more than one occurrence of
271 the option is allowed; example: ``-lm -lpthread``.
272
273 - ``alias_option`` - a special option type for creating aliases. Unlike other
274 option types, aliases are not allowed to have any properties besides the
275 aliased option name.
276 Usage example: ``(alias_option "preprocess", "E")``
277
278 - ``switch_list_option`` - like ``switch_option`` with the ``zero_or_more``
279 property, but remembers how many times the switch was turned on. Useful
280 mostly for forwarding. Example: when ``-foo`` is a switch option (with the
281 ``zero_or_more`` property), the command ``driver -foo -foo`` is forwarded
282 as ``some-tool -foo``, but when ``-foo`` is a switch list, the same command
283 is forwarded as ``some-tool -foo -foo``.
284
285
286 * Possible option properties:
287
288 - ``help`` - help string associated with this option. Used for ``--help``
289 output.
290
291 - ``required`` - this option must be specified exactly once (or, in case of
292 the list options without the ``multi_val`` property, at least
293 once). Incompatible with ``optional`` and ``one_or_more``.
294
295 - ``optional`` - the option can be specified either zero times or exactly
296 once. The default for switch options. Useful only for list options in
297 conjunction with ``multi_val``. Incompatible with ``required``,
298 ``zero_or_more`` and ``one_or_more``.
299
300 - ``one_or_more`` - the option must be specified at least once. Can be useful
301 to allow switch options be both obligatory and be specified multiple
302 times. For list options is useful only in conjunction with ``multi_val``;
303 for ordinary it is synonymous with ``required``. Incompatible with
304 ``required``, ``optional`` and ``zero_or_more``.
305
306 - ``zero_or_more`` - the option can be specified zero or more times. Useful
307 to allow a single switch option to be specified more than
308 once. Incompatible with ``required``, ``optional`` and ``one_or_more``.
309
310 - ``hidden`` - the description of this option will not appear in
311 the ``--help`` output (but will appear in the ``--help-hidden``
312 output).
313
314 - ``really_hidden`` - the option will not be mentioned in any help
315 output.
316
317 - ``comma_separated`` - Indicates that any commas specified for an option's
318 value should be used to split the value up into multiple values for the
319 option. This property is valid only for list options. In conjunction with
320 ``forward_value`` can be used to implement option forwarding in style of
321 gcc's ``-Wa,``.
322
323 - ``multi_val n`` - this option takes *n* arguments (can be useful in some
324 special cases). Usage example: ``(parameter_list_option "foo", (multi_val
325 3))``; the command-line syntax is '-foo a b c'. Only list options can have
326 this attribute; you can, however, use the ``one_or_more``, ``optional``
327 and ``required`` properties.
328
329 - ``init`` - this option has a default value, either a string (if it is a
330 parameter), or a boolean (if it is a switch; as in C++, boolean constants
331 are called ``true`` and ``false``). List options can't have ``init``
332 attribute.
333 Usage examples: ``(switch_option "foo", (init true))``; ``(prefix_option
334 "bar", (init "baz"))``.
335
336 .. _case:
337
338 Conditional evaluation
339 ======================
340
341 The 'case' construct is the main means by which programmability is achieved in
342 LLVMC. It can be used to calculate edge weights, program actions and modify the
343 shell commands to be executed. The 'case' expression is designed after the
344 similarly-named construct in functional languages and takes the form ``(case
345 (test_1), statement_1, (test_2), statement_2, ... (test_N), statement_N)``. The
346 statements are evaluated only if the corresponding tests evaluate to true.
347
348 Examples::
349
350 // Edge weight calculation
351
352 // Increases edge weight by 5 if "-A" is provided on the
353 // command-line, and by 5 more if "-B" is also provided.
354 (case
355 (switch_on "A"), (inc_weight 5),
356 (switch_on "B"), (inc_weight 5))
357
358
359 // Tool command line specification
360
361 // Evaluates to "cmdline1" if the option "-A" is provided on the
362 // command line; to "cmdline2" if "-B" is provided;
363 // otherwise to "cmdline3".
364
365 (case
366 (switch_on "A"), "cmdline1",
367 (switch_on "B"), "cmdline2",
368 (default), "cmdline3")
369
370 Note the slight difference in 'case' expression handling in contexts of edge
371 weights and command line specification - in the second example the value of the
372 ``"B"`` switch is never checked when switch ``"A"`` is enabled, and the whole
373 expression always evaluates to ``"cmdline1"`` in that case.
374
375 Case expressions can also be nested, i.e. the following is legal::
376
377 (case (switch_on "E"), (case (switch_on "o"), ..., (default), ...)
378 (default), ...)
379
380 You should, however, try to avoid doing that because it hurts readability. It is
381 usually better to split tool descriptions and/or use TableGen inheritance
382 instead.
383
384 * Possible tests are:
385
386 - ``switch_on`` - Returns true if a given command-line switch is provided by
387 the user. Can be given multiple arguments, in that case ``(switch_on "foo",
388 "bar", "baz")`` is equivalent to ``(and (switch_on "foo"), (switch_on
389 "bar"), (switch_on "baz"))``.
390 Example: ``(switch_on "opt")``.
391
392 - ``any_switch_on`` - Given a number of switch options, returns true if any of
393 the switches is turned on.
394 Example: ``(any_switch_on "foo", "bar", "baz")`` is equivalent to ``(or
395 (switch_on "foo"), (switch_on "bar"), (switch_on "baz"))``.
396
397 - ``parameter_equals`` - Returns true if a command-line parameter (first
398 argument) equals a given value (second argument).
399 Example: ``(parameter_equals "W", "all")``.
400
401 - ``element_in_list`` - Returns true if a command-line parameter list (first
402 argument) contains a given value (second argument).
403 Example: ``(element_in_list "l", "pthread")``.
404
405 - ``input_languages_contain`` - Returns true if a given language
406 belongs to the current input language set.
407 Example: ``(input_languages_contain "c++")``.
408
409 - ``in_language`` - Evaluates to true if the input file language is equal to
410 the argument. At the moment works only with ``command`` and ``actions`` (on
411 non-join nodes).
412 Example: ``(in_language "c++")``.
413
414 - ``not_empty`` - Returns true if a given option (which should be either a
415 parameter or a parameter list) is set by the user. Like ``switch_on``, can
416 be also given multiple arguments.
417 Examples: ``(not_empty "o")``, ``(not_empty "o", "l")``.
418
419 - ``any_not_empty`` - Returns true if ``not_empty`` returns true for any of
420 the provided options.
421 Example: ``(any_not_empty "foo", "bar", "baz")`` is equivalent to ``(or
422 (not_empty "foo"), (not_empty "bar"), (not_empty "baz"))``.
423
424 - ``empty`` - The opposite of ``not_empty``. Equivalent to ``(not (not_empty
425 X))``. Can be given multiple arguments.
426
427 - ``any_not_empty`` - Returns true if ``not_empty`` returns true for any of
428 the provided options.
429 Example: ``(any_empty "foo", "bar", "baz")`` is equivalent to ``(or
430 (not_empty "foo"), (not_empty "bar"), (not_empty "baz"))``.
431
432 - ``single_input_file`` - Returns true if there was only one input file
433 provided on the command-line. Used without arguments:
434 ``(single_input_file)``.
435
436 - ``multiple_input_files`` - Equivalent to ``(not (single_input_file))`` (the
437 case of zero input files is considered an error).
438
439 - ``default`` - Always evaluates to true. Should always be the last
440 test in the ``case`` expression.
441
442 - ``and`` - A standard logical combinator that returns true iff all of
443 its arguments return true. Used like this: ``(and (test1), (test2),
444 ... (testN))``. Nesting of ``and`` and ``or`` is allowed, but not
445 encouraged.
446
447 - ``or`` - A logical combinator that returns true iff any of its arguments
448 return true.
449 Example: ``(or (test1), (test2), ... (testN))``.
450
451 - ``not`` - Standard unary logical combinator that negates its
452 argument.
453 Example: ``(not (or (test1), (test2), ... (testN)))``.
454
455
456 Writing a tool description
457 ==========================
458
459 As was said earlier, nodes in the compilation graph represent tools, which are
460 described separately. A tool definition looks like this (taken from the
461 ``llvmc/src/Base.td`` file)::
462
463 def llvm_gcc_cpp : Tool<[
464 (in_language "c++"),
465 (out_language "llvm-assembler"),
466 (output_suffix "bc"),
467 (command "llvm-g++ -c -emit-llvm"),
468 (sink)
469 ]>;
470
471 This defines a new tool called ``llvm_gcc_cpp``, which is an alias for
472 ``llvm-g++``. As you can see, a tool definition is just a list of properties;
473 most of them should be self-explanatory. The ``sink`` property means that this
474 tool should be passed all command-line options that aren't mentioned in the
475 option list.
476
477 The complete list of all currently implemented tool properties follows.
478
479 * Possible tool properties:
480
481 - ``in_language`` - input language name. Can be given multiple arguments, in
482 case the tool supports multiple input languages. Used for typechecking and
483 mapping file extensions to tools.
484
485 - ``out_language`` - output language name. Multiple output languages are
486 allowed. Used for typechecking the compilation graph.
487
488 - ``output_suffix`` - output file suffix. Can also be changed dynamically, see
489 documentation on `actions`__.
490
491 __ actions_
492
493 - ``command`` - the actual command used to run the tool. You can use output
494 redirection with ``>``, hook invocations (``$CALL``), environment variables
495 (via ``$ENV``) and the ``case`` construct.
496
497 - ``join`` - this tool is a "join node" in the graph, i.e. it gets a list of
498 input files and joins them together. Used for linkers.
499
500 - ``sink`` - all command-line options that are not handled by other tools are
501 passed to this tool.
502
503 - ``actions`` - A single big ``case`` expression that specifies how this tool
504 reacts on command-line options (described in more detail `below`__).
505
506 __ actions_
507
508 - ``out_file_option``, ``in_file_option`` - Options appended to the
509 ``command`` string to designate output and input files. Default values are
510 ``"-o"`` and ``""``, respectively.
511
512 .. _actions:
513
514 Actions
515 -------
516
517 A tool often needs to react to command-line options, and this is precisely what
518 the ``actions`` property is for. The next example illustrates this feature::
519
520 def llvm_gcc_linker : Tool<[
521 (in_language "object-code"),
522 (out_language "executable"),
523 (output_suffix "out"),
524 (command "llvm-gcc"),
525 (join),
526 (actions (case (not_empty "L"), (forward "L"),
527 (not_empty "l"), (forward "l"),
528 (not_empty "dummy"),
529 [(append_cmd "-dummy1"), (append_cmd "-dummy2")])
530 ]>;
531
532 The ``actions`` tool property is implemented on top of the omnipresent ``case``
533 expression. It associates one or more different *actions* with given
534 conditions - in the example, the actions are ``forward``, which forwards a given
535 option unchanged, and ``append_cmd``, which appends a given string to the tool
536 execution command. Multiple actions can be associated with a single condition by
537 using a list of actions (used in the example to append some dummy options). The
538 same ``case`` construct can also be used in the ``cmd_line`` property to modify
539 the tool command line.
540
541 The "join" property used in the example means that this tool behaves like a
542 linker.
543
544 The list of all possible actions follows.
545
546 * Possible actions:
547
548 - ``append_cmd`` - Append a string to the tool invocation command.
549 Example: ``(case (switch_on "pthread"), (append_cmd "-lpthread"))``.
550
551 - ``error`` - Exit with error.
552 Example: ``(error "Mixing -c and -S is not allowed!")``.
553
554 - ``warning`` - Print a warning.
555 Example: ``(warning "Specifying both -O1 and -O2 is meaningless!")``.
556
557 - ``forward`` - Forward the option unchanged.
558 Example: ``(forward "Wall")``.
559
560 - ``forward_as`` - Change the option's name, but forward the argument
561 unchanged.
562 Example: ``(forward_as "O0", "--disable-optimization")``.
563
564 - ``forward_value`` - Forward only option's value. Cannot be used with switch
565 options (since they don't have values), but works fine with lists.
566 Example: ``(forward_value "Wa,")``.
567
568 - ``forward_transformed_value`` - As above, but applies a hook to the
569 option's value before forwarding (see `below`__). When
570 ``forward_transformed_value`` is applied to a list
571 option, the hook must have signature
572 ``std::string hooks::HookName (const std::vector&)``.
573 Example: ``(forward_transformed_value "m", "ConvertToMAttr")``.
574
575 __ hooks_
576
577 - ``output_suffix`` - Modify the output suffix of this tool.
578 Example: ``(output_suffix "i")``.
579
580 - ``stop_compilation`` - Stop compilation after this tool processes its
581 input. Used without arguments.
582 Example: ``(stop_compilation)``.
583
584
585 Language map
586 ============
587
588 If you are adding support for a new language to LLVMC, you'll need to modify the
589 language map, which defines mappings from file extensions to language names. It
590 is used to choose the proper toolchain(s) for a given input file set. Language
591 map definition looks like this::
592
593 def LanguageMap : LanguageMap<
594 [LangToSuffixes<"c++", ["cc", "cp", "cxx", "cpp", "CPP", "c++", "C"]>,
595 LangToSuffixes<"c", ["c"]>,
596 ...
597 ]>;
598
599 For example, without those definitions the following command wouldn't work::
600
601 $ llvmc hello.cpp
602 llvmc: Unknown suffix: cpp
603
604 The language map entries are needed only for the tools that are linked from the
605 root node. A tool can have multiple output languages.
606
607 Option preprocessor
608 ===================
609
610 It is sometimes useful to run error-checking code before processing the
611 compilation graph. For example, if optimization options "-O1" and "-O2" are
612 implemented as switches, we might want to output a warning if the user invokes
613 the driver with both of these options enabled.
614
615 The ``OptionPreprocessor`` feature is reserved specially for these
616 occasions. Example (adapted from ``llvm/src/Base.td.in``)::
617
618
619 def Preprocess : OptionPreprocessor<
620 (case (not (any_switch_on "O0", "O1", "O2", "O3")),
621 (set_option "O2"),
622 (and (switch_on "O3"), (any_switch_on "O0", "O1", "O2")),
623 (unset_option "O0", "O1", "O2"),
624 (and (switch_on "O2"), (any_switch_on "O0", "O1")),
625 (unset_option "O0", "O1"),
626 (and (switch_on "O1"), (switch_on "O0")),
627 (unset_option "O0"))
628 >;
629
630 Here, ``OptionPreprocessor`` is used to unset all spurious ``-O`` options so
631 that they are not forwarded to the compiler. If no optimization options are
632 specified, ``-O2`` is enabled.
633
634 ``OptionPreprocessor`` is basically a single big ``case`` expression, which is
635 evaluated only once right after the driver is started. The only allowed actions
636 in ``OptionPreprocessor`` are ``error``, ``warning``, and two special actions:
637 ``unset_option`` and ``set_option``. As their names suggest, they can be used to
638 set or unset a given option. To set an option with ``set_option``, use the
639 two-argument form: ``(set_option "parameter", VALUE)``. Here, ``VALUE`` can be
640 either a string, a string list, or a boolean constant.
641
642 For convenience, ``set_option`` and ``unset_option`` also work with multiple
643 arguments. That is, instead of ``[(unset_option "A"), (unset_option "B")]`` you
644 can use ``(unset_option "A", "B")``. Obviously, ``(set_option "A", "B")`` is
645 only valid if both ``A`` and ``B`` are switches.
646
647
648 More advanced topics
649 ====================
650
651 .. _hooks:
652
653 Hooks and environment variables
654 -------------------------------
655
656 Normally, LLVMC searches for programs in the system ``PATH``. Sometimes, this is
657 not sufficient: for example, we may want to specify tool paths or names in the
658 configuration file. This can be achieved via the hooks mechanism. To write your
659 own hooks, add their definitions to the ``Hooks.cpp`` or drop a ``.cpp`` file
660 into your driver directory. Hooks should live in the ``hooks`` namespace and
661 have the signature ``std::string hooks::MyHookName ([const char* Arg0 [ const
662 char* Arg2 [, ...]]])``. They can be used from the ``command`` tool property::
663
664 (command "$CALL(MyHook)/path/to/file -o $CALL(AnotherHook)")
665
666 To pass arguments to hooks, use the following syntax::
667
668 (command "$CALL(MyHook, 'Arg1', 'Arg2', 'Arg # 3')/path/to/file -o1 -o2")
669
670 It is also possible to use environment variables in the same manner::
671
672 (command "$ENV(VAR1)/path/to/file -o $ENV(VAR2)")
673
674 To change the command line string based on user-provided options use
675 the ``case`` expression (documented `above`__)::
676
677 (command
678 (case
679 (switch_on "E"),
680 "llvm-g++ -E -x c $INFILE -o $OUTFILE",
681 (default),
682 "llvm-g++ -c -x c $INFILE -o $OUTFILE -emit-llvm"))
683
684 __ case_
685
686 Debugging
687 ---------
688
689 When writing LLVMC-based drivers, it can be useful to get a visual view of the
690 resulting compilation graph. This can be achieved via the command line option
691 ``--view-graph`` (which assumes that Graphviz_ and Ghostview_ are
692 installed). There is also a ``--write-graph`` option that creates a Graphviz
693 source file (``compilation-graph.dot``) in the current directory.
694
695 Another useful ``llvmc`` option is ``--check-graph``. It checks the compilation
696 graph for common errors like mismatched output/input language names, multiple
697 default edges and cycles. When invoked with ``--check-graph``, ``llvmc`` doesn't
698 perform any compilation tasks and returns the number of encountered errors as
699 its status code. In the future, these checks will be performed at compile-time
700 and this option will disappear.
701
702 .. _Graphviz: http://www.graphviz.org/
703 .. _Ghostview: http://pages.cs.wisc.edu/~ghost/
704
705 Conditioning on the executable name
706 -----------------------------------
707
708 For now, the executable name (the value passed to the driver in ``argv[0]``) is
709 accessible only in the C++ code (i.e. hooks). Use the following code::
710
711 namespace llvmc {
712 extern const char* ProgramName;
713 }
714
715 namespace hooks {
716
717 std::string MyHook() {
718 //...
719 if (strcmp(ProgramName, "mydriver") == 0) {
720 //...
721
722 }
723
724 } // end namespace hooks
725
726 In general, you're encouraged not to make the behaviour dependent on the
727 executable file name, and use command-line switches instead. See for example how
728 the ``llvmc`` program behaves when it needs to choose the correct linker options
729 (think ``g++`` vs. ``gcc``).
730
731 .. raw:: html
732
733
734
735
736
737 alt="Valid CSS" />
738
739
740 alt="Valid XHTML 1.0 Transitional"/>
741
742 Mikhail Glushenkov
743 LLVM Compiler Infrastructure
744
745 Last modified: $Date: 2008-12-11 11:34:48 -0600 (Thu, 11 Dec 2008) $
746
+0
-127
tools/llvmc/doc/LLVMC-Tutorial.rst less more
None ======================
1 Tutorial - Using LLVMC
2 ======================
3 ..
4 This file was automatically generated by rst2html.
5 Please do not edit directly!
6 The ReST source lives in the directory 'tools/llvmc/doc'.
7
8 .. contents::
9
10 .. raw:: html
11
12
13

Written by Mikhail Glushenkov

14
15
16 Introduction
17 ============
18
19 LLVMC is a generic compiler driver, which plays the same role for LLVM as the
20 ``gcc`` program does for GCC - the difference being that LLVMC is designed to be
21 more adaptable and easier to customize. Most of LLVMC functionality is
22 implemented via high-level TableGen code, from which a corresponding C++ source
23 file is automatically generated. This tutorial describes the basic usage and
24 configuration of LLVMC.
25
26
27 Using the ``llvmc`` program
28 ===========================
29
30 In general, ``llvmc`` tries to be command-line compatible with ``gcc`` as much
31 as possible, so most of the familiar options work::
32
33 $ llvmc -O3 -Wall hello.cpp
34 $ ./a.out
35 hello
36
37 This will invoke ``llvm-g++`` under the hood (you can see which commands are
38 executed by using the ``-v`` option). For further help on command-line LLVMC
39 usage, refer to the ``llvmc --help`` output.
40
41
42 Using LLVMC to generate toolchain drivers
43 =========================================
44
45 LLVMC-based drivers are written mostly using TableGen_, so you need to be
46 familiar with it to get anything done.
47
48 .. _TableGen: http://llvm.org/docs/TableGenFundamentals.html
49
50 Start by compiling ``example/Simple``, which is a primitive wrapper for
51 ``gcc``::
52
53 $ cd $LLVM_OBJ_DIR/tools/examples/Simple
54 $ make
55 $ cat > hello.c
56 #include
57 int main() { printf("Hello\n"); }
58 $ $LLVM_BIN_DIR/Simple -v hello.c
59 gcc hello.c -o hello.out
60 $ ./hello.out
61 Hello
62
63 We have thus produced a simple driver called, appropriately, ``Simple``, from
64 the input TableGen file ``Simple.td``. The ``llvmc`` program itself is generated
65 using a similar process (see ``llvmc/src``). Contents of the file ``Simple.td``
66 look like this::
67
68 // Include common definitions
69 include "llvm/CompilerDriver/Common.td"
70
71 // Tool descriptions
72 def gcc : Tool<
73 [(in_language "c"),
74 (out_language "executable"),
75 (output_suffix "out"),
76 (command "gcc"),
77 (sink),
78
79 // -o is what is used by default, out_file_option here is included for
80 // instructive purposes.
81 (out_file_option "-o")
82 ]>;
83
84 // Language map
85 def LanguageMap : LanguageMap<[(lang_to_suffixes "c", "c")]>;
86
87 // Compilation graph
88 def CompilationGraph : CompilationGraph<[(edge "root", "gcc")]>;
89
90 As you can see, this file consists of three parts: tool descriptions, language
91 map, and the compilation graph definition.
92
93 At the heart of LLVMC is the idea of a compilation graph: vertices in this graph
94 are tools, and edges represent a transformation path between two tools (for
95 example, assembly source produced by the compiler can be transformed into
96 executable code by an assembler). The compilation graph is basically a list of
97 edges; a special node named ``root`` is used to mark graph entry points.
98
99 Tool descriptions are represented as property lists: most properties in the
100 example above should be self-explanatory; the ``sink`` property means that all
101 options lacking an explicit description should be forwarded to this tool.
102
103 The ``LanguageMap`` associates a language name with a list of suffixes and is
104 used for deciding which toolchain corresponds to a given input file.
105
106 To learn more about writing your own drivers with LLVMC, refer to the reference
107 manual and examples in the ``examples`` directory. Of a particular interest is
108 the ``Skeleton`` example, which can serve as a template for your LLVMC-based
109 drivers.
110
111 .. raw:: html
112
113
114
115
116
117 alt="Valid CSS" />
118
119
120 alt="Valid XHTML 1.0 Transitional"/>
121
122 Mikhail Glushenkov
123 LLVM Compiler Infrastructure
124
125 Last modified: $Date: 2008-12-11 11:34:48 -0600 (Thu, 11 Dec 2008) $
126
+0
-33
tools/llvmc/doc/Makefile less more
None ##===- tools/llvmc/doc/Makefile ----------------------------*- Makefile -*-===##
1 #
2 # The LLVM Compiler Infrastructure
3 #
4 # This file is distributed under the University of Illinois Open Source
5 # License. See LICENSE.TXT for details.
6 #
7 ##===----------------------------------------------------------------------===##
8
9 LEVEL=../../..
10
11 ifneq (,$(strip $(wildcard $(LEVEL)/Makefile.config)))
12 include $(LEVEL)/Makefile.config
13 else
14 CP=cp
15 RM=rm
16 endif
17
18 DOC_DIR=../../../docs
19 RST2HTML=rst2html --stylesheet=llvm.css --link-stylesheet
20
21 all : LLVMC-Reference.html LLVMC-Tutorial.html
22 $(CP) LLVMC-Reference.html $(DOC_DIR)/CompilerDriver.html
23 $(CP) LLVMC-Tutorial.html $(DOC_DIR)/CompilerDriverTutorial.html
24
25 LLVMC-Tutorial.html : LLVMC-Tutorial.rst
26 $(RST2HTML) $< $@
27
28 LLVMC-Reference.html : LLVMC-Reference.rst
29 $(RST2HTML) $< $@
30
31 clean :
32 $(RM) LLVMC-Tutorial.html LLVMC-Reference.html
tools/llvmc/doc/img/lines.gif less more
Binary diff not shown
+0
-4
tools/llvmc/examples/CMakeLists.txt less more
None add_subdirectory(Hello)
1 add_subdirectory(Simple)
2 add_subdirectory(mcc16)
3 add_subdirectory(Skeleton)
+0
-4
tools/llvmc/examples/Hello/CMakeLists.txt less more
None set(LLVM_USED_LIBS CompilerDriver)
1 set(LLVM_LINK_COMPONENTS support)
2
3 add_llvm_example(Hello Hello.cpp)
+0
-29
tools/llvmc/examples/Hello/Hello.cpp less more
None //===- Hello.cpp - Example code from "Writing an LLVMC Plugin" ------------===//
1 //
2 // The LLVM Compiler Infrastructure
3 //
4 // This file is distributed under the University of Illinois Open Source
5 // License. See LICENSE.TXT for details.
6 //
7 //===----------------------------------------------------------------------===//
8 //
9 // Shows how to write llvmc-based drivers without using TableGen.
10 //
11 //===----------------------------------------------------------------------===//
12
13 #include "llvm/CompilerDriver/AutoGenerated.h"
14 #include "llvm/CompilerDriver/Main.inc"
15
16 #include "llvm/Support/raw_ostream.h"
17
18 namespace llvmc {
19 namespace autogenerated {
20
21 int PreprocessOptions () { return 0; }
22
23 int PopulateLanguageMap (LanguageMap&) { llvm::outs() << "Hello!\n"; return 0; }
24
25 int PopulateCompilationGraph (CompilationGraph&) { return 0; }
26
27 }
28 }
+0
-14
tools/llvmc/examples/Hello/Makefile less more
None ##===- tools/llvmc/examples/Hello/Makefile -----------------*- Makefile -*-===##
1 #
2 # The LLVM Compiler Infrastructure
3 #
4 # This file is distributed under the University of Illinois Open Source
5 # License. See LICENSE.TXT for details.
6 #
7 ##===----------------------------------------------------------------------===##
8
9 LEVEL = ../../../..
10
11 LLVMC_BASED_DRIVER = Hello
12
13 include $(LEVEL)/Makefile.common
+0
-14
tools/llvmc/examples/Makefile less more
None ##===- tools/llvmc/examples/Makefile -----------------------*- Makefile -*-===##
1 #
2 # The LLVM Compiler Infrastructure
3 #
4 # This file is distributed under the University of Illinois Open Source
5 # License. See LICENSE.TXT for details.
6 #
7 ##===----------------------------------------------------------------------===##
8
9 LEVEL=../../..
10
11 PARALLEL_DIRS := Hello Simple mcc16 Skeleton
12
13 include $(LEVEL)/Makefile.common
+0
-10
tools/llvmc/examples/Simple/CMakeLists.txt less more
None set(LLVM_TARGET_DEFINITIONS Simple.td)
1
2 tablegen(Simple.inc -gen-llvmc)
3
4 set(LLVM_USED_LIBS CompilerDriver)
5 set(LLVM_LINK_COMPONENTS support)
6
7 add_llvm_example(Simple
8 Simple.cpp
9 )
+0
-15
tools/llvmc/examples/Simple/Makefile less more
None ##===- llvmc/examples/Simple/Makefile ----------------------*- Makefile -*-===##
1 #
2 # The LLVM Compiler Infrastructure
3 #
4 # This file is distributed under the University of Illinois Open Source
5 # License. See LICENSE.TXT for details.
6 #
7 ##===----------------------------------------------------------------------===##
8
9 LEVEL = ../../../..
10
11 LLVMC_BASED_DRIVER = Simple
12 BUILT_SOURCES = Simple.inc
13
14 include $(LEVEL)/Makefile.common
+0
-2
tools/llvmc/examples/Simple/Simple.cpp less more
None #include "llvm/CompilerDriver/Main.inc"
1 #include "Simple.inc"
+0
-41
tools/llvmc/examples/Simple/Simple.td less more
None //===- Simple.td - A simple LLVMC-based driver ----------------------------===//
1 //
2 // The LLVM Compiler Infrastructure
3 //
4 // This file is distributed under the University of Illinois Open Source
5 // License. See LICENSE.TXT for details.
6 //
7 //===----------------------------------------------------------------------===//
8 //
9 // A simple LLVMC-based gcc wrapper.
10 //
11 // To compile, use this command:
12 //
13 // $ cd $LLVM_OBJ_DIR/tools/llvmc
14 // $ make BUILD_EXAMPLES=1
15 //
16 // Run as:
17 //
18 // $ $LLVM_OBJ_DIR/$(BuildMode)/bin/Simple
19 //
20 // For instructions on how to build your own LLVMC-based driver, see
21 // the 'examples/Skeleton' directory.
22 //===----------------------------------------------------------------------===//
23
24 include "llvm/CompilerDriver/Common.td"
25
26 def gcc : Tool<
27 [(in_language "c"),
28 (out_language "executable"),
29 (output_suffix "out"),
30 (command "gcc"),
31 (sink),
32
33 // -o is what is used by default, out_file_option here is included for
34 // instructive purposes.
35 (out_file_option "-o")
36 ]>;
37
38 def LanguageMap : LanguageMap<[(lang_to_suffixes "c", "c")]>;
39
40 def CompilationGraph : CompilationGraph<[(edge "root", "gcc")]>;
+0
-7
tools/llvmc/examples/Skeleton/AutoGenerated.td less more
None //===- AutoGenerated.td ------------------------------------*- tablegen -*-===//
1 //
2 // Write the TableGen description of your llvmc-based driver here.
3 //
4 //===----------------------------------------------------------------------===//
5
6 include "llvm/CompilerDriver/Common.td"
+0
-11
tools/llvmc/examples/Skeleton/CMakeLists.txt less more
None set(LLVM_TARGET_DEFINITIONS AutoGenerated.td)
1
2 tablegen(AutoGenerated.inc -gen-llvmc)
3
4 set(LLVM_USED_LIBS CompilerDriver)
5 set(LLVM_LINK_COMPONENTS support)
6
7 add_llvm_example(llvmc-skeleton
8 Hooks.cpp
9 Main.cpp
10 )
+0
-12
tools/llvmc/examples/Skeleton/Hooks.cpp less more
None //===--- Hooks.cpp - The LLVM Compiler Driver -------------------*- C++ -*-===//
1 //
2 // The LLVM Compiler Infrastructure
3 //
4 // This file is distributed under the University of Illinois Open
5 // Source License. See LICENSE.TXT for details.
6 //
7 //===----------------------------------------------------------------------===//
8 //
9 // Hook definitions should go here.
10 //
11 //===----------------------------------------------------------------------===//
+0
-15
tools/llvmc/examples/Skeleton/Main.cpp less more
None //===--- Main.cpp - The LLVM Compiler Driver -------------------*- C++ -*-===//
1 //
2 // The LLVM Compiler Infrastructure
3 //
4 // This file is distributed under the University of Illinois Open
5 // Source License. See LICENSE.TXT for details.
6 //
7 //===----------------------------------------------------------------------===//
8 //
9 // Just include CompilerDriver/Main.inc and AutoGenerated.inc.
10 //
11 //===----------------------------------------------------------------------===//
12
13 #include "llvm/CompilerDriver/Main.inc"
14 #include "AutoGenerated.inc"
+0
-20
tools/llvmc/examples/Skeleton/Makefile less more
None ##===- llvmc/examples/Skeleton/Makefile --------------------*- Makefile -*-===##
1 #
2 # The LLVM Compiler Infrastructure
3 #
4 # This file is distributed under the University of Illinois Open
5 # Source License. See LICENSE.TXT for details.
6 #
7 ##===----------------------------------------------------------------------===##
8
9 # Change this so that $(LEVEL)/Makefile.common refers to
10 # $LLVM_OBJ_DIR/Makefile.common or $YOUR_LLVM_BASED_PROJECT/Makefile.common.
11 export LEVEL = ../../../..
12
13 # Change this to the name of your LLVMC-based driver.
14 LLVMC_BASED_DRIVER = llvmc-skeleton
15
16 # Change this to the name of .inc file built from your .td file.
17 BUILT_SOURCES = AutoGenerated.inc
18
19 include $(LEVEL)/Makefile.common
+0
-6
tools/llvmc/examples/Skeleton/README less more
None
1 This is a template that can be used to create your own LLVMC-based drivers. Just
2 copy the `Skeleton` directory to the location of your preference and edit
3 `Skeleton/Makefile` and `Skeleton/AutoGenerated.td`.
4
5 The build system assumes that your project is based on LLVM.
+0
-11
tools/llvmc/examples/mcc16/CMakeLists.txt less more
None set(LLVM_TARGET_DEFINITIONS PIC16.td)
1
2 tablegen(PIC16.inc -gen-llvmc)
3
4 set(LLVM_USED_LIBS CompilerDriver)
5 set(LLVM_LINK_COMPONENTS support)
6
7 add_llvm_example(mcc16
8 Hooks.cpp
9 Main.cpp
10 )
+0
-112
tools/llvmc/examples/mcc16/Hooks.cpp less more
None #include "llvm/Support/Path.h"
1 #include "llvm/Support/CommandLine.h"
2 #include "llvm/Support/raw_ostream.h"
3
4 #include
5 #include
6
7 namespace llvmc {
8 extern const char *ProgramName;
9
10 namespace autogenerated {
11 extern llvm::cl::opt Parameter_p;
12 }
13 }
14
15 using namespace llvm;
16 using namespace llvmc;
17
18 // Returns the platform specific directory separator via #ifdefs.
19 // FIXME: This currently work on linux and windows only. It does not
20 // work on other unices.
21 static std::string GetDirSeparator() {
22 #if __linux__ || __APPLE__
23 return "/";
24 #else
25 return "\\";
26 #endif
27 }
28
29 namespace hooks {
30 // Get preprocessor define for the part.
31 // It is __partname format in lower case.
32 std::string
33 GetLowerCasePartDefine(void) {
34 std::locale loc;
35 std::string Partname;
36 if (autogenerated::Parameter_p.empty()) {
37 Partname = "16f1xxx";
38 } else {
39 Partname = autogenerated::Parameter_p;
40 }
41
42 std::string LowerCase;
43 for (unsigned i = 0; i < Partname.size(); i++) {
44 LowerCase.push_back(std::tolower(Partname[i], loc));
45 }
46
47 return "__" + LowerCase;
48 }
49
50 std::string
51 GetUpperCasePartDefine(void) {
52 std::locale loc;
53 std::string Partname;
54 if (autogenerated::Parameter_p.empty()) {
55 Partname = "16f1xxx";
56 } else {
57 Partname = autogenerated::Parameter_p;
58 }
59
60 std::string UpperCase;
61 for (unsigned i = 0; i < Partname.size(); i++) {
62 UpperCase.push_back(std::toupper(Partname[i], loc));
63 }
64
65 return "__" + UpperCase;
66 }
67
68 // Get the dir where c16 executables reside.
69 std::string GetBinDir() {
70 // Construct a Path object from the program name.
71 void *P = (void*) (intptr_t) GetBinDir;
72 sys::Path ProgramFullPath
73 = sys::Path::GetMainExecutable(llvmc::ProgramName, P);
74
75 // Get the dir name for the program. It's last component should be 'bin'.
76 std::string BinDir = ProgramFullPath.getDirname();
77
78 // llvm::errs() << "BinDir: " << BinDir << '\n';
79 return BinDir + GetDirSeparator();
80 }
81
82 // Get the Top-level Installation dir for c16.
83 std::string GetInstallDir() {
84 sys::Path BinDirPath = sys::Path(GetBinDir());
85
86 // Go one more level up to get the install dir.
87 std::string InstallDir = BinDirPath.getDirname();
88
89 return InstallDir + GetDirSeparator();
90 }
91
92 // Get the dir where the c16 header files reside.
93 std::string GetStdHeadersDir() {
94 return GetInstallDir() + "include";
95 }
96
97 // Get the dir where the assembler header files reside.
98 std::string GetStdAsmHeadersDir() {
99 return GetInstallDir() + "inc";
100 }
101
102 // Get the dir where the linker scripts reside.
103 std::string GetStdLinkerScriptsDir() {
104 return GetInstallDir() + "lkr";
105 }
106
107 // Get the dir where startup code, intrinsics and lib reside.
108 std::string GetStdLibsDir() {
109 return GetInstallDir() + "lib";
110 }
111 }
+0
-57
tools/llvmc/examples/mcc16/Main.cpp less more
None //===--- Main.cpp - The LLVM Compiler Driver -------------------*- C++ -*-===//
1 //
2 // The LLVM Compiler Infrastructure
3 //
4 // This file is distributed under the University of Illinois Open
5 // Source License. See LICENSE.TXT for details.
6 //
7 //===----------------------------------------------------------------------===//
8 //
9 // Usually this file just includes CompilerDriver/Main.inc, but here we apply
10 // some trickery to make the built-in '-save-temps' option hidden and enable
11 // '--temp-dir' by default.
12 //
13 //===----------------------------------------------------------------------===//
14
15 #include "llvm/CompilerDriver/BuiltinOptions.h"
16 #include "llvm/CompilerDriver/Main.h"
17
18 #include "llvm/Support/Path.h"
19 #include "llvm/Config/config.h"
20
21 #include
22
23 #include "PIC16.inc"
24
25 namespace {
26
27 // Modify the PACKAGE_VERSION to use build number in top level configure file.
28 void PIC16VersionPrinter(void) {
29 std::cout << "MPLAB C16 1.0 " << PACKAGE_VERSION << "\n";
30 }
31
32 }
33
34 int main(int argc, char** argv) {
35
36 // HACK
37 SaveTemps.setHiddenFlag(llvm::cl::Hidden);
38 TempDirname.setHiddenFlag(llvm::cl::Hidden);
39 Languages.setHiddenFlag(llvm::cl::Hidden);
40 DryRun.setHiddenFlag(llvm::cl::Hidden);
41
42 llvm::cl::SetVersionPrinter(PIC16VersionPrinter);
43
44 // Ask for a standard temp dir, but just cache its basename., and delete it.
45 llvm::sys::Path tempDir;
46 tempDir = llvm::sys::Path::GetTemporaryDirectory();
47 TempDirname = tempDir.getBasename();
48 tempDir.eraseFromDisk(true);
49
50 // We are creating a temp dir in current dir, with the cached name.
51 // But before that remove if one already exists with that name..
52 tempDir = TempDirname;
53 tempDir.eraseFromDisk(true);
54
55 return llvmc::Main(argc, argv);
56 }
+0
-15
tools/llvmc/examples/mcc16/Makefile less more
None ##===- llvmc/examples/mcc16/Makefile -----------------------*- Makefile -*-===##
1 #
2 # The LLVM Compiler Infrastructure
3 #
4 # This file is distributed under the University of Illinois Open Source
5 # License. See LICENSE.TXT for details.
6 #
7 ##===----------------------------------------------------------------------===##
8
9 LEVEL = ../../../..
10
11 LLVMC_BASED_DRIVER = mcc16
12 BUILT_SOURCES = PIC16.inc
13
14 include $(LEVEL)/Makefile.common
+0
-234
tools/llvmc/examples/mcc16/PIC16.td less more
None //===- PIC16.td - PIC16 toolchain driver -------------------*- tablegen -*-===//
1 //
2 // A basic driver for the PIC16 toolchain.
3 //
4 //===----------------------------------------------------------------------===//
5
6 include "llvm/CompilerDriver/Common.td"
7
8 // Options
9
10 def OptionList : OptionList<[
11 (switch_option "g",
12 (help "Enable Debugging")),
13 (switch_option "E",
14 (help "Stop after preprocessing, do not compile")),
15 (switch_option "S",
16 (help "Stop after compilation, do not assemble")),
17 (switch_option "bc",
18 (help "Stop after b-code generation, do not compile")),
19 (switch_option "c",
20 (help "Stop after assemble, do not link")),
21 (prefix_option "p",
22 (help "Specify part name")),
23 (prefix_list_option "I",
24 (help "Add a directory to include path")),
25 (prefix_list_option "L",
26 (help "Add a directory to library path")),
27 (prefix_list_option "K",
28 (help "Add a directory to linker script search path")),
29 (parameter_option "l",
30 (help "Specify a library to link")),
31 (parameter_option "k",
32 (help "Specify a linker script")),
33 (parameter_option "m",
34 (help "Generate linker map file with the given name")),
35 (prefix_list_option "D",
36 (help "Define a macro")),
37 (switch_option "X",
38 (help "Do not invoke mp2hex to create an output hex file.")),
39 (switch_option "O0",
40 (help "Do not optimize")),
41 (switch_option "O1",
42 (help "Optimization Level 1.")),
43 (switch_option "O2",
44 (help "Optimization Level 2.")),
45 (switch_option "O3",
46 (help "Optimization Level 3.")),
47 (switch_option "Od",
48 (help "Perform Debug-safe Optimizations only.")),
49 (switch_option "w",
50 (help "Disable all warnings.")),
51 // (switch_option "O1",
52 // (help "Optimization level 1")),
53 // (switch_option "O2",
54 // (help "Optimization level 2. (Default)")),
55 // (parameter_option "pre-RA-sched",
56 // (help "Example of an option that is passed to llc")),
57 (parameter_option "regalloc",
58 (help "Register allocator to use (possible values: simple, linearscan, pbqp, local; default=linearscan)")),
59 (prefix_list_option "Wa,", (comma_separated),
60 (help "Pass options to assembler (Run 'gpasm -help' for assembler options)")),
61 (prefix_list_option "Wl,", (comma_separated),
62 (help "Pass options to linker (Run 'mplink -help' for linker options)"))
63 // (prefix_list_option "Wllc,",
64 // (help "Pass options to llc")),
65 // (prefix_list_option "Wo,",
66 // (help "Pass options to llvm-ld"))
67 ]>;
68
69 // Tools
70 class clang_based : Tool<
71 [(in_language language),
72 (out_language "llvm-bitcode"),
73 (output_suffix "bc"),
74 (command cmd),
75 (actions (case
76 (and (multiple_input_files),
77 (or (switch_on "S"), (switch_on "c"))),
78 (error "cannot specify -o with -c or -S with multiple files"),
79 (switch_on "E"), [(forward "E"),
80 (stop_compilation), (output_suffix ext_E)],
81 (and (switch_on "E"), (empty "o")), (no_out_file),
82 (switch_on "bc"),[(stop_compilation), (output_suffix "bc")],
83 (switch_on "g"), (append_cmd "-g"),
84 (switch_on "w"), (append_cmd "-w"),
85 (switch_on "O1"), (append_cmd ""),
86 (switch_on "O2"), (append_cmd ""),
87 (switch_on "O3"), (append_cmd ""),
88 (switch_on "Od"), (append_cmd ""),
89 (not_empty "D"), (forward "D"),
90 (not_empty "I"), (forward "I"),
91 (switch_on "O0"), (append_cmd "-O0"),
92 (default), (append_cmd "-O1")))
93 // (sink)
94 ]>;
95
96 def clang_cc : clang_based<"c", "$CALL(GetBinDir)clang -cc1 -I $CALL(GetStdHeadersDir) -D $CALL(GetLowerCasePartDefine) -D $CALL(GetUpperCasePartDefine) -triple=pic16- -emit-llvm-bc ", "i">;
97
98 //def clang_cc : Tool<[
99 // (in_language "c"),
100 // (out_language "llvm-bitcode"),
101 // (output_suffix "bc"),
102 // (cmd_line "$CALL(GetBinDir)clang-cc -I $CALL(GetStdHeadersDir) -triple=pic16- -emit-llvm-bc "),
103 // (cmd_line kkkkk
104 // (actions (case
105 // (switch_on "g"), (append_cmd "g"),
106 // (not_empty "I"), (forward "I"))),
107 // (sink)
108 //]>;
109
110
111 // pre-link-and-lto step.
112 def llvm_ld : Tool<[
113 (in_language "llvm-bitcode"),
114 (out_language "llvm-bitcode"),
115 (output_suffix "bc"),
116 (command "$CALL(GetBinDir)llvm-ld -L $CALL(GetStdLibsDir) -disable-licm-promotion -l std"),
117 (out_file_option "-b"),
118 (actions (case
119 (switch_on "O0"), (append_cmd "-disable-opt"),
120 (switch_on "O1"), (append_cmd "-disable-opt"),
121 // Whenever O3 is not specified on the command line, default i.e. disable-inlining will always be added.
122 (switch_on "O2"), (append_cmd ""),
123 (switch_on "O3"), (append_cmd ""),
124 (default), (append_cmd "-disable-inlining"))),
125 (join)
126 ]>;
127
128 // optimize single file
129 def llvm_ld_optimizer : Tool<[
130 (in_language "llvm-bitcode"),
131 (out_language "llvm-bitcode"),
132 (output_suffix "bc"),
133 // FIXME: we are still not disabling licm-promotion.
134 // -disable-licm-promotion and building stdn library causes c16-71 to fail.
135 (command "$CALL(GetBinDir)llvm-ld "),
136 (out_file_option "-b"),
137 (actions (case
138 (switch_on "O0"), (append_cmd "-disable-opt"),
139 (switch_on "O1"), (append_cmd "-disable-opt"),
140 // Whenever O3 is not specified on the command line, default i.e. disable-inlining will always be added.
141 (switch_on "O2"), (append_cmd ""),
142 (switch_on "O3"), (append_cmd ""),
143 (default), (append_cmd "-disable-inlining")))
144 ]>;
145
146 // optimizer step.
147 def pic16passes : Tool<[
148 (in_language "llvm-bitcode"),
149 (out_language "llvm-bitcode"),
150 (output_suffix "obc"),
151 (command "$CALL(GetBinDir)opt -pic16cloner -pic16overlay -f"),
152 (actions (case
153 (switch_on "O0"), (append_cmd "-disable-opt")))
154 ]>;
155
156 def llc : Tool<[
157 (in_language "llvm-bitcode"),
158 (out_language "assembler"),
159 (output_suffix "s"),
160 (command "$CALL(GetBinDir)llc -march=pic16 -disable-jump-tables -pre-RA-sched=list-burr -f"),
161 (actions (case
162 (switch_on "S"), (stop_compilation),
163 // (not_empty "Wllc,"), (unpack_values "Wllc,"),
164 // (not_empty "pre-RA-sched"), (forward "pre-RA-sched")))
165 (not_empty "regalloc"), (forward "regalloc"),
166 (empty "regalloc"), (append_cmd "-regalloc=linearscan")))
167 ]>;
168
169 def gpasm : Tool<[
170 (in_language "assembler"),
171 (out_language "object-code"),
172 (output_suffix "o"),
173 (command "$CALL(GetBinDir)gpasm -z -r decimal -I $CALL(GetStdAsmHeadersDir) -C -c -w 2"),
174 (actions (case
175 (switch_on "c"), (stop_compilation),
176 (switch_on "g"), (append_cmd "-g"),
177 (not_empty "p"), (forward "p"),
178 (empty "p"), (append_cmd "-p 16f1xxx"),
179 (not_empty "Wa,"), (forward_value "Wa,")))
180 ]>;
181
182 def mplink : Tool<[
183 (in_language "object-code"),
184 (out_language "executable"),
185 (output_suffix "cof"),
186 (command "$CALL(GetBinDir)mplink -e -k $CALL(GetStdLinkerScriptsDir) -l $CALL(GetStdLibsDir) intrinsics.lib stdn.lib"),
187 (actions (case
188 (not_empty "Wl,"), (forward_value "Wl,"),
189 (switch_on "X"), (append_cmd "-x"),
190 (not_empty "L"), (forward_as "L", "-l"),
191 (not_empty "K"), (forward_as "K", "-k"),
192 (not_empty "m"), (forward "m"),
193 (not_empty "p"), [(forward "p"), (append_cmd "-c")],
194 (empty "p"), (append_cmd "-p 16f1xxx -c"),
195 // (not_empty "l"), [(unpack_values "l"),(append_cmd ".lib")])),
196 (not_empty "k"), (forward "k"),
197 (not_empty "l"), (forward "l"))),
198 (join)
199 ]>;
200
201 // Language map
202
203 def LanguageMap : LanguageMap<[
204 (lang_to_suffixes "c", "c"),
205 (lang_to_suffixes "c-cpp-output", "i"),
206 (lang_to_suffixes "assembler", "s"),
207 (lang_to_suffixes "assembler-with-cpp", "S"),
208 (lang_to_suffixes "llvm-assembler", "ll"),
209 (lang_to_suffixes "llvm-bitcode", "bc"),
210 (lang_to_suffixes "object-code", "o"),
211 (lang_to_suffixes "executable", "cof")
212 ]>;
213
214 // Compilation graph
215
216 def CompilationGraph : CompilationGraph<[
217 (edge "root", "clang_cc"),
218 (edge "root", "llvm_ld"),
219 (optional_edge "root", "llvm_ld_optimizer",
220 (case (switch_on "S"), (inc_weight),
221 (switch_on "c"), (inc_weight))),
222 (edge "root", "gpasm"),
223 (edge "root", "mplink"),
224 (edge "clang_cc", "llvm_ld"),
225 (optional_edge "clang_cc", "llvm_ld_optimizer",
226 (case (switch_on "S"), (inc_weight),
227 (switch_on "c"), (inc_weight))),
228 (edge "llvm_ld", "pic16passes"),
229 (edge "llvm_ld_optimizer", "pic16passes"),
230 (edge "pic16passes", "llc"),
231 (edge "llc", "gpasm"),
232 (edge "gpasm", "mplink")
233 ]>;
+0
-75
tools/llvmc/examples/mcc16/README less more
None This is a basic compiler driver for the PIC16 toolchain that shows how to create
1 your own llvmc-based drivers. It is based on the examples/Skeleton template.
2
3 The PIC16 toolchain looks like this:
4
5 clang-cc (FE) -> llvm-ld (optimizer) -> llc (codegen) -> native-as -> native-ld
6
7 Following features were requested by Sanjiv:
8
9 From: Sanjiv Gupta microchip.com>
10 Subject: Re: llvmc for PIC16
11 Newsgroups: gmane.comp.compilers.llvm.devel
12 Date: 2009-06-05 06:51:14 GMT
13
14 The salient features that we want to have in the driver are:
15 1. llvm-ld will be used as "The Optimizer".
16 2. If the user has specified to generate the final executable, then
17 llvm-ld should run on all the .bc files generated by clang and create a
18 single optimized .bc file for further tools.
19 3. -Wo - pass optimizations to the llvm-ld
20 4. mcc16 -Wl - pass options to native linker.
21 5. mcc16 -Wa - pass options to native assembler.
22
23 Here are some example command lines and sample command invocations as to
24 what should be done.
25
26 $ mcc16 -S foo.c
27 // [clang-cc foo.c] -> foo.bc
28 // [llvm-ld foo.bc] -> foo.opt.bc
29 // [llc foo.opt.bc] -> foo.s
30
31 $ mcc16 -S foo.c bar.c
32 // [clang-cc foo.c] -> foo.bc
33 // [llvm-ld foo.bc] -> foo.opt.bc
34 // [llc foo.opt.bc] -> foo.s
35 // [clang-cc bar.c] -> bar.bc
36 // [llvm-ld bar.bc] -> bar.opt.bc
37 // [llc bar.opt.bc] -> bar.s
38
39 ** Use of -g causes llvm-ld to run with -disable-opt
40 $ mcc16 -S -g foo.c
41 // [clang-cc foo.c] -> foo.bc
42 // [llvm-ld -disable-opt foo.bc] -> foo.opt.bc
43 // [llc foo.opt.bc] -> foo.s
44
45 ** -I is passed to clang-cc, -pre-RA-sched=list-burr to llc.
46 $ mcc16 -S -g -I ../include -pre-RA-sched=list-burr foo.c
47 // [clang-cc -I ../include foo.c] -> foo.bc
48 // [llvm-ld -disable-opt foo.bc] -> foo.opt.bc
49 // [llc -pre-RA-sched=list-burr foo.opt.bc] -> foo.s
50
51 ** -Wo passes options to llvm-ld
52 $ mcc16 -Wo=opt1,opt2 -S -I ../include -pre-RA-sched=list-burr foo.c
53 // [clang-cc -I ../include foo.c] -> foo.bc
54 // [llvm-ld -opt1 -opt2 foo.bc] -> foo.opt.bc
55 // [llc -pre-RA-sched=list-burr foo.opt.bc] -> foo.s
56
57 ** -Wa passes options to native as.
58 $ mcc16 -c foo.c -Wa=opt1
59 // [clang-cc foo.c] -> foo.bc
60 // [llvm-ld foo.bc] -> foo.opt.bc
61 // [llc foo.opt.bc] -> foo.s
62 // [native-as -opt1 foo.s] -> foo.o
63
64 $ mcc16 -Wo=opt1 -Wl=opt2 -Wa=opt3 foo.c bar.c
65 // [clang-cc foo.c] -> foo.bc
66 // [clang-cc bar.c] -> bar.bc
67 // [llvm-ld -opt1 foo.bc bar.bc] -> a.out.bc
68 // [llc a.out.bc] -> a.out.s
69 // [native-as -opt3 a.out.s] -> a.out.o
70 // [native-ld -opt2 a.out.o] -> a.out
71
72 Is this achievable by a tablegen based driver ?
73
74 - Sanjiv
+0
-17
tools/llvmc/src/AutoGenerated.td less more
None //===- AutoGenerated.td - LLVMC toolchain descriptions -----*- tablegen -*-===//
1 //
2 // The LLVM Compiler Infrastructure
3 //
4 // This file is distributed under the University of Illinois Open Source
5 // License. See LICENSE.TXT for details.
6 //
7 //===----------------------------------------------------------------------===//
8 //
9 // This file contains compilation graph description used by llvmc.
10 //
11 //===----------------------------------------------------------------------===//
12
13 include "llvm/CompilerDriver/Common.td"
14
15 include "Base.td"
16 include "Clang.td"
+0
-461
tools/llvmc/src/Base.td.in less more
None //===- Base.td - LLVMC toolchain descriptions --------------*- tablegen -*-===//
1 //
2 // The LLVM Compiler Infrastructure
3 //
4 // This file is distributed under the University of Illinois Open Source
5 // License. See LICENSE.TXT for details.
6 //
7 //===----------------------------------------------------------------------===//
8 //
9 // This file contains compilation graph description used by llvmc.
10 //
11 //===----------------------------------------------------------------------===//
12
13 // Options
14
15 def OptList : OptionList<[
16 (switch_option "emit-llvm",
17 (help "Emit LLVM .ll files instead of native object files")),
18 (switch_option "E",
19 (help "Stop after the preprocessing stage, do not run the compiler")),
20 (switch_option "fsyntax-only",
21 (help "Stop after checking the input for syntax errors")),
22 (switch_option "opt",
23 (help "Enable opt")),
24 (switch_option "O0",
25 (help "Turn off optimization"), (zero_or_more)),
26 (switch_option "O1",
27 (help "Optimization level 1"), (zero_or_more)),
28 (switch_option "O2",
29 (help "Optimization level 2"), (zero_or_more)),
30 (switch_option "O3",
31 (help "Optimization level 3"), (zero_or_more)),
32 (switch_option "S",
33 (help "Stop after compilation, do not assemble")),
34 (switch_option "c",
35 (help "Compile and assemble, but do not link")),
36 (switch_option "m32",
37 (help "Generate code for a 32-bit environment"), (hidden)),
38 (switch_option "m64",
39 (help "Generate code for a 64-bit environment"), (hidden)),
40 (switch_option "fPIC",
41 (help "Relocation model: PIC"), (hidden)),
42 (switch_option "mdynamic-no-pic",
43 (help "Relocation model: dynamic-no-pic"), (hidden)),
44 (parameter_option "linker",
45 (help "Choose linker (possible values: gcc, g++)")),
46 (parameter_option "mtune",
47 (help "Target a specific CPU type"), (forward_not_split)),
48 (parameter_list_option "march",
49 (help "Generate code for the specified machine type")),
50 (parameter_option "mcpu",
51 (help "A deprecated synonym for -mtune"), (hidden), (forward_not_split)),
52 (parameter_option "mfpu",
53 (help "Specify type of floating point unit"),
54 (hidden), (forward_not_split)),
55 (parameter_option "mabi",
56 (help "Generate code for the specified ABI"), (hidden)),
57 (parameter_option "mfloat-abi",
58 (help "Specifies which floating-point ABI to use"), (hidden)),
59 (switch_option "mfix-and-continue",
60 (help "Needed by gdb to load .o files dynamically"), (hidden)),
61 (parameter_option "MF",
62 (help "Specify a file to write dependencies to"), (hidden)),
63 (parameter_list_option "MT",
64 (help "Change the name of the rule emitted by dependency generation"),
65 (hidden)),
66 (parameter_list_option "include",
67 (help "Include the named file prior to preprocessing")),
68 (parameter_list_option "iquote",
69 (help "Search dir only for files requested with #inlcude \"file\""),
70 (hidden)),
71 (prefix_list_option "I",
72 (help "Add a directory to include path")),
73 (prefix_list_option "D",
74 (help "Define a macro")),
75 (parameter_list_option "Xpreprocessor", (hidden),
76 (help "Pass options to preprocessor")),
77 (prefix_list_option "Wa,", (comma_separated),
78 (help "Pass options to assembler")),
79 (parameter_list_option "Xassembler", (hidden),
80 (help "Pass options to assembler")),
81 (prefix_list_option "Wllc,", (comma_separated),
82 (help "Pass options to llc")),
83 (prefix_list_option "Wl,",
84 (help "Pass options to linker")),
85 (parameter_list_option "Xlinker", (hidden),
86 (help "Pass options to linker")),
87 (prefix_list_option "Wo,", (comma_separated),
88 (help "Pass options to opt")),
89 (prefix_list_option "m",
90 (help "Enable or disable various extensions (-mmmx, -msse, etc.)"),
91 (hidden))
92 ]>;
93
94 def LinkerOptList : OptionList<[
95 (prefix_list_option "L",
96 (help "Add a directory to link path")),
97 (prefix_list_option "l",
98 (help "Search a library when linking")),
99 (parameter_option "filelist", (hidden),
100 (help "Link the files listed in file")),
101 (switch_option "nostartfiles",
102 (help "Do not use the standard system startup files when linking"),
103 (hidden)),
104 (switch_option "nodefaultlibs",
105 (help "Do not use the standard system libraries when linking"), (hidden)),
106 (switch_option "nostdlib",
107 (help
108 "Do not use the standard system startup files or libraries when linking"),
109 (hidden)),
110 (switch_option "pie",
111 (help "Produce a position independent executable"), (hidden)),
112 (switch_option "rdynamic",
113 (help "Add all symbols to the dynamic export table"), (hidden)),
114 (switch_option "s",
115 (help "Strip all symbols"), (hidden)),
116 (switch_option "static",
117 (help "Do not link against shared libraries"), (hidden)),
118 (switch_option "static-libgcc",
119 (help "Use static libgcc"), (hidden)),
120 (switch_option "shared",
121 (help "Create a DLL instead of the regular executable")),
122 (switch_option "shared-libgcc",
123 (help "Use shared libgcc"), (hidden)),
124 (parameter_option "T",
125 (help "Read linker script"), (hidden)),
126 (parameter_option "u",
127 (help "Start with undefined reference to SYMBOL"), (hidden)),
128 (switch_option "pthread",
129 (help "Enable threads")),
130
131 // TODO: Add a conditional compilation mechanism to make Darwin-only options
132 // like '-arch' really Darwin-only.
133 (parameter_option "arch",
134 (help "Compile for the specified target architecture"), (hidden)),
135 (prefix_list_option "F",
136 (help "Add a directory to framework search path")),
137 (parameter_list_option "framework",
138 (help "Specifies a framework to link against")),
139 (parameter_list_option "weak_framework",
140 (help "Specifies a framework to weakly link against"), (hidden)),
141 (switch_option "dynamiclib", (hidden),
142 (help "Produce a dynamic library")),
143 (switch_option "prebind", (hidden),
144 (help "Prebind all undefined symbols")),
145 (switch_option "dead_strip", (hidden),
146 (help "Remove unreachable blocks of code")),
147 (switch_option "single_module", (hidden),
148 (help "Build the library so it contains only one module")),
149 (parameter_option "install_name", (hidden),
150 (help "File name the library will be installed in")),
151 (parameter_option "compatibility_version", (hidden),
152 (help "Compatibility version number")),
153 (parameter_option "current_version", (hidden),
154 (help "Current version number"))
155 ]>;
156
157 // Option preprocessor.
158
159 def Preprocess : OptionPreprocessor<
160 (case (not (any_switch_on "O0", "O1", "O2", "O3")),
161 (set_option "O2"),
162 (and (switch_on "O3"), (any_switch_on "O0", "O1", "O2")),
163 (unset_option "O0", "O1", "O2"),
164 (and (switch_on "O2"), (any_switch_on "O0", "O1")),
165 (unset_option "O0", "O1"),
166 (switch_on "O1", "O0"),
167 (unset_option "O0"))
168 >;
169
170 // Tools
171
172 class llvm_gcc_based
173 string out_ext> : Tool<
174 [(in_language in_lang),
175 out_lang,
176 (output_suffix out_ext),
177 (command cmd),
178 (actions
179 (case
180 (and (not_empty "o"),
181 (multiple_input_files), (or (switch_on "S"), (switch_on "c"))),
182 (error "cannot specify -o with -c or -S with multiple files"),
183 (switch_on "E"),
184 [(forward "E"), (stop_compilation), (output_suffix E_ext)],
185 (and (switch_on "E"), (empty "o")), (no_out_file),
186
187 // ('-emit-llvm') && !('opt') -> stop compilation
188 (and (switch_on "emit-llvm"), (not (switch_on "opt"))),
189 (stop_compilation),
190 // ('-S' && '-emit-llvm') && !('opt') -> output .ll
191 (and (switch_on "emit-llvm", "S"), (not (switch_on "opt"))),
192 [(forward "S"), (output_suffix "ll")],
193 // Usually just output .bc
194 (not (switch_on "fsyntax-only")),
195 [(append_cmd "-c"), (append_cmd "-emit-llvm")],
196
197 // -fsyntax-only
198 (switch_on "fsyntax-only"), [(forward "fsyntax-only"),
199 (no_out_file), (stop_compilation)],
200
201 // Forwards
202 (not_empty "Xpreprocessor"), (forward "Xpreprocessor"),
203 (not_empty "include"), (forward "include"),
204 (not_empty "iquote"), (forward "iquote"),
205 (not_empty "save-temps"), (append_cmd "-save-temps"),
206 (not_empty "I"), (forward "I"),
207 (not_empty "F"), (forward "F"),
208 (not_empty "D"), (forward "D"),
209 (not_empty "arch"), (forward "arch"),
210 (not_empty "march"), (forward "march"),
211 (not_empty "mcpu"), (forward "mcpu"),
212 (not_empty "mtune"), (forward "mtune"),
213 (not_empty "mfpu"), (forward "mfpu"),
214 (not_empty "mabi"), (forward "mabi"),
215 (not_empty "mfloat-abi"), (forward "mfloat-abi"),
216 (not_empty "m"), (forward "m"),
217 (switch_on "mfix-and-continue"), (forward "mfix-and-continue"),
218 (switch_on "m32"), (forward "m32"),
219 (switch_on "m64"), (forward "m64"),
220 (switch_on "O0"), (forward "O0"),
221 (switch_on "O1"), (forward "O1"),
222 (switch_on "O2"), (forward "O2"),
223 (switch_on "O3"), (forward "O3"),
224 (switch_on "fPIC"), (forward "fPIC"),
225 (switch_on "mdynamic-no-pic"), (forward "mdynamic-no-pic"),
226 (not_empty "MF"), (forward "MF"),
227 (not_empty "MT"), (forward "MT"))),
228 (sink)
229 ]>;
230
231 class llvm_gcc_comp_based
232 : llvm_gcc_based
233 (out_language "llvm-bitcode", "object-code"), "bc">;
234
235 class llvm_gcc_pch_based
236 : llvm_gcc_based
237 (out_language "precompiled-header"), "gch">;
238
239 def llvm_gcc_c : llvm_gcc_comp_based
240 <"@LLVMGCCCOMMAND@ -x c", "c", "i">;
241 def llvm_gcc_cpp : llvm_gcc_comp_based
242 <"@LLVMGXXCOMMAND@ -x c++", "c++", "i">;
243 def llvm_gcc_m : llvm_gcc_comp_based
244 <"@LLVMGCCCOMMAND@ -x objective-c", "objective-c", "mi">;
245 def llvm_gcc_mxx : llvm_gcc_comp_based
246 <"@LLVMGCCCOMMAND@ -x objective-c++", "objective-c++", "mi">;
247
248 def llvm_gcc_c_pch : llvm_gcc_pch_based
249 <"@LLVMGCCCOMMAND@ -x c-header", "c-header", "i">;
250 def llvm_gcc_cpp_pch : llvm_gcc_pch_based
251 <"@LLVMGXXCOMMAND@ -x c++-header", "c++-header", "i">;
252 def llvm_gcc_m_pch : llvm_gcc_pch_based
253 <"@LLVMGCCCOMMAND@ -x objective-c-header", "objective-c-header", "mi">;
254 def llvm_gcc_mxx_pch : llvm_gcc_pch_based
255 <"@LLVMGCCCOMMAND@ -x objective-c++-header", "objective-c++-header", "mi">;
256
257 def opt : Tool<
258 [(in_language "llvm-bitcode"),
259 (out_language "llvm-bitcode"),
260 (output_suffix "opt.bc"),
261 (actions (case (switch_on "emit-llvm"), (stop_compilation),
262 (switch_on "emit-llvm", "S"),
263 [(append_cmd "-S"), (output_suffix "ll")],
264 (not_empty "Wo,"), (forward_value "Wo,"),
265 (switch_on "O1"), (forward "O1"),
266 (switch_on "O2"), (forward "O2"),
267 (switch_on "O3"), (forward "O3"))),
268 (command "opt -f")
269 ]>;
270
271 def llvm_as : Tool<
272 [(in_language "llvm-assembler"),
273 (out_language "llvm-bitcode"),
274 (output_suffix "bc"),
275 (command "llvm-as"),
276 (actions (case (and (switch_on "emit-llvm"), (not (switch_on "opt"))),
277 (stop_compilation)))
278 ]>;
279
280 def llvm_gcc_assembler : Tool<
281 [(in_language "assembler"),
282 (out_language "object-code"),
283 (output_suffix "o"),
284 (command "@LLVMGCCCOMMAND@ -c -x assembler"),
285 (actions (case
286 (switch_on "c"), (stop_compilation),
287 (not_empty "arch"), (forward "arch"),
288 (not_empty "Xassembler"), (forward "Xassembler"),
289 (not_empty "march"), (forward "march"),
290 (not_empty "mcpu"), (forward "mcpu"),
291 (not_empty "mtune"), (forward "mtune"),
292 (not_empty "mabi"), (forward "mabi"),
293 (not_empty "mfloat-abi"), (forward "mfloat-abi"),
294 (switch_on "m32"), (forward "m32"),
295 (switch_on "m64"), (forward "m64"),
296 (not_empty "Wa,"), (forward "Wa,")))
297 ]>;
298
299 def llc : Tool<
300 [(in_language "llvm-bitcode", "llvm-assembler"),
301 (out_language "assembler"),
302 (output_suffix "s"),
303 (command "llc -disable-cfi"),
304 (actions (case
305 (switch_on "S"), (stop_compilation),
306 (switch_on "O0"), (forward "O0"),
307 (switch_on "O1"), (forward "O1"),
308 (switch_on "O2"), (forward "O2"),
309 (switch_on "O3"), (forward "O3"),
310 (switch_on "fPIC"), (append_cmd "-relocation-model=pic"),
311 (switch_on "mdynamic-no-pic"),
312 (append_cmd "-relocation-model=dynamic-no-pic"),
313 (not_empty "march"), (forward_transformed_value
314 "march", "ConvertMArchToMAttr"),
315 (not_empty "mcpu"), (forward_transformed_value "mcpu", "ConvertMCpu"),
316 (and (not_empty "mtune"), (empty "mcpu")),
317 (forward_as "mtune", "-mcpu"),
318 (not_empty "mfpu"), (forward_transformed_value "mfpu", "ConvertMFpu"),
319 (not_empty "m"), (forward_transformed_value "m", "ConvertToMAttr"),
320 (not_empty "Wllc,"), (forward_value "Wllc,")))
321 ]>;
322
323 // Base class for linkers
324 class llvm_gcc_based_linker : Tool<
325 [(in_language "object-code", "static-library", "dynamic-library"),
326 (out_language "executable"),
327 (output_suffix "out"),
328 (command cmd),
329 (works_on_empty (case (and (not_empty "filelist"), on_empty), true,
330 (default), false)),
331 (join),
332 (actions (case
333 (switch_on "pthread"), (append_cmd "-lpthread"),
334 (not_empty "L"), (forward "L"),
335 (not_empty "F"), (forward "F"),
336 (not_empty "arch"), (forward "arch"),
337 (not_empty "framework"), (forward "framework"),
338 (not_empty "weak_framework"), (forward "weak_framework"),
339 (not_empty "filelist"), (forward "filelist"),
340 (not_empty "march"), (forward "march"),
341 (not_empty "mcpu"), (forward "mcpu"),
342 (not_empty "mtune"), (forward "mtune"),
343 (not_empty "mabi"), (forward "mabi"),
344 (not_empty "mfloat-abi"), (forward "mfloat-abi"),
345 (switch_on "m32"), (forward "m32"),
346 (switch_on "m64"), (forward "m64"),
347 (not_empty "l"), (forward "l"),
348 (not_empty "Xlinker"), (forward "Xlinker"),
349 (not_empty "Wl,"), (forward "Wl,"),
350 (switch_on "nostartfiles"), (forward "nostartfiles"),
351 (switch_on "nodefaultlibs"), (forward "nodefaultlibs"),
352 (switch_on "nostdlib"), (forward "nostdlib"),
353 (switch_on "pie"), (forward "pie"),
354 (switch_on "rdynamic"), (forward "rdynamic"),
355 (switch_on "s"), (forward "s"),
356 (switch_on "static"), (forward "static"),
357 (switch_on "static-libgcc"), (forward "static-libgcc"),
358 (switch_on "shared"), (forward "shared"),
359 (switch_on "shared-libgcc"), (forward "shared-libgcc"),
360 (not_empty "T"), (forward "T"),
361 (not_empty "u"), (forward "u"),
362 (switch_on "dynamiclib"), (forward "dynamiclib"),
363 (switch_on "prebind"), (forward "prebind"),
364 (switch_on "dead_strip"), (forward "dead_strip"),
365 (switch_on "single_module"), (forward "single_module"),
366 (not_empty "compatibility_version"),
367 (forward "compatibility_version"),
368 (not_empty "current_version"), (forward "current_version"),
369 (not_empty "install_name"), (forward "install_name")))
370 ]>;
371
372 // Default linker
373 def llvm_gcc_linker : llvm_gcc_based_linker<"@LLVMGCCCOMMAND@",
374 (not (or (parameter_equals "linker", "g++"),
375 (parameter_equals "linker", "c++")))>;
376 // Alternative linker for C++
377 def llvm_gcc_cpp_linker : llvm_gcc_based_linker<"@LLVMGXXCOMMAND@",
378 (or (parameter_equals "linker", "g++"),
379 (parameter_equals "linker", "c++"))>;
380
381 // Language map
382
383 def LanguageMap : LanguageMap<[
384 (lang_to_suffixes "precompiled-header", ["gch", "pch"]),
385 (lang_to_suffixes "c++", ["cc", "cp", "cxx", "cpp", "CPP", "c++", "C"]),
386 (lang_to_suffixes "c++-header", "hpp"),
387 (lang_to_suffixes "c", "c"),
388 (lang_to_suffixes "c-header", "h"),
389 (lang_to_suffixes "c-cpp-output", "i"),
390 (lang_to_suffixes "objective-c-cpp-output", "mi"),
391 (lang_to_suffixes "objective-c++", "mm"),
392 (lang_to_suffixes "objective-c++-header", "hmm"),
393 (lang_to_suffixes "objective-c", "m"),
394 (lang_to_suffixes "objective-c-header", "hm"),
395 (lang_to_suffixes "assembler", "s"),
396 (lang_to_suffixes "assembler-with-cpp", "S"),
397 (lang_to_suffixes "llvm-assembler", "ll"),
398 (lang_to_suffixes "llvm-bitcode", "bc"),
399 (lang_to_suffixes "object-code", ["o", "*empty*"]),
400 (lang_to_suffixes "static-library", ["a", "lib"]),
401 (lang_to_suffixes "dynamic-library", ["so", "dylib", "dll"]),
402 (lang_to_suffixes "executable", "out")
403 ]>;
404
405 // Compilation graph
406
407 def CompilationGraph : CompilationGraph<[
408 (edge "root", "llvm_gcc_c"),
409 (edge "root", "llvm_gcc_assembler"),
410 (edge "root", "llvm_gcc_cpp"),
411 (edge "root", "llvm_gcc_m"),
412 (edge "root", "llvm_gcc_mxx"),
413 (edge "root", "llc"),
414
415 (edge "root", "llvm_gcc_c_pch"),
416 (edge "root", "llvm_gcc_cpp_pch"),
417 (edge "root", "llvm_gcc_m_pch"),
418 (edge "root", "llvm_gcc_mxx_pch"),
419
420 (edge "llvm_gcc_c", "llc"),
421 (edge "llvm_gcc_cpp", "llc"),
422 (edge "llvm_gcc_m", "llc"),
423 (edge "llvm_gcc_mxx", "llc"),
424 (edge "llvm_as", "llc"),
425
426 (optional_edge "root", "llvm_as",
427 (case (or (switch_on "emit-llvm"),
428 (switch_on "opt")), (inc_weight))),
429 (optional_edge "llvm_gcc_c", "opt",
430 (case (switch_on "opt"), (inc_weight))),
431 (optional_edge "llvm_gcc_cpp", "opt",
432 (case (switch_on "opt"), (inc_weight))),
433 (optional_edge "llvm_gcc_m", "opt",
434 (case (switch_on "opt"), (inc_weight))),
435 (optional_edge "llvm_gcc_mxx", "opt",
436 (case (switch_on "opt"), (inc_weight))),
437 (optional_edge "llvm_as", "opt",
438 (case (switch_on "opt"), (inc_weight))),
439 (edge "opt", "llc"),
440
441 (edge "llc", "llvm_gcc_assembler"),
442 (edge "llvm_gcc_assembler", "llvm_gcc_linker"),
443 (optional_edge "llvm_gcc_assembler", "llvm_gcc_cpp_linker",
444 (case
445 (or (input_languages_contain "c++"),
446 (input_languages_contain "objective-c++")),
447 (inc_weight),
448 (or (parameter_equals "linker", "g++"),
449 (parameter_equals "linker", "c++")), (inc_weight))),
450
451
452 (edge "root", "llvm_gcc_linker"),
453 (optional_edge "root", "llvm_gcc_cpp_linker",
454 (case
455 (or (input_languages_contain "c++"),
456 (input_languages_contain "objective-c++")),
457 (inc_weight),
458 (or (parameter_equals "linker", "g++"),
459 (parameter_equals "linker", "c++")), (inc_weight)))
460 ]>;
+0
-19
tools/llvmc/src/CMakeLists.txt less more
None set(LLVMGCCCOMMAND llvm-gcc)
1 set(LLVMGXXCOMMAND llvm-g++)
2
3 configure_file(
4 ${CMAKE_CURRENT_SOURCE_DIR}/Base.td.in
5 ${CMAKE_CURRENT_BINARY_DIR}/Base.td
6 @ONLY)
7
8 set(LLVM_TARGET_DEFINITIONS AutoGenerated.td)
9
10 tablegen(AutoGenerated.inc -gen-llvmc)
11
12 set(LLVM_USED_LIBS CompilerDriver)
13 set(LLVM_LINK_COMPONENTS support)
14
15 add_llvm_tool(llvmc
16 Hooks.cpp
17 Main.cpp
18 )
+0
-87
tools/llvmc/src/Clang.td less more
None //===- Clang.td - LLVMC toolchain descriptions -------------*- tablegen -*-===//
1 //
2 // The LLVM Compiler Infrastructure
3 //
4 // This file is distributed under the University of Illinois Open Source
5 // License. See LICENSE.TXT for details.
6 //
7 //===----------------------------------------------------------------------===//
8 //
9 // This file contains compilation graph description used by llvmc.
10 //
11 //===----------------------------------------------------------------------===//
12
13
14 def Options : OptionList<[
15 (switch_option "clang", (help "Use Clang instead of llvm-gcc"))
16 ]>;
17
18 class clang_based : Tool<
19 [(in_language language),
20 (out_language "llvm-bitcode"),
21 (output_suffix "bc"),
22 (command cmd),
23 (actions (case (switch_on "E"),
24 [(forward "E"), (stop_compilation), (output_suffix ext_E)],
25 (and (switch_on "E"), (empty "o")), (no_out_file),
26 (switch_on "fsyntax-only"), (stop_compilation),
27 (switch_on "S", "emit-llvm"),
28 [(append_cmd "-emit-llvm"),
29 (stop_compilation), (output_suffix "ll")],
30 (not (switch_on "S", "emit-llvm")),
31 (append_cmd "-emit-llvm-bc"),
32 (switch_on "c", "emit-llvm"),
33 (stop_compilation),
34 (not_empty "include"), (forward "include"),
35 (not_empty "I"), (forward "I"))),
36 (sink)
37 ]>;
38
39 def clang_c : clang_based<"c", "clang -x c", "i">;
40 def clang_cpp : clang_based<"c++", "clang -x c++", "i">;
41 def clang_objective_c : clang_based<"objective-c",
42 "clang -x objective-c", "mi">;
43 def clang_objective_cpp : clang_based<"objective-c++",
44 "clang -x objective-c++", "mi">;
45
46 def as : Tool<
47 [(in_language "assembler"),
48 (out_language "object-code"),
49 (output_suffix "o"),
50 (command "as"),
51 (actions (case (not_empty "Wa,"), (forward_value "Wa,"),
52 (switch_on "c"), (stop_compilation)))
53 ]>;
54
55 // Default linker
56 def llvm_ld : Tool<
57 [(in_language "object-code"),
58 (out_language "executable"),
59 (output_suffix "out"),
60 (command "llvm-ld -native -disable-internalize"),
61 (actions (case
62 (switch_on "pthread"), (append_cmd "-lpthread"),
63 (not_empty "L"), (forward "L"),
64 (not_empty "l"), (forward "l"),
65 (not_empty "Wl,"), (forward_value "Wl,"))),
66 (join)
67 ]>;
68
69 // Compilation graph
70
71 def ClangCompilationGraph : CompilationGraph<[
72 (optional_edge "root", "clang_c",
73 (case (switch_on "clang"), (inc_weight))),
74 (optional_edge "root", "clang_cpp",
75 (case (switch_on "clang"), (inc_weight))),
76 (optional_edge "root", "clang_objective_c",
77 (case (switch_on "clang"), (inc_weight))),
78 (optional_edge "root", "clang_objective_cpp",
79 (case (switch_on "clang"), (inc_weight))),
80 (edge "clang_c", "llc"),
81 (edge "clang_cpp", "llc"),
82 (edge "clang_objective_c", "llc"),
83 (edge "clang_objective_cpp", "llc"),
84 (optional_edge "llc", "as", (case (switch_on "clang"), (inc_weight))),
85 (edge "as", "llvm_ld")
86 ]>;
+0
-193
tools/llvmc/src/Hooks.cpp less more
None #include "llvm/ADT/StringMap.h"
1
2 #include
3 #include
4
5 namespace hooks {
6
7 /// NUM_KEYS - Calculate the size of a const char* array.
8 #define NUM_KEYS(Keys) sizeof(Keys) / sizeof(const char*)
9
10 // See http://graphics.stanford.edu/~seander/bithacks.html#RoundUpPowerOf2
11 inline unsigned NextHighestPowerOf2 (unsigned i) {
12 --i;
13 i |= i >> 1;
14 i |= i >> 2;
15 i |= i >> 4;
16 i |= i >> 8;
17 i |= i >> 16;
18 ++i;
19 return i;
20 }
21
22 typedef std::vector StrVec;
23 typedef llvm::StringMap ArgMap;
24
25 /// AddPlusOrMinus - Convert 'no-foo' to '-foo' and 'foo' to '+foo'.
26 void AddPlusOrMinus (const std::string& Arg, std::string& out) {
27 if (Arg.find("no-") == 0 && Arg[3] != 0) {
28 out += '-';
29 out += Arg.c_str() + 3;
30 }
31 else {
32 out += '+';
33 out += Arg;
34 }
35 }
36
37 // -march values that need to be special-cased.
38 const char* MArchKeysARM[] = { "armv4t", "armv5t", "armv5te", "armv6",
39 "armv6-m", "armv6t2", "armv7-a", "armv7-m" };
40 const char* MArchValuesARM[] = { "v4t", "v5t", "v5te", "v6", "v6m", "v6t2",
41 "v7a", "v7m" };
42 const unsigned MArchNumKeysARM = NUM_KEYS(MArchKeysARM);
43 const unsigned MArchMapSize = NextHighestPowerOf2(MArchNumKeysARM);
44
45 // -march values that should be forwarded as -mcpu
46 const char* MArchMCpuKeysARM[] = { "iwmmxt", "ep9312" };
47 const char* MArchMCpuValuesARM[] = { "iwmmxt", "ep9312"};
48 const unsigned MArchMCpuNumKeysARM = NUM_KEYS(MArchMCpuKeysARM);
49
50
51 void FillInArgMap(ArgMap& Args, const char* Keys[],
52 const char* Values[], unsigned NumKeys)
53 {
54 for (unsigned i = 0; i < NumKeys; ++i) {
55 // Explicit cast to StringRef here is necessary to pick up the right
56 // overload.
57 Args.GetOrCreateValue(llvm::StringRef(Keys[i]), Values[i]);
58 }
59 }
60
61 /// ConvertMArchToMAttr - Convert -march from the gcc dialect to
62 /// something llc can understand.
63 std::string ConvertMArchToMAttr(const StrVec& Opts) {
64 static ArgMap MArchMap(MArchMapSize);
65 static ArgMap MArchMCpuMap(MArchMapSize);
66 static bool StaticDataInitialized = false;
67
68 if (!StaticDataInitialized) {
69 FillInArgMap(MArchMap, MArchKeysARM, MArchValuesARM, MArchNumKeysARM);
70 FillInArgMap(MArchMCpuMap, MArchMCpuKeysARM,
71 MArchMCpuValuesARM, MArchMCpuNumKeysARM);
72 StaticDataInitialized = true;
73 }
74
75 std::string mattr("-mattr=");
76 std::string mcpu("-mcpu=");
77 bool mattrTouched = false;
78 bool mcpuTouched = false;
79
80 for (StrVec::const_iterator B = Opts.begin(), E = Opts.end(); B!=E; ++B) {
81 const std::string& Arg = *B;
82
83 // Check if the argument should be forwarded to -mcpu instead of -mattr.
84 {
85 ArgMap::const_iterator I = MArchMCpuMap.find(Arg);
86
87 if (I != MArchMCpuMap.end()) {
88 mcpuTouched = true;
89 mcpu += I->getValue();
90 continue;
91 }
92 }
93
94 if (mattrTouched)
95 mattr += ",";
96
97 // Check if the argument is a special case.
98 {
99 ArgMap::const_iterator I = MArchMap.find(Arg);
100
101 if (I != MArchMap.end()) {
102 mattrTouched = true;
103 mattr += '+';
104 mattr += I->getValue();
105 continue;
106 }
107 }
108
109 AddPlusOrMinus(Arg, mattr);
110 }
111
112 std::string out;
113 if (mattrTouched)
114 out += mattr;
115 if (mcpuTouched)
116 out += (mattrTouched ? " " : "") + mcpu;
117
118 return out;
119 }
120
121 // -mcpu values that need to be special-cased.
122 const char* MCpuKeysPPC[] = { "G3", "G4", "G5", "powerpc", "powerpc64"};
123 const char* MCpuValuesPPC[] = { "g3", "g4", "g5", "ppc", "ppc64"};
124 const unsigned MCpuNumKeysPPC = NUM_KEYS(MCpuKeysPPC);
125 const unsigned MCpuMapSize = NextHighestPowerOf2(MCpuNumKeysPPC);
126
127 /// ConvertMCpu - Convert -mcpu value from the gcc to the llc dialect.
128 std::string ConvertMCpu(const char* Val) {
129 static ArgMap MCpuMap(MCpuMapSize);
130 static bool StaticDataInitialized = false;
131
132 if (!StaticDataInitialized) {
133 FillInArgMap(MCpuMap, MCpuKeysPPC, MCpuValuesPPC, MCpuNumKeysPPC);
134 StaticDataInitialized = true;
135 }
136
137 std::string ret = "-mcpu=";
138 ArgMap::const_iterator I = MCpuMap.find(Val);
139 if (I != MCpuMap.end()) {
140 return ret + I->getValue();
141 }
142 return ret + Val;
143 }
144
145 // -mfpu values that need to be special-cased.
146 const char* MFpuKeysARM[] = { "vfp", "vfpv3",
147 "vfpv3-fp16", "vfpv3-d16", "vfpv3-d16-fp16",
148 "neon", "neon-fp16" };
149 const char* MFpuValuesARM[] = { "vfp2", "vfp3",
150 "+vfp3,+fp16", "+vfp3,+d16", "+vfp3,+d16,+fp16",
151 "+neon", "+neon,+neonfp" };
152 const unsigned MFpuNumKeysARM = NUM_KEYS(MFpuKeysARM);
153 const unsigned MFpuMapSize = NextHighestPowerOf2(MFpuNumKeysARM);
154
155 /// ConvertMFpu - Convert -mfpu value from the gcc to the llc dialect.
156 std::string ConvertMFpu(const char* Val) {
157 static ArgMap MFpuMap(MFpuMapSize);
158 static bool StaticDataInitialized = false;
159
160 if (!StaticDataInitialized) {
161 FillInArgMap(MFpuMap, MFpuKeysARM, MFpuValuesARM, MFpuNumKeysARM);
162 StaticDataInitialized = true;
163 }
164
165 std::string ret = "-mattr=";
166 ArgMap::const_iterator I = MFpuMap.find(Val);
167 if (I != MFpuMap.end()) {
168 return ret + I->getValue();
169 }
170 return ret + '+' + Val;
171 }
172
173 /// ConvertToMAttr - Convert '-mfoo' and '-mno-bar' to '-mattr=+foo,-bar'.
174 std::string ConvertToMAttr(const StrVec& Opts) {
175 std::string out("-mattr=");
176 bool firstIter = true;
177
178 for (StrVec::const_iterator B = Opts.begin(), E = Opts.end(); B!=E; ++B) {
179 const std::string& Arg = *B;
180
181 if (firstIter)
182 firstIter = false;
183 else
184 out += ",";
185
186 AddPlusOrMinus(Arg, out);
187 }
188
189 return out;
190 }
191
192 }
+0
-16
tools/llvmc/src/Main.cpp less more
None //===--- Main.cpp - The LLVM Compiler Driver -------------------*- C++ -*-===//
1 //
2 // The LLVM Compiler Infrastructure
3 //
4 // This file is distributed under the University of Illinois Open
5 // Source License. See LICENSE.TXT for details.
6 //
7 //===----------------------------------------------------------------------===//
8 //
9 // Just include AutoGenerated.inc and CompilerDriver/Main.inc.
10 //
11 //===----------------------------------------------------------------------===//
12
13 #include "AutoGenerated.inc"
14
15 #include "llvm/CompilerDriver/Main.inc"
+0
-14
tools/llvmc/src/Makefile less more
None ##===- tools/llvmc/src/Makefile ----------------------------*- Makefile -*-===##
1 #
2 # The LLVM Compiler Infrastructure
3 #
4 # This file is distributed under the University of Illinois Open
5 # Source License. See LICENSE.TXT for details.
6 #
7 ##===----------------------------------------------------------------------===##
8
9 LEVEL = ../../..
10 LLVMC_BASED_DRIVER = llvmc
11 BUILT_SOURCES = AutoGenerated.inc
12
13 include $(LEVEL)/Makefile.common