Add driver support for invoking block rewriter.

Also tweaked the create function to take an explicit output file.

llvm-svn: 56305
This commit is contained in:
Steve Naroff 2008-09-18 14:10:13 +00:00
parent 5cc53c34c3
commit 9779e92fa4
3 changed files with 27 additions and 11 deletions

View File

@ -59,6 +59,7 @@ ASTConsumer *CreateASTSerializer(const std::string& InFile,
Diagnostic &Diags);
ASTConsumer *CreateBlockRewriter(const std::string& InFile,
const std::string& OutFile,
Diagnostic &Diags,
const LangOptions &LangOpts);
} // end clang namespace

View File

@ -55,17 +55,11 @@ class RewriteBlocks : public ASTConsumer {
ObjCMethodDecl *CurMethodDef;
bool IsHeader;
std::string InFileName;
std::string OutFileName;
public:
RewriteBlocks(bool isHeader, Diagnostic &D, const LangOptions &LOpts) :
Diags(D), LangOpts(LOpts) {
IsHeader = isHeader;
CurFunctionDef = 0;
CurMethodDef = 0;
RewriteFailedDiag = Diags.getCustomDiagID(Diagnostic::Warning,
"rewriting failed");
NoNestedBlockCalls = Diags.getCustomDiagID(Diagnostic::Warning,
"Rewrite support for closure calls nested within closure blocks is incomplete");
}
RewriteBlocks(std::string inFile, std::string outFile, Diagnostic &D,
const LangOptions &LOpts);
~RewriteBlocks() {
// Get the buffer corresponding to MainFileID.
// If we haven't changed it, then we are done.
@ -155,10 +149,25 @@ static bool IsHeaderFile(const std::string &Filename) {
return Ext == "h" || Ext == "hh" || Ext == "H";
}
RewriteBlocks::RewriteBlocks(std::string inFile, std::string outFile,
Diagnostic &D, const LangOptions &LOpts) :
Diags(D), LangOpts(LOpts) {
IsHeader = IsHeaderFile(inFile);
InFileName = inFile;
OutFileName = outFile;
CurFunctionDef = 0;
CurMethodDef = 0;
RewriteFailedDiag = Diags.getCustomDiagID(Diagnostic::Warning,
"rewriting failed");
NoNestedBlockCalls = Diags.getCustomDiagID(Diagnostic::Warning,
"Rewrite support for closure calls nested within closure blocks is incomplete");
}
ASTConsumer *clang::CreateBlockRewriter(const std::string& InFile,
const std::string& OutFile,
Diagnostic &Diags,
const LangOptions &LangOpts) {
return new RewriteBlocks(IsHeaderFile(InFile), Diags, LangOpts);
return new RewriteBlocks(InFile, OutFile, Diags, LangOpts);
}
void RewriteBlocks::Initialize(ASTContext &context) {

View File

@ -61,6 +61,7 @@ Stats("print-stats",
enum ProgActions {
RewriteObjC, // ObjC->C Rewriter.
RewriteBlocks, // ObjC->C Rewriter for Blocks.
RewriteMacros, // Expand macros but not #includes.
HTMLTest, // HTML displayer testing stuff.
EmitLLVM, // Emit a .ll file.
@ -116,6 +117,8 @@ ProgAction(llvm::cl::desc("Choose output type:"), llvm::cl::ZeroOrMore,
"Rewrite ObjC into C (code rewriter example)"),
clEnumValN(RewriteMacros, "rewrite-macros",
"Expand macros without full preprocessing"),
clEnumValN(RewriteBlocks, "rewrite-blocks",
"Rewrite Blocks to C"),
clEnumValEnd));
@ -989,6 +992,9 @@ static ASTConsumer* CreateASTConsumer(const std::string& InFile,
case RewriteObjC:
return CreateCodeRewriterTest(InFile, OutputFile, Diag, LangOpts);
case RewriteBlocks:
return CreateBlockRewriter(InFile, OutputFile, Diag, LangOpts);
case RunAnalysis:
assert (!AnalysisList.empty());