<commit_before>//===--- SILGen.h - Implements Lowering of ASTs -> SIL ----------*- 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
//
//===----------------------------------------------------------------------===//

#ifndef SILGen_H
#define SILGen_H

#include "Cleanup.h"
#include "Scope.h"
#include "TypeInfo.h"
#include "swift/SIL/Function.h"
#include "swift/SIL/SILModule.h"
#include "swift/SIL/SILBuilder.h"
#include "swift/AST/ASTVisitor.h"
#include "llvm/ADT/DenseMap.h"

namespace swift {
  class BasicBlock;
  
namespace Lowering {
  class Condition;
  class ManagedValue;
  class TypeConverter;
  class SILGenFunction;

class LLVM_LIBRARY_VISIBILITY SILGenModule : public ASTVisitor<SILGenModule> {
public:
  /// The Module being constructed.
  SILModule &M;
  
  /// Types - This creates and manages TypeInfo objects containing extra
  /// information about types needed for SIL generation.
  TypeConverter Types;
  
  /// TopLevelSGF - The SILGenFunction used to visit top-level code, or null if
  /// the module is not a main module.
  SILGenFunction *TopLevelSGF;
  
public:
  SILGenModule(SILModule &M);
  ~SILGenModule();
  
  SILGenModule(SILGenModule const &) = delete;
  void operator=(SILGenModule const &) = delete;

  //===--------------------------------------------------------------------===//
  // Visitors for top-level forms
  //===--------------------------------------------------------------------===//
  // FIXME: visit types, etc.
  void visitFuncDecl(FuncDecl *fd);
  void visitPatternBindingDecl(PatternBindingDecl *vd);
  void visitTopLevelCodeDecl(TopLevelCodeDecl *td);

  Function *emitFunction(SILConstant decl, FuncExpr *fe);
  Function *emitClosure(ClosureExpr *ce);
};

/// CaptureKind - Closure capture modes.
enum class CaptureKind {
  /// A local value captured as a mutable box.
  LValue,
  /// A local value captured by value.
  Constant,
  /// A byref argument captured by address.
  Byref
};
  
class LLVM_LIBRARY_VISIBILITY SILGenFunction
  : public ASTVisitor<SILGenFunction, ManagedValue, void> {
public:
  /// The SILGenModule this function belongs to.
  SILGenModule &SGM;
    
  /// The Function being constructed.
  Function &F;
  
  /// B - The SILBuilder used to construct the Function.  It is what maintains
  /// the notion of the current block being emitted into.
  SILBuilder B;
  
  std::vector<JumpDest> BreakDestStack;
  std::vector<JumpDest> ContinueDestStack;

  /// Cleanups - This records information about the currently active cleanups.
  CleanupManager Cleanups;

  /// VarLoc - representation of an emitted local variable.
  struct VarLoc {
    /// box - the retainable box for the variable, or invalid if no box was
    /// made for the value.
    Value box;
    /// address - the address at which the variable is stored.
    Value address;
  };
    
  /// VarLocs - Entries in this map are generated when a PatternBindingDecl is
  /// emitted. The map is queried to produce the lvalue for a DeclRefExpr to
  /// a local variable.
  llvm::DenseMap<ValueDecl*, VarLoc> VarLocs;
    
  /// LocalConstants - Entries in this map are generated when a local constant
  /// declaration, such as a func, is emitted. This map is queried to produce
  /// the constant value for a DeclRefExpr to a local constant.
  llvm::DenseMap<ValueDecl*, Value> LocalConstants;
    
  bool hasVoidReturn;

public:
  SILGenFunction(SILGenModule &SGM, Function &F, bool hasVoidReturn);
  SILGenFunction(SILGenModule &SGM, Function &F, FuncExpr *FE);
  SILGenFunction(SILGenModule &SGM, Function &F, ClosureExpr *CE);
  ~SILGenFunction();

  void emitProlog(CapturingExpr *ce, ArrayRef<Pattern*> paramPatterns);
  void emitClosureBody(Expr *body);

  /// Return a stable reference to the current cleanup.
  CleanupsDepth getCleanupsDepth() const {
    return Cleanups.getCleanupsDepth();
  }
  
  Function &getFunction() { return F; }
  SILBuilder &getBuilder() { return B; }<commit_msg>SILGen: Add doc comments to some SILGen* methods.<commit_after>//===--- SILGen.h - Implements Lowering of ASTs -> SIL ----------*- 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
//
//===----------------------------------------------------------------------===//

#ifndef SILGen_H
#define SILGen_H

#include "Cleanup.h"
#include "Scope.h"
#include "TypeInfo.h"
#include "swift/SIL/Function.h"
#include "swift/SIL/SILModule.h"
#include "swift/SIL/SILBuilder.h"
#include "swift/AST/ASTVisitor.h"
#include "llvm/ADT/DenseMap.h"

namespace swift {
  class BasicBlock;
  
namespace Lowering {
  class Condition;
  class ManagedValue;
  class TypeConverter;
  class SILGenFunction;

class LLVM_LIBRARY_VISIBILITY SILGenModule : public ASTVisitor<SILGenModule> {
public:
  /// The Module being constructed.
  SILModule &M;
  
  /// Types - This creates and manages TypeInfo objects containing extra
  /// information about types needed for SIL generation.
  TypeConverter Types;
  
  /// TopLevelSGF - The SILGenFunction used to visit top-level code, or null if
  /// the module is not a main module.
  SILGenFunction *TopLevelSGF;
  
public:
  SILGenModule(SILModule &M);
  ~SILGenModule();
  
  SILGenModule(SILGenModule const &) = delete;
  void operator=(SILGenModule const &) = delete;

  //===--------------------------------------------------------------------===//
  // Visitors for top-level forms
  //===--------------------------------------------------------------------===//
  // FIXME: visit types, etc.
  void visitFuncDecl(FuncDecl *fd);
  void visitPatternBindingDecl(PatternBindingDecl *vd);
  void visitTopLevelCodeDecl(TopLevelCodeDecl *td);

  /// emitFunction - Generates code for the given FuncExpr and adds the
  /// Function to the current SILModule under the name SILConstant(decl). For
  /// curried functions, curried entry point Functions are also generated and
  /// added to the current SILModule.
  Function *emitFunction(SILConstant decl, FuncExpr *fe);
  /// emitClosure - Generates code for the given ClosureExpr and adds the
  /// Function to the current SILModule under the name SILConstant(ce).
  Function *emitClosure(ClosureExpr *ce);
};

/// CaptureKind - Closure capture modes.
enum class CaptureKind {
  /// A local value captured as a mutable box.
  LValue,
  /// A local value captured by value.
  Constant,
  /// A byref argument captured by address.
  Byref
};
  
class LLVM_LIBRARY_VISIBILITY SILGenFunction
  : public ASTVisitor<SILGenFunction, ManagedValue, void> {
public:
  /// The SILGenModule this function belongs to.
  SILGenModule &SGM;
    
  /// The Function being constructed.
  Function &F;
  
  /// B - The SILBuilder used to construct the Function.  It is what maintains
  /// the notion of the current block being emitted into.
  SILBuilder B;
  
  std::vector<JumpDest> BreakDestStack;
  std::vector<JumpDest> ContinueDestStack;

  /// Cleanups - This records information about the currently active cleanups.
  CleanupManager Cleanups;

  /// VarLoc - representation of an emitted local variable.
  struct VarLoc {
    /// box - the retainable box for the variable, or invalid if no box was
    /// made for the value.
    Value box;
    /// address - the address at which the variable is stored.
    Value address;
  };
    
  /// VarLocs - Entries in this map are generated when a PatternBindingDecl is
  /// emitted. The map is queried to produce the lvalue for a DeclRefExpr to
  /// a local variable.
  llvm::DenseMap<ValueDecl*, VarLoc> VarLocs;
    
  /// LocalConstants - Entries in this map are generated when a local constant
  /// declaration, such as a func, is emitted. This map is queried to produce
  /// the constant value for a DeclRefExpr to a local constant.
  llvm::DenseMap<ValueDecl*, Value> LocalConstants;
    
  bool hasVoidReturn;

public:
  SILGenFunction(SILGenModule &SGM, Function &F, bool hasVoidReturn);
  SILGenFunction(SILGenModule &SGM, Function &F, FuncExpr *FE);
  SILGenFunction(SILGenModule &SGM, Function &F, ClosureExpr *CE);
  ~SILGenFunction();

  /// emitProlog - Generates prolog code to allocate and clean up mutable
  /// storage for closure captures and local arguments.
  void emitProlog(CapturingExpr *ce, ArrayRef<Pattern*> paramPatterns);
  /// emitClosureBody - Generates code for a ClosureExpr body. This is akin
  /// to visiting the body as if wrapped in a ReturnStmt.
  void emitClosureBody(Expr *body);

  /// Return a stable reference to the current cleanup.
  CleanupsDepth getCleanupsDepth() const {
    return Cleanups.getCleanupsDepth();
  }
  
  Function &getFunction() { return F; }
  SILBuilder &getBuilder() { return B; }
{'fraction_non_alphanumeric': 0.14434556110266986, 'fraction_numerical': 0.0021706099413935317, 'mean_word_length': 2.8300083125519535, 'pattern_counts': {'":': 0, '<': 17, '<?xml version=': 0, '>': 19, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5142602', 'n_tokens_mistral': 2742, 'n_tokens_neox': 2657, 'n_words': 938}