Fix the '-p' command-line switch
authorChristopher Gautier <christopher.gautier@arm.com>
Sun, 21 Jun 2015 15:20:05 +0000 (17:20 +0200)
committerChristopher Gautier <christopher.gautier@arm.com>
Mon, 24 Aug 2015 10:57:57 +0000 (12:57 +0200)
tools/dis/dis.cpp

index 5555073..7d606f3 100644 (file)
@@ -114,16 +114,17 @@ int main(int argc, char **argv) {
   error = spvExtInstTableGet(&extInstTable);
   spvCheck(error, fprintf(stderr, "error: Internal malfunction.\n"));
 
+  bool option_print = spvIsInBitfield(SPV_BINARY_TO_TEXT_OPTION_PRINT, options);
   spv_text text;
   spv_diagnostic diagnostic = nullptr;
   error = spvBinaryToText(&binary, options, opcodeTable, operandTable,
-                          extInstTable, &text, &diagnostic);
+                          extInstTable,
+                          option_print ? NULL : &text,
+                          &diagnostic);
   spvCheck(error, spvDiagnosticPrint(diagnostic);
            spvDiagnosticDestroy(diagnostic); return error);
 
-  if (spvIsInBitfield(SPV_BINARY_TO_TEXT_OPTION_PRINT, options)) {
-    printf("%s", text->str);
-  } else {
+  if (!option_print) {
     if (FILE *fp = fopen(outFile, "w")) {
       size_t written = fwrite(text->str, sizeof(char), (size_t)text->length, fp);
       if (text->length != written) {
@@ -138,7 +139,5 @@ int main(int argc, char **argv) {
     }
   }
 
-  spvTextDestroy(text);
-
   return 0;
 }