summaryrefslogtreecommitdiff
path: root/examples
diff options
context:
space:
mode:
authorChris Lattner <sabre@nondot.org>2009-08-23 07:49:08 +0000
committerChris Lattner <sabre@nondot.org>2009-08-23 07:49:08 +0000
commitb515d75856f58a8b3b71d782eb00916d686329ad (patch)
treef44504088f40b4ba59e2583c25ea523e8c15ae82 /examples
parenta81d29b3916c2eb87a17f800f3759ce21a4a96fd (diff)
eliminate the std::ostream forms of the bitcode writing APIs.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@79840 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'examples')
-rw-r--r--examples/BrainF/BrainFDriver.cpp39
-rw-r--r--examples/ModuleMaker/ModuleMaker.cpp4
2 files changed, 22 insertions, 21 deletions
diff --git a/examples/BrainF/BrainFDriver.cpp b/examples/BrainF/BrainFDriver.cpp
index f4f1e79b822..ad8a922b50c 100644
--- a/examples/BrainF/BrainFDriver.cpp
+++ b/examples/BrainF/BrainFDriver.cpp
@@ -32,11 +32,12 @@
#include "llvm/Bitcode/ReaderWriter.h"
#include "llvm/ExecutionEngine/GenericValue.h"
#include "llvm/ExecutionEngine/JIT.h"
+#include "llvm/Target/TargetSelect.h"
#include "llvm/Support/CommandLine.h"
#include "llvm/Support/ManagedStatic.h"
-#include "llvm/Target/TargetSelect.h"
-#include <fstream>
+#include "llvm/Support/raw_ostream.h"
#include <iostream>
+#include <fstream>
using namespace llvm;
//Command line options
@@ -91,50 +92,49 @@ int main(int argc, char **argv) {
LLVMContext &Context = getGlobalContext();
if (InputFilename == "") {
- std::cerr<<"Error: You must specify the filename of the program to "
+ errs() << "Error: You must specify the filename of the program to "
"be compiled. Use --help to see the options.\n";
abort();
}
//Get the output stream
- std::ostream *out = &std::cout;
+ raw_ostream *out = &outs();
if (!JIT) {
if (OutputFilename == "") {
std::string base = InputFilename;
- if (InputFilename == "-") {base = "a";}
+ if (InputFilename == "-") { base = "a"; }
- //Use default filename
- const char *suffix = ".bc";
- OutputFilename = base+suffix;
+ // Use default filename.
+ OutputFilename = base+".bc";
}
if (OutputFilename != "-") {
- out = new std::
- ofstream(OutputFilename.c_str(),
- std::ios::out | std::ios::trunc | std::ios::binary);
+ std::string ErrInfo;
+ out = new raw_fd_ostream(OutputFilename.c_str(), ErrInfo,
+ raw_fd_ostream::F_Force|
+ raw_fd_ostream::F_Binary);
}
}
//Get the input stream
std::istream *in = &std::cin;
- if (InputFilename != "-") {
+ if (InputFilename != "-")
in = new std::ifstream(InputFilename.c_str());
- }
//Gather the compile flags
BrainF::CompileFlags cf = BrainF::flag_off;
- if (ArrayBoundsChecking) {
+ if (ArrayBoundsChecking)
cf = BrainF::CompileFlags(cf | BrainF::flag_arraybounds);
- }
//Read the BrainF program
BrainF bf;
Module *mod = bf.parse(in, 65536, cf, Context); //64 KiB
- if (in != &std::cin) {delete in;}
+ if (in != &std::cin)
+ delete in;
addMainFunction(mod);
//Verify generated code
if (verifyModule(*mod)) {
- std::cerr<<"Error: module failed verification. This shouldn't happen.\n";
+ errs() << "Error: module failed verification. This shouldn't happen.\n";
abort();
}
@@ -142,7 +142,7 @@ int main(int argc, char **argv) {
if (JIT) {
InitializeNativeTarget();
- std::cout << "------- Running JIT -------\n";
+ outs() << "------- Running JIT -------\n";
ExecutionEngine *ee = EngineBuilder(mod).create();
std::vector<GenericValue> args;
Function *brainf_func = mod->getFunction("brainf");
@@ -152,7 +152,8 @@ int main(int argc, char **argv) {
}
//Clean up
- if (out != &std::cout) {delete out;}
+ if (out != &outs())
+ delete out;
delete mod;
llvm_shutdown();
diff --git a/examples/ModuleMaker/ModuleMaker.cpp b/examples/ModuleMaker/ModuleMaker.cpp
index ded78c7b17a..6bc52c12a03 100644
--- a/examples/ModuleMaker/ModuleMaker.cpp
+++ b/examples/ModuleMaker/ModuleMaker.cpp
@@ -19,7 +19,7 @@
#include "llvm/Constants.h"
#include "llvm/Instructions.h"
#include "llvm/Bitcode/ReaderWriter.h"
-#include <iostream>
+#include "llvm/Support/raw_ostream.h"
using namespace llvm;
int main() {
@@ -56,7 +56,7 @@ int main() {
BB->getInstList().push_back(ReturnInst::Create(Context, Add));
// Output the bitcode file to stdout
- WriteBitcodeToFile(M, std::cout);
+ WriteBitcodeToFile(M, outs());
// Delete the module and all of its contents.
delete M;