#include "rpc_server.hpp" #include "vm_provider.hpp" #include namespace sliger::rpc::action { struct Action { virtual auto perform_action( std::unique_ptr writer, sliger::rpc::vm_provider::VmProvider& vm_provider) -> void = 0; virtual ~Action() = default; }; class FlameGraph : public Action { public: FlameGraph() { } auto perform_action(std::unique_ptr writer, sliger::rpc::vm_provider::VmProvider& vm_provider) -> void; }; class CodeCoverage : public Action { public: CodeCoverage() { } auto perform_action(std::unique_ptr writer, sliger::rpc::vm_provider::VmProvider& vm_provider) -> void; }; class RunDebug : public Action { public: RunDebug(std::vector instructions) : instructions(instructions) { } auto perform_action(std::unique_ptr writer, sliger::rpc::vm_provider::VmProvider& vm_provider) -> void; private: std::vector instructions; }; static auto action_from_json( std::unique_ptr value) -> std::unique_ptr { auto& obj = value->as(); auto type = obj.fields.at("type")->as(); if (type.value == "flame-graph") { auto action = FlameGraph(); return std::make_unique(action); } if (type.value == "code-coverage") { auto action = CodeCoverage(); return std::make_unique(action); } if (type.value == "run-debug") { sliger::json::ArrayValues values = std::move( obj.fields.at("program")->as().values); auto instructions = std::vector(); for (auto& v : values) { std::unique_ptr moved = std::move(v); auto value = moved->as().value; instructions.push_back((uint32_t)value); } auto action = RunDebug(instructions); return std::make_unique(action); } throw "todo"; }; }