Function.cpp 1.7 KB

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