/**
* The maximum lag (exclusive) that the returned time value may have, compared to its actual value.
*/
- uint64_t precision,
+ __wasi_timestamp_t precision,
/**
* The time value of the clock.
* Note: This is similar to `posix_fadvise` in POSIX.
*/
__wasi_errno_t __wasi_fd_advise(
- uint32_t fd,
+ __wasi_fd_t fd,
/**
* The offset within the file to which the advisory applies.
*/
- uint64_t offset,
+ __wasi_filesize_t offset,
/**
* The length of the region to which the advisory applies.
*/
- uint64_t len,
+ __wasi_filesize_t len,
/**
* The advice.
* Note: This is similar to `posix_fallocate` in POSIX.
*/
__wasi_errno_t __wasi_fd_allocate(
- uint32_t fd,
+ __wasi_fd_t fd,
/**
* The offset at which to start the allocation.
*/
- uint64_t offset,
+ __wasi_filesize_t offset,
/**
* The length of the area that is allocated.
*/
- uint64_t len
+ __wasi_filesize_t len
) __attribute__((
__import_module__("wasi_snapshot_preview1"),
__import_name__("fd_allocate"),
* Note: This is similar to `close` in POSIX.
*/
__wasi_errno_t __wasi_fd_close(
- uint32_t fd
+ __wasi_fd_t fd
) __attribute__((
__import_module__("wasi_snapshot_preview1"),
__import_name__("fd_close"),
* Note: This is similar to `fdatasync` in POSIX.
*/
__wasi_errno_t __wasi_fd_datasync(
- uint32_t fd
+ __wasi_fd_t fd
) __attribute__((
__import_module__("wasi_snapshot_preview1"),
__import_name__("fd_datasync"),
* Note: This returns similar flags to `fsync(fd, F_GETFL)` in POSIX, as well as additional fields.
*/
__wasi_errno_t __wasi_fd_fdstat_get(
- uint32_t fd,
+ __wasi_fd_t fd,
/**
* The buffer where the file descriptor's attributes are stored.
* Note: This is similar to `fcntl(fd, F_SETFL, flags)` in POSIX.
*/
__wasi_errno_t __wasi_fd_fdstat_set_flags(
- uint32_t fd,
+ __wasi_fd_t fd,
/**
* The desired values of the file descriptor flags.
* This can only be used to remove rights, and returns `ENOTCAPABLE` if called in a way that would attempt to add rights
*/
__wasi_errno_t __wasi_fd_fdstat_set_rights(
- uint32_t fd,
+ __wasi_fd_t fd,
/**
* The desired rights of the file descriptor.
* Return the attributes of an open file.
*/
__wasi_errno_t __wasi_fd_filestat_get(
- uint32_t fd,
+ __wasi_fd_t fd,
/**
* The buffer where the file's attributes are stored.
* Note: This is similar to `ftruncate` in POSIX.
*/
__wasi_errno_t __wasi_fd_filestat_set_size(
- uint32_t fd,
+ __wasi_fd_t fd,
/**
* The desired file size.
*/
- uint64_t size
+ __wasi_filesize_t size
) __attribute__((
__import_module__("wasi_snapshot_preview1"),
__import_name__("fd_filestat_set_size"),
* Note: This is similar to `futimens` in POSIX.
*/
__wasi_errno_t __wasi_fd_filestat_set_times(
- uint32_t fd,
+ __wasi_fd_t fd,
/**
* The desired values of the data access timestamp.
*/
- uint64_t atim,
+ __wasi_timestamp_t atim,
/**
* The desired values of the data modification timestamp.
*/
- uint64_t mtim,
+ __wasi_timestamp_t mtim,
/**
* A bitmask indicating which timestamps to adjust.
* Note: This is similar to `preadv` in POSIX.
*/
__wasi_errno_t __wasi_fd_pread(
- uint32_t fd,
+ __wasi_fd_t fd,
/**
* List of scatter/gather vectors in which to store data.
/**
* The offset within the file at which to read.
*/
- uint64_t offset,
+ __wasi_filesize_t offset,
/**
* The number of bytes read.
* Return a description of the given preopened file descriptor.
*/
__wasi_errno_t __wasi_fd_prestat_get(
- uint32_t fd,
+ __wasi_fd_t fd,
/**
* The buffer where the description is stored.
* Return a description of the given preopened file descriptor.
*/
__wasi_errno_t __wasi_fd_prestat_dir_name(
- uint32_t fd,
+ __wasi_fd_t fd,
/**
* A buffer into which to write the preopened directory name.
*/
uint8_t * path,
- uint32_t path_len
+ __wasi_size_t path_len
) __attribute__((
__import_module__("wasi_snapshot_preview1"),
__import_name__("fd_prestat_dir_name"),
* Note: This is similar to `pwritev` in POSIX.
*/
__wasi_errno_t __wasi_fd_pwrite(
- uint32_t fd,
+ __wasi_fd_t fd,
/**
* List of scatter/gather vectors from which to retrieve data.
/**
* The offset within the file at which to write.
*/
- uint64_t offset,
+ __wasi_filesize_t offset,
/**
* The number of bytes written.
* Note: This is similar to `readv` in POSIX.
*/
__wasi_errno_t __wasi_fd_read(
- uint32_t fd,
+ __wasi_fd_t fd,
/**
* List of scatter/gather vectors to which to store data.
* entry, or skip the oversized directory entry.
*/
__wasi_errno_t __wasi_fd_readdir(
- uint32_t fd,
+ __wasi_fd_t fd,
/**
* The buffer where directory entries are stored
*/
uint8_t * buf,
- uint32_t buf_len,
+ __wasi_size_t buf_len,
/**
* The location within the directory to start reading
*/
- uint64_t cookie,
+ __wasi_dircookie_t cookie,
/**
* The number of bytes stored in the read buffer. If less than the size of the read buffer, the end of the directory has been reached.
* would disappear if `dup2()` were to be removed entirely.
*/
__wasi_errno_t __wasi_fd_renumber(
- uint32_t fd,
+ __wasi_fd_t fd,
/**
* The file descriptor to overwrite.
*/
- uint32_t to
+ __wasi_fd_t to
) __attribute__((
__import_module__("wasi_snapshot_preview1"),
__import_name__("fd_renumber"),
* Note: This is similar to `lseek` in POSIX.
*/
__wasi_errno_t __wasi_fd_seek(
- uint32_t fd,
+ __wasi_fd_t fd,
/**
* The number of bytes to move.
*/
- int64_t offset,
+ __wasi_filedelta_t offset,
/**
* The base from which the offset is relative.
* Note: This is similar to `fsync` in POSIX.
*/
__wasi_errno_t __wasi_fd_sync(
- uint32_t fd
+ __wasi_fd_t fd
) __attribute__((
__import_module__("wasi_snapshot_preview1"),
__import_name__("fd_sync"),
* Note: This is similar to `lseek(fd, 0, SEEK_CUR)` in POSIX.
*/
__wasi_errno_t __wasi_fd_tell(
- uint32_t fd,
+ __wasi_fd_t fd,
/**
* The current offset of the file descriptor, relative to the start of the file.
* Note: This is similar to `writev` in POSIX.
*/
__wasi_errno_t __wasi_fd_write(
- uint32_t fd,
+ __wasi_fd_t fd,
/**
* List of scatter/gather vectors from which to retrieve data.
* Note: This is similar to `mkdirat` in POSIX.
*/
__wasi_errno_t __wasi_path_create_directory(
- uint32_t fd,
+ __wasi_fd_t fd,
/**
* The path at which to create the directory.
* Note: This is similar to `stat` in POSIX.
*/
__wasi_errno_t __wasi_path_filestat_get(
- uint32_t fd,
+ __wasi_fd_t fd,
/**
* Flags determining the method of how the path is resolved.
* Note: This is similar to `utimensat` in POSIX.
*/
__wasi_errno_t __wasi_path_filestat_set_times(
- uint32_t fd,
+ __wasi_fd_t fd,
/**
* Flags determining the method of how the path is resolved.
/**
* The desired values of the data access timestamp.
*/
- uint64_t atim,
+ __wasi_timestamp_t atim,
/**
* The desired values of the data modification timestamp.
*/
- uint64_t mtim,
+ __wasi_timestamp_t mtim,
/**
* A bitmask indicating which timestamps to adjust.
* Note: This is similar to `linkat` in POSIX.
*/
__wasi_errno_t __wasi_path_link(
- uint32_t old_fd,
+ __wasi_fd_t old_fd,
/**
* Flags determining the method of how the path is resolved.
/**
* The working directory at which the resolution of the new path starts.
*/
- uint32_t new_fd,
+ __wasi_fd_t new_fd,
/**
* The destination path at which to create the hard link.
* Note: This is similar to `openat` in POSIX.
*/
__wasi_errno_t __wasi_path_open(
- uint32_t fd,
+ __wasi_fd_t fd,
/**
* Flags determining the method of how the path is resolved.
* Note: This is similar to `readlinkat` in POSIX.
*/
__wasi_errno_t __wasi_path_readlink(
- uint32_t fd,
+ __wasi_fd_t fd,
/**
* The path of the symbolic link from which to read.
*/
uint8_t * buf,
- uint32_t buf_len,
+ __wasi_size_t buf_len,
/**
* The number of bytes placed in the buffer.
* Note: This is similar to `unlinkat(fd, path, AT_REMOVEDIR)` in POSIX.
*/
__wasi_errno_t __wasi_path_remove_directory(
- uint32_t fd,
+ __wasi_fd_t fd,
/**
* The path to a directory to remove.
* Note: This is similar to `renameat` in POSIX.
*/
__wasi_errno_t __wasi_path_rename(
- uint32_t fd,
+ __wasi_fd_t fd,
/**
* The source path of the file or directory to rename.
/**
* The working directory at which the resolution of the new path starts.
*/
- uint32_t new_fd,
+ __wasi_fd_t new_fd,
/**
* The destination path to which to rename the file or directory.
*/
size_t old_path_len,
- uint32_t fd,
+ __wasi_fd_t fd,
/**
* The destination path at which to create the symbolic link.
* Note: This is similar to `unlinkat(fd, path, 0)` in POSIX.
*/
__wasi_errno_t __wasi_path_unlink_file(
- uint32_t fd,
+ __wasi_fd_t fd,
/**
* The path to a file to unlink.
/**
* Both the number of subscriptions and events.
*/
- uint32_t nsubscriptions,
+ __wasi_size_t nsubscriptions,
/**
* The number of events stored.
/**
* The exit code returned by the process.
*/
- uint32_t rval
+ __wasi_exitcode_t rval
) __attribute__((
__import_module__("wasi_snapshot_preview1"),
__import_name__("proc_exit")));
*/
uint8_t * buf,
- uint32_t buf_len
+ __wasi_size_t buf_len
) __attribute__((
__import_module__("wasi_snapshot_preview1"),
__import_name__("random_get"),
* the data into multiple buffers in the manner of `readv`.
*/
__wasi_errno_t __wasi_sock_recv(
- uint32_t fd,
+ __wasi_fd_t fd,
/**
* List of scatter/gather vectors to which to store data.
* the data from multiple buffers in the manner of `writev`.
*/
__wasi_errno_t __wasi_sock_send(
- uint32_t fd,
+ __wasi_fd_t fd,
/**
* List of scatter/gather vectors to which to retrieve data
/**
* Message flags.
*/
- uint16_t si_flags,
+ __wasi_siflags_t si_flags,
/**
* Number of bytes transmitted.
* Note: This is similar to `shutdown` in POSIX.
*/
__wasi_errno_t __wasi_sock_shutdown(
- uint32_t fd,
+ __wasi_fd_t fd,
/**
* Which channels on the socket to shut down.
inputs_str,
));
- for d in doc.datatypes() {
- print_datatype(&mut ret, &*d);
+ for nt in doc.typenames() {
+ print_datatype(&mut ret, &*nt);
}
for m in doc.modules() {
- print_module(&mut ret, doc, &m);
+ print_module(&mut ret, &m);
}
ret.push_str(
ret
}
-fn print_datatype(ret: &mut String, d: &Datatype) {
- if !d.docs.is_empty() {
+fn print_datatype(ret: &mut String, nt: &NamedType) {
+ if !nt.docs.is_empty() {
ret.push_str("/**\n");
- for line in d.docs.lines() {
+ for line in nt.docs.lines() {
ret.push_str(&format!(" * {}\n", line));
}
ret.push_str(" */\n");
}
- match &d.variant {
- DatatypeVariant::Alias(a) => print_alias(ret, a),
- DatatypeVariant::Enum(e) => print_enum(ret, e),
- DatatypeVariant::Flags(f) => print_flags(ret, f),
- DatatypeVariant::Struct(s) => print_struct(ret, s),
- DatatypeVariant::Union(u) => print_union(ret, u),
- DatatypeVariant::Handle(h) => print_handle(ret, h),
+ match &nt.dt {
+ TypeRef::Value(v) => match &**v {
+ Type::Enum(e) => print_enum(ret, &nt.name, e),
+ Type::Flags(f) => print_flags(ret, &nt.name, f),
+ Type::Struct(s) => print_struct(ret, &nt.name, s),
+ Type::Union(u) => print_union(ret, &nt.name, u),
+ Type::Handle(h) => print_handle(ret, &nt.name, h),
+ Type::Builtin { .. }
+ | Type::Array { .. }
+ | Type::Pointer { .. }
+ | Type::ConstPointer { .. } => print_alias(ret, &nt.name, &nt.dt),
+ },
+ TypeRef::Name(_) => print_alias(ret, &nt.name, &nt.dt),
}
}
-fn print_alias(ret: &mut String, a: &AliasDatatype) {
- match a.to {
- DatatypeIdent::Array(_) => {
+fn print_alias(ret: &mut String, name: &Id, dest: &TypeRef) {
+ match &*dest.type_() {
+ Type::Array(_) => {
// Don't emit arrays as top-level types; instead we special-case
// them in places like parameter lists so that we can pass them
// as pointer and length pairs.
}
_ => {
- if a.name.as_str() == "size" {
+ if name.as_str() == "size" {
// Special-case "size" as "__SIZE_TYPE__" -- TODO: Encode this in witx.
ret.push_str(&format!(
"typedef __SIZE_TYPE__ __wasi_{}_t;\n",
- ident_name(&a.name)
+ ident_name(name)
));
} else {
ret.push_str(&format!(
"typedef {} __wasi_{}_t;\n",
- datatype_ident_name(&a.to),
- ident_name(&a.name)
+ typeref_name(dest),
+ ident_name(name)
));
}
ret.push_str("\n");
}
}
-fn print_enum(ret: &mut String, e: &EnumDatatype) {
+fn print_enum(ret: &mut String, name: &Id, e: &EnumDatatype) {
ret.push_str(&format!(
"typedef {} __wasi_{}_t;\n",
intrepr_name(e.repr),
- ident_name(&e.name)
+ ident_name(name)
));
ret.push_str("\n");
}
ret.push_str(&format!(
"#define __WASI_{}_{} ((__wasi_{}_t){})\n",
- ident_name(&e.name).to_shouty_snake_case(),
+ ident_name(&name).to_shouty_snake_case(),
ident_name(&variant.name).to_shouty_snake_case(),
- ident_name(&e.name),
+ ident_name(&name),
index
));
ret.push_str("\n");
}
}
-fn print_flags(ret: &mut String, f: &FlagsDatatype) {
+fn print_flags(ret: &mut String, name: &Id, f: &FlagsDatatype) {
ret.push_str(&format!(
"typedef {} __wasi_{}_t;\n",
intrepr_name(f.repr),
- ident_name(&f.name)
+ ident_name(name)
));
ret.push_str("\n");
}
ret.push_str(&format!(
"#define __WASI_{}_{} ((__wasi_{}_t){})\n",
- ident_name(&f.name).to_shouty_snake_case(),
+ ident_name(name).to_shouty_snake_case(),
ident_name(&flag.name).to_shouty_snake_case(),
- ident_name(&f.name),
+ ident_name(name),
1u128 << index
));
ret.push_str("\n");
}
}
-fn print_struct(ret: &mut String, s: &StructDatatype) {
+fn print_struct(ret: &mut String, name: &Id, s: &StructDatatype) {
ret.push_str(&format!(
"typedef struct __wasi_{}_t {{\n",
- ident_name(&s.name)
+ ident_name(name)
));
for member in &s.members {
}
ret.push_str(&format!(
" {} {};\n",
- datatype_ident_name(&member.type_),
+ typeref_name(&member.tref),
ident_name(&member.name)
));
ret.push_str("\n");
}
- ret.push_str(&format!("}} __wasi_{}_t;\n", ident_name(&s.name)));
+ ret.push_str(&format!("}} __wasi_{}_t;\n", ident_name(name)));
ret.push_str("\n");
}
-fn print_union(ret: &mut String, u: &UnionDatatype) {
- ret.push_str(&format!(
- "typedef union __wasi_{}_t {{\n",
- ident_name(&u.name)
- ));
+fn print_union(ret: &mut String, name: &Id, u: &UnionDatatype) {
+ ret.push_str(&format!("typedef union __wasi_{}_t {{\n", ident_name(name)));
for variant in &u.variants {
if !variant.docs.is_empty() {
}
ret.push_str(&format!(
" {} {};\n",
- datatype_ident_name(&variant.type_),
+ typeref_name(&variant.tref),
ident_name(&variant.name)
));
ret.push_str("\n");
}
- ret.push_str(&format!("}} __wasi_{}_t;\n", ident_name(&u.name)));
+ ret.push_str(&format!("}} __wasi_{}_t;\n", ident_name(name)));
ret.push_str("\n");
}
-fn print_handle(ret: &mut String, h: &HandleDatatype) {
- ret.push_str(&format!("typedef int __wasi_{}_t;", ident_name(&h.name)));
+fn print_handle(ret: &mut String, name: &Id, _h: &HandleDatatype) {
+ ret.push_str(&format!("typedef int __wasi_{}_t;", ident_name(name)));
}
-fn print_module(ret: &mut String, doc: &Document, m: &Module) {
+fn print_module(ret: &mut String, m: &Module) {
ret.push_str("/**\n");
ret.push_str(&format!(" * @defgroup {}\n", ident_name(&m.name),));
for line in m.docs.lines() {
ret.push_str("\n");
for func in m.funcs() {
- print_func(ret, doc, &func, &m.name);
+ print_func(ret, &func, &m.name);
}
ret.push_str("/** @} */\n");
ret.push_str("\n");
}
-fn print_func(ret: &mut String, doc: &Document, func: &InterfaceFunc, module_name: &Id) {
+fn print_func(ret: &mut String, func: &InterfaceFunc, module_name: &Id) {
if !func.docs.is_empty() {
ret.push_str("/**\n");
for line in func.docs.lines() {
ret.push_str("void ");
} else {
let first_result = &func.results[0];
- ret.push_str(&format!("{} ", datatype_ident_name(&first_result.type_)));
+ ret.push_str(&format!("{} ", typeref_name(&first_result.tref)));
}
ret.push_str(&format!("__wasi_{}(\n", ident_name(&func.name)));
}
ret.push_str(" */\n");
}
- add_params(ret, doc, &ident_name(¶m.name), ¶m.type_);
+ add_params(ret, &ident_name(¶m.name), ¶m.tref);
ret.push_str(&format!(
"{}\n",
if index + 1 < func.params.len() || func.results.len() > 1 {
}
ret.push_str(&format!(
" {} *{}{}\n",
- datatype_ident_name(&result.type_),
+ typeref_name(&result.tref),
ident_name(&result.name),
if index + 1 < func.results.len() {
","
ret.push_str("\n");
}
-fn add_params(ret: &mut String, doc: &Document, name: &str, type_: &DatatypeIdent) {
- match type_ {
- DatatypeIdent::Ident(i) => match &doc.datatype(&i.name).unwrap().as_ref().variant {
- DatatypeVariant::Alias(a) => add_resolved_params(ret, name, &a.to),
- _ => add_resolved_params(ret, name, type_),
- },
- _ => add_resolved_params(ret, name, type_),
- }
-}
-
-fn add_resolved_params(ret: &mut String, name: &str, type_: &DatatypeIdent) {
- match type_ {
- DatatypeIdent::Builtin(BuiltinType::String) => {
+fn add_params(ret: &mut String, name: &str, tref: &TypeRef) {
+ match &*tref.type_() {
+ Type::Builtin(BuiltinType::String) => {
ret.push_str(&format!(" const char *{},\n", name));
ret.push_str("\n");
ret.push_str(" /**\n");
ret.push_str(" */\n");
ret.push_str(&format!(" size_t {}_len", name));
}
- DatatypeIdent::Array(element) => {
+ Type::Array(element) => {
ret.push_str(&format!(
" const {} *{},\n",
- datatype_ident_name(&element),
+ typeref_name(&element),
name
));
ret.push_str("\n");
ret.push_str(&format!(" size_t {}_len", name));
}
_ => {
- ret.push_str(&format!(" {} {}", datatype_ident_name(&type_), name));
+ ret.push_str(&format!(" {} {}", typeref_name(tref), name));
}
}
}
}
}
-fn datatype_ident_name(data_ty: &DatatypeIdent) -> String {
- match data_ty {
- DatatypeIdent::Builtin(b) => builtin_type_name(*b).to_string(),
- DatatypeIdent::Array(_) => unreachable!("arrays should be special-cased"),
- DatatypeIdent::Pointer(p) => format!("{} *", datatype_ident_name(&*p)),
- DatatypeIdent::ConstPointer(p) => format!("const {} *", datatype_ident_name(&*p)),
- DatatypeIdent::Ident(i) => format!("__wasi_{}_t", i.name.as_str()),
+fn typeref_name(tref: &TypeRef) -> String {
+ match tref {
+ TypeRef::Name(named_type) => format!("__wasi_{}_t", named_type.name.as_str()),
+ TypeRef::Value(anon_type) => match &**anon_type {
+ Type::Builtin(b) => builtin_type_name(*b).to_string(),
+ Type::Array(_) => unreachable!("arrays should be special-cased"),
+ Type::Pointer(p) => format!("{} *", typeref_name(&*p)),
+ Type::ConstPointer(p) => format!("const {} *", typeref_name(&*p)),
+ Type::Struct { .. }
+ | Type::Union { .. }
+ | Type::Enum { .. }
+ | Type::Flags { .. }
+ | Type::Handle { .. } => unreachable!(
+ "wasi should not have anonymous structs, unions, enums, flags, handles"
+ ),
+ },
}
}