MCPcopy Create free account
hub / github.com/WasmEdge/WasmEdge / to_cpp_header

Function to_cpp_header

utils/wasi-cpp-header/src/cpp_header.rs:7–79  ·  view source on GitHub ↗
(doc: &Document, inputs_str: &str)

Source from the content-addressed store, hash-verified

5use witx::*;
6
7pub fn to_cpp_header(doc: &Document, inputs_str: &str) -> String {
8 let mut ret = String::new();
9
10 ret.push_str(&format!(
11 r#"// SPDX-License-Identifier: Apache-2.0
12// SPDX-FileCopyrightText: 2019-2024 Second State INC
13
14/**
15 * THIS FILE IS AUTO-GENERATED from the following files:
16 * {}
17 *
18 * @file
19 * This file describes the [WASI] interface, consisting of functions, types,
20 * and defined values (macros).
21 *
22 * The interface described here is greatly inspired by [CloudABI]'s clean,
23 * thoughtfully-designed, capability-oriented, POSIX-style API.
24 *
25 * [CloudABI]: https://github.com/NuxiNL/cloudlibc
26 * [WASI]: https://github.com/WebAssembly/WASI/
27 */
28
29#pragma once
30
31#include <cstddef>
32#include <cstdint>
33#include <type_traits>
34
35using const_uint8_t_ptr = uint32_t;
36using uint8_t_ptr = uint32_t;
37
38#define DEFINE_ENUM_OPERATORS(type) \
39 inline constexpr type operator~(type a) noexcept {{ \
40 return static_cast<type>(~static_cast<std::underlying_type_t<type>>(a)); \
41 }} \
42 inline constexpr type operator|(type a, type b) noexcept {{ \
43 return static_cast<type>(static_cast<std::underlying_type_t<type>>(a) | \
44 static_cast<std::underlying_type_t<type>>(b)); \
45 }} \
46 inline constexpr type &operator|=(type &a, type b) noexcept {{ \
47 a = a | b; \
48 return a; \
49 }} \
50 inline constexpr type operator&(type a, type b) noexcept {{ \
51 return static_cast<type>(static_cast<std::underlying_type_t<type>>(a) & \
52 static_cast<std::underlying_type_t<type>>(b)); \
53 }} \
54 inline constexpr type &operator&=(type &a, type b) noexcept {{ \
55 a = a & b; \
56 return a; \
57 }}
58
59static_assert(alignof(int8_t) == 1, "non-wasi data layout");
60static_assert(alignof(uint8_t) == 1, "non-wasi data layout");
61static_assert(alignof(int16_t) == 2, "non-wasi data layout");
62static_assert(alignof(uint16_t) == 2, "non-wasi data layout");
63static_assert(alignof(int32_t) == 4, "non-wasi data layout");
64static_assert(alignof(uint32_t) == 4, "non-wasi data layout");

Callers 1

generateFunction · 0.85

Calls 1

print_datatypeFunction · 0.85

Tested by

no test coverage detected