Skip to content

[Demo] Having LibASR at src/libasr/src/libasr #2835

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 5 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ CPackConfig.cmake
CPackSourceConfig.cmake
_CPack_Packages
/CMakeSettings.json
src/libasr/libasr.a.*
src/libasr/src/libasr/libasr.a.*

## libraries
*.a
Expand All @@ -56,10 +56,10 @@ lpython/ast/ast.py
lpython/asr/asr.py
src/lpython/ast.h
src/lpython/asr.h
src/libasr/asr.h
src/libasr/wasm_visitor.h
src/libasr/pass/intrinsic_function_registry_util.h
src/libasr/config.h
src/libasr/src/libasr/asr.h
src/libasr/src/libasr/wasm_visitor.h
src/libasr/src/libasr/pass/intrinsic_function_registry_util.h
src/libasr/src/libasr/config.h
share/jupyter/kernels/fortran/kernel.json
share/jupyter/kernels/lpython/kernel.json
src/runtime/*.o.empty.c
Expand Down
10 changes: 5 additions & 5 deletions build0.sh
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,13 @@ ci/version.sh
# Generate a Python AST from Python.asdl (Python)
python grammar/asdl_py.py
# Generate a Python AST from Python.asdl (C++)
python src/libasr/asdl_cpp.py grammar/Python.asdl src/lpython/python_ast.h
python src/libasr/src/libasr/asdl_cpp.py grammar/Python.asdl src/lpython/python_ast.h
# Generate a Fortran ASR from ASR.asdl (C++)
python src/libasr/asdl_cpp.py src/libasr/ASR.asdl src/libasr/asr.h
# Generate a wasm_visitor.h from src/libasr/wasm_instructions.txt (C++)
python src/libasr/wasm_instructions_visitor.py
python src/libasr/src/libasr/asdl_cpp.py src/libasr/src/libasr/ASR.asdl src/libasr/src/libasr/asr.h
# Generate a wasm_visitor.h from src/libasr/src/libasr/wasm_instructions.txt (C++)
python src/libasr/src/libasr/wasm_instructions_visitor.py
# Generate the intrinsic_function_registry_util.h (C++)
python src/libasr/intrinsic_func_registry_util_gen.py
python src/libasr/src/libasr/intrinsic_func_registry_util_gen.py

# Generate the tokenizer and parser
(cd src/lpython/parser && re2c -W -b tokenizer.re -o tokenizer.cpp)
Expand Down
10 changes: 5 additions & 5 deletions build0_win.xsh
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,13 @@ echo @(version) > version
# Generate a Python AST from Python.asdl (Python)
python grammar/asdl_py.py
# Generate a Python AST from Python.asdl (C++)
python src/libasr/asdl_cpp.py grammar/Python.asdl src/lpython/python_ast.h
python src/libasr/src/libasr/asdl_cpp.py grammar/Python.asdl src/lpython/python_ast.h
# Generate a Fortran ASR from ASR.asdl (C++)
python src/libasr/asdl_cpp.py src/libasr/ASR.asdl src/libasr/asr.h
# Generate a wasm_visitor.h from src/libasr/wasm_instructions.txt (C++)
python src/libasr/wasm_instructions_visitor.py
python src/libasr/src/libasr/asdl_cpp.py src/libasr/src/libasr/ASR.asdl src/libasr/src/libasr/asr.h
# Generate a wasm_visitor.h from src/libasr/src/libasr/wasm_instructions.txt (C++)
python src/libasr/src/libasr/wasm_instructions_visitor.py
# Generate the intrinsic_function_registry_util.h (C++)
python src/libasr/intrinsic_func_registry_util_gen.py
python src/libasr/src/libasr/intrinsic_func_registry_util_gen.py

# Generate the tokenizer and parser
pushd src/lpython/parser && re2c -W -b tokenizer.re -o tokenizer.cpp && popd
Expand Down
10 changes: 5 additions & 5 deletions ci/build.xsh
Original file line number Diff line number Diff line change
Expand Up @@ -27,15 +27,15 @@ llvm-config --components
bash ci/version.sh

# Generate a Fortran ASR from ASR.asdl (C++)
python src/libasr/asdl_cpp.py src/libasr/ASR.asdl src/libasr/asr.h
python src/libasr/src/libasr/asdl_cpp.py src/libasr/src/libasr/ASR.asdl src/libasr/src/libasr/asr.h
# Generate a Python AST from Python.asdl (C++)
python src/libasr/asdl_cpp.py grammar/Python.asdl src/lpython/python_ast.h
python src/libasr/src/libasr/asdl_cpp.py grammar/Python.asdl src/lpython/python_ast.h
# Generate a Python AST from Python.asdl (Python)
python grammar/asdl_py.py
# Generate a wasm_visitor.h from src/libasr/wasm_instructions.txt (C++)
python src/libasr/wasm_instructions_visitor.py
# Generate a wasm_visitor.h from src/libasr/src/libasr/wasm_instructions.txt (C++)
python src/libasr/src/libasr/wasm_instructions_visitor.py
# Generate the intrinsic_function_registry_util.h (C++)
python src/libasr/intrinsic_func_registry_util_gen.py
python src/libasr/src/libasr/intrinsic_func_registry_util_gen.py

# Generate the tokenizer and parser
pushd src/lpython/parser && re2c -W -b tokenizer.re -o tokenizer.cpp && popd
Expand Down
2 changes: 1 addition & 1 deletion grammar/asdl_py.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import sys
import os

sys.path.append("src/libasr")
sys.path.append("src/libasr/src/libasr")
import asdl

products = []
Expand Down
2 changes: 1 addition & 1 deletion run_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import os

ROOT_DIR = os.path.abspath(os.path.join(os.path.dirname(__file__)))
sys.path.append(os.path.join(ROOT_DIR, "src", "libasr"))
sys.path.append(os.path.join(ROOT_DIR, "src", "libasr", "src", "libasr"))

from compiler_tester.tester import color, fg, log, run_test, style, tester_main

Expand Down
2 changes: 1 addition & 1 deletion src/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
add_subdirectory(libasr)
add_subdirectory(libasr/src/libasr)
add_subdirectory(tests)
add_subdirectory(lpython)
add_subdirectory(bin)
Expand Down
2 changes: 1 addition & 1 deletion src/bin/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ if (WITH_STACKTRACE AND APPLE AND CMAKE_CXX_COMPILER_ID MATCHES Clang)
add_custom_command(
TARGET lpython
POST_BUILD
COMMAND ${CMAKE_CURRENT_SOURCE_DIR}/../libasr/dwarf_convert.py lpython.dSYM/raw.txt lpython.dSYM/lines.txt lpython.dSYM/lines.dat
COMMAND ${CMAKE_CURRENT_SOURCE_DIR}/../libasr/src/libasr/dwarf_convert.py lpython.dSYM/raw.txt lpython.dSYM/lines.txt lpython.dSYM/lines.dat
)
endif()
endif()
Expand Down
14 changes: 7 additions & 7 deletions src/bin/lpython.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -856,9 +856,9 @@ int interactive_python_repl(
std::cout << " - History (Keys: Up, Down)" << std::endl;

std::vector<std::string> history;

std::function<bool(std::string)> iscomplete = determine_completeness;

std::string code_string;
size_t cell_count = 0;
while (true) {
Expand Down Expand Up @@ -1013,8 +1013,8 @@ int interactive_python_repl(
}
case (LCompilers::PythonCompiler::EvalResult::struct_type) : {
if (verbose) {
std::cout << "Return type: "
<< LCompilers::ASRUtils::get_type_code(r.structure.ttype)
std::cout << "Return type: "
<< LCompilers::ASRUtils::get_type_code(r.structure.ttype)
<< std::endl;
}
if (verbose) section("Result:");
Expand Down Expand Up @@ -2261,9 +2261,9 @@ int main(int argc, char *argv[])
#else
cmd += "llvm-dwarfdump --debug-line " + basename + ".out > ";
#endif
cmd += basename + "_ldd.txt && (cd src/libasr; ./dwarf_convert.py ../../"
+ basename + "_ldd.txt ../../" + basename + "_lines.txt ../../"
+ basename + "_lines.dat && ./dat_convert.py ../../"
cmd += basename + "_ldd.txt && (cd src/libasr/src/libasr; ./dwarf_convert.py ../../../../"
+ basename + "_ldd.txt ../../../../" + basename + "_lines.txt ../../../../"
+ basename + "_lines.dat && ./dat_convert.py ../../../../"
+ basename + "_lines.dat)";
int status = system(cmd.c_str());
if ( status != 0 ) {
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
cmake_minimum_required(VERSION 3.10)

project(libasr)
project(libasr/src/libasr)

if (NOT CMAKE_CXX_STANDARD)
set(CMAKE_CXX_STANDARD 17
Expand Down Expand Up @@ -103,8 +103,8 @@ if (WITH_LLVM)
endif()
endif()
add_library(asr STATIC ${SRC})
target_include_directories(asr BEFORE PUBLIC ${libasr_SOURCE_DIR}/..)
target_include_directories(asr BEFORE PUBLIC ${libasr_BINARY_DIR}/..)
target_include_directories(asr BEFORE PUBLIC ${libasr/src/libasr_SOURCE_DIR}/..)
target_include_directories(asr BEFORE PUBLIC ${libasr/src/libasr_BINARY_DIR}/..)
if (WITH_BFD)
target_link_libraries(asr p::bfd)
endif()
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@


TESTER_DIR = os.path.abspath(os.path.join(os.path.dirname(__file__)))
if "src/libasr/src/libasr" in TESTER_DIR:
TESTER_DIR = TESTER_DIR.replace("src/libasr", "", 1)
Copy link
Collaborator Author

@ubaidsk ubaidsk Mar 29, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This seems hackish and would get contributed to LFortran. Are we happy with this change going to LFortran?

(We can probably make this look more professional, for example using something like
subprocess.run("git rev-parse --show-toplevel" to get the project root directory and then updating the SRC, LIBASR_DIR, TESTER_DIR according to it).

LIBASR_DIR = os.path.dirname(TESTER_DIR)
SRC_DIR = os.path.dirname(LIBASR_DIR)
ROOT_DIR = os.path.dirname(SRC_DIR)
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
6 changes: 3 additions & 3 deletions src/lpython/utils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ std::string get_runtime_library_header_dir()
char *env_p = std::getenv("LFORTRAN_RUNTIME_LIBRARY_HEADER_DIR");
if (env_p) return env_p;

// The header file is in src/libasr/runtime for development, but in impure
// The header file is in libasr/src/libasr/runtime for development, but in impure
// in installed version
std::string path;
int dirname_length;
Expand All @@ -94,11 +94,11 @@ std::string get_runtime_library_header_dir()
|| endswith(dirname, "src\\bin")
|| endswith(dirname, "SRC\\BIN")) {
// Development version
return dirname + "/../libasr/runtime";
return dirname + "/../libasr/src/libasr/runtime";
} else if (endswith(dirname, "src/lpython/tests") ||
endswith(to_lower(dirname), "src\\lpython\\tests")) {
// CTest Tests
return dirname + "/../../libasr/runtime";
return dirname + "/../../libasr/src/libasr/runtime";
} else {
// Installed version
return dirname + "/../share/lpython/lib/impure";
Expand Down
10 changes: 5 additions & 5 deletions src/runtime/legacy/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
set(SRC
../../../src/libasr/runtime/lfortran_intrinsics.c
../../../src/libasr/src/libasr/runtime/lfortran_intrinsics.c
)
add_library(lpython_runtime SHARED ${SRC})
target_include_directories(lpython_runtime BEFORE PUBLIC ${libasr_SOURCE_DIR}/..)
target_include_directories(lpython_runtime BEFORE PUBLIC ${libasr_BINARY_DIR}/..)
target_include_directories(lpython_runtime BEFORE PUBLIC ${libasr/src/libasr_SOURCE_DIR}/..)
target_include_directories(lpython_runtime BEFORE PUBLIC ${libasr/src/libasr_BINARY_DIR}/..)
set_target_properties(lpython_runtime PROPERTIES
RUNTIME_OUTPUT_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/../$<0:>
LIBRARY_OUTPUT_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/../$<0:>
ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/../$<0:>)
add_library(lpython_runtime_static STATIC ${SRC})
target_include_directories(lpython_runtime_static BEFORE PUBLIC ${libasr_SOURCE_DIR}/..)
target_include_directories(lpython_runtime_static BEFORE PUBLIC ${libasr_BINARY_DIR}/..)
target_include_directories(lpython_runtime_static BEFORE PUBLIC ${libasr/src/libasr_SOURCE_DIR}/..)
target_include_directories(lpython_runtime_static BEFORE PUBLIC ${libasr/src/libasr_BINARY_DIR}/..)
set_target_properties(lpython_runtime_static PROPERTIES
RUNTIME_OUTPUT_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/../$<0:>
LIBRARY_OUTPUT_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/../$<0:>
Expand Down
2 changes: 1 addition & 1 deletion src/runtime/lpython/lpython.py
Original file line number Diff line number Diff line change
Expand Up @@ -717,7 +717,7 @@ def get_rtlib_dir():
get_python_version
python_path = "-I" + get_python_inc() + " "
numpy_path = "-I" + get_include() + " "
rt_path_01 = "-I" + get_rtlib_dir() + "/../libasr/runtime "
rt_path_01 = "-I" + get_rtlib_dir() + "/../libasr/src/libasr/runtime "
rt_path_02 = "-L" + get_rtlib_dir() + " -Wl,-rpath," \
+ get_rtlib_dir() + " -llpython_runtime "
python_lib = "-L" + get_python_lib() + "/../.." + f" -Wl,-rpath,{get_python_lib()+'/../..'}" + " -lpython" + \
Expand Down
Loading