Skip to content

Commit

Permalink
update to clang18
Browse files Browse the repository at this point in the history
add cmake support
  • Loading branch information
limuy2022 committed Nov 25, 2023
1 parent a3779d8 commit 94ab808
Show file tree
Hide file tree
Showing 16 changed files with 138 additions and 7 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,14 @@
build/
out/
bin/
cmake_third_party/
Testing/
CMakeFiles/
.ninja_deps
.ninja_log
build.ninja
cmake_install.cmake
CMakeCache.txt
CMakeLists.txt
Makefile
rules.ninja
compile_commands.json
Expand Down
45 changes: 45 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
cmake_minimum_required(VERSION 3.28)
project(Trc CXX)
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)

set(CMAKE_CXX_STANDARD 20)
set(CMAKE_C_STANDARD 17)

add_library(modulefiles)

file(GLOB_RECURSE SOURCES "src/*.cppm")
file(GLOB_RECURSE LANGUAGE_SOURCES "language/*.cppm")
add_subdirectory("language")
target_sources(modulefiles
PUBLIC
FILE_SET CXX_MODULES FILES
${SOURCES}
${LANGUAGE_SOURCES}
)

file(GLOB_RECURSE CPP_SOURCES "src/*.cpp")
add_executable(Trc ${CPP_SOURCES})

target_link_libraries(Trc modulefiles language)

add_compile_definitions("UNITTEST")
file(GLOB_RECURSE TEST_SOURCES "tests/unittest/*.cpp")
file(GLOB_RECURSE TEST_MODULE_SOURCES "tests/unittest/*.cppm")
add_library(testmodulefiles)

target_sources(testmodulefiles
PUBLIC
FILE_SET CXX_MODULES FILES
${SOURCES}
${LANGUAGE_SOURCES}
${TEST_MODULE_SOURCES}
)

add_executable(unittest
${CPP_SOURCES}
${TEST_SOURCES}
)
target_link_libraries(Trc testmodulefiles language)

add_subdirectory("cmake_third_party/googletest")
include_directories("cmake_third_party/googletest/googletest/include")
24 changes: 24 additions & 0 deletions language/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
add_library(languagemodule)
file(GLOB_RECURSE LANGUAGE_SOURCES "*.cppm")

target_sources(languagemodule
PUBLIC
FILE_SET CXX_MODULES FILES
${LANGUAGE_SOURCES}
)

add_library(Chinese SHARED
chinese.cpp
)

add_library(English SHARED
english.cpp
)

add_library(language SHARED
english.cpp
)

target_link_libraries(Chinese languagemodule)
target_link_libraries(English languagemodule)
target_link_libraries(language languagemodule)
3 changes: 0 additions & 3 deletions language/xmake.lua
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,11 @@
target("Chinese")
set_kind("shared")
add_files("chinese.cpp", "./**.cppm")
add_defines("BUILD_language_DLL")

target("English")
set_kind("shared")
add_files("english.cpp", "./**.cppm")
add_defines("BUILD_language_DLL")

target("language")
set_kind("shared")
add_files("english.cpp", "./**.cppm")
add_defines("BUILD_language_DLL")
4 changes: 2 additions & 2 deletions src/Compiler/Compiler.cppm
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,7 @@ failed:

bool Compiler::left_value(bool error_report) {
// 匹配到ID
return func_call() || id();
return func_call() || id(true);
}

Compiler::Compiler(const std::string& module_name,
Expand Down Expand Up @@ -381,7 +381,7 @@ bool Compiler::value() {
}

bool Compiler::factor() {
if (item()) {
if (item(false)) {
return true;
}
return match(token_ticks::LEFT_SMALL_BRACE) && expr()
Expand Down
2 changes: 1 addition & 1 deletion src/TVM/TVM.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ namespace trc::TVM_space {
TVM::TVM(std::string name)
: name(std::move(name)) {
// 初始化TVM
TVM_space::init_mem();
init_mem();
}

void TVM::reload_data() {
Expand Down
11 changes: 11 additions & 0 deletions src/trc/Trc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,17 @@ import tools.token;
import tshell;
import basic_def;
import language;
import token;
import data;
import unreach;
import color;
import help;
import compile_env;
import Compiler;
import ctree_loader;
import filesys;
import code_loader;
import io;

namespace trc {
/**
Expand Down
10 changes: 10 additions & 0 deletions src/trc/tools/brun.cppm
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,16 @@ import build;
import generated_params;
import cmdparser;
import basic_def;
import compiler_def;
import token;
import data;
import unreach;
import color;
import help;
import compile_env;
import Compiler;
import ctree_loader;
import filesys;

export namespace trc::tools {
namespace tools_in {
Expand Down
7 changes: 7 additions & 0 deletions src/trc/tools/build.cppm
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,13 @@ import filesys;
import generated_params;
import cmdparser;
import basic_def;
import compiler_def;
import token;
import data;
import unreach;
import color;
import help;
import compile_env;

export namespace trc::tools {
namespace tools_in {
Expand Down
5 changes: 5 additions & 0 deletions src/trc/tools/dis.cppm
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,11 @@ import TVM;
import generated_params;
import cmdparser;
import basic_def;
import compiler_def;
import token;
import compile_env;
import help;
import color;

namespace trc::tools {
namespace tools_in {
Expand Down
6 changes: 6 additions & 0 deletions src/trc/tools/generated_params.cppm
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,18 @@ module;
#include <format>
export module generated_params;
import Compiler;
import compile_env;
import compiler_def;
import cmdparser;
import color;
import trcdef;
import help;
import basic_def;
import token;
import trc_flong;
import trc_long;
import data;
import unreach;

namespace trc::tools {
bool gen_number_table = true;
Expand Down
6 changes: 6 additions & 0 deletions src/trc/tools/run.cppm
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,12 @@ import filesys;
import generated_params;
import cmdparser;
import basic_def;
import compile_env;
import compiler_def;
import token;
import data;
import help;
import color;

export namespace trc::tools {
namespace tools_in {
Expand Down
3 changes: 3 additions & 0 deletions src/trc/tools/style.cppm
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@ import Compiler;
import generated_params;
import cmdparser;
import basic_def;
import compile_env;
import color;
import help;

namespace trc::tools {
static TVM_space::TVM_static_data vm;
Expand Down
8 changes: 8 additions & 0 deletions src/trc/tools/tdb.cppm
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,14 @@ import generated_params;
import trcdef;
import TVM.memory;
import language;
import compile_env;
import compiler_def;
import token;
import unreach;
import cmdparser;
import color;
import help;
import basic_def;

namespace trc {
namespace tdb {
Expand Down
3 changes: 3 additions & 0 deletions src/trc/tools/token.cppm
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@ import compiler_def;
import generated_params;
import cmdparser;
import basic_def;
import compile_env;
import color;
import help;

// token标记映射到名称,便于输出
// todo:从最新的token进行更新
Expand Down
5 changes: 5 additions & 0 deletions src/trc/tools/tshell.cppm
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,11 @@ import Error;
import io;
import generated_params;
import trcdef;
import compile_env;
import compiler_def;
import token;
import color;
import help;

/**
* @brief 判断是否为新的语句块开始
Expand Down

0 comments on commit 94ab808

Please sign in to comment.