// Block for SourceManager, LangOptions, and Target. Allows easy skipping
// around to the block for the Selectors during deserialization.
Sezr.EnterBlock();
-
- // Emit the name of the source file.
- Sezr.EmitCStr(SourceFile.c_str());
- Sezr.FlushRecord();
-
+
// Emit the SourceManager.
Sezr.Emit(Context->getSourceManager());
FoundBlock = Dezr.SkipToBlock(BasicMetadataBlock);
assert (FoundBlock);
- { // Read the SourceFile.
- char* SName = Dezr.ReadCStr(NULL,0,true);
- TU->SourceFile = SName;
- delete [] SName;
- }
-
// Read the SourceManager.
SourceManager::CreateAndRegister(Dezr,FMgr);
TranslationUnit TU;
const llvm::sys::Path FName;
public:
- ASTSerializer(const std::string& SourceFile,
- const llvm::sys::Path& F, Diagnostic &diags,
+ ASTSerializer(const llvm::sys::Path& F, Diagnostic &diags,
const LangOptions &LO)
- : Diags(diags), TU(SourceFile,LO), FName(F) {}
+ : Diags(diags), TU(LO), FName(F) {}
virtual void Initialize(ASTContext &Context, unsigned MainFileID) {
TU.setContext(&Context);
} // end anonymous namespace
-ASTConsumer* clang::CreateASTSerializer(const std::string& SourceFile,
+ASTConsumer* clang::CreateASTSerializer(const std::string& InFile,
Diagnostic &Diags,
const LangOptions &Features) {
// FIXME: If the translation unit we are serializing came was itself
// be completely replaced momentarily.
// FIXME: This is a hack: "/" separator not portable.
- std::string::size_type idx = SourceFile.rfind("/");
+ std::string::size_type idx = InFile.rfind("/");
- if (idx != std::string::npos && idx == SourceFile.size()-1)
+ if (idx != std::string::npos && idx == InFile.size()-1)
return NULL;
std::string TargetPrefix( idx == std::string::npos ?
- SourceFile : SourceFile.substr(idx+1));
+ InFile : InFile.substr(idx+1));
llvm::sys::Path FName = llvm::sys::Path((TargetPrefix + ".ast").c_str());
- return new ASTSerializer(SourceFile, FName, Diags, Features);
+ return new ASTSerializer(FName, Diags, Features);
}
struct LangOptions;
ASTConsumer *CreateASTPrinter(std::ostream* OS = NULL);
+
ASTConsumer *CreateASTDumper();
+
ASTConsumer *CreateASTViewer();
+
ASTConsumer *CreateCFGDumper(bool ViewGraphs = false);
+
ASTConsumer *CreateLiveVarAnalyzer();
+
ASTConsumer *CreateDeadStoreChecker(Diagnostic &Diags);
+
ASTConsumer *CreateUnitValsChecker(Diagnostic &Diags);
+
ASTConsumer *CreateLLVMEmitter(Diagnostic &Diags, const LangOptions &Features);
+
ASTConsumer *CreateCodeRewriterTest(Diagnostic &Diags);
-ASTConsumer *CreateSerializationTest(const std::string& SourceFile,
- Diagnostic &Diags, FileManager& FMgr,
+
+ASTConsumer *CreateSerializationTest(Diagnostic &Diags,
+ FileManager& FMgr,
const LangOptions &LOpts);
-ASTConsumer *CreateASTSerializer(const std::string& SourceFile,
- Diagnostic &Diags, const LangOptions &LOpts);
+ASTConsumer *CreateASTSerializer(const std::string& InFile,
+ Diagnostic &Diags,
+ const LangOptions &LOpts);
} // end clang namespace
Diagnostic &Diags;
FileManager &FMgr;
public:
- SerializationTest(const std::string& SourceFile, Diagnostic &d,
- FileManager& fmgr, const LangOptions& LOpts)
- : TU(SourceFile, LOpts), Diags(d), FMgr(fmgr) {}
+ SerializationTest(Diagnostic &d, FileManager& fmgr, const LangOptions& LOpts)
+ : TU(LOpts), Diags(d), FMgr(fmgr) {}
~SerializationTest();
} // end anonymous namespace
ASTConsumer*
-clang::CreateSerializationTest(const std::string& SourceFile, Diagnostic &Diags,
- FileManager& FMgr, const LangOptions &LOpts) {
- return new SerializationTest(SourceFile,Diags,FMgr,LOpts);
+clang::CreateSerializationTest(Diagnostic &Diags, FileManager& FMgr,
+ const LangOptions &LOpts) {
+
+ return new SerializationTest(Diags,FMgr,LOpts);
}
/// CreateASTConsumer - Create the ASTConsumer for the corresponding program
/// action. These consumers can operate on both ASTs that are freshly
/// parsed from source files as well as those deserialized from Bitcode.
-static ASTConsumer* CreateASTConsumer(const std::string& SourceFile,
+static ASTConsumer* CreateASTConsumer(const std::string& InFile,
Diagnostic& Diag, FileManager& FileMgr,
const LangOptions& LangOpts) {
switch (ProgAction) {
return CreateUnitValsChecker(Diag);
case TestSerialization:
- return CreateSerializationTest(SourceFile, Diag, FileMgr, LangOpts);
+ return CreateSerializationTest(Diag, FileMgr, LangOpts);
case EmitLLVM:
return CreateLLVMEmitter(Diag, LangOpts);
case SerializeAST:
// FIXME: Allow user to tailor where the file is written.
- return CreateASTSerializer(SourceFile, Diag, LangOpts);
+ return CreateASTSerializer(InFile, Diag, LangOpts);
case RewriteTest:
return CreateCodeRewriterTest(Diag);
/// ProcessInputFile - Process a single input file with the specified state.
///
static void ProcessInputFile(Preprocessor &PP, unsigned MainFileID,
- const std::string &SourceFile,
+ const std::string &InFile,
TextDiagnostics &OurDiagnosticClient) {
ASTConsumer* Consumer = NULL;
switch (ProgAction) {
default:
- Consumer = CreateASTConsumer(SourceFile, PP.getDiagnostics(),
+ Consumer = CreateASTConsumer(InFile,
+ PP.getDiagnostics(),
PP.getFileManager(),
PP.getLangOptions());
fprintf(stderr, "Unexpected program action!\n");
return;
}
+
break;
case DumpTokens: { // Token dump mode.
}
if (Stats) {
- fprintf(stderr, "\nSTATISTICS FOR '%s':\n", SourceFile.c_str());
+ fprintf(stderr, "\nSTATISTICS FOR '%s':\n", InFile.c_str());
PP.PrintStats();
PP.getIdentifierTable().PrintStats();
PP.getHeaderSearchInfo().PrintStats();
// Observe that we use the source file name stored in the deserialized
// translation unit, rather than InFile.
llvm::scoped_ptr<ASTConsumer>
- Consumer(CreateASTConsumer(TU->getSourceFile(), Diag, FileMgr,
- TU->getLangOpts()));
+ Consumer(CreateASTConsumer(InFile, Diag, FileMgr, TU->getLangOpts()));
if (!Consumer) {
fprintf(stderr, "Unsupported program action with serialized ASTs!\n");
class FileEntry;
class TranslationUnit {
- std::string SourceFile;
LangOptions LangOpts;
ASTContext* Context;
std::vector<Decl*> TopLevelDecls;
explicit TranslationUnit() : Context(NULL) {}
public:
- explicit TranslationUnit(const std::string& sourcefile,
- const LangOptions& lopt)
- : SourceFile(sourcefile), LangOpts(lopt), Context(NULL) {}
-
-
+ explicit TranslationUnit(const LangOptions& lopt)
+ : LangOpts(lopt), Context(NULL) {}
+
void setContext(ASTContext* context) { Context = context; }
ASTContext* getContext() const { return Context; }
+
const LangOptions& getLangOpts() const { return LangOpts; }
- const std::string& getSourceFile() const { return SourceFile; }
+ const std::string& getSourceFile() const;
/// Emit - Emit the translation unit to an arbitray bitcode stream.
void Emit(llvm::Serializer& S) const;