binji / wasm-clang

Running Clang/LLD in WebAssembly Demo
https://binji.github.io/wasm-clang
Apache License 2.0
259 stars 27 forks source link

Added support for reading from stdin. #6

Closed leoleoasd closed 4 years ago

leoleoasd commented 4 years ago

Added support for reading from stdin.

As described in this issue.

I only added functionality to read, didn't add an interface in HTML to specify the input. You can change the default MemFS.stdinStr to test this patch.

leoleoasd commented 4 years ago

Why the memfs binary is smaller than original :thinking:

leoleoasd commented 4 years ago

Also, can you remove memfs changes here from the PR?

Should I make a git revert commit or git reset --soft and commit again to avoid the modified memfs file left in the git history?

leoleoasd commented 4 years ago

I just realized you will need to update memfs anyway; host_read isn't defined there, so you'll need to call out from memfs to the host in the same way host_write is implemented.

Also created a PR for your fork of llvm contains the changes of memfs.c.

leoleoasd commented 4 years ago

Another question is that the js file (shared.js) requires the binary mapping of the iovs, such as the first 4 bytes is the buf. So, this can only be used with a specified wasi-sdk version, (10.0 wont work on my side), should we migrate it to use some helper functions from memfs.c such as getBufOfIovs to get the pointer of buf?

binji commented 4 years ago

So, this can only be used with a specified wasi-sdk version, (10.0 wont work on my side), should we migrate it to use some helper functions from memfs.c such as getBufOfIovs to get the pointer of buf?

I'd guess that there would be a lot more changes required for a different WASI version, so I'm not sure it's worth abstracting it for just this one case.

leoleoasd commented 4 years ago

Ready for final review and merge.

kkoomen commented 6 months ago

How can I make this work in the current version without the use of any server? Because the example C code below inside the editor component doesn't prompt xterm for some stdin:

#include <stdio.h>

int main() {
    int num;
    printf("Enter a number: ");
    scanf("%d", &num);
    printf("The number you entered is %d\n", num);
    return 0;
}