mirror of
https://github.com/c64scene-ar/llvm-6502.git
synced 2025-08-05 13:26:55 +00:00
Implemented shl, shl, & load instructions
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@161 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
@@ -19,10 +19,10 @@ public:
|
||||
assert(Ty->isPointerType() && "Can't allocate a non pointer type!");
|
||||
|
||||
if (ArraySize) {
|
||||
// Make sure they didn't try to specify a size for !(unsized array) type...
|
||||
// Make sure they didn't try to specify a size for !(unsized array) type
|
||||
assert((getType()->getValueType()->isArrayType() &&
|
||||
((const ArrayType*)getType()->getValueType())->isUnsized()) &&
|
||||
"Trying to allocate something other than unsized array, with size!");
|
||||
"Trying to allocate something other than unsized array, with size!");
|
||||
|
||||
Operands.reserve(1);
|
||||
Operands.push_back(Use(ArraySize, this));
|
||||
@@ -37,10 +37,11 @@ public:
|
||||
virtual Instruction *clone() const = 0;
|
||||
};
|
||||
|
||||
|
||||
class MallocInst : public AllocationInst {
|
||||
public:
|
||||
MallocInst(const Type *Ty, Value *ArraySize = 0, const string &Name = "")
|
||||
: AllocationInst(Ty, ArraySize, Instruction::Malloc, Name) {}
|
||||
: AllocationInst(Ty, ArraySize, Malloc, Name) {}
|
||||
|
||||
virtual Instruction *clone() const {
|
||||
return new MallocInst(getType(), Operands.size() ? Operands[1] : 0);
|
||||
@@ -49,10 +50,11 @@ public:
|
||||
virtual const char *getOpcodeName() const { return "malloc"; }
|
||||
};
|
||||
|
||||
|
||||
class AllocaInst : public AllocationInst {
|
||||
public:
|
||||
AllocaInst(const Type *Ty, Value *ArraySize = 0, const string &Name = "")
|
||||
: AllocationInst(Ty, ArraySize, Instruction::Alloca, Name) {}
|
||||
: AllocationInst(Ty, ArraySize, Alloca, Name) {}
|
||||
|
||||
virtual Instruction *clone() const {
|
||||
return new AllocaInst(getType(), Operands.size() ? Operands[1] : 0);
|
||||
@@ -62,20 +64,41 @@ public:
|
||||
};
|
||||
|
||||
|
||||
|
||||
class FreeInst : public Instruction {
|
||||
public:
|
||||
FreeInst(Value *Ptr, const string &Name = "")
|
||||
: Instruction(Type::VoidTy, Instruction::Free, Name) {
|
||||
: Instruction(Type::VoidTy, Free, Name) {
|
||||
assert(Ptr->getType()->isPointerType() && "Can't free nonpointer!");
|
||||
Operands.reserve(1);
|
||||
Operands.push_back(Use(Ptr, this));
|
||||
}
|
||||
inline ~FreeInst() {}
|
||||
|
||||
virtual Instruction *clone() const { return new FreeInst(Operands[0]); }
|
||||
|
||||
virtual const char *getOpcodeName() const { return "free"; }
|
||||
};
|
||||
|
||||
|
||||
class LoadInst : public Instruction {
|
||||
LoadInst(const LoadInst &LI) : Instruction(LI.getType(), Load) {
|
||||
Operands.reserve(LI.Operands.size());
|
||||
for (unsigned i = 0, E = LI.Operands.size(); i != E; ++i)
|
||||
Operands.push_back(Use(LI.Operands[i], this));
|
||||
}
|
||||
public:
|
||||
LoadInst(Value *Ptr, const vector<ConstPoolVal*> &Idx,
|
||||
const string &Name = "");
|
||||
virtual Instruction *clone() const { return new LoadInst(*this); }
|
||||
virtual const char *getOpcodeName() const { return "load"; }
|
||||
|
||||
// getIndexedType - Returns the type of the element that would be loaded with
|
||||
// a load instruction with the specified parameters.
|
||||
//
|
||||
// A null type is returned if the indices are invalid for the specified
|
||||
// pointer type.
|
||||
//
|
||||
static const Type *getIndexedType(const Type *Ptr,
|
||||
const vector<ConstPoolVal*> &);
|
||||
};
|
||||
|
||||
#endif // LLVM_IMEMORY_H
|
||||
|
@@ -12,30 +12,6 @@
|
||||
#include "llvm/Method.h"
|
||||
#include <vector>
|
||||
|
||||
//===----------------------------------------------------------------------===//
|
||||
// CastInst Class
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
// CastInst - This function represents a cast from Operand[0] to the type of
|
||||
// the instruction (i->getType()).
|
||||
//
|
||||
class CastInst : public Instruction {
|
||||
CastInst(const CastInst &CI) : Instruction(CI.getType(), Cast) {
|
||||
Operands.reserve(1);
|
||||
Operands.push_back(Use((Value*)CI.getOperand(0), this));
|
||||
}
|
||||
public:
|
||||
CastInst(Value *S, const Type *Ty, const string &Name = "")
|
||||
: Instruction(Ty, Cast, Name) {
|
||||
Operands.reserve(1);
|
||||
Operands.push_back(Use(S, this));
|
||||
}
|
||||
|
||||
virtual Instruction *clone() const { return new CastInst(*this); }
|
||||
virtual const char *getOpcodeName() const { return "cast"; }
|
||||
};
|
||||
|
||||
|
||||
//===----------------------------------------------------------------------===//
|
||||
// PHINode Class
|
||||
//===----------------------------------------------------------------------===//
|
||||
@@ -80,6 +56,30 @@ public:
|
||||
};
|
||||
|
||||
|
||||
//===----------------------------------------------------------------------===//
|
||||
// CastInst Class
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
// CastInst - This class represents a cast from Operand[0] to the type of
|
||||
// the instruction (i->getType()).
|
||||
//
|
||||
class CastInst : public Instruction {
|
||||
CastInst(const CastInst &CI) : Instruction(CI.getType(), Cast) {
|
||||
Operands.reserve(1);
|
||||
Operands.push_back(Use(Operands[0], this));
|
||||
}
|
||||
public:
|
||||
CastInst(Value *S, const Type *Ty, const string &Name = "")
|
||||
: Instruction(Ty, Cast, Name) {
|
||||
Operands.reserve(1);
|
||||
Operands.push_back(Use(S, this));
|
||||
}
|
||||
|
||||
virtual Instruction *clone() const { return new CastInst(*this); }
|
||||
virtual const char *getOpcodeName() const { return "cast"; }
|
||||
};
|
||||
|
||||
|
||||
//===----------------------------------------------------------------------===//
|
||||
// MethodArgument Class
|
||||
//===----------------------------------------------------------------------===//
|
||||
@@ -127,4 +127,32 @@ public:
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
//===----------------------------------------------------------------------===//
|
||||
// ShiftInst Class
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
// ShiftInst - This class represents left and right shift instructions.
|
||||
//
|
||||
class ShiftInst : public Instruction {
|
||||
ShiftInst(const ShiftInst &CI) : Instruction(CI.getType(), CI.getOpcode()) {
|
||||
Operands.reserve(2);
|
||||
Operands.push_back(Use(Operands[0], this));
|
||||
Operands.push_back(Use(Operands[1], this));
|
||||
}
|
||||
public:
|
||||
ShiftInst(OtherOps Opcode, Value *S, Value *SA, const string &Name = "")
|
||||
: Instruction(S->getType(), Opcode, Name) {
|
||||
assert((Opcode == Shl || Opcode == Shr) && "ShiftInst Opcode invalid!");
|
||||
Operands.reserve(2);
|
||||
Operands.push_back(Use(S, this));
|
||||
Operands.push_back(Use(SA, this));
|
||||
}
|
||||
|
||||
virtual Instruction *clone() const { return new ShiftInst(*this); }
|
||||
virtual const char *getOpcodeName() const {
|
||||
return getOpcode() == Shl ? "shl" : "shr";
|
||||
}
|
||||
};
|
||||
|
||||
#endif
|
||||
|
Reference in New Issue
Block a user