init4
This commit is contained in:
parent
0bf7488ed1
commit
ee28e8e2ee
|
|
@ -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")
|
||||
|
||||
|
|
|
|||
10
README.md
10
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 文件名
|
||||
|
||||
|
||||
# 文件结构
|
||||
|
|
|
|||
14
main.cpp
14
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;
|
||||
|
|
|
|||
|
|
@ -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_);
|
||||
|
|
|
|||
Loading…
Reference in New Issue