Motr  M0
xcode.c File Reference
#include <stdio.h>
#include <ctype.h>
#include "lib/memory.h"
#include "lib/vec.h"
#include "lib/misc.h"
#include "lib/arith.h"
#include "lib/errno.h"
#include "lib/string.h"
#include "ut/ut.h"
#include "xcode/xcode.h"
#include "test_gccxml_simple.h"
#include "test_gccxml_simple_xc.h"
Include dependency graph for xcode.c:

Go to the source code of this file.

Data Structures

struct  foo
 
struct  un
 
struct  ar
 
struct  top
 
struct  top::v
 
struct  static_xt
 
struct  tdata
 
struct  tdata::_foo
 
struct  _foo
 
struct  pair
 

Macros

#define OBJ(xt, ptr)   (&(struct m0_xcode_obj){ .xo_type = (xt), .xo_ptr = (ptr) })
 
#define ARS   "<(0, 0x1), (0, 0x1), (0, 0x1), (0, 0x1), (0, 0x1), (0, 0x1)>"
 
#define __ENUM_ONLY
 
#define CHECK(v)   m0_streq(m0_xcode_enum_print(&m0_xc_testenum_enum, v, NULL), #v)
 
#define C(v)   (enum_read_check(#v, strlen(#v), v, 0))
 

Typedefs

typedef uint32_t tdef
 

Enumerations

enum  { N = 6 }
 
enum  { CHILDREN_MAX = 16 }
 
enum  { FSIZE = sizeof(uint64_t) + sizeof(uint64_t) }
 

Functions

static struct tdata __attribute__ ((packed))
 
static int xcode_init (void)
 
 __attribute__ ((unused))
 
static void chk (struct m0_xcode_cursor *it, int depth, const struct m0_xcode_type *xt, void *addr, int fieldno, int elno, enum m0_xcode_cursor_flag flag)
 
static void xcode_cursor_test (void)
 
static void xcode_length_test (void)
 
static void xcode_encode_test (void)
 
static void xcode_opaque_test (void)
 
static void decode (struct m0_xcode_obj *obj)
 
static void xcode_decode_test (void)
 
static int foo_length (struct m0_xcode_ctx *ctx, const void *obj)
 
static void foo_xor (char *buf)
 
static int foo_encode (struct m0_xcode_ctx *ctx, const void *obj)
 
static int foo_decode (struct m0_xcode_ctx *ctx, void *obj)
 
static void xcode_nonstandard_test (void)
 
static void xcode_cmp_test (void)
 
static int custom_read (const struct m0_xcode_cursor *it, struct m0_xcode_obj *obj, const char *str)
 
static void literal (const char *input, const char *output)
 
static void xcode_read_test (void)
 
static void xcode_print_test (void)
 
static void xcode_find_test (void)
 
static void xcode_enum_gccxml (void)
 
static void xcode_enum_print (void)
 
static void enum_read_check (const char *name, int nr, uint64_t v, int rc)
 
static void xcode_enum_read (void)
 
static void bitmask_print_check (uint64_t mask, int nr, bool ok, const char *out)
 
static void xcode_bitmask_print (void)
 
static void bitmask_read_check (uint64_t mask, int nr, bool ok, const char *buf)
 
static void xcode_bitmask_read (void)
 
static void xcode_enum_loop (void)
 
static void xcode_enum_field (void)
 
static void t_count (struct m0_xcode_type *xt, void *data)
 
static void f_count (struct m0_xcode_type *xt, struct m0_xcode_field *field, void *data)
 
static void xcode_iterate (void)
 
static void flagset (struct m0_xcode_type *xt, uint32_t flags)
 
static void fieldset (struct m0_xcode_type *xt, struct m0_xcode_field *field, void *unused)
 
static void fieldclear (struct m0_xcode_type *xt, struct m0_xcode_field *field, void *unused)
 
static void xcode_flags (void)
 
int m0_package_cred_get (const struct m0_xcode_obj *par, const struct m0_xcode_type **out)
 

Variables

static struct static_xt xut_un
 
static struct static_xt xut_tdef
 
static struct static_xt xut_v
 
static struct static_xt xut_foo
 
static struct static_xt xut_ar
 
static struct static_xt xut_top
 
static char data [] = "Hello, world!\n"
 
static struct top T
 
static char ebuf [1000]
 
static m0_bcount_t count = ARRAY_SIZE(ebuf)
 
static void * vec = ebuf
 
static struct m0_bufvec bvec = M0_BUFVEC_INIT_BUF(&vec, &count)
 
static struct m0_xcode_ctx ctx
 
uint64_t f_x
 
uint64_t f_y
 
enum { ... }  __attribute__
 
static char foo_buf [FSIZE]
 
static void * foo_addr = foo_buf
 
static m0_bcount_t foo_count = ARRAY_SIZE(foo_buf)
 
static struct m0_bufvec foo_bvec = M0_BUFVEC_INIT_BUF(&foo_addr, &foo_count)
 
static const struct m0_xcode_type_ops foo_ops
 
static const struct m0_xcode_type_ops read_ops
 
static int ecount
 
struct pair builtins []
 
struct m0_ut_suite xcode_ut
 

Macro Definition Documentation

◆ __ENUM_ONLY

#define __ENUM_ONLY

Definition at line 948 of file xcode.c.

◆ ARS

#define ARS   "<(0, 0x1), (0, 0x1), (0, 0x1), (0, 0x1), (0, 0x1), (0, 0x1)>"

◆ C

#define C (   v)    (enum_read_check(#v, strlen(#v), v, 0))

◆ CHECK

#define CHECK (   v)    m0_streq(m0_xcode_enum_print(&m0_xc_testenum_enum, v, NULL), #v)

◆ OBJ

#define OBJ (   xt,
  ptr 
)    (&(struct m0_xcode_obj){ .xo_type = (xt), .xo_ptr = (ptr) })

Definition at line 667 of file xcode.c.

Typedef Documentation

◆ tdef

typedef uint32_t tdef

Definition at line 43 of file xcode.c.

Enumeration Type Documentation

◆ anonymous enum

anonymous enum
Enumerator

Definition at line 53 of file xcode.c.

◆ anonymous enum

anonymous enum
Enumerator
CHILDREN_MAX 

Definition at line 75 of file xcode.c.

◆ anonymous enum

anonymous enum
Enumerator
FSIZE 

Definition at line 523 of file xcode.c.

Function Documentation

◆ __attribute__() [1/2]

static struct tdata __attribute__ ( (packed)  )
static

Definition at line 194 of file xcode.c.

◆ __attribute__() [2/2]

__attribute__ ( (unused)  )

Definition at line 321 of file xcode.c.

◆ bitmask_print_check()

static void bitmask_print_check ( uint64_t  mask,
int  nr,
bool  ok,
const char *  out 
)
static

Definition at line 1010 of file xcode.c.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ bitmask_read_check()

static void bitmask_read_check ( uint64_t  mask,
int  nr,
bool  ok,
const char *  buf 
)
static

Definition at line 1053 of file xcode.c.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ chk()

static void chk ( struct m0_xcode_cursor it,
int  depth,
const struct m0_xcode_type xt,
void *  addr,
int  fieldno,
int  elno,
enum m0_xcode_cursor_flag  flag 
)
static

Definition at line 354 of file xcode.c.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ custom_read()

static int custom_read ( const struct m0_xcode_cursor it,
struct m0_xcode_obj obj,
const char *  str 
)
static

Definition at line 653 of file xcode.c.

◆ decode()

static void decode ( struct m0_xcode_obj obj)
static

Definition at line 487 of file xcode.c.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ enum_read_check()

static void enum_read_check ( const char *  name,
int  nr,
uint64_t  v,
int  rc 
)
static

Definition at line 985 of file xcode.c.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ f_count()

static void f_count ( struct m0_xcode_type xt,
struct m0_xcode_field field,
void *  data 
)
static

Definition at line 1168 of file xcode.c.

Here is the caller graph for this function:

◆ fieldclear()

static void fieldclear ( struct m0_xcode_type xt,
struct m0_xcode_field field,
void *  unused 
)
static

Definition at line 1219 of file xcode.c.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ fieldset()

static void fieldset ( struct m0_xcode_type xt,
struct m0_xcode_field field,
void *  unused 
)
static

Definition at line 1204 of file xcode.c.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ flagset()

static void flagset ( struct m0_xcode_type xt,
uint32_t  flags 
)
static

Definition at line 1189 of file xcode.c.

Here is the caller graph for this function:

◆ foo_decode()

static int foo_decode ( struct m0_xcode_ctx ctx,
void *  obj 
)
static

Definition at line 556 of file xcode.c.

Here is the call graph for this function:

◆ foo_encode()

static int foo_encode ( struct m0_xcode_ctx ctx,
const void *  obj 
)
static

Definition at line 545 of file xcode.c.

Here is the call graph for this function:

◆ foo_length()

static int foo_length ( struct m0_xcode_ctx ctx,
const void *  obj 
)
static

Definition at line 532 of file xcode.c.

◆ foo_xor()

static void foo_xor ( char *  buf)
static

Definition at line 537 of file xcode.c.

Here is the caller graph for this function:

◆ literal()

static void literal ( const char *  input,
const char *  output 
)
static

Definition at line 669 of file xcode.c.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ m0_package_cred_get()

int m0_package_cred_get ( const struct m0_xcode_obj par,
const struct m0_xcode_type **  out 
)

Definition at line 1267 of file xcode.c.

◆ t_count()

static void t_count ( struct m0_xcode_type xt,
void *  data 
)
static

Definition at line 1163 of file xcode.c.

Here is the caller graph for this function:

◆ xcode_bitmask_print()

static void xcode_bitmask_print ( void  )
static

Definition at line 1023 of file xcode.c.

Here is the call graph for this function:

◆ xcode_bitmask_read()

static void xcode_bitmask_read ( void  )
static

Definition at line 1066 of file xcode.c.

Here is the call graph for this function:

◆ xcode_cmp_test()

static void xcode_cmp_test ( void  )
static

Definition at line 602 of file xcode.c.

Here is the call graph for this function:

◆ xcode_cursor_test()

static void xcode_cursor_test ( void  )
static

Definition at line 379 of file xcode.c.

Here is the call graph for this function:

◆ xcode_decode_test()

static void xcode_decode_test ( void  )
static

Definition at line 501 of file xcode.c.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ xcode_encode_test()

static void xcode_encode_test ( void  )
static

Definition at line 464 of file xcode.c.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ xcode_enum_field()

static void xcode_enum_field ( void  )
static

Definition at line 1139 of file xcode.c.

Here is the call graph for this function:

◆ xcode_enum_gccxml()

static void xcode_enum_gccxml ( void  )
static

Definition at line 952 of file xcode.c.

◆ xcode_enum_loop()

static void xcode_enum_loop ( void  )
static

Definition at line 1111 of file xcode.c.

Here is the call graph for this function:

◆ xcode_enum_print()

static void xcode_enum_print ( void  )
static

Definition at line 967 of file xcode.c.

Here is the call graph for this function:

◆ xcode_enum_read()

static void xcode_enum_read ( void  )
static

Definition at line 994 of file xcode.c.

Here is the call graph for this function:

◆ xcode_find_test()

static void xcode_find_test ( void  )
static

Definition at line 923 of file xcode.c.

Here is the call graph for this function:

◆ xcode_flags()

static void xcode_flags ( void  )
static

Definition at line 1233 of file xcode.c.

Here is the call graph for this function:

◆ xcode_init()

static int xcode_init ( void  )
static

Definition at line 214 of file xcode.c.

◆ xcode_iterate()

static void xcode_iterate ( void  )
static

Definition at line 1174 of file xcode.c.

Here is the call graph for this function:

◆ xcode_length_test()

static void xcode_length_test ( void  )
static

Definition at line 455 of file xcode.c.

Here is the call graph for this function:

◆ xcode_nonstandard_test()

static void xcode_nonstandard_test ( void  )
static

Definition at line 575 of file xcode.c.

Here is the call graph for this function:

◆ xcode_opaque_test()

static void xcode_opaque_test ( void  )
static

Definition at line 476 of file xcode.c.

Here is the call graph for this function:

◆ xcode_print_test()

static void xcode_print_test ( void  )
static

Definition at line 863 of file xcode.c.

Here is the call graph for this function:

◆ xcode_read_test()

static void xcode_read_test ( void  )
static

Definition at line 692 of file xcode.c.

Here is the call graph for this function:

Variable Documentation

◆ __attribute__

enum { ... } __attribute__

◆ builtins

struct pair builtins[]
Initial value:
= {
{ &M0_XT_U8, {} },
{ &M0_XT_U32, {} },
{ &M0_XT_U64, {} },
{ &M0_XT_OPAQUE, {} }
}
const struct m0_xcode_type M0_XT_OPAQUE
Definition: xcode.c:948
const struct m0_xcode_type M0_XT_U32
Definition: xcode.c:932
const struct m0_xcode_type M0_XT_U8
Definition: xcode.c:924
const struct m0_xcode_type M0_XT_U64
Definition: xcode.c:940

◆ bvec

struct m0_bufvec bvec = M0_BUFVEC_INIT_BUF(&vec, &count)
static

Definition at line 169 of file xcode.c.

◆ count

m0_bcount_t count = ARRAY_SIZE(ebuf)
static

Definition at line 167 of file xcode.c.

◆ ctx

struct m0_xcode_ctx ctx
static

Definition at line 170 of file xcode.c.

◆ data

char data[] = "Hello, world!\n"
static

Definition at line 136 of file xcode.c.

◆ ebuf

char ebuf[1000]
static

Definition at line 166 of file xcode.c.

◆ ecount

int ecount
static

Definition at line 1162 of file xcode.c.

◆ f_x

uint64_t f_x

Definition at line 71 of file xcode.c.

◆ f_y

uint64_t f_y

Definition at line 72 of file xcode.c.

◆ foo_addr

void* foo_addr = foo_buf
static

Definition at line 528 of file xcode.c.

◆ foo_buf

char foo_buf[FSIZE]
static

Definition at line 527 of file xcode.c.

◆ foo_bvec

struct m0_bufvec foo_bvec = M0_BUFVEC_INIT_BUF(&foo_addr, &foo_count)
static

Definition at line 530 of file xcode.c.

◆ foo_count

m0_bcount_t foo_count = ARRAY_SIZE(foo_buf)
static

Definition at line 529 of file xcode.c.

◆ foo_ops

const struct m0_xcode_type_ops foo_ops
static
Initial value:
= {
.xto_length = foo_length,
.xto_encode = foo_encode,
.xto_decode = foo_decode
}
static int foo_length(struct m0_xcode_ctx *ctx, const void *obj)
Definition: xcode.c:532
static int foo_decode(struct m0_xcode_ctx *ctx, void *obj)
Definition: xcode.c:556
static int foo_encode(struct m0_xcode_ctx *ctx, const void *obj)
Definition: xcode.c:545

Definition at line 569 of file xcode.c.

◆ read_ops

const struct m0_xcode_type_ops read_ops
static
Initial value:
= {
.xto_read = &custom_read
}
static int custom_read(const struct m0_xcode_cursor *it, struct m0_xcode_obj *obj, const char *str)
Definition: xcode.c:653

Definition at line 663 of file xcode.c.

◆ T

struct top T
static
Initial value:
= {
.t_foo = {
.f_x = 7,
.f_y = 8
},
.t_flag = 0xF,
.t_v = {
.v_nr = sizeof data,
.v_data = data
},
.t_un = {
.u_tag = 4
},
.t_opaq = {
.o_32 = &T.t_v.v_nr
},
.t_ar = {
.a_el = {
[0] = { 0, 1 },
[1] = { 1, 1 },
[2] = { 2, 1 },
[3] = { 3, 1 },
[4] = { 4, 1 },
[5] = { 5, 1 }
}
}
}
uint32_t v_nr
Definition: xcode.c:63
static char data[]
Definition: xcode.c:136
struct top::v t_v
static struct top T
Definition: xcode.c:138

Definition at line 138 of file xcode.c.

◆ vec

void* vec = ebuf
static

Definition at line 168 of file xcode.c.

◆ xcode_ut

struct m0_ut_suite xcode_ut
Initial value:
= {
.ts_name = "xcode-ut",
.ts_init = xcode_init,
.ts_fini = NULL,
.ts_tests = {
{ "xcode-cursor", xcode_cursor_test },
{ "xcode-length", xcode_length_test },
{ "xcode-encode", xcode_encode_test },
{ "xcode-opaque", xcode_opaque_test },
{ "xcode-decode", xcode_decode_test },
{ "xcode-nonstandard", xcode_nonstandard_test },
{ "xcode-cmp", xcode_cmp_test },
{ "xcode-read", xcode_read_test },
{ "xcode-print", xcode_print_test },
{ "xcode-find", xcode_find_test },
{ "xcode-enum-gccxml", xcode_enum_gccxml, "Nikita" },
{ "xcode-enum-print", xcode_enum_print, "Nikita" },
{ "xcode-enum-read", xcode_enum_read, "Nikita" },
{ "xcode-bitmask-print", xcode_bitmask_print, "Nikita" },
{ "xcode-bitmask-read", xcode_bitmask_read, "Nikita" },
{ "xcode-enum-loop", xcode_enum_loop, "Nikita" },
{ "xcode-enum-field", xcode_enum_field, "Nikita" },
{ "xcode-iterate", xcode_iterate, "Nikita" },
{ "xcode-flags", xcode_flags, "Nikita" },
{ NULL, NULL }
}
}
static void xcode_find_test(void)
Definition: xcode.c:923
#define NULL
Definition: misc.h:38
static int xcode_init(void)
Definition: xcode.c:214
static void xcode_length_test(void)
Definition: xcode.c:455
static void xcode_enum_gccxml(void)
Definition: xcode.c:952
static void xcode_opaque_test(void)
Definition: xcode.c:476
static void xcode_encode_test(void)
Definition: xcode.c:464
static void xcode_decode_test(void)
Definition: xcode.c:501
static void xcode_enum_read(void)
Definition: xcode.c:994
static void xcode_nonstandard_test(void)
Definition: xcode.c:575
static void xcode_read_test(void)
Definition: xcode.c:692
static void xcode_cursor_test(void)
Definition: xcode.c:379
static void xcode_enum_field(void)
Definition: xcode.c:1139
static void xcode_enum_loop(void)
Definition: xcode.c:1111
static void xcode_flags(void)
Definition: xcode.c:1233
static void xcode_print_test(void)
Definition: xcode.c:863
static void xcode_iterate(void)
Definition: xcode.c:1174
static void xcode_enum_print(void)
Definition: xcode.c:967
static void xcode_bitmask_print(void)
Definition: xcode.c:1023
static void xcode_cmp_test(void)
Definition: xcode.c:602
static void xcode_bitmask_read(void)
Definition: xcode.c:1066

Definition at line 1273 of file xcode.c.

◆ xut_ar

struct static_xt xut_ar
static
Initial value:
= {
.xt = {
.xct_aggr = M0_XA_ARRAY,
.xct_name = "ar",
.xct_sizeof = sizeof (struct ar),
.xct_nr = 1
}
}
Definition: xcode.c:55

Definition at line 118 of file xcode.c.

◆ xut_foo

struct static_xt xut_foo
static
Initial value:
= {
.xt = {
.xct_aggr = M0_XA_RECORD,
.xct_name = "foo",
.xct_sizeof = sizeof (struct foo),
.xct_nr = 2
}
}
Definition: bob.c:32

Definition at line 109 of file xcode.c.

◆ xut_tdef

struct static_xt xut_tdef
static
Initial value:
= {
.xt = {
.xct_aggr = M0_XA_TYPEDEF,
.xct_name = "tdef",
.xct_sizeof = sizeof (tdef),
.xct_nr = 1
}
}
uint32_t tdef
Definition: xcode.c:43

Definition at line 91 of file xcode.c.

◆ xut_top

struct static_xt xut_top
static
Initial value:
= {
.xt = {
.xct_aggr = M0_XA_RECORD,
.xct_name = "top",
.xct_sizeof = sizeof (struct top),
.xct_nr = 7
}
}
Definition: xcode.c:59

Definition at line 127 of file xcode.c.

◆ xut_un

struct static_xt xut_un
static
Initial value:
= {
.xt = {
.xct_aggr = M0_XA_UNION,
.xct_name = "un",
.xct_sizeof = sizeof (struct un),
.xct_nr = 3
}
}
Definition: xcode.c:45

Definition at line 82 of file xcode.c.

◆ xut_v

struct static_xt xut_v
static
Initial value:
= {
.xt = {
.xct_aggr = M0_XA_SEQUENCE,
.xct_name = "v",
.xct_sizeof = sizeof (struct v),
.xct_nr = 2
}
}

Definition at line 100 of file xcode.c.