mirror of
https://github.com/c64scene-ar/llvm-6502.git
synced 2025-08-07 12:28:24 +00:00
Add support for more constant expressions
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@6203 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
@@ -31,10 +31,10 @@ void *ExecutionEngine::getPointerToGlobal(const GlobalValue *GV) {
|
|||||||
GenericValue ExecutionEngine::getConstantValue(const Constant *C) {
|
GenericValue ExecutionEngine::getConstantValue(const Constant *C) {
|
||||||
GenericValue Result;
|
GenericValue Result;
|
||||||
|
|
||||||
if (ConstantExpr *CE = const_cast<ConstantExpr*>(dyn_cast<ConstantExpr>(C)))
|
if (ConstantExpr *CE = const_cast<ConstantExpr*>(dyn_cast<ConstantExpr>(C))) {
|
||||||
switch (CE->getOpcode()) {
|
switch (CE->getOpcode()) {
|
||||||
case Instruction::GetElementPtr: {
|
case Instruction::GetElementPtr: {
|
||||||
Result = getConstantValue(cast<Constant>(CE->getOperand(0)));
|
Result = getConstantValue(CE->getOperand(0));
|
||||||
std::vector<Value*> Indexes(CE->op_begin()+1, CE->op_end());
|
std::vector<Value*> Indexes(CE->op_begin()+1, CE->op_end());
|
||||||
uint64_t Offset =
|
uint64_t Offset =
|
||||||
TD->getIndexedOffset(CE->getOperand(0)->getType(), Indexes);
|
TD->getIndexedOffset(CE->getOperand(0)->getType(), Indexes);
|
||||||
@@ -42,13 +42,42 @@ GenericValue ExecutionEngine::getConstantValue(const Constant *C) {
|
|||||||
Result.LongVal += Offset;
|
Result.LongVal += Offset;
|
||||||
return Result;
|
return Result;
|
||||||
}
|
}
|
||||||
|
case Instruction::Cast: {
|
||||||
|
// We only need to handle a few cases here. Almost all casts will
|
||||||
|
// automatically fold, just the ones involving pointers won't.
|
||||||
|
//
|
||||||
|
Constant *Op = CE->getOperand(0);
|
||||||
|
|
||||||
default:
|
// Handle cast of pointer to pointer...
|
||||||
std::cerr << "ConstantExpr not handled as global var init: " << *CE
|
if (Op->getType()->getPrimitiveID() == C->getType()->getPrimitiveID())
|
||||||
<< "\n";
|
return getConstantValue(Op);
|
||||||
abort();
|
|
||||||
|
// Handle cast of long to pointer or pointer to long...
|
||||||
|
if ((isa<PointerType>(Op->getType()) && (C->getType() == Type::LongTy ||
|
||||||
|
C->getType() == Type::ULongTy))||
|
||||||
|
(isa<PointerType>(C->getType()) && (Op->getType() == Type::LongTy ||
|
||||||
|
Op->getType() == Type::ULongTy))){
|
||||||
|
return getConstantValue(Op);
|
||||||
|
}
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
case Instruction::Add:
|
||||||
|
if (C->getOperand(0)->getType() == Type::LongTy ||
|
||||||
|
C->getOperand(0)->getType() == Type::ULongTy)
|
||||||
|
Result.LongVal = getConstantValue(C->getOperand(0)).LongVal +
|
||||||
|
getConstantValue(C->getOperand(1)).LongVal;
|
||||||
|
else
|
||||||
|
break;
|
||||||
|
return Result;
|
||||||
|
|
||||||
|
default:
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
std::cerr << "ConstantExpr not handled as global var init: " << *CE << "\n";
|
||||||
|
abort();
|
||||||
|
}
|
||||||
|
|
||||||
switch (C->getType()->getPrimitiveID()) {
|
switch (C->getType()->getPrimitiveID()) {
|
||||||
#define GET_CONST_VAL(TY, CLASS) \
|
#define GET_CONST_VAL(TY, CLASS) \
|
||||||
case Type::TY##TyID: Result.TY##Val = cast<CLASS>(C)->getValue(); break
|
case Type::TY##TyID: Result.TY##Val = cast<CLASS>(C)->getValue(); break
|
||||||
|
Reference in New Issue
Block a user