6 Commits

Author SHA1 Message Date
Anutosh Bhat
8f56394487
[clang-repl] Implement LoadDynamicLibrary for clang-repl wasm use cases (#133037)
**Currently we don't make use of the JIT for the wasm use cases so the
approach using the execution engine won't work in these cases.**

Rather if we use dlopen. We should be able to do the following
(demonstrating through a toy project)

1) Make use of LoadDynamicLibrary through the given implementation

```
extern "C" EMSCRIPTEN_KEEPALIVE int load_library(const char *name) {
  auto Err = Interp->LoadDynamicLibrary(name);
  if (Err) {
    llvm::logAllUnhandledErrors(std::move(Err), llvm::errs(), "load_library error: ");
    return -1;
  }
  return 0;
}
```
2) Add a button to call load_library once the library has been added in
our MEMFS (currently we have symengine built as a SIDE MODULE and we are
loading it)
2025-04-01 15:33:45 +03:00
Nikita Popov
f137c3d592
[TargetRegistry] Accept Triple in createTargetMachine() (NFC) (#130940)
This avoids doing a Triple -> std::string -> Triple round trip in lots
of places, now that the Module stores a Triple.
2025-03-12 17:35:09 +01:00
Anutosh Bhat
369c0a7483
[clang-repl] Fix target creation in Wasm.cpp (#130909)
Convert the Triple to a string to account for the change from #129868.
2025-03-12 09:36:01 +01:00
Anutosh Bhat
a174aa1e41
[clang-repl] Fix generation of wasm binaries while running clang-repl in browser (#117978)
Co-authored-by: Vassil Vassilev <v.g.vassilev@gmail.com>
2024-11-29 12:01:02 +02:00
Anutosh Bhat
752dbd6112
[clang-repl] Improve flags responsible for generating shared wasm binaries (#116735)
There are a couple changes in this PR that help getting clang-repl to
run in the browser. Using a jupyterlite instance for the example pasted
below

1) Updating flags responsible for generating shared wasm binaries that
need to be dynamically loaded Most Importantly as can be seen in the
changes `shared` and `allow-undefined` are crucial.



![image](https://github.com/user-attachments/assets/1183fd44-8951-496a-899a-e4af39a48447)

2) While exiting we encounter this.



![image](https://github.com/user-attachments/assets/9487a3f4-7200-471d-ba88-09e98ccbc47a)


Now as can be seen here 


cd418030de/clang/lib/Interpreter/Interpreter.cpp (L421-L430)

We call cleanUP in the destructor. Now cleanUP through
IncrementalExecutor tries to deinitialize the JIT which wasn't even
intialized as runCtors in wasm.cpp is a no-op


cd418030de/clang/lib/Interpreter/IncrementalExecutor.cpp (L94-L101)


cd418030de/clang/lib/Interpreter/Wasm.cpp (L107-L109)
2024-11-19 09:07:40 +01:00
Vassil Vassilev
9a9546e30c
[clang-repl] Support wasm execution (#86402)
This commit introduces support for running clang-repl and executing C++
code interactively inside a Javascript engine using WebAssembly when
built with Emscripten. This is achieved by producing WASM "shared
libraries" that can be loaded by the Emscripten runtime using dlopen()

More discussion is available in https://reviews.llvm.org/D158140

Co-authored-by: Anubhab Ghosh <anubhabghosh.me@gmail.com>
2024-07-02 13:29:31 +03:00