Skip to content

Commit

Permalink
Use unique name for the lpython decorator generated files
Browse files Browse the repository at this point in the history
  • Loading branch information
Thirumalai-Shaktivel committed May 12, 2023
1 parent a9e9a33 commit d48b523
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 8 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ inst/bin/*
*_lines.dat.txt
*__tmp__generated__.c
visualize*.html
lpython_decorator*/
a.c
a.h
a.py
Expand Down
20 changes: 12 additions & 8 deletions src/runtime/lpython/lpython.py
Original file line number Diff line number Diff line change
Expand Up @@ -570,11 +570,13 @@ def get_data_type(t):
source_code = getsource(function)
source_code = source_code[source_code.find('\n'):]

# TODO: Create a filename based on the function name
# filename = function.__name__ + ".py"
dir_name = "./lpython_decorator_" + self.fn_name
if not os.path.exists(dir_name):
os.mkdir(dir_name)
filename = dir_name + "/" + self.fn_name

# Open the file for writing
with open("a.py", "w") as file:
with open(filename + ".py", "w") as file:
# Write the Python source code to the file
file.write("@ccallable")
file.write(source_code)
Expand Down Expand Up @@ -680,7 +682,7 @@ def get_data_type(t):
#include <numpy/ndarrayobject.h>
// LPython generated C code
#include "a.h"
#include "{self.fn_name}.h"
// Define the Python module and method mappings
static PyObject* define_module(PyObject* self, PyObject* args) {{
Expand Down Expand Up @@ -718,13 +720,14 @@ def get_data_type(t):
"""
# ----------------------------------------------------------------------
# Write the C source code to the file
with open("a.c", "w") as file:
with open(filename + ".c", "w") as file:
file.write(template)

# ----------------------------------------------------------------------
# Generate the Shared library
# TODO: Use LLVM instead of C backend
r = os.system("lpython --show-c --disable-main a.py > a.h")
r = os.system("lpython --show-c --disable-main "
+ filename + ".py > " + filename + ".h")
assert r == 0, "Failed to create C file"

gcc_flags = ""
Expand All @@ -738,14 +741,15 @@ def get_data_type(t):
from numpy import get_include
from distutils.sysconfig import get_python_inc, get_python_lib
python_path = "-I" + get_python_inc() + " "
numpy_path = "-I" + get_include()
numpy_path = "-I" + get_include() + " "
rt_path_01 = "-I" + get_rtlib_dir() + "/../libasr/runtime "
rt_path_02 = "-L" + get_rtlib_dir() + " -Wl,-rpath " \
+ get_rtlib_dir() + " -llpython_runtime "
python_lib = "-L" + get_python_lib() + "/../.. -lpython3.10 -lm"

r = os.system("gcc -g" + gcc_flags + python_path + numpy_path +
" a.c -o lpython_jit_module.so " + rt_path_01 + rt_path_02 + python_lib)
filename + ".c -o lpython_jit_module.so " +
rt_path_01 + rt_path_02 + python_lib)
assert r == 0, "Failed to create the shared library"

def __call__(self, *args, **kwargs):
Expand Down

0 comments on commit d48b523

Please sign in to comment.