实现 12.3 toml 读取:schema 校验、文件集合、工程哈希。
- Project.h/cpp:toml++ 解析 + 字段白名单(未知键带行号报错)、name/entry/cycle_limit/dt_ms/files.st 必填、io 条目完整性、entry 必须 program MAIN - compile_files:files.st ∪ gvl.file 去重;compute_project_hash:路径排序后 FNV-1a 64 增量,缺文件报 file missing - STCompiler <project.toml>:打印文件列表与哈希,失败退出码 1,--help - compiler 私有链接 toml++ v3.4.0;测试固化 compiler_toml(35 断言,line1 哈希冻结 0xc3fe4ae74ad45900)
This commit is contained in:
@@ -0,0 +1,42 @@
|
||||
/**
|
||||
* @file Project.h
|
||||
* @brief 工程定义与 project.toml 解析(schema 校验)
|
||||
* @author
|
||||
* @date 2026-08-21
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <cstdint>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
#include "isa/Image.h"
|
||||
|
||||
namespace compiler {
|
||||
|
||||
// 与 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<isa::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(isa::kFnvBasis)。缺文件报错前缀 "file missing"。
|
||||
bool compute_project_hash(const Project& p, uint64_t* hash, std::string* err);
|
||||
}
|
||||
Reference in New Issue
Block a user