- Project.h 自带 IoBinding;Stb.h/cpp:compiler 侧 .stb 规范(常量/ConstEntry/FNV/StbView/读写/sidecar) - Codec.h/cpp:指令字 pack/字段/配置驱动 disasm(format 表驱动) - Codegen:opcode 全查 MachineConfig(E_* 发射器)、常量 tag 查配置类型、初值按基元宽度写、 映像拼装用 Stb 常量;codegen_project 增加 cfg 参数 - main.cpp:--machine <path>(编译/反汇编必填),--disasm 用 StbView+Codec - CMake:compiler 不再链接 isa(仅 toml++ 私有);测试补链 isa(自身断言用) - 验证:20 用例字节不变(hash 0xc3fe4ae74ad45900 相同)、ctest 12/12、缺 --machine 报错退出
50 lines
2.1 KiB
C++
50 lines
2.1 KiB
C++
/**
|
||
* @file Project.h
|
||
* @brief 工程定义与 project.toml 解析(schema 校验)
|
||
* @author
|
||
* @date 2026-08-21
|
||
*/
|
||
|
||
#pragma once
|
||
|
||
#include <cstdint>
|
||
#include <string>
|
||
#include <vector>
|
||
|
||
namespace compiler {
|
||
|
||
// I/O 绑定(project.toml [[io.*]];不创造变量,slot 由链接结果解析)
|
||
struct IoBinding {
|
||
std::string var;
|
||
uint32_t slot = 0;
|
||
uint32_t channel = 0;
|
||
uint32_t bit = 0;
|
||
bool is_input = false; // true = [[io.input]],false = [[io.output]]
|
||
};
|
||
|
||
// 与 Doc/初步计划.md 12.1 的 toml 字段表一一对应。
|
||
// 字段白名单 / 必填 / io 完整性在 parse_project 内校验。
|
||
struct Project {
|
||
std::string name; // [project] 必填
|
||
std::string entry; // 必填,第一版必须 "program MAIN"
|
||
uint32_t cycle_limit = 0; // 必填 > 0
|
||
uint32_t dt_ms = 0; // 必填 > 0
|
||
std::vector<std::string> files_st; // [files] 必填非空
|
||
std::string gvl_file; // [gvl] 可选;无则空串
|
||
std::vector<IoBinding> io; // [[io.*]] 可选;slot 12.6 才解析,此处填 0
|
||
std::string base_dir; // toml 所在目录(解析相对路径用)
|
||
};
|
||
|
||
// 解析并校验 project.toml。成功返回 true;失败返回 false 并写 err,
|
||
// err 带稳定类别前缀(unknown key / missing field / invalid value / bad entry)+ 行号。
|
||
bool parse_project(const std::string& toml_path, Project* out, std::string* err);
|
||
|
||
// 编译文件集合:files.st ∪ gvl.file,去重(gvl 已在 files.st 则跳过)。
|
||
// 保持 files.st 顺序,gvl 追加在后;相对路径以 base_dir 为基准解析。
|
||
std::vector<std::string> compile_files(const Project& p);
|
||
|
||
// 校验全部文件存在并计算工程哈希:集合按路径排序,对内容做 FNV-1a 64 增量;
|
||
// 空集合 = basis(Stb::kFnvBasis)。缺文件报错前缀 "file missing"。
|
||
bool compute_project_hash(const Project& p, uint64_t* hash, std::string* err);
|
||
}
|