1 /* 2 * Copyright (c) 2021 Huawei Device Co., Ltd. 3 * Licensed under the Apache License, Version 2.0 (the "License"); 4 * you may not use this file except in compliance with the License. 5 * You may obtain a copy of the License at 6 * 7 * http://www.apache.org/licenses/LICENSE-2.0 8 * 9 * Unless required by applicable law or agreed to in writing, software 10 * distributed under the License is distributed on an "AS IS" BASIS, 11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 * See the License for the specific language governing permissions and 13 * limitations under the License. 14 */ 15 16 #ifndef PANDA_LIBPANDAFILE_LINE_PROGRAM_STATE_H_ 17 #define PANDA_LIBPANDAFILE_LINE_PROGRAM_STATE_H_ 18 19 #include "file-inl.h" 20 21 namespace panda::panda_file { 22 23 class LineProgramState { 24 public: LineProgramState(const File & pf,File::EntityId file,size_t line,Span<const uint8_t> constant_pool)25 LineProgramState(const File &pf, File::EntityId file, size_t line, Span<const uint8_t> constant_pool) 26 : pf_(pf), file_(file), line_(line), constant_pool_(constant_pool) 27 { 28 } 29 ~LineProgramState() = default; 30 DEFAULT_COPY_CTOR(LineProgramState) 31 DEFAULT_MOVE_CTOR(LineProgramState) 32 NO_COPY_OPERATOR(LineProgramState); 33 NO_MOVE_OPERATOR(LineProgramState); 34 AdvanceLine(int32_t v)35 void AdvanceLine(int32_t v) 36 { 37 line_ += static_cast<size_t>(v); 38 } 39 AdvancePc(uint32_t v)40 void AdvancePc(uint32_t v) 41 { 42 address_ += v; 43 } 44 SetColumn(int32_t c)45 void SetColumn(int32_t c) 46 { 47 column_ = static_cast<size_t>(c); 48 } 49 GetColumn()50 size_t GetColumn() const 51 { 52 return column_; 53 } 54 SetFile(uint32_t offset)55 void SetFile(uint32_t offset) 56 { 57 file_ = File::EntityId(offset); 58 } 59 GetFile()60 const uint8_t *GetFile() const 61 { 62 return pf_.GetStringData(file_).data; 63 } 64 HasFile()65 bool HasFile() const 66 { 67 return file_.IsValid(); 68 } 69 SetSourceCode(uint32_t offset)70 void SetSourceCode(uint32_t offset) 71 { 72 source_code_ = File::EntityId(offset); 73 } 74 GetSourceCode()75 const uint8_t *GetSourceCode() const 76 { 77 return pf_.GetStringData(source_code_).data; 78 } 79 HasSourceCode()80 bool HasSourceCode() const 81 { 82 return source_code_.IsValid(); 83 } 84 GetLine()85 size_t GetLine() const 86 { 87 return line_; 88 } 89 GetAddress()90 uint32_t GetAddress() const 91 { 92 return address_; 93 } 94 ReadULeb128()95 uint32_t ReadULeb128() 96 { 97 return panda_file::helpers::ReadULeb128(&constant_pool_); 98 } 99 ReadSLeb128()100 int32_t ReadSLeb128() 101 { 102 return panda_file::helpers::ReadLeb128(&constant_pool_); 103 } 104 GetPandaFile()105 const File &GetPandaFile() const 106 { 107 return pf_; 108 } 109 110 private: 111 const File &pf_; 112 113 File::EntityId file_; 114 File::EntityId source_code_; 115 size_t line_; 116 size_t column_ {0}; 117 Span<const uint8_t> constant_pool_; 118 119 uint32_t address_ {0}; 120 }; 121 122 } // namespace panda::panda_file 123 124 #endif // PANDA_LIBPANDAFILE_LINE_PROGRAM_STATE_H_ 125