Skip to content

Commit

Permalink
初步使用Module
Browse files Browse the repository at this point in the history
  • Loading branch information
wangziwenhk committed Sep 24, 2024
1 parent 89733ca commit 8224502
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 27 deletions.
8 changes: 7 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,16 @@ include_directories(parser)

file(GLOB_RECURSE AST_FILES "parser/*.cpp" "parser/*.h")
file(GLOB_RECURSE SOURCE_FILES "src/*.cpp" "src/*.h")
file(GLOB_RECURSE MODULE_FILES "src/*.ixx")

add_library(Riddle_Module ${SOURCE_FILES})

target_sources(Riddle_Module PUBLIC FILE_SET CXX_MODULES FILES ${MODULE_FILES})

add_executable(Riddle_Language ${SOURCE_FILES} ${AST_FILES})

target_compile_definitions(Riddle_Language PRIVATE ${PLATFORM_DEFINES})

target_link_libraries(Riddle_Language LLVMCore)
target_link_libraries(Riddle_Language antlr4_shared)
target_link_libraries(Riddle_Language antlr4_shared)
target_link_libraries(Riddle_Language Riddle_Module)
2 changes: 1 addition & 1 deletion src/Tools/Managers/ClassManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
#define RIDDLE_LANGUAGE_CLASSMANAGER_H
#include <llvm/IR/IRBuilder.h>

#include "Types/Class.h"
import Types.Class;
#include "Types/ClassNode.h"

namespace Riddle{
Expand Down
9 changes: 0 additions & 9 deletions src/Types/Class.cpp

This file was deleted.

21 changes: 6 additions & 15 deletions src/Types/Class.h → src/Types/Class.ixx
Original file line number Diff line number Diff line change
@@ -1,23 +1,14 @@
//
// Created by wangz on 24-8-7.
//

#ifndef CLASS_H
#define CLASS_H

#include <map>
module;
#include <llvm/IR/DerivedTypes.h>
#include <llvm/IR/Function.h>

namespace Riddle{

#include <map>
export module Types.Class;
export namespace Riddle {
class Class {
public:
llvm::StructType *types = nullptr;
std::unordered_map<std::string,int> names;
std::unordered_map<std::string, int> names;
std::map<std::string, llvm::FunctionCallee> funcs;
};

} // Riddle

#endif //CLASS_H
}// namespace Riddle
2 changes: 1 addition & 1 deletion src/Types/ClassNode.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

#ifndef CLASSNODE_H
#define CLASSNODE_H
#include "Class.h"
import Types.Class;

namespace Riddle{
// 防止内存泄漏,启用 RAII 思想
Expand Down

0 comments on commit 8224502

Please sign in to comment.