forked from llvm-mirror/llvm
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Move TableGen's parser and entry point into a library
This is the first step towards splitting LLVM and Clang's tblgen executables. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@140951 91177308-0d34-0410-b5e6-96231b3b80d8
- Loading branch information
Showing
77 changed files
with
369 additions
and
241 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
//===- llvm/TableGen/Main.h - tblgen entry point ----------------*- C++ -*-===// | ||
// | ||
// The LLVM Compiler Infrastructure | ||
// | ||
// This file is distributed under the University of Illinois Open Source | ||
// License. See LICENSE.TXT for details. | ||
// | ||
//===----------------------------------------------------------------------===// | ||
// | ||
// This file declares the common entry point for tblgen tools. | ||
// | ||
//===----------------------------------------------------------------------===// | ||
|
||
#ifndef LLVM_TABLEGEN_MAIN_H | ||
#define LLVM_TABLEGEN_MAIN_H | ||
|
||
namespace llvm { | ||
|
||
class TableGenAction; | ||
|
||
/// Run the table generator, performing the specified Action on parsed records. | ||
int TableGenMain(char *argv0, TableGenAction &Action); | ||
|
||
} | ||
|
||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
//===- llvm/TableGen/TableGenAction.h - defines TableGenAction --*- C++ -*-===// | ||
// | ||
// The LLVM Compiler Infrastructure | ||
// | ||
// This file is distributed under the University of Illinois Open Source | ||
// License. See LICENSE.TXT for details. | ||
// | ||
//===----------------------------------------------------------------------===// | ||
// | ||
// This file defines the TableGenAction base class to be derived from by | ||
// tblgen tools. | ||
// | ||
//===----------------------------------------------------------------------===// | ||
|
||
#ifndef LLVM_TABLEGEN_TABLEGENACTION_H | ||
#define LLVM_TABLEGEN_TABLEGENACTION_H | ||
|
||
namespace llvm { | ||
|
||
class raw_ostream; | ||
class RecordKeeper; | ||
|
||
class TableGenAction { | ||
public: | ||
virtual ~TableGenAction() {} | ||
|
||
/// Perform the action using Records, and write output to OS. | ||
/// @returns true on error, false otherwise | ||
virtual bool operator()(raw_ostream &OS, RecordKeeper &Records) = 0; | ||
}; | ||
|
||
} | ||
|
||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
## FIXME: This only requires RTTI because tblgen uses it. Fix that. | ||
set(LLVM_REQUIRES_RTTI 1) | ||
set(LLVM_REQUIRES_EH 1) | ||
|
||
add_llvm_library(LLVMTableGen | ||
Error.cpp | ||
Main.cpp | ||
Record.cpp | ||
TableGenBackend.cpp | ||
TGLexer.cpp | ||
TGParser.cpp | ||
) | ||
|
||
add_llvm_library_dependencies(LLVMTableGen | ||
LLVMSupport | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,124 @@ | ||
//===- Main.cpp - Top-Level TableGen implementation -----------------------===// | ||
// | ||
// The LLVM Compiler Infrastructure | ||
// | ||
// This file is distributed under the University of Illinois Open Source | ||
// License. See LICENSE.TXT for details. | ||
// | ||
//===----------------------------------------------------------------------===// | ||
// | ||
// TableGen is a tool which can be used to build up a description of something, | ||
// then invoke one or more "tablegen backends" to emit information about the | ||
// description in some predefined format. In practice, this is used by the LLVM | ||
// code generators to automate generation of a code generator through a | ||
// high-level description of the target. | ||
// | ||
//===----------------------------------------------------------------------===// | ||
|
||
#include "TGParser.h" | ||
#include "llvm/ADT/OwningPtr.h" | ||
#include "llvm/Support/CommandLine.h" | ||
#include "llvm/Support/MemoryBuffer.h" | ||
#include "llvm/Support/ToolOutputFile.h" | ||
#include "llvm/Support/system_error.h" | ||
#include "llvm/TableGen/Error.h" | ||
#include "llvm/TableGen/Record.h" | ||
#include "llvm/TableGen/TableGenAction.h" | ||
#include <algorithm> | ||
#include <cstdio> | ||
using namespace llvm; | ||
|
||
namespace { | ||
cl::opt<std::string> | ||
OutputFilename("o", cl::desc("Output filename"), cl::value_desc("filename"), | ||
cl::init("-")); | ||
|
||
cl::opt<std::string> | ||
DependFilename("d", cl::desc("Dependency filename"), cl::value_desc("filename"), | ||
cl::init("")); | ||
|
||
cl::opt<std::string> | ||
InputFilename(cl::Positional, cl::desc("<input file>"), cl::init("-")); | ||
|
||
cl::list<std::string> | ||
IncludeDirs("I", cl::desc("Directory of include files"), | ||
cl::value_desc("directory"), cl::Prefix); | ||
} | ||
|
||
namespace llvm { | ||
|
||
int TableGenMain(char *argv0, TableGenAction &Action) { | ||
RecordKeeper Records; | ||
|
||
try { | ||
// Parse the input file. | ||
OwningPtr<MemoryBuffer> File; | ||
if (error_code ec = MemoryBuffer::getFileOrSTDIN(InputFilename.c_str(), File)) { | ||
errs() << "Could not open input file '" << InputFilename << "': " | ||
<< ec.message() <<"\n"; | ||
return 1; | ||
} | ||
MemoryBuffer *F = File.take(); | ||
|
||
// Tell SrcMgr about this buffer, which is what TGParser will pick up. | ||
SrcMgr.AddNewSourceBuffer(F, SMLoc()); | ||
|
||
// Record the location of the include directory so that the lexer can find | ||
// it later. | ||
SrcMgr.setIncludeDirs(IncludeDirs); | ||
|
||
TGParser Parser(SrcMgr, Records); | ||
|
||
if (Parser.ParseFile()) | ||
return 1; | ||
|
||
std::string Error; | ||
tool_output_file Out(OutputFilename.c_str(), Error); | ||
if (!Error.empty()) { | ||
errs() << argv0 << ": error opening " << OutputFilename | ||
<< ":" << Error << "\n"; | ||
return 1; | ||
} | ||
if (!DependFilename.empty()) { | ||
if (OutputFilename == "-") { | ||
errs() << argv0 << ": the option -d must be used together with -o\n"; | ||
return 1; | ||
} | ||
tool_output_file DepOut(DependFilename.c_str(), Error); | ||
if (!Error.empty()) { | ||
errs() << argv0 << ": error opening " << DependFilename | ||
<< ":" << Error << "\n"; | ||
return 1; | ||
} | ||
DepOut.os() << OutputFilename << ":"; | ||
const std::vector<std::string> &Dependencies = Parser.getDependencies(); | ||
for (std::vector<std::string>::const_iterator I = Dependencies.begin(), | ||
E = Dependencies.end(); | ||
I != E; ++I) { | ||
DepOut.os() << " " << (*I); | ||
} | ||
DepOut.os() << "\n"; | ||
DepOut.keep(); | ||
} | ||
|
||
if (Action(Out.os(), Records)) | ||
return 1; | ||
|
||
// Declare success. | ||
Out.keep(); | ||
return 0; | ||
|
||
} catch (const TGError &Error) { | ||
PrintError(Error); | ||
} catch (const std::string &Error) { | ||
PrintError(Error); | ||
} catch (const char *Error) { | ||
PrintError(Error); | ||
} catch (...) { | ||
errs() << argv0 << ": Unknown unexpected exception occurred.\n"; | ||
} | ||
|
||
return 1; | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
##===- lib/TableGen/Makefile -------------------------------*- Makefile -*-===## | ||
# | ||
# The LLVM Compiler Infrastructure | ||
# | ||
# This file is distributed under the University of Illinois Open Source | ||
# License. See LICENSE.TXT for details. | ||
# | ||
##===----------------------------------------------------------------------===## | ||
|
||
LEVEL = ../.. | ||
LIBRARYNAME = LLVMTableGen | ||
BUILD_ARCHIVE = 1 | ||
|
||
## FIXME: This only requires RTTI because tblgen uses it. Fix that. | ||
REQUIRES_RTTI = 1 | ||
REQUIRES_EH = 1 | ||
|
||
include $(LEVEL)/Makefile.common |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.