From b676fc15a009204f05e548deb5f3695ceb6d231b Mon Sep 17 00:00:00 2001 From: Mikhail Glushenkov Date: Mon, 28 Sep 2009 01:16:42 +0000 Subject: [PATCH] Add a way to query the number of input files. llvm-svn: 82957 --- include/llvm/CompilerDriver/Common.td | 2 ++ tools/llvmc/doc/LLVMC-Reference.rst | 7 ++++++ tools/llvmc/plugins/Base/Base.td.in | 2 ++ utils/TableGen/LLVMCConfigurationEmitter.cpp | 26 ++++++++++++++++---- 4 files changed, 32 insertions(+), 5 deletions(-) diff --git a/include/llvm/CompilerDriver/Common.td b/include/llvm/CompilerDriver/Common.td index e1a0213bf0b..5b7c543f1c9 100644 --- a/include/llvm/CompilerDriver/Common.td +++ b/include/llvm/CompilerDriver/Common.td @@ -66,6 +66,8 @@ def input_languages_contain; def empty; def not_empty; def default; +def single_input_file; +def multiple_input_files; // Possible actions. diff --git a/tools/llvmc/doc/LLVMC-Reference.rst b/tools/llvmc/doc/LLVMC-Reference.rst index 7e609a7bc34..5d3b02a1695 100644 --- a/tools/llvmc/doc/LLVMC-Reference.rst +++ b/tools/llvmc/doc/LLVMC-Reference.rst @@ -458,6 +458,13 @@ 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. diff --git a/tools/llvmc/plugins/Base/Base.td.in b/tools/llvmc/plugins/Base/Base.td.in index d4bff17a318..4b964e3dea1 100644 --- a/tools/llvmc/plugins/Base/Base.td.in +++ b/tools/llvmc/plugins/Base/Base.td.in @@ -70,6 +70,8 @@ class llvm_gcc_based : 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)], diff --git a/utils/TableGen/LLVMCConfigurationEmitter.cpp b/utils/TableGen/LLVMCConfigurationEmitter.cpp index 2800678f8c5..f9a447adffa 100644 --- a/utils/TableGen/LLVMCConfigurationEmitter.cpp +++ b/utils/TableGen/LLVMCConfigurationEmitter.cpp @@ -976,8 +976,22 @@ void CheckForSuperfluousOptions (const RecordVector& Edges, } } -/// EmitCaseTest1Arg - Helper function used by -/// EmitCaseConstructHandler. +/// EmitCaseTest0Args - Helper function used by EmitCaseConstructHandler(). +bool EmitCaseTest0Args(const std::string& TestName, raw_ostream& O) { + if (TestName == "single_input_file") { + O << "InputFilenames.size() == 1"; + return true; + } + else if (TestName == "multiple_input_files") { + O << "InputFilenames.size() > 1"; + return true; + } + + return false; +} + + +/// EmitCaseTest1Arg - Helper function used by EmitCaseConstructHandler(). bool EmitCaseTest1Arg(const std::string& TestName, const DagInit& d, const OptionDescriptions& OptDescs, @@ -1021,8 +1035,7 @@ bool EmitCaseTest1Arg(const std::string& TestName, return false; } -/// EmitCaseTest2Args - Helper function used by -/// EmitCaseConstructHandler. +/// EmitCaseTest2Args - Helper function used by EmitCaseConstructHandler(). bool EmitCaseTest2Args(const std::string& TestName, const DagInit& d, unsigned IndentLevel, @@ -1101,6 +1114,8 @@ void EmitCaseTest(const DagInit& d, unsigned IndentLevel, EmitLogicalOperationTest(d, "||", IndentLevel, OptDescs, O); else if (TestName == "not") EmitLogicalNot(d, IndentLevel, OptDescs, O); + else if (EmitCaseTest0Args(TestName, O)) + return; else if (EmitCaseTest1Arg(TestName, d, OptDescs, O)) return; else if (EmitCaseTest2Args(TestName, d, IndentLevel, OptDescs, O)) @@ -2043,7 +2058,8 @@ void EmitRegisterPlugin(int Priority, raw_ostream& O) { /// EmitIncludes - Emit necessary #include directives and some /// additional declarations. void EmitIncludes(raw_ostream& O) { - O << "#include \"llvm/CompilerDriver/CompilationGraph.h\"\n" + O << "#include \"llvm/CompilerDriver/BuiltinOptions.h\"\n" + << "#include \"llvm/CompilerDriver/CompilationGraph.h\"\n" << "#include \"llvm/CompilerDriver/ForceLinkageMacros.h\"\n" << "#include \"llvm/CompilerDriver/Plugin.h\"\n" << "#include \"llvm/CompilerDriver/Tool.h\"\n\n"