mie: add macros for defining dialect and dialect types/ops
This commit is contained in:
70
mie/include/mie/macros.h
Normal file
70
mie/include/mie/macros.h
Normal file
@@ -0,0 +1,70 @@
|
||||
#ifndef MIE_MACROS_H_
|
||||
#define MIE_MACROS_H_
|
||||
|
||||
#define __MIE_DIALECT_BEGIN(func_prefix, dialect_name) \
|
||||
struct mie_dialect *func_prefix##_dialect_create(struct mie_ctx *ctx) \
|
||||
{ \
|
||||
struct mie_dialect *self = mie_dialect_create(ctx, dialect_name); \
|
||||
if (!self) { \
|
||||
return NULL; \
|
||||
} \
|
||||
struct mie_dialect_op *op = NULL; \
|
||||
struct mie_dialect_type *type = NULL;
|
||||
|
||||
#define __MIE_DIALECT_END() \
|
||||
return self; \
|
||||
}
|
||||
|
||||
#define __MIE_DIALECT_OP_BEGIN(func_prefix, op_name) \
|
||||
struct mie_dialect_op *func_prefix##_op_create(struct mie_dialect *d) \
|
||||
{ \
|
||||
struct mie_dialect_op *op = mie_dialect_op_create(d, op_name); \
|
||||
if (!op) { \
|
||||
return NULL; \
|
||||
}
|
||||
|
||||
#define __MIE_DIALECT_OP_END() \
|
||||
return op; \
|
||||
}
|
||||
|
||||
#define __MIE_DIALECT_TYPE_BEGIN(func_prefix, type_name) \
|
||||
struct mie_dialect_type *func_prefix##_type_create(struct mie_dialect *d) \
|
||||
{ \
|
||||
struct mie_dialect_type *type \
|
||||
= mie_dialect_type_create(d, type_name); \
|
||||
if (!type) { \
|
||||
return NULL; \
|
||||
}
|
||||
|
||||
#define __MIE_DIALECT_TYPE_END() \
|
||||
return type; \
|
||||
}
|
||||
|
||||
#define __MIE_DIALECT_ADD_OP(op_id) \
|
||||
extern struct mie_dialect_op *op_id##_op_create(struct mie_dialect *); \
|
||||
op = op_id##_op_create(self)
|
||||
#define __MIE_DIALECT_ADD_TYPE(type_id) \
|
||||
extern struct mie_dialect_type *type_id##_type_create( \
|
||||
struct mie_dialect *); \
|
||||
type = type_id##_type_create(self)
|
||||
|
||||
#define MIE_DIALECT_BEGIN(c_sym, name) __MIE_DIALECT_BEGIN(c_sym, name)
|
||||
#define MIE_DIALECT_END() __MIE_DIALECT_END()
|
||||
#define MIE_DIALECT_ADD_OP(c_sym) __MIE_DIALECT_ADD_OP(c_sym)
|
||||
#define MIE_DIALECT_ADD_TYPE(c_sym) __MIE_DIALECT_ADD_TYPE(c_sym)
|
||||
|
||||
#define MIE_DIALECT_OP_BEGIN(c_sym, op) __MIE_DIALECT_OP_BEGIN(c_sym, op)
|
||||
#define MIE_DIALECT_OP_END() __MIE_DIALECT_OP_END()
|
||||
#define MIE_DIALECT_OP_PRINT(func) op->op_print = (func)
|
||||
#define MIE_DIALECT_OP_PARSE(func) op->op_parse = (func)
|
||||
|
||||
#define MIE_DIALECT_TYPE_BEGIN(c_sym, type) \
|
||||
__MIE_DIALECT_TYPE_BEGIN(c_sym, type)
|
||||
#define MIE_DIALECT_TYPE_END() __MIE_DIALECT_TYPE_END()
|
||||
#define MIE_DIALECT_TYPE_STRUCT(name) type->ty_data_size = sizeof(name)
|
||||
#define MIE_DIALECT_TYPE_PRINT(func) type->ty_print = (func)
|
||||
#define MIE_DIALECT_TYPE_PARSE(func) type->ty_parse = (func)
|
||||
#define MIE_DIALECT_TYPE_INIT(func) type->ty_init = (func)
|
||||
#define MIE_DIALECT_TYPE_CLEANUP(func) type->ty_cleanup = (func)
|
||||
|
||||
#endif
|
||||
Reference in New Issue
Block a user