/*
 * Copyright (C) 2026 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

syntax = "proto2";

package perfetto.protos;

// The configuration for the ProtoVM compiler.
// It defines a sequence of high-level compilation commands that the compiler
// translates into low-level instructions (VmProgram/VmInstruction).
message CompileConfig {
  // The fully qualified name of the root message. The paths in the compiler
  // commands are relative to this message. This is tipically set to
  // "perfetto.protos.TracePacket".
  optional string root_message = 1;
  repeated CompileCommand commands = 2;
}

message CompileCommand {
  oneof command {
    CompileCommandDel del = 1;
    CompileCommandEnterScope enter_scope = 2;
    CompileCommandMerge merge = 3;
    CompileCommandSet set = 4;
  }

  enum AbortLevel {
    // Skip current command but execute following ones
    SKIP_CURRENT_COMMAND = 1;
    // Skip current command as well as following ones (default)
    SKIP_CURRENT_COMMAND_AND_BREAK_OUTER = 2;
    // Abort whole program
    ABORT = 3;
  };
  optional AbortLevel abort_level = 5;
}

message CompileCommandDel {
  repeated string src = 1;
  repeated string dst = 2;
  optional bool if_src_present = 3;
  optional string dst_key_field = 4;
}

message CompileCommandEnterScope {
  repeated string src = 1;
  repeated string dst = 2;
  repeated CompileCommand commands = 3;
}

message CompileCommandMerge {
  repeated string src = 1;
  repeated string dst = 2;
  optional bool recursive = 3;
  optional string key_field = 4;
}

message CompileCommandSet {
  repeated string src = 1;
  repeated string dst = 2;
}
