Skip to content

[WIP] Decompiler #346

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 60 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
60 commits
Select commit Hold shift + click to select a range
c48a230
Merge pull request #1 from AssemblyScript/master
nidin Aug 9, 2018
3b4f4fb
Merge pull request #2 from AssemblyScript/master
nidin Nov 12, 2018
0d983b5
Path tracer and shared memory support added
nidin Jul 16, 2018
68adaeb
path tracer bucket indicator added
nidin Jul 16, 2018
0bd5fdc
Working on atomic load store
nidin Sep 10, 2018
ae41a85
Atomic operations added.
nidin Sep 21, 2018
8c0e6fa
If sharedMemory is greater than 0.
nidin Sep 21, 2018
5099533
smallpt CPP codes removed
nidin Sep 21, 2018
e6b1594
Removed tmp examples.
nidin Sep 21, 2018
931e221
CLI updated with shared memory options.
nidin Sep 22, 2018
179a2b2
Atomic operation tests added
nidin Sep 23, 2018
892949d
Atomic operations updated
nidin Sep 23, 2018
a09e397
Shared memory examples updated
nidin Sep 23, 2018
0ce39e4
Sign off
nidin Nov 12, 2018
9d7a8c9
Shared memory tests fixed.
nidin Nov 12, 2018
ea23fe0
Shared memory tests alignment issues fixed
nidin Nov 12, 2018
2deef79
Wait wake feature added
nidin Nov 17, 2018
c967b64
Added Function Calls and globals. However, globals don't print prope…
willemneal Nov 25, 2018
4a565b0
Tried to minimize transformation of asc source, but names are still c…
willemneal Nov 25, 2018
c3633c5
Fixed up test cases. Also improved how nested expressions with `{}`'…
willemneal Nov 25, 2018
aac78d2
Fix linting issues.
Nov 25, 2018
5862d50
Added loop, if, block, break, return, & can get func names with parser.
willemneal Nov 28, 2018
ff102b5
Atomic wait wake example updated
nidin Nov 29, 2018
ba56ef1
Wait wake example clean up
nidin Nov 29, 2018
cbaa786
Wait wake example html updated
nidin Nov 29, 2018
e9cf712
Merge pull request #3 from 01alchemist/feature/worker-based-threads-w…
nidin Nov 29, 2018
47f76a6
Added loader.
willemneal Dec 5, 2018
fa22f54
Delay the start of module so instance can be referenced by imports.
willemneal Dec 6, 2018
49ad4c2
Example of nulling the start function and then exporting original.
willemneal Dec 7, 2018
8b98771
Rename atomic.wake -> atomic.notify to align with WebAssembbly Spec.
nidin Dec 11, 2018
41fa72b
Handle the case where an inlined body is empty
dcodeIO Nov 12, 2018
feebe09
Fix parsing of properties and field names using semi-reserved keywords
dcodeIO Nov 13, 2018
c0706e3
Add ArrayBuffer/DataView/Symbol#toString and improve Errors (#332)
MaxGraey Nov 18, 2018
c496345
Add Math.signbit (#333)
MaxGraey Nov 18, 2018
877c1d1
Fix unsafeCompare (#336)
MaxGraey Nov 19, 2018
fec60b3
Update dist files
dcodeIO Nov 19, 2018
8bf5fb9
Update Binaryen to latest
dcodeIO Nov 22, 2018
5897dbf
Cast to bool by comparing to zero (#343)
dcodeIO Nov 23, 2018
2846e81
Shortcut f32/f64/i64 conversions to bool
dcodeIO Nov 23, 2018
7a002d2
Fix unsupported element access on 'this', see #349
dcodeIO Nov 29, 2018
0c40d2f
Add 'instantiate<T>' builtin (like 'new' but from a type), see #349
dcodeIO Nov 29, 2018
1c969f1
Fix implementation of Array#splice (#347)
MaxGraey Nov 29, 2018
b7f9ba1
Document the use of two type parameters in loadUnsafe, TypedArray etc…
dcodeIO Nov 30, 2018
ee2a4e4
Add a test suite option to also generate binaries
dcodeIO Nov 30, 2018
99faca2
Fix an issue with 'super' not being present when inlining
dcodeIO Nov 30, 2018
40434bc
Update Binaryen to latest
dcodeIO Dec 1, 2018
846215e
Add a way to ensure that lazy globals are resolved, fixes #355
dcodeIO Dec 1, 2018
4db1ea0
Fix partial function prototypes not sharing their instances
dcodeIO Dec 1, 2018
1d625b8
Add missing definitions for Uint8ClampedArray
dcodeIO Dec 1, 2018
bc95999
Allow asynchronous file read/writes for cli.
willemneal Dec 5, 2018
c9cb854
Trying to use wake/wait on single thread.
willemneal Dec 5, 2018
f49d793
Adding threading library.
willemneal Dec 22, 2018
8adbd7c
Cleaning up print statements.
willemneal Dec 22, 2018
aaaf0c7
Added notes to README
willemneal Dec 22, 2018
907e812
Update README.md
willemneal Dec 22, 2018
170a8c1
Moved back to using a mailbox.
willemneal Dec 22, 2018
97f5a5f
Update README.md
willemneal Dec 22, 2018
3eadf63
Isolating bug. Uncomment log_str in Lock.aquire and it causes the va…
willemneal Dec 24, 2018
25b8d1d
Moved to typescript. Todo: make test with node that uses webworker.
willemneal Dec 25, 2018
9f83376
Merge branch 'lib/threading' into decompiler
Dec 26, 2018
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,6 @@ docs/
node_modules/
out/
raw/
.history
.vscode
.idea
Empty file modified bin/asinit
100644 → 100755
Empty file.
76 changes: 44 additions & 32 deletions cli/asc.js
Original file line number Diff line number Diff line change
Expand Up @@ -92,35 +92,43 @@ exports.definitionFiles = exports.isBundle ? BUNDLE_DEFINITIONS : (() => { // se
})();

/** Convenience function that parses and compiles source strings directly. */
exports.compileString = (sources, options) => {
exports.compileString = async (sources, options) => {
if (typeof sources === "string") sources = { "input.ts": sources };
const output = Object.create({
stdout: createMemoryStream(),
stderr: createMemoryStream(),
binary: null,
text: null
});
var argv = [
"--binaryFile", "binary",
"--textFile", "text",
];
debugger;
var argv = [];
Object.keys(options || {}).forEach(key => {
var val = options[key];
if (Array.isArray(val)) val.forEach(val => argv.push("--" + key, String(val)));
else argv.push("--" + key, String(val));
if (key != "readFile" && key != 'writeFile'){
var val = options[key];
debugger;
if (Array.isArray(val)) val.forEach(val => argv.push("--" + key, String(val)));
else argv.push("--" + key, String(val));
}
});
exports.main(argv.concat(Object.keys(sources)), {
await exports.main(argv.concat(Object.keys(sources)), {
stdout: output.stdout,
stderr: output.stderr,
readFile: name => sources.hasOwnProperty(name) ? sources[name] : null,
writeFile: (name, contents) => output[name] = contents,
readFile: async (name) => {
try {
return await options.readFile(name);
}catch (e){
return null;
}
},
writeFile: async (name, contents) => await options.writeFile(name, contents),
listFiles: () => []
});
debugger;
return output;
}

/** Runs the command line utility using the specified arguments array. */
exports.main = function main(argv, options, callback) {
exports.main = async function main(argv, options, callback) {
if (typeof options === "function") {
callback = options;
options = {};
Expand Down Expand Up @@ -228,7 +236,7 @@ exports.main = function main(argv, options, callback) {

// Begin parsing
var parser = null;

debugger;
// Include library files
if (!args.noLib) {
Object.keys(exports.libraryFiles).forEach(libPath => {
Expand Down Expand Up @@ -270,7 +278,7 @@ exports.main = function main(argv, options, callback) {
}
for (let j = 0, l = libFiles.length; j < l; ++j) {
let libPath = libFiles[j];
let libText = readFile(path.join(libDir, libPath));
let libText = await readFile(path.join(libDir, libPath));
if (libText === null) return callback(Error("Library file '" + libPath + "' not found."));
stats.parseCount++;
stats.parseTime += measure(() => {
Expand All @@ -288,13 +296,14 @@ exports.main = function main(argv, options, callback) {
// Include entry files
for (let i = 0, k = argv.length; i < k; ++i) {
const filename = argv[i];
if (filename == "undefined") continue;

let sourcePath = String(filename).replace(/\\/g, "/").replace(/(\.ts|\/)$/, "");

// Try entryPath.ts, then entryPath/index.ts
let sourceText = readFile(path.join(baseDir, sourcePath) + ".ts");
let sourceText = await readFile(path.join(baseDir, sourcePath) + ".ts");
if (sourceText === null) {
sourceText = readFile(path.join(baseDir, sourcePath, "index.ts"));
sourceText = await readFile(path.join(baseDir, sourcePath, "index.ts"));
if (sourceText === null) {
return callback(Error("Entry file '" + sourcePath + ".ts' not found."));
} else {
Expand All @@ -303,6 +312,7 @@ exports.main = function main(argv, options, callback) {
} else {
sourcePath += ".ts";
}
debugger;

stats.parseCount++;
stats.parseTime += measure(() => {
Expand All @@ -326,12 +336,12 @@ exports.main = function main(argv, options, callback) {
} else {
for (let i = 0, k = customLibDirs.length; i < k; ++i) {
const dir = customLibDirs[i];
sourceText = readFile(path.join(dir, plainName + ".ts"));
sourceText = await readFile(path.join(dir, plainName + ".ts"));
if (sourceText !== null) {
sourcePath = exports.libraryPrefix + plainName + ".ts";
break;
} else {
sourceText = readFile(path.join(dir, indexName + ".ts"));
sourceText = await readFile(path.join(dir, indexName + ".ts"));
if (sourceText !== null) {
sourcePath = exports.libraryPrefix + indexName + ".ts";
break;
Expand All @@ -344,11 +354,11 @@ exports.main = function main(argv, options, callback) {
} else {
const plainName = sourcePath;
const indexName = sourcePath + "/index";
sourceText = readFile(path.join(baseDir, plainName + ".ts"));
sourceText = await readFile(path.join(baseDir, plainName + ".ts"));
if (sourceText !== null) {
sourcePath = plainName + ".ts";
} else {
sourceText = readFile(path.join(baseDir, indexName + ".ts"));
sourceText = await readFile(path.join(baseDir, indexName + ".ts"));
if (sourceText !== null) {
sourcePath = indexName + ".ts";
} else if (!plainName.startsWith(".")) {
Expand All @@ -361,12 +371,12 @@ exports.main = function main(argv, options, callback) {
} else {
for (let i = 0, k = customLibDirs.length; i < k; ++i) {
const dir = customLibDirs[i];
sourceText = readFile(path.join(dir, plainName + ".ts"));
sourceText = await readFile(path.join(dir, plainName + ".ts"));
if (sourceText !== null) {
sourcePath = exports.libraryPrefix + plainName + ".ts";
break;
} else {
sourceText = readFile(path.join(dir, indexName + ".ts"));
sourceText = await readFile(path.join(dir, indexName + ".ts"));
if (sourceText !== null) {
sourcePath = exports.libraryPrefix + indexName + ".ts";
break;
Expand Down Expand Up @@ -417,7 +427,9 @@ exports.main = function main(argv, options, callback) {
assemblyscript.setNoTreeShaking(compilerOptions, args.noTreeShaking);
assemblyscript.setNoAssert(compilerOptions, args.noAssert);
assemblyscript.setImportMemory(compilerOptions, args.importMemory);
assemblyscript.setSharedMemory(compilerOptions, args.sharedMemory);
assemblyscript.setImportTable(compilerOptions, args.importTable);
assemblyscript.ignoreDataSegments(compilerOptions, args.ignoreDataSegments);
assemblyscript.setMemoryBase(compilerOptions, args.memoryBase >>> 0);
assemblyscript.setSourceMap(compilerOptions, args.sourceMap != null);
assemblyscript.setOptimizeLevelHints(compilerOptions, optimizeLevel, shrinkLevel);
Expand Down Expand Up @@ -550,7 +562,7 @@ exports.main = function main(argv, options, callback) {
args.binaryFile = args.outFile;
}
}

debugger;
// Write binary
if (args.binaryFile != null) {
let sourceMapURL = args.sourceMap != null
Expand All @@ -566,7 +578,7 @@ exports.main = function main(argv, options, callback) {
});

if (args.binaryFile.length) {
writeFile(path.join(baseDir, args.binaryFile), wasm.output);
await writeFile(path.join(baseDir, args.binaryFile), wasm.output);
} else {
writeStdout(wasm.output);
hasStdout = true;
Expand All @@ -578,31 +590,31 @@ exports.main = function main(argv, options, callback) {
if (args.binaryFile.length) {
let sourceMap = JSON.parse(wasm.sourceMap);
sourceMap.sourceRoot = exports.sourceMapRoot;
sourceMap.sources.forEach((name, index) => {
sourceMap.sources.forEach(async (name, index) => {
let text = null;
if (name.startsWith(exports.libraryPrefix)) {
let stdName = name.substring(exports.libraryPrefix.length).replace(/\.ts$/, "");
if (exports.libraryFiles.hasOwnProperty(stdName)) {
text = exports.libraryFiles[stdName];
} else {
for (let i = 0, k = customLibDirs.length; i < k; ++i) {
text = readFile(path.join(
text = await readFile(path.join(
customLibDirs[i],
name.substring(exports.libraryPrefix.length))
);
if (text !== null) break;
}
}
} else {
text = readFile(path.join(baseDir, name));
text = await readFile(path.join(baseDir, name));
}
if (text === null) {
return callback(Error("Source file '" + name + "' not found."));
}
if (!sourceMap.sourceContents) sourceMap.sourceContents = [];
sourceMap.sourceContents[index] = text;
});
writeFile(path.join(
await writeFile(path.join(
baseDir,
path.dirname(args.binaryFile),
path.basename(sourceMapURL)
Expand All @@ -621,7 +633,7 @@ exports.main = function main(argv, options, callback) {
stats.emitTime += measure(() => {
asm = module.toAsmjs();
});
writeFile(path.join(baseDir, args.asmjsFile), asm);
await writeFile(path.join(baseDir, args.asmjsFile), asm);
} else if (!hasStdout) {
stats.emitCount++;
stats.emitTime += measure(() => {
Expand All @@ -641,7 +653,7 @@ exports.main = function main(argv, options, callback) {
stats.emitTime += measure(() => {
idl = assemblyscript.buildIDL(program);
});
writeFile(path.join(baseDir, args.idlFile), idl);
await writeFile(path.join(baseDir, args.idlFile), idl);
} else if (!hasStdout) {
stats.emitCount++;
stats.emitTime += measure(() => {
Expand All @@ -661,7 +673,7 @@ exports.main = function main(argv, options, callback) {
stats.emitTime += measure(() => {
tsd = assemblyscript.buildTSD(program);
});
writeFile(path.join(baseDir, args.tsdFile), tsd);
await writeFile(path.join(baseDir, args.tsdFile), tsd);
} else if (!hasStdout) {
stats.emitCount++;
stats.emitTime += measure(() => {
Expand All @@ -681,7 +693,7 @@ exports.main = function main(argv, options, callback) {
stats.emitTime += measure(() => {
wat = module.toText();
});
writeFile(path.join(baseDir, args.textFile), wat);
await writeFile(path.join(baseDir, args.textFile), wat);
} else if (!hasStdout) {
stats.emitCount++;
stats.emitTime += measure(() => {
Expand Down
10 changes: 10 additions & 0 deletions cli/asc.json
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,16 @@
"type": "b",
"default": false
},
"sharedMemory": {
"description": "Declare memory as shared.",
"type": "i",
"default": 0
},
"ignoreDataSegments": {
"description": "Ingore data segments to binary. Default false.",
"type": "b",
"default": false
},
"memoryBase": {
"description": "Sets the start offset of compiler-generated static memory.",
"type": "i",
Expand Down
2 changes: 1 addition & 1 deletion dist/asc.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/asc.js.map

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions dist/assemblyscript.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/assemblyscript.js.map

Large diffs are not rendered by default.

23 changes: 23 additions & 0 deletions examples/atomic-shared-memory/assembly/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
const fs = require("fs");
const path = require("path");

const compiled = new WebAssembly.Module(
fs.readFileSync(path.resolve(__dirname, "..", "build", "atomic.builtins.wasm"))
);
const memory = new WebAssembly.Memory({
initial: 256,
maximum: 256,
shared: true
})
const imports = {
env: {
memory,
abort: (filename, line, column) => {
throw Error("abort called at " + line + ":" + colum);
}
}
};

Object.defineProperty(module, "exports", {
get: () => new WebAssembly.Instance(compiled, imports).exports
});
105 changes: 105 additions & 0 deletions examples/atomic-shared-memory/assembly/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
declare function log(v: i32): void;

export function test(): void {
var i: i32 = 0;
var u: u32 = 0;
var I: i64 = 0;
var U: u64 = 0;

// Atomic store
Atomic.store<i8>(120, <i32>8);
Atomic.store<i16>(121, <i32>16);
Atomic.store<i32>(123, <i32>32);

Atomic.store<i8>(120, <i64>8);
Atomic.store<i16>(121, <i64>16);
Atomic.store<i32>(123, <i64>32);
Atomic.store<i64>(127, <i64>64);

// Atomic load
i = Atomic.load<i8>(120);
i = Atomic.load<i16>(121);
i = Atomic.load<i32>(123);
u = Atomic.load<i8>(120);
u = Atomic.load<i16>(121);
u = Atomic.load<i32>(123);

I = Atomic.load<i8>(120);
I = Atomic.load<i16>(121);
I = Atomic.load<i32>(123);
I = Atomic.load<i64>(127);
U = Atomic.load<i8>(120);
U = Atomic.load<i16>(121);
U = Atomic.load<i32>(123);
U = Atomic.load<i64>(127);

// Atomic add
i = Atomic.add<i8>(120, 1);
i = Atomic.add<i16>(121, 1);
i = Atomic.add<i32>(123, 1);

I = Atomic.add<i8>(120, <i64>1);
I = Atomic.add<i16>(121, <i64>1);
I = Atomic.add<i32>(123, <i64>1);
I = Atomic.add<i64>(127, <i64>1);

// Atomic subtract
Atomic.sub<i8>(120, 1);
Atomic.sub<i16>(121, 1);
Atomic.sub<i32>(123, 1);

I = Atomic.sub<i8>(120, <i64>1);
I = Atomic.sub<i16>(121, <i64>1);
I = Atomic.sub<i32>(123, <i64>1);
I = Atomic.sub<i64>(127, <i64>1);

// Atomic AND
Atomic.and<i8>(120, 1);
Atomic.and<i16>(121, 1);
Atomic.and<i32>(123, 1);

I = Atomic.and<i8>(120, <i64>1);
I = Atomic.and<i16>(121, <i64>1);
I = Atomic.and<i32>(123, <i64>1);
I = Atomic.and<i64>(127, <i64>1);

// Atomic OR
Atomic.or<i8>(120, 1);
Atomic.or<i16>(121, 1);
Atomic.or<i32>(123, 1);

I = Atomic.or<i8>(120, <i64>1);
I = Atomic.or<i16>(121, <i64>1);
I = Atomic.or<i32>(123, <i64>1);
I = Atomic.or<i64>(127, <i64>1);

// Atomic XOR
Atomic.xor<i8>(120, 1);
Atomic.xor<i16>(121, 1);
Atomic.xor<i32>(123, 1);

I = Atomic.xor<i8>(120, <i64>1);
I = Atomic.xor<i16>(121, <i64>1);
I = Atomic.xor<i32>(123, <i64>1);
I = Atomic.xor<i64>(127, <i64>1);

// Atomic xchg
Atomic.xchg<i8>(120, 1);
Atomic.xchg<i16>(121, 1);
Atomic.xchg<i32>(123, 1);

I = Atomic.xchg<i8>(120, <i64>1);
I = Atomic.xchg<i16>(121, <i64>1);
I = Atomic.xchg<i32>(123, <i64>1);
I = Atomic.xchg<i64>(127, <i64>1);

// Atomic cmpxchg
Atomic.cmpxchg<i8>(120, 1, 2);
Atomic.cmpxchg<i16>(121, 1, 2);
Atomic.cmpxchg<i32>(123, 1, 2);

I = Atomic.cmpxchg<i8>(120, <i64>1, <i64>2);
I = Atomic.cmpxchg<i16>(121, <i64>1, <i64>2);
I = Atomic.cmpxchg<i32>(123, <i64>1, <i64>2);
I = Atomic.cmpxchg<i64>(127, <i64>1, <i64>2);
}
Loading