mirror of
https://git.sfja.dk/Mikkel/slige.git
synced 2025-01-18 12:46:31 +00:00
add debug arg
This commit is contained in:
parent
753788b06d
commit
ab853d0516
@ -3,16 +3,16 @@
|
||||
#include "rpc_server.hpp"
|
||||
#include "vm.hpp"
|
||||
#include "vm_provider.hpp"
|
||||
#include <cstddef>
|
||||
#include <cstdint>
|
||||
#include <cstdlib>
|
||||
#include <format>
|
||||
#include <fstream>
|
||||
#include <iostream>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
bool print_stack_debug = true;
|
||||
|
||||
int execute_file_and_exit(std::string filename)
|
||||
int execute_file_and_exit(std::string filename, bool print_debug)
|
||||
{
|
||||
auto file = std::ifstream();
|
||||
file.open(filename.c_str());
|
||||
@ -36,7 +36,7 @@ int execute_file_and_exit(std::string filename)
|
||||
{
|
||||
.flame_graph = false,
|
||||
.code_coverage = false,
|
||||
.print_stack_debug = print_stack_debug,
|
||||
.print_debug = print_debug,
|
||||
});
|
||||
vm.run_until_done();
|
||||
return 0;
|
||||
@ -45,7 +45,27 @@ int execute_file_and_exit(std::string filename)
|
||||
int main(int argc, char** argv)
|
||||
{
|
||||
if (argc >= 3 && std::string(argv[1]) == "run") {
|
||||
return execute_file_and_exit(argv[2]);
|
||||
auto filename = std::string();
|
||||
bool print_debug = false;
|
||||
|
||||
for (int i = 2; i < argc; ++i) {
|
||||
auto arg = std::string(argv[i]);
|
||||
if (arg == "--print-debug") {
|
||||
print_debug = true;
|
||||
} else {
|
||||
if (!filename.empty()) {
|
||||
std::cerr << std::format("error: >1 files specified\n");
|
||||
std::exit(1);
|
||||
}
|
||||
filename = arg;
|
||||
}
|
||||
}
|
||||
if (filename.empty()) {
|
||||
std::cerr << std::format("error: no file specified\n");
|
||||
std::exit(1);
|
||||
}
|
||||
|
||||
return execute_file_and_exit(argv[2], print_debug);
|
||||
}
|
||||
|
||||
auto state = sliger::rpc::vm_provider::VmProvider();
|
||||
|
@ -30,7 +30,7 @@ void VM::run_n_instructions(size_t amount)
|
||||
|
||||
void VM::run_instruction()
|
||||
{
|
||||
if (this->opts.print_stack_debug) {
|
||||
if (this->opts.print_debug) {
|
||||
// std::cout << std::format(" {:>4}: {:<12}{}\n", this->pc,
|
||||
// maybe_op_to_string(this->program[this->pc]),
|
||||
// stack_repr_string(8));
|
||||
@ -281,7 +281,7 @@ void VM::run_instruction()
|
||||
|
||||
void VM::run_builtin(Builtin builtin_id)
|
||||
{
|
||||
if (this->opts.print_stack_debug) {
|
||||
if (this->opts.print_debug) {
|
||||
std::cout << std::format("Running builtin {}\n",
|
||||
maybe_builtin_to_string(static_cast<uint32_t>(builtin_id)));
|
||||
}
|
||||
|
@ -141,7 +141,7 @@ private:
|
||||
struct VMOpts {
|
||||
bool flame_graph;
|
||||
bool code_coverage;
|
||||
bool print_stack_debug;
|
||||
bool print_debug;
|
||||
};
|
||||
|
||||
class VM {
|
||||
|
@ -9,7 +9,7 @@ auto VmProvider::load_and_run(std::vector<uint32_t> instructions) -> void
|
||||
{
|
||||
.flame_graph = true,
|
||||
.code_coverage = true,
|
||||
.print_stack_debug = false,
|
||||
.print_debug = false,
|
||||
});
|
||||
vm.run_until_done();
|
||||
this->vm = vm;
|
||||
|
@ -11,5 +11,5 @@ deno run --allow-read --allow-write compiler/main.ts $1
|
||||
|
||||
echo Running out.slgbc...
|
||||
|
||||
./runtime/build/sliger run out.slgbc
|
||||
./runtime/build/sliger run out.slgbc ${@:2}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user