diff --git a/cmd/puffs-gen-c/base-impl.h b/cmd/puffs-gen-c/base-impl.h index 28fe0d64..c363eb17 100644 --- a/cmd/puffs-gen-c/base-impl.h +++ b/cmd/puffs-gen-c/base-impl.h @@ -25,6 +25,9 @@ #if defined(__GNUC__) #define PUFFS_LIKELY(expr) (__builtin_expect(!!(expr), 1)) #define PUFFS_UNLIKELY(expr) (__builtin_expect(!!(expr), 0)) +// Declare the printf prototype. The generated code shouldn't need this at all, +// but it's useful for manual printf debugging. +extern int printf(const char* __restrict __format, ...); #else #define PUFFS_LIKELY(expr) (expr) #define PUFFS_UNLIKELY(expr) (expr) diff --git a/cmd/puffs-gen-c/data.go b/cmd/puffs-gen-c/data.go index ffbc0b5d..b00959c1 100644 --- a/cmd/puffs-gen-c/data.go +++ b/cmd/puffs-gen-c/data.go @@ -13,5 +13,5 @@ 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_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 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#else\n#define PUFFS_LIKELY(expr) (expr)\n#define PUFFS_UNLIKELY(expr) (expr)\n#endif\n\n#endif // PUFFS_BASE_IMPL_H\n" + + "!!(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" + "" diff --git a/gen/c/std/flate.c b/gen/c/std/flate.c index f98dbba5..b3de20d6 100644 --- a/gen/c/std/flate.c +++ b/gen/c/std/flate.c @@ -261,6 +261,9 @@ puffs_flate_status puffs_flate_decoder_decode(puffs_flate_decoder* self, #if defined(__GNUC__) #define PUFFS_LIKELY(expr) (__builtin_expect(!!(expr), 1)) #define PUFFS_UNLIKELY(expr) (__builtin_expect(!!(expr), 0)) +// Declare the printf prototype. The generated code shouldn't need this at all, +// but it's useful for manual printf debugging. +extern int printf(const char* __restrict __format, ...); #else #define PUFFS_LIKELY(expr) (expr) #define PUFFS_UNLIKELY(expr) (expr) diff --git a/gen/c/std/gif.c b/gen/c/std/gif.c index 30c8d73c..4d8b70d6 100644 --- a/gen/c/std/gif.c +++ b/gen/c/std/gif.c @@ -275,6 +275,9 @@ puffs_gif_status puffs_gif_lzw_decoder_decode(puffs_gif_lzw_decoder* self, #if defined(__GNUC__) #define PUFFS_LIKELY(expr) (__builtin_expect(!!(expr), 1)) #define PUFFS_UNLIKELY(expr) (__builtin_expect(!!(expr), 0)) +// Declare the printf prototype. The generated code shouldn't need this at all, +// but it's useful for manual printf debugging. +extern int printf(const char* __restrict __format, ...); #else #define PUFFS_LIKELY(expr) (expr) #define PUFFS_UNLIKELY(expr) (expr)