1 #pragma once 2 3 #include <cstddef> 4 5 #include <torch/csrc/jit/mobile/code.h> 6 #include <optional> 7 8 namespace torch::jit::mobile { 9 10 class Frame { 11 public: Frame(const Code & code)12 explicit Frame(const Code& code) : code_(code) {} getCode()13 const Code& getCode() const { 14 return code_; 15 } 16 step()17 void step() { 18 pc_++; 19 } 20 jump(size_t n)21 void jump(size_t n) { 22 pc_ += n; 23 } 24 getPC()25 size_t getPC() const { 26 return pc_; 27 } 28 getInstruction()29 const Instruction& getInstruction() const { 30 return code_.instructions_.at(pc_); 31 } 32 getDebugHandle()33 std::optional<int64_t> getDebugHandle() const { 34 return getDebugHandle(pc_); 35 } 36 getDebugHandle(size_t pc)37 std::optional<int64_t> getDebugHandle(size_t pc) const { 38 if (pc >= code_.debug_handles_.size()) { 39 return {}; 40 } 41 return code_.debug_handles_[pc]; 42 } 43 44 private: 45 const Code& code_; 46 size_t pc_{0}; 47 }; 48 49 } // namespace torch::jit::mobile 50