Skip to content

Commit 60564a0

Browse files
committed
Add a char8 type to represent data which is expected to be valid UTF-8.
This will allow the generated C header file to use [char8_t]. [char8_t]: https://en.cppreference.com/w/cpp/keyword/char8_t Fixes bytecodealliance#6.
1 parent 5158f0f commit 60564a0

File tree

11 files changed

+20
-9
lines changed

11 files changed

+20
-9
lines changed

phases/ephemeral/witx/wasi_ephemeral_args.witx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@
1212
;;; Read command-line argument data.
1313
;;; The size of the array should match that returned by `sizes_get`
1414
(@interface func (export "get")
15-
(param $argv (@witx pointer (@witx pointer u8)))
16-
(param $argv_buf (@witx pointer u8))
15+
(param $argv (@witx pointer (@witx pointer char8)))
16+
(param $argv_buf (@witx pointer char8))
1717
(result $error $errno)
1818
)
1919

phases/ephemeral/witx/wasi_ephemeral_environ.witx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@
1212
;;; Read environment variable data.
1313
;;; The sizes of the buffers should match that returned by `sizes_get`.
1414
(@interface func (export "get")
15-
(param $environ (@witx pointer (@witx pointer u8)))
16-
(param $environ_buf (@witx pointer u8))
15+
(param $environ (@witx pointer (@witx pointer char8)))
16+
(param $environ_buf (@witx pointer char8))
1717
(result $error $errno)
1818
)
1919

phases/ephemeral/witx/wasi_ephemeral_fd.witx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,7 @@
132132
(@interface func (export "prestat_dir_name")
133133
(param $fd $fd)
134134
;;; A buffer into which to write the preopened directory name.
135-
(param $path (@witx pointer u8))
135+
(param $path (@witx pointer char8))
136136
(param $path_len $size)
137137
(result $error $errno)
138138
)

phases/ephemeral/witx/wasi_ephemeral_path.witx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@
106106
;;; The path of the symbolic link from which to read.
107107
(param $path string)
108108
;;; The buffer to which to write the contents of the symbolic link.
109-
(param $buf (@witx pointer u8))
109+
(param $buf (@witx pointer char8))
110110
(param $buf_len $size)
111111
(result $error $errno)
112112
;;; The number of bytes placed in the buffer.

phases/ephemeral/witx/wasi_ephemeral_random.witx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
;;; number generator, rather than to provide the random data directly.
2020
(@interface func (export "get")
2121
;;; The buffer to fill with random data.
22-
(param $buf (@witx pointer u8))
22+
(param $buf (@witx pointer char8))
2323
(param $buf_len $size)
2424
(result $error $errno)
2525
)

tools/witx/src/ast.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -172,6 +172,7 @@ impl Type {
172172
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
173173
pub enum BuiltinType {
174174
String,
175+
Char8,
175176
U8,
176177
U16,
177178
U32,

tools/witx/src/coretypes.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,8 @@ impl Type {
4141
| BuiltinType::U32
4242
| BuiltinType::S8
4343
| BuiltinType::S16
44-
| BuiltinType::S32 => TypePassedBy::Value(AtomType::I32),
44+
| BuiltinType::S32
45+
| BuiltinType::Char8 => TypePassedBy::Value(AtomType::I32),
4546
BuiltinType::U64 | BuiltinType::S64 => TypePassedBy::Value(AtomType::I64),
4647
BuiltinType::F32 => TypePassedBy::Value(AtomType::F32),
4748
BuiltinType::F64 => TypePassedBy::Value(AtomType::F64),

tools/witx/src/docs.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ impl BuiltinType {
2525
pub fn type_name(&self) -> &'static str {
2626
match self {
2727
BuiltinType::String => "string",
28+
BuiltinType::Char8 => "char8",
2829
BuiltinType::U8 => "u8",
2930
BuiltinType::U16 => "u16",
3031
BuiltinType::U32 => "u32",

tools/witx/src/layout.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -170,7 +170,9 @@ impl Layout for BuiltinType {
170170
fn mem_size_align(&self) -> SizeAlign {
171171
match self {
172172
BuiltinType::String => SizeAlign { size: 8, align: 4 }, // Pointer and Length
173-
BuiltinType::U8 | BuiltinType::S8 => SizeAlign { size: 1, align: 1 },
173+
BuiltinType::U8 | BuiltinType::S8 | BuiltinType::Char8 => {
174+
SizeAlign { size: 1, align: 1 }
175+
}
174176
BuiltinType::U16 | BuiltinType::S16 => SizeAlign { size: 2, align: 2 },
175177
BuiltinType::U32 | BuiltinType::S32 | BuiltinType::F32 => {
176178
SizeAlign { size: 4, align: 4 }

tools/witx/src/parser.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ mod kw {
1919
pub use wast::kw::{export, func, import, memory, module, param, result};
2020

2121
wast::custom_keyword!(array);
22+
wast::custom_keyword!(char8);
2223
wast::custom_keyword!(const_pointer);
2324
wast::custom_keyword!(f32);
2425
wast::custom_keyword!(f64);
@@ -48,6 +49,9 @@ impl Parse<'_> for BuiltinType {
4849
if l.peek::<kw::string>() {
4950
parser.parse::<kw::string>()?;
5051
Ok(BuiltinType::String)
52+
} else if l.peek::<kw::char8>() {
53+
parser.parse::<kw::char8>()?;
54+
Ok(BuiltinType::Char8)
5155
} else if l.peek::<kw::u8>() {
5256
parser.parse::<kw::u8>()?;
5357
Ok(BuiltinType::U8)
@@ -87,6 +91,7 @@ impl Parse<'_> for BuiltinType {
8791
impl wast::parser::Peek for BuiltinType {
8892
fn peek(cursor: wast::parser::Cursor<'_>) -> bool {
8993
<kw::string as Peek>::peek(cursor)
94+
|| <kw::char8 as Peek>::peek(cursor)
9095
|| <kw::u8 as Peek>::peek(cursor)
9196
|| <kw::u16 as Peek>::peek(cursor)
9297
|| <kw::u32 as Peek>::peek(cursor)

tools/witx/src/render.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,7 @@ impl BuiltinType {
7878
pub fn to_sexpr(&self) -> SExpr {
7979
match self {
8080
BuiltinType::String => SExpr::word("string"),
81+
BuiltinType::Char8 => SExpr::word("char8"),
8182
BuiltinType::U8 => SExpr::word("u8"),
8283
BuiltinType::U16 => SExpr::word("u16"),
8384
BuiltinType::U32 => SExpr::word("u32"),

0 commit comments

Comments
 (0)