diff --git a/cmd/wuffs-c/internal/cgen/base-impl.h b/cmd/wuffs-c/internal/cgen/base/base-private.h similarity index 99% rename from cmd/wuffs-c/internal/cgen/base-impl.h rename to cmd/wuffs-c/internal/cgen/base/base-private.h index adb06159..4c8c0edd 100644 --- a/cmd/wuffs-c/internal/cgen/base-impl.h +++ b/cmd/wuffs-c/internal/cgen/base/base-private.h @@ -1,4 +1,4 @@ -// After editing this file, run "go generate" in this directory. +// After editing this file, run "go generate" in the parent directory. // Copyright 2017 The Wuffs Authors. // diff --git a/cmd/wuffs-c/internal/cgen/base-header.h b/cmd/wuffs-c/internal/cgen/base/base-public.h similarity index 99% rename from cmd/wuffs-c/internal/cgen/base-header.h rename to cmd/wuffs-c/internal/cgen/base/base-public.h index edfcd710..4621a5eb 100644 --- a/cmd/wuffs-c/internal/cgen/base-header.h +++ b/cmd/wuffs-c/internal/cgen/base/base-public.h @@ -1,4 +1,4 @@ -// After editing this file, run "go generate" in this directory. +// After editing this file, run "go generate" in the parent directory. #ifndef WUFFS_BASE_HEADER_H #define WUFFS_BASE_HEADER_H diff --git a/cmd/wuffs-c/internal/cgen/cgen.go b/cmd/wuffs-c/internal/cgen/cgen.go index 4af7d435..b86c80fa 100644 --- a/cmd/wuffs-c/internal/cgen/cgen.go +++ b/cmd/wuffs-c/internal/cgen/cgen.go @@ -226,7 +226,7 @@ func (g *gen) genHeader(b *buffer) error { b.printf("#ifndef %s\n#define %s\n\n", includeGuard, includeGuard) b.printf("// Code generated by wuffs-c. DO NOT EDIT.\n\n") - b.writes(baseHeader) + b.writes(basePublicH) b.writeb('\n') b.writes("// ---------------- Use Declarations\n\n") @@ -304,7 +304,7 @@ func (g *gen) genHeader(b *buffer) error { func (g *gen) genImpl(b *buffer) error { b.writes("#ifndef WUFFS_BASE_IMPL_H\n#define WUFFS_BASE_IMPL_H\n\n") - b.writes(baseImpl) + b.writes(basePrivateH) b.writes("\n") b.printf("static const char* wuffs_base__status__strings[%d] = {\n", len(builtin.StatusList)) for _, z := range builtin.StatusList { diff --git a/cmd/wuffs-c/internal/cgen/data.go b/cmd/wuffs-c/internal/cgen/data.go index f5a12f46..ff222a4a 100644 --- a/cmd/wuffs-c/internal/cgen/data.go +++ b/cmd/wuffs-c/internal/cgen/data.go @@ -16,7 +16,7 @@ package cgen -const baseHeader = "" + +const basePublicH = "" + "#ifndef WUFFS_BASE_HEADER_H\n#define WUFFS_BASE_HEADER_H\n\n// Copyright 2017 The Wuffs Authors.\n//\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// https://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\n#include \n#include \n#include \n\n// Wuffs assumes that:\n// - converting a uint32_t to a size_t will never overflow.\n// - converting a size_t to a uint64_t will never overflow.\n#if (__WORDSIZE != 32) && (__WORDSIZE != 64)\n#error \"Wuffs requires a word size of either 32 or 64 bits\"\n#endif\n\n// WUFFS_VERSION is the major.minor.patch version, " + "as per https://semver.org/,\n// as a uint64_t. The major number is the high 32 bits. The minor number is the\n// middle 16 bits. The patch number is the low 16 bits. The version extension\n// (such as \"\", \"beta\" or \"rc.1\") is part of the string representation (such as\n// \"1.2.3-beta\") but not the uint64_t representation.\n//\n// All three of major, minor and patch being zero means that this is a\n// work-in-progress version, not a release version, and has no backwards or\n// forwards compatibility guarantees.\n//\n// !! Some code generation programs can override WUFFS_VERSION.\n#define WUFFS_VERSION ((uint64_t)0)\n#define WUFFS_VERSION_MAJOR ((uint64_t)0)\n#define WUFFS_VERSION_MINOR ((uint64_t)0)\n#define WUFFS_VERSION_PATCH ((uint64_t)0)\n#define WUFFS_VERSION_EXTENSION \"\"\n#define WUFFS_VERSION_STRING \"0.0.0\"\n\n// wuffs_base__empty_struct is used when a Wuffs function returns an empty\n// struct. In C, if a function f returns void, you can't say \"x = f()\", but in\n// Wuffs, if a function g returns empty, you can say \"y = g(" + ")\".\ntypedef struct {\n} wuffs_base__empty_struct;\n\n" + @@ -90,7 +90,7 @@ const baseHeader = "" + "base__image_buffer__palette returns the palette that the pixel data\n// can index. The backing array is inside b and has length 1024.\nstatic inline wuffs_base__slice_u8 wuffs_base__image_buffer__palette(\n wuffs_base__image_buffer* b) {\n return b ? ((wuffs_base__slice_u8){.ptr = b->private_impl.palette,\n .len = 1024})\n : ((wuffs_base__slice_u8){});\n}\n\nstatic inline wuffs_base__table_u8 wuffs_base__image_buffer__plane(\n wuffs_base__image_buffer* b,\n uint32_t p) {\n return (b && (p < WUFFS_BASE__PIXEL_FORMAT__NUM_PLANES_MAX))\n ? b->private_impl.pixbuf.planes[p]\n : ((wuffs_base__table_u8){});\n}\n\n#endif // WUFFS_BASE_HEADER_H\n" + "" -const baseImpl = "" + +const basePrivateH = "" + "// Copyright 2017 The Wuffs Authors.\n//\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// https://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\nstatic inline wuffs_base__empty_struct wuffs_base__return_empty_struct() {\n return ((wuffs_base__empty_struct){});\n}\n\n#define WUFFS_BASE__IGNORE_POTENTIALLY_UNUSED_VARIABLE(x) (void)(x)\n\n// WUFFS_BASE__MAGIC is a magic number to check that initializers are called.\n// It's not foolproof, given C doesn't automatically zero memory before use,\n// but it should catch 99.99% of cases.\n//\n// Its (non-zero) value is arbitrary, base" + "d on md5sum(\"wuffs\").\n#define WUFFS_BASE__MAGIC ((uint32_t)0x3CCB6C71)\n\n// Denote intentional fallthroughs for -Wimplicit-fallthrough.\n//\n// The order matters here. Clang also defines \"__GNUC__\".\n#if defined(__clang__) && __cplusplus >= 201103L\n#define WUFFS_BASE__FALLTHROUGH [[clang::fallthrough]]\n#elif !defined(__clang__) && defined(__GNUC__) && (__GNUC__ >= 7)\n#define WUFFS_BASE__FALLTHROUGH __attribute__((fallthrough))\n#else\n#define WUFFS_BASE__FALLTHROUGH\n#endif\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 trivial macros instead of an explicit assignment and case statement\n// so that clang-format doesn't get confused by the unusual \"case\"s.\n#define WUFFS_BASE__COROUTINE_SUSPENSION_POINT_0 case 0:;\n#define WUFFS_BASE__COROUTINE_SUSPENSION_POINT(n) \\\n coro_susp_point = n; \\\n WUFFS_BASE__FALLTHROUGH; \\\n case n:;\n\n#define WUFFS_BASE__COROUTINE_" + "SUSPENSION_POINT_MAYBE_SUSPEND(n) \\\n if (status < 0) { \\\n goto exit; \\\n } else if (status == 0) { \\\n goto ok; \\\n } \\\n coro_susp_point = n; \\\n goto suspend; \\\n case n:;\n\n// Clang also defines \"__GNUC__\".\n#if defined(__GNUC__)\n#define WUFFS_BASE__LIKELY(expr) (__builtin_expect(!!(expr), 1))\n#define WUFFS_BASE__UNLIKELY(expr) (__builtin_expect(!!(expr), 0))\n#else\n#define WUFFS_BASE__LIKELY(expr) (expr)\n#define WUFFS_BASE__UNLIKELY(expr) (expr)\n#endif\n\n// Uncomment this #include for printf-debugging.\n// #include \n\n// The helpers below are functions, instead of macros, because their arguments\n// can be an expression that we shouldn't evaluate more than once.\n//\n// They a" + diff --git a/cmd/wuffs-c/internal/cgen/gen.go b/cmd/wuffs-c/internal/cgen/gen.go index 88839f6c..86fb2a44 100644 --- a/cmd/wuffs-c/internal/cgen/gen.go +++ b/cmd/wuffs-c/internal/cgen/gen.go @@ -79,8 +79,8 @@ func genBase(out *bytes.Buffer) error { files := []struct { filename, varname string }{ - {"base-header.h", "baseHeader"}, - {"base-impl.h", "baseImpl"}, + {"base/base-public.h", "basePublicH"}, + {"base/base-private.h", "basePrivateH"}, } for _, f := range files {