================
@@ -251,3 +254,150 @@ std::string ScriptedSyntheticChildren::GetDescription() {
 
   return std::string(sstr.GetString());
 }
+
+BytecodeSyntheticChildren::FrontEnd::FrontEnd(
+    ValueObject &backend,
+    FormatterBytecode::SyntheticProviderDefinition &definition)
+    : SyntheticChildrenFrontEnd(backend), m_definition(definition) {
+  FormatterBytecode::DataStack data(backend.GetSP());
+  if (!m_definition.init) {
+    m_self = std::move(data);
+    return;
+  }
+
+  FormatterBytecode::ControlStack control = {m_definition.init->getBuffer()};
+  llvm::Error error =
+      FormatterBytecode::Interpret(control, data, FormatterBytecode::sig_init);
+  if (error) {
+    LLDB_LOG_ERROR(GetLog(LLDBLog::DataFormatters), std::move(error),
+                   "@init failed: {0}");
+    return;
+  }
+
+  if (data.size() > 0)
+    m_self = std::move(data);
+}
+
+lldb::ChildCacheState BytecodeSyntheticChildren::FrontEnd::Update() {
+  if (!m_definition.update)
+    return ChildCacheState::eRefetch;
+
+  FormatterBytecode::ControlStack control = {m_definition.update->getBuffer()};
+  FormatterBytecode::DataStack data = m_self;
+  llvm::Error error = FormatterBytecode::Interpret(
+      control, data, FormatterBytecode::sig_update);
+  if (error) {
+    LLDB_LOG_ERROR(GetLog(LLDBLog::DataFormatters), std::move(error),
+                   "@update failed: {0}");
+    return ChildCacheState::eRefetch;
+  }
+
+  if (data.size() > 0)
+    m_self = std::move(data);
+
+  return ChildCacheState::eRefetch;
+}
+
+llvm::Expected<uint32_t>
----------------
kastiglione wrote:

yes, these reinterpret the bytecode. To my knowledge, the caching works the 
same as with Python.

> `Update` is the expensive thing that computes all the info that we need in 
> order to answer the other APIs efficiently.

This is my understanding too. However, at least for Python, it's a convention. 
You don't have to include an `update` method in your formatter class. A 
formatter could recompute each answer on every API call.

I think I see the perspective you have, and perhaps lldb could do more 
aggressive caching of results between calls to `update`, but I think that would 
happen outside of the respective Python or bytecode implementations.

https://github.com/llvm/llvm-project/pull/179832
_______________________________________________
lldb-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits

Reply via email to