mirror of
https://github.com/c64scene-ar/llvm-6502.git
synced 2025-05-13 01:15:32 +00:00
Do not depend on the gep index types to determine what flavor of index it is
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@10225 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
parent
4af6de8f0a
commit
23e907082a
@ -21,9 +21,10 @@
|
|||||||
#include "llvm/Intrinsics.h"
|
#include "llvm/Intrinsics.h"
|
||||||
#include "llvm/Analysis/FindUsedTypes.h"
|
#include "llvm/Analysis/FindUsedTypes.h"
|
||||||
#include "llvm/Analysis/ConstantsScanner.h"
|
#include "llvm/Analysis/ConstantsScanner.h"
|
||||||
|
#include "llvm/Support/CallSite.h"
|
||||||
|
#include "llvm/Support/GetElementPtrTypeIterator.h"
|
||||||
#include "llvm/Support/InstVisitor.h"
|
#include "llvm/Support/InstVisitor.h"
|
||||||
#include "llvm/Support/InstIterator.h"
|
#include "llvm/Support/InstIterator.h"
|
||||||
#include "llvm/Support/CallSite.h"
|
|
||||||
#include "llvm/Support/Mangler.h"
|
#include "llvm/Support/Mangler.h"
|
||||||
#include "Support/StringExtras.h"
|
#include "Support/StringExtras.h"
|
||||||
#include "Support/STLExtras.h"
|
#include "Support/STLExtras.h"
|
||||||
@ -160,8 +161,8 @@ namespace {
|
|||||||
}
|
}
|
||||||
void printBranchToBlock(BasicBlock *CurBlock, BasicBlock *SuccBlock,
|
void printBranchToBlock(BasicBlock *CurBlock, BasicBlock *SuccBlock,
|
||||||
unsigned Indent);
|
unsigned Indent);
|
||||||
void printIndexingExpression(Value *Ptr, User::op_iterator I,
|
void printIndexingExpression(Value *Ptr, gep_type_iterator I,
|
||||||
User::op_iterator E);
|
gep_type_iterator E);
|
||||||
};
|
};
|
||||||
|
|
||||||
// Pass the Type* and the variable name and this prints out the variable
|
// Pass the Type* and the variable name and this prints out the variable
|
||||||
@ -381,8 +382,8 @@ void CWriter::printConstant(Constant *CPV) {
|
|||||||
|
|
||||||
case Instruction::GetElementPtr:
|
case Instruction::GetElementPtr:
|
||||||
Out << "(&(";
|
Out << "(&(";
|
||||||
printIndexingExpression(CE->getOperand(0),
|
printIndexingExpression(CE->getOperand(0), gep_type_begin(CPV),
|
||||||
CPV->op_begin()+1, CPV->op_end());
|
gep_type_end(CPV));
|
||||||
Out << "))";
|
Out << "))";
|
||||||
return;
|
return;
|
||||||
case Instruction::Add:
|
case Instruction::Add:
|
||||||
@ -1336,8 +1337,8 @@ void CWriter::visitFreeInst(FreeInst &I) {
|
|||||||
Out << ")";
|
Out << ")";
|
||||||
}
|
}
|
||||||
|
|
||||||
void CWriter::printIndexingExpression(Value *Ptr, User::op_iterator I,
|
void CWriter::printIndexingExpression(Value *Ptr, gep_type_iterator I,
|
||||||
User::op_iterator E) {
|
gep_type_iterator E) {
|
||||||
bool HasImplicitAddress = false;
|
bool HasImplicitAddress = false;
|
||||||
// If accessing a global value with no indexing, avoid *(&GV) syndrome
|
// If accessing a global value with no indexing, avoid *(&GV) syndrome
|
||||||
if (GlobalValue *V = dyn_cast<GlobalValue>(Ptr)) {
|
if (GlobalValue *V = dyn_cast<GlobalValue>(Ptr)) {
|
||||||
@ -1357,7 +1358,7 @@ void CWriter::printIndexingExpression(Value *Ptr, User::op_iterator I,
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
const Constant *CI = dyn_cast<Constant>(I);
|
const Constant *CI = dyn_cast<Constant>(I.getOperand());
|
||||||
if (HasImplicitAddress && (!CI || !CI->isNullValue()))
|
if (HasImplicitAddress && (!CI || !CI->isNullValue()))
|
||||||
Out << "(&";
|
Out << "(&";
|
||||||
|
|
||||||
@ -1373,22 +1374,24 @@ void CWriter::printIndexingExpression(Value *Ptr, User::op_iterator I,
|
|||||||
|
|
||||||
if (HasImplicitAddress) {
|
if (HasImplicitAddress) {
|
||||||
++I;
|
++I;
|
||||||
} else if (CI && CI->isNullValue() && I+1 != E) {
|
} else if (CI && CI->isNullValue()) {
|
||||||
|
gep_type_iterator TmpI = I; ++TmpI;
|
||||||
|
|
||||||
// Print out the -> operator if possible...
|
// Print out the -> operator if possible...
|
||||||
if ((*(I+1))->getType() == Type::UByteTy) {
|
if (TmpI != E && isa<StructType>(*TmpI)) {
|
||||||
Out << (HasImplicitAddress ? "." : "->");
|
Out << (HasImplicitAddress ? "." : "->");
|
||||||
Out << "field" << cast<ConstantUInt>(*(I+1))->getValue();
|
Out << "field" << cast<ConstantUInt>(I.getOperand())->getValue();
|
||||||
I += 2;
|
I = ++TmpI;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
for (; I != E; ++I)
|
for (; I != E; ++I)
|
||||||
if ((*I)->getType() == Type::LongTy) {
|
if (isa<StructType>(*I)) {
|
||||||
Out << "[";
|
Out << ".field" << cast<ConstantUInt>(I.getOperand())->getValue();
|
||||||
writeOperand(*I);
|
|
||||||
Out << "]";
|
|
||||||
} else {
|
} else {
|
||||||
Out << ".field" << cast<ConstantUInt>(*I)->getValue();
|
Out << "[";
|
||||||
|
writeOperand(I.getOperand());
|
||||||
|
Out << "]";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1406,7 +1409,8 @@ void CWriter::visitStoreInst(StoreInst &I) {
|
|||||||
|
|
||||||
void CWriter::visitGetElementPtrInst(GetElementPtrInst &I) {
|
void CWriter::visitGetElementPtrInst(GetElementPtrInst &I) {
|
||||||
Out << "&";
|
Out << "&";
|
||||||
printIndexingExpression(I.getPointerOperand(), I.idx_begin(), I.idx_end());
|
printIndexingExpression(I.getPointerOperand(), gep_type_begin(I),
|
||||||
|
gep_type_end(I));
|
||||||
}
|
}
|
||||||
|
|
||||||
void CWriter::visitVANextInst(VANextInst &I) {
|
void CWriter::visitVANextInst(VANextInst &I) {
|
||||||
|
@ -21,9 +21,10 @@
|
|||||||
#include "llvm/Intrinsics.h"
|
#include "llvm/Intrinsics.h"
|
||||||
#include "llvm/Analysis/FindUsedTypes.h"
|
#include "llvm/Analysis/FindUsedTypes.h"
|
||||||
#include "llvm/Analysis/ConstantsScanner.h"
|
#include "llvm/Analysis/ConstantsScanner.h"
|
||||||
|
#include "llvm/Support/CallSite.h"
|
||||||
|
#include "llvm/Support/GetElementPtrTypeIterator.h"
|
||||||
#include "llvm/Support/InstVisitor.h"
|
#include "llvm/Support/InstVisitor.h"
|
||||||
#include "llvm/Support/InstIterator.h"
|
#include "llvm/Support/InstIterator.h"
|
||||||
#include "llvm/Support/CallSite.h"
|
|
||||||
#include "llvm/Support/Mangler.h"
|
#include "llvm/Support/Mangler.h"
|
||||||
#include "Support/StringExtras.h"
|
#include "Support/StringExtras.h"
|
||||||
#include "Support/STLExtras.h"
|
#include "Support/STLExtras.h"
|
||||||
@ -160,8 +161,8 @@ namespace {
|
|||||||
}
|
}
|
||||||
void printBranchToBlock(BasicBlock *CurBlock, BasicBlock *SuccBlock,
|
void printBranchToBlock(BasicBlock *CurBlock, BasicBlock *SuccBlock,
|
||||||
unsigned Indent);
|
unsigned Indent);
|
||||||
void printIndexingExpression(Value *Ptr, User::op_iterator I,
|
void printIndexingExpression(Value *Ptr, gep_type_iterator I,
|
||||||
User::op_iterator E);
|
gep_type_iterator E);
|
||||||
};
|
};
|
||||||
|
|
||||||
// Pass the Type* and the variable name and this prints out the variable
|
// Pass the Type* and the variable name and this prints out the variable
|
||||||
@ -381,8 +382,8 @@ void CWriter::printConstant(Constant *CPV) {
|
|||||||
|
|
||||||
case Instruction::GetElementPtr:
|
case Instruction::GetElementPtr:
|
||||||
Out << "(&(";
|
Out << "(&(";
|
||||||
printIndexingExpression(CE->getOperand(0),
|
printIndexingExpression(CE->getOperand(0), gep_type_begin(CPV),
|
||||||
CPV->op_begin()+1, CPV->op_end());
|
gep_type_end(CPV));
|
||||||
Out << "))";
|
Out << "))";
|
||||||
return;
|
return;
|
||||||
case Instruction::Add:
|
case Instruction::Add:
|
||||||
@ -1336,8 +1337,8 @@ void CWriter::visitFreeInst(FreeInst &I) {
|
|||||||
Out << ")";
|
Out << ")";
|
||||||
}
|
}
|
||||||
|
|
||||||
void CWriter::printIndexingExpression(Value *Ptr, User::op_iterator I,
|
void CWriter::printIndexingExpression(Value *Ptr, gep_type_iterator I,
|
||||||
User::op_iterator E) {
|
gep_type_iterator E) {
|
||||||
bool HasImplicitAddress = false;
|
bool HasImplicitAddress = false;
|
||||||
// If accessing a global value with no indexing, avoid *(&GV) syndrome
|
// If accessing a global value with no indexing, avoid *(&GV) syndrome
|
||||||
if (GlobalValue *V = dyn_cast<GlobalValue>(Ptr)) {
|
if (GlobalValue *V = dyn_cast<GlobalValue>(Ptr)) {
|
||||||
@ -1357,7 +1358,7 @@ void CWriter::printIndexingExpression(Value *Ptr, User::op_iterator I,
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
const Constant *CI = dyn_cast<Constant>(I);
|
const Constant *CI = dyn_cast<Constant>(I.getOperand());
|
||||||
if (HasImplicitAddress && (!CI || !CI->isNullValue()))
|
if (HasImplicitAddress && (!CI || !CI->isNullValue()))
|
||||||
Out << "(&";
|
Out << "(&";
|
||||||
|
|
||||||
@ -1373,22 +1374,24 @@ void CWriter::printIndexingExpression(Value *Ptr, User::op_iterator I,
|
|||||||
|
|
||||||
if (HasImplicitAddress) {
|
if (HasImplicitAddress) {
|
||||||
++I;
|
++I;
|
||||||
} else if (CI && CI->isNullValue() && I+1 != E) {
|
} else if (CI && CI->isNullValue()) {
|
||||||
|
gep_type_iterator TmpI = I; ++TmpI;
|
||||||
|
|
||||||
// Print out the -> operator if possible...
|
// Print out the -> operator if possible...
|
||||||
if ((*(I+1))->getType() == Type::UByteTy) {
|
if (TmpI != E && isa<StructType>(*TmpI)) {
|
||||||
Out << (HasImplicitAddress ? "." : "->");
|
Out << (HasImplicitAddress ? "." : "->");
|
||||||
Out << "field" << cast<ConstantUInt>(*(I+1))->getValue();
|
Out << "field" << cast<ConstantUInt>(I.getOperand())->getValue();
|
||||||
I += 2;
|
I = ++TmpI;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
for (; I != E; ++I)
|
for (; I != E; ++I)
|
||||||
if ((*I)->getType() == Type::LongTy) {
|
if (isa<StructType>(*I)) {
|
||||||
Out << "[";
|
Out << ".field" << cast<ConstantUInt>(I.getOperand())->getValue();
|
||||||
writeOperand(*I);
|
|
||||||
Out << "]";
|
|
||||||
} else {
|
} else {
|
||||||
Out << ".field" << cast<ConstantUInt>(*I)->getValue();
|
Out << "[";
|
||||||
|
writeOperand(I.getOperand());
|
||||||
|
Out << "]";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1406,7 +1409,8 @@ void CWriter::visitStoreInst(StoreInst &I) {
|
|||||||
|
|
||||||
void CWriter::visitGetElementPtrInst(GetElementPtrInst &I) {
|
void CWriter::visitGetElementPtrInst(GetElementPtrInst &I) {
|
||||||
Out << "&";
|
Out << "&";
|
||||||
printIndexingExpression(I.getPointerOperand(), I.idx_begin(), I.idx_end());
|
printIndexingExpression(I.getPointerOperand(), gep_type_begin(I),
|
||||||
|
gep_type_end(I));
|
||||||
}
|
}
|
||||||
|
|
||||||
void CWriter::visitVANextInst(VANextInst &I) {
|
void CWriter::visitVANextInst(VANextInst &I) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user