Skip to content

Commit 7ea4129

Browse files
committed
C API: Add BinaryenFunctionAppendVar
1 parent 1850199 commit 7ea4129

File tree

2 files changed

+12
-0
lines changed

2 files changed

+12
-0
lines changed

src/binaryen-c.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5878,6 +5878,14 @@ BinaryenType BinaryenFunctionGetVar(BinaryenFunctionRef func,
58785878
assert(index < vars.size());
58795879
return vars[index].getID();
58805880
}
5881+
BinaryenIndex BinaryenFunctionAppendVar(BinaryenFunctionRef func,
5882+
BinaryenType type) {
5883+
auto* function = (Function*)func;
5884+
auto& list = function->vars;
5885+
auto index = list.size();
5886+
list.push_back((Type)type);
5887+
return index;
5888+
}
58815889
BinaryenIndex BinaryenFunctionGetNumLocals(BinaryenFunctionRef func) {
58825890
return ((Function*)func)->getNumLocals();
58835891
}

src/binaryen-c.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3197,6 +3197,10 @@ BINARYEN_API BinaryenIndex BinaryenFunctionGetNumVars(BinaryenFunctionRef func);
31973197
// specified `Function`.
31983198
BINARYEN_API BinaryenType BinaryenFunctionGetVar(BinaryenFunctionRef func,
31993199
BinaryenIndex index);
3200+
// Appends a local variable to the specified `Function`, returning its
3201+
// insertion index.
3202+
BINARYEN_API BinaryenIndex BinaryenFunctionAppendVar(BinaryenFunctionRef func,
3203+
BinaryenType type);
32003204
// Gets the number of locals within the specified function. Includes parameters.
32013205
BINARYEN_API BinaryenIndex
32023206
BinaryenFunctionGetNumLocals(BinaryenFunctionRef func);

0 commit comments

Comments
 (0)