mirror of
https://github.com/c64scene-ar/llvm-6502.git
synced 2025-09-26 09:18:56 +00:00
Changes to build successfully with GCC 3.02
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@1503 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
@@ -14,8 +14,9 @@
|
||||
#include "llvm/ConstantVals.h"
|
||||
#include "llvm/GlobalVariable.h"
|
||||
#include <algorithm>
|
||||
|
||||
|
||||
#include <iostream>
|
||||
using std::make_pair;
|
||||
using std::cerr;
|
||||
|
||||
const Type *BytecodeParser::parseTypeConstant(const uchar *&Buf,
|
||||
const uchar *EndBuf) {
|
||||
@@ -36,7 +37,7 @@ const Type *BytecodeParser::parseTypeConstant(const uchar *&Buf,
|
||||
unsigned NumParams;
|
||||
if (read_vbr(Buf, EndBuf, NumParams)) return failure(Val);
|
||||
|
||||
vector<const Type*> Params;
|
||||
std::vector<const Type*> Params;
|
||||
while (NumParams--) {
|
||||
if (read_vbr(Buf, EndBuf, Typ)) return failure(Val);
|
||||
const Type *Ty = getType(Typ);
|
||||
@@ -59,12 +60,12 @@ const Type *BytecodeParser::parseTypeConstant(const uchar *&Buf,
|
||||
if (read_vbr(Buf, EndBuf, NumElements)) return failure(Val);
|
||||
|
||||
BCR_TRACE(5, "Array Type Constant #" << ElTyp << " size="
|
||||
<< NumElements << endl);
|
||||
<< NumElements << "\n");
|
||||
return ArrayType::get(ElementType, NumElements);
|
||||
}
|
||||
case Type::StructTyID: {
|
||||
unsigned Typ;
|
||||
vector<const Type*> Elements;
|
||||
std::vector<const Type*> Elements;
|
||||
|
||||
if (read_vbr(Buf, EndBuf, Typ)) return failure(Val);
|
||||
while (Typ) { // List is terminated by void/0 typeid
|
||||
@@ -80,7 +81,7 @@ const Type *BytecodeParser::parseTypeConstant(const uchar *&Buf,
|
||||
case Type::PointerTyID: {
|
||||
unsigned ElTyp;
|
||||
if (read_vbr(Buf, EndBuf, ElTyp)) return failure(Val);
|
||||
BCR_TRACE(5, "Pointer Type Constant #" << (ElTyp-14) << endl);
|
||||
BCR_TRACE(5, "Pointer Type Constant #" << (ElTyp-14) << "\n");
|
||||
const Type *ElementType = getType(ElTyp);
|
||||
if (ElementType == 0) return failure(Val);
|
||||
return PointerType::get(ElementType);
|
||||
@@ -241,7 +242,7 @@ bool BytecodeParser::parseConstantValue(const uchar *&Buf, const uchar *EndBuf,
|
||||
const ArrayType *AT = cast<const ArrayType>(Ty);
|
||||
unsigned NumElements = AT->getNumElements();
|
||||
|
||||
vector<Constant*> Elements;
|
||||
std::vector<Constant*> Elements;
|
||||
while (NumElements--) { // Read all of the elements of the constant.
|
||||
unsigned Slot;
|
||||
if (read_vbr(Buf, EndBuf, Slot)) return failure(true);
|
||||
@@ -257,7 +258,7 @@ bool BytecodeParser::parseConstantValue(const uchar *&Buf, const uchar *EndBuf,
|
||||
const StructType *ST = cast<StructType>(Ty);
|
||||
const StructType::ElementTypes &ET = ST->getElementTypes();
|
||||
|
||||
vector<Constant *> Elements;
|
||||
std::vector<Constant *> Elements;
|
||||
for (unsigned i = 0; i < ET.size(); ++i) {
|
||||
unsigned Slot;
|
||||
if (read_vbr(Buf, EndBuf, Slot)) return failure(true);
|
||||
|
@@ -16,6 +16,9 @@
|
||||
#include "llvm/iMemory.h"
|
||||
#include "llvm/iPHINode.h"
|
||||
#include "llvm/iOther.h"
|
||||
#include <iostream>
|
||||
using std::vector;
|
||||
using std::cerr;
|
||||
|
||||
bool BytecodeParser::ParseRawInst(const uchar *&Buf, const uchar *EndBuf,
|
||||
RawInst &Result) {
|
||||
@@ -107,7 +110,7 @@ bool BytecodeParser::ParseRawInst(const uchar *&Buf, const uchar *EndBuf,
|
||||
#if 0
|
||||
cerr << "NO: " << Result.NumOperands << " opcode: " << Result.Opcode
|
||||
<< " Ty: " << Result.Ty->getDescription() << " arg1: " << Result.Arg1
|
||||
<< " arg2: " << Result.Arg2 << " arg3: " << Result.Arg3 << endl;
|
||||
<< " arg2: " << Result.Arg2 << " arg3: " << Result.Arg3 << "\n";
|
||||
#endif
|
||||
return false;
|
||||
}
|
||||
@@ -441,6 +444,6 @@ bool BytecodeParser::ParseInstruction(const uchar *&Buf, const uchar *EndBuf,
|
||||
} // end switch(Raw.Opcode)
|
||||
|
||||
cerr << "Unrecognized instruction! " << Raw.Opcode
|
||||
<< " ADDR = 0x" << (void*)Buf << endl;
|
||||
<< " ADDR = 0x" << (void*)Buf << "\n";
|
||||
return failure(true);
|
||||
}
|
||||
|
@@ -20,11 +20,15 @@
|
||||
#include "llvm/iPHINode.h"
|
||||
#include "llvm/iOther.h"
|
||||
#include <sys/types.h>
|
||||
#include <sys/mman.h>
|
||||
typedef int blksize_t;
|
||||
#include <sys/stat.h>
|
||||
#include <sys/mman.h>
|
||||
#include <fcntl.h>
|
||||
#include <unistd.h>
|
||||
#include <algorithm>
|
||||
#include <iostream>
|
||||
using std::cerr;
|
||||
using std::make_pair;
|
||||
|
||||
bool BytecodeParser::getTypeSlot(const Type *Ty, unsigned &Slot) {
|
||||
if (Ty->isPrimitiveType()) {
|
||||
@@ -42,7 +46,7 @@ bool BytecodeParser::getTypeSlot(const Type *Ty, unsigned &Slot) {
|
||||
Slot = FirstDerivedTyID + (&*I - &ModuleTypeValues[0]);
|
||||
}
|
||||
}
|
||||
//cerr << "getTypeSlot '" << Ty->getName() << "' = " << Slot << endl;
|
||||
//cerr << "getTypeSlot '" << Ty->getName() << "' = " << Slot << "\n";
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -50,7 +54,7 @@ const Type *BytecodeParser::getType(unsigned ID) {
|
||||
const Type *T = Type::getPrimitiveType((Type::PrimitiveID)ID);
|
||||
if (T) return T;
|
||||
|
||||
//cerr << "Looking up Type ID: " << ID << endl;
|
||||
//cerr << "Looking up Type ID: " << ID << "\n";
|
||||
|
||||
const Value *D = getValue(Type::TypeTy, ID, false);
|
||||
if (D == 0) return failure<const Type*>(0);
|
||||
@@ -58,7 +62,7 @@ const Type *BytecodeParser::getType(unsigned ID) {
|
||||
return cast<Type>(D);
|
||||
}
|
||||
|
||||
int BytecodeParser::insertValue(Value *Val, vector<ValueList> &ValueTab) {
|
||||
int BytecodeParser::insertValue(Value *Val, std::vector<ValueList> &ValueTab) {
|
||||
unsigned type;
|
||||
if (getTypeSlot(Val->getType(), type)) return failure<int>(-1);
|
||||
assert(type != Type::TypeTyID && "Types should never be insertValue'd!");
|
||||
@@ -67,7 +71,7 @@ int BytecodeParser::insertValue(Value *Val, vector<ValueList> &ValueTab) {
|
||||
ValueTab.resize(type+1, ValueList());
|
||||
|
||||
//cerr << "insertValue Values[" << type << "][" << ValueTab[type].size()
|
||||
// << "] = " << Val << endl;
|
||||
// << "] = " << Val << "\n";
|
||||
ValueTab[type].push_back(Val);
|
||||
|
||||
return ValueTab[type].size()-1;
|
||||
@@ -115,7 +119,7 @@ Value *BytecodeParser::getValue(const Type *Ty, unsigned oNum, bool Create) {
|
||||
case Type::LabelTyID: d = new BBPHolder(Ty, oNum); break;
|
||||
case Type::MethodTyID:
|
||||
cerr << "Creating method pholder! : " << type << ":" << oNum << " "
|
||||
<< Ty->getName() << endl;
|
||||
<< Ty->getName() << "\n";
|
||||
d = new MethPHolder(Ty, oNum);
|
||||
if (insertValue(d, LateResolveModuleValues) ==-1) return failure<Value*>(0);
|
||||
return d;
|
||||
@@ -196,17 +200,17 @@ bool BytecodeParser::ParseSymbolTable(const uchar *&Buf, const uchar *EndBuf,
|
||||
// Symtab entry: [def slot #][name]
|
||||
unsigned slot;
|
||||
if (read_vbr(Buf, EndBuf, slot)) return failure(true);
|
||||
string Name;
|
||||
std::string Name;
|
||||
if (read(Buf, EndBuf, Name, false)) // Not aligned...
|
||||
return failure(true);
|
||||
|
||||
Value *D = getValue(Ty, slot, false); // Find mapping...
|
||||
if (D == 0) {
|
||||
BCR_TRACE(3, "FAILED LOOKUP: Slot #" << slot << endl);
|
||||
BCR_TRACE(3, "FAILED LOOKUP: Slot #" << slot << "\n");
|
||||
return failure(true);
|
||||
}
|
||||
BCR_TRACE(4, "Map: '" << Name << "' to #" << slot << ":" << D;
|
||||
if (!isa<Instruction>(D)) cerr << endl);
|
||||
if (!isa<Instruction>(D)) cerr << "\n");
|
||||
|
||||
D->setName(Name, ST);
|
||||
}
|
||||
@@ -272,7 +276,7 @@ bool BytecodeParser::ParseMethod(const uchar *&Buf, const uchar *EndBuf,
|
||||
MethodSignatureList.pop_front();
|
||||
Method *M = new Method(MTy, isInternal != 0);
|
||||
|
||||
BCR_TRACE(2, "METHOD TYPE: " << MTy << endl);
|
||||
BCR_TRACE(2, "METHOD TYPE: " << MTy << "\n");
|
||||
|
||||
const MethodType::ParamTypes &Params = MTy->getParamTypes();
|
||||
for (MethodType::ParamTypes::const_iterator It = Params.begin();
|
||||
@@ -418,7 +422,7 @@ bool BytecodeParser::ParseModuleGlobalInfo(const uchar *&Buf, const uchar *End,
|
||||
DeclareNewGlobalValue(GV, unsigned(DestSlot));
|
||||
|
||||
BCR_TRACE(2, "Global Variable of type: " << PTy->getDescription()
|
||||
<< " into slot #" << DestSlot << endl);
|
||||
<< " into slot #" << DestSlot << "\n");
|
||||
|
||||
if (read_vbr(Buf, End, VarType)) return failure(true);
|
||||
}
|
||||
@@ -459,7 +463,7 @@ bool BytecodeParser::ParseModuleGlobalInfo(const uchar *&Buf, const uchar *End,
|
||||
MethodSignatureList.push_back(
|
||||
make_pair(cast<const PointerType>(Val->getType()), SlotNo));
|
||||
if (read_vbr(Buf, End, MethSignature)) return failure(true);
|
||||
BCR_TRACE(2, "Method of type: " << Ty << endl);
|
||||
BCR_TRACE(2, "Method of type: " << Ty << "\n");
|
||||
}
|
||||
|
||||
if (align32(Buf, End)) return failure(true);
|
||||
@@ -566,11 +570,11 @@ Module *ParseBytecodeBuffer(const uchar *Buffer, unsigned Length) {
|
||||
|
||||
// Parse and return a class file...
|
||||
//
|
||||
Module *ParseBytecodeFile(const string &Filename, string *ErrorStr) {
|
||||
Module *ParseBytecodeFile(const std::string &Filename, std::string *ErrorStr) {
|
||||
struct stat StatBuf;
|
||||
Module *Result = 0;
|
||||
|
||||
if (Filename != string("-")) { // Read from a file...
|
||||
if (Filename != std::string("-")) { // Read from a file...
|
||||
int FD = open(Filename.c_str(), O_RDONLY);
|
||||
if (FD == -1) {
|
||||
if (ErrorStr) *ErrorStr = "Error opening file!";
|
||||
|
@@ -21,7 +21,7 @@
|
||||
|
||||
#if TRACE_LEVEL // ByteCodeReading_TRACEer
|
||||
#include "llvm/Assembly/Writer.h"
|
||||
#define BCR_TRACE(n, X) if (n < TRACE_LEVEL) cerr << string(n*2, ' ') << X
|
||||
#define BCR_TRACE(n, X) if (n < TRACE_LEVEL) cerr << std::string(n*2, ' ') << X
|
||||
#else
|
||||
#define BCR_TRACE(n, X)
|
||||
#endif
|
||||
@@ -41,12 +41,12 @@ struct RawInst { // The raw fields out of the bytecode stream...
|
||||
unsigned Arg1, Arg2;
|
||||
union {
|
||||
unsigned Arg3;
|
||||
vector<unsigned> *VarArgs; // Contains arg #3,4,5... if NumOperands > 3
|
||||
std::vector<unsigned> *VarArgs; // Contains arg #3,4,5... if NumOperands > 3
|
||||
};
|
||||
};
|
||||
|
||||
class BytecodeParser : public AbstractTypeUser {
|
||||
string Error; // Error message string goes here...
|
||||
std::string Error; // Error message string goes here...
|
||||
public:
|
||||
BytecodeParser() {
|
||||
// Define this in case we don't see a ModuleGlobalInfo block.
|
||||
@@ -55,13 +55,13 @@ public:
|
||||
|
||||
Module *ParseBytecode(const uchar *Buf, const uchar *EndBuf);
|
||||
|
||||
string getError() const { return Error; }
|
||||
std::string getError() const { return Error; }
|
||||
|
||||
private: // All of this data is transient across calls to ParseBytecode
|
||||
Module *TheModule; // Current Module being read into...
|
||||
|
||||
typedef vector<Value *> ValueList;
|
||||
typedef vector<ValueList> ValueTable;
|
||||
typedef std::vector<Value *> ValueList;
|
||||
typedef std::vector<ValueList> ValueTable;
|
||||
ValueTable Values, LateResolveValues;
|
||||
ValueTable ModuleValues, LateResolveModuleValues;
|
||||
|
||||
@@ -70,14 +70,14 @@ private: // All of this data is transient across calls to ParseBytecode
|
||||
// are defined, and if so, the temporary object that they represent is held
|
||||
// here.
|
||||
//
|
||||
typedef map<pair<const PointerType *, unsigned>, GlobalVariable*>
|
||||
GlobalRefsType;
|
||||
typedef std::map<std::pair<const PointerType *, unsigned>,
|
||||
GlobalVariable*> GlobalRefsType;
|
||||
GlobalRefsType GlobalRefs;
|
||||
|
||||
// TypesLoaded - This vector mirrors the Values[TypeTyID] plane. It is used
|
||||
// to deal with forward references to types.
|
||||
//
|
||||
typedef vector<PATypeHandle<Type> > TypeValuesListTy;
|
||||
typedef std::vector<PATypeHandle<Type> > TypeValuesListTy;
|
||||
TypeValuesListTy ModuleTypeValues;
|
||||
TypeValuesListTy MethodTypeValues;
|
||||
|
||||
@@ -89,11 +89,11 @@ private: // All of this data is transient across calls to ParseBytecode
|
||||
// into its slot to reserve it. When the method is loaded, this placeholder
|
||||
// is replaced.
|
||||
//
|
||||
list<pair<const PointerType *, unsigned> > MethodSignatureList;
|
||||
std::list<std::pair<const PointerType *, unsigned> > MethodSignatureList;
|
||||
|
||||
private:
|
||||
bool ParseModule (const uchar * Buf, const uchar *End, Module *&);
|
||||
bool ParseModuleGlobalInfo (const uchar *&Buf, const uchar *End, Module *);
|
||||
bool ParseModule (const uchar * Buf, const uchar *End, Module *&);
|
||||
bool ParseModuleGlobalInfo(const uchar *&Buf, const uchar *End, Module *);
|
||||
bool ParseSymbolTable (const uchar *&Buf, const uchar *End, SymbolTable *);
|
||||
bool ParseMethod (const uchar *&Buf, const uchar *End, Module *);
|
||||
bool ParseBasicBlock (const uchar *&Buf, const uchar *End, BasicBlock *&);
|
||||
@@ -111,7 +111,7 @@ private:
|
||||
Value *getValue(const Type *Ty, unsigned num, bool Create = true);
|
||||
const Type *getType(unsigned ID);
|
||||
|
||||
int insertValue(Value *D, vector<ValueList> &D); // -1 = Failure
|
||||
int insertValue(Value *D, std::vector<ValueList> &D); // -1 = Failure
|
||||
bool postResolveValues(ValueTable &ValTab);
|
||||
|
||||
bool getTypeSlot(const Type *Ty, unsigned &Slot);
|
||||
|
Reference in New Issue
Block a user