summaryrefslogtreecommitdiffstats
path: root/clang/CodeGen/CGDecl.cpp
diff options
context:
space:
mode:
authorChris Lattner <sabre@nondot.org>2007-06-02 04:53:11 +0000
committerChris Lattner <sabre@nondot.org>2007-06-02 04:53:11 +0000
commit03df12294baab0e9470a382ec2c7ea5fcb95ce0f (patch)
tree2ef71ebf7320225cca898f87291e72147c9b7d2a /clang/CodeGen/CGDecl.cpp
parent238cbc58c34b76bdcdaab9f0837352cab6ac4c29 (diff)
downloadbcm5719-llvm-03df12294baab0e9470a382ec2c7ea5fcb95ce0f.tar.gz
bcm5719-llvm-03df12294baab0e9470a382ec2c7ea5fcb95ce0f.zip
Add initial support for fixed-size local vardecls. This allows us to compile:
int func() { register int X; { int Y; into: define i32 @func() { entry: %X = alloca i32 ; <i32*> [#uses=0] %Y = alloca i32 ; <i32*> [#uses=0] %allocapt = bitcast i32 undef to i32 ; <i32> [#uses=0] ... llvm-svn: 39553
Diffstat (limited to 'clang/CodeGen/CGDecl.cpp')
-rw-r--r--clang/CodeGen/CGDecl.cpp44
1 files changed, 40 insertions, 4 deletions
diff --git a/clang/CodeGen/CGDecl.cpp b/clang/CodeGen/CGDecl.cpp
index 1645b6b2b5b..bc6892dacb6 100644
--- a/clang/CodeGen/CGDecl.cpp
+++ b/clang/CodeGen/CGDecl.cpp
@@ -46,11 +46,47 @@ void CodeGenFunction::EmitDeclStmt(const DeclStmt &S) {
}
}
+void CodeGenFunction::EmitEnumConstantDecl(const EnumConstantDecl &D) {
+ assert(0 && "FIXME: Enum constant decls not implemented yet!");
+}
+
+/// EmitBlockVarDecl - This method handles emission of any variable declaration
+/// inside a function, including static vars etc.
void CodeGenFunction::EmitBlockVarDecl(const BlockVarDecl &D) {
- //assert(0 && "FIXME: Enum constant decls not implemented yet!");
-
+ switch (D.getStorageClass()) {
+ case VarDecl::Static:
+ assert(0 && "FIXME: local static vars not implemented yet");
+ case VarDecl::Extern:
+ assert(0 && "FIXME: should call up to codegenmodule");
+ default:
+ assert((D.getStorageClass() == VarDecl::None ||
+ D.getStorageClass() == VarDecl::Auto ||
+ D.getStorageClass() == VarDecl::Register) &&
+ "Unknown storage class");
+ return EmitLocalBlockVarDecl(D);
+ }
}
-void CodeGenFunction::EmitEnumConstantDecl(const EnumConstantDecl &D) {
- assert(0 && "FIXME: Enum constant decls not implemented yet!");
+/// EmitLocalBlockVarDecl - Emit code and set up an entry in LocalDeclMap for a
+/// variable declaration with auto, register, or no storage class specifier.
+/// These turn into simple stack objects.
+void CodeGenFunction::EmitLocalBlockVarDecl(const BlockVarDecl &D) {
+ QualType Ty = D.getCanonicalType();
+
+ llvm::Value *DeclPtr;
+ if (Ty->isConstantSizeType()) {
+ // A normal fixed sized variable becomes an alloca in the entry block.
+ const llvm::Type *LTy = ConvertType(Ty, D.getLocation());
+ // TODO: Alignment
+ DeclPtr = new AllocaInst(LTy, 0, D.getName(), AllocaInsertPt);
+ } else {
+ // TODO: Create a dynamic alloca.
+ assert(0 && "FIXME: Local VLAs not implemented yet");
+ }
+
+ llvm::Value *&DMEntry = LocalDeclMap[&D];
+ assert(DMEntry == 0 && "Decl already exists in localdeclmap!");
+ DMEntry = DeclPtr;
+
+ // FIXME: Evaluate initializer.
}
OpenPOWER on IntegriCloud