Files
swift-mirror/lib/IRGen/IRGenModule.cpp
John McCall b2facdae4b Getterize Stmt.h.
Swift SVN r720
2011-09-20 07:07:53 +00:00

70 lines
2.3 KiB
C++

//===--- IRGenModule.cpp - Swift Global LLVM IR Generation ----------------===//
//
// This source file is part of the Swift.org open source project
//
// Copyright (c) 2014 - 2015 Apple Inc. and the Swift project authors
// Licensed under Apache License v2.0 with Runtime Library Exception
//
// See http://swift.org/LICENSE.txt for license information
// See http://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
//
//===----------------------------------------------------------------------===//
//
// This file implements IR generation for global declarations in Swift.
//
//===----------------------------------------------------------------------===//
#include "swift/AST/ASTContext.h"
#include "swift/AST/Module.h"
#include "swift/AST/Stmt.h"
#include "llvm/Module.h"
#include "llvm/Type.h"
#include "llvm/ADT/PointerUnion.h"
#include "llvm/Support/ErrorHandling.h"
#include "llvm/Support/SourceMgr.h"
#include "GenType.h"
#include "IRGenModule.h"
using namespace swift;
using namespace irgen;
IRGenModule::IRGenModule(ASTContext &Context, Options &Opts,
llvm::Module &Module,
const llvm::TargetData &TargetData)
: Context(Context), Opts(Opts),
Module(Module), LLVMContext(Module.getContext()),
TargetData(TargetData), Types(*new TypeConverter()) {
Int1Ty = llvm::Type::getInt1Ty(getLLVMContext());
Int8Ty = llvm::Type::getInt8Ty(getLLVMContext());
Int16Ty = llvm::Type::getInt16Ty(getLLVMContext());
Int32Ty = llvm::Type::getInt32Ty(getLLVMContext());
Int64Ty = llvm::Type::getInt64Ty(getLLVMContext());
Int8PtrTy = llvm::Type::getInt8PtrTy(getLLVMContext());
}
IRGenModule::~IRGenModule() {
delete &Types;
}
/// Emit a top-level context.
void IRGenModule::emitTopLevel(BraceStmt *Body) {
for (auto Elt : Body->getElements()) {
if (Decl *D = Elt.dyn_cast<Decl*>())
emitGlobalDecl(D);
// TODO: handle top-level statements and expressions.
}
}
/// Emit all the top-level code in the translation unit.
void IRGenModule::emitTranslationUnit(TranslationUnit *TU) {
// The semantics of the top-level BraceStmt are a bit different from
// the normal semantics.
emitTopLevel(TU->Body);
}
void IRGenModule::unimplemented(llvm::SMLoc Loc, const llvm::Twine &Message) {
Context.SourceMgr.PrintMessage(Loc, Message, "error");
Context.setHadError();
}