aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorChris Lattner <sabre@nondot.org>2002-02-11 22:35:46 +0000
committerChris Lattner <sabre@nondot.org>2002-02-11 22:35:46 +0000
commit9530a6f3cd8d071c260baa12f28d66f9d6f983d1 (patch)
tree9f09243fcfb9317d5c45e7105c0e85e410af24ff
parent355df3f73d6eabc7ce236c0204fe155996543d08 (diff)
downloadexternal_llvm-9530a6f3cd8d071c260baa12f28d66f9d6f983d1.zip
external_llvm-9530a6f3cd8d071c260baa12f28d66f9d6f983d1.tar.gz
external_llvm-9530a6f3cd8d071c260baa12f28d66f9d6f983d1.tar.bz2
Write llvm bytecode to output .s file as last step of LLC.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@1728 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r--lib/Target/SparcV9/EmitBytecodeToAssembly.cpp77
-rw-r--r--lib/Target/SparcV9/SparcV9Internals.h1
-rw-r--r--lib/Target/SparcV9/SparcV9TargetMachine.cpp3
3 files changed, 81 insertions, 0 deletions
diff --git a/lib/Target/SparcV9/EmitBytecodeToAssembly.cpp b/lib/Target/SparcV9/EmitBytecodeToAssembly.cpp
new file mode 100644
index 0000000..7cbf085
--- /dev/null
+++ b/lib/Target/SparcV9/EmitBytecodeToAssembly.cpp
@@ -0,0 +1,77 @@
+//===-- EmitBytecodeToAssembly.cpp - Emit bytecode to Sparc .s File --------==//
+//
+// This file implements the pass that writes LLVM bytecode as data to a sparc
+// assembly file. The bytecode gets assembled into a special bytecode section
+// of the executable for use at runtime later.
+//
+//===----------------------------------------------------------------------===//
+
+#include "SparcInternals.h"
+#include "llvm/Bytecode/Writer.h"
+
+namespace {
+
+ // sparcasmbuf - stream buf for encoding output bytes as .byte directives for
+ // the sparc assembler.
+ //
+ class sparcasmbuf : public streambuf {
+ std::ostream &BaseStr;
+ public:
+ typedef char char_type;
+ typedef int int_type;
+ typedef streampos pos_type;
+ typedef streamoff off_type;
+
+ sparcasmbuf(std::ostream &On) : BaseStr(On) {}
+
+ virtual int_type overflow(int_type C) {
+ if (C != EOF)
+ BaseStr << "\t.byte " << C << "\n"; // Output C;
+ return C;
+ }
+ };
+
+
+ // osparcasmstream - Define an ostream implementation that uses a sparcasmbuf
+ // as the underlying streambuf to write the data to. This streambuf formats
+ // the output as .byte directives for sparc output.
+ //
+ class osparcasmstream : public ostream {
+ sparcasmbuf sb;
+ public:
+ typedef char char_type;
+ typedef int int_type;
+ typedef streampos pos_type;
+ typedef streamoff off_type;
+
+ explicit osparcasmstream(ostream &On) : ostream(&sb), sb(On) { }
+
+ sparcasmbuf *rdbuf() const {
+ return const_cast<sparcasmbuf*>(&sb);
+ }
+ };
+
+ // SparcBytecodeWriter - Write bytecode out to a stream that is sparc'ified
+ class SparcBytecodeWriter : public Pass {
+ std::ostream &Out;
+ public:
+ SparcBytecodeWriter(std::ostream &out) : Out(out) {}
+
+ virtual bool run(Module *M) {
+ // Write bytecode out to the sparc assembly stream
+ Out << "\n\n!LLVM BYTECODE OUTPUT\n\t.section \".rodata\"\n\t.align 8\n";
+ Out << "\t.global LLVMBytecode\n\t.type LLVMBytecode,#object\n";
+ Out << "LLVMBytecode:\n";
+ osparcasmstream OS(Out);
+ WriteBytecodeToFile(M, OS);
+
+ Out << ".end_LLVMBytecode:\n";
+ Out << "\t.size LLVMBytecode, .end_LLVMBytecode-LLVMBytecode\n\n";
+ return false;
+ }
+ };
+} // end anonymous namespace
+
+Pass *UltraSparc::getEmitBytecodeToAsmPass(std::ostream &Out) {
+ return new SparcBytecodeWriter(Out);
+}
diff --git a/lib/Target/SparcV9/SparcV9Internals.h b/lib/Target/SparcV9/SparcV9Internals.h
index ad3f478b..73f02c3 100644
--- a/lib/Target/SparcV9/SparcV9Internals.h
+++ b/lib/Target/SparcV9/SparcV9Internals.h
@@ -607,6 +607,7 @@ public:
private:
Pass *getMethodAsmPrinterPass(PassManager &PM, std::ostream &Out);
Pass *getModuleAsmPrinterPass(PassManager &PM, std::ostream &Out);
+ Pass *getEmitBytecodeToAsmPass(std::ostream &Out);
};
#endif
diff --git a/lib/Target/SparcV9/SparcV9TargetMachine.cpp b/lib/Target/SparcV9/SparcV9TargetMachine.cpp
index 422dda0..14be992 100644
--- a/lib/Target/SparcV9/SparcV9TargetMachine.cpp
+++ b/lib/Target/SparcV9/SparcV9TargetMachine.cpp
@@ -269,4 +269,7 @@ void UltraSparc::addPassesToEmitAssembly(PassManager &PM, std::ostream &Out) {
// Emit Module level assembly after all of the methods have been processed.
PM.add(getModuleAsmPrinterPass(PM, Out));
+
+ // Emit bytecode to the sparc assembly file into its special section next
+ PM.add(getEmitBytecodeToAsmPass(Out));
}