From ee28e8e2eeed1373731c527efe9a78a4dc996dad Mon Sep 17 00:00:00 2001 From: lyc Date: Tue, 3 Dec 2024 00:06:45 +0800 Subject: [PATCH] init4 --- CMakeLists.txt | 2 +- README.md | 10 ++-------- main.cpp | 14 +++++++++++--- src/TCG/Translator.cpp | 2 +- 4 files changed, 15 insertions(+), 13 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 345bb8f..c5eec1a 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,7 +1,7 @@ cmake_minimum_required(VERSION 3.5) project(LiteGoCompiler) -set(CMAKE_CXX_STANDARD 20) +set(CMAKE_CXX_STANDARD 17) set(CMAKE_BUILD_TYPE Release) set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -w -O2 -g") diff --git a/README.md b/README.md index 4f0c20a..a3a8863 100644 --- a/README.md +++ b/README.md @@ -5,18 +5,12 @@ - openJDK version "17.0.12" - NASM version 2.16.01 - antlr complete & runtime Version: 4.9.3 - +- glog # 执行 ```shell -bash runme.sh +bash test_all.sh ``` -参数说明: -1. -d (--dir): [default: ./ ] 输出文件路径 -2. -3 (--3code): [default: 3code.txt] 输出 3code 文件名 -3. -a (--asm): [default: out] 输出 asm 文件名 -4. -b (--bin): [default: bin] 输出 bin 文件名 - # 文件结构 diff --git a/main.cpp b/main.cpp index f41bebe..ce1d038 100644 --- a/main.cpp +++ b/main.cpp @@ -15,6 +15,14 @@ using namespace std; +bool ends_with(const std::string& str, const std::string& suffix) { + if (str.length() < suffix.length()) { + return false; + } + return str.compare(str.length() - suffix.length(), suffix.length(), suffix) == 0; +} + + void init_log(const std::string& log_file_name, const std::string& log_path) { system(("mkdir -p " + log_path).c_str()); google::InitGoogleLogging(log_file_name.c_str()); @@ -32,7 +40,7 @@ struct CmdParam { std::string output_3code = "3code.txt"; std::string output_asm = "out.asm"; std::string output_bin = "out.bin"; - std::string log_path; + std::string log_path = "./log"; std::string log_file_name; }; @@ -50,7 +58,7 @@ CmdParam read_cmd_param(int argc, char* argv[]) { for (int i = 1; i < argc; ++i) { std::string argv_i = argv[i]; - if (argv_i.starts_with('-')) { + if (argv_i[0] == '-') { if (argv_i.length() == 1) { std::cerr << "Invalid option." << std::endl; exit(EXIT_FAILURE); @@ -77,7 +85,7 @@ CmdParam read_cmd_param(int argc, char* argv[]) { for (const auto& input_file : cmd_param.input) { std::string base_name = std::filesystem::path(input_file).stem().string(); - if (base_name.ends_with(".go")) { + if (ends_with(base_name, ".go")) { base_name = base_name.substr(0, base_name.length() - 3); } cmd_param.output = base_name; diff --git a/src/TCG/Translator.cpp b/src/TCG/Translator.cpp index c7b63dc..c24c625 100644 --- a/src/TCG/Translator.cpp +++ b/src/TCG/Translator.cpp @@ -60,7 +60,7 @@ void Translator::textTranslate() { /* crTODO: 将 SymbolManager_ 改为 一个快一个 ? ljh 不用 */ // todo 根据函数名到block的map初始化 if (i->first == "global" || i->first == "myprint" || i->second->size() == 0) continue; - LOG(WARNING) << "start 翻译函数: " << i->first; + LOG(WARNING) << "Function: " << i->first; SymbolManager SymbolManager_(Global_Scope, i->first); ASMBlock ASMBlock_ = BlockTranslator_.BlockTranslate(SymbolManager_, i->second); ASMSection_.asmblocks.push_back(ASMBlock_);