forked from OSchip/llvm-project
Replacing std::iostreams with llvm iostreams. Some of these changes involve
adding a temporary wrapper around the ostream to make it friendly to functions expecting an LLVM stream. This should be fixed in the future. llvm-svn: 31990
This commit is contained in:
parent
a531ac291c
commit
afd54eb8b6
|
@ -18,8 +18,7 @@
|
||||||
#include "llvm/Constants.h"
|
#include "llvm/Constants.h"
|
||||||
#include "llvm/Instructions.h"
|
#include "llvm/Instructions.h"
|
||||||
#include "llvm/Bytecode/Writer.h"
|
#include "llvm/Bytecode/Writer.h"
|
||||||
#include <iostream>
|
#include "llvm/Support/Streams.h"
|
||||||
|
|
||||||
using namespace llvm;
|
using namespace llvm;
|
||||||
|
|
||||||
int main() {
|
int main() {
|
||||||
|
@ -54,7 +53,7 @@ int main() {
|
||||||
BB->getInstList().push_back(new ReturnInst(Add));
|
BB->getInstList().push_back(new ReturnInst(Add));
|
||||||
|
|
||||||
// Output the bytecode file to stdout
|
// Output the bytecode file to stdout
|
||||||
WriteBytecodeToFile(M, std::cout);
|
WriteBytecodeToFile(M, llvm_cout);
|
||||||
|
|
||||||
// Delete the module and all of its contents.
|
// Delete the module and all of its contents.
|
||||||
delete M;
|
delete M;
|
||||||
|
|
|
@ -152,6 +152,9 @@ public:
|
||||||
///
|
///
|
||||||
void initialize(Module &M);
|
void initialize(Module &M);
|
||||||
|
|
||||||
|
void print(llvm_ostream &o, const Module *M) const {
|
||||||
|
if (o.stream()) print(*o.stream(), M);
|
||||||
|
}
|
||||||
virtual void print(std::ostream &o, const Module *M) const;
|
virtual void print(std::ostream &o, const Module *M) const;
|
||||||
void dump() const;
|
void dump() const;
|
||||||
|
|
||||||
|
@ -198,6 +201,9 @@ public:
|
||||||
/// dump - Print out this call graph node.
|
/// dump - Print out this call graph node.
|
||||||
///
|
///
|
||||||
void dump() const;
|
void dump() const;
|
||||||
|
void print(llvm_ostream &OS) const {
|
||||||
|
if (OS.stream()) print(*OS.stream());
|
||||||
|
}
|
||||||
void print(std::ostream &OS) const;
|
void print(std::ostream &OS) const;
|
||||||
|
|
||||||
//===---------------------------------------------------------------------
|
//===---------------------------------------------------------------------
|
||||||
|
|
|
@ -17,18 +17,19 @@
|
||||||
|
|
||||||
#include "llvm/Pass.h"
|
#include "llvm/Pass.h"
|
||||||
#include "llvm/Bytecode/Writer.h"
|
#include "llvm/Bytecode/Writer.h"
|
||||||
#include <iostream>
|
|
||||||
|
|
||||||
namespace llvm {
|
namespace llvm {
|
||||||
|
|
||||||
|
class llvm_ostream;
|
||||||
|
|
||||||
class WriteBytecodePass : public ModulePass {
|
class WriteBytecodePass : public ModulePass {
|
||||||
std::ostream *Out; // ostream to print on
|
llvm_ostream *Out; // ostream to print on
|
||||||
bool DeleteStream;
|
bool DeleteStream;
|
||||||
bool CompressFile;
|
bool CompressFile;
|
||||||
public:
|
public:
|
||||||
WriteBytecodePass()
|
WriteBytecodePass()
|
||||||
: Out(&std::cout), DeleteStream(false), CompressFile(true) {}
|
: Out(&llvm_cout), DeleteStream(false), CompressFile(true) {}
|
||||||
WriteBytecodePass(std::ostream *o, bool DS = false, bool CF = true)
|
WriteBytecodePass(llvm_ostream *o, bool DS = false, bool CF = true)
|
||||||
: Out(o), DeleteStream(DS), CompressFile(CF) {}
|
: Out(o), DeleteStream(DS), CompressFile(CF) {}
|
||||||
|
|
||||||
inline ~WriteBytecodePass() {
|
inline ~WriteBytecodePass() {
|
||||||
|
|
|
@ -15,14 +15,13 @@
|
||||||
#ifndef LLVM_BYTECODE_WRITER_H
|
#ifndef LLVM_BYTECODE_WRITER_H
|
||||||
#define LLVM_BYTECODE_WRITER_H
|
#define LLVM_BYTECODE_WRITER_H
|
||||||
|
|
||||||
#include <iosfwd>
|
|
||||||
|
|
||||||
namespace llvm {
|
namespace llvm {
|
||||||
|
class llvm_ostream;
|
||||||
class Module;
|
class Module;
|
||||||
/// WriteBytecodeToFile - Write the specified module to the specified output
|
/// WriteBytecodeToFile - Write the specified module to the specified output
|
||||||
/// stream. If compress is set to true, try to use compression when writing
|
/// stream. If compress is set to true, try to use compression when writing
|
||||||
/// out the file. This can never fail if M is a well-formed module.
|
/// out the file. This can never fail if M is a well-formed module.
|
||||||
void WriteBytecodeToFile(const Module *M, std::ostream &Out,
|
void WriteBytecodeToFile(const Module *M, llvm_ostream &Out,
|
||||||
bool compress = true);
|
bool compress = true);
|
||||||
} // End llvm namespace
|
} // End llvm namespace
|
||||||
|
|
||||||
|
|
|
@ -70,6 +70,11 @@ namespace llvm {
|
||||||
///
|
///
|
||||||
FunctionPass *createLinearScanRegisterAllocator();
|
FunctionPass *createLinearScanRegisterAllocator();
|
||||||
|
|
||||||
|
/// PriorityBasedGraphColoringRegisterAllocator Pass - This pass implements
|
||||||
|
/// the priority-based graph coloring register allocator by Chow & Hennessey,
|
||||||
|
/// a global register allocator.
|
||||||
|
FunctionPass *createGraphColoringRegisterAllocator();
|
||||||
|
|
||||||
/// PrologEpilogCodeInserter Pass - This pass inserts prolog and epilog code,
|
/// PrologEpilogCodeInserter Pass - This pass inserts prolog and epilog code,
|
||||||
/// and eliminates abstract frame references.
|
/// and eliminates abstract frame references.
|
||||||
///
|
///
|
||||||
|
|
|
@ -43,6 +43,7 @@ namespace llvm {
|
||||||
}
|
}
|
||||||
|
|
||||||
bool operator == (const std::ostream &OS) { return &OS == Stream; }
|
bool operator == (const std::ostream &OS) { return &OS == Stream; }
|
||||||
|
bool operator == (const llvm_ostream &OS) { return OS.Stream == Stream; }
|
||||||
};
|
};
|
||||||
|
|
||||||
extern llvm_ostream llvm_null;
|
extern llvm_ostream llvm_null;
|
||||||
|
|
|
@ -24,7 +24,6 @@
|
||||||
#include "llvm/Support/CommandLine.h"
|
#include "llvm/Support/CommandLine.h"
|
||||||
#include "llvm/Support/Debug.h"
|
#include "llvm/Support/Debug.h"
|
||||||
#include "llvm/Support/Timer.h"
|
#include "llvm/Support/Timer.h"
|
||||||
#include <iostream>
|
|
||||||
|
|
||||||
// FIXME: This should eventually be a FunctionPass that is automatically
|
// FIXME: This should eventually be a FunctionPass that is automatically
|
||||||
// aggregated into a Pass.
|
// aggregated into a Pass.
|
||||||
|
@ -435,7 +434,7 @@ void GraphBuilder::visitGetElementPtrInst(User &GEP) {
|
||||||
// Variable index into a node. We must merge all of the elements of the
|
// Variable index into a node. We must merge all of the elements of the
|
||||||
// sequential type here.
|
// sequential type here.
|
||||||
if (isa<PointerType>(STy))
|
if (isa<PointerType>(STy))
|
||||||
std::cerr << "Pointer indexing not handled yet!\n";
|
llvm_cerr << "Pointer indexing not handled yet!\n";
|
||||||
else {
|
else {
|
||||||
const ArrayType *ATy = cast<ArrayType>(STy);
|
const ArrayType *ATy = cast<ArrayType>(STy);
|
||||||
unsigned ElSize = TD.getTypeSize(CurTy);
|
unsigned ElSize = TD.getTypeSize(CurTy);
|
||||||
|
@ -1062,7 +1061,7 @@ void GraphBuilder::visitCallSite(CallSite CS) {
|
||||||
if (DisableDirectCallOpt || !isa<Function>(Callee)) {
|
if (DisableDirectCallOpt || !isa<Function>(Callee)) {
|
||||||
CalleeNode = getValueDest(*Callee).getNode();
|
CalleeNode = getValueDest(*Callee).getNode();
|
||||||
if (CalleeNode == 0) {
|
if (CalleeNode == 0) {
|
||||||
std::cerr << "WARNING: Program is calling through a null pointer?\n"<< *I;
|
llvm_cerr << "WARNING: Program is calling through a null pointer?\n"<< *I;
|
||||||
return; // Calling a null pointer?
|
return; // Calling a null pointer?
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -19,9 +19,10 @@
|
||||||
#include "llvm/Assembly/Writer.h"
|
#include "llvm/Assembly/Writer.h"
|
||||||
#include "llvm/Support/CommandLine.h"
|
#include "llvm/Support/CommandLine.h"
|
||||||
#include "llvm/Support/GraphWriter.h"
|
#include "llvm/Support/GraphWriter.h"
|
||||||
|
#include "llvm/Support/Streams.h"
|
||||||
#include "llvm/ADT/Statistic.h"
|
#include "llvm/ADT/Statistic.h"
|
||||||
#include "llvm/Config/config.h"
|
#include "llvm/Config/config.h"
|
||||||
#include <iostream>
|
#include <ostream>
|
||||||
#include <fstream>
|
#include <fstream>
|
||||||
#include <sstream>
|
#include <sstream>
|
||||||
using namespace llvm;
|
using namespace llvm;
|
||||||
|
@ -36,7 +37,7 @@ namespace {
|
||||||
Statistic<> NumFoldedNodes ("dsa", "Number of folded nodes (in final graph)");
|
Statistic<> NumFoldedNodes ("dsa", "Number of folded nodes (in final graph)");
|
||||||
}
|
}
|
||||||
|
|
||||||
void DSNode::dump() const { print(std::cerr, 0); }
|
void DSNode::dump() const { print(llvm_cerr, 0); }
|
||||||
|
|
||||||
static std::string getCaption(const DSNode *N, const DSGraph *G) {
|
static std::string getCaption(const DSNode *N, const DSGraph *G) {
|
||||||
std::stringstream OS;
|
std::stringstream OS;
|
||||||
|
|
|
@ -20,7 +20,7 @@
|
||||||
#include "llvm/Analysis/Passes.h"
|
#include "llvm/Analysis/Passes.h"
|
||||||
#include "llvm/Module.h"
|
#include "llvm/Module.h"
|
||||||
#include "llvm/Support/Debug.h"
|
#include "llvm/Support/Debug.h"
|
||||||
#include <iostream>
|
#include <ostream>
|
||||||
using namespace llvm;
|
using namespace llvm;
|
||||||
|
|
||||||
namespace {
|
namespace {
|
||||||
|
@ -53,6 +53,9 @@ namespace {
|
||||||
}
|
}
|
||||||
|
|
||||||
// print - Implement the Pass::print method...
|
// print - Implement the Pass::print method...
|
||||||
|
void print(llvm_ostream O, const Module *M) const {
|
||||||
|
if (O.stream()) print(*O.stream(), M);
|
||||||
|
}
|
||||||
void print(std::ostream &O, const Module *M) const {
|
void print(std::ostream &O, const Module *M) const {
|
||||||
assert(ResultGraph && "Result graph has not yet been computed!");
|
assert(ResultGraph && "Result graph has not yet been computed!");
|
||||||
ResultGraph->writeGraphToFile(O, "steensgaards");
|
ResultGraph->writeGraphToFile(O, "steensgaards");
|
||||||
|
@ -188,7 +191,7 @@ bool Steens::runOnModule(Module &M) {
|
||||||
// FIXME: We should be able to disable the globals graph for steens!
|
// FIXME: We should be able to disable the globals graph for steens!
|
||||||
//ResultGraph->removeDeadNodes(DSGraph::KeepUnreachableGlobals);
|
//ResultGraph->removeDeadNodes(DSGraph::KeepUnreachableGlobals);
|
||||||
|
|
||||||
DEBUG(print(std::cerr, &M));
|
print(DOUT, &M);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -62,7 +62,6 @@
|
||||||
#include "llvm/Support/Debug.h"
|
#include "llvm/Support/Debug.h"
|
||||||
#include "llvm/ADT/Statistic.h"
|
#include "llvm/ADT/Statistic.h"
|
||||||
#include <set>
|
#include <set>
|
||||||
#include <iostream>
|
|
||||||
using namespace llvm;
|
using namespace llvm;
|
||||||
|
|
||||||
namespace {
|
namespace {
|
||||||
|
@ -534,7 +533,7 @@ Andersens::Node *Andersens::getNodeForConstantPointer(Constant *C) {
|
||||||
case Instruction::BitCast:
|
case Instruction::BitCast:
|
||||||
return getNodeForConstantPointer(CE->getOperand(0));
|
return getNodeForConstantPointer(CE->getOperand(0));
|
||||||
default:
|
default:
|
||||||
std::cerr << "Constant Expr not yet handled: " << *CE << "\n";
|
llvm_cerr << "Constant Expr not yet handled: " << *CE << "\n";
|
||||||
assert(0);
|
assert(0);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
@ -561,7 +560,7 @@ Andersens::Node *Andersens::getNodeForConstantPointerTarget(Constant *C) {
|
||||||
case Instruction::BitCast:
|
case Instruction::BitCast:
|
||||||
return getNodeForConstantPointerTarget(CE->getOperand(0));
|
return getNodeForConstantPointerTarget(CE->getOperand(0));
|
||||||
default:
|
default:
|
||||||
std::cerr << "Constant Expr not yet handled: " << *CE << "\n";
|
llvm_cerr << "Constant Expr not yet handled: " << *CE << "\n";
|
||||||
assert(0);
|
assert(0);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
@ -787,7 +786,7 @@ void Andersens::visitInstruction(Instruction &I) {
|
||||||
return;
|
return;
|
||||||
default:
|
default:
|
||||||
// Is this something we aren't handling yet?
|
// Is this something we aren't handling yet?
|
||||||
std::cerr << "Unknown instruction: " << I;
|
llvm_cerr << "Unknown instruction: " << I;
|
||||||
abort();
|
abort();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1105,13 +1104,13 @@ void Andersens::SolveConstraints() {
|
||||||
|
|
||||||
void Andersens::PrintNode(Node *N) {
|
void Andersens::PrintNode(Node *N) {
|
||||||
if (N == &GraphNodes[UniversalSet]) {
|
if (N == &GraphNodes[UniversalSet]) {
|
||||||
std::cerr << "<universal>";
|
llvm_cerr << "<universal>";
|
||||||
return;
|
return;
|
||||||
} else if (N == &GraphNodes[NullPtr]) {
|
} else if (N == &GraphNodes[NullPtr]) {
|
||||||
std::cerr << "<nullptr>";
|
llvm_cerr << "<nullptr>";
|
||||||
return;
|
return;
|
||||||
} else if (N == &GraphNodes[NullObject]) {
|
} else if (N == &GraphNodes[NullObject]) {
|
||||||
std::cerr << "<null>";
|
llvm_cerr << "<null>";
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1120,56 +1119,56 @@ void Andersens::PrintNode(Node *N) {
|
||||||
if (Function *F = dyn_cast<Function>(V)) {
|
if (Function *F = dyn_cast<Function>(V)) {
|
||||||
if (isa<PointerType>(F->getFunctionType()->getReturnType()) &&
|
if (isa<PointerType>(F->getFunctionType()->getReturnType()) &&
|
||||||
N == getReturnNode(F)) {
|
N == getReturnNode(F)) {
|
||||||
std::cerr << F->getName() << ":retval";
|
llvm_cerr << F->getName() << ":retval";
|
||||||
return;
|
return;
|
||||||
} else if (F->getFunctionType()->isVarArg() && N == getVarargNode(F)) {
|
} else if (F->getFunctionType()->isVarArg() && N == getVarargNode(F)) {
|
||||||
std::cerr << F->getName() << ":vararg";
|
llvm_cerr << F->getName() << ":vararg";
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (Instruction *I = dyn_cast<Instruction>(V))
|
if (Instruction *I = dyn_cast<Instruction>(V))
|
||||||
std::cerr << I->getParent()->getParent()->getName() << ":";
|
llvm_cerr << I->getParent()->getParent()->getName() << ":";
|
||||||
else if (Argument *Arg = dyn_cast<Argument>(V))
|
else if (Argument *Arg = dyn_cast<Argument>(V))
|
||||||
std::cerr << Arg->getParent()->getName() << ":";
|
llvm_cerr << Arg->getParent()->getName() << ":";
|
||||||
|
|
||||||
if (V->hasName())
|
if (V->hasName())
|
||||||
std::cerr << V->getName();
|
llvm_cerr << V->getName();
|
||||||
else
|
else
|
||||||
std::cerr << "(unnamed)";
|
llvm_cerr << "(unnamed)";
|
||||||
|
|
||||||
if (isa<GlobalValue>(V) || isa<AllocationInst>(V))
|
if (isa<GlobalValue>(V) || isa<AllocationInst>(V))
|
||||||
if (N == getObject(V))
|
if (N == getObject(V))
|
||||||
std::cerr << "<mem>";
|
llvm_cerr << "<mem>";
|
||||||
}
|
}
|
||||||
|
|
||||||
void Andersens::PrintConstraints() {
|
void Andersens::PrintConstraints() {
|
||||||
std::cerr << "Constraints:\n";
|
llvm_cerr << "Constraints:\n";
|
||||||
for (unsigned i = 0, e = Constraints.size(); i != e; ++i) {
|
for (unsigned i = 0, e = Constraints.size(); i != e; ++i) {
|
||||||
std::cerr << " #" << i << ": ";
|
llvm_cerr << " #" << i << ": ";
|
||||||
Constraint &C = Constraints[i];
|
Constraint &C = Constraints[i];
|
||||||
if (C.Type == Constraint::Store)
|
if (C.Type == Constraint::Store)
|
||||||
std::cerr << "*";
|
llvm_cerr << "*";
|
||||||
PrintNode(C.Dest);
|
PrintNode(C.Dest);
|
||||||
std::cerr << " = ";
|
llvm_cerr << " = ";
|
||||||
if (C.Type == Constraint::Load)
|
if (C.Type == Constraint::Load)
|
||||||
std::cerr << "*";
|
llvm_cerr << "*";
|
||||||
PrintNode(C.Src);
|
PrintNode(C.Src);
|
||||||
std::cerr << "\n";
|
llvm_cerr << "\n";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void Andersens::PrintPointsToGraph() {
|
void Andersens::PrintPointsToGraph() {
|
||||||
std::cerr << "Points-to graph:\n";
|
llvm_cerr << "Points-to graph:\n";
|
||||||
for (unsigned i = 0, e = GraphNodes.size(); i != e; ++i) {
|
for (unsigned i = 0, e = GraphNodes.size(); i != e; ++i) {
|
||||||
Node *N = &GraphNodes[i];
|
Node *N = &GraphNodes[i];
|
||||||
std::cerr << "[" << (N->end() - N->begin()) << "] ";
|
llvm_cerr << "[" << (N->end() - N->begin()) << "] ";
|
||||||
PrintNode(N);
|
PrintNode(N);
|
||||||
std::cerr << "\t--> ";
|
llvm_cerr << "\t--> ";
|
||||||
for (Node::iterator I = N->begin(), E = N->end(); I != E; ++I) {
|
for (Node::iterator I = N->begin(), E = N->end(); I != E; ++I) {
|
||||||
if (I != N->begin()) std::cerr << ", ";
|
if (I != N->begin()) llvm_cerr << ", ";
|
||||||
PrintNode(*I);
|
PrintNode(*I);
|
||||||
}
|
}
|
||||||
std::cerr << "\n";
|
llvm_cerr << "\n";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -16,7 +16,8 @@
|
||||||
#include "llvm/Module.h"
|
#include "llvm/Module.h"
|
||||||
#include "llvm/Instructions.h"
|
#include "llvm/Instructions.h"
|
||||||
#include "llvm/Support/CallSite.h"
|
#include "llvm/Support/CallSite.h"
|
||||||
#include <iostream>
|
#include "llvm/Support/Streams.h"
|
||||||
|
#include <ostream>
|
||||||
using namespace llvm;
|
using namespace llvm;
|
||||||
|
|
||||||
static bool isOnlyADirectCall(Function *F, CallSite CS) {
|
static bool isOnlyADirectCall(Function *F, CallSite CS) {
|
||||||
|
@ -72,6 +73,10 @@ public:
|
||||||
AU.setPreservesAll();
|
AU.setPreservesAll();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void print(llvm_ostream &o, const Module *M) const {
|
||||||
|
if (o.stream()) print(*o.stream(), M);
|
||||||
|
}
|
||||||
|
|
||||||
virtual void print(std::ostream &o, const Module *M) const {
|
virtual void print(std::ostream &o, const Module *M) const {
|
||||||
o << "CallGraph Root is: ";
|
o << "CallGraph Root is: ";
|
||||||
if (Function *F = getRoot()->getFunction())
|
if (Function *F = getRoot()->getFunction())
|
||||||
|
@ -89,7 +94,7 @@ public:
|
||||||
/// dump - Print out this call graph.
|
/// dump - Print out this call graph.
|
||||||
///
|
///
|
||||||
inline void dump() const {
|
inline void dump() const {
|
||||||
print(std::cerr, Mod);
|
print(llvm_cerr, Mod);
|
||||||
}
|
}
|
||||||
|
|
||||||
CallGraphNode* getExternalCallingNode() const { return ExternalCallingNode; }
|
CallGraphNode* getExternalCallingNode() const { return ExternalCallingNode; }
|
||||||
|
@ -207,7 +212,7 @@ void CallGraph::print(std::ostream &OS, const Module *M) const {
|
||||||
}
|
}
|
||||||
|
|
||||||
void CallGraph::dump() const {
|
void CallGraph::dump() const {
|
||||||
print(std::cerr, 0);
|
print(llvm_cerr, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
//===----------------------------------------------------------------------===//
|
//===----------------------------------------------------------------------===//
|
||||||
|
@ -270,7 +275,7 @@ void CallGraphNode::print(std::ostream &OS) const {
|
||||||
OS << "\n";
|
OS << "\n";
|
||||||
}
|
}
|
||||||
|
|
||||||
void CallGraphNode::dump() const { print(std::cerr); }
|
void CallGraphNode::dump() const { print(llvm_cerr); }
|
||||||
|
|
||||||
void CallGraphNode::removeCallEdgeTo(CallGraphNode *Callee) {
|
void CallGraphNode::removeCallEdgeTo(CallGraphNode *Callee) {
|
||||||
for (unsigned i = CalledFunctions.size(); ; --i) {
|
for (unsigned i = CalledFunctions.size(); ; --i) {
|
||||||
|
|
|
@ -174,7 +174,7 @@ Value *SCEVExpander::visitAddRecExpr(SCEVAddRecExpr *S) {
|
||||||
SCEVHandle IH = SCEVUnknown::get(I); // Get I as a "symbolic" SCEV.
|
SCEVHandle IH = SCEVUnknown::get(I); // Get I as a "symbolic" SCEV.
|
||||||
|
|
||||||
SCEVHandle V = S->evaluateAtIteration(IH);
|
SCEVHandle V = S->evaluateAtIteration(IH);
|
||||||
//std::cerr << "Evaluated: " << *this << "\n to: " << *V << "\n";
|
//llvm_cerr << "Evaluated: " << *this << "\n to: " << *V << "\n";
|
||||||
|
|
||||||
return expandInTy(V, Ty);
|
return expandInTy(V, Ty);
|
||||||
}
|
}
|
||||||
|
|
|
@ -31,8 +31,8 @@
|
||||||
using namespace llvm;
|
using namespace llvm;
|
||||||
|
|
||||||
#if 0
|
#if 0
|
||||||
#include <iostream>
|
#include "llvm/Support/Streams.h"
|
||||||
#define SC_DEBUG(X) std::cerr << X
|
#define SC_DEBUG(X) llvm_cerr << X
|
||||||
#else
|
#else
|
||||||
#define SC_DEBUG(X)
|
#define SC_DEBUG(X)
|
||||||
#endif
|
#endif
|
||||||
|
@ -800,7 +800,7 @@ int SlotCalculator::doInsertValue(const Value *D) {
|
||||||
|
|
||||||
// Used for debugging DefSlot=-1 assertion...
|
// Used for debugging DefSlot=-1 assertion...
|
||||||
//if (Typ == Type::TypeTy)
|
//if (Typ == Type::TypeTy)
|
||||||
// cerr << "Inserting type '" << cast<Type>(D)->getDescription() << "'!\n";
|
// llvm_cerr << "Inserting type '"<<cast<Type>(D)->getDescription() <<"'!\n";
|
||||||
|
|
||||||
if (Typ->isDerivedType()) {
|
if (Typ->isDerivedType()) {
|
||||||
int ValSlot;
|
int ValSlot;
|
||||||
|
|
|
@ -29,6 +29,7 @@
|
||||||
#include "llvm/Support/GetElementPtrTypeIterator.h"
|
#include "llvm/Support/GetElementPtrTypeIterator.h"
|
||||||
#include "llvm/Support/Compressor.h"
|
#include "llvm/Support/Compressor.h"
|
||||||
#include "llvm/Support/MathExtras.h"
|
#include "llvm/Support/MathExtras.h"
|
||||||
|
#include "llvm/Support/Streams.h"
|
||||||
#include "llvm/System/Program.h"
|
#include "llvm/System/Program.h"
|
||||||
#include "llvm/ADT/STLExtras.h"
|
#include "llvm/ADT/STLExtras.h"
|
||||||
#include "llvm/ADT/Statistic.h"
|
#include "llvm/ADT/Statistic.h"
|
||||||
|
@ -275,7 +276,7 @@ void BytecodeWriter::outputType(const Type *T) {
|
||||||
break;
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
std::cerr << __FILE__ << ":" << __LINE__ << ": Don't know how to serialize"
|
llvm_cerr << __FILE__ << ":" << __LINE__ << ": Don't know how to serialize"
|
||||||
<< " Type '" << T->getDescription() << "'\n";
|
<< " Type '" << T->getDescription() << "'\n";
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -384,7 +385,7 @@ void BytecodeWriter::outputConstant(const Constant *CPV) {
|
||||||
case Type::VoidTyID:
|
case Type::VoidTyID:
|
||||||
case Type::LabelTyID:
|
case Type::LabelTyID:
|
||||||
default:
|
default:
|
||||||
std::cerr << __FILE__ << ":" << __LINE__ << ": Don't know how to serialize"
|
llvm_cerr << __FILE__ << ":" << __LINE__ << ": Don't know how to serialize"
|
||||||
<< " type '" << *CPV->getType() << "'\n";
|
<< " type '" << *CPV->getType() << "'\n";
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -1225,13 +1226,13 @@ void BytecodeWriter::outputSymbolTable(const SymbolTable &MST) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void llvm::WriteBytecodeToFile(const Module *M, std::ostream &Out,
|
void llvm::WriteBytecodeToFile(const Module *M, llvm_ostream &Out,
|
||||||
bool compress) {
|
bool compress) {
|
||||||
assert(M && "You can't write a null module!!");
|
assert(M && "You can't write a null module!!");
|
||||||
|
|
||||||
// Make sure that std::cout is put into binary mode for systems
|
// Make sure that std::cout is put into binary mode for systems
|
||||||
// that care.
|
// that care.
|
||||||
if (&Out == std::cout)
|
if (Out == llvm_cout)
|
||||||
sys::Program::ChangeStdoutToBinary();
|
sys::Program::ChangeStdoutToBinary();
|
||||||
|
|
||||||
// Create a vector of unsigned char for the bytecode output. We
|
// Create a vector of unsigned char for the bytecode output. We
|
||||||
|
@ -1264,21 +1265,21 @@ void llvm::WriteBytecodeToFile(const Module *M, std::ostream &Out,
|
||||||
compressed_magic[2] = 'v';
|
compressed_magic[2] = 'v';
|
||||||
compressed_magic[3] = 'c';
|
compressed_magic[3] = 'c';
|
||||||
|
|
||||||
Out.write(compressed_magic,4);
|
Out.stream()->write(compressed_magic,4);
|
||||||
|
|
||||||
// Compress everything after the magic number (which we altered)
|
// Compress everything after the magic number (which we altered)
|
||||||
Compressor::compressToStream(
|
Compressor::compressToStream(
|
||||||
(char*)(FirstByte+4), // Skip the magic number
|
(char*)(FirstByte+4), // Skip the magic number
|
||||||
Buffer.size()-4, // Skip the magic number
|
Buffer.size()-4, // Skip the magic number
|
||||||
Out // Where to write compressed data
|
*Out.stream() // Where to write compressed data
|
||||||
);
|
);
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
|
|
||||||
// We're not compressing, so just write the entire block.
|
// We're not compressing, so just write the entire block.
|
||||||
Out.write((char*)FirstByte, Buffer.size());
|
Out.stream()->write((char*)FirstByte, Buffer.size());
|
||||||
}
|
}
|
||||||
|
|
||||||
// make sure it hits disk now
|
// make sure it hits disk now
|
||||||
Out.flush();
|
Out.stream()->flush();
|
||||||
}
|
}
|
||||||
|
|
|
@ -22,11 +22,11 @@
|
||||||
#include "llvm/Bytecode/Writer.h"
|
#include "llvm/Bytecode/Writer.h"
|
||||||
#include "llvm/Analysis/Verifier.h"
|
#include "llvm/Analysis/Verifier.h"
|
||||||
#include "llvm/Support/CommandLine.h"
|
#include "llvm/Support/CommandLine.h"
|
||||||
|
#include "llvm/Support/Streams.h"
|
||||||
#include "llvm/System/Signals.h"
|
#include "llvm/System/Signals.h"
|
||||||
#include <fstream>
|
#include <fstream>
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <memory>
|
#include <memory>
|
||||||
|
|
||||||
using namespace llvm;
|
using namespace llvm;
|
||||||
|
|
||||||
static cl::opt<std::string>
|
static cl::opt<std::string>
|
||||||
|
@ -115,7 +115,7 @@ int main(int argc, char **argv)
|
||||||
}
|
}
|
||||||
|
|
||||||
if (DumpAsm)
|
if (DumpAsm)
|
||||||
std::cerr << "Here's the assembly:" << M.get();
|
llvm_cerr << "Here's the assembly:" << M.get();
|
||||||
|
|
||||||
if (OutputFilename != "") { // Specified an output filename?
|
if (OutputFilename != "") { // Specified an output filename?
|
||||||
if (OutputFilename != "-") { // Not stdout?
|
if (OutputFilename != "-") { // Not stdout?
|
||||||
|
@ -163,14 +163,15 @@ int main(int argc, char **argv)
|
||||||
throw std::string("error opening ") + OutputFilename + "!";
|
throw std::string("error opening ") + OutputFilename + "!";
|
||||||
}
|
}
|
||||||
|
|
||||||
WriteBytecodeToFile(M.get(), *Out);
|
llvm_ostream L(*Out);
|
||||||
|
WriteBytecodeToFile(M.get(), L);
|
||||||
} catch (const ParseError &E) {
|
} catch (const ParseError &E) {
|
||||||
std::cerr << argv[0] << ": " << E.getMessage() << "\n";
|
llvm_cerr << argv[0] << ": " << E.getMessage() << "\n";
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
catch (const std::string& msg ) {
|
catch (const std::string& msg ) {
|
||||||
std::cerr << argv[0] << ": " << msg << "\n";
|
llvm_cerr << argv[0] << ": " << msg << "\n";
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -27,6 +27,7 @@
|
||||||
#include "llvm/Target/TargetData.h"
|
#include "llvm/Target/TargetData.h"
|
||||||
#include "llvm/Support/FileUtilities.h"
|
#include "llvm/Support/FileUtilities.h"
|
||||||
#include "llvm/Support/CommandLine.h"
|
#include "llvm/Support/CommandLine.h"
|
||||||
|
#include "llvm/Support/Streams.h"
|
||||||
#include "llvm/System/Path.h"
|
#include "llvm/System/Path.h"
|
||||||
#include "llvm/System/Program.h"
|
#include "llvm/System/Program.h"
|
||||||
#include "llvm/Config/alloca.h"
|
#include "llvm/Config/alloca.h"
|
||||||
|
@ -55,7 +56,8 @@ bool BugDriver::writeProgramToFile(const std::string &Filename,
|
||||||
std::ofstream Out(Filename.c_str(), io_mode);
|
std::ofstream Out(Filename.c_str(), io_mode);
|
||||||
if (!Out.good()) return true;
|
if (!Out.good()) return true;
|
||||||
try {
|
try {
|
||||||
WriteBytecodeToFile(M ? M : Program, Out, /*compression=*/true);
|
llvm_ostream L(Out);
|
||||||
|
WriteBytecodeToFile(M ? M : Program, L, /*compression=*/true);
|
||||||
} catch (...) {
|
} catch (...) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
@ -72,15 +74,15 @@ void BugDriver::EmitProgressBytecode(const std::string &ID, bool NoFlyer) {
|
||||||
//
|
//
|
||||||
std::string Filename = "bugpoint-" + ID + ".bc";
|
std::string Filename = "bugpoint-" + ID + ".bc";
|
||||||
if (writeProgramToFile(Filename)) {
|
if (writeProgramToFile(Filename)) {
|
||||||
std::cerr << "Error opening file '" << Filename << "' for writing!\n";
|
llvm_cerr << "Error opening file '" << Filename << "' for writing!\n";
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::cout << "Emitted bytecode to '" << Filename << "'\n";
|
llvm_cout << "Emitted bytecode to '" << Filename << "'\n";
|
||||||
if (NoFlyer || PassesToRun.empty()) return;
|
if (NoFlyer || PassesToRun.empty()) return;
|
||||||
std::cout << "\n*** You can reproduce the problem with: ";
|
llvm_cout << "\n*** You can reproduce the problem with: ";
|
||||||
std::cout << "opt " << Filename << " ";
|
llvm_cout << "opt " << Filename << " ";
|
||||||
std::cout << getPassesString(PassesToRun) << "\n";
|
llvm_cout << getPassesString(PassesToRun) << "\n";
|
||||||
}
|
}
|
||||||
|
|
||||||
int BugDriver::runPassesAsChild(const std::vector<const PassInfo*> &Passes) {
|
int BugDriver::runPassesAsChild(const std::vector<const PassInfo*> &Passes) {
|
||||||
|
@ -89,7 +91,7 @@ int BugDriver::runPassesAsChild(const std::vector<const PassInfo*> &Passes) {
|
||||||
std::ios::binary;
|
std::ios::binary;
|
||||||
std::ofstream OutFile(ChildOutput.c_str(), io_mode);
|
std::ofstream OutFile(ChildOutput.c_str(), io_mode);
|
||||||
if (!OutFile.good()) {
|
if (!OutFile.good()) {
|
||||||
std::cerr << "Error opening bytecode file: " << ChildOutput << "\n";
|
llvm_cerr << "Error opening bytecode file: " << ChildOutput << "\n";
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -101,14 +103,15 @@ int BugDriver::runPassesAsChild(const std::vector<const PassInfo*> &Passes) {
|
||||||
if (Passes[i]->getNormalCtor())
|
if (Passes[i]->getNormalCtor())
|
||||||
PM.add(Passes[i]->getNormalCtor()());
|
PM.add(Passes[i]->getNormalCtor()());
|
||||||
else
|
else
|
||||||
std::cerr << "Cannot create pass yet: " << Passes[i]->getPassName()
|
llvm_cerr << "Cannot create pass yet: " << Passes[i]->getPassName()
|
||||||
<< "\n";
|
<< "\n";
|
||||||
}
|
}
|
||||||
// Check that the module is well formed on completion of optimization
|
// Check that the module is well formed on completion of optimization
|
||||||
PM.add(createVerifierPass());
|
PM.add(createVerifierPass());
|
||||||
|
|
||||||
// Write bytecode out to disk as the last step...
|
// Write bytecode out to disk as the last step...
|
||||||
PM.add(new WriteBytecodePass(&OutFile));
|
llvm_ostream L(OutFile);
|
||||||
|
PM.add(new WriteBytecodePass(&L));
|
||||||
|
|
||||||
// Run all queued passes.
|
// Run all queued passes.
|
||||||
PM.run(*Program);
|
PM.run(*Program);
|
||||||
|
@ -128,11 +131,11 @@ bool BugDriver::runPasses(const std::vector<const PassInfo*> &Passes,
|
||||||
std::string &OutputFilename, bool DeleteOutput,
|
std::string &OutputFilename, bool DeleteOutput,
|
||||||
bool Quiet) const {
|
bool Quiet) const {
|
||||||
// setup the output file name
|
// setup the output file name
|
||||||
std::cout << std::flush;
|
llvm_cout << std::flush;
|
||||||
sys::Path uniqueFilename("bugpoint-output.bc");
|
sys::Path uniqueFilename("bugpoint-output.bc");
|
||||||
std::string ErrMsg;
|
std::string ErrMsg;
|
||||||
if (uniqueFilename.makeUnique(true, &ErrMsg)) {
|
if (uniqueFilename.makeUnique(true, &ErrMsg)) {
|
||||||
std::cerr << getToolName() << ": Error making unique filename: "
|
llvm_cerr << getToolName() << ": Error making unique filename: "
|
||||||
<< ErrMsg << "\n";
|
<< ErrMsg << "\n";
|
||||||
return(1);
|
return(1);
|
||||||
}
|
}
|
||||||
|
@ -141,7 +144,7 @@ bool BugDriver::runPasses(const std::vector<const PassInfo*> &Passes,
|
||||||
// set up the input file name
|
// set up the input file name
|
||||||
sys::Path inputFilename("bugpoint-input.bc");
|
sys::Path inputFilename("bugpoint-input.bc");
|
||||||
if (inputFilename.makeUnique(true, &ErrMsg)) {
|
if (inputFilename.makeUnique(true, &ErrMsg)) {
|
||||||
std::cerr << getToolName() << ": Error making unique filename: "
|
llvm_cerr << getToolName() << ": Error making unique filename: "
|
||||||
<< ErrMsg << "\n";
|
<< ErrMsg << "\n";
|
||||||
return(1);
|
return(1);
|
||||||
}
|
}
|
||||||
|
@ -149,10 +152,11 @@ bool BugDriver::runPasses(const std::vector<const PassInfo*> &Passes,
|
||||||
std::ios::binary;
|
std::ios::binary;
|
||||||
std::ofstream InFile(inputFilename.c_str(), io_mode);
|
std::ofstream InFile(inputFilename.c_str(), io_mode);
|
||||||
if (!InFile.good()) {
|
if (!InFile.good()) {
|
||||||
std::cerr << "Error opening bytecode file: " << inputFilename << "\n";
|
llvm_cerr << "Error opening bytecode file: " << inputFilename << "\n";
|
||||||
return(1);
|
return(1);
|
||||||
}
|
}
|
||||||
WriteBytecodeToFile(Program,InFile,false);
|
llvm_ostream L(InFile);
|
||||||
|
WriteBytecodeToFile(Program,L,false);
|
||||||
InFile.close();
|
InFile.close();
|
||||||
|
|
||||||
// setup the child process' arguments
|
// setup the child process' arguments
|
||||||
|
@ -203,17 +207,17 @@ bool BugDriver::runPasses(const std::vector<const PassInfo*> &Passes,
|
||||||
|
|
||||||
if (!Quiet) {
|
if (!Quiet) {
|
||||||
if (result == 0)
|
if (result == 0)
|
||||||
std::cout << "Success!\n";
|
llvm_cout << "Success!\n";
|
||||||
else if (result > 0)
|
else if (result > 0)
|
||||||
std::cout << "Exited with error code '" << result << "'\n";
|
llvm_cout << "Exited with error code '" << result << "'\n";
|
||||||
else if (result < 0) {
|
else if (result < 0) {
|
||||||
if (result == -1)
|
if (result == -1)
|
||||||
std::cout << "Execute failed: " << ErrMsg << "\n";
|
llvm_cout << "Execute failed: " << ErrMsg << "\n";
|
||||||
else
|
else
|
||||||
std::cout << "Crashed with signal #" << abs(result) << "\n";
|
llvm_cout << "Crashed with signal #" << abs(result) << "\n";
|
||||||
}
|
}
|
||||||
if (result & 0x01000000)
|
if (result & 0x01000000)
|
||||||
std::cout << "Dumped core\n";
|
llvm_cout << "Dumped core\n";
|
||||||
}
|
}
|
||||||
|
|
||||||
// Was the child successful?
|
// Was the child successful?
|
||||||
|
@ -231,7 +235,7 @@ Module *BugDriver::runPassesOn(Module *M,
|
||||||
std::string BytecodeResult;
|
std::string BytecodeResult;
|
||||||
if (runPasses(Passes, BytecodeResult, false/*delete*/, true/*quiet*/)) {
|
if (runPasses(Passes, BytecodeResult, false/*delete*/, true/*quiet*/)) {
|
||||||
if (AutoDebugCrashes) {
|
if (AutoDebugCrashes) {
|
||||||
std::cerr << " Error running this sequence of passes"
|
llvm_cerr << " Error running this sequence of passes"
|
||||||
<< " on the input program!\n";
|
<< " on the input program!\n";
|
||||||
delete OldProgram;
|
delete OldProgram;
|
||||||
EmitProgressBytecode("pass-error", false);
|
EmitProgressBytecode("pass-error", false);
|
||||||
|
@ -246,7 +250,7 @@ Module *BugDriver::runPassesOn(Module *M,
|
||||||
|
|
||||||
Module *Ret = ParseInputFile(BytecodeResult);
|
Module *Ret = ParseInputFile(BytecodeResult);
|
||||||
if (Ret == 0) {
|
if (Ret == 0) {
|
||||||
std::cerr << getToolName() << ": Error reading bytecode file '"
|
llvm_cerr << getToolName() << ": Error reading bytecode file '"
|
||||||
<< BytecodeResult << "'!\n";
|
<< BytecodeResult << "'!\n";
|
||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
|
|
|
@ -23,10 +23,11 @@
|
||||||
#include "llvm/Transforms/IPO.h"
|
#include "llvm/Transforms/IPO.h"
|
||||||
#include "llvm/Transforms/Scalar.h"
|
#include "llvm/Transforms/Scalar.h"
|
||||||
#include "llvm/Support/CommandLine.h"
|
#include "llvm/Support/CommandLine.h"
|
||||||
|
#include "llvm/Support/Streams.h"
|
||||||
#include "llvm/System/Signals.h"
|
#include "llvm/System/Signals.h"
|
||||||
|
#include <iostream>
|
||||||
#include <memory>
|
#include <memory>
|
||||||
#include <fstream>
|
#include <fstream>
|
||||||
|
|
||||||
using namespace llvm;
|
using namespace llvm;
|
||||||
|
|
||||||
namespace {
|
namespace {
|
||||||
|
@ -140,7 +141,7 @@ int main(int argc, char **argv) {
|
||||||
ParseError Err;
|
ParseError Err;
|
||||||
std::auto_ptr<Module> M(ParseAssemblyFile(InputFilename,&Err));
|
std::auto_ptr<Module> M(ParseAssemblyFile(InputFilename,&Err));
|
||||||
if (M.get() == 0) {
|
if (M.get() == 0) {
|
||||||
std::cerr << argv[0] << ": " << Err.getMessage() << "\n";
|
llvm_cerr << argv[0] << ": " << Err.getMessage() << "\n";
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -175,7 +176,7 @@ int main(int argc, char **argv) {
|
||||||
|
|
||||||
|
|
||||||
if (!Out->good()) {
|
if (!Out->good()) {
|
||||||
std::cerr << argv[0] << ": error opening " << OutputFilename << "!\n";
|
llvm_cerr << argv[0] << ": error opening " << OutputFilename << "!\n";
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -194,7 +195,8 @@ int main(int argc, char **argv) {
|
||||||
Passes.add(createVerifierPass());
|
Passes.add(createVerifierPass());
|
||||||
|
|
||||||
// Write bytecode to file...
|
// Write bytecode to file...
|
||||||
Passes.add(new WriteBytecodePass(Out,false,!NoCompress));
|
llvm_ostream L(*Out);
|
||||||
|
Passes.add(new WriteBytecodePass(&L,false,!NoCompress));
|
||||||
|
|
||||||
// Run our queue of passes all at once now, efficiently.
|
// Run our queue of passes all at once now, efficiently.
|
||||||
Passes.run(*M.get());
|
Passes.run(*M.get());
|
||||||
|
@ -202,9 +204,9 @@ int main(int argc, char **argv) {
|
||||||
if (Out != &std::cout) delete Out;
|
if (Out != &std::cout) delete Out;
|
||||||
return 0;
|
return 0;
|
||||||
} catch (const std::string& msg) {
|
} catch (const std::string& msg) {
|
||||||
std::cerr << argv[0] << ": " << msg << "\n";
|
llvm_cerr << argv[0] << ": " << msg << "\n";
|
||||||
} catch (...) {
|
} catch (...) {
|
||||||
std::cerr << argv[0] << ": Unexpected unknown exception occurred.\n";
|
llvm_cerr << argv[0] << ": Unexpected unknown exception occurred.\n";
|
||||||
}
|
}
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
|
@ -27,7 +27,7 @@
|
||||||
#include "llvm/Transforms/Scalar.h"
|
#include "llvm/Transforms/Scalar.h"
|
||||||
#include "llvm/Support/SystemUtils.h"
|
#include "llvm/Support/SystemUtils.h"
|
||||||
#include "llvm/Support/CommandLine.h"
|
#include "llvm/Support/CommandLine.h"
|
||||||
|
#include "llvm/Support/Streams.h"
|
||||||
using namespace llvm;
|
using namespace llvm;
|
||||||
|
|
||||||
namespace {
|
namespace {
|
||||||
|
@ -123,10 +123,10 @@ static void RemoveEnv(const char * name, char ** const envp) {
|
||||||
}
|
}
|
||||||
|
|
||||||
static void dumpArgs(const char **args) {
|
static void dumpArgs(const char **args) {
|
||||||
std::cerr << *args++;
|
llvm_cerr << *args++;
|
||||||
while (*args)
|
while (*args)
|
||||||
std::cerr << ' ' << *args++;
|
llvm_cerr << ' ' << *args++;
|
||||||
std::cerr << '\n' << std::flush;
|
llvm_cerr << '\n' << std::flush;
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline void addPass(PassManager &PM, Pass *P) {
|
static inline void addPass(PassManager &PM, Pass *P) {
|
||||||
|
@ -283,7 +283,8 @@ int llvm::GenerateBytecode(Module *M, int StripLevel, bool Internalize,
|
||||||
Passes.add(createVerifierPass());
|
Passes.add(createVerifierPass());
|
||||||
|
|
||||||
// Add the pass that writes bytecode to the output file...
|
// Add the pass that writes bytecode to the output file...
|
||||||
addPass(Passes, new WriteBytecodePass(Out, false, !NoCompress));
|
llvm_ostream L(*Out);
|
||||||
|
addPass(Passes, new WriteBytecodePass(&L, false, !NoCompress));
|
||||||
|
|
||||||
// Run our queue of passes all at once now, efficiently.
|
// Run our queue of passes all at once now, efficiently.
|
||||||
Passes.run(*M);
|
Passes.run(*M);
|
||||||
|
|
|
@ -31,6 +31,7 @@
|
||||||
#include "llvm/Transforms/Scalar.h"
|
#include "llvm/Transforms/Scalar.h"
|
||||||
#include "llvm/Support/CommandLine.h"
|
#include "llvm/Support/CommandLine.h"
|
||||||
#include "llvm/Support/FileUtilities.h"
|
#include "llvm/Support/FileUtilities.h"
|
||||||
|
#include "llvm/Support/Streams.h"
|
||||||
#include "llvm/System/Signals.h"
|
#include "llvm/System/Signals.h"
|
||||||
#include "llvm/Support/SystemUtils.h"
|
#include "llvm/Support/SystemUtils.h"
|
||||||
#include <fstream>
|
#include <fstream>
|
||||||
|
@ -126,7 +127,7 @@ namespace {
|
||||||
/// Message - The message to print to standard error.
|
/// Message - The message to print to standard error.
|
||||||
///
|
///
|
||||||
static int PrintAndReturn(const char *progname, const std::string &Message) {
|
static int PrintAndReturn(const char *progname, const std::string &Message) {
|
||||||
std::cerr << progname << ": " << Message << "\n";
|
llvm_cerr << progname << ": " << Message << "\n";
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -140,11 +141,11 @@ static void EmitShellScript(char **argv) {
|
||||||
std::string ErrMsg;
|
std::string ErrMsg;
|
||||||
sys::Path llvmstub = FindExecutable("llvm-stub.exe", argv[0]);
|
sys::Path llvmstub = FindExecutable("llvm-stub.exe", argv[0]);
|
||||||
if (llvmstub.isEmpty()) {
|
if (llvmstub.isEmpty()) {
|
||||||
std::cerr << "Could not find llvm-stub.exe executable!\n";
|
llvm_cerr << "Could not find llvm-stub.exe executable!\n";
|
||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
if (0 != sys::CopyFile(sys::Path(OutputFilename), llvmstub, &ErrMsg)) {
|
if (0 != sys::CopyFile(sys::Path(OutputFilename), llvmstub, &ErrMsg)) {
|
||||||
std::cerr << argv[0] << ": " << ErrMsg << "\n";
|
llvm_cerr << argv[0] << ": " << ErrMsg << "\n";
|
||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -324,18 +325,18 @@ int main(int argc, char **argv, char **envp ) {
|
||||||
return PrintAndReturn(argv[0], "Failed to find gcc");
|
return PrintAndReturn(argv[0], "Failed to find gcc");
|
||||||
|
|
||||||
// Generate an assembly language file for the bytecode.
|
// Generate an assembly language file for the bytecode.
|
||||||
if (Verbose) std::cout << "Generating Assembly Code\n";
|
if (Verbose) llvm_cout << "Generating Assembly Code\n";
|
||||||
std::string ErrMsg;
|
std::string ErrMsg;
|
||||||
if (0 != GenerateAssembly(
|
if (0 != GenerateAssembly(
|
||||||
AssemblyFile.toString(), RealBytecodeOutput, llc, ErrMsg, Verbose)) {
|
AssemblyFile.toString(), RealBytecodeOutput, llc, ErrMsg, Verbose)) {
|
||||||
std::cerr << argv[0] << ": " << ErrMsg << "\n";
|
llvm_cerr << argv[0] << ": " << ErrMsg << "\n";
|
||||||
return 2;
|
return 2;
|
||||||
}
|
}
|
||||||
if (Verbose) std::cout << "Generating Native Code\n";
|
if (Verbose) llvm_cout << "Generating Native Code\n";
|
||||||
if (0 != GenerateNative(OutputFilename, AssemblyFile.toString(),
|
if (0 != GenerateNative(OutputFilename, AssemblyFile.toString(),
|
||||||
LibPaths, Libraries, gcc, envp, LinkAsLibrary,
|
LibPaths, Libraries, gcc, envp, LinkAsLibrary,
|
||||||
NoInternalize, RPath, SOName, ErrMsg, Verbose) ) {
|
NoInternalize, RPath, SOName, ErrMsg, Verbose) ) {
|
||||||
std::cerr << argv[0] << ": " << ErrMsg << "\n";
|
llvm_cerr << argv[0] << ": " << ErrMsg << "\n";
|
||||||
return 2;
|
return 2;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -364,18 +365,18 @@ int main(int argc, char **argv, char **envp ) {
|
||||||
return PrintAndReturn(argv[0], "Failed to find gcc");
|
return PrintAndReturn(argv[0], "Failed to find gcc");
|
||||||
|
|
||||||
// Generate an assembly language file for the bytecode.
|
// Generate an assembly language file for the bytecode.
|
||||||
if (Verbose) std::cout << "Generating C Source Code\n";
|
if (Verbose) llvm_cout << "Generating C Source Code\n";
|
||||||
std::string ErrMsg;
|
std::string ErrMsg;
|
||||||
if (0 != GenerateCFile(
|
if (0 != GenerateCFile(
|
||||||
CFile.toString(), RealBytecodeOutput, llc, ErrMsg, Verbose)) {
|
CFile.toString(), RealBytecodeOutput, llc, ErrMsg, Verbose)) {
|
||||||
std::cerr << argv[0] << ": " << ErrMsg << "\n";
|
llvm_cerr << argv[0] << ": " << ErrMsg << "\n";
|
||||||
return 2;
|
return 2;
|
||||||
}
|
}
|
||||||
if (Verbose) std::cout << "Generating Native Code\n";
|
if (Verbose) llvm_cout << "Generating Native Code\n";
|
||||||
if (0 != GenerateNative(OutputFilename, CFile.toString(),
|
if (0 != GenerateNative(OutputFilename, CFile.toString(),
|
||||||
LibPaths, Libraries, gcc, envp, LinkAsLibrary,
|
LibPaths, Libraries, gcc, envp, LinkAsLibrary,
|
||||||
NoInternalize, RPath, SOName, ErrMsg, Verbose)) {
|
NoInternalize, RPath, SOName, ErrMsg, Verbose)) {
|
||||||
std::cerr << argv[0] << ": " << ErrMsg << "\n";
|
llvm_cerr << argv[0] << ": " << ErrMsg << "\n";
|
||||||
return 2;
|
return 2;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -392,11 +393,11 @@ int main(int argc, char **argv, char **envp ) {
|
||||||
// Make the bytecode file readable and directly executable in LLEE
|
// Make the bytecode file readable and directly executable in LLEE
|
||||||
std::string ErrMsg;
|
std::string ErrMsg;
|
||||||
if (sys::Path(RealBytecodeOutput).makeExecutableOnDisk(&ErrMsg)) {
|
if (sys::Path(RealBytecodeOutput).makeExecutableOnDisk(&ErrMsg)) {
|
||||||
std::cerr << argv[0] << ": " << ErrMsg << "\n";
|
llvm_cerr << argv[0] << ": " << ErrMsg << "\n";
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
if (sys::Path(RealBytecodeOutput).makeReadableOnDisk(&ErrMsg)) {
|
if (sys::Path(RealBytecodeOutput).makeReadableOnDisk(&ErrMsg)) {
|
||||||
std::cerr << argv[0] << ": " << ErrMsg << "\n";
|
llvm_cerr << argv[0] << ": " << ErrMsg << "\n";
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -404,18 +405,18 @@ int main(int argc, char **argv, char **envp ) {
|
||||||
// Make the output, whether native or script, executable as well...
|
// Make the output, whether native or script, executable as well...
|
||||||
std::string ErrMsg;
|
std::string ErrMsg;
|
||||||
if (sys::Path(OutputFilename).makeExecutableOnDisk(&ErrMsg)) {
|
if (sys::Path(OutputFilename).makeExecutableOnDisk(&ErrMsg)) {
|
||||||
std::cerr << argv[0] << ": " << ErrMsg << "\n";
|
llvm_cerr << argv[0] << ": " << ErrMsg << "\n";
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
} catch (const char*msg) {
|
} catch (const char*msg) {
|
||||||
std::cerr << argv[0] << ": " << msg << "\n";
|
llvm_cerr << argv[0] << ": " << msg << "\n";
|
||||||
exitCode = 1;
|
exitCode = 1;
|
||||||
} catch (const std::string& msg) {
|
} catch (const std::string& msg) {
|
||||||
std::cerr << argv[0] << ": " << msg << "\n";
|
llvm_cerr << argv[0] << ": " << msg << "\n";
|
||||||
exitCode = 2;
|
exitCode = 2;
|
||||||
} catch (...) {
|
} catch (...) {
|
||||||
// This really shouldn't happen, but just in case ....
|
// This really shouldn't happen, but just in case ....
|
||||||
std::cerr << argv[0] << ": An unexpected unknown exception occurred.\n";
|
llvm_cerr << argv[0] << ": An unexpected unknown exception occurred.\n";
|
||||||
exitCode = 3;
|
exitCode = 3;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -20,12 +20,12 @@
|
||||||
#include "llvm/Bytecode/Writer.h"
|
#include "llvm/Bytecode/Writer.h"
|
||||||
#include "llvm/Analysis/Verifier.h"
|
#include "llvm/Analysis/Verifier.h"
|
||||||
#include "llvm/Support/CommandLine.h"
|
#include "llvm/Support/CommandLine.h"
|
||||||
|
#include "llvm/Support/Streams.h"
|
||||||
#include "llvm/Support/SystemUtils.h"
|
#include "llvm/Support/SystemUtils.h"
|
||||||
#include "llvm/System/Signals.h"
|
#include "llvm/System/Signals.h"
|
||||||
#include <fstream>
|
#include <fstream>
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <memory>
|
#include <memory>
|
||||||
|
|
||||||
using namespace llvm;
|
using namespace llvm;
|
||||||
|
|
||||||
static cl::opt<std::string>
|
static cl::opt<std::string>
|
||||||
|
@ -60,27 +60,27 @@ int main(int argc, char **argv) {
|
||||||
ParseError Err;
|
ParseError Err;
|
||||||
std::auto_ptr<Module> M(ParseAssemblyFile(InputFilename,&Err));
|
std::auto_ptr<Module> M(ParseAssemblyFile(InputFilename,&Err));
|
||||||
if (M.get() == 0) {
|
if (M.get() == 0) {
|
||||||
std::cerr << argv[0] << ": " << Err.getMessage() << "\n";
|
llvm_cerr << argv[0] << ": " << Err.getMessage() << "\n";
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!DisableVerify) {
|
if (!DisableVerify) {
|
||||||
std::string Err;
|
std::string Err;
|
||||||
if (verifyModule(*M.get(), ReturnStatusAction, &Err)) {
|
if (verifyModule(*M.get(), ReturnStatusAction, &Err)) {
|
||||||
std::cerr << argv[0]
|
llvm_cerr << argv[0]
|
||||||
<< ": assembly parsed, but does not verify as correct!\n";
|
<< ": assembly parsed, but does not verify as correct!\n";
|
||||||
std::cerr << Err;
|
llvm_cerr << Err;
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (DumpAsm) std::cerr << "Here's the assembly:\n" << *M.get();
|
if (DumpAsm) llvm_cerr << "Here's the assembly:\n" << *M.get();
|
||||||
|
|
||||||
if (OutputFilename != "") { // Specified an output filename?
|
if (OutputFilename != "") { // Specified an output filename?
|
||||||
if (OutputFilename != "-") { // Not stdout?
|
if (OutputFilename != "-") { // Not stdout?
|
||||||
if (!Force && std::ifstream(OutputFilename.c_str())) {
|
if (!Force && std::ifstream(OutputFilename.c_str())) {
|
||||||
// If force is not specified, make sure not to overwrite a file!
|
// If force is not specified, make sure not to overwrite a file!
|
||||||
std::cerr << argv[0] << ": error opening '" << OutputFilename
|
llvm_cerr << argv[0] << ": error opening '" << OutputFilename
|
||||||
<< "': file exists!\n"
|
<< "': file exists!\n"
|
||||||
<< "Use -f command line argument to force output\n";
|
<< "Use -f command line argument to force output\n";
|
||||||
return 1;
|
return 1;
|
||||||
|
@ -108,7 +108,7 @@ int main(int argc, char **argv) {
|
||||||
|
|
||||||
if (!Force && std::ifstream(OutputFilename.c_str())) {
|
if (!Force && std::ifstream(OutputFilename.c_str())) {
|
||||||
// If force is not specified, make sure not to overwrite a file!
|
// If force is not specified, make sure not to overwrite a file!
|
||||||
std::cerr << argv[0] << ": error opening '" << OutputFilename
|
llvm_cerr << argv[0] << ": error opening '" << OutputFilename
|
||||||
<< "': file exists!\n"
|
<< "': file exists!\n"
|
||||||
<< "Use -f command line argument to force output\n";
|
<< "Use -f command line argument to force output\n";
|
||||||
return 1;
|
return 1;
|
||||||
|
@ -123,18 +123,19 @@ int main(int argc, char **argv) {
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!Out->good()) {
|
if (!Out->good()) {
|
||||||
std::cerr << argv[0] << ": error opening " << OutputFilename << "!\n";
|
llvm_cerr << argv[0] << ": error opening " << OutputFilename << "!\n";
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (Force || !CheckBytecodeOutputToConsole(Out,true)) {
|
if (Force || !CheckBytecodeOutputToConsole(Out,true)) {
|
||||||
WriteBytecodeToFile(M.get(), *Out, !NoCompress);
|
llvm_ostream L(*Out);
|
||||||
|
WriteBytecodeToFile(M.get(), L, !NoCompress);
|
||||||
}
|
}
|
||||||
} catch (const std::string& msg) {
|
} catch (const std::string& msg) {
|
||||||
std::cerr << argv[0] << ": " << msg << "\n";
|
llvm_cerr << argv[0] << ": " << msg << "\n";
|
||||||
exitCode = 1;
|
exitCode = 1;
|
||||||
} catch (...) {
|
} catch (...) {
|
||||||
std::cerr << argv[0] << ": Unexpected unknown exception occurred.\n";
|
llvm_cerr << argv[0] << ": Unexpected unknown exception occurred.\n";
|
||||||
exitCode = 1;
|
exitCode = 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -19,7 +19,9 @@
|
||||||
#include "llvm/Transforms/IPO.h"
|
#include "llvm/Transforms/IPO.h"
|
||||||
#include "llvm/Target/TargetData.h"
|
#include "llvm/Target/TargetData.h"
|
||||||
#include "llvm/Support/CommandLine.h"
|
#include "llvm/Support/CommandLine.h"
|
||||||
|
#include "llvm/Support/Streams.h"
|
||||||
#include "llvm/System/Signals.h"
|
#include "llvm/System/Signals.h"
|
||||||
|
#include <iostream>
|
||||||
#include <memory>
|
#include <memory>
|
||||||
#include <fstream>
|
#include <fstream>
|
||||||
using namespace llvm;
|
using namespace llvm;
|
||||||
|
@ -51,14 +53,14 @@ int main(int argc, char **argv) {
|
||||||
|
|
||||||
std::auto_ptr<Module> M(ParseBytecodeFile(InputFilename));
|
std::auto_ptr<Module> M(ParseBytecodeFile(InputFilename));
|
||||||
if (M.get() == 0) {
|
if (M.get() == 0) {
|
||||||
std::cerr << argv[0] << ": bytecode didn't read correctly.\n";
|
llvm_cerr << argv[0] << ": bytecode didn't read correctly.\n";
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Figure out which function we should extract
|
// Figure out which function we should extract
|
||||||
Function *F = M.get()->getNamedFunction(ExtractFunc);
|
Function *F = M.get()->getNamedFunction(ExtractFunc);
|
||||||
if (F == 0) {
|
if (F == 0) {
|
||||||
std::cerr << argv[0] << ": program doesn't contain function named '"
|
llvm_cerr << argv[0] << ": program doesn't contain function named '"
|
||||||
<< ExtractFunc << "'!\n";
|
<< ExtractFunc << "'!\n";
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
@ -78,7 +80,7 @@ int main(int argc, char **argv) {
|
||||||
if (OutputFilename != "-") { // Not stdout?
|
if (OutputFilename != "-") { // Not stdout?
|
||||||
if (!Force && std::ifstream(OutputFilename.c_str())) {
|
if (!Force && std::ifstream(OutputFilename.c_str())) {
|
||||||
// If force is not specified, make sure not to overwrite a file!
|
// If force is not specified, make sure not to overwrite a file!
|
||||||
std::cerr << argv[0] << ": error opening '" << OutputFilename
|
llvm_cerr << argv[0] << ": error opening '" << OutputFilename
|
||||||
<< "': file exists!\n"
|
<< "': file exists!\n"
|
||||||
<< "Use -f command line argument to force output\n";
|
<< "Use -f command line argument to force output\n";
|
||||||
return 1;
|
return 1;
|
||||||
|
@ -91,16 +93,17 @@ int main(int argc, char **argv) {
|
||||||
Out = &std::cout;
|
Out = &std::cout;
|
||||||
}
|
}
|
||||||
|
|
||||||
Passes.add(new WriteBytecodePass(Out)); // Write bytecode to file...
|
llvm_ostream L(*Out);
|
||||||
|
Passes.add(new WriteBytecodePass(&L)); // Write bytecode to file...
|
||||||
Passes.run(*M.get());
|
Passes.run(*M.get());
|
||||||
|
|
||||||
if (Out != &std::cout)
|
if (Out != &std::cout)
|
||||||
delete Out;
|
delete Out;
|
||||||
return 0;
|
return 0;
|
||||||
} catch (const std::string& msg) {
|
} catch (const std::string& msg) {
|
||||||
std::cerr << argv[0] << ": " << msg << "\n";
|
llvm_cerr << argv[0] << ": " << msg << "\n";
|
||||||
} catch (...) {
|
} catch (...) {
|
||||||
std::cerr << argv[0] << ": Unexpected unknown exception occurred.\n";
|
llvm_cerr << argv[0] << ": Unexpected unknown exception occurred.\n";
|
||||||
}
|
}
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
|
@ -32,12 +32,11 @@
|
||||||
#include "llvm/Target/TargetMachineRegistry.h"
|
#include "llvm/Target/TargetMachineRegistry.h"
|
||||||
#include "llvm/Support/CommandLine.h"
|
#include "llvm/Support/CommandLine.h"
|
||||||
#include "llvm/Support/FileUtilities.h"
|
#include "llvm/Support/FileUtilities.h"
|
||||||
|
#include "llvm/Support/Streams.h"
|
||||||
#include "llvm/Support/SystemUtils.h"
|
#include "llvm/Support/SystemUtils.h"
|
||||||
#include "llvm/System/Signals.h"
|
#include "llvm/System/Signals.h"
|
||||||
#include <fstream>
|
#include <fstream>
|
||||||
#include <iostream>
|
|
||||||
#include <memory>
|
#include <memory>
|
||||||
|
|
||||||
using namespace llvm;
|
using namespace llvm;
|
||||||
|
|
||||||
// Input/Output Options
|
// Input/Output Options
|
||||||
|
@ -109,7 +108,7 @@ static std::string progname;
|
||||||
/// Message - The message to print to standard error.
|
/// Message - The message to print to standard error.
|
||||||
///
|
///
|
||||||
static int PrintAndReturn(const std::string &Message) {
|
static int PrintAndReturn(const std::string &Message) {
|
||||||
std::cerr << progname << ": " << Message << "\n";
|
llvm_cerr << progname << ": " << Message << "\n";
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -208,7 +207,8 @@ void GenerateBytecode(Module* M, const std::string& FileName) {
|
||||||
sys::RemoveFileOnSignal(sys::Path(FileName));
|
sys::RemoveFileOnSignal(sys::Path(FileName));
|
||||||
|
|
||||||
// Write it out
|
// Write it out
|
||||||
WriteBytecodeToFile(M, Out, !DisableCompression);
|
llvm_ostream L(Out);
|
||||||
|
WriteBytecodeToFile(M, L, !DisableCompression);
|
||||||
|
|
||||||
// Close the bytecode file.
|
// Close the bytecode file.
|
||||||
Out.close();
|
Out.close();
|
||||||
|
@ -351,12 +351,12 @@ static void EmitShellScript(char **argv) {
|
||||||
std::string ErrMsg;
|
std::string ErrMsg;
|
||||||
sys::Path llvmstub = FindExecutable("llvm-stub.exe", argv[0]);
|
sys::Path llvmstub = FindExecutable("llvm-stub.exe", argv[0]);
|
||||||
if (llvmstub.isEmpty()) {
|
if (llvmstub.isEmpty()) {
|
||||||
std::cerr << "Could not find llvm-stub.exe executable!\n";
|
llvm_cerr << "Could not find llvm-stub.exe executable!\n";
|
||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (0 != sys::CopyFile(sys::Path(OutputFilename), llvmstub, &ErrMsg)) {
|
if (0 != sys::CopyFile(sys::Path(OutputFilename), llvmstub, &ErrMsg)) {
|
||||||
std::cerr << argv[0] << ": " << ErrMsg << "\n";
|
llvm_cerr << argv[0] << ": " << ErrMsg << "\n";
|
||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -518,14 +518,14 @@ int main(int argc, char **argv, char **envp) {
|
||||||
sys::Path target(RealBytecodeOutput);
|
sys::Path target(RealBytecodeOutput);
|
||||||
target.eraseFromDisk();
|
target.eraseFromDisk();
|
||||||
if (tmp_output.renamePathOnDisk(target, &ErrMsg)) {
|
if (tmp_output.renamePathOnDisk(target, &ErrMsg)) {
|
||||||
std::cerr << argv[0] << ": " << ErrMsg << "\n";
|
llvm_cerr << argv[0] << ": " << ErrMsg << "\n";
|
||||||
return 2;
|
return 2;
|
||||||
}
|
}
|
||||||
} else
|
} else
|
||||||
return PrintAndReturn(
|
return PrintAndReturn(
|
||||||
"Post-link optimization output is not bytecode");
|
"Post-link optimization output is not bytecode");
|
||||||
} else {
|
} else {
|
||||||
std::cerr << argv[0] << ": " << ErrMsg << "\n";
|
llvm_cerr << argv[0] << ": " << ErrMsg << "\n";
|
||||||
return 2;
|
return 2;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -554,18 +554,18 @@ int main(int argc, char **argv, char **envp) {
|
||||||
return PrintAndReturn("Failed to find gcc");
|
return PrintAndReturn("Failed to find gcc");
|
||||||
|
|
||||||
// Generate an assembly language file for the bytecode.
|
// Generate an assembly language file for the bytecode.
|
||||||
if (Verbose) std::cout << "Generating Assembly Code\n";
|
if (Verbose) llvm_cout << "Generating Assembly Code\n";
|
||||||
std::string ErrMsg;
|
std::string ErrMsg;
|
||||||
if (0 != GenerateAssembly(AssemblyFile.toString(), RealBytecodeOutput,
|
if (0 != GenerateAssembly(AssemblyFile.toString(), RealBytecodeOutput,
|
||||||
llc, ErrMsg)) {
|
llc, ErrMsg)) {
|
||||||
std::cerr << argv[0] << ": " << ErrMsg << "\n";
|
llvm_cerr << argv[0] << ": " << ErrMsg << "\n";
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (Verbose) std::cout << "Generating Native Code\n";
|
if (Verbose) llvm_cout << "Generating Native Code\n";
|
||||||
if (0 != GenerateNative(OutputFilename, AssemblyFile.toString(),
|
if (0 != GenerateNative(OutputFilename, AssemblyFile.toString(),
|
||||||
LinkItems,gcc,envp,ErrMsg)) {
|
LinkItems,gcc,envp,ErrMsg)) {
|
||||||
std::cerr << argv[0] << ": " << ErrMsg << "\n";
|
llvm_cerr << argv[0] << ": " << ErrMsg << "\n";
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -589,18 +589,18 @@ int main(int argc, char **argv, char **envp) {
|
||||||
return PrintAndReturn("Failed to find gcc");
|
return PrintAndReturn("Failed to find gcc");
|
||||||
|
|
||||||
// Generate an assembly language file for the bytecode.
|
// Generate an assembly language file for the bytecode.
|
||||||
if (Verbose) std::cout << "Generating Assembly Code\n";
|
if (Verbose) llvm_cout << "Generating Assembly Code\n";
|
||||||
std::string ErrMsg;
|
std::string ErrMsg;
|
||||||
if (0 != GenerateCFile(
|
if (0 != GenerateCFile(
|
||||||
CFile.toString(), RealBytecodeOutput, llc, ErrMsg)) {
|
CFile.toString(), RealBytecodeOutput, llc, ErrMsg)) {
|
||||||
std::cerr << argv[0] << ": " << ErrMsg << "\n";
|
llvm_cerr << argv[0] << ": " << ErrMsg << "\n";
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (Verbose) std::cout << "Generating Native Code\n";
|
if (Verbose) llvm_cout << "Generating Native Code\n";
|
||||||
if (0 != GenerateNative(OutputFilename, CFile.toString(), LinkItems,
|
if (0 != GenerateNative(OutputFilename, CFile.toString(), LinkItems,
|
||||||
gcc, envp, ErrMsg)) {
|
gcc, envp, ErrMsg)) {
|
||||||
std::cerr << argv[0] << ": " << ErrMsg << "\n";
|
llvm_cerr << argv[0] << ": " << ErrMsg << "\n";
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -614,26 +614,26 @@ int main(int argc, char **argv, char **envp) {
|
||||||
// Make the script executable...
|
// Make the script executable...
|
||||||
std::string ErrMsg;
|
std::string ErrMsg;
|
||||||
if (sys::Path(OutputFilename).makeExecutableOnDisk(&ErrMsg)) {
|
if (sys::Path(OutputFilename).makeExecutableOnDisk(&ErrMsg)) {
|
||||||
std::cerr << argv[0] << ": " << ErrMsg << "\n";
|
llvm_cerr << argv[0] << ": " << ErrMsg << "\n";
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Make the bytecode file readable and directly executable in LLEE as well
|
// Make the bytecode file readable and directly executable in LLEE as well
|
||||||
if (sys::Path(RealBytecodeOutput).makeExecutableOnDisk(&ErrMsg)) {
|
if (sys::Path(RealBytecodeOutput).makeExecutableOnDisk(&ErrMsg)) {
|
||||||
std::cerr << argv[0] << ": " << ErrMsg << "\n";
|
llvm_cerr << argv[0] << ": " << ErrMsg << "\n";
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
if (sys::Path(RealBytecodeOutput).makeReadableOnDisk(&ErrMsg)) {
|
if (sys::Path(RealBytecodeOutput).makeReadableOnDisk(&ErrMsg)) {
|
||||||
std::cerr << argv[0] << ": " << ErrMsg << "\n";
|
llvm_cerr << argv[0] << ": " << ErrMsg << "\n";
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
} catch (const std::string& msg) {
|
} catch (const std::string& msg) {
|
||||||
std::cerr << argv[0] << ": " << msg << "\n";
|
llvm_cerr << argv[0] << ": " << msg << "\n";
|
||||||
} catch (...) {
|
} catch (...) {
|
||||||
std::cerr << argv[0] << ": Unexpected unknown exception occurred.\n";
|
llvm_cerr << argv[0] << ": Unexpected unknown exception occurred.\n";
|
||||||
}
|
}
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
|
@ -18,12 +18,12 @@
|
||||||
#include "llvm/Bytecode/Reader.h"
|
#include "llvm/Bytecode/Reader.h"
|
||||||
#include "llvm/Bytecode/Writer.h"
|
#include "llvm/Bytecode/Writer.h"
|
||||||
#include "llvm/Support/CommandLine.h"
|
#include "llvm/Support/CommandLine.h"
|
||||||
|
#include "llvm/Support/Streams.h"
|
||||||
#include "llvm/System/Signals.h"
|
#include "llvm/System/Signals.h"
|
||||||
#include "llvm/System/Path.h"
|
#include "llvm/System/Path.h"
|
||||||
#include <fstream>
|
#include <fstream>
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <memory>
|
#include <memory>
|
||||||
|
|
||||||
using namespace llvm;
|
using namespace llvm;
|
||||||
|
|
||||||
static cl::list<std::string>
|
static cl::list<std::string>
|
||||||
|
@ -51,23 +51,23 @@ static cl::opt<bool> NoCompress("disable-compression", cl::init(false),
|
||||||
static inline std::auto_ptr<Module> LoadFile(const std::string &FN) {
|
static inline std::auto_ptr<Module> LoadFile(const std::string &FN) {
|
||||||
sys::Path Filename;
|
sys::Path Filename;
|
||||||
if (!Filename.set(FN)) {
|
if (!Filename.set(FN)) {
|
||||||
std::cerr << "Invalid file name: '" << FN << "'\n";
|
llvm_cerr << "Invalid file name: '" << FN << "'\n";
|
||||||
return std::auto_ptr<Module>();
|
return std::auto_ptr<Module>();
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string ErrorMessage;
|
std::string ErrorMessage;
|
||||||
if (Filename.exists()) {
|
if (Filename.exists()) {
|
||||||
if (Verbose) std::cerr << "Loading '" << Filename.c_str() << "'\n";
|
if (Verbose) llvm_cerr << "Loading '" << Filename.c_str() << "'\n";
|
||||||
Module* Result = ParseBytecodeFile(Filename.toString(), &ErrorMessage);
|
Module* Result = ParseBytecodeFile(Filename.toString(), &ErrorMessage);
|
||||||
if (Result) return std::auto_ptr<Module>(Result); // Load successful!
|
if (Result) return std::auto_ptr<Module>(Result); // Load successful!
|
||||||
|
|
||||||
if (Verbose) {
|
if (Verbose) {
|
||||||
std::cerr << "Error opening bytecode file: '" << Filename.c_str() << "'";
|
llvm_cerr << "Error opening bytecode file: '" << Filename.c_str() << "'";
|
||||||
if (ErrorMessage.size()) std::cerr << ": " << ErrorMessage;
|
if (ErrorMessage.size()) llvm_cerr << ": " << ErrorMessage;
|
||||||
std::cerr << "\n";
|
llvm_cerr << "\n";
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
std::cerr << "Bytecode file: '" << Filename.c_str()
|
llvm_cerr << "Bytecode file: '" << Filename.c_str()
|
||||||
<< "' does not exist.\n";
|
<< "' does not exist.\n";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -85,7 +85,7 @@ int main(int argc, char **argv) {
|
||||||
|
|
||||||
std::auto_ptr<Module> Composite(LoadFile(InputFilenames[BaseArg]));
|
std::auto_ptr<Module> Composite(LoadFile(InputFilenames[BaseArg]));
|
||||||
if (Composite.get() == 0) {
|
if (Composite.get() == 0) {
|
||||||
std::cerr << argv[0] << ": error loading file '"
|
llvm_cerr << argv[0] << ": error loading file '"
|
||||||
<< InputFilenames[BaseArg] << "'\n";
|
<< InputFilenames[BaseArg] << "'\n";
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
@ -93,15 +93,15 @@ int main(int argc, char **argv) {
|
||||||
for (unsigned i = BaseArg+1; i < InputFilenames.size(); ++i) {
|
for (unsigned i = BaseArg+1; i < InputFilenames.size(); ++i) {
|
||||||
std::auto_ptr<Module> M(LoadFile(InputFilenames[i]));
|
std::auto_ptr<Module> M(LoadFile(InputFilenames[i]));
|
||||||
if (M.get() == 0) {
|
if (M.get() == 0) {
|
||||||
std::cerr << argv[0] << ": error loading file '"
|
llvm_cerr << argv[0] << ": error loading file '"
|
||||||
<< InputFilenames[i] << "'\n";
|
<< InputFilenames[i] << "'\n";
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (Verbose) std::cerr << "Linking in '" << InputFilenames[i] << "'\n";
|
if (Verbose) llvm_cerr << "Linking in '" << InputFilenames[i] << "'\n";
|
||||||
|
|
||||||
if (Linker::LinkModules(Composite.get(), M.get(), &ErrorMessage)) {
|
if (Linker::LinkModules(Composite.get(), M.get(), &ErrorMessage)) {
|
||||||
std::cerr << argv[0] << ": link error in '" << InputFilenames[i]
|
llvm_cerr << argv[0] << ": link error in '" << InputFilenames[i]
|
||||||
<< "': " << ErrorMessage << "\n";
|
<< "': " << ErrorMessage << "\n";
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
@ -110,14 +110,14 @@ int main(int argc, char **argv) {
|
||||||
// TODO: Iterate over the -l list and link in any modules containing
|
// TODO: Iterate over the -l list and link in any modules containing
|
||||||
// global symbols that have not been resolved so far.
|
// global symbols that have not been resolved so far.
|
||||||
|
|
||||||
if (DumpAsm) std::cerr << "Here's the assembly:\n" << *Composite.get();
|
if (DumpAsm) llvm_cerr << "Here's the assembly:\n" << *Composite.get();
|
||||||
|
|
||||||
// FIXME: cout is not binary!
|
// FIXME: cout is not binary!
|
||||||
std::ostream *Out = &std::cout; // Default to printing to stdout...
|
std::ostream *Out = &std::cout; // Default to printing to stdout...
|
||||||
if (OutputFilename != "-") {
|
if (OutputFilename != "-") {
|
||||||
if (!Force && std::ifstream(OutputFilename.c_str())) {
|
if (!Force && std::ifstream(OutputFilename.c_str())) {
|
||||||
// If force is not specified, make sure not to overwrite a file!
|
// If force is not specified, make sure not to overwrite a file!
|
||||||
std::cerr << argv[0] << ": error opening '" << OutputFilename
|
llvm_cerr << argv[0] << ": error opening '" << OutputFilename
|
||||||
<< "': file exists!\n"
|
<< "': file exists!\n"
|
||||||
<< "Use -f command line argument to force output\n";
|
<< "Use -f command line argument to force output\n";
|
||||||
return 1;
|
return 1;
|
||||||
|
@ -126,7 +126,7 @@ int main(int argc, char **argv) {
|
||||||
std::ios::binary;
|
std::ios::binary;
|
||||||
Out = new std::ofstream(OutputFilename.c_str(), io_mode);
|
Out = new std::ofstream(OutputFilename.c_str(), io_mode);
|
||||||
if (!Out->good()) {
|
if (!Out->good()) {
|
||||||
std::cerr << argv[0] << ": error opening '" << OutputFilename << "'!\n";
|
llvm_cerr << argv[0] << ": error opening '" << OutputFilename << "'!\n";
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -136,19 +136,20 @@ int main(int argc, char **argv) {
|
||||||
}
|
}
|
||||||
|
|
||||||
if (verifyModule(*Composite.get())) {
|
if (verifyModule(*Composite.get())) {
|
||||||
std::cerr << argv[0] << ": linked module is broken!\n";
|
llvm_cerr << argv[0] << ": linked module is broken!\n";
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (Verbose) std::cerr << "Writing bytecode...\n";
|
if (Verbose) llvm_cerr << "Writing bytecode...\n";
|
||||||
WriteBytecodeToFile(Composite.get(), *Out, !NoCompress);
|
llvm_ostream L(*Out);
|
||||||
|
WriteBytecodeToFile(Composite.get(), L, !NoCompress);
|
||||||
|
|
||||||
if (Out != &std::cout) delete Out;
|
if (Out != &std::cout) delete Out;
|
||||||
return 0;
|
return 0;
|
||||||
} catch (const std::string& msg) {
|
} catch (const std::string& msg) {
|
||||||
std::cerr << argv[0] << ": " << msg << "\n";
|
llvm_cerr << argv[0] << ": " << msg << "\n";
|
||||||
} catch (...) {
|
} catch (...) {
|
||||||
std::cerr << argv[0] << ": Unexpected unknown exception occurred.\n";
|
llvm_cerr << argv[0] << ": Unexpected unknown exception occurred.\n";
|
||||||
}
|
}
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
|
@ -37,10 +37,10 @@
|
||||||
#include "llvm/Transforms/Scalar.h"
|
#include "llvm/Transforms/Scalar.h"
|
||||||
#include "llvm/Analysis/LoadValueNumbering.h"
|
#include "llvm/Analysis/LoadValueNumbering.h"
|
||||||
#include "llvm/Support/MathExtras.h"
|
#include "llvm/Support/MathExtras.h"
|
||||||
|
#include "llvm/Support/Streams.h"
|
||||||
#include "llvm/LinkTimeOptimizer.h"
|
#include "llvm/LinkTimeOptimizer.h"
|
||||||
#include <fstream>
|
#include <fstream>
|
||||||
#include <iostream>
|
#include <ostream>
|
||||||
|
|
||||||
using namespace llvm;
|
using namespace llvm;
|
||||||
|
|
||||||
extern "C"
|
extern "C"
|
||||||
|
@ -361,7 +361,8 @@ LTO::optimizeModules(const std::string &OutputFilename,
|
||||||
std::string tempFileName(FinalOutputPath.c_str());
|
std::string tempFileName(FinalOutputPath.c_str());
|
||||||
tempFileName += "0.bc";
|
tempFileName += "0.bc";
|
||||||
std::ofstream Out(tempFileName.c_str(), io_mode);
|
std::ofstream Out(tempFileName.c_str(), io_mode);
|
||||||
WriteBytecodeToFile(bigOne, Out, true);
|
llvm_ostream L(Out);
|
||||||
|
WriteBytecodeToFile(bigOne, L, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Strip leading underscore because it was added to match names
|
// Strip leading underscore because it was added to match names
|
||||||
|
@ -377,17 +378,17 @@ LTO::optimizeModules(const std::string &OutputFilename,
|
||||||
std::string ErrMsg;
|
std::string ErrMsg;
|
||||||
sys::Path TempDir = sys::Path::GetTemporaryDirectory(&ErrMsg);
|
sys::Path TempDir = sys::Path::GetTemporaryDirectory(&ErrMsg);
|
||||||
if (TempDir.isEmpty()) {
|
if (TempDir.isEmpty()) {
|
||||||
std::cerr << "lto: " << ErrMsg << "\n";
|
llvm_cerr << "lto: " << ErrMsg << "\n";
|
||||||
return LTO_WRITE_FAILURE;
|
return LTO_WRITE_FAILURE;
|
||||||
}
|
}
|
||||||
sys::Path tmpAsmFilePath(TempDir);
|
sys::Path tmpAsmFilePath(TempDir);
|
||||||
if (!tmpAsmFilePath.appendComponent("lto")) {
|
if (!tmpAsmFilePath.appendComponent("lto")) {
|
||||||
std::cerr << "lto: " << ErrMsg << "\n";
|
llvm_cerr << "lto: " << ErrMsg << "\n";
|
||||||
TempDir.eraseFromDisk(true);
|
TempDir.eraseFromDisk(true);
|
||||||
return LTO_WRITE_FAILURE;
|
return LTO_WRITE_FAILURE;
|
||||||
}
|
}
|
||||||
if (tmpAsmFilePath.createTemporaryFileOnDisk(&ErrMsg)) {
|
if (tmpAsmFilePath.createTemporaryFileOnDisk(&ErrMsg)) {
|
||||||
std::cerr << "lto: " << ErrMsg << "\n";
|
llvm_cerr << "lto: " << ErrMsg << "\n";
|
||||||
TempDir.eraseFromDisk(true);
|
TempDir.eraseFromDisk(true);
|
||||||
return LTO_WRITE_FAILURE;
|
return LTO_WRITE_FAILURE;
|
||||||
}
|
}
|
||||||
|
@ -414,7 +415,8 @@ LTO::optimizeModules(const std::string &OutputFilename,
|
||||||
std::string tempFileName(FinalOutputPath.c_str());
|
std::string tempFileName(FinalOutputPath.c_str());
|
||||||
tempFileName += "1.bc";
|
tempFileName += "1.bc";
|
||||||
std::ofstream Out(tempFileName.c_str(), io_mode);
|
std::ofstream Out(tempFileName.c_str(), io_mode);
|
||||||
WriteBytecodeToFile(bigOne, Out, true);
|
llvm_ostream L(Out);
|
||||||
|
WriteBytecodeToFile(bigOne, L, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
targetTriple = bigOne->getTargetTriple();
|
targetTriple = bigOne->getTargetTriple();
|
||||||
|
@ -443,7 +445,7 @@ LTO::optimizeModules(const std::string &OutputFilename,
|
||||||
args.push_back(0);
|
args.push_back(0);
|
||||||
|
|
||||||
if (sys::Program::ExecuteAndWait(gcc, &args[0], 0, 0, 1, &ErrMsg)) {
|
if (sys::Program::ExecuteAndWait(gcc, &args[0], 0, 0, 1, &ErrMsg)) {
|
||||||
std::cerr << "lto: " << ErrMsg << "\n";
|
llvm_cerr << "lto: " << ErrMsg << "\n";
|
||||||
return LTO_ASM_FAILURE;
|
return LTO_ASM_FAILURE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -28,6 +28,7 @@
|
||||||
#include "llvm/Support/Timer.h"
|
#include "llvm/Support/Timer.h"
|
||||||
#include "llvm/LinkAllPasses.h"
|
#include "llvm/LinkAllPasses.h"
|
||||||
#include "llvm/LinkAllVMCore.h"
|
#include "llvm/LinkAllVMCore.h"
|
||||||
|
#include <iostream>
|
||||||
#include <fstream>
|
#include <fstream>
|
||||||
#include <memory>
|
#include <memory>
|
||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
|
@ -251,8 +252,10 @@ int main(int argc, char **argv) {
|
||||||
Passes.add(createVerifierPass());
|
Passes.add(createVerifierPass());
|
||||||
|
|
||||||
// Write bytecode out to disk or cout as the last step...
|
// Write bytecode out to disk or cout as the last step...
|
||||||
if (!NoOutput && !AnalyzeOnly)
|
if (!NoOutput && !AnalyzeOnly) {
|
||||||
Passes.add(new WriteBytecodePass(Out, Out != &std::cout, !NoCompress));
|
llvm_ostream L(*Out);
|
||||||
|
Passes.add(new WriteBytecodePass(&L, Out != &std::cout, !NoCompress));
|
||||||
|
}
|
||||||
|
|
||||||
// Now that we have all of the passes ready, run them.
|
// Now that we have all of the passes ready, run them.
|
||||||
Passes.run(*M.get());
|
Passes.run(*M.get());
|
||||||
|
|
Loading…
Reference in New Issue