- probe_dump.cc: import_file(argv[1], cell_size),cell_size 可走 argv[2],默认 8 - r8_test.cc: 两处直接写 scopes[0][...] 改成 set_cell_size(8)。bef8310 起 scopes 默认是空 vector(不再预置全局帧),旧写法是空 vector 上的 scopes[0], 实测 segfault;tape 用例块里新建的 r8asm 也要自己播种(.xor 展开读 scopes[0]["_CELL_SIZE"],否则 map::at 抛) - 新增 tools/cellsize_probe.cc: 测 CELL_SIZE 的播种时序(未播种时 CELL_SIZE 是 indeterminate、scopes 为空) 验收:build.sh 后端 29 断言全绿;stdmac_matrix.py 627 例 0 失败;asm/test.r8asm tape 与 2469c3a 版本 md5 一致(264296f5…)、VM 输出 127 11 1 139 0 / 127 11 11 / 127 11 127 / 127 11 116 / 127 1 128 0
56 lines
2.1 KiB
C++
56 lines
2.1 KiB
C++
#include <cstddef>
|
|
#include <cstdint>
|
|
#include <fstream>
|
|
#include <iostream>
|
|
#include <map>
|
|
#include <sstream>
|
|
#include <string>
|
|
#include <vector>
|
|
|
|
#define private public
|
|
#include "r8asm/r8asm.hh"
|
|
#undef private
|
|
|
|
// cellsize_probe — CELL_SIZE 的播种时序探针(bef8310 起 CELL_SIZE 从编译期常量
|
|
// 变成 ast 的运行时成员,由 set_cell_size 播种)。
|
|
//
|
|
// 编译与运行(必须在 r8asm_rev 根目录跑,%include 路径相对 cwd):
|
|
// g++ -std=c++20 -Iinclude src/r8asm.cc \
|
|
// r8asm-rev-tests/tools/cellsize_probe.cc -o build/cellsize_probe
|
|
// ./build/cellsize_probe asm/test.r8asm
|
|
//
|
|
// 关注点:
|
|
// [A]/[B] 未播种时 CELL_SIZE 是 indeterminate(实测 0,但不保证)、scopes 为空 vector
|
|
// → 此时 scopes[0] 是越界写,scopes.back() 是越界读
|
|
// [C] import_file 结束后 CELL_SIZE 与 scopes[0] 才成型(播种发生在 parse 之后,
|
|
// 所以 %include 里嵌套那次 import_file 读到的是父层当时的 CELL_SIZE)
|
|
int main(int argc, char **argv) {
|
|
using ast = r8asm::ast;
|
|
|
|
// 1) 直接构造 ast: scopes 默认是什么?CELL_SIZE 默认是什么?
|
|
{
|
|
ast a;
|
|
std::cout << "[A] freshly constructed ast: scopes.size()=" << a.scopes.size()
|
|
<< " CELL_SIZE(未初始化)=" << a.CELL_SIZE << "\n";
|
|
}
|
|
|
|
// 2) 构造 r8asm,打印 import_file 之前的 main_tree.CELL_SIZE
|
|
r8asm r;
|
|
std::cout << "[B] before any import_file: main_tree.CELL_SIZE="
|
|
<< r.main_tree.CELL_SIZE
|
|
<< " scopes.size()=" << r.main_tree.scopes.size() << "\n";
|
|
|
|
// 3) import_file 之后 CELL_SIZE 与 scopes[0] 的形态
|
|
// 先塞哨兵值,确认 import_file 末尾的 set_cell_size 会把它覆盖成实参
|
|
r.main_tree.CELL_SIZE = 0xDEADBEEF;
|
|
r.import_file(argv[1], 8);
|
|
std::cout << "[C] after import_file(...,8): CELL_SIZE=" << r.main_tree.CELL_SIZE
|
|
<< " scopes.size()=" << r.main_tree.scopes.size() << "\n";
|
|
if (!r.main_tree.scopes.empty()) {
|
|
for (const auto &kv : r.main_tree.scopes[0])
|
|
std::cout << " scopes[0] " << kv.first << " = " << kv.second << "\n";
|
|
}
|
|
std::cout << "tape bytes=" << r.export_rot8().size() << "\n";
|
|
return 0;
|
|
}
|