Created
July 11, 2018 18:33
-
-
Save TerrorJack/093b65141e3f0c798ac255fad4d42278 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// beginning a Binaryen API trace | |
#include <math.h> | |
#include <map> | |
#include "src/binaryen-c.h" | |
int main() { | |
std::map<size_t, BinaryenFunctionTypeRef> functionTypes; | |
std::map<size_t, BinaryenExpressionRef> expressions; | |
std::map<size_t, BinaryenFunctionRef> functions; | |
std::map<size_t, BinaryenImportRef> imports; | |
std::map<size_t, BinaryenExportRef> exports; | |
std::map<size_t, RelooperBlockRef> relooperBlocks; | |
BinaryenModuleRef the_module = NULL; | |
RelooperRef the_relooper = NULL; | |
the_module = BinaryenModuleCreate(); | |
expressions[size_t(NULL)] = BinaryenExpressionRef(NULL); | |
{ | |
BinaryenType paramTypes[] = { 0 }; | |
functionTypes[0] = BinaryenAddFunctionType(the_module, "func_type", 1, paramTypes, 0); | |
} | |
the_relooper = RelooperCreate(); | |
expressions[1] = BinaryenConst(the_module, BinaryenLiteralInt32(19)); | |
expressions[2] = BinaryenReturn(the_module, expressions[1]); | |
relooperBlocks[0] = RelooperAddBlock(the_relooper, expressions[2]); | |
expressions[3] = BinaryenNop(the_module); | |
expressions[4] = BinaryenGetLocal(the_module, 0, 1); | |
relooperBlocks[0] = RelooperAddBlockWithSwitch(the_relooper, expressions[3], expressions[4]); | |
expressions[5] = BinaryenConst(the_module, BinaryenLiteralInt32(233)); | |
expressions[6] = BinaryenReturn(the_module, expressions[5]); | |
relooperBlocks[2] = RelooperAddBlock(the_relooper, expressions[6]); | |
{ | |
BinaryenIndex indexes[] = { 0 }; | |
RelooperAddBranchForSwitch(relooperBlocks[0], relooperBlocks[0], indexes, 1, expressions[0]); | |
} | |
RelooperAddBranch(relooperBlocks[0], relooperBlocks[2], expressions[0], expressions[0]); | |
expressions[7] = RelooperRenderAndDispose(the_relooper, relooperBlocks[0], 0, the_module); | |
{ | |
BinaryenType varTypes[] = { 1 }; | |
functions[0] = BinaryenAddFunction(the_module, "func", functionTypes[0], varTypes, 1, expressions[7]); | |
} | |
BinaryenModuleValidate(the_module); | |
BinaryenModuleDispose(the_module); | |
functionTypes.clear(); | |
expressions.clear(); | |
functions.clear(); | |
imports.clear(); | |
exports.clear(); | |
relooperBlocks.clear(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment