2007-06-16 08:12:05 +08:00
|
|
|
//===--- CodeGenTypes.h - Type translation for LLVM CodeGen -----*- C++ -*-===//
|
|
|
|
//
|
|
|
|
// The LLVM Compiler Infrastructure
|
|
|
|
//
|
|
|
|
// This file was developed by Chris Lattner and is distributed under
|
|
|
|
// the University of Illinois Open Source License. See LICENSE.TXT for details.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
//
|
|
|
|
// This is the code that handles AST -> LLVM type lowering.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
#ifndef CODEGEN_CODEGENTYPES_H
|
|
|
|
#define CODEGEN_CODEGENTYPES_H
|
|
|
|
|
2007-08-21 08:21:21 +08:00
|
|
|
#include "llvm/ADT/DenseMap.h"
|
2007-10-23 10:10:49 +08:00
|
|
|
#include "llvm/ADT/SmallVector.h"
|
2007-06-16 08:12:05 +08:00
|
|
|
#include <vector>
|
|
|
|
|
|
|
|
namespace llvm {
|
2007-08-18 06:00:32 +08:00
|
|
|
class Module;
|
2007-06-16 08:12:05 +08:00
|
|
|
class Type;
|
|
|
|
}
|
|
|
|
|
|
|
|
namespace clang {
|
2007-07-14 09:29:45 +08:00
|
|
|
class ASTContext;
|
2007-08-21 08:21:21 +08:00
|
|
|
class TagDecl;
|
2007-06-16 08:12:05 +08:00
|
|
|
class TargetInfo;
|
|
|
|
class QualType;
|
|
|
|
class FunctionTypeProto;
|
2007-10-23 10:10:49 +08:00
|
|
|
class FieldDecl;
|
|
|
|
|
2007-06-16 08:12:05 +08:00
|
|
|
namespace CodeGen {
|
2007-10-23 10:10:49 +08:00
|
|
|
class CodeGenTypes;
|
|
|
|
|
|
|
|
/// RecordOrganizer - This helper class, used by RecordLayoutInfo, layouts
|
|
|
|
/// structs and unions. It manages transient information used during layout.
|
|
|
|
/// FIXME : At the moment assume
|
|
|
|
/// - one to one mapping between AST FieldDecls and
|
|
|
|
/// llvm::StructType elements.
|
|
|
|
/// - Ignore bit fields
|
|
|
|
/// - Ignore field aligments
|
|
|
|
/// - Ignore packed structs
|
|
|
|
class RecordOrganizer {
|
|
|
|
public:
|
|
|
|
RecordOrganizer() : STy(NULL) {}
|
|
|
|
|
|
|
|
/// addField - Add new field.
|
|
|
|
void addField(const FieldDecl *FD);
|
|
|
|
|
|
|
|
/// layoutFields - Do the actual work and lay out all fields. Create
|
|
|
|
/// corresponding llvm struct type. This should be invoked only after
|
|
|
|
/// all fields are added.
|
|
|
|
void layoutFields(CodeGenTypes &CGT);
|
|
|
|
|
|
|
|
/// getLLVMType - Return associated llvm struct type. This may be NULL
|
|
|
|
/// if fields are not laid out.
|
|
|
|
llvm::Type *getLLVMType() {
|
|
|
|
return STy;
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
llvm::Type *STy;
|
|
|
|
llvm::SmallVector<const FieldDecl *, 8> FieldDecls;
|
|
|
|
};
|
|
|
|
|
|
|
|
/// RecordLayoutInfo - This class handles struct and union layout info while
|
|
|
|
/// lowering AST types to LLVM types.
|
|
|
|
class RecordLayoutInfo {
|
|
|
|
RecordLayoutInfo(); // DO NOT IMPLEMENT
|
|
|
|
public:
|
|
|
|
RecordLayoutInfo(RecordOrganizer *RO);
|
|
|
|
|
|
|
|
/// getLLVMType - Return llvm type associated with this record.
|
|
|
|
llvm::Type *getLLVMType() {
|
|
|
|
return STy;
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
llvm::Type *STy;
|
|
|
|
};
|
2007-06-16 08:12:05 +08:00
|
|
|
|
|
|
|
/// CodeGenTypes - This class organizes the cross-module state that is used
|
|
|
|
/// while lowering AST types to LLVM types.
|
|
|
|
class CodeGenTypes {
|
2007-07-14 09:29:45 +08:00
|
|
|
ASTContext &Context;
|
2007-06-16 08:12:05 +08:00
|
|
|
TargetInfo &Target;
|
2007-08-18 06:00:32 +08:00
|
|
|
llvm::Module& TheModule;
|
2007-08-21 08:21:21 +08:00
|
|
|
|
|
|
|
llvm::DenseMap<const TagDecl*, llvm::Type*> TagDeclTypes;
|
2007-10-23 10:10:49 +08:00
|
|
|
|
|
|
|
/// RecordLayouts - This maps llvm struct type with corresponding
|
|
|
|
/// record layout info.
|
|
|
|
llvm::DenseMap<const llvm::Type*, RecordLayoutInfo *> RecordLayouts;
|
|
|
|
|
|
|
|
/// FieldInfo - This maps struct field with corresponding llvm struct type
|
|
|
|
/// field no. This info is populated by record organizer.
|
|
|
|
llvm::DenseMap<const FieldDecl *, unsigned> FieldInfo;
|
|
|
|
|
2007-06-16 08:12:05 +08:00
|
|
|
public:
|
2007-08-18 06:00:32 +08:00
|
|
|
CodeGenTypes(ASTContext &Ctx, llvm::Module &M);
|
2007-10-23 10:10:49 +08:00
|
|
|
~CodeGenTypes();
|
2007-06-16 08:12:05 +08:00
|
|
|
|
|
|
|
TargetInfo &getTarget() const { return Target; }
|
|
|
|
|
2007-06-23 03:05:19 +08:00
|
|
|
const llvm::Type *ConvertType(QualType T);
|
2007-06-16 08:12:05 +08:00
|
|
|
void DecodeArgumentTypes(const FunctionTypeProto &FTP,
|
2007-06-23 03:05:19 +08:00
|
|
|
std::vector<const llvm::Type*> &ArgTys);
|
2007-10-23 10:10:49 +08:00
|
|
|
|
|
|
|
RecordLayoutInfo *getRecordLayoutInfo(const llvm::Type*);
|
|
|
|
|
|
|
|
/// getLLVMFieldNo - Return llvm::StructType element number
|
|
|
|
/// that corresponds to the field FD.
|
|
|
|
unsigned getLLVMFieldNo(const FieldDecl *FD);
|
|
|
|
|
|
|
|
/// addFieldInfo - Assign field number to field FD.
|
|
|
|
void addFieldInfo(const FieldDecl *FD, unsigned No);
|
2007-06-16 08:12:05 +08:00
|
|
|
};
|
2007-07-14 06:13:22 +08:00
|
|
|
|
2007-06-16 08:12:05 +08:00
|
|
|
} // end namespace CodeGen
|
|
|
|
} // end namespace clang
|
|
|
|
|
|
|
|
#endif
|