[llvm-commits] [TV] r79020 - in /television/trunk: include/llvm-tv/Support/FileUtils.h include/llvm-tv/Support/Snapshots.h lib/Snapshot/FileUtils.cpp lib/Snapshot/ReadSnapshots.cpp lib/Snapshot/WriteSnapshot.cpp
Misha Brukman
brukman+llvm at gmail.com
Fri Aug 14 11:54:20 PDT 2009
Author: brukman
Date: Fri Aug 14 13:54:19 2009
New Revision: 79020
URL: http://llvm.org/viewvc/llvm-project?rev=79020&view=rev
Log:
Updated to use the current LLVM APIs.
Modified:
television/trunk/include/llvm-tv/Support/FileUtils.h
television/trunk/include/llvm-tv/Support/Snapshots.h
television/trunk/lib/Snapshot/FileUtils.cpp
television/trunk/lib/Snapshot/ReadSnapshots.cpp
television/trunk/lib/Snapshot/WriteSnapshot.cpp
Modified: television/trunk/include/llvm-tv/Support/FileUtils.h
URL: http://llvm.org/viewvc/llvm-project/television/trunk/include/llvm-tv/Support/FileUtils.h?rev=79020&r1=79019&r2=79020&view=diff
==============================================================================
--- television/trunk/include/llvm-tv/Support/FileUtils.h (original)
+++ television/trunk/include/llvm-tv/Support/FileUtils.h Fri Aug 14 13:54:19 2009
@@ -27,9 +27,9 @@
///
void GetFilesInDir(const std::string &path, std::vector<std::string> &list);
-bool DirectoryExists (const std::string &dirPath);
+bool DirectoryExists(const std::string &dirPath);
-void EnsureDirectoryExists (const std::string &dirPath);
+void EnsureDirectoryExists(const std::string &dirPath);
}
Modified: television/trunk/include/llvm-tv/Support/Snapshots.h
URL: http://llvm.org/viewvc/llvm-project/television/trunk/include/llvm-tv/Support/Snapshots.h?rev=79020&r1=79019&r2=79020&view=diff
==============================================================================
--- television/trunk/include/llvm-tv/Support/Snapshots.h (original)
+++ television/trunk/include/llvm-tv/Support/Snapshots.h Fri Aug 14 13:54:19 2009
@@ -20,8 +20,8 @@
class Module;
-void ReadSnapshots(std::vector<std::string> &oldModules,
- std::vector<llvm::Module*> NewModules);
+void ReadSnapshots(const std::vector<std::string> &oldModules,
+ std::vector<Module*> &NewModules);
}
Modified: television/trunk/lib/Snapshot/FileUtils.cpp
URL: http://llvm.org/viewvc/llvm-project/television/trunk/lib/Snapshot/FileUtils.cpp?rev=79020&r1=79019&r2=79020&view=diff
==============================================================================
--- television/trunk/lib/Snapshot/FileUtils.cpp (original)
+++ television/trunk/lib/Snapshot/FileUtils.cpp Fri Aug 14 13:54:19 2009
@@ -1,10 +1,10 @@
//===- FileUtils.cpp - File system utility functions for snapshotting -----===//
-//
+//
// The LLVM Compiler Infrastructure
//
// This file was developed by the LLVM research group and is distributed under
// the University of Illinois Open Source License. See LICENSE.TXT for details.
-//
+//
//===----------------------------------------------------------------------===//
//
// This file is Unix-specific; to become part of LLVM it needs to be made
@@ -30,7 +30,7 @@
if (n < 0)
perror("scandir");
else {
- while(n--)
+ while (n--)
free(namelist[n]);
free(namelist);
}
@@ -67,4 +67,3 @@
if (!DirectoryExists (dirPath))
mkdir (dirPath.c_str (), 0777);
}
-
Modified: television/trunk/lib/Snapshot/ReadSnapshots.cpp
URL: http://llvm.org/viewvc/llvm-project/television/trunk/lib/Snapshot/ReadSnapshots.cpp?rev=79020&r1=79019&r2=79020&view=diff
==============================================================================
--- television/trunk/lib/Snapshot/ReadSnapshots.cpp (original)
+++ television/trunk/lib/Snapshot/ReadSnapshots.cpp Fri Aug 14 13:54:19 2009
@@ -1,38 +1,59 @@
//===- ReadSnapshots.cpp - View snapshots that were saved previously ------===//
-//
+//
// The LLVM Compiler Infrastructure
//
// This file was developed by the LLVM research group and is distributed under
// the University of Illinois Open Source License. See LICENSE.TXT for details.
-//
+//
//===----------------------------------------------------------------------===//
//
//
//===----------------------------------------------------------------------===//
+#include "llvm/LLVMContext.h"
#include "llvm/Module.h"
-#include "llvm/Bytecode/Reader.h"
+#include "llvm/Bitcode/ReaderWriter.h"
+#include "llvm/Support/MemoryBuffer.h"
+#include "llvm/Support/raw_ostream.h"
+#include "llvm-tv/Config.h"
#include "llvm-tv/Support/FileUtils.h"
#include "llvm-tv/Support/Snapshots.h"
#include <string>
#include <vector>
using namespace llvm;
-namespace {
- const std::string bytecodePath = "/tmp/llvm-tv/snapshots";
-}
-
/// ReadSnapshots - load all bytecode files in a directory that haven't yet been
/// slurped in earlier.
///
-void llvm::ReadSnapshots(std::vector<std::string> &oldModules,
- std::vector<Module*> NewModules) {
- std::string Filename (bytecodePath);
+void llvm::ReadSnapshots(const std::vector<std::string> &oldModules,
+ std::vector<Module*> &NewModules) {
std::vector<std::string> FileListing;
- GetFilesInDir(bytecodePath, FileListing);
+ GetFilesInDir(snapshotsPath, FileListing);
- for (std::vector<std::string>::iterator i = FileListing.begin(),
- e = FileListing.end(); i != e; ++i)
+ LLVMContext &Context = getGlobalContext();
+
+ for (std::vector<std::string>::const_iterator i = FileListing.begin(),
+ e = FileListing.end(); i != e; ++i) {
if (std::find(oldModules.begin(), oldModules.end(), *i) != oldModules.end())
- NewModules.push_back(ParseBytecodeFile(*i));
+ continue;
+
+ std::string ErrorMessage;
+ std::auto_ptr<MemoryBuffer> Buffer(MemoryBuffer::getFile((*i).c_str(),
+ &ErrorMessage));
+ Module *M = 0;
+ if (Buffer.get()) {
+ M = ParseBitcodeFile(Buffer.get(), Context, &ErrorMessage);
+ } else {
+ errs() << *i << ": could not load into memory.\n";
+ errs() << "Reason: " << ErrorMessage << "\n";
+ continue;
+ }
+
+ if (M == 0) {
+ errs() << *i << ": bitcode didn't read correctly.\n";
+ errs() << "Reason: " << ErrorMessage << "\n";
+ continue;
+ }
+ NewModules.push_back(M);
+ }
}
Modified: television/trunk/lib/Snapshot/WriteSnapshot.cpp
URL: http://llvm.org/viewvc/llvm-project/television/trunk/lib/Snapshot/WriteSnapshot.cpp?rev=79020&r1=79019&r2=79020&view=diff
==============================================================================
--- television/trunk/lib/Snapshot/WriteSnapshot.cpp (original)
+++ television/trunk/lib/Snapshot/WriteSnapshot.cpp Fri Aug 14 13:54:19 2009
@@ -1,25 +1,26 @@
//===- Snapshot.cpp - Snapshot Module views and communicate with llvm-tv --===//
-//
+//
// The LLVM Compiler Infrastructure
//
// This file was developed by the LLVM research group and is distributed under
// the University of Illinois Open Source License. See LICENSE.TXT for details.
-//
+//
//===----------------------------------------------------------------------===//
//
// * If llvm-tv is not running, start it.
// * Send update to llvm-tv each time this pass is called on the command line,
-// e.g. opt -snapshot -licm -snapshot -gcse -snapshot ...
+// e.g. opt -snapshot -licm -snapshot -gcse -snapshot ...
//
//===----------------------------------------------------------------------===//
#include "llvm/Module.h"
#include "llvm/Pass.h"
-#include "llvm/Bytecode/WriteBytecodePass.h"
#include "llvm/ADT/StringExtras.h"
+#include "llvm/Bitcode/ReaderWriter.h"
#include "llvm/Support/CommandLine.h"
#include "llvm/Support/Debug.h"
#include "llvm/Support/SystemUtils.h"
+#include "llvm/Support/raw_ostream.h"
#include "llvm-tv/Support/FileUtils.h"
#include "llvm-tv/Config.h"
#include <csignal>
@@ -42,14 +43,18 @@
struct Snapshot : public ModulePass {
/// getAnalysisUsage - this pass does not require or invalidate any analysis
///
- virtual void getAnalysisUsage(AnalysisUsage &AU) {
+ virtual void getAnalysisUsage(AnalysisUsage &AU) const {
AU.setPreservesAll();
}
-
+
+ Snapshot() : ModulePass(&ID) {}
+
/// runOnModule - save the Module in a pre-defined location with our naming
/// strategy
bool runOnModule(Module &M);
+ static char ID;
+
private:
bool sendSignalToLLVMTV();
std::string findOption(unsigned Idx);
@@ -60,7 +65,9 @@
static unsigned int PassPosition = 1;
/// The name of the command-line option to invoke the snapshot pass
const std::string SnapshotCmd = "snapshot";
- RegisterOpt<Snapshot> X("snapshot", "Snapshot a module, signal llvm-tv");
+
+ char Snapshot::ID = 0;
+ RegisterPass<Snapshot> X("snapshot", "Snapshot a module, signal llvm-tv");
}
@@ -83,7 +90,7 @@
findOption(PassPosition++) + ".bc";
std::ofstream os(Filename.c_str());
- WriteBytecodeToFile(&M, os);
+ WriteBitcodeToFile(&M, os);
os.close();
// Communicate to llvm-tv that we have added a new snapshot
@@ -91,25 +98,26 @@
// Since we were not successful in sending a signal to an already-running
// instance of llvm-tv, start a new instance and send a signal to it.
- sys::Path llvmtvExe = FindExecutable("llvm-tv", "");
- if (llvmtvExe.isValid() && !llvmtvExe.isEmpty() && llvmtvExe.isFile() &&
+ sys::PathWithStatus llvmtvExe = FindExecutable("llvm-tv", "", 0);
+ if (llvmtvExe.isValid() && !llvmtvExe.isEmpty() &&
+ llvmtvExe.getFileStatus()->isFile &&
llvmtvExe.canExecute()) {
int pid = fork();
// Child process morphs into llvm-tv
if (!pid) {
- char *argv[1]; argv[0] = 0;
+ char *argv[1]; argv[0] = 0;
if (execve(llvmtvExe.toString().c_str(), argv, environ) == -1) {
perror("execve");
return false;
}
}
-
+
// parent waits for llvm-tv to write out its pid to a file
// and then sends it a signal
sleep(3);
sendSignalToLLVMTV();
} else
- std::cerr << "Cannot find llvm-tv in the path!\n";
+ errs() << "Cannot find llvm-tv in the path!\n";
return false;
}
More information about the llvm-commits
mailing list