Skip to content
23 changes: 22 additions & 1 deletion src/clang.html
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,13 @@
flex-direction: column;
padding: 10px;
}

#pane-input>div {
overflow: auto;
display: flex;
flex-direction: column;
padding: 10px;
}

#runtime-iframe-container {
z-index: 41;
Expand All @@ -110,6 +117,12 @@
</div>
<pre id="clang-io" class="io"></pre>
</div>
<div id="pane-input" class="flex-col">
<div>Program Input:</div>
<div>
<textarea id="inputText" wrap="off"></textarea>
</div>
</div>
<div id="pane-gist-links" class="flex-col">
<div>
<h3>Emscripten API</h3>
Expand Down Expand Up @@ -212,6 +225,12 @@ <h3>HTML Integration</h3>
isClosable: false,
componentName: 'component',
componentState: { id: 'pane-html-source', className: 'source' }
}, {
type: 'component',
title: 'input',
isClosable: false,
componentName: 'component',
componentState: { id: 'pane-input' }
}]
}, {
type: 'component',
Expand Down Expand Up @@ -416,6 +435,7 @@ <h3>HTML Integration</h3>
runtime.process.postMessage({
function: 'run',
wasmBinary: clangOutput,
userInput: document.getElementById("inputText").value,
});
};

Expand Down Expand Up @@ -470,6 +490,7 @@ <h3>HTML Integration</h3>
runtime.process.worker.postMessage({
function: 'run',
wasmBinary: clangOutput,
userInput: document.getElementById("inputText").value,
});
}
}
Expand Down Expand Up @@ -571,4 +592,4 @@ <h3>HTML Integration</h3>
</script>
</body>

</html>
</html>
14 changes: 13 additions & 1 deletion src/process-runtime.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@ var inWorker = this.importScripts != undefined;
var wasmImports = {};
var wasmExports = {};

var inputText = "";
var i = 0;

if (inWorker) {
importScripts('process.js');
importScripts('wasm-tools.js');
Expand Down Expand Up @@ -67,6 +70,14 @@ commands.start = async function ({ moduleName, wasmBinary }) {
try {
if (inWorker)
importScripts(moduleName + '.js');
emModule.stdin = function () {
// Return ASCII code of character, or null if no input remains
if (i < inputText.length) {
let c = inputText.charCodeAt(i++);
return c;
} else
return null;
};
let binary = new Uint8Array(wasmBinary);
let { standardSections, relocs, linking } = getSegments(binary);
let { dataSize, initFunctions } = getLinkingInfo(binary, linking)
Expand Down Expand Up @@ -105,8 +116,9 @@ commands.start = async function ({ moduleName, wasmBinary }) {
}
};

commands.run = async function ({ wasmBinary }) {
commands.run = async function ({ wasmBinary, userInput }) {
try {
inputText = userInput;
let binary = new Uint8Array(wasmBinary);
let rtlExports = emModule.wasmInstance.exports;
let memory = emModule.wasmMemory;
Expand Down
2 changes: 1 addition & 1 deletion src/process.js
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ let emModule = {

async compileWasm() {
let hash, cacheResult;
if (crypto.subtle) {
if (typeof crypto !== "undefined" && crypto.subtle) {
hash = await crypto.subtle.digest('SHA-512', this.wasmBinary);
cacheResult = await checkCache(this.moduleName, hash);
} else {
Expand Down