1a7dea167SDimitry Andric //===--- Function.h - Bytecode function for the VM --------------*- C++ -*-===// 2a7dea167SDimitry Andric // 3a7dea167SDimitry Andric // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 4a7dea167SDimitry Andric // See https://llvm.org/LICENSE.txt for license information. 5a7dea167SDimitry Andric // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 6a7dea167SDimitry Andric // 7a7dea167SDimitry Andric //===----------------------------------------------------------------------===// 8a7dea167SDimitry Andric 9a7dea167SDimitry Andric #include "Function.h" 10a7dea167SDimitry Andric #include "Program.h" 11a7dea167SDimitry Andric #include "Opcode.h" 12a7dea167SDimitry Andric #include "clang/AST/Decl.h" 13a7dea167SDimitry Andric #include "clang/AST/DeclCXX.h" 14a7dea167SDimitry Andric 15a7dea167SDimitry Andric using namespace clang; 16a7dea167SDimitry Andric using namespace clang::interp; 17a7dea167SDimitry Andric 18a7dea167SDimitry Andric Function::Function(Program &P, const FunctionDecl *F, unsigned ArgSize, 19*06c3fb27SDimitry Andric llvm::SmallVectorImpl<PrimType> &&ParamTypes, 20bdd1243dSDimitry Andric llvm::DenseMap<unsigned, ParamDescriptor> &&Params, 21*06c3fb27SDimitry Andric llvm::SmallVectorImpl<unsigned> &&ParamOffsets, 22bdd1243dSDimitry Andric bool HasThisPointer, bool HasRVO) 23a7dea167SDimitry Andric : P(P), Loc(F->getBeginLoc()), F(F), ArgSize(ArgSize), 24bdd1243dSDimitry Andric ParamTypes(std::move(ParamTypes)), Params(std::move(Params)), 25*06c3fb27SDimitry Andric ParamOffsets(std::move(ParamOffsets)), HasThisPointer(HasThisPointer), 26*06c3fb27SDimitry Andric HasRVO(HasRVO) {} 27a7dea167SDimitry Andric 28a7dea167SDimitry Andric Function::ParamDescriptor Function::getParamDescriptor(unsigned Offset) const { 29a7dea167SDimitry Andric auto It = Params.find(Offset); 30a7dea167SDimitry Andric assert(It != Params.end() && "Invalid parameter offset"); 31a7dea167SDimitry Andric return It->second; 32a7dea167SDimitry Andric } 33a7dea167SDimitry Andric 34a7dea167SDimitry Andric SourceInfo Function::getSource(CodePtr PC) const { 35bdd1243dSDimitry Andric assert(PC >= getCodeBegin() && "PC does not belong to this function"); 36bdd1243dSDimitry Andric assert(PC <= getCodeEnd() && "PC Does not belong to this function"); 37*06c3fb27SDimitry Andric assert(hasBody() && "Function has no body"); 38a7dea167SDimitry Andric unsigned Offset = PC - getCodeBegin(); 39a7dea167SDimitry Andric using Elem = std::pair<unsigned, SourceInfo>; 4081ad6265SDimitry Andric auto It = llvm::lower_bound(SrcMap, Elem{Offset, {}}, llvm::less_first()); 41bdd1243dSDimitry Andric assert(It != SrcMap.end()); 42a7dea167SDimitry Andric return It->second; 43a7dea167SDimitry Andric } 44a7dea167SDimitry Andric 45a7dea167SDimitry Andric bool Function::isVirtual() const { 46a7dea167SDimitry Andric if (auto *M = dyn_cast<CXXMethodDecl>(F)) 47a7dea167SDimitry Andric return M->isVirtual(); 48a7dea167SDimitry Andric return false; 49a7dea167SDimitry Andric } 50