mirror of
https://github.com/c64scene-ar/llvm-6502.git
synced 2025-01-07 11:33:44 +00:00
changed implementation of LLVM BYTECODE Length
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@3089 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
parent
db14500d88
commit
0009c2e8b3
@ -10,8 +10,7 @@
|
|||||||
#include "llvm/Pass.h"
|
#include "llvm/Pass.h"
|
||||||
#include "llvm/Bytecode/Writer.h"
|
#include "llvm/Bytecode/Writer.h"
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <sstream>
|
|
||||||
#include <string>
|
|
||||||
using std::ostream;
|
using std::ostream;
|
||||||
|
|
||||||
namespace {
|
namespace {
|
||||||
@ -41,7 +40,7 @@ namespace {
|
|||||||
// as the underlying streambuf to write the data to. This streambuf formats
|
// as the underlying streambuf to write the data to. This streambuf formats
|
||||||
// the output as .byte directives for sparc output.
|
// the output as .byte directives for sparc output.
|
||||||
//
|
//
|
||||||
class osparcasmstream : public ostream {
|
class osparcasmstream : public std::ostream {
|
||||||
sparcasmbuf sb;
|
sparcasmbuf sb;
|
||||||
public:
|
public:
|
||||||
typedef char char_type;
|
typedef char char_type;
|
||||||
@ -49,7 +48,7 @@ namespace {
|
|||||||
typedef std::streampos pos_type;
|
typedef std::streampos pos_type;
|
||||||
typedef std::streamoff off_type;
|
typedef std::streamoff off_type;
|
||||||
|
|
||||||
explicit osparcasmstream(ostream &On) : ostream(&sb), sb(On) { }
|
explicit osparcasmstream(std::ostream &On) : std::ostream(&sb), sb(On) { }
|
||||||
|
|
||||||
sparcasmbuf *rdbuf() const {
|
sparcasmbuf *rdbuf() const {
|
||||||
return const_cast<sparcasmbuf*>(&sb);
|
return const_cast<sparcasmbuf*>(&sb);
|
||||||
@ -67,28 +66,27 @@ namespace {
|
|||||||
virtual bool run(Module &M) {
|
virtual bool run(Module &M) {
|
||||||
// Write bytecode out to the sparc assembly stream
|
// Write bytecode out to the sparc assembly stream
|
||||||
|
|
||||||
|
|
||||||
Out << "\n\n!LLVM BYTECODE OUTPUT\n\t.section \".rodata\"\n\t.align 8\n";
|
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 << "\t.global LLVMBytecode\n\t.type LLVMBytecode,#object\n";
|
||||||
Out << "LLVMBytecode:\n";
|
Out << "LLVMBytecode:\n";
|
||||||
//changed --anand, to get the size of bytecode
|
//changed --anand, to get the size of bytecode
|
||||||
std::ostringstream Ostr;
|
osparcasmstream OS(Out);
|
||||||
osparcasmstream OS(Ostr);
|
|
||||||
WriteBytecodeToFile(&M, OS);
|
WriteBytecodeToFile(&M, OS);
|
||||||
|
|
||||||
//compute length: count number of "."
|
|
||||||
std::string myString=Ostr.str();
|
|
||||||
int llvm_len=0;
|
|
||||||
for(std::string::iterator si=myString.begin(), se=myString.end(); si!=se; si++)
|
|
||||||
if(*si == '.')
|
|
||||||
llvm_len++;
|
|
||||||
|
|
||||||
//now put Ostr into Out
|
|
||||||
//count no of
|
|
||||||
Out<<Ostr.str();
|
|
||||||
Out << ".end_LLVMBytecode:\n";
|
Out << ".end_LLVMBytecode:\n";
|
||||||
Out << "\t.size LLVMBytecode, .end_LLVMBytecode-LLVMBytecode\n\n";
|
Out << "\t.size LLVMBytecode, .end_LLVMBytecode-LLVMBytecode\n\n";
|
||||||
|
|
||||||
Out <<"\n\n!LLVM BYTECODE Length\n\t.section \".data\",#alloc,#write\n\t.global llvm_length\n\t.align 4\n\t.type llvm_length,#object\n\t.size llvm_length,4\nllvm_length:\n\t.word "<<llvm_len<<"\n";
|
|
||||||
|
Out <<"\n\n!LLVM BYTECODE Length\n";
|
||||||
|
Out <<"\t.section \".data\",#alloc,#write\n";
|
||||||
|
Out <<"\t.global llvm_length\n";
|
||||||
|
Out <<"\t.align 4\n";
|
||||||
|
Out <<"\t.type llvm_length,#object\n";
|
||||||
|
Out <<"\t.size llvm_length,4\n";
|
||||||
|
Out <<"llvm_length:\n";
|
||||||
|
Out <<"\t.word\t.end_LLVMBytecode-LLVMBytecode\n";
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
Loading…
Reference in New Issue
Block a user