-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Yisheng Jiang
committed
Apr 13, 2024
1 parent
1db5b7f
commit f71a3ef
Showing
8 changed files
with
89 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
all: yofi.wasm.js | ||
|
||
clean: src/yofi.c | ||
rm -f build/* | ||
|
||
build/yofi.ll: clean | ||
clang src/yofi.c -o build/yofi.ll --target=wasm32 -emit-llvm -c -S | ||
|
||
build/yofi.o: build/yofi.ll | ||
llc -march=wasm32 -filetype=obj build/yofi.ll -o build/yofi.o | ||
|
||
yofi.wasm: build/yofi.o | ||
wasm-ld --features=atomics,mutable-global --no-check-features --allow-undefined --import-memory --no-entry --export-all -o yofi.wasm build/yofi.o | ||
|
||
yofi.wasm.js: yofi.wasm | ||
cat yofi.wasm | npx encode-wasm-uint8 > yofi.wasm.js |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
{ | ||
"name": "grep-fifo", | ||
"version": "1.0.0", | ||
"description": "ES6 compliant and (typescript friendly) implementation of circular fifo in C99", | ||
"main": "fifo.wasmodule.js", | ||
"scripts": { | ||
"build": "docker run --rm -v `pwd`:/src trzeci/emscripten-slim emcc yofi.c -s EXPORT_ALL=1 -o yofi.js", | ||
"test": "node ./test.js" | ||
}, | ||
"keywords": [ | ||
"pain in the arse", | ||
"allegedly faster than javascript" | ||
], | ||
"author": "", | ||
"license": "ISC" | ||
} |
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
#include <stdint.h> | ||
|
||
#define QUEUE_SIZE 1 << 16 | ||
|
||
typedef struct { | ||
uint16_t head; | ||
uint16_t tail; | ||
char data[QUEUE_SIZE]; | ||
} queue_t; | ||
|
||
queue_t instance[1]; | ||
|
||
queue_t* getInstance() { return instance; } | ||
|
||
uint16_t queue_count(queue_t* queue) { return queue->head - queue->tail; } | ||
|
||
char queue_read(queue_t* queue) { | ||
if (queue->tail == queue->head) return 0; | ||
return queue->data[queue->tail++]; | ||
} | ||
|
||
int queue_write(queue_t* queue, char c) { | ||
queue->data[queue->head++] = c; | ||
return 0; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
<!DOCTYPE html> | ||
<html lang="en"> | ||
<head> | ||
<meta charset="UTF-8"> | ||
<meta http-equiv="X-UA-Compatible" content="IE=edge"> | ||
<meta name="viewport" content="width=device-width, initial-scale=1.0"> | ||
<title>Document</title> | ||
</head> | ||
<body> | ||
<script type="module"> | ||
import * as module from "./yofi.wasm.js"; | ||
const m = new WebAssembly.Module(module.wasmbin); | ||
const ll = new WebAssembly.Instance(m, { | ||
env: { | ||
memory: new WebAssembly.Memory({initial: 41}) | ||
} | ||
}); | ||
const qq = ll.exports.getInstance(); | ||
fetch("song.mid").then(r => r.arrayBuffer).then(ab => { | ||
const arr = new Uint8Array(ab); | ||
let off = 0; | ||
while (ll.exports.queue_write(qq, arr[off++])); | ||
|
||
}) | ||
|
||
|
||
</script> | ||
</body> | ||
</html> |
Binary file not shown.
Large diffs are not rendered by default.
Oops, something went wrong.