Skip to content

Commit

Permalink
Merge pull request #21 from X-FRI/main
Browse files Browse the repository at this point in the history
update compiler, support vs2022
  • Loading branch information
muqiuhan authored Apr 18, 2024
2 parents ad8adaf + 651ebf9 commit 4067bd4
Show file tree
Hide file tree
Showing 42 changed files with 6,510 additions and 1,730 deletions.
12 changes: 6 additions & 6 deletions .clang-format
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ BreakBeforeTernaryOperators: true
BreakConstructorInitializersBeforeComma: true
AllowAllArgumentsOnNextLine: true
AllowAllParametersOfDeclarationOnNextLine: true
ColumnLimit: 80
ColumnLimit: 120
CommentPragmas: '^ IWYU pragma:'
ConstructorInitializerAllOnOneLineOrOnePerLine: true
ConstructorInitializerIndentWidth: 2
Expand All @@ -47,11 +47,11 @@ MacroBlockBegin: ''
MacroBlockEnd: ''
MaxEmptyLinesToKeep: 1
NamespaceIndentation: All
PenaltyBreakComment: 80
PenaltyBreakFirstLessLess: 80
PenaltyBreakString: 80
PenaltyExcessCharacter: 80
PenaltyReturnTypeOnItsOwnLine: 80
PenaltyBreakComment: 120
PenaltyBreakFirstLessLess: 120
PenaltyBreakString: 120
PenaltyExcessCharacter: 120
PenaltyReturnTypeOnItsOwnLine: 120
PointerAlignment: Middle
ReflowComments: true
SortIncludes: "Never"
Expand Down
5 changes: 0 additions & 5 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,6 @@ build/

compile_commands.json

compiler/lexer/flex_lexer.cpp
compiler/parser/bison_parser.cpp
compiler/parser/bison_parser.hpp
compiler/parser/location.hh

.ninja_deps
.ninja_log

Expand Down
56 changes: 25 additions & 31 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -8,23 +8,24 @@ cmake_policy(SET CMP0091 NEW)
project(swallow VERSION 0.0.1 LANGUAGES CXX)

# target
set(CMAKE_C_COMPILER "/usr/bin/clang")
set(CMAKE_CXX_COMPILER "/usr/bin/clang++")
add_library(base SHARED "")
set_target_properties(base PROPERTIES OUTPUT_NAME "base")
set_target_properties(base PROPERTIES LIBRARY_OUTPUT_DIRECTORY "${CMAKE_SOURCE_DIR}/build/linux/x86_64/release")
set_target_properties(base PROPERTIES LIBRARY_OUTPUT_DIRECTORY "${CMAKE_SOURCE_DIR}/build/linux/x86_64/debug")
target_compile_options(base PRIVATE
$<$<COMPILE_LANGUAGE:C>:-m64>
$<$<COMPILE_LANGUAGE:CXX>:-m64>
$<$<COMPILE_LANGUAGE:C>:-DNDEBUG>
$<$<COMPILE_LANGUAGE:CXX>:-DNDEBUG>
)
set_target_properties(base PROPERTIES CXX_EXTENSIONS OFF)
target_compile_features(base PRIVATE cxx_std_20)
if(MSVC)
target_compile_options(base PRIVATE $<$<CONFIG:Release>:-Ox -fp:fast>)
target_compile_options(base PRIVATE $<$<CONFIG:Debug>:-Od>)
else()
target_compile_options(base PRIVATE -O3)
target_compile_options(base PRIVATE -O0)
endif()
if(MSVC)
target_compile_options(base PRIVATE -Zi)
else()
target_compile_options(base PRIVATE -g)
endif()
if(MSVC)
set_property(TARGET base PROPERTY
Expand All @@ -38,11 +39,9 @@ target_sources(base PRIVATE
)

# target
set(CMAKE_C_COMPILER "/usr/bin/clang")
set(CMAKE_CXX_COMPILER "/usr/bin/clang++")
add_executable(swc "")
set_target_properties(swc PROPERTIES OUTPUT_NAME "swc")
set_target_properties(swc PROPERTIES RUNTIME_OUTPUT_DIRECTORY "${CMAKE_SOURCE_DIR}/build/linux/x86_64/release")
set_target_properties(swc PROPERTIES RUNTIME_OUTPUT_DIRECTORY "${CMAKE_SOURCE_DIR}/build/linux/x86_64/debug")
add_dependencies(swc base)
target_include_directories(swc PRIVATE
compiler
Expand All @@ -56,20 +55,18 @@ target_include_directories(swc PRIVATE
target_compile_options(swc PRIVATE
$<$<COMPILE_LANGUAGE:C>:-m64>
$<$<COMPILE_LANGUAGE:CXX>:-m64>
$<$<COMPILE_LANGUAGE:C>:-DNDEBUG>
$<$<COMPILE_LANGUAGE:CXX>:-DNDEBUG>
$<$<COMPILE_LANGUAGE:CXX>:-stdlib=libc++>
)
set_target_properties(swc PROPERTIES CXX_EXTENSIONS OFF)
target_compile_features(swc PRIVATE cxx_std_20)
if(MSVC)
target_compile_options(swc PRIVATE $<$<CONFIG:Release>:-Ox -fp:fast>)
target_compile_options(swc PRIVATE $<$<CONFIG:Debug>:-Od>)
else()
target_compile_options(swc PRIVATE -O3)
target_compile_options(swc PRIVATE -O0)
endif()
if(MSVC)
target_compile_options(swc PRIVATE -Zi)
else()
target_compile_options(swc PRIVATE -fvisibility=hidden)
target_compile_options(swc PRIVATE -g)
endif()
if(MSVC)
set_property(TARGET swc PROPERTY
Expand All @@ -79,55 +76,52 @@ target_link_libraries(swc PRIVATE
base
)
target_link_directories(swc PRIVATE
build/linux/x86_64/release
build/linux/x86_64/debug
)
target_link_options(swc PRIVATE
-m64
)
target_sources(swc PRIVATE
compiler/compiler.cpp
compiler/ast/g-machine.cpp
compiler/ast/dump.cpp
compiler/ast/ast.cpp
compiler/ast/dump.cpp
compiler/ast/g-machine.cpp
compiler/ast/type.cpp
compiler/diagnostics/utils.cpp
compiler/diagnostics/reporter.cpp
compiler/diagnostics/diagnostics.cpp
compiler/g-machine/instruction.cpp
compiler/diagnostics/reporter.cpp
compiler/g-machine/binop.cpp
compiler/g-machine/environment.cpp
compiler/g-machine/instruction.cpp
compiler/lexer/lexer.cpp
compiler/lexer/flex_lexer.cpp
compiler/parser/parser.cpp
compiler/parser/bison_parser.cpp
compiler/type/type.cpp
compiler/type/dump.cpp
compiler/type/environment.cpp
compiler/type/type.cpp
)

# target
set(CMAKE_C_COMPILER "/usr/bin/clang")
set(CMAKE_CXX_COMPILER "/usr/bin/clang++")
add_executable(swi "")
set_target_properties(swi PROPERTIES OUTPUT_NAME "swi")
set_target_properties(swi PROPERTIES RUNTIME_OUTPUT_DIRECTORY "${CMAKE_SOURCE_DIR}/build/linux/x86_64/release")
set_target_properties(swi PROPERTIES RUNTIME_OUTPUT_DIRECTORY "${CMAKE_SOURCE_DIR}/build/linux/x86_64/debug")
add_dependencies(swi swc)
target_compile_options(swi PRIVATE
$<$<COMPILE_LANGUAGE:C>:-m64>
$<$<COMPILE_LANGUAGE:CXX>:-m64>
$<$<COMPILE_LANGUAGE:C>:-DNDEBUG>
$<$<COMPILE_LANGUAGE:CXX>:-DNDEBUG>
)
set_target_properties(swi PROPERTIES CXX_EXTENSIONS OFF)
target_compile_features(swi PRIVATE cxx_std_20)
if(MSVC)
target_compile_options(swi PRIVATE $<$<CONFIG:Release>:-Ox -fp:fast>)
target_compile_options(swi PRIVATE $<$<CONFIG:Debug>:-Od>)
else()
target_compile_options(swi PRIVATE -O3)
target_compile_options(swi PRIVATE -O0)
endif()
if(MSVC)
target_compile_options(swi PRIVATE -Zi)
else()
target_compile_options(swi PRIVATE -fvisibility=hidden)
target_compile_options(swi PRIVATE -g)
endif()
if(MSVC)
set_property(TARGET swi PROPERTY
Expand All @@ -137,7 +131,7 @@ target_link_libraries(swi PRIVATE
base
)
target_link_directories(swi PRIVATE
build/linux/x86_64/release
build/linux/x86_64/debug
)
target_link_options(swi PRIVATE
-m64
Expand Down
3 changes: 1 addition & 2 deletions compiler/ast/ast.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -81,8 +81,7 @@ namespace swallow::compiler::type
Environment typeEnvironment;

auto intType = Type::Ptr(new Base("Int"));
auto binopType = Type::Ptr(
new Arrow(intType, Type::Ptr(new type::Arrow(intType, intType))));
auto binopType = Type::Ptr(new Arrow(intType, Type::Ptr(new type::Arrow(intType, intType))));

typeEnvironment.Bind("+", binopType);
typeEnvironment.Bind("-", binopType);
Expand Down
Loading

0 comments on commit 4067bd4

Please sign in to comment.