add some flame graph stuff

This commit is contained in:
SimonFJ20 2024-11-18 15:01:24 +01:00
parent fca7370fee
commit 1e2406efce
4 changed files with 47 additions and 15 deletions

View File

@ -1,18 +1,6 @@
import { Pos } from "./Token.ts";
export type Output = {
program: Program;
sourceMap: SourceMapping[];
};
export type Program = Ins[]; export type Program = Ins[];
export type Ins = Ops | number; export type Ins = Ops | number;
export type SourceMapping = {
bytecodeOffset: number;
pos: Pos;
};
// NOTICE: keep up to date with runtime/arch.hpp // NOTICE: keep up to date with runtime/arch.hpp
export type Ops = typeof Ops; export type Ops = typeof Ops;
@ -41,4 +29,5 @@ export const Ops = {
Or: 21, Or: 21,
Xor: 22, Xor: 22,
Not: 23, Not: 23,
SourceMap: 24,
} as const; } as const;

View File

@ -31,6 +31,7 @@ enum class Op : uint32_t {
Or = 21, Or = 21,
Xor = 22, Xor = 22,
Not = 23, Not = 23,
SourceMap = 24,
}; };
} }

View File

@ -195,11 +195,20 @@ void VM::run()
stack_push(Bool { .value = value }); stack_push(Bool { .value = value });
break; break;
} }
case Op::Not: case Op::Not: {
assert_stack_has(1); assert_stack_has(1);
auto value = !stack_pop().as_bool().value; auto value = !stack_pop().as_bool().value;
stack_push(Bool { .value = value }); stack_push(Bool { .value = value });
break; break;
} }
case Op::SourceMap: {
assert_program_has(3);
auto index = eat_int32();
auto line = eat_int32();
auto col = eat_int32();
this->current_pos = { index, line, col };
break;
}
}
} }
} }

View File

@ -10,10 +10,40 @@
namespace sliger { namespace sliger {
struct SourcePos {
int index;
int line;
int col;
};
struct FGNode {
uint32_t fn;
int64_t acc;
int64_t ic_start;
size_t parent;
std::vector<size_t> children;
};
class FlameGraphBuilder {
public:
inline auto report_call(size_t fn, int64_t ic_start) { }
inline auto report_return(int64_t ic_end) { }
private:
std::vector<FGNode> nodes;
};
struct VMOpts {
bool flameGraph;
bool codeCoverage;
};
class VM { class VM {
public: public:
VM(const std::vector<uint32_t>& program) VM(const std::vector<uint32_t>& program, VMOpts opts)
: program(program.data()) : opts(opts)
, program(program.data())
, program_size(program.size()) , program_size(program.size())
{ {
} }
@ -92,11 +122,14 @@ public:
} }
private: private:
VMOpts opts;
uint32_t pc = 0; uint32_t pc = 0;
uint32_t bp = 0; uint32_t bp = 0;
const uint32_t* program; const uint32_t* program;
size_t program_size; size_t program_size;
std::vector<Value> stack; std::vector<Value> stack;
std::vector<Value> pool_heap; std::vector<Value> pool_heap;
SourcePos current_pos = { 0, 1, 1 };
}; };
} }