Skip to content

Commit 6fe2beb

Browse files
committed
Reland "[clang-repl] Re-implement clang-interpreter as a test case."
Original commit message: " Original commit message:" The current infrastructure in lib/Interpreter has a tool, clang-repl, very similar to clang-interpreter which also allows incremental compilation. This patch moves clang-interpreter as a test case and drops it as conditionally built example as we already have clang-repl in place. Differential revision: https://reviews.llvm.org/D107049 " This patch also ignores ppc due to missing weak symbol for __gxx_personality_v0 which may be a feature request for the jit infrastructure. Also, adds a missing build system dependency to the orc jit. " Additionally, this patch defines a custom exception type and thus avoids the requirement to include header <exception>, making it easier to deploy across systems without standard location of the c++ headers. Differential revision: https://reviews.llvm.org/D107049
1 parent 53486ea commit 6fe2beb

File tree

16 files changed

+184
-168
lines changed

16 files changed

+184
-168
lines changed

clang/docs/ClangFormattedStatus.rst

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -59,11 +59,6 @@ tree in terms of conformance to :doc:`ClangFormat` as of: June 04, 2021 13:01:37
5959
- `1`
6060
- `0`
6161
- :good:`100%`
62-
* - clang/examples/clang-interpreter
63-
- `1`
64-
- `0`
65-
- `1`
66-
- :none:`0%`
6762
* - clang/examples/PrintFunctionNames
6863
- `1`
6964
- `0`

clang/examples/CMakeLists.txt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ if(NOT CLANG_BUILD_EXAMPLES)
33
set(EXCLUDE_FROM_ALL ON)
44
endif()
55

6-
add_subdirectory(clang-interpreter)
76
add_subdirectory(PrintFunctionNames)
87
add_subdirectory(AnnotateFunctions)
98
add_subdirectory(Attribute)

clang/examples/clang-interpreter/CMakeLists.txt

Lines changed: 0 additions & 93 deletions
This file was deleted.

clang/examples/clang-interpreter/README.txt

Lines changed: 0 additions & 20 deletions
This file was deleted.

clang/examples/clang-interpreter/Test.cxx

Lines changed: 0 additions & 33 deletions
This file was deleted.

clang/include/clang/Interpreter/Interpreter.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616

1717
#include "clang/Interpreter/PartialTranslationUnit.h"
1818

19+
#include "llvm/ExecutionEngine/JITSymbol.h"
1920
#include "llvm/Support/Error.h"
2021

2122
#include <memory>
@@ -65,6 +66,8 @@ class Interpreter {
6566
return Execute(*PTU);
6667
return llvm::Error::success();
6768
}
69+
llvm::Expected<llvm::JITTargetAddress>
70+
getSymbolAddress(llvm::StringRef UnmangledName) const;
6871
};
6972
} // namespace clang
7073

clang/lib/Interpreter/IncrementalExecutor.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,4 +60,12 @@ llvm::Error IncrementalExecutor::runCtors() const {
6060
return Jit->initialize(Jit->getMainJITDylib());
6161
}
6262

63+
llvm::Expected<llvm::JITTargetAddress>
64+
IncrementalExecutor::getSymbolAddress(llvm::StringRef UnmangledName) const {
65+
auto Sym = Jit->lookup(UnmangledName);
66+
if (!Sym)
67+
return Sym.takeError();
68+
return Sym->getAddress();
69+
}
70+
6371
} // end namespace clang

clang/lib/Interpreter/IncrementalExecutor.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,8 @@ class IncrementalExecutor {
4141

4242
llvm::Error addModule(std::unique_ptr<llvm::Module> M);
4343
llvm::Error runCtors() const;
44+
llvm::Expected<llvm::JITTargetAddress>
45+
getSymbolAddress(llvm::StringRef UnmangledName) const;
4446
};
4547

4648
} // end namespace clang

clang/lib/Interpreter/Interpreter.cpp

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,7 @@
3535
using namespace clang;
3636

3737
// FIXME: Figure out how to unify with namespace init_convenience from
38-
// tools/clang-import-test/clang-import-test.cpp and
39-
// examples/clang-interpreter/main.cpp
38+
// tools/clang-import-test/clang-import-test.cpp
4039
namespace {
4140
/// Retrieves the clang CC1 specific flags out of the compilation's jobs.
4241
/// \returns NULL on error.
@@ -218,3 +217,13 @@ llvm::Error Interpreter::Execute(PartialTranslationUnit &T) {
218217

219218
return llvm::Error::success();
220219
}
220+
221+
llvm::Expected<llvm::JITTargetAddress>
222+
Interpreter::getSymbolAddress(llvm::StringRef UnmangledName) const {
223+
if (!IncrExecutor)
224+
return llvm::make_error<llvm::StringError>("Operation failed. "
225+
"No execution engine",
226+
std::error_code());
227+
228+
return IncrExecutor->getSymbolAddress(UnmangledName);
229+
}

clang/test/CMakeLists.txt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,6 @@ if (CLANG_BUILD_EXAMPLES)
9696
Attribute
9797
AnnotateFunctions
9898
CallSuperAttr
99-
clang-interpreter
10099
PrintFunctionNames
101100
)
102101
endif ()

clang/test/Misc/interpreter.c

Lines changed: 0 additions & 10 deletions
This file was deleted.

clang/test/lit.cfg.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,6 @@
7171

7272
if config.clang_examples:
7373
config.available_features.add('examples')
74-
tools.append('clang-interpreter')
7574

7675
def have_host_jit_support():
7776
clang_repl_exe = lit.util.which('clang-repl', config.clang_tools_dir)

clang/unittests/Interpreter/CMakeLists.txt

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
set(LLVM_LINK_COMPONENTS
2+
${LLVM_TARGETS_TO_BUILD}
23
Core
4+
OrcJIT
5+
Support
36
)
47

58
add_clang_unittest(ClangReplInterpreterTests
@@ -12,3 +15,8 @@ target_link_libraries(ClangReplInterpreterTests PUBLIC
1215
clangInterpreter
1316
clangFrontend
1417
)
18+
19+
# Exceptions on Windows are not yet supported.
20+
if(NOT WIN32)
21+
add_subdirectory(ExceptionTests)
22+
endif()
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
# The interpreter can throw an exception from user input. The test binary needs
2+
# to be compiled with exception support to expect and catch the thrown
3+
# exception.
4+
set(LLVM_REQUIRES_EH ON)
5+
set(LLVM_REQUIRES_RTTI ON)
6+
7+
set(LLVM_LINK_COMPONENTS
8+
${LLVM_TARGETS_TO_BUILD}
9+
Core
10+
OrcJIT
11+
Support
12+
)
13+
14+
add_clang_unittest(ClangReplInterpreterExceptionTests
15+
InterpreterExceptionTest.cpp
16+
)
17+
18+
llvm_update_compile_flags(ClangReplInterpreterExceptionTests)
19+
target_link_libraries(ClangReplInterpreterExceptionTests PUBLIC
20+
clangAST
21+
clangBasic
22+
clangInterpreter
23+
clangFrontend
24+
)
25+
add_dependencies(ClangReplInterpreterExceptionTests clang-resource-headers)

0 commit comments

Comments
 (0)