diff --git a/w2c2/c.c b/w2c2/c.c index b85b60d..d15ae35 100644 --- a/w2c2/c.c +++ b/w2c2/c.c @@ -828,10 +828,8 @@ WARN_UNUSED_RESULT wasmCWriteLocalGetExpr( const WasmCFunctionWriter* writer ) { - static const WasmOpcode opcode = wasmOpcodeLocalGet; - WasmLocalInstruction instruction; - if (!wasmLocalInstructionRead(writer->code, opcode, &instruction)) { + if (!wasmLocalInstructionRead(writer->code, &instruction)) { fprintf(stderr, "w2c2: invalid local.get instruction encoding\n"); return false; } @@ -876,7 +874,7 @@ wasmCWriteLocalAssignmentExpr( const WasmOpcode opcode ) { WasmLocalInstruction instruction; - if (!wasmLocalInstructionRead(writer->code, opcode, &instruction)) { + if (!wasmLocalInstructionRead(writer->code, &instruction)) { fprintf( stderr, "w2c2: invalid %s instruction encoding\n", @@ -930,7 +928,7 @@ wasmCWriteGlobalGetExpr( static const WasmOpcode opcode = wasmOpcodeGlobalGet; WasmGlobalInstruction instruction; - if (!wasmGlobalInstructionRead(writer->code, opcode, &instruction)) { + if (!wasmGlobalInstructionRead(writer->code, &instruction)) { fprintf( stderr, "w2c2: invalid %s instruction encoding\n", @@ -980,7 +978,7 @@ wasmCWriteGlobalSetExpr( static const WasmOpcode opcode = wasmOpcodeGlobalSet; WasmGlobalInstruction instruction; - if (!wasmGlobalInstructionRead(writer->code, opcode, &instruction)) { + if (!wasmGlobalInstructionRead(writer->code, &instruction)) { fprintf( stderr, "w2c2: invalid %s instruction encoding\n", @@ -1131,7 +1129,7 @@ wasmCWriteLoadExpr( ) { WasmLoadStoreInstruction instruction; - if (!wasmLoadStoreInstructionRead(writer->code, opcode, &instruction)) { + if (!wasmLoadStoreInstructionRead(writer->code, &instruction)) { fprintf(stderr, "w2c2: invalid load instruction encoding\n"); return false; } @@ -1260,7 +1258,7 @@ wasmCWriteStoreExpr( const WasmOpcode opcode ) { WasmLoadStoreInstruction instruction; - if (!wasmLoadStoreInstructionRead(writer->code, opcode, &instruction)) { + if (!wasmLoadStoreInstructionRead(writer->code, &instruction)) { fprintf(stderr, "w2c2: invalid store instruction encoding\n"); return false; } @@ -1356,10 +1354,8 @@ WARN_UNUSED_RESULT wasmCWriteMemorySize( const WasmCFunctionWriter* writer ) { - static const WasmOpcode opcode = wasmOpcodeMemorySize; - WasmMemoryInstruction instruction; - if (!wasmMemoryInstructionRead(writer->code, opcode, &instruction)) { + if (!wasmMemoryInstructionRead(writer->code, &instruction)) { fprintf(stderr, "w2c2: invalid memory.size instruction encoding\n"); return false; } @@ -1411,10 +1407,8 @@ WARN_UNUSED_RESULT wasmCWriteMemoryGrow( const WasmCFunctionWriter* writer ) { - static const WasmOpcode opcode = wasmOpcodeMemoryGrow; - WasmMemoryInstruction instruction; - if (!wasmMemoryInstructionRead(writer->code, opcode, &instruction)) { + if (!wasmMemoryInstructionRead(writer->code, &instruction)) { fprintf(stderr, "w2c2: invalid memory.grow instruction encoding\n"); return false; } @@ -1551,8 +1545,8 @@ wasmCWriteMemoryFill( const WasmCFunctionWriter* writer, const WasmMiscOpcode miscOpcode ) { - WasmMiscMemoryInstruction instruction; - if (!wasmMiscMemoryInstructionRead(writer->code, miscOpcode, &instruction)) { + WasmMemoryInstruction instruction; + if (!wasmMemoryInstructionRead(writer->code, &instruction)) { fprintf(stderr, "w2c2: invalid memory.fill instruction encoding\n"); return false; } @@ -2286,10 +2280,8 @@ WARN_UNUSED_RESULT wasmCWriteBranchExpr( const WasmCFunctionWriter* writer ) { - static const WasmOpcode opcode = wasmOpcodeBr; - WasmBranchInstruction instruction; - if (!wasmBranchInstructionRead(writer->code, opcode, &instruction)) { + if (!wasmBranchInstructionRead(writer->code, &instruction)) { fprintf(stderr, "w2c2: invalid br instruction encoding\n"); return false; } @@ -2308,10 +2300,8 @@ WARN_UNUSED_RESULT wasmCWriteBranchIfExpr( WasmCFunctionWriter* writer ) { - static const WasmOpcode opcode = wasmOpcodeBrIf; - WasmBranchInstruction instruction; - if (!wasmBranchInstructionRead(writer->code, opcode, &instruction)) { + if (!wasmBranchInstructionRead(writer->code, &instruction)) { fprintf(stderr, "w2c2: invalid br.if instruction encoding\n"); return false; } @@ -3614,7 +3604,7 @@ wasmCWriteConstantExpr( } case wasmOpcodeGlobalGet: { WasmGlobalInstruction instruction; - MUST (wasmGlobalInstructionRead(&code, opcode, &instruction)) + MUST (wasmGlobalInstructionRead(&code, &instruction)) MUST (wasmCWriteStringGlobalUse(builder, module, instruction.globalIndex, false)) break; } @@ -4860,19 +4850,19 @@ wasmCImplementationWriterThread( } { - WasmCImplementationWriterTask* task = writer->task; + const WasmCImplementationWriterTask* task = writer->task; const WasmModule* module = task->module; const char* moduleName = task->moduleName; const char* headerName = task->headerName; - char filePrefix = task->filePrefix; - U32 fileIndex = task->fileIndex; - U32 functionsPerFile = task->functionsPerFile; - U32 startFunctionIDIndex = task->startFunctionIDIndex; - WasmFunctionIDs functionIDs = task->functionIDs; - bool pretty = task->pretty; - bool debug = task->debug; - bool multipleModules = task->multipleModules; + const char filePrefix = task->filePrefix; + const U32 fileIndex = task->fileIndex; + const U32 functionsPerFile = task->functionsPerFile; + const U32 startFunctionIDIndex = task->startFunctionIDIndex; + const WasmFunctionIDs functionIDs = task->functionIDs; + const bool pretty = task->pretty; + const bool debug = task->debug; + const bool multipleModules = task->multipleModules; WasmDebugLines* debugLines = task->debugLines; writer->task = NULL; @@ -4880,7 +4870,7 @@ wasmCImplementationWriterThread( pthread_mutex_unlock(&writer->mutex); { - bool result = wasmCWriteImplementationFile( + const bool result = wasmCWriteImplementationFile( module, moduleName, headerName, @@ -4895,7 +4885,7 @@ wasmCImplementationWriterThread( multipleModules ); if (!result) { - WasmFunctionID startFunctionID = functionIDs.functionIDs[startFunctionIDIndex]; + const WasmFunctionID startFunctionID = functionIDs.functionIDs[startFunctionIDIndex]; fprintf( stderr, "w2c2: failed to write implementation file %d. start function index: %d\n", diff --git a/w2c2/instruction.c b/w2c2/instruction.c index b722800..cc32f9b 100644 --- a/w2c2/instruction.c +++ b/w2c2/instruction.c @@ -5,13 +5,11 @@ bool wasmLocalInstructionRead( Buffer* buffer, - const WasmOpcode opcode, WasmLocalInstruction* result ) { U32 localIndex = 0; MUST (leb128ReadU32(buffer, &localIndex) > 0) - result->opcode = opcode; result->localIndex = localIndex; return true; @@ -22,13 +20,11 @@ wasmLocalInstructionRead( bool wasmGlobalInstructionRead( Buffer* buffer, - const WasmOpcode opcode, WasmGlobalInstruction* result ) { U32 globalIndex = 0; MUST (leb128ReadU32(buffer, &globalIndex) > 0) - result->opcode = opcode; result->globalIndex = globalIndex; return true; @@ -42,7 +38,6 @@ wasmConstInstructionRead( const WasmOpcode opcode, WasmConstInstruction* result ) { - result->opcode = opcode; switch (opcode) { case wasmOpcodeI32Const: return leb128ReadI32(buffer, &result->value.i32) > 0; @@ -62,7 +57,6 @@ wasmConstInstructionRead( bool wasmLoadStoreInstructionRead( Buffer* buffer, - const WasmOpcode opcode, WasmLoadStoreInstruction* result ) { U32 align = 0; @@ -71,7 +65,6 @@ wasmLoadStoreInstructionRead( MUST (leb128ReadU32(buffer, &align) > 0) MUST (leb128ReadU32(buffer, &offset) > 0) - result->opcode = opcode; result->align = align; result->offset = offset; @@ -117,13 +110,11 @@ wasmCallIndirectInstructionRead( bool wasmBranchInstructionRead( Buffer* buffer, - const WasmOpcode opcode, WasmBranchInstruction* result ) { U32 labelIndex = 0; MUST(leb128ReadU32(buffer, &labelIndex) > 0) - result->opcode = opcode; result->labelIndex = labelIndex; return true; @@ -171,31 +162,11 @@ wasmBranchTableInstructionFree( bool wasmMemoryInstructionRead( Buffer* buffer, - const WasmOpcode opcode, WasmMemoryInstruction* result ) { U32 memoryIndex = 0; MUST(leb128ReadU32(buffer, &memoryIndex) > 0) - result->opcode = opcode; - result->memoryIndex = memoryIndex; - - return true; -} - -/* WasmMiscMemoryInstruction */ - -bool -WARN_UNUSED_RESULT -wasmMiscMemoryInstructionRead( - Buffer* buffer, - const WasmMiscOpcode opcode, - WasmMiscMemoryInstruction* result -) { - U32 memoryIndex = 0; - MUST(leb128ReadU32(buffer, &memoryIndex) > 0) - - result->opcode = opcode; result->memoryIndex = memoryIndex; return true; @@ -219,4 +190,3 @@ wasmMemoryCopyInstructionRead( return true; } - diff --git a/w2c2/instruction.h b/w2c2/instruction.h index bba6b68..2d33ea6 100644 --- a/w2c2/instruction.h +++ b/w2c2/instruction.h @@ -8,7 +8,6 @@ /* WasmLocalInstruction */ typedef struct WasmLocalInstruction { - WasmOpcode opcode; U32 localIndex; } WasmLocalInstruction; @@ -16,14 +15,12 @@ bool WARN_UNUSED_RESULT wasmLocalInstructionRead( Buffer* buffer, - WasmOpcode opcode, WasmLocalInstruction* result ); /* WasmGlobalInstruction */ typedef struct WasmGlobalInstruction { - WasmOpcode opcode; U32 globalIndex; } WasmGlobalInstruction; @@ -31,7 +28,6 @@ bool WARN_UNUSED_RESULT wasmGlobalInstructionRead( Buffer* buffer, - WasmOpcode opcode, WasmGlobalInstruction* result ); @@ -45,7 +41,6 @@ typedef union WasmValue { } WasmValue; typedef struct WasmConstInstruction { - WasmOpcode opcode; WasmValue value; } WasmConstInstruction; @@ -60,7 +55,6 @@ wasmConstInstructionRead( /* WasmLoadStoreInstruction */ typedef struct WasmLoadStoreInstruction { - WasmOpcode opcode; U32 align; U32 offset; } WasmLoadStoreInstruction; @@ -69,7 +63,6 @@ bool WARN_UNUSED_RESULT wasmLoadStoreInstructionRead( Buffer* buffer, - WasmOpcode opcode, WasmLoadStoreInstruction* result ); @@ -103,7 +96,6 @@ wasmCallIndirectInstructionRead( /* WasmBranchInstruction */ typedef struct WasmBranchInstruction { - WasmOpcode opcode; U32 labelIndex; } WasmBranchInstruction; @@ -111,7 +103,6 @@ bool WARN_UNUSED_RESULT wasmBranchInstructionRead( Buffer* buffer, - WasmOpcode opcode, WasmBranchInstruction* result ); @@ -138,7 +129,6 @@ wasmBranchTableInstructionRead( /* WasmMemoryInstruction */ typedef struct WasmMemoryInstruction { - WasmOpcode opcode; U32 memoryIndex; } WasmMemoryInstruction; @@ -146,25 +136,9 @@ bool WARN_UNUSED_RESULT wasmMemoryInstructionRead( Buffer* buffer, - WasmOpcode opcode, WasmMemoryInstruction* result ); -/* WasmMiscMemoryInstruction */ - -typedef struct WasmMiscMemoryInstruction { - WasmMiscOpcode opcode; - U32 memoryIndex; -} WasmMiscMemoryInstruction; - -bool -WARN_UNUSED_RESULT -wasmMiscMemoryInstructionRead( - Buffer* buffer, - WasmMiscOpcode opcode, - WasmMiscMemoryInstruction* result -); - /* WasmMemoryCopyInstruction */ typedef struct WasmMemoryCopyInstruction { diff --git a/w2c2/main.c b/w2c2/main.c index d573ad3..6a2609f 100644 --- a/w2c2/main.c +++ b/w2c2/main.c @@ -203,7 +203,7 @@ cleanImplementationFiles(void) { #if HAS_GLOB glob_t globbuf; size_t pathIndex = 0; - int globResult = glob("*.c", GLOB_NOSORT, NULL, &globbuf); + const int globResult = glob("*.c", GLOB_NOSORT, NULL, &globbuf); if (globResult != 0) { if (globResult != GLOB_NOMATCH) { fprintf(stderr, "w2c2: failed to glob files to clean\n"); diff --git a/w2c2/reader.c b/w2c2/reader.c index 294a541..2610d8b 100644 --- a/w2c2/reader.c +++ b/w2c2/reader.c @@ -1088,7 +1088,7 @@ wasmReadConstantExpr( } case wasmOpcodeGlobalGet: { WasmGlobalInstruction instruction; - MUST (wasmGlobalInstructionRead(buffer, opcode, &instruction)) + MUST (wasmGlobalInstructionRead(buffer, &instruction)) break; } case wasmOpcodeEnd: