2024-10-31 06:51:07 +00:00
|
|
|
cmake_minimum_required(VERSION 3.5 FATAL_ERROR)
|
|
|
|
|
|
|
|
set(TOLK_SOURCE
|
2024-10-31 06:59:23 +00:00
|
|
|
src-file.cpp
|
2024-10-31 06:51:07 +00:00
|
|
|
lexer.cpp
|
|
|
|
symtable.cpp
|
2024-10-31 07:02:01 +00:00
|
|
|
compiler-state.cpp
|
2024-10-31 07:03:33 +00:00
|
|
|
ast.cpp
|
|
|
|
ast-from-tokens.cpp
|
[Tolk] AST-based semantic analysis, get rid of Expr
This is a huge refactoring focusing on untangling compiler internals
(previously forked from FunC).
The goal is to convert AST directly to Op (a kind of IR representation),
doing all code analysis at AST level.
Noteable changes:
- AST-based semantic kernel includes: registering global symbols,
scope handling and resolving local/global identifiers,
lvalue/rvalue calc and check, implicit return detection,
mutability analysis, pure/impure validity checks,
simple constant folding
- values of `const` variables are calculated NOT based on CodeBlob,
but via a newly-introduced AST-based constant evaluator
- AST vertices are now inherited from expression/statement/other;
expression vertices have common properties (TypeExpr, lvalue/rvalue)
- symbol table is rewritten completely, SymDef/SymVal no longer exist,
lexer now doesn't need to register identifiers
- AST vertices have references to symbols, filled at different
stages of pipeline
- the remaining "FunC legacy part" is almost unchanged besides Expr
which was fully dropped; AST is converted to Ops (IR) directly
2024-12-16 18:19:45 +00:00
|
|
|
constant-evaluator.cpp
|
2024-10-31 07:04:58 +00:00
|
|
|
pipe-discover-parse-sources.cpp
|
|
|
|
pipe-register-symbols.cpp
|
[Tolk] AST-based semantic analysis, get rid of Expr
This is a huge refactoring focusing on untangling compiler internals
(previously forked from FunC).
The goal is to convert AST directly to Op (a kind of IR representation),
doing all code analysis at AST level.
Noteable changes:
- AST-based semantic kernel includes: registering global symbols,
scope handling and resolving local/global identifiers,
lvalue/rvalue calc and check, implicit return detection,
mutability analysis, pure/impure validity checks,
simple constant folding
- values of `const` variables are calculated NOT based on CodeBlob,
but via a newly-introduced AST-based constant evaluator
- AST vertices are now inherited from expression/statement/other;
expression vertices have common properties (TypeExpr, lvalue/rvalue)
- symbol table is rewritten completely, SymDef/SymVal no longer exist,
lexer now doesn't need to register identifiers
- AST vertices have references to symbols, filled at different
stages of pipeline
- the remaining "FunC legacy part" is almost unchanged besides Expr
which was fully dropped; AST is converted to Ops (IR) directly
2024-12-16 18:19:45 +00:00
|
|
|
pipe-resolve-symbols.cpp
|
|
|
|
pipe-calc-rvalue-lvalue.cpp
|
|
|
|
pipe-detect-unreachable.cpp
|
|
|
|
pipe-infer-check-types.cpp
|
|
|
|
pipe-refine-lvalue-for-mutate.cpp
|
|
|
|
pipe-check-rvalue-lvalue.cpp
|
|
|
|
pipe-check-pure-impure.cpp
|
|
|
|
pipe-constant-folding.cpp
|
2024-10-31 07:04:58 +00:00
|
|
|
pipe-ast-to-legacy.cpp
|
|
|
|
pipe-find-unused-symbols.cpp
|
|
|
|
pipe-generate-fif-output.cpp
|
2024-10-31 06:51:07 +00:00
|
|
|
unify-types.cpp
|
|
|
|
abscode.cpp
|
|
|
|
analyzer.cpp
|
|
|
|
asmops.cpp
|
|
|
|
builtins.cpp
|
|
|
|
stack-transform.cpp
|
|
|
|
optimize.cpp
|
|
|
|
codegen.cpp
|
|
|
|
tolk.cpp
|
|
|
|
)
|
|
|
|
|
|
|
|
add_executable(tolk tolk-main.cpp ${TOLK_SOURCE})
|
|
|
|
target_include_directories(tolk PUBLIC $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}>)
|
2024-10-31 07:20:54 +00:00
|
|
|
target_link_libraries(tolk PUBLIC git ton_crypto_core)
|
2024-10-31 06:51:07 +00:00
|
|
|
if (WINGETOPT_FOUND)
|
|
|
|
target_link_libraries_system(tolk wingetopt)
|
|
|
|
endif ()
|
2024-10-31 06:54:05 +00:00
|
|
|
if (${TOLK_DEBUG}) # -DTOLK_DEBUG=1 in CMake options => #define TOLK_DEBUG (for development purposes)
|
|
|
|
message(STATUS "TOLK_DEBUG is ON")
|
|
|
|
target_compile_definitions(tolk PRIVATE TOLK_DEBUG=1)
|
|
|
|
endif()
|
2024-10-31 06:51:07 +00:00
|
|
|
|
|
|
|
if (USE_EMSCRIPTEN)
|
|
|
|
add_executable(tolkfiftlib tolk-wasm.cpp ${TOLK_SOURCE})
|
|
|
|
target_include_directories(tolkfiftlib PUBLIC $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}>)
|
|
|
|
target_link_libraries(tolkfiftlib PUBLIC fift-lib git)
|
|
|
|
target_link_options(tolkfiftlib PRIVATE
|
|
|
|
-sEXPORTED_RUNTIME_METHODS=FS,ccall,cwrap,UTF8ToString,stringToUTF8,lengthBytesUTF8,addFunction,removeFunction,setValue
|
|
|
|
-sEXPORTED_FUNCTIONS=_tolk_compile,_version,_malloc,_free,_setThrew
|
|
|
|
-sEXPORT_NAME=CompilerModule
|
|
|
|
-sERROR_ON_UNDEFINED_SYMBOLS=0
|
|
|
|
-sFILESYSTEM=1 -lnodefs.js
|
|
|
|
-Oz
|
|
|
|
-sIGNORE_MISSING_MAIN=1
|
|
|
|
-sAUTO_NATIVE_LIBRARIES=0
|
|
|
|
-sMODULARIZE=1
|
|
|
|
-sTOTAL_MEMORY=33554432
|
|
|
|
-sALLOW_MEMORY_GROWTH=1
|
|
|
|
-sALLOW_TABLE_GROWTH=1
|
|
|
|
--embed-file ${CMAKE_CURRENT_SOURCE_DIR}/../crypto/fift/lib@/fiftlib
|
|
|
|
-fexceptions
|
|
|
|
)
|
|
|
|
target_compile_options(tolkfiftlib PRIVATE -fexceptions -fno-stack-protector)
|
|
|
|
endif ()
|
|
|
|
|
|
|
|
install(TARGETS tolk RUNTIME DESTINATION bin)
|