阶段3-5:编译器验证——13 正例源码↔反汇编对照 + --dump-map

- STCompiler --dump-map:编译后打印变量/槽映射(函数局部 r 寄存器、
  全局 slot/off/type/func、实例 slot/off/fb/size/字段偏移)
- CodegenMap 输出结构(codegen_project 可选参数)
- 修复参数循环 bug(i+1<argc 漏掉末尾单参数选项)
- 结构自检(临时 stbcheck):13 用例寄存器/func/跳转/槽/长度全部通过
- 13 正例逐条对照全部通过,产出 Doc/compiler/用例反汇编对照.md
- 已知缺陷记录:LREAL 字面量装载按 REAL(TODO)
This commit is contained in:
2026-08-26 09:47:24 +08:00
parent b19a61aabf
commit 7b4961f7ed
5 changed files with 207 additions and 9 deletions
+15 -1
View File
@@ -11,6 +11,7 @@
#pragma once
#include <cstdint>
#include <map>
#include <string>
#include <vector>
@@ -21,6 +22,18 @@
namespace compiler {
/**
* @brief 变量/槽映射(--dump-map 用;验证源码 ↔ 反汇编对照)。
*/
struct CodegenMap {
/// 每函数:{ 函数名, { 局部变量名 → "寄存器号" } }
std::vector<std::pair<std::string, std::map<std::string, std::string>>> funcs;
/// 全局:{ 变量名 → "slot=.. off=.. type=.." }
std::map<std::string, std::string> globals;
/// 实例:{ "POU名/实例名" → "slot=.. off=.. fb=.. size=.. 字段:名@off.." }
std::map<std::string, std::string> instances;
};
/**
* @brief 编译工程为 .stb 映像字节(在链接 + 类型检查成功后调用)。
* @param proj 工程定义(cycle_limit / dt_ms / 哈希)
@@ -34,5 +47,6 @@ namespace compiler {
*/
bool codegen_project(const Project& proj, const std::vector<SourceUnit>& units,
const LinkResult& link, const MachineConfig& cfg,
std::vector<uint8_t>* image, std::string* err);
std::vector<uint8_t>* image, std::string* err,
CodegenMap* map = nullptr);
}