@@ -109,8 +109,10 @@ class Value {
109109
110110 Scalar &ResolveValue (ExecutionContext *exe_ctx, Module *module = nullptr );
111111
112+ // / See comment on m_scalar to understand what GetScalar returns.
112113 const Scalar &GetScalar () const { return m_value; }
113114
115+ // / See comment on m_scalar to understand what GetScalar returns.
114116 Scalar &GetScalar () { return m_value; }
115117
116118 size_t ResizeData (size_t len);
@@ -148,6 +150,32 @@ class Value {
148150 static ValueType GetValueTypeFromAddressType (AddressType address_type);
149151
150152protected:
153+ // / Represents a value, which can be a scalar, a load address, a file address,
154+ // / or a host address.
155+ // /
156+ // / The interpretation of `m_value` depends on `m_value_type`:
157+ // / - Scalar: `m_value` contains the scalar value.
158+ // / - Load Address: `m_value` contains the load address.
159+ // / - File Address: `m_value` contains the file address.
160+ // / - Host Address: `m_value` contains a pointer to the start of the buffer in
161+ // / host memory.
162+ // / Currently, this can point to either:
163+ // / - The `m_data_buffer` of this Value instance (e.g., in DWARF
164+ // / computations).
165+ // / - The `m_data` of a Value Object containing this Value.
166+ // TODO: the GetScalar() API relies on knowledge not codified by the type
167+ // system, making it hard to understand and easy to misuse.
168+ // - Separate the scalar from the variable that contains the address (be it a
169+ // load, file or host address).
170+ // - Rename GetScalar() to something more indicative to what the scalar is,
171+ // like GetScalarOrAddress() for example.
172+ // - Split GetScalar() into two functions, GetScalar() and GetAddress(), which
173+ // verify (or assert) what m_value_type is to make sure users of the class are
174+ // querying the right thing.
175+ // TODO: It's confusing to point to multiple possible buffers when the
176+ // ValueType is a host address. Value should probably always own its buffer.
177+ // Perhaps as a shared pointer with a copy on write system if the same buffer
178+ // can be shared by multiple classes.
151179 Scalar m_value;
152180 CompilerType m_compiler_type;
153181 void *m_context = nullptr ;
0 commit comments