diff --git a/doc/实验进度与测试方法.md b/doc/实验进度与测试方法.md index 1f20576..3c982dd 100644 --- a/doc/实验进度与测试方法.md +++ b/doc/实验进度与测试方法.md @@ -124,7 +124,7 @@ g++ -std=c++17 \ -Isrc \ -Ibuild-sema/generated/antlr4 \ -Ithird_party/antlr4-runtime-4.13.2/runtime/src \ - build-sema/sema_check.cpp \ + tools/sema_check.cpp \ build-sema/src/sem/libsem.a \ build-sema/src/frontend/libfrontend.a \ build-sema/src/utils/libutils.a \ diff --git a/sysy2022.pdf b/sysy2022.pdf new file mode 100644 index 0000000..217d6bd Binary files /dev/null and b/sysy2022.pdf differ diff --git a/tools/sema_check.cpp b/tools/sema_check.cpp new file mode 100644 index 0000000..ce6b574 --- /dev/null +++ b/tools/sema_check.cpp @@ -0,0 +1,34 @@ +#include +#include +#include + +#include "frontend/AntlrDriver.h" +#include "sem/Sema.h" +#include "utils/Log.h" + +int main(int argc, char** argv) { + if (argc < 2) { + std::cerr << "usage: sema_check [more.sy...]\n"; + return 2; + } + + bool failed = false; + for (int i = 1; i < argc; ++i) { + const std::string path = argv[i]; + try { + auto antlr = ParseFileWithAntlr(path); + auto* comp_unit = dynamic_cast(antlr.tree); + if (!comp_unit) { + throw std::runtime_error(FormatError("sema_check", "语法树根节点不是 compUnit")); + } + (void)RunSema(*comp_unit); + std::cout << "OK " << path << "\n"; + } catch (const std::exception& ex) { + failed = true; + std::cout << "ERR " << path << "\n"; + PrintException(std::cout, ex); + } + } + + return failed ? 1 : 0; +}