diff --git a/.clangd b/.clangd new file mode 100644 index 0000000..829c7b0 --- /dev/null +++ b/.clangd @@ -0,0 +1,2 @@ +CompileFlags: + CompilationDatabase: build/gcc-debug diff --git a/compiler/src/Project.cpp b/compiler/src/Project.cpp index c809ee5..a7f748a 100644 --- a/compiler/src/Project.cpp +++ b/compiler/src/Project.cpp @@ -23,12 +23,14 @@ namespace { // ---- 错误收集:稳定类别前缀 + 行号 ---- + // 写错误消息;err 为 nullptr 时静默忽略(调用方可不关心原因) void fail(std::string* err, const std::string& msg) { if (err) { *err = msg; } } + // 给 toml 节点附加行号后缀 " (line N)",用于定位非法值位置 std::string at(const toml::node& n) { char buf[32]; std::snprintf(buf, sizeof buf, " (line %u)", n.source().begin.line); @@ -125,6 +127,8 @@ namespace { // ---- [project] ---- + // [project] 段:name/entry/cycle_limit/dt_ms 全必填; + // 第一版 entry 只接受 "program MAIN" bool parse_project_section(const toml::table& root, Project* out, std::string* err) { static const char* const allowed[] = {"name", "entry", "cycle_limit", "dt_ms"}; @@ -162,6 +166,7 @@ namespace { // ---- [files] ---- + // [files] 段:st 必填、非空数组,元素必须全为字符串,按声明顺序收集 bool parse_files_section(const toml::table& root, Project* out, std::string* err) { static const char* const allowed[] = {"st"}; @@ -203,6 +208,7 @@ namespace { // ---- [gvl](可选)---- + // [gvl] 段:可选;存在时 file 必填字符串,缺失整段不报错 bool parse_gvl_section(const toml::table& root, Project* out, std::string* err) { static const char* const allowed[] = {"file"}; @@ -222,6 +228,7 @@ namespace { // ---- [[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) { static const char* const allowed[] = {"var", "channel", "bit"}; @@ -250,6 +257,7 @@ namespace { return true; } + // [io] 段:可选;input/output 子表为数组时逐条解析,两数组都可缺省 bool parse_io_section(const toml::table& root, Project* out, std::string* err) { 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) { static const char* const allowed[] = {"project", "files", "gvl", "io"}; if (!check_keys(root, "root", allowed, 4, err)) { @@ -301,6 +311,7 @@ namespace { return parse_io_section(root, out, err); } + // 取路径的目录部分:最后一个分隔符之前;无分隔符返回 "."(相对当前目录) std::string dir_of(const std::string& path) { const size_t slash = path.find_last_of("/\\"); return (slash == std::string::npos) ? "." : path.substr(0, slash); diff --git a/isa/CMakeLists.txt b/isa/CMakeLists.txt index 2f42c49..508b752 100644 --- a/isa/CMakeLists.txt +++ b/isa/CMakeLists.txt @@ -6,10 +6,6 @@ project(ISA VERSION 0.1 DESCRIPTION "指令集架构") -# C/C++ 标准版本 -set(CMAKE_C_STANDARD 11) -set(CMAKE_CXX_STANDARD 11) - add_library(isa STATIC ./src/Encode.cpp ./src/Image.cpp)