================
@@ -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>
----------------
Michael137 wrote:

Sorry for not coming back to this earlier. Thanks for the additional context. 
Having re-read my comment, I *think* my point was probably moot? Thinking about 
the Python->byte-code compiler, if the user took care to only do expensive 
calls in `update`, the resulting byte-code would do the same. So 
re-interpreting the byte code *should* be cheap if the user to care to not make 
them expensive (which is the recommended way to write formatters anyway?). So 
even with your implementation here, it's really still mostly up to the user how 
expensive the resulting byte code interpretation is.

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