Skip to content
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

v0.16 #335

Merged
merged 182 commits into from
Apr 12, 2023
Merged

v0.16 #335

Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
182 commits
Select commit Hold shift + click to select a range
cf5a193
Add Python extension lowering pass
arshajii Jan 28, 2023
947b9fe
Add DocstringAttribute
arshajii Jan 28, 2023
2285057
Add extension module codegen
arshajii Jan 29, 2023
84d1502
Handle different argument counts efficiently
arshajii Jan 29, 2023
2f4fddd
Add warnings to extension lowering
arshajii Jan 29, 2023
509ea38
Merge branch 'develop' into pyext
arshajii Jan 29, 2023
0d99225
Fix module name
arshajii Jan 29, 2023
e4edf22
Fix extension codegen
arshajii Jan 29, 2023
95f28e1
Fix argument check
arshajii Jan 30, 2023
999e426
Auto-convert Codon exceptions to Python exceptions
arshajii Jan 30, 2023
24fe4d1
Fix #183
inumanag Jan 30, 2023
8831698
Fix #162; Fix #135
inumanag Jan 31, 2023
8ea7993
Fix #155
inumanag Jan 31, 2023
ef957c4
Fix CPython interface in codegen
arshajii Feb 2, 2023
ad7409b
Fix #191
inumanag Feb 2, 2023
8fb65dc
Fix #187
inumanag Feb 2, 2023
2790e5d
Fix #189
inumanag Feb 2, 2023
b3a8e69
Generate object file in pyext mode
arshajii Feb 2, 2023
e79a3c0
Merge branch 'develop' into pyext
arshajii Feb 4, 2023
c7080d2
Convert Codon exceptions to Python exceptions
arshajii Feb 5, 2023
c97a824
Fix vtable init; Fix failing tests on Linux
inumanag Feb 5, 2023
b746012
Fix #190
inumanag Feb 5, 2023
49d9097
Fix #156
inumanag Feb 5, 2023
247cf20
Fix union routing
inumanag Feb 5, 2023
8a7a529
Merge branch 'bug-fixes' into pyext
inumanag Feb 5, 2023
ba2b672
Merge branch 'pyext' of github.com:exaloop/codon into pyext
inumanag Feb 5, 2023
33933f4
Remove need for import python
inumanag Feb 5, 2023
fea4247
Automatic @export and wrapping for toplevel functions
inumanag Feb 6, 2023
5920148
Merge branch 'develop' into pyext
arshajii Feb 6, 2023
c08a2d7
Reorganize API
arshajii Feb 6, 2023
252f8c2
Add Python extension IR structs
arshajii Feb 9, 2023
db089a7
Add special calls for no-suspend yield-expr
inumanag Feb 9, 2023
f4b643a
Add special calls for no-suspend yield-expr
inumanag Feb 9, 2023
6343a6c
pyextension.h support [wip]
inumanag Feb 9, 2023
d6aa7e5
pyextension.h support [wip]
inumanag Feb 9, 2023
14ea712
pyextension.h support
inumanag Feb 10, 2023
c03d2e1
pyextension.h support for toplevel functions
inumanag Feb 10, 2023
47949ed
clang-format
arshajii Feb 10, 2023
c467645
Add PyFunction::nargs field
arshajii Feb 10, 2023
7d3f62c
Update pyextension codegen (WIP)
arshajii Feb 10, 2023
946972d
SUpport nargs
inumanag Feb 10, 2023
92f9a27
Add support for @pycapture
inumanag Feb 11, 2023
573f3f6
PyType codegen (WIP)
arshajii Feb 11, 2023
765fd3a
Py method codegen (WIP)
arshajii Feb 11, 2023
9b494e6
Add type ptr hook
arshajii Feb 11, 2023
d9ca0c2
Add getset codegen
arshajii Feb 11, 2023
634878e
Add type alloc function
arshajii Feb 12, 2023
07b9cff
Add type pointer hook codegen
arshajii Feb 12, 2023
7c4c4a4
Re-organize codegen
arshajii Feb 12, 2023
b336fc6
Add member codegen
arshajii Feb 12, 2023
1a7a48a
Update module init codegen
arshajii Feb 12, 2023
19f9190
Update module init codegen
arshajii Feb 12, 2023
3b0d277
Add support for typePtrHook and new to/from_py hooks
inumanag Feb 12, 2023
e97fa0a
Fix extension codegen
arshajii Feb 12, 2023
727f251
Fix init codegen
arshajii Feb 12, 2023
c8a24e0
Fix init codegen; add "tp_new" slot
arshajii Feb 12, 2023
3bec4c1
Fix type hook
arshajii Feb 13, 2023
b0b594d
Add extra flags
arshajii Feb 13, 2023
e044a61
Specialized wrappers (PyType specs)
inumanag Feb 14, 2023
6e9d9d1
Add static Python link option
arshajii Feb 14, 2023
7fd8ff3
Fix C imports
arshajii Feb 14, 2023
f98018c
Add guards
arshajii Feb 14, 2023
86fe7e0
Remove unused field
arshajii Feb 14, 2023
303855e
Python mode only when pyExt set
inumanag Feb 15, 2023
a29ea1c
Update python module
arshajii Feb 15, 2023
d746ea7
Fix assert
inumanag Feb 15, 2023
cbac1b8
Update codegen/passes
arshajii Feb 15, 2023
6da0f9b
Fix tuple parsing in index expression
inumanag Feb 16, 2023
6a2db47
Fix empty tuple unification
inumanag Feb 16, 2023
2ead259
Do not Cythonize underscore fns
inumanag Feb 17, 2023
9f08ecd
clang-format
arshajii Feb 17, 2023
2bfb893
Fix switch
arshajii Feb 17, 2023
93dfcb5
Add Py support for cmp/setitem
inumanag Feb 18, 2023
894bf5b
Add Py support for cmp/setitem
inumanag Feb 18, 2023
57881a8
Add type is support
inumanag Feb 18, 2023
651dad1
GetSet support
inumanag Feb 19, 2023
016e828
clang-format
arshajii Feb 19, 2023
ed850f2
GetSet support (fixes)
inumanag Feb 20, 2023
7e7daf8
Avoid useless vtable alloc
inumanag Feb 20, 2023
407a2f0
Add iter support
inumanag Feb 20, 2023
47ebd6a
Fix size_t capture bug
inumanag Feb 21, 2023
259aec3
clang-format
arshajii Feb 21, 2023
f3f3e7e
Fix POD type unification with tuples
inumanag Feb 22, 2023
732dfcb
Add __try_from_py__ API
arshajii Feb 23, 2023
d0461d5
Fix annotation
arshajii Feb 27, 2023
12d21ff
Add static reflection methods (setattr; internal.static.*); refactor …
inumanag Mar 3, 2023
3ab03b9
Python compat fixes
inumanag Mar 4, 2023
921cf74
Update Python object conversions
arshajii Mar 4, 2023
3adb42b
Fix PyErrors
arshajii Mar 4, 2023
7f82194
clang-format; add copyright
arshajii Mar 4, 2023
691c1b8
Add PyFunction::keywords field
arshajii Mar 4, 2023
c24cec7
Fix JIT MRO handling; Refactor out Jupyter support
inumanag Mar 5, 2023
7fbf877
Refactor out Jupyter support
inumanag Mar 5, 2023
ba1562f
Add support for custom linking args (link=[]) to TOML plugins
inumanag Mar 5, 2023
3f48536
Fix tests
inumanag Mar 5, 2023
417be68
Add no-suspend yield support
inumanag Mar 5, 2023
06c9318
Use g++ instead of gcc
inumanag Mar 5, 2023
cfb6b8e
Fix Jupyter CMAKE
inumanag Mar 9, 2023
900a642
Fix Jupyter CMAKE
inumanag Mar 9, 2023
e1ddbf8
Add _PyArg_Parser definition
arshajii Mar 11, 2023
ac97877
Add complex64 type
arshajii Mar 12, 2023
938ab8d
Add extra complex64 tests
arshajii Mar 12, 2023
66f9e4f
Fix Python calls; add staticenumerate
inumanag Mar 15, 2023
5640651
Fix call
arshajii Mar 15, 2023
f87b82f
Fix calls
arshajii Mar 15, 2023
9629232
Update pyext wrappers
arshajii Mar 16, 2023
416cfe9
Fix staticenumerate; Support static calls in tuple()
inumanag Mar 17, 2023
6734a41
Merge branch 'pyext' of github.com:exaloop/codon into pyext
inumanag Mar 17, 2023
31caa1d
Fix pyext routing
inumanag Mar 17, 2023
4e80861
Add add/mul for tuples
inumanag Mar 17, 2023
7882c56
clang-format
arshajii Mar 17, 2023
8d57bc1
Fix pyext codegen
arshajii Mar 17, 2023
2736bda
Fix wrap_multiple
inumanag Mar 18, 2023
a03e4b0
Add seq_alloc_atomic_uncollectable
arshajii Mar 18, 2023
3fb60ae
Fix default generics issue
inumanag Mar 18, 2023
9110986
Merge branch 'pyext' of github.com:exaloop/codon into pyext
inumanag Mar 18, 2023
bc951f2
Add binary/ternary ops
inumanag Mar 18, 2023
a65a1cb
Fix missing generic issue
inumanag Mar 20, 2023
a29c3d5
Fix number slots
arshajii Mar 20, 2023
de548b7
Update pow
arshajii Mar 20, 2023
e484bbe
Remove unnecessary pyobj
arshajii Mar 23, 2023
fbd0105
Fix allocation
arshajii Mar 23, 2023
e573f6d
Refactor errors
arshajii Mar 24, 2023
f19faf1
Add test extension
arshajii Mar 24, 2023
94dca39
Fix formatting
arshajii Mar 24, 2023
2ef0bdb
clang-format
arshajii Mar 24, 2023
02873b9
Fix getitem/setitem/delitem in pyext
arshajii Mar 24, 2023
2bd28c8
Fix pyext iterators
arshajii Mar 24, 2023
87e5181
Merge branch 'develop' into pyext
arshajii Mar 24, 2023
3ca06a5
Add builtin pow() (fix #294)
arshajii Mar 25, 2023
64d59bb
Fix #244
inumanag Mar 25, 2023
8101c4d
Fix #231
inumanag Mar 25, 2023
f449cb7
Fix #229
inumanag Mar 26, 2023
07073db
Fix #205
inumanag Mar 26, 2023
d587bbb
Update docs
arshajii Mar 27, 2023
4f30b2a
Fix error message
arshajii Mar 27, 2023
3933471
Add pyext tests
arshajii Mar 27, 2023
1ccb2f1
Add pyext support for @property
inumanag Mar 27, 2023
1e839ca
Add pyext support for toplevel fns and @tuple classes
inumanag Mar 27, 2023
be6b4d7
More pyext tests
arshajii Mar 27, 2023
3707990
More pyext tests
arshajii Mar 27, 2023
cf57b58
Fix file error checking
arshajii Mar 29, 2023
0f1913b
More pyext tests
arshajii Mar 30, 2023
809b898
Update pyext tests
arshajii Mar 30, 2023
256e500
Update docs
arshajii Mar 30, 2023
3e1a9a8
Add pyext test to CI
arshajii Mar 30, 2023
9ef321c
Add pyext support for @tuple.__new__
inumanag Mar 30, 2023
d1b5279
Add pyext support for @tuple.__new__
inumanag Mar 30, 2023
da709f5
Fix hetero-tuple issue with fn_overloads
inumanag Mar 31, 2023
2d1dc89
More pyext tests
arshajii Mar 31, 2023
02060cf
Bump versions
arshajii Mar 31, 2023
2b4ed6e
Fix del magic in pyext
arshajii Mar 31, 2023
50d105e
Fix init magic for tuples in pyext
arshajii Mar 31, 2023
821bfb4
Have test-pypi only run on develop branch
arshajii Mar 31, 2023
b3789d0
Make exception type indices unnamed-addr
arshajii Mar 31, 2023
38452e1
Fix #316; Fix #317 (slash issue)
inumanag Apr 3, 2023
67d4958
Use uncollectible-alloc for vtable
arshajii Apr 3, 2023
a67bf61
Merge branch 'pyext' of github.com:exaloop/codon into pyext
inumanag Apr 3, 2023
439396c
Fix #249
inumanag Apr 4, 2023
daaf014
Add pyext docs
arshajii Apr 4, 2023
8b339e8
Fix #249; Fix clashing vtables; Fix super() and class_copy
inumanag Apr 5, 2023
bb72a6d
Add content-atomic type property instruction
arshajii Apr 5, 2023
716b1b8
__contents_atomic__ support
inumanag Apr 5, 2023
7fe9763
Update internal functions
arshajii Apr 5, 2023
4ac0ff9
Use PIC when generating Python extension
arshajii Apr 6, 2023
92f470d
Cleanup
arshajii Apr 6, 2023
1c900b5
Add Dockerfile & fix -fPIC
inumanag Apr 8, 2023
2a44089
Cleanup
arshajii Apr 8, 2023
484d8e6
Fix setup.py
inumanag Apr 8, 2023
f04a6c7
Fix setup.py
inumanag Apr 8, 2023
e01de18
Fix pyext fn iteration
inumanag Apr 8, 2023
d027079
Fix CI
arshajii Apr 9, 2023
4dd4b55
clang-format
arshajii Apr 9, 2023
293be5e
Update long conversions in Py bridge
arshajii Apr 9, 2023
dd09995
Support wide-int to str conversions
arshajii Apr 10, 2023
b3b0397
Fix test
arshajii Apr 11, 2023
2eda792
Add pow for arbitrary-width ints
arshajii Apr 11, 2023
379bf60
Fix Linux backtraces
arshajii Apr 12, 2023
93332bc
Cleanup
arshajii Apr 12, 2023
b515f51
Add more tests
arshajii Apr 12, 2023
d8211f1
Fix docs; Remove tuple.__add__ for scalars
inumanag Apr 12, 2023
b1fa163
Update docs
arshajii Apr 12, 2023
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
3 changes: 2 additions & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,7 @@ jobs:
ln -s build/libcodonrt.${LIBEXT} .
build/codon_test
test/app/test.sh build
(cd test/python && CODON_DIR=$(pwd)/../../codon-deploy python3 setup.py build_ext --inplace && python3 pyext.py)
env:
CODON_PATH: ./stdlib
PYTHONPATH: .:./test/python
Expand Down Expand Up @@ -232,7 +233,7 @@ jobs:
path: codon-linux-x86_64.tar.gz

- name: Publish on TestPyPI
if: startsWith(matrix.os, 'ubuntu')
if: github.ref == 'refs/heads/develop' && startsWith(matrix.os, 'ubuntu')
uses: pypa/gh-action-pypi-publish@release/v1
with:
user: __token__
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
build/
build_*/
install/
install_*/
extra/python/src/jit.cpp
extra/jupyter/build/

Expand Down
23 changes: 10 additions & 13 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,16 +1,15 @@
cmake_minimum_required(VERSION 3.14)
project(
Codon
VERSION "0.15.5"
VERSION "0.16.0"
HOMEPAGE_URL "https://github.com/exaloop/codon"
DESCRIPTION "high-performance, extensible Python compiler")
set(CODON_JIT_PYTHON_VERSION "0.1.3")
set(CODON_JIT_PYTHON_VERSION "0.1.4")
configure_file("${PROJECT_SOURCE_DIR}/cmake/config.h.in"
"${PROJECT_SOURCE_DIR}/codon/config/config.h")
configure_file("${PROJECT_SOURCE_DIR}/cmake/config.py.in"
"${PROJECT_SOURCE_DIR}/extra/python/codon/version.py")

option(CODON_JUPYTER "build Codon Jupyter server" OFF)
option(CODON_GPU "build Codon GPU backend" OFF)

set(CMAKE_CXX_STANDARD 17)
Expand Down Expand Up @@ -69,6 +68,10 @@ add_custom_command(
omp
DEPENDS peg2cpp codon/parser/peg/openmp.peg)

# Codon Jupyter library
set(CODON_JUPYTER_FILES codon/util/jupyter.h codon/util/jupyter.cpp)
add_library(codon_jupyter SHARED ${CODON_JUPYTER_FILES})

# Codon runtime library
set(CODONRT_FILES codon/runtime/lib.h codon/runtime/lib.cpp
codon/runtime/re.cpp codon/runtime/exc.cpp
Expand Down Expand Up @@ -181,6 +184,7 @@ set(CODON_HPPFILES
codon/cir/llvm/llvm.h
codon/cir/llvm/optimize.h
codon/cir/module.h
codon/cir/pyextension.h
codon/cir/cir.h
codon/cir/transform/cleanup/canonical.h
codon/cir/transform/cleanup/dead_code.h
Expand Down Expand Up @@ -218,7 +222,6 @@ set(CODON_HPPFILES
codon/cir/value.h
codon/cir/var.h
codon/util/common.h
extra/jupyter/jupyter.h
codon/compiler/jit_extern.h)
set(CODON_CPPFILES
codon/compiler/compiler.cpp
Expand Down Expand Up @@ -320,16 +323,10 @@ set(CODON_CPPFILES
codon/cir/util/visitor.cpp
codon/cir/value.cpp
codon/cir/var.cpp
codon/util/common.cpp
extra/jupyter/jupyter.cpp)
codon/util/common.cpp)
add_library(codonc SHARED ${CODON_HPPFILES})
target_include_directories(codonc PRIVATE ${peglib_SOURCE_DIR} ${toml_SOURCE_DIR}/include ${semver_SOURCE_DIR}/include)
target_sources(codonc PRIVATE ${CODON_CPPFILES} codon_rules.cpp omp_rules.cpp)
if(CODON_JUPYTER)
add_compile_definitions(CODON_JUPYTER)
add_dependencies(codonc xeus-static nlohmann_json)
target_link_libraries(codonc PRIVATE xeus-static)
endif()
if(ASAN)
target_compile_options(
codonc PRIVATE "-fno-omit-frame-pointer" "-fsanitize=address"
Expand Down Expand Up @@ -427,7 +424,7 @@ endif()

# Codon command-line tool
add_executable(codon codon/app/main.cpp)
target_link_libraries(codon PUBLIC ${STATIC_LIBCPP} fmt codonc Threads::Threads)
target_link_libraries(codon PUBLIC ${STATIC_LIBCPP} fmt codonc codon_jupyter Threads::Threads)

# Codon test Download and unpack googletest at configure time
include(FetchContent)
Expand Down Expand Up @@ -463,7 +460,7 @@ target_link_libraries(codon_test fmt codonc codonrt gtest_main)
target_compile_definitions(codon_test
PRIVATE TEST_DIR="${CMAKE_CURRENT_SOURCE_DIR}/test")

install(TARGETS codonrt codonc DESTINATION lib/codon)
install(TARGETS codonrt codonc codon_jupyter DESTINATION lib/codon)
install(FILES ${CMAKE_BINARY_DIR}/libomp${CMAKE_SHARED_LIBRARY_SUFFIX} DESTINATION lib/codon)
install(TARGETS codon DESTINATION bin)
install(DIRECTORY ${CMAKE_BINARY_DIR}/include/codon DESTINATION include)
Expand Down
47 changes: 0 additions & 47 deletions cmake/deps.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -169,50 +169,3 @@ if(APPLE AND APPLE_ARM)
"LIBUNWIND_ENABLE_SHARED ON"
"LIBUNWIND_INCLUDE_DOCS OFF")
endif()

if(CODON_JUPYTER)
CPMAddPackage(
NAME libzmq
VERSION 4.3.4
URL https://github.com/zeromq/libzmq/releases/download/v4.3.4/zeromq-4.3.4.tar.gz
EXCLUDE_FROM_ALL YES
OPTIONS "WITH_PERF_TOOL OFF"
"ZMQ_BUILD_TESTS OFF"
"ENABLE_CPACK OFF"
"BUILD_SHARED ON"
"WITH_LIBSODIUM OFF"
"WITH_TLS OFF")
CPMAddPackage(
NAME cppzmq
URL https://github.com/zeromq/cppzmq/archive/refs/tags/v4.8.1.tar.gz
VERSION 4.8.1
EXCLUDE_FROM_ALL YES
OPTIONS "CPPZMQ_BUILD_TESTS OFF")
CPMAddPackage(
NAME xtl
GITHUB_REPOSITORY "xtensor-stack/xtl"
VERSION 0.7.3
GIT_TAG 0.7.3
EXCLUDE_FROM_ALL YES
OPTIONS "BUILD_TESTS OFF")
CPMAddPackage(
NAME json
GITHUB_REPOSITORY "nlohmann/json"
VERSION 3.10.1)
CPMAddPackage(
NAME xeus
GITHUB_REPOSITORY "jupyter-xeus/xeus"
VERSION 2.2.0
GIT_TAG 2.2.0
EXCLUDE_FROM_ALL YES
PATCH_COMMAND patch -N -u CMakeLists.txt -b ${CMAKE_SOURCE_DIR}/cmake/xeus.patch || true
OPTIONS "BUILD_EXAMPLES OFF"
"XEUS_BUILD_SHARED_LIBS OFF"
"XEUS_STATIC_DEPENDENCIES ON"
"CMAKE_POSITION_INDEPENDENT_CODE ON"
"XEUS_DISABLE_ARCH_NATIVE ON"
"XEUS_USE_DYNAMIC_UUID ${XEUS_USE_DYNAMIC_UUID}")
if (xeus_ADDED)
install(TARGETS nlohmann_json EXPORT xeus-targets)
endif()
endif()
58 changes: 31 additions & 27 deletions codon/app/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
#include <cstdio>
#include <cstdlib>
#include <fstream>
#include <functional>
#include <iostream>
#include <sstream>
#include <string>
Expand All @@ -14,7 +15,9 @@
#include "codon/compiler/error.h"
#include "codon/compiler/jit.h"
#include "codon/util/common.h"
#include "codon/util/jupyter.h"
#include "llvm/Support/CommandLine.h"
#include "llvm/Support/FileSystem.h"

namespace {
void versMsg(llvm::raw_ostream &out) {
Expand Down Expand Up @@ -83,7 +86,7 @@ void initLogFlags(const llvm::cl::opt<std::string> &log) {
codon::getLogger().parse(std::string(d));
}

enum BuildKind { LLVM, Bitcode, Object, Executable, Library, Detect };
enum BuildKind { LLVM, Bitcode, Object, Executable, Library, PyExtension, Detect };
enum OptMode { Debug, Release };
enum Numerics { C, Python };
} // namespace
Expand All @@ -109,8 +112,9 @@ int docMode(const std::vector<const char *> &args, const std::string &argv0) {
return EXIT_SUCCESS;
}

std::unique_ptr<codon::Compiler> processSource(const std::vector<const char *> &args,
bool standalone) {
std::unique_ptr<codon::Compiler> processSource(
const std::vector<const char *> &args, bool standalone,
std::function<bool()> pyExtension = [] { return false; }) {
llvm::cl::opt<std::string> input(llvm::cl::Positional, llvm::cl::desc("<input file>"),
llvm::cl::init("-"));
auto regs = llvm::cl::getRegisteredOptions();
Expand Down Expand Up @@ -163,9 +167,9 @@ std::unique_ptr<codon::Compiler> processSource(const std::vector<const char *> &

const bool isDebug = (optMode == OptMode::Debug);
std::vector<std::string> disabledOptsVec(disabledOpts);
auto compiler = std::make_unique<codon::Compiler>(args[0], isDebug, disabledOptsVec,
/*isTest=*/false,
(numerics == Numerics::Python));
auto compiler = std::make_unique<codon::Compiler>(
args[0], isDebug, disabledOptsVec,
/*isTest=*/false, (numerics == Numerics::Python), pyExtension());
compiler->getLLVMVisitor()->setStandalone(standalone);

// load plugins
Expand Down Expand Up @@ -296,21 +300,27 @@ int buildMode(const std::vector<const char *> &args, const std::string &argv0) {
llvm::cl::desc("Pass given flags to linker"));
llvm::cl::opt<BuildKind> buildKind(
llvm::cl::desc("output type"),
llvm::cl::values(clEnumValN(LLVM, "llvm", "Generate LLVM IR"),
clEnumValN(Bitcode, "bc", "Generate LLVM bitcode"),
clEnumValN(Object, "obj", "Generate native object file"),
clEnumValN(Executable, "exe", "Generate executable"),
clEnumValN(Library, "lib", "Generate shared library"),
clEnumValN(Detect, "detect",
"Detect output type based on output file extension")),
llvm::cl::values(
clEnumValN(LLVM, "llvm", "Generate LLVM IR"),
clEnumValN(Bitcode, "bc", "Generate LLVM bitcode"),
clEnumValN(Object, "obj", "Generate native object file"),
clEnumValN(Executable, "exe", "Generate executable"),
clEnumValN(Library, "lib", "Generate shared library"),
clEnumValN(PyExtension, "pyext", "Generate Python extension module"),
clEnumValN(Detect, "detect",
"Detect output type based on output file extension")),
llvm::cl::init(Detect));
llvm::cl::opt<std::string> output(
"o",
llvm::cl::desc(
"Write compiled output to specified file. Supported extensions: "
"none (executable), .o (object file), .ll (LLVM IR), .bc (LLVM bitcode)"));
llvm::cl::opt<std::string> pyModule(
"module", llvm::cl::desc("Python extension module name (only applicable when "
"building Python extension module)"));

auto compiler = processSource(args, /*standalone=*/true);
auto compiler = processSource(args, /*standalone=*/true,
[&] { return buildKind == BuildKind::PyExtension; });
if (!compiler)
return EXIT_FAILURE;
std::vector<std::string> libsVec(libs);
Expand All @@ -326,6 +336,7 @@ int buildMode(const std::vector<const char *> &args, const std::string &argv0) {
extension = ".bc";
break;
case BuildKind::Object:
case BuildKind::PyExtension:
extension = ".o";
break;
case BuildKind::Library:
Expand Down Expand Up @@ -358,6 +369,12 @@ int buildMode(const std::vector<const char *> &args, const std::string &argv0) {
compiler->getLLVMVisitor()->writeToExecutable(filename, argv0, true, libsVec,
lflags);
break;
case BuildKind::PyExtension:
compiler->getCache()->pyModule->name =
pyModule.empty() ? llvm::sys::path::stem(compiler->getInput()).str() : pyModule;
compiler->getLLVMVisitor()->writeToPythonExtension(*compiler->getCache()->pyModule,
filename);
break;
case BuildKind::Detect:
compiler->getLLVMVisitor()->compile(filename, argv0, libsVec, lflags);
break;
Expand All @@ -368,15 +385,7 @@ int buildMode(const std::vector<const char *> &args, const std::string &argv0) {
return EXIT_SUCCESS;
}

#ifdef CODON_JUPYTER
namespace codon {
int startJupyterKernel(const std::string &argv0,
const std::vector<std::string> &plugins,
const std::string &configPath);
}
#endif
int jupyterMode(const std::vector<const char *> &args) {
#ifdef CODON_JUPYTER
llvm::cl::list<std::string> plugins("plugin",
llvm::cl::desc("Load specified plugin"));
llvm::cl::opt<std::string> input(llvm::cl::Positional,
Expand All @@ -385,11 +394,6 @@ int jupyterMode(const std::vector<const char *> &args) {
llvm::cl::ParseCommandLineOptions(args.size(), args.data());
int code = codon::startJupyterKernel(args[0], plugins, input);
return code;
#else
fmt::print("Jupyter support not included. Please recompile with "
"-DCODON_JUPYTER.");
return EXIT_FAILURE;
#endif
}

void showCommandsAndExit() {
Expand Down
2 changes: 2 additions & 0 deletions codon/cir/attribute.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@ std::ostream &MemberAttribute::doFormat(std::ostream &os) const {

const std::string SrcInfoAttribute::AttributeName = "srcInfoAttribute";

const std::string DocstringAttribute::AttributeName = "docstringAttribute";

const std::string TupleLiteralAttribute::AttributeName = "tupleLiteralAttribute";

std::unique_ptr<Attribute> TupleLiteralAttribute::clone(util::CloneVisitor &cv) const {
Expand Down
20 changes: 20 additions & 0 deletions codon/cir/attribute.h
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,26 @@ struct SrcInfoAttribute : public Attribute {
std::ostream &doFormat(std::ostream &os) const override { return os << info; }
};

/// Attribute containing docstring from source
struct DocstringAttribute : public Attribute {
static const std::string AttributeName;

/// the docstring
std::string docstring;

DocstringAttribute() = default;
/// Constructs a DocstringAttribute.
/// @param docstring the docstring
explicit DocstringAttribute(const std::string &docstring) : docstring(docstring) {}

std::unique_ptr<Attribute> clone(util::CloneVisitor &cv) const override {
return std::make_unique<DocstringAttribute>(*this);
}

private:
std::ostream &doFormat(std::ostream &os) const override { return os << docstring; }
};

/// Attribute containing function information
struct KeyValueAttribute : public Attribute {
static const std::string AttributeName;
Expand Down
2 changes: 2 additions & 0 deletions codon/cir/instr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,8 @@ types::Type *TypePropertyInstr::doGetType() const {
switch (property) {
case Property::IS_ATOMIC:
return getModule()->getBoolType();
case Property::IS_CONTENT_ATOMIC:
return getModule()->getBoolType();
case Property::SIZEOF:
return getModule()->getIntType();
default:
Expand Down
2 changes: 1 addition & 1 deletion codon/cir/instr.h
Original file line number Diff line number Diff line change
Expand Up @@ -269,7 +269,7 @@ class StackAllocInstr : public AcceptorExtend<StackAllocInstr, Instr> {
/// Instr representing getting information about a type.
class TypePropertyInstr : public AcceptorExtend<TypePropertyInstr, Instr> {
public:
enum Property { IS_ATOMIC, SIZEOF };
enum Property { IS_ATOMIC, IS_CONTENT_ATOMIC, SIZEOF };

private:
/// the type being inspected
Expand Down
Loading