]> git.proxmox.com Git - wasi-libc.git/commitdiff
c header generation updated for reorganized witx ast (#139)
authorPat Hickey <phickey@fastly.com>
Fri, 22 Nov 2019 18:06:12 +0000 (13:06 -0500)
committerGitHub <noreply@github.com>
Fri, 22 Nov 2019 18:06:12 +0000 (13:06 -0500)
libc-bottom-half/headers/public/wasi/api.h
tools/wasi-headers/WASI
tools/wasi-headers/src/c_header.rs

index a2c774bea42f4ad54aa8cd8e5e2ecd973f61f9ba..f1def0c37a5c9a9d26c7eb0aa6ba2a2cc7b69a87 100644 (file)
@@ -1574,7 +1574,7 @@ __wasi_errno_t __wasi_clock_time_get(
     /**
      * 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.
@@ -1591,17 +1591,17 @@ __wasi_errno_t __wasi_clock_time_get(
  * 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.
@@ -1618,17 +1618,17 @@ __wasi_errno_t __wasi_fd_advise(
  * 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"),
@@ -1640,7 +1640,7 @@ __wasi_errno_t __wasi_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"),
@@ -1652,7 +1652,7 @@ __wasi_errno_t __wasi_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"),
@@ -1664,7 +1664,7 @@ __wasi_errno_t __wasi_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.
@@ -1681,7 +1681,7 @@ __wasi_errno_t __wasi_fd_fdstat_get(
  * 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.
@@ -1698,7 +1698,7 @@ __wasi_errno_t __wasi_fd_fdstat_set_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.
@@ -1716,7 +1716,7 @@ __wasi_errno_t __wasi_fd_fdstat_set_rights(
  * 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.
@@ -1733,12 +1733,12 @@ __wasi_errno_t __wasi_fd_filestat_get(
  * 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"),
@@ -1750,17 +1750,17 @@ __wasi_errno_t __wasi_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.
@@ -1777,7 +1777,7 @@ __wasi_errno_t __wasi_fd_filestat_set_times(
  * 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.
@@ -1792,7 +1792,7 @@ __wasi_errno_t __wasi_fd_pread(
     /**
      * The offset within the file at which to read.
      */
-    uint64_t offset,
+    __wasi_filesize_t offset,
 
     /**
      * The number of bytes read.
@@ -1808,7 +1808,7 @@ __wasi_errno_t __wasi_fd_pread(
  * 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.
@@ -1824,14 +1824,14 @@ __wasi_errno_t __wasi_fd_prestat_get(
  * 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"),
@@ -1843,7 +1843,7 @@ __wasi_errno_t __wasi_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.
@@ -1858,7 +1858,7 @@ __wasi_errno_t __wasi_fd_pwrite(
     /**
      * The offset within the file at which to write.
      */
-    uint64_t offset,
+    __wasi_filesize_t offset,
 
     /**
      * The number of bytes written.
@@ -1875,7 +1875,7 @@ __wasi_errno_t __wasi_fd_pwrite(
  * 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.
@@ -1909,19 +1909,19 @@ __wasi_errno_t __wasi_fd_read(
  * 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.
@@ -1944,12 +1944,12 @@ __wasi_errno_t __wasi_fd_readdir(
  * 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"),
@@ -1961,12 +1961,12 @@ __wasi_errno_t __wasi_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.
@@ -1988,7 +1988,7 @@ __wasi_errno_t __wasi_fd_seek(
  * 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"),
@@ -2000,7 +2000,7 @@ __wasi_errno_t __wasi_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.
@@ -2017,7 +2017,7 @@ __wasi_errno_t __wasi_fd_tell(
  * 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.
@@ -2044,7 +2044,7 @@ __wasi_errno_t __wasi_fd_write(
  * 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.
@@ -2066,7 +2066,7 @@ __wasi_errno_t __wasi_path_create_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.
@@ -2098,7 +2098,7 @@ __wasi_errno_t __wasi_path_filestat_get(
  * 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.
@@ -2118,12 +2118,12 @@ __wasi_errno_t __wasi_path_filestat_set_times(
     /**
      * 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.
@@ -2140,7 +2140,7 @@ __wasi_errno_t __wasi_path_filestat_set_times(
  * 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.
@@ -2160,7 +2160,7 @@ __wasi_errno_t __wasi_path_link(
     /**
      * 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.
@@ -2187,7 +2187,7 @@ __wasi_errno_t __wasi_path_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.
@@ -2240,7 +2240,7 @@ __wasi_errno_t __wasi_path_open(
  * 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.
@@ -2257,7 +2257,7 @@ __wasi_errno_t __wasi_path_readlink(
      */
     uint8_t * buf,
 
-    uint32_t buf_len,
+    __wasi_size_t buf_len,
 
     /**
      * The number of bytes placed in the buffer.
@@ -2275,7 +2275,7 @@ __wasi_errno_t __wasi_path_readlink(
  * 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.
@@ -2297,7 +2297,7 @@ __wasi_errno_t __wasi_path_remove_directory(
  * 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.
@@ -2312,7 +2312,7 @@ __wasi_errno_t __wasi_path_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.
@@ -2344,7 +2344,7 @@ __wasi_errno_t __wasi_path_symlink(
      */
     size_t old_path_len,
 
-    uint32_t fd,
+    __wasi_fd_t fd,
 
     /**
      * The destination path at which to create the symbolic link.
@@ -2367,7 +2367,7 @@ __wasi_errno_t __wasi_path_symlink(
  * 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.
@@ -2401,7 +2401,7 @@ __wasi_errno_t __wasi_poll_oneoff(
     /**
      * Both the number of subscriptions and events.
      */
-    uint32_t nsubscriptions,
+    __wasi_size_t nsubscriptions,
 
     /**
      * The number of events stored.
@@ -2422,7 +2422,7 @@ _Noreturn void __wasi_proc_exit(
     /**
      * The exit code returned by the process.
      */
-    uint32_t rval
+    __wasi_exitcode_t rval
 ) __attribute__((
     __import_module__("wasi_snapshot_preview1"),
     __import_name__("proc_exit")));
@@ -2468,7 +2468,7 @@ __wasi_errno_t __wasi_random_get(
      */
     uint8_t * buf,
 
-    uint32_t buf_len
+    __wasi_size_t buf_len
 ) __attribute__((
     __import_module__("wasi_snapshot_preview1"),
     __import_name__("random_get"),
@@ -2481,7 +2481,7 @@ __wasi_errno_t __wasi_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.
@@ -2518,7 +2518,7 @@ __wasi_errno_t __wasi_sock_recv(
  * 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
@@ -2533,7 +2533,7 @@ __wasi_errno_t __wasi_sock_send(
     /**
      * Message flags.
      */
-    uint16_t si_flags,
+    __wasi_siflags_t si_flags,
 
     /**
      * Number of bytes transmitted.
@@ -2550,7 +2550,7 @@ __wasi_errno_t __wasi_sock_send(
  * 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.
index 9fc6370acd9a2da8fdf4f741e8a7106113e13b77..8ff4e845d7baf48bf7cf7b6d9cc2a32a973da04e 160000 (submodule)
@@ -1 +1 @@
-Subproject commit 9fc6370acd9a2da8fdf4f741e8a7106113e13b77
+Subproject commit 8ff4e845d7baf48bf7cf7b6d9cc2a32a973da04e
index 4857528e148448ce3ff66af1ffd116104d4fbda2..a82868aeed1ab6d14f63c80c8d12adfac1ecf30f 100644 (file)
@@ -49,12 +49,12 @@ extern "C" {{
         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(
@@ -69,44 +69,50 @@ extern "C" {{
     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");
@@ -114,11 +120,11 @@ fn print_alias(ret: &mut String, a: &AliasDatatype) {
     }
 }
 
-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");
 
@@ -132,20 +138,20 @@ fn print_enum(ret: &mut String, e: &EnumDatatype) {
         }
         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");
 
@@ -159,19 +165,19 @@ fn print_flags(ret: &mut String, f: &FlagsDatatype) {
         }
         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 {
@@ -184,21 +190,18 @@ fn print_struct(ret: &mut String, s: &StructDatatype) {
         }
         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() {
@@ -210,21 +213,21 @@ fn print_union(ret: &mut String, u: &UnionDatatype) {
         }
         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() {
@@ -235,14 +238,14 @@ fn print_module(ret: &mut String, doc: &Document, m: &Module) {
     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() {
@@ -267,7 +270,7 @@ fn print_func(ret: &mut String, doc: &Document, func: &InterfaceFunc, module_nam
         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)));
@@ -283,7 +286,7 @@ fn print_func(ret: &mut String, doc: &Document, func: &InterfaceFunc, module_nam
             }
             ret.push_str("     */\n");
         }
-        add_params(ret, doc, &ident_name(&param.name), &param.type_);
+        add_params(ret, &ident_name(&param.name), &param.tref);
         ret.push_str(&format!(
             "{}\n",
             if index + 1 < func.params.len() || func.results.len() > 1 {
@@ -308,7 +311,7 @@ fn print_func(ret: &mut String, doc: &Document, func: &InterfaceFunc, module_nam
         }
         ret.push_str(&format!(
             "    {} *{}{}\n",
-            datatype_ident_name(&result.type_),
+            typeref_name(&result.tref),
             ident_name(&result.name),
             if index + 1 < func.results.len() {
                 ","
@@ -334,19 +337,9 @@ fn print_func(ret: &mut String, doc: &Document, func: &InterfaceFunc, module_nam
     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");
@@ -357,10 +350,10 @@ fn add_resolved_params(ret: &mut String, name: &str, type_: &DatatypeIdent) {
             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");
@@ -373,7 +366,7 @@ fn add_resolved_params(ret: &mut String, name: &str, type_: &DatatypeIdent) {
             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));
         }
     }
 }
@@ -398,13 +391,22 @@ fn builtin_type_name(b: BuiltinType) -> &'static str {
     }
 }
 
-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"
+            ),
+        },
     }
 }