diff options
author | Chris Lattner <sabre@nondot.org> | 2007-06-02 19:52:24 +0000 |
---|---|---|
committer | Chris Lattner <sabre@nondot.org> | 2007-06-02 19:52:24 +0000 |
commit | 2b4e21ac3f0dcda6e9af30b941401adad28c5d56 (patch) | |
tree | 4fb38248cac93c8501518ed05f2d69891b4f016e /clang/CodeGen/CodeGenFunction.cpp | |
parent | a45c5af87b57dceec8532aa71ad537f4ea902b0c (diff) | |
download | bcm5719-llvm-2b4e21ac3f0dcda6e9af30b941401adad28c5d56.tar.gz bcm5719-llvm-2b4e21ac3f0dcda6e9af30b941401adad28c5d56.zip |
Implement translation of pointer, reference and simple array types. We now
compile:
void foo() {
int A[10];
int *P;
into:
entry:
%A = alloca [10 x i32] ; <[10 x i32]*> [#uses=0]
%P = alloca i32* ; <i32**> [#uses=0]
llvm-svn: 39561
Diffstat (limited to 'clang/CodeGen/CodeGenFunction.cpp')
-rw-r--r-- | clang/CodeGen/CodeGenFunction.cpp | 26 |
1 files changed, 22 insertions, 4 deletions
diff --git a/clang/CodeGen/CodeGenFunction.cpp b/clang/CodeGen/CodeGenFunction.cpp index 0283760dc99..ef80e51d0e3 100644 --- a/clang/CodeGen/CodeGenFunction.cpp +++ b/clang/CodeGen/CodeGenFunction.cpp @@ -81,10 +81,28 @@ const llvm::Type *CodeGenFunction::ConvertType(QualType T, SourceLocation Loc) { } break; } - case Type::Pointer: - case Type::Reference: - case Type::Array: - break; + case Type::Pointer: { + const PointerType &P = cast<PointerType>(Ty); + return llvm::PointerType::get(ConvertType(P.getPointeeType(), Loc)); + } + case Type::Reference: { + const ReferenceType &R = cast<ReferenceType>(Ty); + return llvm::PointerType::get(ConvertType(R.getReferenceeType(), Loc)); + } + + case Type::Array: { + const ArrayType &A = cast<ArrayType>(Ty); + assert(A.getSizeModifier() == ArrayType::Normal && + A.getIndexTypeQualifier() == 0 && + "FIXME: We only handle trivial array types so far!"); + // FIXME: are there any promotions etc here? + ExprResult Size = EmitExpr(A.getSize()); + assert(Size.isScalar() && isa<llvm::ConstantInt>(Size.getVal()) && + "FIXME: Only handle fixed-size arrays so far"); + const llvm::Type *EltTy = ConvertType(A.getElementType(), Loc); + return llvm::ArrayType::get(EltTy, + cast<llvm::ConstantInt>(Size.getVal())->getZExtValue()); + } case Type::FunctionNoProto: case Type::FunctionProto: { const FunctionType &FP = cast<FunctionType>(Ty); |