Files
swift-mirror/include/swift/SIL/SILModule.h
Joe Groff 814229fce7 SILGen: Generate top-level code.
Add a toplevel Function object to SILModule. When SILGenModule encounters TopLevelCodeDecls, pass their bodies on to SILGenFunction to emit SIL into the toplevel function

Swift SVN r3336
2012-12-03 20:38:14 +00:00

107 lines
3.2 KiB
C++

//===--- SILModule.h - Defines the SILModule class --------------*- C++ -*-===//
//
// 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 defines the SILModule class.
//
//===----------------------------------------------------------------------===//
#ifndef SWIFT_SIL_SILMODULE_H
#define SWIFT_SIL_SILMODULE_H
#include "swift/SIL/SILBase.h"
#include "llvm/ADT/ArrayRef.h"
#include "llvm/ADT/MapVector.h"
namespace swift {
class TranslationUnit;
class ASTContext;
class FuncDecl;
namespace Lowering {
class SILGenModule;
}
/// SILModule - A SIL translation unit. The module object owns all of the SIL
/// Function and other top-level objects generated when a translation unit is
/// lowered to SIL.
class SILModule : public SILBase {
private:
friend class BasicBlock;
friend class Function;
friend class Lowering::SILGenModule;
/// Context - This is the context that uniques the types used by this
/// Function.
ASTContext &Context;
/// The collection of all Functions in the module.
llvm::MapVector<ValueDecl*, Function*> functions;
/// The top-level Function for the module.
Function *toplevel;
// Intentionally marked private so that we need to use 'constructSIL()'
// to construct a SILModule.
SILModule(ASTContext &Context) : Context(Context), toplevel(nullptr) {}
public:
~SILModule();
/// Construct a SIL module from a translation unit. It is the caller's
/// responsibility to 'delete' this object.
static SILModule *constructSIL(TranslationUnit *tu);
ASTContext &getContext() const { return Context; }
/// Returns true if this module has top-level code.
bool hasToplevelFunction() const {
return toplevel != nullptr;
}
/// Returns the Function containing top-level code for the module.
Function *getToplevelFunction() const {
assert(toplevel && "no toplevel");
return toplevel;
}
/// Returns true if a Function was generated from the given declaration.
bool hasFunction(ValueDecl *decl) const {
return functions.find(decl) != functions.end();
}
/// Returns a pointer to the Function generated from the given declaration.
Function *getFunction(ValueDecl *decl) const {
auto found = functions.find(decl);
assert(found != functions.end() && "no Function generated for Decl");
return found->second;
}
typedef llvm::MapVector<ValueDecl*, Function*>::const_iterator iterator;
typedef iterator const_iterator;
iterator begin() const { return functions.begin(); }
iterator end() const { return functions.end(); }
/// verify - Run the SIL verifier to make sure that all Functions follow
/// invariants.
void verify() const;
/// Pretty-print the module.
void dump() const;
/// Pretty-print the module to the designated stream.
void print(raw_ostream &OS) const;
};
} // end swift namespace
#endif