Skip to content

Commit 2145be3

Browse files
committed
feat: apply tbfleming#13 patch; adjust install cmd; adjust build.py
1 parent 51a7e96 commit 2145be3

File tree

5 files changed

+47
-8
lines changed

5 files changed

+47
-8
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ Ubuntu 16.04:
3434
```
3535
sudo apt update
3636
sudo apt upgrade
37-
sudo apt install build-essential cmake ninja-build python nodejs-legacy libncurses-dev unzip libboost1.58-tools-dev
37+
sudo apt install -y build-essential cmake ninja-build python3 nodejs libncurses-dev unzip libboost-all-dev
3838
```
3939

4040
## Building WASM binaries

build.py

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
# FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
2121
# DEALINGS IN THE SOFTWARE.
2222

23-
import argparse, os, subprocess, sys
23+
import argparse, os, subprocess, sys, re
2424
from urllib.parse import urlparse
2525

2626
useTag = 'cib-013' # --clone and --checkout retrieve this tag
@@ -167,7 +167,7 @@ def download(url, basename=None):
167167
# ('repos/fastcomp', 'tbfleming/cib-emscripten-fastcomp.git', 'kripken/emscripten-fastcomp.git', True, 'incoming', 'incoming'),
168168
# ('repos/fastcomp/tools/clang', 'tbfleming/cib-emscripten-fastcomp-clang.git', 'kripken/emscripten-fastcomp-clang.git', True, 'incoming', 'incoming'),
169169
('repos/emscripten', 'tbfleming/cib-emscripten.git', 'kripken/emscripten.git', True, 'incoming', 'cib'),
170-
('repos/wabt', 'WebAssembly/wabt.git', 'WebAssembly/wabt.git', False, 'master', 'master'),
170+
('repos/wabt', 'WebAssembly/wabt.git', 'WebAssembly/wabt.git', False, 'main', 'main'),
171171
('repos/binaryen', 'tbfleming/cib-binaryen.git', 'WebAssembly/binaryen.git', True, 'master', 'cib'),
172172
('repos/zip.js', 'gildas-lormeau/zip.js.git', 'gildas-lormeau/zip.js.git', False, '3e7920810f63d5057ef6028833243105521da369', '3e7920810f63d5057ef6028833243105521da369'),
173173
('repos/eos', 'tbfleming/cib-eos.git', 'EOSIO/eos.git', True, 'dawn-v3.0.0', 'cib'),
@@ -185,6 +185,9 @@ def format():
185185
run('chmod a-x *.md .gitignore src/*.h src/*.cpp src/*.js src/*.html src/*.txt src/rtl/*')
186186
run('chmod a-x src/eos/.gitignore src/eos/package.json src/eos/src/*')
187187

188+
def is_commit_hash(commit_hash):
189+
return re.match(r'^[0-9a-f]{40}$', commit_hash)
190+
188191
def clone():
189192
for (path, url, upstream, isPushable, upstreamBranch, branch) in repos:
190193
if os.path.isdir(path):
@@ -194,9 +197,12 @@ def clone():
194197
dir = os.path.dirname(path)
195198
base = os.path.basename(path)
196199
run('mkdir -p ' + dir)
197-
run('cd ' + dir + ' && git clone ' + gitProtocol + url + ' ' + base)
200+
if is_commit_hash(branch):
201+
run('cd ' + dir + ' && git clone ' + gitProtocol + url + ' ' + base)
202+
run('cd ' + path + ' git checkout ' + branch)
203+
else:
204+
run('cd ' + dir + ' && git clone --branch ' + branch + ' --depth 1 ' + gitProtocol + url + ' ' + base)
198205
run('cd ' + path + ' && git remote add upstream ' + gitProtocol + upstream)
199-
run('cd ' + path + ' && git checkout ' + branch)
200206

201207
def status():
202208
for (path, url, upstream, isPushable, upstreamBranch, branch) in repos:

src/clang.html

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,13 @@
8484
flex-direction: column;
8585
padding: 10px;
8686
}
87+
88+
#pane-input>div {
89+
overflow: auto;
90+
display: flex;
91+
flex-direction: column;
92+
padding: 10px;
93+
}
8794

8895
#runtime-iframe-container {
8996
z-index: 41;
@@ -110,6 +117,12 @@
110117
</div>
111118
<pre id="clang-io" class="io"></pre>
112119
</div>
120+
<div id="pane-input" class="flex-col">
121+
<div>Program Input:</div>
122+
<div>
123+
<textarea id="inputText" wrap="off"></textarea>
124+
</div>
125+
</div>
113126
<div id="pane-gist-links" class="flex-col">
114127
<div>
115128
<h3>Emscripten API</h3>
@@ -212,6 +225,12 @@ <h3>HTML Integration</h3>
212225
isClosable: false,
213226
componentName: 'component',
214227
componentState: { id: 'pane-html-source', className: 'source' }
228+
}, {
229+
type: 'component',
230+
title: 'input',
231+
isClosable: false,
232+
componentName: 'component',
233+
componentState: { id: 'pane-input' }
215234
}]
216235
}, {
217236
type: 'component',
@@ -416,6 +435,7 @@ <h3>HTML Integration</h3>
416435
runtime.process.postMessage({
417436
function: 'run',
418437
wasmBinary: clangOutput,
438+
userInput: document.getElementById("inputText").value,
419439
});
420440
};
421441

@@ -470,6 +490,7 @@ <h3>HTML Integration</h3>
470490
runtime.process.worker.postMessage({
471491
function: 'run',
472492
wasmBinary: clangOutput,
493+
userInput: document.getElementById("inputText").value,
473494
});
474495
}
475496
}
@@ -571,4 +592,4 @@ <h3>HTML Integration</h3>
571592
</script>
572593
</body>
573594

574-
</html>
595+
</html>

src/process-runtime.js

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,9 @@ var inWorker = this.importScripts != undefined;
2424
var wasmImports = {};
2525
var wasmExports = {};
2626

27+
var inputText = "";
28+
var i = 0;
29+
2730
if (inWorker) {
2831
importScripts('process.js');
2932
importScripts('wasm-tools.js');
@@ -67,6 +70,14 @@ commands.start = async function ({ moduleName, wasmBinary }) {
6770
try {
6871
if (inWorker)
6972
importScripts(moduleName + '.js');
73+
emModule.stdin = function () {
74+
// Return ASCII code of character, or null if no input remains
75+
if (i < inputText.length) {
76+
let c = inputText.charCodeAt(i++);
77+
return c;
78+
} else
79+
return null;
80+
};
7081
let binary = new Uint8Array(wasmBinary);
7182
let { standardSections, relocs, linking } = getSegments(binary);
7283
let { dataSize, initFunctions } = getLinkingInfo(binary, linking)
@@ -105,8 +116,9 @@ commands.start = async function ({ moduleName, wasmBinary }) {
105116
}
106117
};
107118

108-
commands.run = async function ({ wasmBinary }) {
119+
commands.run = async function ({ wasmBinary, userInput }) {
109120
try {
121+
inputText = userInput;
110122
let binary = new Uint8Array(wasmBinary);
111123
let rtlExports = emModule.wasmInstance.exports;
112124
let memory = emModule.wasmMemory;

src/process.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ let emModule = {
116116

117117
async compileWasm() {
118118
let hash, cacheResult;
119-
if (crypto.subtle) {
119+
if (typeof crypto !== "undefined" && crypto.subtle) {
120120
hash = await crypto.subtle.digest('SHA-512', this.wasmBinary);
121121
cacheResult = await checkCache(this.moduleName, hash);
122122
} else {

0 commit comments

Comments
 (0)