Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
185 changes: 168 additions & 17 deletions src/js/binaryen.js-post.js
Original file line number Diff line number Diff line change
Expand Up @@ -3058,14 +3058,16 @@ Module['getExpressionType'] = function(expr) {
Module['getExpressionInfo'] = function(expr) {
const id = Module['_BinaryenExpressionGetId'](expr);
const type = Module['_BinaryenExpressionGetType'](expr);
switch (id) { // TODO: GC instructions
case Module['BlockId']:
switch (id) {
case Module['BlockId']: {
const name = Module['_BinaryenBlockGetName'](expr);
return {
'id': id,
'type': type,
'name': UTF8ToString(Module['_BinaryenBlockGetName'](expr)),
'name': name ? UTF8ToString(name) : null,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Perhaps we could have a UTF8ToStringOrNull helper for this pattern, but we can consider that separately.

'children': getAllNested(expr, Module['_BinaryenBlockGetNumChildren'], Module['_BinaryenBlockGetChildAt'])
};
}
case Module['IfId']:
return {
'id': id,
Expand All @@ -3074,21 +3076,25 @@ Module['getExpressionInfo'] = function(expr) {
'ifTrue': Module['_BinaryenIfGetIfTrue'](expr),
'ifFalse': Module['_BinaryenIfGetIfFalse'](expr)
};
case Module['LoopId']:
case Module['LoopId']: {
const name = Module['_BinaryenLoopGetName'](expr);
return {
'id': id,
'type': type,
'name': UTF8ToString(Module['_BinaryenLoopGetName'](expr)),
'name': name ? UTF8ToString(name) : null,
'body': Module['_BinaryenLoopGetBody'](expr)
};
case Module['BreakId']:
}
case Module['BreakId']: {
const name = Module['_BinaryenBreakGetName'](expr);
return {
'id': id,
'type': type,
'name': UTF8ToString(Module['_BinaryenBreakGetName'](expr)),
'name': name ? UTF8ToString(name) : null,
'condition': Module['_BinaryenBreakGetCondition'](expr),
'value': Module['_BinaryenBreakGetValue'](expr)
};
}
case Module['SwitchId']:
return {
'id': id,
Expand All @@ -3113,8 +3119,10 @@ Module['getExpressionInfo'] = function(expr) {
'type': type,
'isReturn': Boolean(Module['_BinaryenCallIndirectIsReturn'](expr)),
'target': Module['_BinaryenCallIndirectGetTarget'](expr),
'table': Module['_BinaryenCallIndirectGetTable'](expr),
'operands': getAllNested(expr, Module['_BinaryenCallIndirectGetNumOperands'], Module['_BinaryenCallIndirectGetOperandAt'])
'table': UTF8ToString(Module['_BinaryenCallIndirectGetTable'](expr)),
'operands': getAllNested(expr, Module['_BinaryenCallIndirectGetNumOperands'], Module['_BinaryenCallIndirectGetOperandAt']),
'params': Module['_BinaryenCallIndirectGetParams'](expr),
'results': Module['_BinaryenCallIndirectGetResults'](expr)
};
case Module['LocalGetId']:
return {
Expand Down Expand Up @@ -3192,7 +3200,8 @@ Module['getExpressionInfo'] = function(expr) {
'bytes': Module['_BinaryenStoreGetBytes'](expr),
'align': Module['_BinaryenStoreGetAlign'](expr),
'ptr': Module['_BinaryenStoreGetPtr'](expr),
'value': Module['_BinaryenStoreGetValue'](expr)
'value': Module['_BinaryenStoreGetValue'](expr),
'valueType': Module['_BinaryenStoreGetValueType'](expr)
};
case Module['ConstId']: {
let value;
Expand Down Expand Up @@ -3386,11 +3395,13 @@ Module['getExpressionInfo'] = function(expr) {
'align': Module['_BinaryenSIMDLoadStoreLaneGetAlign'](expr),
'index': Module['_BinaryenSIMDLoadStoreLaneGetIndex'](expr),
'ptr': Module['_BinaryenSIMDLoadStoreLaneGetPtr'](expr),
'vec': Module['_BinaryenSIMDLoadStoreLaneGetVec'](expr)
'vec': Module['_BinaryenSIMDLoadStoreLaneGetVec'](expr),
'isStore': Boolean(Module['_BinaryenSIMDLoadStoreLaneIsStore'](expr))
};
case Module['MemoryInitId']:
return {
'id': id,
'type': type,
'segment': UTF8ToString(Module['_BinaryenMemoryInitGetSegment'](expr)),
'dest': Module['_BinaryenMemoryInitGetDest'](expr),
'offset': Module['_BinaryenMemoryInitGetOffset'](expr),
Expand All @@ -3399,18 +3410,21 @@ Module['getExpressionInfo'] = function(expr) {
case Module['DataDropId']:
return {
'id': id,
'type': type,
'segment': UTF8ToString(Module['_BinaryenDataDropGetSegment'](expr)),
};
case Module['MemoryCopyId']:
return {
'id': id,
'type': type,
'dest': Module['_BinaryenMemoryCopyGetDest'](expr),
'source': Module['_BinaryenMemoryCopyGetSource'](expr),
'size': Module['_BinaryenMemoryCopyGetSize'](expr)
};
case Module['MemoryFillId']:
return {
'id': id,
'type': type,
'dest': Module['_BinaryenMemoryFillGetDest'](expr),
'value': Module['_BinaryenMemoryFillGetValue'](expr),
'size': Module['_BinaryenMemoryFillGetSize'](expr)
Expand Down Expand Up @@ -3446,18 +3460,155 @@ Module['getExpressionInfo'] = function(expr) {
'left': Module['_BinaryenRefEqGetLeft'](expr),
'right': Module['_BinaryenRefEqGetRight'](expr)
};
case Module['TryId']:
case Module['RefTestId']:
return {
'id': id,
'type': type,
'ref': Module['_BinaryenRefTestGetRef'](expr),
'castType': Module['_BinaryenRefTestGetCastType'](expr)
};
case Module['RefCastId']:
return {
'id': id,
'type': type,
'ref': Module['_BinaryenRefCastGetRef'](expr)
};
case Module['BrOnId']:
return {
'id': id,
'type': type,
'op': Module['_BinaryenBrOnGetOp'](expr),
'name': UTF8ToString(Module['_BinaryenBrOnGetName'](expr)),
'ref': Module['_BinaryenBrOnGetRef'](expr),
'castType': Module['_BinaryenBrOnGetCastType'](expr)
};
case Module['StructNewId']:
return {
'id': id,
'type': type,
'operands': getAllNested(expr, Module['_BinaryenStructNewGetNumOperands'], Module['_BinaryenStructNewGetOperandAt']),
};
case Module['StructGetId']:
return {
'id': id,
'type': type,
'index': Module['_BinaryenStructGetGetIndex'](expr),
'ref': Module['_BinaryenStructGetGetRef'](expr),
'isSigned': Boolean(Module['_BinaryenStructGetIsSigned'](expr))
};
case Module['StructSetId']:
return {
'id': id,
'type': type,
'index': Module['_BinaryenStructSetGetIndex'](expr),
'ref': Module['_BinaryenStructSetGetRef'](expr),
'value': Module['_BinaryenStructSetGetValue'](expr)
};
case Module['ArrayNewId']:
return {
'id': id,
'type': type,
'init': Module['_BinaryenArrayNewGetInit'](expr),
'size': Module['_BinaryenArrayNewGetSize'](expr)
};
case Module['ArrayNewFixedId']:
return {
'id': id,
'type': type,
'values': getAllNested(expr, Module['_BinaryenArrayNewFixedGetNumValues'], Module['_BinaryenArrayNewFixedGetValueAt'])
};
case Module['ArrayNewDataId']:
return {
'id': id,
'type': type,
'segment': UTF8ToString(Module['_BinaryenArrayNewDataGetSegment'](expr)),
'offset': Module['_BinaryenArrayNewDataGetOffset'](expr),
'size': Module['_BinaryenArrayNewDataGetSize'](expr)
};
case Module['ArrayNewElemId']:
return {
'id': id,
'type': type,
'segment': UTF8ToString(Module['_BinaryenArrayNewElemGetSegment'](expr)),
'offset': Module['_BinaryenArrayNewElemGetOffset'](expr),
'size': Module['_BinaryenArrayNewElemGetSize'](expr)
};
case Module['ArrayGetId']:
return {
'id': id,
'type': type,
'ref': Module['_BinaryenArrayGetGetRef'](expr),
'index': Module['_BinaryenArrayGetGetIndex'](expr),
'isSigned': Boolean(Module['_BinaryenArrayGetIsSigned'](expr))
};
case Module['ArraySetId']:
return {
'id': id,
'type': type,
'ref': Module['_BinaryenArraySetGetRef'](expr),
'index': Module['_BinaryenArraySetGetIndex'](expr),
'value': Module['_BinaryenArraySetGetValue'](expr)
};
case Module['ArrayLenId']:
return {
'id': id,
'type': type,
'ref': Module['_BinaryenArrayLenGetRef'](expr)
};
case Module['ArrayFillId']:
return {
'id': id,
'type': type,
'ref': Module['_BinaryenArrayFillGetRef'](expr),
'index': Module['_BinaryenArrayFillGetIndex'](expr),
'value': Module['_BinaryenArrayFillGetValue'](expr),
'size': Module['_BinaryenArrayFillGetSize'](expr)
};
case Module['ArrayCopyId']:
return {
'id': id,
'type': type,
'destRef': Module['_BinaryenArrayCopyGetDestRef'](expr),
'destIndex': Module['_BinaryenArrayCopyGetDestIndex'](expr),
'srcRef': Module['_BinaryenArrayCopyGetSrcRef'](expr),
'srcIndex': Module['_BinaryenArrayCopyGetSrcIndex'](expr),
'length': Module['_BinaryenArrayCopyGetLength'](expr)
};
case Module['ArrayInitDataId']:
return {
'id': id,
'type': type,
'name': UTF8ToString(Module['_BinaryenTryGetName'](expr)),
'segment': UTF8ToString(Module['_BinaryenArrayInitDataGetSegment'](expr)),
'ref': Module['_BinaryenArrayInitDataGetRef'](expr),
'index': Module['_BinaryenArrayInitDataGetIndex'](expr),
'offset': Module['_BinaryenArrayInitDataGetOffset'](expr),
'size': Module['_BinaryenArrayInitDataGetSize'](expr)
};
case Module['ArrayInitElemId']:
return {
'id': id,
'type': type,
'segment': UTF8ToString(Module['_BinaryenArrayInitElemGetSegment'](expr)),
'ref': Module['_BinaryenArrayInitElemGetRef'](expr),
'index': Module['_BinaryenArrayInitElemGetIndex'](expr),
'offset': Module['_BinaryenArrayInitElemGetOffset'](expr),
'size': Module['_BinaryenArrayInitElemGetSize'](expr)
};
case Module['TryId']: {
const name = Module['_BinaryenTryGetName'](expr);
const delegateTarget = Module['_BinaryenTryGetDelegateTarget'](expr);
return {
'id': id,
'type': type,
'name': name ? UTF8ToString(name) : null,
'body': Module['_BinaryenTryGetBody'](expr),
'catchTags': getAllNested(expr, Module['_BinaryenTryGetNumCatchTags'], Module['_BinaryenTryGetCatchTagAt']),
'catchTags': getAllNested(expr, Module['_BinaryenTryGetNumCatchTags'], Module['_BinaryenTryGetCatchTagAt']).map(p => UTF8ToString(p)),
'catchBodies': getAllNested(expr, Module['_BinaryenTryGetNumCatchBodies'], Module['_BinaryenTryGetCatchBodyAt']),
'hasCatchAll': Module['_BinaryenTryHasCatchAll'](expr),
'delegateTarget': UTF8ToString(Module['_BinaryenTryGetDelegateTarget'](expr)),
'isDelegate': Module['_BinaryenTryIsDelegate'](expr)
'hasCatchAll': Boolean(Module['_BinaryenTryHasCatchAll'](expr)),
'delegateTarget': delegateTarget ? UTF8ToString(delegateTarget) : null,
'isDelegate': Boolean(Module['_BinaryenTryIsDelegate'](expr))
};
}
case Module['ThrowId']:
return {
'id': id,
Expand Down
4 changes: 2 additions & 2 deletions test/binaryen.js/exception-handling.js.txt
Original file line number Diff line number Diff line change
Expand Up @@ -36,5 +36,5 @@

getExpressionInfo(throw) = {"id":54,"type":1,"tag":"e"}
getExpressionInfo(rethrow) = {"id":55,"type":1,"target":"l0"}
getExpressionInfo(try_catch) = {"id":52,"type":1,"name":"l0","hasCatchAll":0,"delegateTarget":"","isDelegate":0}
getExpressionInfo(try_delegate) = {"id":52,"type":0,"name":"try_outer","hasCatchAll":1,"delegateTarget":"","isDelegate":0}
getExpressionInfo(try_catch) = {"id":52,"type":1,"name":"l0","hasCatchAll":false,"delegateTarget":null,"isDelegate":false}
getExpressionInfo(try_delegate) = {"id":52,"type":0,"name":"try_outer","hasCatchAll":true,"delegateTarget":null,"isDelegate":false}
Loading
Loading