mirror of
https://github.com/ddidderr/wuffs.git
synced 2026-11-17 16:32:11 +01:00
Add PUFFS_IGNORE_POTENTIALLY_UNUSED_VARIABLE.
This commit is contained in:
1 parent
18e32d61e5
commit
fda696bf95
6 files changed
+16
-20
No files matched your search
@@ -6,6 +6,8 @@
|
||||
// Use of this source code is governed by a BSD-style license that can be found
|
||||
// in the LICENSE file.
|
||||
|
||||
#define PUFFS_IGNORE_POTENTIALLY_UNUSED_VARIABLE(x) (void)(x)
|
||||
|
||||
// TODO: look for (ifdef) the x86 architecture and cast the pointer? Only do so
|
||||
// if a benchmark justifies the additional code path.
|
||||
#define PUFFS_U16BE(p) (((uint16_t)(p[0]) << 8) | ((uint16_t)(p[1]) << 0))
|
||||
|
||||
@@ -12,8 +12,8 @@ const baseHeader = "" +
|
||||
""
|
||||
|
||||
const baseImpl = "" +
|
||||
"#ifndef PUFFS_BASE_IMPL_H\n#define PUFFS_BASE_IMPL_H\n\n// Use of this source code is governed by a BSD-style license that can be found\n// in the LICENSE file.\n\n// TODO: look for (ifdef) the x86 architecture and cast the pointer? Only do so\n// if a benchmark justifies the additional code path.\n#define PUFFS_U16BE(p) (((uint16_t)(p[0]) << 8) | ((uint16_t)(p[1]) << 0))\n#define PUFFS_U16LE(p) (((uint16_t)(p[0]) << 0) | ((uint16_t)(p[1]) << 8))\n#define PUFFS_U32BE(p) \\\n (((uint32_t)(p[0]) << 24) | ((uint32_t)(p[1]) << 16) | \\\n ((uint32_t)(p[2]) << 8) | ((uint32_t)(p[3]) << 0))\n#define PUFFS_U32LE(p) \\\n (((uint32_t)(p[0]) << 0) | ((uint32_t)(p[1]) << 8) | \\\n ((uint32_t)(p[2]) << 16) | ((uint32_t)(p[3]) << 24))\n\n// Use switch cases for coroutine suspension points, similar to the technique\n// in https://www.chiark.greenend.org.uk/~sgtatham/coroutines.html\n//\n// We use a trivial macro instead of an explicit assignment and case statement\n// so that c" +
|
||||
"lang-format doesn't get confused by the unusual \"case\"s.\n#define PUFFS_COROUTINE_SUSPENSION_POINT(n) \\\n coro_susp_point = n; \\\n case n:\n\n// Clang also defines \"__GNUC__\".\n#if defined(__GNUC__)\n#define PUFFS_LIKELY(expr) (__builtin_expect(!!(expr), 1))\n#define PUFFS_UNLIKELY(expr) (__builtin_expect(!!(expr), 0))\n// Declare the printf prototype. The generated code shouldn't need this at all,\n// but it's useful for manual printf debugging.\nextern int printf(const char* __restrict __format, ...);\n#else\n#define PUFFS_LIKELY(expr) (expr)\n#define PUFFS_UNLIKELY(expr) (expr)\n#endif\n\n#endif // PUFFS_BASE_IMPL_H\n" +
|
||||
"#ifndef PUFFS_BASE_IMPL_H\n#define PUFFS_BASE_IMPL_H\n\n// Use of this source code is governed by a BSD-style license that can be found\n// in the LICENSE file.\n\n#define PUFFS_IGNORE_POTENTIALLY_UNUSED_VARIABLE(x) (void)(x)\n\n// TODO: look for (ifdef) the x86 architecture and cast the pointer? Only do so\n// if a benchmark justifies the additional code path.\n#define PUFFS_U16BE(p) (((uint16_t)(p[0]) << 8) | ((uint16_t)(p[1]) << 0))\n#define PUFFS_U16LE(p) (((uint16_t)(p[0]) << 0) | ((uint16_t)(p[1]) << 8))\n#define PUFFS_U32BE(p) \\\n (((uint32_t)(p[0]) << 24) | ((uint32_t)(p[1]) << 16) | \\\n ((uint32_t)(p[2]) << 8) | ((uint32_t)(p[3]) << 0))\n#define PUFFS_U32LE(p) \\\n (((uint32_t)(p[0]) << 0) | ((uint32_t)(p[1]) << 8) | \\\n ((uint32_t)(p[2]) << 16) | ((uint32_t)(p[3]) << 24))\n\n// Use switch cases for coroutine suspension points, similar to the technique\n// in https://www.chiark.greenend.org.uk/~sgtatham/coroutines.html\n//\n// We use a trivial macro in" +
|
||||
"stead of an explicit assignment and case statement\n// so that clang-format doesn't get confused by the unusual \"case\"s.\n#define PUFFS_COROUTINE_SUSPENSION_POINT(n) \\\n coro_susp_point = n; \\\n case n:\n\n// Clang also defines \"__GNUC__\".\n#if defined(__GNUC__)\n#define PUFFS_LIKELY(expr) (__builtin_expect(!!(expr), 1))\n#define PUFFS_UNLIKELY(expr) (__builtin_expect(!!(expr), 0))\n// Declare the printf prototype. The generated code shouldn't need this at all,\n// but it's useful for manual printf debugging.\nextern int printf(const char* __restrict __format, ...);\n#else\n#define PUFFS_LIKELY(expr) (expr)\n#define PUFFS_UNLIKELY(expr) (expr)\n#endif\n\n#endif // PUFFS_BASE_IMPL_H\n" +
|
||||
""
|
||||
|
||||
type template_args_short_read struct {
|
||||
|
||||
@@ -199,8 +199,7 @@ func (g *gen) writeStatement(b *buffer, n *a.Node, depth uint32) error {
|
||||
|
||||
// TODO: remove this.
|
||||
if n.XType().Decorator().Key() == t.KeyColon {
|
||||
b.printf("\n/* Avoid the \"unused variable\" warning. */\n")
|
||||
b.printf("if (%s%s.ptr) {}\n", vPrefix, n.Name().String(g.tm))
|
||||
b.printf("PUFFS_IGNORE_POTENTIALLY_UNUSED_VARIABLE(%s%s);\n", vPrefix, n.Name().String(g.tm))
|
||||
}
|
||||
}
|
||||
return nil
|
||||
|
||||
@@ -149,8 +149,7 @@ func (g *gen) writeSaveDerivedVar(b *buffer, name t.ID, typ *a.TypeExpr) error {
|
||||
b.printf("}")
|
||||
|
||||
// Not all writer1 methods use the wend variable.
|
||||
b.printf("\n/* Avoid the \"unused variable\" warning. */\n")
|
||||
b.printf("(void)(%swend_%s);", bPrefix, nameStr)
|
||||
b.printf("PUFFS_IGNORE_POTENTIALLY_UNUSED_VARIABLE(%swend_%s);", bPrefix, nameStr)
|
||||
|
||||
b.printf("}\n")
|
||||
}
|
||||
|
||||
+7
-12
@@ -290,6 +290,8 @@ puffs_flate_status puffs_flate_zlib_decoder_decode(
|
||||
// Use of this source code is governed by a BSD-style license that can be found
|
||||
// in the LICENSE file.
|
||||
|
||||
#define PUFFS_IGNORE_POTENTIALLY_UNUSED_VARIABLE(x) (void)(x)
|
||||
|
||||
// TODO: look for (ifdef) the x86 architecture and cast the pointer? Only do so
|
||||
// if a benchmark justifies the additional code path.
|
||||
#define PUFFS_U16BE(p) (((uint16_t)(p[0]) << 8) | ((uint16_t)(p[1]) << 0))
|
||||
@@ -567,8 +569,7 @@ puffs_flate_status puffs_flate_decoder_decode(puffs_flate_decoder* self,
|
||||
*lim->ptr_to_len -= n;
|
||||
}
|
||||
}
|
||||
/* Avoid the "unused variable" warning. */
|
||||
(void)(b_wend_dst);
|
||||
PUFFS_IGNORE_POTENTIALLY_UNUSED_VARIABLE(b_wend_dst);
|
||||
}
|
||||
puffs_flate_status t_0 =
|
||||
puffs_flate_decoder_decode_blocks(self, a_dst, a_src);
|
||||
@@ -587,10 +588,7 @@ puffs_flate_status puffs_flate_decoder_decode(puffs_flate_decoder* self,
|
||||
if (v_z > 0) {
|
||||
v_written = ((puffs_base_slice_u8){.ptr = a_dst.buf->ptr,
|
||||
.len = b_wptr_dst - a_dst.buf->ptr});
|
||||
|
||||
/* Avoid the "unused variable" warning. */
|
||||
if (v_written.ptr) {
|
||||
}
|
||||
PUFFS_IGNORE_POTENTIALLY_UNUSED_VARIABLE(v_written);
|
||||
}
|
||||
status = v_z;
|
||||
goto suspend;
|
||||
@@ -614,8 +612,7 @@ exit:
|
||||
*lim->ptr_to_len -= n;
|
||||
}
|
||||
}
|
||||
/* Avoid the "unused variable" warning. */
|
||||
(void)(b_wend_dst);
|
||||
PUFFS_IGNORE_POTENTIALLY_UNUSED_VARIABLE(b_wend_dst);
|
||||
}
|
||||
|
||||
self->private_impl.status = status;
|
||||
@@ -919,8 +916,7 @@ exit:
|
||||
*lim->ptr_to_len -= n;
|
||||
}
|
||||
}
|
||||
/* Avoid the "unused variable" warning. */
|
||||
(void)(b_wend_dst);
|
||||
PUFFS_IGNORE_POTENTIALLY_UNUSED_VARIABLE(b_wend_dst);
|
||||
}
|
||||
if (a_src.buf) {
|
||||
size_t n = b_rptr_src - (a_src.buf->ptr + a_src.buf->ri);
|
||||
@@ -1255,8 +1251,7 @@ exit:
|
||||
*lim->ptr_to_len -= n;
|
||||
}
|
||||
}
|
||||
/* Avoid the "unused variable" warning. */
|
||||
(void)(b_wend_dst);
|
||||
PUFFS_IGNORE_POTENTIALLY_UNUSED_VARIABLE(b_wend_dst);
|
||||
}
|
||||
if (a_src.buf) {
|
||||
size_t n = b_rptr_src - (a_src.buf->ptr + a_src.buf->ri);
|
||||
|
||||
+3
-2
@@ -263,6 +263,8 @@ puffs_gif_status puffs_gif_lzw_decoder_decode(puffs_gif_lzw_decoder* self,
|
||||
// Use of this source code is governed by a BSD-style license that can be found
|
||||
// in the LICENSE file.
|
||||
|
||||
#define PUFFS_IGNORE_POTENTIALLY_UNUSED_VARIABLE(x) (void)(x)
|
||||
|
||||
// TODO: look for (ifdef) the x86 architecture and cast the pointer? Only do so
|
||||
// if a benchmark justifies the additional code path.
|
||||
#define PUFFS_U16BE(p) (((uint16_t)(p[0]) << 8) | ((uint16_t)(p[1]) << 0))
|
||||
@@ -1288,8 +1290,7 @@ exit:
|
||||
*lim->ptr_to_len -= n;
|
||||
}
|
||||
}
|
||||
/* Avoid the "unused variable" warning. */
|
||||
(void)(b_wend_dst);
|
||||
PUFFS_IGNORE_POTENTIALLY_UNUSED_VARIABLE(b_wend_dst);
|
||||
}
|
||||
if (a_src.buf) {
|
||||
size_t n = b_rptr_src - (a_src.buf->ptr + a_src.buf->ri);
|
||||
|
||||
Reference in new issue
Block a user