diff options
Diffstat (limited to 'tools/llvmc')
-rw-r--r-- | tools/llvmc/doc/LLVMC-Reference.rst | 42 | ||||
-rw-r--r-- | tools/llvmc/example/Hello/Hello.cpp | 5 | ||||
-rw-r--r-- | tools/llvmc/example/mcc16/driver/Main.cpp | 27 | ||||
-rw-r--r-- | tools/llvmc/example/mcc16/plugins/PIC16Base/PIC16Base.td | 6 | ||||
-rw-r--r-- | tools/llvmc/example/mcc16/plugins/PIC16Base/PluginMain.cpp | 18 | ||||
-rw-r--r-- | tools/llvmc/plugins/Base/Base.td.in | 32 |
6 files changed, 97 insertions, 33 deletions
diff --git a/tools/llvmc/doc/LLVMC-Reference.rst b/tools/llvmc/doc/LLVMC-Reference.rst index b43c3e3..fad2ccc 100644 --- a/tools/llvmc/doc/LLVMC-Reference.rst +++ b/tools/llvmc/doc/LLVMC-Reference.rst @@ -97,6 +97,11 @@ configuration libraries: the ``-o`` option. The ``--save-temps=cwd`` and ``--save-temps`` switches are both synonyms for the default behaviour. +* ``--temp-dir DIRECTORY`` - Store temporary files in the given directory. This + directory is deleted on exit unless ``--save-temps`` is specified. If + ``--save-temps=obj`` is also specified, ``--temp-dir`` is given the + precedence. + * ``--check-graph`` - Check the compilation for common errors like mismatched output/input language names, multiple default edges and cycles. Because of plugins, these checks can't be performed at compile-time. Exit with code zero @@ -347,6 +352,12 @@ separate option groups syntactically. 3))``. Only list options can have this attribute; you can, however, use the ``one_or_more`` and ``zero_or_one`` properties. + - ``init`` - this option has a default value, either a string (if it is a + parameter), or a boolean (if it is a switch; boolean constants are called + ``true`` and ``false``). List options can't have this attribute. Usage + examples: ``(switch_option "foo", (init true))``; ``(prefix_option "bar", + (init "baz"))``. + - ``extern`` - this option is defined in some other plugin, see below. External options @@ -362,7 +373,8 @@ for. Example:: (switch_option "E", (extern)) ... -See also the section on plugin `priorities`__. +If an external option has additional attributes besides 'extern', they are +ignored. See also the section on plugin `priorities`__. __ priorities_ @@ -446,17 +458,27 @@ use TableGen inheritance instead. - ``empty`` - The opposite of ``not_empty``. Equivalent to ``(not (not_empty X))``. Provided for convenience. + - ``single_input_file`` - Returns true if there was only one input file + provided on the command-line. Used without arguments: + ``(single_input_file)``. + + - ``multiple_input_files`` - Equivalent to ``(not (single_input_file))`` (the + case of zero input files is considered an error). + - ``default`` - Always evaluates to true. Should always be the last test in the ``case`` expression. - - ``and`` - A standard logical combinator that returns true iff all - of its arguments return true. Used like this: ``(and (test1), - (test2), ... (testN))``. Nesting of ``and`` and ``or`` is allowed, - but not encouraged. + - ``and`` - A standard binary logical combinator that returns true iff all of + its arguments return true. Used like this: ``(and (test1), (test2), + ... (testN))``. Nesting of ``and`` and ``or`` is allowed, but not + encouraged. + + - ``or`` - A binary logical combinator that returns true iff any of its + arguments returns true. Example: ``(or (test1), (test2), ... (testN))``. + + - ``not`` - Standard unary logical combinator that negates its + argument. Example: ``(not (or (test1), (test2), ... (testN)))``. - - ``or`` - Another logical combinator that returns true only if any - one of its arguments returns true. Example: ``(or (test1), - (test2), ... (testN))``. Writing a tool description @@ -487,8 +509,8 @@ The complete list of all currently implemented tool properties follows. - ``in_language`` - input language name. Can be either a string or a list, in case the tool supports multiple input languages. - - ``out_language`` - output language name. Tools are not allowed to - have multiple output languages. + - ``out_language`` - output language name. Multiple output languages are not + allowed. - ``output_suffix`` - output file suffix. Can also be changed dynamically, see documentation on actions. diff --git a/tools/llvmc/example/Hello/Hello.cpp b/tools/llvmc/example/Hello/Hello.cpp index 23a13a5..9c96bd0 100644 --- a/tools/llvmc/example/Hello/Hello.cpp +++ b/tools/llvmc/example/Hello/Hello.cpp @@ -13,13 +13,12 @@ #include "llvm/CompilerDriver/CompilationGraph.h" #include "llvm/CompilerDriver/Plugin.h" - -#include <iostream> +#include "llvm/Support/raw_ostream.h" namespace { struct MyPlugin : public llvmc::BasePlugin { void PopulateLanguageMap(llvmc::LanguageMap&) const - { std::cout << "Hello!\n"; } + { outs() << "Hello!\n"; } void PopulateCompilationGraph(llvmc::CompilationGraph&) const {} diff --git a/tools/llvmc/example/mcc16/driver/Main.cpp b/tools/llvmc/example/mcc16/driver/Main.cpp index b1f5b67..f42e17f 100644 --- a/tools/llvmc/example/mcc16/driver/Main.cpp +++ b/tools/llvmc/example/mcc16/driver/Main.cpp @@ -7,8 +7,31 @@ // //===----------------------------------------------------------------------===// // -// Just include CompilerDriver/Main.inc. +// Usually this file just includes CompilerDriver/Main.inc, but here we apply +// some trickery to make the built-in '-save-temps' option hidden and enable +// '--temp-dir' by default. // //===----------------------------------------------------------------------===// -#include "llvm/CompilerDriver/Main.inc" +#include "llvm/CompilerDriver/BuiltinOptions.h" +#include "llvm/CompilerDriver/ForceLinkage.h" +#include "llvm/System/Path.h" + +namespace llvmc { + int Main(int argc, char** argv); +} + +int main(int argc, char** argv) { + + // HACK + SaveTemps.setHiddenFlag(llvm::cl::Hidden); + TempDirname = "tmp-objs"; + + // Remove the temp dir if already exists. + llvm::sys::Path tempDir; + tempDir = TempDirname; + tempDir.eraseFromDisk(true); + + llvmc::ForceLinkage(); + return llvmc::Main(argc, argv); +} diff --git a/tools/llvmc/example/mcc16/plugins/PIC16Base/PIC16Base.td b/tools/llvmc/example/mcc16/plugins/PIC16Base/PIC16Base.td index de85fa9..3d25ab6 100644 --- a/tools/llvmc/example/mcc16/plugins/PIC16Base/PIC16Base.td +++ b/tools/llvmc/example/mcc16/plugins/PIC16Base/PIC16Base.td @@ -55,7 +55,7 @@ def llvm_ld_lto : Tool<[ (in_language "llvm-bitcode"), (out_language "llvm-bitcode"), (output_suffix "bc"), - (cmd_line "$CALL(GetBinDir)llvm-ld -link-as-library $INFILE -o $OUTFILE"), + (cmd_line "$CALL(GetBinDir)llvm-ld -L $CALL(GetStdLibsDir) -l std $INFILE -b $OUTFILE"), (actions (case (switch_on "g"), (append_cmd "-disable-opt"), (not_empty "Wo,"), (unpack_values "Wo,"))), @@ -66,7 +66,7 @@ def llc : Tool<[ (in_language "llvm-bitcode"), (out_language "assembler"), (output_suffix "s"), - (cmd_line "$CALL(GetBinDir)llc -march=pic16 -f $INFILE -o $OUTFILE"), + (cmd_line "$CALL(GetBinDir)llc -march=pic16 -disable-jump-tables -f $INFILE -o $OUTFILE"), (actions (case (switch_on "S"), (stop_compilation), (not_empty "Wllc,"), (unpack_values "Wllc,"), @@ -87,7 +87,7 @@ def mplink : Tool<[ (in_language "object-code"), (out_language "executable"), (output_suffix "out"), - (cmd_line "$CALL(GetBinDir)mplink.exe /k $CALL(GetStdLinkerScriptsDir) /l $CALL(GetStdLibsDir) 16f1937.lkr intrinsics.lib std.lib $INFILE -o $OUTFILE"), + (cmd_line "$CALL(GetBinDir)mplink.exe -k $CALL(GetStdLinkerScriptsDir) -l $CALL(GetStdLibsDir) 16f1937_g.lkr intrinsics.lib devices.lib $INFILE -o $OUTFILE"), (actions (case (not_empty "Wl,"), (unpack_values "Wl,"))), (join) diff --git a/tools/llvmc/example/mcc16/plugins/PIC16Base/PluginMain.cpp b/tools/llvmc/example/mcc16/plugins/PIC16Base/PluginMain.cpp index 21a25b3..f8492ed 100644 --- a/tools/llvmc/example/mcc16/plugins/PIC16Base/PluginMain.cpp +++ b/tools/llvmc/example/mcc16/plugins/PIC16Base/PluginMain.cpp @@ -10,13 +10,17 @@ namespace llvmc { } // Returns the platform specific directory separator via #ifdefs. -static std::string GetDirSeparator(void) { +static std::string GetDirSeparator() { +#ifdef _WIN32 + return "\\"; +#else return "/"; +#endif } namespace hooks { // Get the dir where c16 executables reside. -std::string GetBinDir (void) { +std::string GetBinDir() { // Construct a Path object from the program name. void *P = (void*) (intptr_t) GetBinDir; sys::Path ProgramFullPath @@ -30,7 +34,7 @@ std::string GetBinDir (void) { } // Get the Top-level Installation dir for c16. -std::string GetInstallDir (void) { +std::string GetInstallDir() { sys::Path BinDirPath = sys::Path(GetBinDir()); // Go one more level up to get the install dir. @@ -40,22 +44,22 @@ std::string GetInstallDir (void) { } // Get the dir where the c16 header files reside. -std::string GetStdHeadersDir (void) { +std::string GetStdHeadersDir() { return GetInstallDir() + "include"; } // Get the dir where the assembler header files reside. -std::string GetStdAsmHeadersDir (void) { +std::string GetStdAsmHeadersDir() { return GetInstallDir() + "inc"; } // Get the dir where the linker scripts reside. -std::string GetStdLinkerScriptsDir (void) { +std::string GetStdLinkerScriptsDir() { return GetInstallDir() + "lkr"; } // Get the dir where startup code, intrinsics and lib reside. -std::string GetStdLibsDir (void) { +std::string GetStdLibsDir() { return GetInstallDir() + "lib"; } } diff --git a/tools/llvmc/plugins/Base/Base.td.in b/tools/llvmc/plugins/Base/Base.td.in index 757078a..be325a0 100644 --- a/tools/llvmc/plugins/Base/Base.td.in +++ b/tools/llvmc/plugins/Base/Base.td.in @@ -1,4 +1,4 @@ -//===- Base.td - LLVMC2 toolchain descriptions -------------*- tablegen -*-===// +//===- Base.td - LLVMC toolchain descriptions --------------*- tablegen -*-===// // // The LLVM Compiler Infrastructure // @@ -7,7 +7,7 @@ // //===----------------------------------------------------------------------===// // -// This file contains compilation graph description used by llvmc2. +// This file contains compilation graph description used by llvmc. // //===----------------------------------------------------------------------===// @@ -32,10 +32,17 @@ def OptList : OptionList<[ (help "Enable threads")), (parameter_option "linker", (help "Choose linker (possible values: gcc, g++)")), + (parameter_option "MF", + (help "Specify a file to write dependencies to"), (hidden)), + (parameter_option "MT", + (help "Change the name of the rule emitted by dependency generation"), + (hidden)), (parameter_list_option "include", (help "Include the named file prior to preprocessing")), (prefix_list_option "I", (help "Add a directory to include path")), + (prefix_list_option "D", + (help "Define a macro")), (prefix_list_option "Wa,", (help "Pass options to assembler")), (prefix_list_option "Wllc,", @@ -70,19 +77,25 @@ class llvm_gcc_based <string cmd_prefix, string in_lang, string E_ext> : Tool< !strconcat(cmd_prefix, " -c $INFILE -o $OUTFILE -emit-llvm"))), (actions (case + (and (multiple_input_files), (or (switch_on "S"), (switch_on "c"))), + (error "cannot specify -o with -c or -S with multiple files"), (switch_on "E"), [(stop_compilation), (output_suffix E_ext)], (and (switch_on "emit-llvm"), (switch_on "S")), [(output_suffix "ll"), (stop_compilation)], (and (switch_on "emit-llvm"), (switch_on "c")), (stop_compilation), (switch_on "fsyntax-only"), (stop_compilation), (not_empty "include"), (forward "include"), - (not_empty "I"), (forward "I"))), + (not_empty "I"), (forward "I"), + (not_empty "D"), (forward "D"), + (not_empty "MF"), (forward "MF"), + (not_empty "MT"), (forward "MT"))), (sink) ]>; def llvm_gcc_c : llvm_gcc_based<"@LLVMGCCCOMMAND@ -x c", "c", "i">; def llvm_gcc_cpp : llvm_gcc_based<"@LLVMGXXCOMMAND@ -x c++", "c++", "i">; -def llvm_gcc_m : llvm_gcc_based<"@LLVMGCCCOMMAND@ -x objective-c", "objective-c", "mi">; +def llvm_gcc_m : llvm_gcc_based<"@LLVMGCCCOMMAND@ -x objective-c", + "objective-c", "mi">; def llvm_gcc_mxx : llvm_gcc_based<"@LLVMGCCCOMMAND@ -x objective-c++", "objective-c++", "mi">; @@ -98,7 +111,8 @@ def llvm_as : Tool< [(in_language "llvm-assembler"), (out_language "llvm-bitcode"), (output_suffix "bc"), - (cmd_line "llvm-as $INFILE -o $OUTFILE") + (cmd_line "llvm-as $INFILE -o $OUTFILE"), + (actions (case (switch_on "emit-llvm"), (stop_compilation))) ]>; def llvm_gcc_assembler : Tool< @@ -112,7 +126,7 @@ def llvm_gcc_assembler : Tool< ]>; def llc : Tool< -[(in_language "llvm-bitcode"), +[(in_language ["llvm-bitcode", "llvm-assembler"]), (out_language "assembler"), (output_suffix "s"), (cmd_line "llc -f $INFILE -o $OUTFILE"), @@ -132,7 +146,7 @@ class llvm_gcc_based_linker <string cmd_prefix> : Tool< (switch_on "pthread"), (append_cmd "-lpthread"), (not_empty "L"), (forward "L"), (not_empty "l"), (forward "l"), - (not_empty "Wl,"), (unpack_values "Wl,"))) + (not_empty "Wl,"), (forward "Wl,"))) ]>; // Default linker @@ -165,7 +179,7 @@ def CompilationGraph : CompilationGraph<[ Edge<"root", "llvm_gcc_cpp">, Edge<"root", "llvm_gcc_m">, Edge<"root", "llvm_gcc_mxx">, - Edge<"root", "llvm_as">, + Edge<"root", "llc">, Edge<"llvm_gcc_c", "llc">, Edge<"llvm_gcc_cpp", "llc">, @@ -173,6 +187,8 @@ def CompilationGraph : CompilationGraph<[ Edge<"llvm_gcc_mxx", "llc">, Edge<"llvm_as", "llc">, + OptionalEdge<"root", "llvm_as", + (case (switch_on "emit-llvm"), (inc_weight))>, OptionalEdge<"llvm_gcc_c", "opt", (case (switch_on "opt"), (inc_weight))>, OptionalEdge<"llvm_gcc_cpp", "opt", (case (switch_on "opt"), (inc_weight))>, OptionalEdge<"llvm_gcc_m", "opt", (case (switch_on "opt"), (inc_weight))>, |