mirror of
https://github.com/RPCSX/llvm.git
synced 2024-11-29 06:30:39 +00:00
Use Doxygen-style comments.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@50833 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
parent
1fd2e6d84e
commit
4561ab5d81
@ -21,8 +21,11 @@ namespace llvmc {
|
|||||||
|
|
||||||
typedef std::vector<std::string> StringVector;
|
typedef std::vector<std::string> StringVector;
|
||||||
|
|
||||||
|
/// Action - A class that encapsulates a single shell command.
|
||||||
class Action {
|
class Action {
|
||||||
|
/// Command_ - The actual command (for example, 'ls').
|
||||||
std::string Command_;
|
std::string Command_;
|
||||||
|
/// Args_ - Command arguments. Stdout redirection is allowed.
|
||||||
std::vector<std::string> Args_;
|
std::vector<std::string> Args_;
|
||||||
public:
|
public:
|
||||||
Action (const std::string& C,
|
Action (const std::string& C,
|
||||||
@ -30,6 +33,7 @@ namespace llvmc {
|
|||||||
: Command_(C), Args_(A)
|
: Command_(C), Args_(A)
|
||||||
{}
|
{}
|
||||||
|
|
||||||
|
/// Execute - Executes the represented action.
|
||||||
int Execute() const;
|
int Execute() const;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -23,7 +23,11 @@ namespace llvmc {
|
|||||||
typedef llvm::StringMap<std::string> LanguageMap;
|
typedef llvm::StringMap<std::string> LanguageMap;
|
||||||
class CompilationGraph;
|
class CompilationGraph;
|
||||||
|
|
||||||
|
/// PopulateLanguageMap - The auto-generated function that fills in
|
||||||
|
/// the language map (map from file extensions to language names).
|
||||||
void PopulateLanguageMap(LanguageMap& language_map);
|
void PopulateLanguageMap(LanguageMap& language_map);
|
||||||
|
/// PopulateCompilationGraph - The auto-generated function that
|
||||||
|
/// populates the compilation graph with nodes and edges.
|
||||||
void PopulateCompilationGraph(CompilationGraph& tools);
|
void PopulateCompilationGraph(CompilationGraph& tools);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -33,7 +33,7 @@ extern cl::list<std::string> Languages;
|
|||||||
|
|
||||||
namespace {
|
namespace {
|
||||||
|
|
||||||
// Return the edge with the maximum weight.
|
/// ChooseEdge - Return the edge with the maximum weight.
|
||||||
template <class C>
|
template <class C>
|
||||||
const Edge* ChooseEdge(const C& EdgesContainer,
|
const Edge* ChooseEdge(const C& EdgesContainer,
|
||||||
const InputLanguagesSet& InLangs,
|
const InputLanguagesSet& InLangs,
|
||||||
@ -304,8 +304,6 @@ TopologicalSortFilterJoinNodes(std::vector<const Node*>& Out) {
|
|||||||
std::back_inserter(Out), NotJoinNode);
|
std::back_inserter(Out), NotJoinNode);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Build the targets. Command-line options are accessed through global
|
|
||||||
// variables.
|
|
||||||
int CompilationGraph::Build (const sys::Path& TempDir) {
|
int CompilationGraph::Build (const sys::Path& TempDir) {
|
||||||
|
|
||||||
InputLanguagesSet InLangs;
|
InputLanguagesSet InLangs;
|
||||||
|
@ -29,8 +29,9 @@
|
|||||||
|
|
||||||
namespace llvmc {
|
namespace llvmc {
|
||||||
|
|
||||||
// A wrapper for StringMap that provides set-like functionality.
|
/// StringSet - A wrapper for StringMap that provides set-like
|
||||||
// Only insert() and count() methods are used by my code.
|
/// functionality. Only insert() and count() methods are used by my
|
||||||
|
/// code.
|
||||||
template <class AllocatorTy = llvm::MallocAllocator>
|
template <class AllocatorTy = llvm::MallocAllocator>
|
||||||
class StringSet : public llvm::StringMap<char, AllocatorTy> {
|
class StringSet : public llvm::StringMap<char, AllocatorTy> {
|
||||||
typedef llvm::StringMap<char, AllocatorTy> base;
|
typedef llvm::StringMap<char, AllocatorTy> base;
|
||||||
@ -45,7 +46,7 @@ namespace llvmc {
|
|||||||
};
|
};
|
||||||
typedef StringSet<> InputLanguagesSet;
|
typedef StringSet<> InputLanguagesSet;
|
||||||
|
|
||||||
// An edge of the compilation graph.
|
/// Edge - Represents an edge of the compilation graph.
|
||||||
class Edge : public llvm::RefCountedBaseVPTR<Edge> {
|
class Edge : public llvm::RefCountedBaseVPTR<Edge> {
|
||||||
public:
|
public:
|
||||||
Edge(const std::string& T) : ToolName_(T) {}
|
Edge(const std::string& T) : ToolName_(T) {}
|
||||||
@ -57,14 +58,14 @@ namespace llvmc {
|
|||||||
std::string ToolName_;
|
std::string ToolName_;
|
||||||
};
|
};
|
||||||
|
|
||||||
// Edges that have no properties are instances of this class.
|
/// SimpleEdge - An edge that has no properties.
|
||||||
class SimpleEdge : public Edge {
|
class SimpleEdge : public Edge {
|
||||||
public:
|
public:
|
||||||
SimpleEdge(const std::string& T) : Edge(T) {}
|
SimpleEdge(const std::string& T) : Edge(T) {}
|
||||||
unsigned Weight(const InputLanguagesSet&) const { return 1; }
|
unsigned Weight(const InputLanguagesSet&) const { return 1; }
|
||||||
};
|
};
|
||||||
|
|
||||||
// A node of the compilation graph.
|
/// Node - A node (vertex) of the compilation graph.
|
||||||
struct Node {
|
struct Node {
|
||||||
// A Node holds a list of the outward edges.
|
// A Node holds a list of the outward edges.
|
||||||
typedef llvm::SmallVector<llvm::IntrusiveRefCntPtr<Edge>, 3> container_type;
|
typedef llvm::SmallVector<llvm::IntrusiveRefCntPtr<Edge>, 3> container_type;
|
||||||
@ -86,7 +87,8 @@ namespace llvmc {
|
|||||||
iterator EdgesEnd() { return OutEdges.end(); }
|
iterator EdgesEnd() { return OutEdges.end(); }
|
||||||
const_iterator EdgesEnd() const { return OutEdges.end(); }
|
const_iterator EdgesEnd() const { return OutEdges.end(); }
|
||||||
|
|
||||||
// Add an outward edge. Takes ownership of the Edge object.
|
/// AddEdge - Add an outward edge. Takes ownership of the provided
|
||||||
|
/// Edge object.
|
||||||
void AddEdge(Edge* E)
|
void AddEdge(Edge* E)
|
||||||
{ OutEdges.push_back(llvm::IntrusiveRefCntPtr<Edge>(E)); }
|
{ OutEdges.push_back(llvm::IntrusiveRefCntPtr<Edge>(E)); }
|
||||||
|
|
||||||
@ -111,56 +113,57 @@ namespace llvmc {
|
|||||||
|
|
||||||
class NodesIterator;
|
class NodesIterator;
|
||||||
|
|
||||||
// The compilation graph itself.
|
/// CompilationGraph - The compilation graph itself.
|
||||||
class CompilationGraph {
|
class CompilationGraph {
|
||||||
// Main data structure.
|
/// nodes_map_type - The main data structure.
|
||||||
typedef llvm::StringMap<Node> nodes_map_type;
|
typedef llvm::StringMap<Node> nodes_map_type;
|
||||||
// These are used to map from language names to tools. (We can
|
/// tools_vector_type, tools_map_type - Data structures used to
|
||||||
// have several tools associated with each language name, hence
|
/// map from language names to tools. (We can have several tools
|
||||||
// the need for a vector of Edges.)
|
/// associated with each language name, hence the need for a
|
||||||
|
/// vector.)
|
||||||
typedef
|
typedef
|
||||||
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;
|
||||||
|
|
||||||
// Map from file extensions to language names.
|
/// ExtsToLangs - Map from file extensions to language names.
|
||||||
LanguageMap ExtsToLangs;
|
LanguageMap ExtsToLangs;
|
||||||
// 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;
|
||||||
// Map from tool names to Tool objects.
|
/// NodesMap - Map from tool names to Tool objects.
|
||||||
nodes_map_type NodesMap;
|
nodes_map_type NodesMap;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
||||||
CompilationGraph();
|
CompilationGraph();
|
||||||
|
|
||||||
// insertVertex - insert a new node into the graph. Takes
|
/// insertNode - Insert a new node into the graph. Takes
|
||||||
// ownership of the object.
|
/// ownership of the object.
|
||||||
void insertNode(Tool* T);
|
void insertNode(Tool* T);
|
||||||
|
|
||||||
// insertEdge - Insert a new edge into the graph. Takes ownership
|
/// insertEdge - Insert a new edge into the graph. Takes ownership
|
||||||
// of the Edge object.
|
/// of the Edge object.
|
||||||
void insertEdge(const std::string& A, Edge* E);
|
void insertEdge(const std::string& A, Edge* E);
|
||||||
|
|
||||||
// Build - Build target(s) from the input file set. Command-line
|
/// Build - Build target(s) from the input file set. Command-line
|
||||||
// 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);
|
||||||
|
|
||||||
// Return a reference to the node correponding to the given tool
|
/// getNode -Return a reference to the node correponding to the
|
||||||
// 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;
|
||||||
|
|
||||||
// viewGraph - This function is meant for use from the debugger.
|
/// viewGraph - This function is meant for use from the debugger.
|
||||||
// You can just say 'call G->viewGraph()' and a ghostview window
|
/// You can just say 'call G->viewGraph()' and a ghostview window
|
||||||
// should pop up from the program, displaying the compilation
|
/// should pop up from the program, displaying the compilation
|
||||||
// graph. This depends on there being a 'dot' and 'gv' program
|
/// graph. This depends on there being a 'dot' and 'gv' program
|
||||||
// in your path.
|
/// in your path.
|
||||||
void viewGraph();
|
void viewGraph();
|
||||||
|
|
||||||
// Write a CompilationGraph.dot file.
|
/// writeGraph - Write a compilation-graph.dot file.
|
||||||
void writeGraph();
|
void writeGraph();
|
||||||
|
|
||||||
// GraphTraits support
|
// GraphTraits support.
|
||||||
friend NodesIterator GraphBegin(CompilationGraph*);
|
friend NodesIterator GraphBegin(CompilationGraph*);
|
||||||
friend NodesIterator GraphEnd(CompilationGraph*);
|
friend NodesIterator GraphEnd(CompilationGraph*);
|
||||||
friend void PopulateCompilationGraph(CompilationGraph&);
|
friend void PopulateCompilationGraph(CompilationGraph&);
|
||||||
@ -168,39 +171,42 @@ namespace llvmc {
|
|||||||
private:
|
private:
|
||||||
// Helper functions.
|
// Helper functions.
|
||||||
|
|
||||||
// Find out which language corresponds to the suffix of this file.
|
/// getLanguage - Find out which language corresponds to the
|
||||||
|
/// suffix of this file.
|
||||||
const std::string& getLanguage(const llvm::sys::Path& File) const;
|
const std::string& getLanguage(const llvm::sys::Path& File) const;
|
||||||
|
|
||||||
// Return a reference to the list of tool names corresponding to
|
/// getToolsVector - Return a reference to the list of tool names
|
||||||
// the given language name. Throws std::runtime_error.
|
/// corresponding to the given language name. Throws
|
||||||
|
/// std::runtime_error.
|
||||||
const tools_vector_type& getToolsVector(const std::string& LangName) const;
|
const tools_vector_type& getToolsVector(const std::string& LangName) const;
|
||||||
|
|
||||||
// Pass the input file through the toolchain starting at StartNode.
|
/// PassThroughGraph - Pass the input file through the toolchain
|
||||||
|
/// starting at StartNode.
|
||||||
void PassThroughGraph (const llvm::sys::Path& In, const Node* StartNode,
|
void PassThroughGraph (const llvm::sys::Path& In, const Node* StartNode,
|
||||||
const InputLanguagesSet& InLangs,
|
const InputLanguagesSet& InLangs,
|
||||||
const llvm::sys::Path& TempDir) const;
|
const llvm::sys::Path& TempDir) const;
|
||||||
|
|
||||||
// Find head of the toolchain corresponding to the given file.
|
/// FindToolChain - Find head of the toolchain corresponding to the given file.
|
||||||
const Node* FindToolChain(const llvm::sys::Path& In,
|
const Node* FindToolChain(const llvm::sys::Path& In,
|
||||||
const std::string* forceLanguage,
|
const std::string* forceLanguage,
|
||||||
InputLanguagesSet& InLangs) const;
|
InputLanguagesSet& InLangs) const;
|
||||||
|
|
||||||
// Traverse the initial parts of the toolchains.
|
/// BuildInitial - Traverse the initial parts of the toolchains.
|
||||||
void BuildInitial(InputLanguagesSet& InLangs,
|
void BuildInitial(InputLanguagesSet& InLangs,
|
||||||
const llvm::sys::Path& TempDir);
|
const llvm::sys::Path& TempDir);
|
||||||
|
|
||||||
// Sort the nodes in topological order.
|
/// TopologicalSort - Sort the nodes in topological order.
|
||||||
void TopologicalSort(std::vector<const Node*>& Out);
|
void TopologicalSort(std::vector<const Node*>& Out);
|
||||||
// Call TopologicalSort and filter the resulting list to include
|
/// TopologicalSortFilterJoinNodes - Call TopologicalSort and
|
||||||
// only Join nodes.
|
/// filter the resulting list to include only Join nodes.
|
||||||
void TopologicalSortFilterJoinNodes(std::vector<const Node*>& Out);
|
void TopologicalSortFilterJoinNodes(std::vector<const Node*>& Out);
|
||||||
};
|
};
|
||||||
|
|
||||||
/// GraphTraits support code.
|
// GraphTraits support code.
|
||||||
|
|
||||||
// Auxiliary class needed to implement GraphTraits support. Can be
|
/// NodesIterator - Auxiliary class needed to implement GraphTraits
|
||||||
// generalised to something like value_iterator for map-like
|
/// support. Can be generalised to something like value_iterator
|
||||||
// containers.
|
/// for map-like containers.
|
||||||
class NodesIterator : public llvm::StringMap<Node>::iterator {
|
class NodesIterator : public llvm::StringMap<Node>::iterator {
|
||||||
typedef llvm::StringMap<Node>::iterator super;
|
typedef llvm::StringMap<Node>::iterator super;
|
||||||
typedef NodesIterator ThisType;
|
typedef NodesIterator ThisType;
|
||||||
@ -227,7 +233,7 @@ namespace llvmc {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// Another auxiliary class needed by GraphTraits.
|
/// NodeChildIterator - Another auxiliary class needed by GraphTraits.
|
||||||
class NodeChildIterator : public bidirectional_iterator<Node, ptrdiff_t> {
|
class NodeChildIterator : public bidirectional_iterator<Node, ptrdiff_t> {
|
||||||
typedef NodeChildIterator ThisType;
|
typedef NodeChildIterator ThisType;
|
||||||
typedef Node::container_type::iterator iterator;
|
typedef Node::container_type::iterator iterator;
|
||||||
|
@ -26,6 +26,7 @@ namespace llvmc {
|
|||||||
|
|
||||||
typedef std::vector<llvm::sys::Path> PathVector;
|
typedef std::vector<llvm::sys::Path> PathVector;
|
||||||
|
|
||||||
|
/// Tool - A class
|
||||||
class Tool : public llvm::RefCountedBaseVPTR<Tool> {
|
class Tool : public llvm::RefCountedBaseVPTR<Tool> {
|
||||||
public:
|
public:
|
||||||
|
|
||||||
@ -46,7 +47,7 @@ namespace llvmc {
|
|||||||
virtual bool IsJoin() const = 0;
|
virtual bool IsJoin() const = 0;
|
||||||
};
|
};
|
||||||
|
|
||||||
// Join tools have an input file list associated with them.
|
/// JoinTool - A Tool that has an associated input file list.
|
||||||
class JoinTool : public Tool {
|
class JoinTool : public Tool {
|
||||||
public:
|
public:
|
||||||
void AddToJoinList(const llvm::sys::Path& P) { JoinList_.push_back(P); }
|
void AddToJoinList(const llvm::sys::Path& P) { JoinList_.push_back(P); }
|
||||||
|
@ -48,6 +48,7 @@ cl::opt<bool> ViewGraph("view-graph",
|
|||||||
cl::Hidden);
|
cl::Hidden);
|
||||||
|
|
||||||
namespace {
|
namespace {
|
||||||
|
/// BuildTargets - A small wrapper for CompilationGraph::Build.
|
||||||
int BuildTargets(CompilationGraph& graph) {
|
int BuildTargets(CompilationGraph& graph) {
|
||||||
int ret;
|
int ret;
|
||||||
sys::Path tempDir(sys::Path::GetTemporaryDirectory());
|
sys::Path tempDir(sys::Path::GetTemporaryDirectory());
|
||||||
|
@ -38,16 +38,16 @@ typedef std::vector<std::string> StrVector;
|
|||||||
//===----------------------------------------------------------------------===//
|
//===----------------------------------------------------------------------===//
|
||||||
/// Constants
|
/// Constants
|
||||||
|
|
||||||
// Indentation strings
|
// Indentation strings.
|
||||||
const char * Indent1 = " ";
|
const char * Indent1 = " ";
|
||||||
const char * Indent2 = " ";
|
const char * Indent2 = " ";
|
||||||
const char * Indent3 = " ";
|
const char * Indent3 = " ";
|
||||||
const char * Indent4 = " ";
|
const char * Indent4 = " ";
|
||||||
|
|
||||||
// Default help string
|
// Default help string.
|
||||||
const char * DefaultHelpString = "NO HELP MESSAGE PROVIDED";
|
const char * DefaultHelpString = "NO HELP MESSAGE PROVIDED";
|
||||||
|
|
||||||
// Name for the "sink" option
|
// Name for the "sink" option.
|
||||||
const char * SinkOptionName = "AutoGeneratedSinkOption";
|
const char * SinkOptionName = "AutoGeneratedSinkOption";
|
||||||
|
|
||||||
//===----------------------------------------------------------------------===//
|
//===----------------------------------------------------------------------===//
|
||||||
@ -69,8 +69,8 @@ const DagInit& InitPtrToDagInitRef(Init* ptr) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// Ensure that the number of args in d is <= min_arguments,
|
// checkNumberOfArguments - Ensure that the number of args in d is
|
||||||
// throw exception otherwise
|
// less than or equal to min_arguments, otherwise throw an exception .
|
||||||
void checkNumberOfArguments (const DagInit* d, unsigned min_arguments) {
|
void checkNumberOfArguments (const DagInit* d, unsigned min_arguments) {
|
||||||
if (d->getNumArgs() < min_arguments)
|
if (d->getNumArgs() < min_arguments)
|
||||||
throw "Property " + d->getOperator()->getAsString()
|
throw "Property " + d->getOperator()->getAsString()
|
||||||
@ -111,8 +111,7 @@ bool IsListOptionType (OptionType::OptionType t) {
|
|||||||
// the option registration code, while ToolOptionDescriptions are used
|
// the option registration code, while ToolOptionDescriptions are used
|
||||||
// to generate tool-specific code.
|
// to generate tool-specific code.
|
||||||
|
|
||||||
// Base class for option descriptions
|
/// OptionDescription - Base class for option descriptions.
|
||||||
|
|
||||||
struct OptionDescription {
|
struct OptionDescription {
|
||||||
OptionType::OptionType Type;
|
OptionType::OptionType Type;
|
||||||
std::string Name;
|
std::string Name;
|
||||||
@ -154,7 +153,7 @@ struct OptionDescription {
|
|||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
// Global option description
|
// Global option description.
|
||||||
|
|
||||||
namespace GlobalOptionDescriptionFlags {
|
namespace GlobalOptionDescriptionFlags {
|
||||||
enum GlobalOptionDescriptionFlags { Required = 0x1 };
|
enum GlobalOptionDescriptionFlags { Required = 0x1 };
|
||||||
@ -180,7 +179,7 @@ struct GlobalOptionDescription : public OptionDescription {
|
|||||||
Flags |= GlobalOptionDescriptionFlags::Required;
|
Flags |= GlobalOptionDescriptionFlags::Required;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Merge two option descriptions
|
/// Merge - Merge two option descriptions.
|
||||||
void Merge (const GlobalOptionDescription& other)
|
void Merge (const GlobalOptionDescription& other)
|
||||||
{
|
{
|
||||||
if (other.Type != Type)
|
if (other.Type != Type)
|
||||||
@ -197,15 +196,16 @@ struct GlobalOptionDescription : public OptionDescription {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
// A GlobalOptionDescription array
|
/// GlobalOptionDescriptions - A GlobalOptionDescription array
|
||||||
// + some flags affecting generation of option declarations
|
/// together with some flags affecting generation of option
|
||||||
|
/// declarations.
|
||||||
struct GlobalOptionDescriptions {
|
struct GlobalOptionDescriptions {
|
||||||
typedef StringMap<GlobalOptionDescription> container_type;
|
typedef StringMap<GlobalOptionDescription> container_type;
|
||||||
typedef container_type::const_iterator const_iterator;
|
typedef container_type::const_iterator const_iterator;
|
||||||
|
|
||||||
// A list of GlobalOptionDescriptions
|
/// Descriptions - A list of GlobalOptionDescriptions.
|
||||||
container_type Descriptions;
|
container_type Descriptions;
|
||||||
// Should the emitter generate a "cl::sink" option?
|
/// HasSink - Should the emitter generate a "cl::sink" option?
|
||||||
bool HasSink;
|
bool HasSink;
|
||||||
|
|
||||||
const GlobalOptionDescription& FindOption(const std::string& OptName) const {
|
const GlobalOptionDescription& FindOption(const std::string& OptName) const {
|
||||||
@ -307,31 +307,34 @@ struct ToolProperties : public RefCountedBase<ToolProperties> {
|
|||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
// A list of Tool information records
|
/// ToolPropertiesList - A list of Tool information records
|
||||||
// IntrusiveRefCntPtrs are used because StringMap has no copy constructor
|
/// IntrusiveRefCntPtrs are used here because StringMap has no copy
|
||||||
// (and we want to avoid copying ToolProperties anyway)
|
/// constructor (and we want to avoid copying ToolProperties anyway).
|
||||||
typedef std::vector<IntrusiveRefCntPtr<ToolProperties> > ToolPropertiesList;
|
typedef std::vector<IntrusiveRefCntPtr<ToolProperties> > ToolPropertiesList;
|
||||||
|
|
||||||
|
|
||||||
// Function object for iterating over a list of tool property records
|
/// CollectProperties - Function object for iterating over a list of
|
||||||
|
/// tool property records
|
||||||
class CollectProperties {
|
class CollectProperties {
|
||||||
private:
|
private:
|
||||||
|
|
||||||
/// Implementation details
|
/// Implementation details
|
||||||
|
|
||||||
// "Property handler" - a function that extracts information
|
/// PropertyHandler - a function that extracts information
|
||||||
// about a given tool property from its DAG representation
|
/// about a given tool property from its DAG representation
|
||||||
typedef void (CollectProperties::*PropertyHandler)(const DagInit*);
|
typedef void (CollectProperties::*PropertyHandler)(const DagInit*);
|
||||||
|
|
||||||
// Map from property names -> property handlers
|
/// PropertyHandlerMap - A map from property names to property
|
||||||
|
/// handlers.
|
||||||
typedef StringMap<PropertyHandler> PropertyHandlerMap;
|
typedef StringMap<PropertyHandler> PropertyHandlerMap;
|
||||||
|
|
||||||
// "Option property handler" - a function that extracts information
|
/// OptionPropertyHandler - a function that extracts information
|
||||||
// about a given option property from its DAG representation
|
/// about a given option property from its DAG representation.
|
||||||
typedef void (CollectProperties::* OptionPropertyHandler)
|
typedef void (CollectProperties::* OptionPropertyHandler)
|
||||||
(const DagInit*, GlobalOptionDescription &);
|
(const DagInit*, GlobalOptionDescription &);
|
||||||
|
|
||||||
// Map from option property names -> option property handlers
|
/// OptionPropertyHandlerMap - A map from option property names to
|
||||||
|
/// option property handlers
|
||||||
typedef StringMap<OptionPropertyHandler> OptionPropertyHandlerMap;
|
typedef StringMap<OptionPropertyHandler> OptionPropertyHandlerMap;
|
||||||
|
|
||||||
// Static maps from strings to CollectProperties methods("handlers")
|
// Static maps from strings to CollectProperties methods("handlers")
|
||||||
@ -342,9 +345,10 @@ private:
|
|||||||
|
|
||||||
/// This is where the information is stored
|
/// This is where the information is stored
|
||||||
|
|
||||||
// Current Tool properties
|
/// toolProps_ - Properties of the current Tool.
|
||||||
ToolProperties& toolProps_;
|
ToolProperties& toolProps_;
|
||||||
// OptionDescriptions table(used to register options globally)
|
/// optDescs_ - OptionDescriptions table (used to register options
|
||||||
|
/// globally).
|
||||||
GlobalOptionDescriptions& optDescs_;
|
GlobalOptionDescriptions& optDescs_;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
@ -383,8 +387,8 @@ public:
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Gets called for every tool property;
|
/// operator() - Gets called for every tool property; Just forwards
|
||||||
// Just forwards to the corresponding property handler.
|
/// to the corresponding property handler.
|
||||||
void operator() (Init* i) {
|
void operator() (Init* i) {
|
||||||
const DagInit& d = InitPtrToDagInitRef(i);
|
const DagInit& d = InitPtrToDagInitRef(i);
|
||||||
const std::string& property_name = d.getOperator()->getAsString();
|
const std::string& property_name = d.getOperator()->getAsString();
|
||||||
@ -525,12 +529,12 @@ private:
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Go through the list of option properties and call a corresponding
|
/// processOptionProperties - Go through the list of option
|
||||||
// handler for each.
|
/// properties and call a corresponding handler for each.
|
||||||
//
|
///
|
||||||
// Parameters:
|
/// Parameters:
|
||||||
// name - option name
|
/// name - option name
|
||||||
// d - option property list
|
/// d - option property list
|
||||||
void processOptionProperties (const DagInit* d, GlobalOptionDescription& o) {
|
void processOptionProperties (const DagInit* d, GlobalOptionDescription& o) {
|
||||||
// First argument is option name
|
// First argument is option name
|
||||||
checkNumberOfArguments(d, 2);
|
checkNumberOfArguments(d, 2);
|
||||||
@ -564,8 +568,8 @@ CollectProperties::optionPropertyHandlers_;
|
|||||||
bool CollectProperties::staticMembersInitialized_ = false;
|
bool CollectProperties::staticMembersInitialized_ = false;
|
||||||
|
|
||||||
|
|
||||||
// Gather information from the parsed TableGen data
|
/// CollectToolProperties - Gather information from the parsed
|
||||||
// (Basically a wrapper for CollectProperties)
|
/// TableGen data (basically a wrapper for CollectProperties).
|
||||||
void CollectToolProperties (RecordVector::const_iterator B,
|
void CollectToolProperties (RecordVector::const_iterator B,
|
||||||
RecordVector::const_iterator E,
|
RecordVector::const_iterator E,
|
||||||
ToolPropertiesList& TPList,
|
ToolPropertiesList& TPList,
|
||||||
@ -585,7 +589,7 @@ void CollectToolProperties (RecordVector::const_iterator B,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Used by EmitGenerateActionMethod
|
/// EmitOptionPropertyHandlingCode - Used by EmitGenerateActionMethod.
|
||||||
void EmitOptionPropertyHandlingCode (const ToolProperties& P,
|
void EmitOptionPropertyHandlingCode (const ToolProperties& P,
|
||||||
const ToolOptionDescription& D,
|
const ToolOptionDescription& D,
|
||||||
std::ostream& O)
|
std::ostream& O)
|
||||||
@ -673,7 +677,8 @@ void EmitOptionPropertyHandlingCode (const ToolProperties& P,
|
|||||||
O << Indent2 << "}\n";
|
O << Indent2 << "}\n";
|
||||||
}
|
}
|
||||||
|
|
||||||
// Emite one of two versions of GenerateAction method
|
// EmitGenerateActionMethod - Emit one of two versions of
|
||||||
|
// GenerateAction method.
|
||||||
void EmitGenerateActionMethod (const ToolProperties& P, int V, std::ostream& O)
|
void EmitGenerateActionMethod (const ToolProperties& P, int V, std::ostream& O)
|
||||||
{
|
{
|
||||||
assert(V==1 || V==2);
|
assert(V==1 || V==2);
|
||||||
@ -731,7 +736,8 @@ void EmitGenerateActionMethod (const ToolProperties& P, int V, std::ostream& O)
|
|||||||
<< Indent1 << "}\n\n";
|
<< Indent1 << "}\n\n";
|
||||||
}
|
}
|
||||||
|
|
||||||
// Emit GenerateAction methods for Tool classes
|
/// EmitGenerateActionMethods - Emit two GenerateAction methods for a given
|
||||||
|
/// Tool class.
|
||||||
void EmitGenerateActionMethods (const ToolProperties& P, std::ostream& O) {
|
void EmitGenerateActionMethods (const ToolProperties& P, std::ostream& O) {
|
||||||
|
|
||||||
if (!P.isJoin())
|
if (!P.isJoin())
|
||||||
@ -747,7 +753,7 @@ void EmitGenerateActionMethods (const ToolProperties& P, std::ostream& O) {
|
|||||||
EmitGenerateActionMethod(P, 2, O);
|
EmitGenerateActionMethod(P, 2, O);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Emit IsLast() method for Tool classes
|
/// EmitIsLastMethod - Emit IsLast() method for a given Tool class
|
||||||
void EmitIsLastMethod (const ToolProperties& P, std::ostream& O) {
|
void EmitIsLastMethod (const ToolProperties& P, std::ostream& O) {
|
||||||
O << Indent1 << "bool IsLast() const {\n"
|
O << Indent1 << "bool IsLast() const {\n"
|
||||||
<< Indent2 << "bool last = false;\n";
|
<< Indent2 << "bool last = false;\n";
|
||||||
@ -766,7 +772,8 @@ void EmitIsLastMethod (const ToolProperties& P, std::ostream& O) {
|
|||||||
<< Indent1 << "}\n\n";
|
<< Indent1 << "}\n\n";
|
||||||
}
|
}
|
||||||
|
|
||||||
// Emit static [Input,Output]Language() methods for Tool classes
|
/// EmitInOutLanguageMethods - Emit the [Input,Output]Language()
|
||||||
|
/// methods for a given Tool class.
|
||||||
void EmitInOutLanguageMethods (const ToolProperties& P, std::ostream& O) {
|
void EmitInOutLanguageMethods (const ToolProperties& P, std::ostream& O) {
|
||||||
O << Indent1 << "const char* InputLanguage() const {\n"
|
O << Indent1 << "const char* InputLanguage() const {\n"
|
||||||
<< Indent2 << "return \"" << P.InLanguage << "\";\n"
|
<< Indent2 << "return \"" << P.InLanguage << "\";\n"
|
||||||
@ -777,21 +784,23 @@ void EmitInOutLanguageMethods (const ToolProperties& P, std::ostream& O) {
|
|||||||
<< Indent1 << "}\n\n";
|
<< Indent1 << "}\n\n";
|
||||||
}
|
}
|
||||||
|
|
||||||
// Emit static [Input,Output]Language() methods for Tool classes
|
/// EmitOutputSuffixMethod - Emit the OutputSuffix() method for a
|
||||||
|
/// given Tool class.
|
||||||
void EmitOutputSuffixMethod (const ToolProperties& P, std::ostream& O) {
|
void EmitOutputSuffixMethod (const ToolProperties& P, std::ostream& O) {
|
||||||
O << Indent1 << "const char* OutputSuffix() const {\n"
|
O << Indent1 << "const char* OutputSuffix() const {\n"
|
||||||
<< Indent2 << "return \"" << P.OutputSuffix << "\";\n"
|
<< Indent2 << "return \"" << P.OutputSuffix << "\";\n"
|
||||||
<< Indent1 << "}\n\n";
|
<< Indent1 << "}\n\n";
|
||||||
}
|
}
|
||||||
|
|
||||||
// Emit static Name() method for Tool classes
|
/// EmitNameMethod - Emit the Name() method for a given Tool class.
|
||||||
void EmitNameMethod (const ToolProperties& P, std::ostream& O) {
|
void EmitNameMethod (const ToolProperties& P, std::ostream& O) {
|
||||||
O << Indent1 << "const char* Name() const {\n"
|
O << Indent1 << "const char* Name() const {\n"
|
||||||
<< Indent2 << "return \"" << P.Name << "\";\n"
|
<< Indent2 << "return \"" << P.Name << "\";\n"
|
||||||
<< Indent1 << "}\n\n";
|
<< Indent1 << "}\n\n";
|
||||||
}
|
}
|
||||||
|
|
||||||
// Emit static Name() method for Tool classes
|
/// EmitIsJoinMethod - Emit the IsJoin() method for a given Tool
|
||||||
|
/// class.
|
||||||
void EmitIsJoinMethod (const ToolProperties& P, std::ostream& O) {
|
void EmitIsJoinMethod (const ToolProperties& P, std::ostream& O) {
|
||||||
O << Indent1 << "bool IsJoin() const {\n";
|
O << Indent1 << "bool IsJoin() const {\n";
|
||||||
if (P.isJoin())
|
if (P.isJoin())
|
||||||
@ -801,7 +810,7 @@ void EmitIsJoinMethod (const ToolProperties& P, std::ostream& O) {
|
|||||||
O << Indent1 << "}\n\n";
|
O << Indent1 << "}\n\n";
|
||||||
}
|
}
|
||||||
|
|
||||||
// Emit a Tool class definition
|
/// EmitToolClassDefinition - Emit a Tool class definition.
|
||||||
void EmitToolClassDefinition (const ToolProperties& P, std::ostream& O) {
|
void EmitToolClassDefinition (const ToolProperties& P, std::ostream& O) {
|
||||||
|
|
||||||
if(P.Name == "root")
|
if(P.Name == "root")
|
||||||
@ -826,7 +835,8 @@ void EmitToolClassDefinition (const ToolProperties& P, std::ostream& O) {
|
|||||||
O << "};\n\n";
|
O << "};\n\n";
|
||||||
}
|
}
|
||||||
|
|
||||||
// Iterate over a list of option descriptions and emit registration code
|
/// EmitOptionDescriptions - Iterate over a list of option
|
||||||
|
/// descriptions and emit registration code.
|
||||||
void EmitOptionDescriptions (const GlobalOptionDescriptions& descs,
|
void EmitOptionDescriptions (const GlobalOptionDescriptions& descs,
|
||||||
std::ostream& O)
|
std::ostream& O)
|
||||||
{
|
{
|
||||||
@ -862,6 +872,7 @@ void EmitOptionDescriptions (const GlobalOptionDescriptions& descs,
|
|||||||
O << '\n';
|
O << '\n';
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// EmitPopulateLanguageMap - Emit the PopulateLanguageMap() function.
|
||||||
void EmitPopulateLanguageMap (const RecordKeeper& Records, std::ostream& O)
|
void EmitPopulateLanguageMap (const RecordKeeper& Records, std::ostream& O)
|
||||||
{
|
{
|
||||||
// Get the relevant field out of RecordKeeper
|
// Get the relevant field out of RecordKeeper
|
||||||
@ -891,8 +902,8 @@ void EmitPopulateLanguageMap (const RecordKeeper& Records, std::ostream& O)
|
|||||||
O << "}\n\n";
|
O << "}\n\n";
|
||||||
}
|
}
|
||||||
|
|
||||||
// Fills in two tables that map tool names to (input, output) languages.
|
/// FillInToolToLang - Fills in two tables that map tool names to
|
||||||
// Used by the typechecker.
|
/// (input, output) languages. Used by the typechecker.
|
||||||
void FillInToolToLang (const ToolPropertiesList& TPList,
|
void FillInToolToLang (const ToolPropertiesList& TPList,
|
||||||
StringMap<std::string>& ToolToInLang,
|
StringMap<std::string>& ToolToInLang,
|
||||||
StringMap<std::string>& ToolToOutLang) {
|
StringMap<std::string>& ToolToOutLang) {
|
||||||
@ -904,7 +915,8 @@ void FillInToolToLang (const ToolPropertiesList& TPList,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Check that all output and input language names match.
|
/// TypecheckGraph - Check that names for output and input languages
|
||||||
|
/// on all edges do match.
|
||||||
// TOFIX: check for cycles.
|
// TOFIX: check for cycles.
|
||||||
// TOFIX: check for multiple default edges.
|
// TOFIX: check for multiple default edges.
|
||||||
void TypecheckGraph (Record* CompilationGraph,
|
void TypecheckGraph (Record* CompilationGraph,
|
||||||
@ -935,7 +947,8 @@ void TypecheckGraph (Record* CompilationGraph,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Helper function used by EmitEdgePropertyTest.
|
/// EmitEdgePropertyTest1Arg - Helper function used by
|
||||||
|
/// EmitEdgePropertyTest.
|
||||||
bool EmitEdgePropertyTest1Arg(const std::string& PropName,
|
bool EmitEdgePropertyTest1Arg(const std::string& PropName,
|
||||||
const DagInit& Prop,
|
const DagInit& Prop,
|
||||||
const GlobalOptionDescriptions& OptDescs,
|
const GlobalOptionDescriptions& OptDescs,
|
||||||
@ -956,7 +969,8 @@ bool EmitEdgePropertyTest1Arg(const std::string& PropName,
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Helper function used by EmitEdgePropertyTest.
|
/// EmitEdgePropertyTest2Args - Helper function used by
|
||||||
|
/// EmitEdgePropertyTest.
|
||||||
bool EmitEdgePropertyTest2Args(const std::string& PropName,
|
bool EmitEdgePropertyTest2Args(const std::string& PropName,
|
||||||
const DagInit& Prop,
|
const DagInit& Prop,
|
||||||
const GlobalOptionDescriptions& OptDescs,
|
const GlobalOptionDescriptions& OptDescs,
|
||||||
@ -992,7 +1006,8 @@ void EmitEdgePropertyTest(const DagInit& Prop,
|
|||||||
const GlobalOptionDescriptions& OptDescs,
|
const GlobalOptionDescriptions& OptDescs,
|
||||||
std::ostream& O);
|
std::ostream& O);
|
||||||
|
|
||||||
// Helper function used by EmitEdgeClass.
|
/// EmitLogicalOperationTest - Helper function used by
|
||||||
|
/// EmitEdgePropertyTest.
|
||||||
void EmitLogicalOperationTest(const DagInit& Prop, const char* LogicOp,
|
void EmitLogicalOperationTest(const DagInit& Prop, const char* LogicOp,
|
||||||
const GlobalOptionDescriptions& OptDescs,
|
const GlobalOptionDescriptions& OptDescs,
|
||||||
std::ostream& O) {
|
std::ostream& O) {
|
||||||
@ -1007,7 +1022,7 @@ void EmitLogicalOperationTest(const DagInit& Prop, const char* LogicOp,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Helper function used by EmitEdgeClass.
|
/// EmitEdgePropertyTest - Helper function used by EmitEdgeClass.
|
||||||
void EmitEdgePropertyTest(const DagInit& Prop,
|
void EmitEdgePropertyTest(const DagInit& Prop,
|
||||||
const GlobalOptionDescriptions& OptDescs,
|
const GlobalOptionDescriptions& OptDescs,
|
||||||
std::ostream& O) {
|
std::ostream& O) {
|
||||||
@ -1025,7 +1040,7 @@ void EmitEdgePropertyTest(const DagInit& Prop,
|
|||||||
throw PropName + ": unknown edge property!";
|
throw PropName + ": unknown edge property!";
|
||||||
}
|
}
|
||||||
|
|
||||||
// Emit a single Edge* class.
|
/// EmitEdgeClass - Emit a single Edge# class.
|
||||||
void EmitEdgeClass(unsigned N, const std::string& Target,
|
void EmitEdgeClass(unsigned N, const std::string& Target,
|
||||||
ListInit* Props, const GlobalOptionDescriptions& OptDescs,
|
ListInit* Props, const GlobalOptionDescriptions& OptDescs,
|
||||||
std::ostream& O) {
|
std::ostream& O) {
|
||||||
@ -1083,6 +1098,8 @@ void EmitEdgeClasses (Record* CompilationGraph,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// EmitPopulateCompilationGraph - Emit the PopulateCompilationGraph()
|
||||||
|
/// function.
|
||||||
void EmitPopulateCompilationGraph (Record* CompilationGraph,
|
void EmitPopulateCompilationGraph (Record* CompilationGraph,
|
||||||
std::ostream& O)
|
std::ostream& O)
|
||||||
{
|
{
|
||||||
@ -1131,29 +1148,30 @@ void EmitPopulateCompilationGraph (Record* CompilationGraph,
|
|||||||
// End of anonymous namespace
|
// End of anonymous namespace
|
||||||
}
|
}
|
||||||
|
|
||||||
// Back-end entry point
|
/// run - The back-end entry point.
|
||||||
void LLVMCConfigurationEmitter::run (std::ostream &O) {
|
void LLVMCConfigurationEmitter::run (std::ostream &O) {
|
||||||
// Emit file header
|
|
||||||
|
// Emit file header.
|
||||||
EmitSourceFileHeader("LLVMC Configuration Library", O);
|
EmitSourceFileHeader("LLVMC Configuration Library", O);
|
||||||
|
|
||||||
// Get a list of all defined Tools
|
// Get a list of all defined Tools.
|
||||||
RecordVector Tools = Records.getAllDerivedDefinitions("Tool");
|
RecordVector Tools = Records.getAllDerivedDefinitions("Tool");
|
||||||
if (Tools.empty())
|
if (Tools.empty())
|
||||||
throw std::string("No tool definitions found!");
|
throw std::string("No tool definitions found!");
|
||||||
|
|
||||||
// Gather information from the Tool descriptions
|
// Gather information from the Tool description dags.
|
||||||
ToolPropertiesList tool_props;
|
ToolPropertiesList tool_props;
|
||||||
GlobalOptionDescriptions opt_descs;
|
GlobalOptionDescriptions opt_descs;
|
||||||
CollectToolProperties(Tools.begin(), Tools.end(), tool_props, opt_descs);
|
CollectToolProperties(Tools.begin(), Tools.end(), tool_props, opt_descs);
|
||||||
|
|
||||||
// Emit global option registration code
|
// Emit global option registration code.
|
||||||
EmitOptionDescriptions(opt_descs, O);
|
EmitOptionDescriptions(opt_descs, O);
|
||||||
|
|
||||||
// Emit PopulateLanguageMap function
|
// Emit PopulateLanguageMap() function
|
||||||
// (a language map maps from file extensions to language names)
|
// (a language map maps from file extensions to language names).
|
||||||
EmitPopulateLanguageMap(Records, O);
|
EmitPopulateLanguageMap(Records, O);
|
||||||
|
|
||||||
// Emit Tool classes
|
// Emit Tool classes.
|
||||||
for (ToolPropertiesList::const_iterator B = tool_props.begin(),
|
for (ToolPropertiesList::const_iterator B = tool_props.begin(),
|
||||||
E = tool_props.end(); B!=E; ++B)
|
E = tool_props.end(); B!=E; ++B)
|
||||||
EmitToolClassDefinition(*(*B), O);
|
EmitToolClassDefinition(*(*B), O);
|
||||||
@ -1165,10 +1183,10 @@ void LLVMCConfigurationEmitter::run (std::ostream &O) {
|
|||||||
// Typecheck the compilation graph.
|
// Typecheck the compilation graph.
|
||||||
TypecheckGraph(CompilationGraphRecord, tool_props);
|
TypecheckGraph(CompilationGraphRecord, tool_props);
|
||||||
|
|
||||||
// Emit Edge* classes.
|
// Emit Edge# classes.
|
||||||
EmitEdgeClasses(CompilationGraphRecord, opt_descs, O);
|
EmitEdgeClasses(CompilationGraphRecord, opt_descs, O);
|
||||||
|
|
||||||
// Emit PopulateCompilationGraph function
|
// Emit PopulateCompilationGraph() function.
|
||||||
EmitPopulateCompilationGraph(CompilationGraphRecord, O);
|
EmitPopulateCompilationGraph(CompilationGraphRecord, O);
|
||||||
|
|
||||||
// EOF
|
// EOF
|
||||||
|
@ -17,6 +17,9 @@
|
|||||||
#include "TableGenBackend.h"
|
#include "TableGenBackend.h"
|
||||||
|
|
||||||
namespace llvm {
|
namespace llvm {
|
||||||
|
|
||||||
|
/// LLVMCConfigurationEmitter - TableGen backend that generates
|
||||||
|
/// configuration code for LLVMC.
|
||||||
class LLVMCConfigurationEmitter : public TableGenBackend {
|
class LLVMCConfigurationEmitter : public TableGenBackend {
|
||||||
RecordKeeper &Records;
|
RecordKeeper &Records;
|
||||||
public:
|
public:
|
||||||
|
Loading…
Reference in New Issue
Block a user