2024-11-27 13:28:45 +01:00
|
|
|
#include "rpc_server.hpp"
|
2024-12-09 13:03:21 +01:00
|
|
|
#include "vm_provider.hpp"
|
2024-11-27 13:28:45 +01:00
|
|
|
#include <memory>
|
|
|
|
|
|
|
|
namespace sliger::rpc::action {
|
|
|
|
|
|
|
|
struct Action {
|
|
|
|
virtual auto perform_action(
|
2024-12-09 13:03:21 +01:00
|
|
|
std::unique_ptr<sliger::rpc::BufferedWriter> writer,
|
2024-12-12 11:57:18 +01:00
|
|
|
sliger::rpc::vm_provider::VmProvider& vm_provider) -> void = 0;
|
2024-11-27 13:28:45 +01:00
|
|
|
virtual ~Action() = default;
|
|
|
|
};
|
|
|
|
|
2024-12-09 13:03:21 +01:00
|
|
|
class FlameGraph : public Action {
|
|
|
|
public:
|
|
|
|
FlameGraph() { }
|
|
|
|
auto perform_action(std::unique_ptr<sliger::rpc::BufferedWriter> writer,
|
2024-12-12 11:57:18 +01:00
|
|
|
sliger::rpc::vm_provider::VmProvider& vm_provider) -> void;
|
2024-12-09 13:03:21 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
class CodeCoverage : public Action {
|
|
|
|
public:
|
|
|
|
CodeCoverage() { }
|
|
|
|
auto perform_action(std::unique_ptr<sliger::rpc::BufferedWriter> writer,
|
2024-12-12 11:57:18 +01:00
|
|
|
sliger::rpc::vm_provider::VmProvider& vm_provider) -> void;
|
2024-12-09 13:03:21 +01:00
|
|
|
};
|
|
|
|
|
2024-11-27 13:28:45 +01:00
|
|
|
class RunDebug : public Action {
|
|
|
|
public:
|
|
|
|
RunDebug(std::vector<uint32_t> instructions)
|
|
|
|
: instructions(instructions)
|
|
|
|
{
|
|
|
|
}
|
2024-12-09 13:03:21 +01:00
|
|
|
auto perform_action(std::unique_ptr<sliger::rpc::BufferedWriter> writer,
|
2024-12-12 11:57:18 +01:00
|
|
|
sliger::rpc::vm_provider::VmProvider& vm_provider) -> void;
|
2024-11-27 13:28:45 +01:00
|
|
|
|
|
|
|
private:
|
|
|
|
std::vector<uint32_t> instructions;
|
|
|
|
};
|
|
|
|
|
2024-12-13 16:03:01 +01:00
|
|
|
static inline auto action_from_json(
|
2024-11-27 13:28:45 +01:00
|
|
|
std::unique_ptr<json::Value> value) -> std::unique_ptr<Action>
|
|
|
|
{
|
|
|
|
auto& obj = value->as<sliger::json::Object>();
|
|
|
|
auto type = obj.fields.at("type")->as<sliger::json::String>();
|
|
|
|
|
2024-12-12 11:57:18 +01:00
|
|
|
if (type.value == "flame-graph") {
|
2024-12-09 13:03:21 +01:00
|
|
|
auto action = FlameGraph();
|
|
|
|
return std::make_unique<FlameGraph>(action);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (type.value == "code-coverage") {
|
|
|
|
auto action = CodeCoverage();
|
|
|
|
return std::make_unique<CodeCoverage>(action);
|
|
|
|
}
|
|
|
|
|
2024-11-27 13:28:45 +01:00
|
|
|
if (type.value == "run-debug") {
|
|
|
|
sliger::json::ArrayValues values = std::move(
|
|
|
|
obj.fields.at("program")->as<sliger::json::Array>().values);
|
|
|
|
auto instructions = std::vector<uint32_t>();
|
|
|
|
for (auto& v : values) {
|
|
|
|
std::unique_ptr<json::Value> moved = std::move(v);
|
|
|
|
auto value = moved->as<sliger::json::Number>().value;
|
|
|
|
instructions.push_back((uint32_t)value);
|
|
|
|
}
|
|
|
|
auto action = RunDebug(instructions);
|
|
|
|
return std::make_unique<RunDebug>(action);
|
|
|
|
}
|
|
|
|
throw "todo";
|
|
|
|
};
|
|
|
|
}
|