Skip to content

Commit 6285642

Browse files
authored
Minor code cleanups (#1617)
* code cleanups in wasm-binary: remove an & param, and standardize whitespace * add some docs for how the relooper handles blocks with no outgoing branches [ci skip]
1 parent 5ccfbac commit 6285642

File tree

4 files changed

+130
-125
lines changed

4 files changed

+130
-125
lines changed

src/binaryen-c.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -822,7 +822,8 @@ const char* BinaryenExportGetValue(BinaryenExportRef export_);
822822
// General usage is (1) create a relooper, (2) create blocks, (3) add
823823
// branches between them, (4) render the output.
824824
//
825-
// See Relooper.h for more details
825+
// For more details, see src/cfg/Relooper.h and
826+
// https://github.com/WebAssembly/binaryen/wiki/Compiling-to-WebAssembly-with-Binaryen#cfg-api
826827

827828
typedef void* RelooperRef;
828829
typedef void* RelooperBlockRef;

src/cfg/Relooper.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -235,6 +235,10 @@ struct Block {
235235
// Add a branch: if the condition holds we branch (or if null, we branch if all others failed)
236236
// Note that there can be only one branch from A to B (if you need multiple conditions for the branch,
237237
// create a more interesting expression in the Condition).
238+
// If a Block has no outgoing branches, the contents in Code must contain a terminating
239+
// instruction, as the relooper doesn't know whether you want control flow to stop with
240+
// an `unreachable` or a `return` or something else (if you forget to do this, control
241+
// flow may continue into the block that happens to be emitted right after it).
238242
void AddBranchTo(Block *Target, wasm::Expression* Condition, wasm::Expression* Code = nullptr);
239243

240244
// Add a switch branch: if the switch condition is one of these values, we branch (or if the list is empty, we are the default)

src/wasm-binary.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -750,7 +750,7 @@ class WasmBinaryWriter : public Visitor<WasmBinaryWriter, void> {
750750
// AST writing via visitors
751751
int depth = 0; // only for debugging
752752

753-
void recurse(Expression*& curr);
753+
void recurse(Expression* curr);
754754
std::vector<Name> breakStack;
755755
Function::DebugLocation lastDebugLocation;
756756
size_t lastBytecodeOffset;

0 commit comments

Comments
 (0)