tree: a24ef0b9aefc9cff730a5c98e4c98b2e4456522b [path history] [tgz]
  1. templates/
  2. BUILD.gn
  3. c.go
  4. README.md
zircon/tools/zither/backends/c/README.md

The Zither C Backend

The Zither C backend is gives C data layout bindings.

Consider a FIDL library by the name of ${id1}.${id2}.....${idn}.

Output layout

Given a FIDL library by the name of id1.id2.....idn, one header <fidl/id1/id2/.../idn/data/c/${filename}.h> is generated per original FIDL source file, containing the bindings for the declarations defined therein.

A README.md comprised of library-level FIDL documentation is generated as well.

GN integration

${fidl_target}_zither.c gives a C library target with the generated headers as public dependencies.

Bindings

Any declaration type not mentioned below is ignored.

Built-in types

FIDL typeC type
int8int8_t
int16int16_t
int32int32_t
int64int64_t
uint8uint8_t
uint16uint16_t
uint32uint32_t
uint64uint64_t
boolbool
stringconst char*
ucharchar
usize64size_t
uintptr64uintptr_t
array<T, N>T'[N]

Note that FIDL strings are only permitted as constants.

Constants

library example.lib;

const INT_CONST uint32 = 10;  // Or any integral type.
const STR_CONST string = "string constant";

yields

#define EXAMPLE_LIB_INT_CONST ((uint32_t)(10u))
#define EXAMPLE_LIB_STR_CONST ("string constant")

Enums

library example.lib;

type MyEnum = enum : int8 {  // Or any valid integral type
    ZERO = 0;
    ONE = 1;
};

yields

typedef int8_t example_lib_my_enum_t;

#define EXAMPLE_LIB_MY_ENUM_ZERO ((example_lib_my_enum_t)(0))
#define EXAMPLE_LIB_MY_ENUM_ONE ((example_lib_my_enum_t)(1))

Bits

library example.lib;

type MyBits = bits : uint8 {  // Or any valid integral type
    ONE = 1;
    TWO = 2;
    FOUR = 4;
};

yields

typedef uint8_t example_lib_my_bits_t;

#define EXAMPLE_LIB_MY_BITS_ONE ((example_lib_my_bits_t)(1u << 0))
#define EXAMPLE_LIB_MY_BITS_TWO ((example_lib_my_bits_t)(1u << 1))
#define EXAMPLE_LIB_MY_BITS_FOUR ((example_lib_my_bits_t)(1u << 2))

Structs

library example.lib;

type MyStruct = struct {
    member_a uint64;
    member_b bool;
};

yields

typedef struct {
   uint64_t member_a;
   bool member_b;
} example_lib_my_struct_t;

Aliases

library example.lib;

alias MyAlias = MyType;

yields

typedef example_lib_my_type_t example_lib_my_aliase_t;

Overlays

type MyOverlay = strict overlay {
    1: a MyOverlayStructVariant;
    2: b uint32;
};

yields

#define EXAMPLE_MY_OVERLAY_A ((uint64_t)(1u))
#define EXAMPLE_MY_OVERLAY_B ((uint64_t)(2u))

typedef struct {
  uint64_t discriminant;
  union {
    example_my_overlay_struct_variant_t a;
    uint32_t b;
  };
} example_my_overlay_t;