mirror of
https://github.com/c64scene-ar/llvm-6502.git
synced 2025-02-12 18:33:22 +00:00
New tests for the 'case' expression: not_empty, in_language.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@51744 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
parent
ef4160dff0
commit
2e73e851d8
@ -24,5 +24,10 @@
|
|||||||
using namespace llvm;
|
using namespace llvm;
|
||||||
using namespace llvmc;
|
using namespace llvmc;
|
||||||
|
|
||||||
|
namespace llvmc {
|
||||||
|
extern LanguageMap GlobalLanguageMap;
|
||||||
|
extern const std::string& GetLanguage(const sys::Path& File);
|
||||||
|
}
|
||||||
|
|
||||||
// The auto-generated file
|
// The auto-generated file
|
||||||
#include "AutoGenerated.inc"
|
#include "AutoGenerated.inc"
|
||||||
|
@ -25,7 +25,7 @@ namespace llvmc {
|
|||||||
|
|
||||||
/// PopulateLanguageMap - The auto-generated function that fills in
|
/// PopulateLanguageMap - The auto-generated function that fills in
|
||||||
/// the language map (map from file extensions to language names).
|
/// the language map (map from file extensions to language names).
|
||||||
void PopulateLanguageMap(LanguageMap& language_map);
|
void PopulateLanguageMap();
|
||||||
/// PopulateCompilationGraph - The auto-generated function that
|
/// PopulateCompilationGraph - The auto-generated function that
|
||||||
/// populates the compilation graph with nodes and edges.
|
/// populates the compilation graph with nodes and edges.
|
||||||
void PopulateCompilationGraph(CompilationGraph& tools);
|
void PopulateCompilationGraph(CompilationGraph& tools);
|
||||||
|
@ -56,6 +56,8 @@ def switch_on;
|
|||||||
def parameter_equals;
|
def parameter_equals;
|
||||||
def element_in_list;
|
def element_in_list;
|
||||||
def input_languages_contain;
|
def input_languages_contain;
|
||||||
|
def not_empty;
|
||||||
|
// TOTHINK: remove?
|
||||||
def default;
|
def default;
|
||||||
|
|
||||||
// Boolean operators.
|
// Boolean operators.
|
||||||
|
@ -32,6 +32,19 @@ extern cl::list<std::string> InputFilenames;
|
|||||||
extern cl::opt<std::string> OutputFilename;
|
extern cl::opt<std::string> OutputFilename;
|
||||||
extern cl::list<std::string> Languages;
|
extern cl::list<std::string> Languages;
|
||||||
|
|
||||||
|
namespace llvmc {
|
||||||
|
/// ExtsToLangs - Map from file extensions to language names.
|
||||||
|
LanguageMap GlobalLanguageMap;
|
||||||
|
|
||||||
|
/// GetLanguage - Find the language name corresponding to the given file.
|
||||||
|
const std::string& GetLanguage(const sys::Path& File) {
|
||||||
|
LanguageMap::const_iterator Lang = GlobalLanguageMap.find(File.getSuffix());
|
||||||
|
if (Lang == GlobalLanguageMap.end())
|
||||||
|
throw std::runtime_error("Unknown suffix: " + File.getSuffix());
|
||||||
|
return Lang->second;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
namespace {
|
namespace {
|
||||||
|
|
||||||
/// ChooseEdge - Return the edge with the maximum weight.
|
/// ChooseEdge - Return the edge with the maximum weight.
|
||||||
@ -87,14 +100,6 @@ const Node& CompilationGraph::getNode(const std::string& ToolName) const {
|
|||||||
return I->second;
|
return I->second;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Find the language name corresponding to the given file.
|
|
||||||
const std::string& CompilationGraph::getLanguage(const sys::Path& File) const {
|
|
||||||
LanguageMap::const_iterator Lang = ExtsToLangs.find(File.getSuffix());
|
|
||||||
if (Lang == ExtsToLangs.end())
|
|
||||||
throw std::runtime_error("Unknown suffix: " + File.getSuffix());
|
|
||||||
return Lang->second;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Find the tools list corresponding to the given language name.
|
// Find the tools list corresponding to the given language name.
|
||||||
const CompilationGraph::tools_vector_type&
|
const CompilationGraph::tools_vector_type&
|
||||||
CompilationGraph::getToolsVector(const std::string& LangName) const
|
CompilationGraph::getToolsVector(const std::string& LangName) const
|
||||||
@ -200,7 +205,7 @@ FindToolChain(const sys::Path& In, const std::string* forceLanguage,
|
|||||||
|
|
||||||
// Determine the input language.
|
// Determine the input language.
|
||||||
const std::string& InLanguage =
|
const std::string& InLanguage =
|
||||||
forceLanguage ? *forceLanguage : getLanguage(In);
|
forceLanguage ? *forceLanguage : GetLanguage(In);
|
||||||
|
|
||||||
// Add the current input language to the input language set.
|
// Add the current input language to the input language set.
|
||||||
InLangs.insert(InLanguage);
|
InLangs.insert(InLanguage);
|
||||||
|
@ -111,8 +111,6 @@ namespace llvmc {
|
|||||||
llvm::SmallVector<llvm::IntrusiveRefCntPtr<Edge>, 3> tools_vector_type;
|
llvm::SmallVector<llvm::IntrusiveRefCntPtr<Edge>, 3> tools_vector_type;
|
||||||
typedef llvm::StringMap<tools_vector_type> tools_map_type;
|
typedef llvm::StringMap<tools_vector_type> tools_map_type;
|
||||||
|
|
||||||
/// ExtsToLangs - Map from file extensions to language names.
|
|
||||||
LanguageMap ExtsToLangs;
|
|
||||||
/// ToolsMap - Map from language names to lists of tool names.
|
/// ToolsMap - Map from language names to lists of tool names.
|
||||||
tools_map_type ToolsMap;
|
tools_map_type ToolsMap;
|
||||||
/// NodesMap - Map from tool names to Tool objects.
|
/// NodesMap - Map from tool names to Tool objects.
|
||||||
@ -134,7 +132,7 @@ namespace llvmc {
|
|||||||
/// options are passed implicitly as global variables.
|
/// options are passed implicitly as global variables.
|
||||||
int Build(llvm::sys::Path const& tempDir);
|
int Build(llvm::sys::Path const& tempDir);
|
||||||
|
|
||||||
/// getNode -Return a reference to the node correponding to the
|
/// getNode - Return a reference to the node correponding to the
|
||||||
/// given tool name. Throws std::runtime_error.
|
/// given tool name. Throws std::runtime_error.
|
||||||
Node& getNode(const std::string& ToolName);
|
Node& getNode(const std::string& ToolName);
|
||||||
const Node& getNode(const std::string& ToolName) const;
|
const Node& getNode(const std::string& ToolName) const;
|
||||||
@ -152,15 +150,10 @@ namespace llvmc {
|
|||||||
// GraphTraits support.
|
// GraphTraits support.
|
||||||
friend NodesIterator GraphBegin(CompilationGraph*);
|
friend NodesIterator GraphBegin(CompilationGraph*);
|
||||||
friend NodesIterator GraphEnd(CompilationGraph*);
|
friend NodesIterator GraphEnd(CompilationGraph*);
|
||||||
friend void PopulateCompilationGraph(CompilationGraph&);
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
// Helper functions.
|
// Helper functions.
|
||||||
|
|
||||||
/// getLanguage - Find out which language corresponds to the
|
|
||||||
/// suffix of this file.
|
|
||||||
const std::string& getLanguage(const llvm::sys::Path& File) const;
|
|
||||||
|
|
||||||
/// getToolsVector - Return a reference to the list of tool names
|
/// getToolsVector - Return a reference to the list of tool names
|
||||||
/// corresponding to the given language name. Throws
|
/// corresponding to the given language name. Throws
|
||||||
/// std::runtime_error.
|
/// std::runtime_error.
|
||||||
|
@ -41,6 +41,7 @@ def llvm_gcc_cpp : Tool<
|
|||||||
(output_suffix "bc"),
|
(output_suffix "bc"),
|
||||||
(cmd_line (case
|
(cmd_line (case
|
||||||
(switch_on "E"),
|
(switch_on "E"),
|
||||||
|
// TOFIX: this does not play well with -o
|
||||||
"llvm-g++ -E -x c++ $INFILE",
|
"llvm-g++ -E -x c++ $INFILE",
|
||||||
(default),
|
(default),
|
||||||
"llvm-g++ -c -x c++ $INFILE -o $OUTFILE -emit-llvm")),
|
"llvm-g++ -c -x c++ $INFILE -o $OUTFILE -emit-llvm")),
|
||||||
|
@ -8,9 +8,13 @@ def clang : Tool<
|
|||||||
[(in_language ["c", "c++", "objective-c"]),
|
[(in_language ["c", "c++", "objective-c"]),
|
||||||
(out_language "llvm-bitcode"),
|
(out_language "llvm-bitcode"),
|
||||||
(output_suffix "bc"),
|
(output_suffix "bc"),
|
||||||
// TOFIX: We should be able to test the language of the input file
|
|
||||||
(cmd_line (case (switch_on "E"), "clang -E $INFILE",
|
(cmd_line (case (switch_on "E"), "clang -E $INFILE",
|
||||||
(default), "clang -emit-llvm-bc $INFILE -o $OUTFILE")),
|
(in_language "c"),
|
||||||
|
"clang -emit-llvm-bc -x c $INFILE -o $OUTFILE",
|
||||||
|
(in_language "c++"),
|
||||||
|
"clang -emit-llvm-bc -x c++ $INFILE -o $OUTFILE",
|
||||||
|
(in_language "objective-c"),
|
||||||
|
"clang -emit-llvm-bc -x objective-c$INFILE -o $OUTFILE")),
|
||||||
(switch_option "E", (stop_compilation), (output_suffix "i"),
|
(switch_option "E", (stop_compilation), (output_suffix "i"),
|
||||||
(help "Stop after the preprocessing stage, do not run the compiler")),
|
(help "Stop after the preprocessing stage, do not run the compiler")),
|
||||||
(sink)
|
(sink)
|
||||||
|
@ -667,6 +667,16 @@ bool EmitCaseTest1Arg(const std::string& TestName,
|
|||||||
} else if (TestName == "input_languages_contain") {
|
} else if (TestName == "input_languages_contain") {
|
||||||
O << "InLangs.count(\"" << OptName << "\") != 0";
|
O << "InLangs.count(\"" << OptName << "\") != 0";
|
||||||
return true;
|
return true;
|
||||||
|
} else if (TestName == "in_language") {
|
||||||
|
// Works only for cmd_line!
|
||||||
|
O << "GetLanguage(inFile) == \"" << OptName << '\"';
|
||||||
|
return true;
|
||||||
|
} else if (TestName == "not_empty") {
|
||||||
|
const GlobalOptionDescription& OptDesc = OptDescs.FindOption(OptName);
|
||||||
|
if (OptDesc.Type == OptionType::Switch)
|
||||||
|
throw OptName + ": incorrect option type!";
|
||||||
|
O << '!' << OptDesc.GenVariableName() << ".empty()";
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
@ -1026,7 +1036,7 @@ void EmitGenerateActionMethod (const ToolProperties& P,
|
|||||||
else
|
else
|
||||||
EmitCaseConstructHandler(&InitPtrToDag(P.CmdLine), Indent2,
|
EmitCaseConstructHandler(&InitPtrToDag(P.CmdLine), Indent2,
|
||||||
EmitCmdLineVecFillCallback(Version, P.Name),
|
EmitCmdLineVecFillCallback(Version, P.Name),
|
||||||
true, OptDescs, O);
|
false, OptDescs, O);
|
||||||
|
|
||||||
// For every understood option, emit handling code.
|
// For every understood option, emit handling code.
|
||||||
for (ToolOptionDescriptions::const_iterator B = P.OptDescs.begin(),
|
for (ToolOptionDescriptions::const_iterator B = P.OptDescs.begin(),
|
||||||
@ -1222,7 +1232,7 @@ void EmitPopulateLanguageMap (const RecordKeeper& Records, std::ostream& O)
|
|||||||
throw std::string("Error in the language map definition!");
|
throw std::string("Error in the language map definition!");
|
||||||
|
|
||||||
// Generate code
|
// Generate code
|
||||||
O << "void llvmc::PopulateLanguageMap(LanguageMap& language_map) {\n";
|
O << "void llvmc::PopulateLanguageMap() {\n";
|
||||||
|
|
||||||
for (unsigned i = 0; i < LangsToSuffixesList->size(); ++i) {
|
for (unsigned i = 0; i < LangsToSuffixesList->size(); ++i) {
|
||||||
Record* LangToSuffixes = LangsToSuffixesList->getElementAsRecord(i);
|
Record* LangToSuffixes = LangsToSuffixesList->getElementAsRecord(i);
|
||||||
@ -1231,7 +1241,7 @@ void EmitPopulateLanguageMap (const RecordKeeper& Records, std::ostream& O)
|
|||||||
const ListInit* Suffixes = LangToSuffixes->getValueAsListInit("suffixes");
|
const ListInit* Suffixes = LangToSuffixes->getValueAsListInit("suffixes");
|
||||||
|
|
||||||
for (unsigned i = 0; i < Suffixes->size(); ++i)
|
for (unsigned i = 0; i < Suffixes->size(); ++i)
|
||||||
O << Indent1 << "language_map[\""
|
O << Indent1 << "GlobalLanguageMap[\""
|
||||||
<< InitPtrToString(Suffixes->getElement(i))
|
<< InitPtrToString(Suffixes->getElement(i))
|
||||||
<< "\"] = \"" << Lang << "\";\n";
|
<< "\"] = \"" << Lang << "\";\n";
|
||||||
}
|
}
|
||||||
@ -1360,7 +1370,7 @@ void EmitPopulateCompilationGraph (Record* CompilationGraph,
|
|||||||
|
|
||||||
// Generate code
|
// Generate code
|
||||||
O << "void llvmc::PopulateCompilationGraph(CompilationGraph& G) {\n"
|
O << "void llvmc::PopulateCompilationGraph(CompilationGraph& G) {\n"
|
||||||
<< Indent1 << "PopulateLanguageMap(G.ExtsToLangs);\n\n";
|
<< Indent1 << "PopulateLanguageMap();\n\n";
|
||||||
|
|
||||||
// Insert vertices
|
// Insert vertices
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user