Skip to content

protovm: add compiler#5784

Open
rukkal wants to merge 2 commits into
mainfrom
dev/rukkal/protovm-compiler
Open

protovm: add compiler#5784
rukkal wants to merge 2 commits into
mainfrom
dev/rukkal/protovm-compiler

Conversation

@rukkal
Copy link
Copy Markdown
Contributor

@rukkal rukkal commented May 8, 2026

protovm: add compiler

Introduces a compiler for ProtoVM that translates high-level configuration commands into
low-level bytecode instructions (VmProgram).

CompileConfig proto:

  • Defines a sequence of high-level commands.

CLI:

  • Reads CompileConfig textproto from stdin and outputs the compiled binary VmProgram
    to stdout.

Internal Compiler and InstructionEmitter classes:

  • Parse compile configs (textproto).
  • Resolve human-readable paths (field names) into field IDs using TracePacket and
    WinscopeExtensions descriptors.
  • Convert high-level commands into the corresponding sequence of VmInstruction.

@rukkal rukkal force-pushed the dev/rukkal/protovm-compiler branch 4 times, most recently from 496f16a to c458f69 Compare May 8, 2026 17:21
Introduces a compiler for ProtoVM that translates high-level
configuration commands into low-level bytecode instructions
(VmProgram).

CompileConfig proto:
- Defines a sequence of high-level commands

CLI:
- Reads CompileConfig textproto from stdin and outputs the
  compiled binary VmProgram to stdout.

Internal Compiler and InstructionEmitter classes:
- Parse compile configs (textproto)
- Resolve human-readable paths (field names) into field IDs
  using TracePacket and WinscopeExtensions descriptors.
- Convert high-level commands into the corresponding sequence
  of VmInstruction.

Change-Id: Icc63a5e653726f1b94100138099a80a9f99562a4
@rukkal rukkal force-pushed the dev/rukkal/protovm-compiler branch from c458f69 to 808c987 Compare May 8, 2026 17:50
@rukkal rukkal marked this pull request as ready for review May 9, 2026 14:09
@rukkal rukkal requested a review from a team as a code owner May 9, 2026 14:09
@rukkal rukkal requested a review from primiano May 9, 2026 14:09
Copy link
Copy Markdown
Member

@primiano primiano left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

THe code makes sense, my main suggestion is:

  1. use protoc_lib to pass the .proto file from cmdline rather than baking assumptions on which protos/descriptors you are going to need (or find a way to bundle them all, not just the winscope descriptor)

  2. Some more comments would help for future reading

the rest looks great

syntax = "proto2";

package perfetto.protos;

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

add some comments to explain what this is about?

Comment thread src/protovm/compiler/compiler.cc Outdated
namespace perfetto::protovm {

Compiler::Compiler() : emitter_(&pool_) {
pool_.AddFromFileDescriptorSet(perfetto::kTraceDescriptor.data(),
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

rather than building the descriptors in the tool, I think it woudl be more flebible if we depend on //gn:protoc_lib and we allow passing .proto files from the cmdline.
This makes the compiler more flexible, because you can just point it to the proto you need, rather than assuming "I'm going to need winscope so i am going to bundle them inside the tool"


namespace perfetto::protovm {

// Implements the compiler front-end.
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can we have README.md (or a /docs/design-doc) that explains what this compiler does. Just ask AI to turn your doc + code here into a README.md for here.

public:
Compiler();

base::StatusOr<std::string> Compile(std::string_view config_textproto);
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

add a comment saying which message config_textproto is supposed to match

syntax = "proto2";

package perfetto.protos;

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can you add a comment / explain what these protos are for? and how they are different from vm_program.proto?

Comment thread src/protovm/compiler/compiler.h Outdated
const protos::pbzero::Command::Decoder& command) const;

perfetto::trace_processor::DescriptorPool pool_;
const perfetto::trace_processor::ProtoDescriptor* root_proto_;
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

= nullptr

Comment thread src/protovm/compiler/main.cc Outdated
#include "perfetto/ext/base/file_utils.h"
#include "src/protovm/compiler/compiler.h"

int ProcessArgs(int argc, char** argv);
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

put this in the anon namespace

Comment thread src/protovm/compiler/main.cc Outdated
Comment thread src/protovm/compiler/main.cc Outdated
}

perfetto_host_executable("protovm_compiler") {
sources = [ "main.cc" ]
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if you make it testonly=true you can depend on protoc lib

Change-Id: Ibd7ece2b5c3dd218e8549494913ed68cc8c92493
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants