mirror of
https://github.com/apple/swift.git
synced 2025-12-21 12:14:44 +01:00
Swift's ASTs are lacking the extremely useful concept of a DeclContext, without which it's probably possible to make this work, but it'll be extremely awkward. Anyway, these hacks are good enough to get the test passing again. Swift SVN r620
71 lines
2.4 KiB
C++
71 lines
2.4 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/Decl.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 (unsigned I = 0, E = Body->NumElements; I != E; ++I) {
|
|
BraceStmt::ExprStmtOrDecl Elt = Body->Elements[I];
|
|
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(TranslationUnitDecl *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();
|
|
}
|