Support exports of globals in assembler
This commit is contained in:
25
asm.js
25
asm.js
@@ -888,6 +888,7 @@ const Section = Object.freeze({
|
||||
const Kind = Object.freeze({
|
||||
FUNC: 0x00,
|
||||
MEM: 0x02,
|
||||
GLOBAL: 0x03,
|
||||
});
|
||||
|
||||
export class Assembler {
|
||||
@@ -942,8 +943,28 @@ export class Assembler {
|
||||
}
|
||||
|
||||
action_export(action) {
|
||||
const index = Object.keys(this.funcs).indexOf(action.name);
|
||||
this.exports[action.name] = { kind: Kind.FUNC, index };
|
||||
const func_index = Object.keys(this.funcs).indexOf(action.name);
|
||||
if (func_index != -1) {
|
||||
this.exports[action.name] = {
|
||||
kind: Kind.FUNC,
|
||||
index: func_index,
|
||||
};
|
||||
return;
|
||||
}
|
||||
|
||||
const global_index = Object.keys(this.globals).indexOf(action.name);
|
||||
if (global_index != -1) {
|
||||
this.exports[action.name] = {
|
||||
kind: Kind.GLOBAL,
|
||||
index: global_index,
|
||||
};
|
||||
return;
|
||||
}
|
||||
|
||||
console.error(
|
||||
`ERROR: Unable to resolve export ${action.name} `
|
||||
+ "(only functions and globals currently supported)"
|
||||
);
|
||||
}
|
||||
|
||||
action_func(action) {
|
||||
|
||||
Reference in New Issue
Block a user