mirror of
https://github.com/c64scene-ar/llvm-6502.git
synced 2024-10-21 01:25:20 +00:00
Add an ability to choose between different edges based on edge properties.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@50732 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
parent
9ef501b120
commit
6591c8938c
@ -25,6 +25,31 @@ using namespace llvmcc;
|
|||||||
extern cl::list<std::string> InputFilenames;
|
extern cl::list<std::string> InputFilenames;
|
||||||
extern cl::opt<std::string> OutputFilename;
|
extern cl::opt<std::string> OutputFilename;
|
||||||
|
|
||||||
|
// Choose one of the edges based on command-line options.
|
||||||
|
const Edge* Node::ChooseEdge() const {
|
||||||
|
const Edge* DefaultEdge = 0;
|
||||||
|
for (const_iterator B = EdgesBegin(), E = EdgesEnd();
|
||||||
|
B != E; ++B) {
|
||||||
|
const Edge* E = (*B).getPtr();
|
||||||
|
if (E->isDefault())
|
||||||
|
if (!DefaultEdge)
|
||||||
|
DefaultEdge = E;
|
||||||
|
else
|
||||||
|
throw std::runtime_error("Node " + Name() +
|
||||||
|
": multiple default edges found!"
|
||||||
|
"Most probably a specification error.");
|
||||||
|
if (E->isEnabled())
|
||||||
|
return E;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (DefaultEdge)
|
||||||
|
return DefaultEdge;
|
||||||
|
else
|
||||||
|
throw std::runtime_error("Node " + Name() +
|
||||||
|
": no suitable edge found! "
|
||||||
|
"Most probably a specification error.");
|
||||||
|
}
|
||||||
|
|
||||||
CompilationGraph::CompilationGraph() {
|
CompilationGraph::CompilationGraph() {
|
||||||
NodesMap["root"] = Node(this);
|
NodesMap["root"] = Node(this);
|
||||||
}
|
}
|
||||||
@ -84,8 +109,8 @@ void CompilationGraph::insertEdge(const std::string& A, Edge* E) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// TOFIX: support edge properties.
|
// TOFIX: support more interesting graph topologies. We will need to
|
||||||
// TOFIX: support more interesting graph topologies.
|
// do topological sorting to process multiple Join nodes correctly.
|
||||||
int CompilationGraph::Build (const sys::Path& tempDir) const {
|
int CompilationGraph::Build (const sys::Path& tempDir) const {
|
||||||
PathVector JoinList;
|
PathVector JoinList;
|
||||||
const Tool* JoinTool = 0;
|
const Tool* JoinTool = 0;
|
||||||
@ -102,7 +127,7 @@ int CompilationGraph::Build (const sys::Path& tempDir) const {
|
|||||||
throw std::runtime_error("Tool names vector is empty!");
|
throw std::runtime_error("Tool names vector is empty!");
|
||||||
const Node* N = &getNode(*TV.begin());
|
const Node* N = &getNode(*TV.begin());
|
||||||
|
|
||||||
// Pass it through the chain until we bump into a Join node or a
|
// Pass file through the chain until we bump into a Join node or a
|
||||||
// node that says that it is the last.
|
// node that says that it is the last.
|
||||||
bool Last = false;
|
bool Last = false;
|
||||||
while(!Last) {
|
while(!Last) {
|
||||||
@ -135,7 +160,7 @@ int CompilationGraph::Build (const sys::Path& tempDir) const {
|
|||||||
if (CurTool->GenerateAction(In, Out).Execute() != 0)
|
if (CurTool->GenerateAction(In, Out).Execute() != 0)
|
||||||
throw std::runtime_error("Tool returned error code!");
|
throw std::runtime_error("Tool returned error code!");
|
||||||
|
|
||||||
N = &getNode((*N->EdgesBegin())->ToolName());
|
N = &getNode(N->ChooseEdge()->ToolName());
|
||||||
In = Out; Out.clear();
|
In = Out; Out.clear();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -166,7 +191,7 @@ namespace llvm {
|
|||||||
template<typename GraphType>
|
template<typename GraphType>
|
||||||
static std::string getNodeLabel(const Node* N, const GraphType&) {
|
static std::string getNodeLabel(const Node* N, const GraphType&) {
|
||||||
if (N->ToolPtr)
|
if (N->ToolPtr)
|
||||||
return N->ToolPtr->Name();
|
return N->Name();
|
||||||
else
|
else
|
||||||
return "root";
|
return "root";
|
||||||
}
|
}
|
||||||
|
@ -45,7 +45,7 @@ namespace llvmcc {
|
|||||||
class SimpleEdge : public Edge {
|
class SimpleEdge : public Edge {
|
||||||
public:
|
public:
|
||||||
SimpleEdge(const std::string& T) : Edge(T) {}
|
SimpleEdge(const std::string& T) : Edge(T) {}
|
||||||
bool isEnabled() const { return true;}
|
bool isEnabled() const { return false;}
|
||||||
bool isDefault() const { return true;}
|
bool isDefault() const { return true;}
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -60,12 +60,16 @@ namespace llvmcc {
|
|||||||
Node(CompilationGraph* G, Tool* T) : OwningGraph(G), ToolPtr(T) {}
|
Node(CompilationGraph* G, Tool* T) : OwningGraph(G), ToolPtr(T) {}
|
||||||
|
|
||||||
bool HasChildren() const { return !OutEdges.empty(); }
|
bool HasChildren() const { return !OutEdges.empty(); }
|
||||||
|
const std::string Name() const { return ToolPtr->Name(); }
|
||||||
|
|
||||||
iterator EdgesBegin() { return OutEdges.begin(); }
|
iterator EdgesBegin() { return OutEdges.begin(); }
|
||||||
const_iterator EdgesBegin() const { return OutEdges.begin(); }
|
const_iterator EdgesBegin() const { return OutEdges.begin(); }
|
||||||
iterator EdgesEnd() { return OutEdges.end(); }
|
iterator EdgesEnd() { return OutEdges.end(); }
|
||||||
const_iterator EdgesEnd() const { return OutEdges.end(); }
|
const_iterator EdgesEnd() const { return OutEdges.end(); }
|
||||||
|
|
||||||
|
// Choose one of the edges based on command-line options.
|
||||||
|
const Edge* ChooseEdge() const;
|
||||||
|
|
||||||
// Takes ownership of the object.
|
// Takes ownership of the object.
|
||||||
void AddEdge(Edge* E)
|
void AddEdge(Edge* E)
|
||||||
{ OutEdges.push_back(llvm::IntrusiveRefCntPtr<Edge>(E)); }
|
{ OutEdges.push_back(llvm::IntrusiveRefCntPtr<Edge>(E)); }
|
||||||
|
@ -26,11 +26,10 @@ def CompilationGraph : CompilationGraph<[
|
|||||||
Edge<llvm_gcc_cpp, llc>,
|
Edge<llvm_gcc_cpp, llc>,
|
||||||
Edge<llvm_as, llc>,
|
Edge<llvm_as, llc>,
|
||||||
|
|
||||||
OptionalEdge<llvm_gcc_c, opt, [(switch_on "S")]>,
|
OptionalEdge<llvm_gcc_c, opt, [(switch_on "opt")]>,
|
||||||
OptionalEdge<llvm_gcc_cpp, opt, [(switch_on "S")]>,
|
OptionalEdge<llvm_gcc_cpp, opt, [(switch_on "opt")]>,
|
||||||
OptionalEdge<llvm_as, opt, [(switch_on "S")]>,
|
OptionalEdge<llvm_as, opt, [(switch_on "opt")]>,
|
||||||
OptionalEdge<opt, llc, [(and (switch_on "S"), (parameter_equals "O", "V")),
|
Edge<opt, llc>,
|
||||||
(element_in_list "P", "E")]>,
|
|
||||||
|
|
||||||
Edge<llc, llvm_gcc_assembler>,
|
Edge<llc, llvm_gcc_assembler>,
|
||||||
Edge<llvm_gcc_assembler, llvm_gcc_linker>
|
Edge<llvm_gcc_assembler, llvm_gcc_linker>
|
||||||
|
@ -38,9 +38,9 @@ def llvm_gcc_cpp : Tool<
|
|||||||
def opt : Tool<
|
def opt : Tool<
|
||||||
[(in_language "llvm-bitcode"),
|
[(in_language "llvm-bitcode"),
|
||||||
(out_language "llvm-bitcode"),
|
(out_language "llvm-bitcode"),
|
||||||
(switch_option "S", (help "Test switch")),
|
(switch_option "opt", (help "Enable opt")),
|
||||||
(parameter_option "O", (help "Test Parameter")),
|
//(parameter_option "O", (help "Test Parameter")),
|
||||||
(prefix_list_option "P", (help "Test Parameter List")),
|
//(prefix_list_option "P", (help "Test Parameter List")),
|
||||||
(output_suffix "bc"),
|
(output_suffix "bc"),
|
||||||
(cmd_line "opt $INFILE -o $OUTFILE")
|
(cmd_line "opt $INFILE -o $OUTFILE")
|
||||||
]>;
|
]>;
|
||||||
|
Loading…
Reference in New Issue
Block a user