add some flame graph stuff
This commit is contained in:
parent
fca7370fee
commit
1e2406efce
@ -1,18 +1,6 @@
|
||||
import { Pos } from "./Token.ts";
|
||||
|
||||
export type Output = {
|
||||
program: Program;
|
||||
sourceMap: SourceMapping[];
|
||||
};
|
||||
|
||||
export type Program = Ins[];
|
||||
export type Ins = Ops | number;
|
||||
|
||||
export type SourceMapping = {
|
||||
bytecodeOffset: number;
|
||||
pos: Pos;
|
||||
};
|
||||
|
||||
// NOTICE: keep up to date with runtime/arch.hpp
|
||||
|
||||
export type Ops = typeof Ops;
|
||||
@ -41,4 +29,5 @@ export const Ops = {
|
||||
Or: 21,
|
||||
Xor: 22,
|
||||
Not: 23,
|
||||
SourceMap: 24,
|
||||
} as const;
|
||||
|
@ -31,6 +31,7 @@ enum class Op : uint32_t {
|
||||
Or = 21,
|
||||
Xor = 22,
|
||||
Not = 23,
|
||||
SourceMap = 24,
|
||||
};
|
||||
|
||||
}
|
||||
|
@ -195,11 +195,20 @@ void VM::run()
|
||||
stack_push(Bool { .value = value });
|
||||
break;
|
||||
}
|
||||
case Op::Not:
|
||||
case Op::Not: {
|
||||
assert_stack_has(1);
|
||||
auto value = !stack_pop().as_bool().value;
|
||||
stack_push(Bool { .value = value });
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -10,10 +10,40 @@
|
||||
|
||||
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 {
|
||||
public:
|
||||
VM(const std::vector<uint32_t>& program)
|
||||
: program(program.data())
|
||||
VM(const std::vector<uint32_t>& program, VMOpts opts)
|
||||
: opts(opts)
|
||||
, program(program.data())
|
||||
, program_size(program.size())
|
||||
{
|
||||
}
|
||||
@ -92,11 +122,14 @@ public:
|
||||
}
|
||||
|
||||
private:
|
||||
VMOpts opts;
|
||||
uint32_t pc = 0;
|
||||
uint32_t bp = 0;
|
||||
const uint32_t* program;
|
||||
size_t program_size;
|
||||
std::vector<Value> stack;
|
||||
std::vector<Value> pool_heap;
|
||||
SourcePos current_pos = { 0, 1, 1 };
|
||||
};
|
||||
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user