清理:isa 去掉局部 C++11 覆盖,Project.cpp 补注释,加 .clangd。
- isa/CMakeLists.txt 删除 set(CMAKE_CXX_STANDARD 11):会覆盖全局 C++20 决策,改由 Standards.cmake 统一 - Project.cpp 各段解析补说明注释 - .clangd:clangd 编译数据库指向 build/gcc-debug
This commit is contained in:
@@ -23,12 +23,14 @@ namespace {
|
|||||||
|
|
||||||
// ---- 错误收集:稳定类别前缀 + 行号 ----
|
// ---- 错误收集:稳定类别前缀 + 行号 ----
|
||||||
|
|
||||||
|
// 写错误消息;err 为 nullptr 时静默忽略(调用方可不关心原因)
|
||||||
void fail(std::string* err, const std::string& msg) {
|
void fail(std::string* err, const std::string& msg) {
|
||||||
if (err) {
|
if (err) {
|
||||||
*err = msg;
|
*err = msg;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 给 toml 节点附加行号后缀 " (line N)",用于定位非法值位置
|
||||||
std::string at(const toml::node& n) {
|
std::string at(const toml::node& n) {
|
||||||
char buf[32];
|
char buf[32];
|
||||||
std::snprintf(buf, sizeof buf, " (line %u)", n.source().begin.line);
|
std::snprintf(buf, sizeof buf, " (line %u)", n.source().begin.line);
|
||||||
@@ -125,6 +127,8 @@ namespace {
|
|||||||
|
|
||||||
// ---- [project] ----
|
// ---- [project] ----
|
||||||
|
|
||||||
|
// [project] 段:name/entry/cycle_limit/dt_ms 全必填;
|
||||||
|
// 第一版 entry 只接受 "program MAIN"
|
||||||
bool parse_project_section(const toml::table& root, Project* out, std::string* err) {
|
bool parse_project_section(const toml::table& root, Project* out, std::string* err) {
|
||||||
static const char* const allowed[] = {"name", "entry", "cycle_limit", "dt_ms"};
|
static const char* const allowed[] = {"name", "entry", "cycle_limit", "dt_ms"};
|
||||||
|
|
||||||
@@ -162,6 +166,7 @@ namespace {
|
|||||||
|
|
||||||
// ---- [files] ----
|
// ---- [files] ----
|
||||||
|
|
||||||
|
// [files] 段:st 必填、非空数组,元素必须全为字符串,按声明顺序收集
|
||||||
bool parse_files_section(const toml::table& root, Project* out, std::string* err) {
|
bool parse_files_section(const toml::table& root, Project* out, std::string* err) {
|
||||||
static const char* const allowed[] = {"st"};
|
static const char* const allowed[] = {"st"};
|
||||||
|
|
||||||
@@ -203,6 +208,7 @@ namespace {
|
|||||||
|
|
||||||
// ---- [gvl](可选)----
|
// ---- [gvl](可选)----
|
||||||
|
|
||||||
|
// [gvl] 段:可选;存在时 file 必填字符串,缺失整段不报错
|
||||||
bool parse_gvl_section(const toml::table& root, Project* out, std::string* err) {
|
bool parse_gvl_section(const toml::table& root, Project* out, std::string* err) {
|
||||||
static const char* const allowed[] = {"file"};
|
static const char* const allowed[] = {"file"};
|
||||||
|
|
||||||
@@ -222,6 +228,7 @@ namespace {
|
|||||||
|
|
||||||
// ---- [[io.input]] / [[io.output]](可选)----
|
// ---- [[io.input]] / [[io.output]](可选)----
|
||||||
|
|
||||||
|
// 单个 I/O 条目:var/channel/bit 全必填、全非负整数;slot 留待 12.6 链接阶段
|
||||||
bool parse_io_entry(const toml::node& el, bool is_input, Project* out, std::string* err) {
|
bool parse_io_entry(const toml::node& el, bool is_input, Project* out, std::string* err) {
|
||||||
static const char* const allowed[] = {"var", "channel", "bit"};
|
static const char* const allowed[] = {"var", "channel", "bit"};
|
||||||
|
|
||||||
@@ -250,6 +257,7 @@ namespace {
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// [io] 段:可选;input/output 子表为数组时逐条解析,两数组都可缺省
|
||||||
bool parse_io_section(const toml::table& root, Project* out, std::string* err) {
|
bool parse_io_section(const toml::table& root, Project* out, std::string* err) {
|
||||||
static const char* const allowed[] = {"input", "output"};
|
static const char* const allowed[] = {"input", "output"};
|
||||||
|
|
||||||
@@ -284,6 +292,8 @@ namespace {
|
|||||||
|
|
||||||
// ---- 顶层 ----
|
// ---- 顶层 ----
|
||||||
|
|
||||||
|
// 顶层:root 键白名单 + 按 project → files → gvl → io 顺序解析,
|
||||||
|
// 任一段失败立即返回 false(首个错误优先,不做恢复)
|
||||||
bool parse_root(const toml::table& root, Project* out, std::string* err) {
|
bool parse_root(const toml::table& root, Project* out, std::string* err) {
|
||||||
static const char* const allowed[] = {"project", "files", "gvl", "io"};
|
static const char* const allowed[] = {"project", "files", "gvl", "io"};
|
||||||
if (!check_keys(root, "root", allowed, 4, err)) {
|
if (!check_keys(root, "root", allowed, 4, err)) {
|
||||||
@@ -301,6 +311,7 @@ namespace {
|
|||||||
return parse_io_section(root, out, err);
|
return parse_io_section(root, out, err);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 取路径的目录部分:最后一个分隔符之前;无分隔符返回 "."(相对当前目录)
|
||||||
std::string dir_of(const std::string& path) {
|
std::string dir_of(const std::string& path) {
|
||||||
const size_t slash = path.find_last_of("/\\");
|
const size_t slash = path.find_last_of("/\\");
|
||||||
return (slash == std::string::npos) ? "." : path.substr(0, slash);
|
return (slash == std::string::npos) ? "." : path.substr(0, slash);
|
||||||
|
|||||||
@@ -6,10 +6,6 @@ project(ISA
|
|||||||
VERSION 0.1
|
VERSION 0.1
|
||||||
DESCRIPTION "指令集架构")
|
DESCRIPTION "指令集架构")
|
||||||
|
|
||||||
# C/C++ 标准版本
|
|
||||||
set(CMAKE_C_STANDARD 11)
|
|
||||||
set(CMAKE_CXX_STANDARD 11)
|
|
||||||
|
|
||||||
add_library(isa STATIC
|
add_library(isa STATIC
|
||||||
./src/Encode.cpp
|
./src/Encode.cpp
|
||||||
./src/Image.cpp)
|
./src/Image.cpp)
|
||||||
|
|||||||
Reference in New Issue
Block a user