tbfleming / cib Goto Github PK
View Code? Open in Web Editor NEWclang running in browser (wasm)
Home Page: https://tbfleming.github.io/cib/
clang running in browser (wasm)
Home Page: https://tbfleming.github.io/cib/
It would be really great to be able to preview the resulting webassembly bytecode, something similar to https://mbebenita.github.io/WasmExplorer/
On the website https://tbfleming.github.io/cib/,
keeping the example string-sorting code as-is,
click "Compile" -> "wasm size: 14001",
click "Run" -> "RuntimeError: index out of bounds"
Browser I use:
Chrome: Version 83.0.4103.116 (Official Build) (64-bit)
Firefox: 78.0.1 (64-bit)
I open https://tbfleming.github.io/cib/
But I see that "Preparing clang...", "Preparing runtime..". Buttons disabled. And "Failed to fetch" messages.
I noticed that there's no software license in the repo, FOSS or otherwise. Is that intentional?
I am trying to compile and run the following example and I get this error ...
// cib:{"fetch":"https://cdn.rawgit.com/mikeptweet/HelloWorld/21a97199/sqlite.zip", "system_includes":["."], "unzip_compiler":true}
#include "sqlite/sqlite3.h"
#include <stdio.h>
int main(void) {
sqlite3 *db;
sqlite3_stmt *res;
int rc = sqlite3_open(":memory:", &db);
if (rc != SQLITE_OK) {
fprintf(stderr, "Cannot open database: %s\n", sqlite3_errmsg(db));
sqlite3_close(db);
return 1;
}
rc = sqlite3_prepare_v2(db, "SELECT SQLITE_VERSION()", -1, &res, 0);
if (rc != SQLITE_OK) {
fprintf(stderr, "Failed to fetch data: %s\n", sqlite3_errmsg(db));
sqlite3_close(db);
return 1;
}
rc = sqlite3_step(res);
if (rc == SQLITE_ROW) {
printf("%s\n", sqlite3_column_text(res, 0));
}
sqlite3_finalize(res);
sqlite3_close(db);
return 0;
}
Do you have any instructions for if you already have emscripten installed? I tried deleting ~/.emscripten
, but it still didn't work.
@tbfleming with my latest experiments with your tool I discovered an issue that boggled my mind (a picture has been attached). Somehow, the executed WebAssembly throws a Link Error even though I am pretty sure that all the necessary files have been added to the ZIP archive which is loaded at the beginning of the process. I bet it is something minor that we are currently overlooking but I hope that you can help us with our issue. The code snippet to be compiled has also been attached.
// Download a file using https. Only works with sites which support CORS.
// cib:{"fetch":"https://raw.githubusercontent.com/EmbeddedMontiArc/website/master/test2.zip","system_includes":["antlr4","common","monticore", "."], "unzip_compiler":true}
#include <emscripten.h>
#include <stdio.h>
#include <string>
#include <memory>
#include "Grammar_WithConceptsAntlrLexer.h"
#include "Grammar_WithConceptsAntlrParser.h"
#include "antlr4-runtime.h"
using namespace std;
using antlr4::tree::ParseTreeWalker;
using antlr4::ANTLRInputStream;
using antlr4::CommonTokenStream;
using antlrcpp::ws2s;
int main() {
wstring wstr(L"");
string input = ws2s(wstr);
ANTLRInputStream stream(input);
Grammar_WithConceptsAntlrLexer lexer(&stream);
CommonTokenStream tokens(&lexer);
Grammar_WithConceptsAntlrParser parser(&tokens);
parser.mCGrammar();
}
Has anyone tried compiling clangd
to be used as a Language Server with Monaco (the editor behind VS Code?)
Try and put cout<<42; at the end of the sample code and it won't print. Multiple subsequent couts without a newline also won't show, anything on that last line. Hit run again and that lost cout will print first then the rest
HI ... thanks for this awesome project!
Everytime I try to run any of the examples, I get a "RuntimeError: index out of bounds". It seems to compile ok but fails on running the code. Would it be possible to get this fixed as I use this environment for teaching.
thanks
First of all, thanks for your efforts in bringing LLVM to the browser, great work.
The Clang format library from this project is being used in http://WebAssembly.studio. For now, compilation is done server side (in order to reduce code size) but we'd like to eventually do everything on the client.
Would you be interested in integrating these two projects more tightly?
When running the example, compilation succeeds (wasm size: 14001
) but running gives the output:-
RuntimeError: memory access out of bounds
Hi!
I'm trying to compile a program, which has been written in C++ to .wasm using cib. Could you please tell me, is it possible to pass compiler options? Maybe in the source code(like we do downloading some .zip files) or in another way?
When I do compilation with emscripten, I'm passing following parameters:
emcc.bat, pID.cpp, -o, pID.js, -I"..\armadillo", -s, WASM=1, -s, AGGRESSIVE_VARIABLE_ELIMINATION=1, -s, ALLOW_MEMORY_GROWTH=1, -L., -DARMA_DONT_USE_WRAPPER, -llapack_WIN64, -lblas_WIN64, -llibf2c, -ltmglib_WIN64, -llibfblaswr, -O3, --bind, -std=c++11
How you can see I use additional libraries. If it possible somehow use them during "web compilation"? Thank you in advance.
PS.: This is actually the code, which I'm trying to compile: https://tbfleming.github.io/cib/#gist=9bedf2bb85d1d67cf48454655aff4993
This project is really interesting!
I was able to get Armadillo to compile: http://arma.sourceforge.net/
Using the github pages branch locally, taking the armadillo download, and repackaging it as a zip:
// cib:{"fetch":"armadillo-9.200.7.zip", "system_includes":["include"], "unzip_compiler":true}
#define ARMA_DONT_USE_LAPACK
#define ARMA_DONT_USE_BLAS
#define ARMA_DONT_USE_NEWARP
#define ARMA_DONT_USE_ARPACK
#define ARMA_DONT_USE_SUPERLU
#define ARMA_DONT_USE_HDF5
#define ARMA_DONT_USE_OPENMP
#include <armadillo>
#include <stdio.h>
using namespace std;
using namespace arma;
int main() {
mat A = randu<mat>(4,5);
mat B = randu<mat>(4,5);
printf("%f\n", A[0]);
return 0;
}
I had to use the printf instead of the examples cout << A*B.t() << endl;
because of #17
Having this available in the browser could be really useful!
clang.wasm is 54315717 bytes. Running binaryen's wasm-opt -O2
shrinks it by around 15%, and -Os
by 20%, which suggests maybe it wasn't fully optimized?
I see the build script uses cmake and sets it to release, which should optimize the object files, but I'm not sure how it handles the final link to wasm (in emcc, we need -Os
or such during both compile and link). @juj, I think you wrote the emcmake code, what does it do for the final link?
cc @mbebenita
I wanted to ask if it would be possible to compile Libclang (C interface to clang) to WASM?
I am a complete noob here, please feel free to close this issue if this question is totally ridiculous. ๐
Hello,
I tried to build the project twice, without any success.
I have an EC2 Ubuntu machine, clean, with the packages you said to install. (nodejs instead of nodejs-legacy and libboost-all-tools instead of libboost1.58-tools-dev)
The repos are downloaded, cmake starts, then ninja starts, but at the very end, the whole thing stops with some error.
Building this takes a lot of time. (And apparently I may get an error after 5 hours of building)
Can you please provide the pre-built binaries for easier testing?
Thank you!
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.