qapi: De-duplicate enum code generation

Duplicated in commit 21cd70d. Yes, we can't import qapi-types, but
that's no excuse. Move the helpers from qapi-types.py to qapi.py, and
replace the duplicates in qapi-event.py.

The generated event enumeration type's lookup table becomes
const-correct (see commit 2e4450f), and uses explicit indexes instead
of relying on order (see commit 912ae9c).

Backports commit efd2eaa6c2992c214a13f102b6ddd4dca4697fb3 from qemu
This commit is contained in:
Markus Armbruster 2018-02-19 17:08:05 -05:00 committed by Lioncash
parent baa36c6c88
commit 782a549898
No known key found for this signature in database
GPG key ID: 4E3C3CC1031BA9C7
7 changed files with 696 additions and 729 deletions

View file

@ -18,7 +18,7 @@
#include "qapi-types.h"
#include "qapi-visit.h"
const char *ErrorClass_lookup[] = {
const char *const ErrorClass_lookup[] = {
"GenericError",
"CommandNotFound",
"DeviceEncrypted",
@ -28,7 +28,7 @@ const char *ErrorClass_lookup[] = {
NULL,
};
const char *X86CPURegister32_lookup[] = {
const char *const X86CPURegister32_lookup[] = {
"EAX",
"EBX",
"ECX",
@ -40,12 +40,7 @@ const char *X86CPURegister32_lookup[] = {
NULL,
};
#ifndef QAPI_TYPES_BUILTIN_CLEANUP_DEF_H
#define QAPI_TYPES_BUILTIN_CLEANUP_DEF_H
void qapi_free_int32List(int32List *obj)
void qapi_free_ErrorClassList(ErrorClassList *obj)
{
QapiDeallocVisitor *md;
Visitor *v;
@ -56,11 +51,11 @@ void qapi_free_int32List(int32List *obj)
md = qapi_dealloc_visitor_new();
v = qapi_dealloc_get_visitor(md);
visit_type_int32List(v, &obj, NULL, NULL);
visit_type_ErrorClassList(v, &obj, NULL, NULL);
qapi_dealloc_visitor_cleanup(md);
}
void qapi_free_int16List(int16List *obj)
void qapi_free_X86CPUFeatureWordInfo(X86CPUFeatureWordInfo *obj)
{
QapiDeallocVisitor *md;
Visitor *v;
@ -71,11 +66,11 @@ void qapi_free_int16List(int16List *obj)
md = qapi_dealloc_visitor_new();
v = qapi_dealloc_get_visitor(md);
visit_type_int16List(v, &obj, NULL, NULL);
visit_type_X86CPUFeatureWordInfo(v, &obj, NULL, NULL);
qapi_dealloc_visitor_cleanup(md);
}
void qapi_free_intList(intList *obj)
void qapi_free_X86CPUFeatureWordInfoList(X86CPUFeatureWordInfoList *obj)
{
QapiDeallocVisitor *md;
Visitor *v;
@ -86,11 +81,11 @@ void qapi_free_intList(intList *obj)
md = qapi_dealloc_visitor_new();
v = qapi_dealloc_get_visitor(md);
visit_type_intList(v, &obj, NULL, NULL);
visit_type_X86CPUFeatureWordInfoList(v, &obj, NULL, NULL);
qapi_dealloc_visitor_cleanup(md);
}
void qapi_free_uint8List(uint8List *obj)
void qapi_free_X86CPURegister32List(X86CPURegister32List *obj)
{
QapiDeallocVisitor *md;
Visitor *v;
@ -101,82 +96,7 @@ void qapi_free_uint8List(uint8List *obj)
md = qapi_dealloc_visitor_new();
v = qapi_dealloc_get_visitor(md);
visit_type_uint8List(v, &obj, NULL, NULL);
qapi_dealloc_visitor_cleanup(md);
}
void qapi_free_numberList(numberList *obj)
{
QapiDeallocVisitor *md;
Visitor *v;
if (!obj) {
return;
}
md = qapi_dealloc_visitor_new();
v = qapi_dealloc_get_visitor(md);
visit_type_numberList(v, &obj, NULL, NULL);
qapi_dealloc_visitor_cleanup(md);
}
void qapi_free_int8List(int8List *obj)
{
QapiDeallocVisitor *md;
Visitor *v;
if (!obj) {
return;
}
md = qapi_dealloc_visitor_new();
v = qapi_dealloc_get_visitor(md);
visit_type_int8List(v, &obj, NULL, NULL);
qapi_dealloc_visitor_cleanup(md);
}
void qapi_free_sizeList(sizeList *obj)
{
QapiDeallocVisitor *md;
Visitor *v;
if (!obj) {
return;
}
md = qapi_dealloc_visitor_new();
v = qapi_dealloc_get_visitor(md);
visit_type_sizeList(v, &obj, NULL, NULL);
qapi_dealloc_visitor_cleanup(md);
}
void qapi_free_uint64List(uint64List *obj)
{
QapiDeallocVisitor *md;
Visitor *v;
if (!obj) {
return;
}
md = qapi_dealloc_visitor_new();
v = qapi_dealloc_get_visitor(md);
visit_type_uint64List(v, &obj, NULL, NULL);
qapi_dealloc_visitor_cleanup(md);
}
void qapi_free_uint16List(uint16List *obj)
{
QapiDeallocVisitor *md;
Visitor *v;
if (!obj) {
return;
}
md = qapi_dealloc_visitor_new();
v = qapi_dealloc_get_visitor(md);
visit_type_uint16List(v, &obj, NULL, NULL);
visit_type_X86CPURegister32List(v, &obj, NULL, NULL);
qapi_dealloc_visitor_cleanup(md);
}
@ -195,7 +115,7 @@ void qapi_free_boolList(boolList *obj)
qapi_dealloc_visitor_cleanup(md);
}
void qapi_free_strList(strList *obj)
void qapi_free_int16List(int16List *obj)
{
QapiDeallocVisitor *md;
Visitor *v;
@ -206,7 +126,22 @@ void qapi_free_strList(strList *obj)
md = qapi_dealloc_visitor_new();
v = qapi_dealloc_get_visitor(md);
visit_type_strList(v, &obj, NULL, NULL);
visit_type_int16List(v, &obj, NULL, NULL);
qapi_dealloc_visitor_cleanup(md);
}
void qapi_free_int32List(int32List *obj)
{
QapiDeallocVisitor *md;
Visitor *v;
if (!obj) {
return;
}
md = qapi_dealloc_visitor_new();
v = qapi_dealloc_get_visitor(md);
visit_type_int32List(v, &obj, NULL, NULL);
qapi_dealloc_visitor_cleanup(md);
}
@ -225,6 +160,96 @@ void qapi_free_int64List(int64List *obj)
qapi_dealloc_visitor_cleanup(md);
}
void qapi_free_int8List(int8List *obj)
{
QapiDeallocVisitor *md;
Visitor *v;
if (!obj) {
return;
}
md = qapi_dealloc_visitor_new();
v = qapi_dealloc_get_visitor(md);
visit_type_int8List(v, &obj, NULL, NULL);
qapi_dealloc_visitor_cleanup(md);
}
void qapi_free_intList(intList *obj)
{
QapiDeallocVisitor *md;
Visitor *v;
if (!obj) {
return;
}
md = qapi_dealloc_visitor_new();
v = qapi_dealloc_get_visitor(md);
visit_type_intList(v, &obj, NULL, NULL);
qapi_dealloc_visitor_cleanup(md);
}
void qapi_free_numberList(numberList *obj)
{
QapiDeallocVisitor *md;
Visitor *v;
if (!obj) {
return;
}
md = qapi_dealloc_visitor_new();
v = qapi_dealloc_get_visitor(md);
visit_type_numberList(v, &obj, NULL, NULL);
qapi_dealloc_visitor_cleanup(md);
}
void qapi_free_sizeList(sizeList *obj)
{
QapiDeallocVisitor *md;
Visitor *v;
if (!obj) {
return;
}
md = qapi_dealloc_visitor_new();
v = qapi_dealloc_get_visitor(md);
visit_type_sizeList(v, &obj, NULL, NULL);
qapi_dealloc_visitor_cleanup(md);
}
void qapi_free_strList(strList *obj)
{
QapiDeallocVisitor *md;
Visitor *v;
if (!obj) {
return;
}
md = qapi_dealloc_visitor_new();
v = qapi_dealloc_get_visitor(md);
visit_type_strList(v, &obj, NULL, NULL);
qapi_dealloc_visitor_cleanup(md);
}
void qapi_free_uint16List(uint16List *obj)
{
QapiDeallocVisitor *md;
Visitor *v;
if (!obj) {
return;
}
md = qapi_dealloc_visitor_new();
v = qapi_dealloc_get_visitor(md);
visit_type_uint16List(v, &obj, NULL, NULL);
qapi_dealloc_visitor_cleanup(md);
}
void qapi_free_uint32List(uint32List *obj)
{
QapiDeallocVisitor *md;
@ -240,10 +265,7 @@ void qapi_free_uint32List(uint32List *obj)
qapi_dealloc_visitor_cleanup(md);
}
#endif /* QAPI_TYPES_BUILTIN_CLEANUP_DEF_H */
void qapi_free_ErrorClassList(ErrorClassList *obj)
void qapi_free_uint64List(uint64List *obj)
{
QapiDeallocVisitor *md;
Visitor *v;
@ -254,12 +276,11 @@ void qapi_free_ErrorClassList(ErrorClassList *obj)
md = qapi_dealloc_visitor_new();
v = qapi_dealloc_get_visitor(md);
visit_type_ErrorClassList(v, &obj, NULL, NULL);
visit_type_uint64List(v, &obj, NULL, NULL);
qapi_dealloc_visitor_cleanup(md);
}
void qapi_free_X86CPURegister32List(X86CPURegister32List *obj)
void qapi_free_uint8List(uint8List *obj)
{
QapiDeallocVisitor *md;
Visitor *v;
@ -270,39 +291,6 @@ void qapi_free_X86CPURegister32List(X86CPURegister32List *obj)
md = qapi_dealloc_visitor_new();
v = qapi_dealloc_get_visitor(md);
visit_type_X86CPURegister32List(v, &obj, NULL, NULL);
visit_type_uint8List(v, &obj, NULL, NULL);
qapi_dealloc_visitor_cleanup(md);
}
void qapi_free_X86CPUFeatureWordInfoList(X86CPUFeatureWordInfoList *obj)
{
QapiDeallocVisitor *md;
Visitor *v;
if (!obj) {
return;
}
md = qapi_dealloc_visitor_new();
v = qapi_dealloc_get_visitor(md);
visit_type_X86CPUFeatureWordInfoList(v, &obj, NULL, NULL);
qapi_dealloc_visitor_cleanup(md);
}
void qapi_free_X86CPUFeatureWordInfo(X86CPUFeatureWordInfo *obj)
{
QapiDeallocVisitor *md;
Visitor *v;
if (!obj) {
return;
}
md = qapi_dealloc_visitor_new();
v = qapi_dealloc_get_visitor(md);
visit_type_X86CPUFeatureWordInfo(v, &obj, NULL, NULL);
qapi_dealloc_visitor_cleanup(md);
}

View file

@ -18,133 +18,143 @@
#include "unicorn/platform.h"
#ifndef QAPI_TYPES_BUILTIN_STRUCT_DECL_H
#define QAPI_TYPES_BUILTIN_STRUCT_DECL_H
#ifndef QAPI_TYPES_BUILTIN
#define QAPI_TYPES_BUILTIN
typedef struct int32List
{
union {
int32_t value;
uint64_t padding;
};
struct int32List *next;
} int32List;
typedef struct int16List
{
union {
int16_t value;
uint64_t padding;
};
struct int16List *next;
} int16List;
typedef struct intList
{
union {
int64_t value;
uint64_t padding;
};
struct intList *next;
} intList;
typedef struct uint8List
{
union {
uint8_t value;
uint64_t padding;
};
struct uint8List *next;
} uint8List;
typedef struct numberList
{
union {
double value;
uint64_t padding;
};
struct numberList *next;
} numberList;
typedef struct int8List
{
union {
int8_t value;
uint64_t padding;
};
struct int8List *next;
} int8List;
typedef struct sizeList
{
union {
uint64_t value;
uint64_t padding;
};
struct sizeList *next;
} sizeList;
typedef struct uint64List
{
union {
uint64_t value;
uint64_t padding;
};
struct uint64List *next;
} uint64List;
typedef struct uint16List
{
union {
uint16_t value;
uint64_t padding;
};
struct uint16List *next;
} uint16List;
typedef struct boolList
{
typedef struct boolList boolList;
struct boolList {
union {
bool value;
uint64_t padding;
};
struct boolList *next;
} boolList;
};
void qapi_free_boolList(boolList *obj);
typedef struct strList
{
typedef struct int16List int16List;
struct int16List {
union {
char *value;
int16_t value;
uint64_t padding;
};
struct strList *next;
} strList;
struct int16List *next;
};
void qapi_free_int16List(int16List *obj);
typedef struct int64List
{
typedef struct int32List int32List;
struct int32List {
union {
int32_t value;
uint64_t padding;
};
struct int32List *next;
};
void qapi_free_int32List(int32List *obj);
typedef struct int64List int64List;
struct int64List {
union {
int64_t value;
uint64_t padding;
};
struct int64List *next;
} int64List;
};
void qapi_free_int64List(int64List *obj);
typedef struct uint32List
{
typedef struct int8List int8List;
struct int8List {
union {
int8_t value;
uint64_t padding;
};
struct int8List *next;
};
void qapi_free_int8List(int8List *obj);
typedef struct intList intList;
struct intList {
union {
int64_t value;
uint64_t padding;
};
struct intList *next;
};
void qapi_free_intList(intList *obj);
typedef struct numberList numberList;
struct numberList {
union {
double value;
uint64_t padding;
};
struct numberList *next;
};
void qapi_free_numberList(numberList *obj);
typedef struct sizeList sizeList;
struct sizeList {
union {
uint64_t value;
uint64_t padding;
};
struct sizeList *next;
};
void qapi_free_sizeList(sizeList *obj);
typedef struct strList strList;
struct strList {
union {
char *value;
uint64_t padding;
};
struct strList *next;
};
void qapi_free_strList(strList *obj);
typedef struct uint16List uint16List;
struct uint16List {
union {
uint16_t value;
uint64_t padding;
};
struct uint16List *next;
};
void qapi_free_uint16List(uint16List *obj);
typedef struct uint32List uint32List;
struct uint32List {
union {
uint32_t value;
uint64_t padding;
};
struct uint32List *next;
} uint32List;
};
void qapi_free_uint32List(uint32List *obj);
#endif /* QAPI_TYPES_BUILTIN_STRUCT_DECL_H */
typedef struct uint64List uint64List;
struct uint64List {
union {
uint64_t value;
uint64_t padding;
};
struct uint64List *next;
};
void qapi_free_uint64List(uint64List *obj);
typedef struct uint8List uint8List;
struct uint8List {
union {
uint8_t value;
uint64_t padding;
};
struct uint8List *next;
};
void qapi_free_uint8List(uint8List *obj);
extern const char *ErrorClass_lookup[];
typedef enum ErrorClass
{
#endif /* QAPI_TYPES_BUILTIN */
typedef enum ErrorClass {
ERROR_CLASS_GENERIC_ERROR = 0,
ERROR_CLASS_COMMAND_NOT_FOUND = 1,
ERROR_CLASS_DEVICE_ENCRYPTED = 2,
@ -153,19 +163,14 @@ typedef enum ErrorClass
ERROR_CLASS_KVM_MISSING_CAP = 5,
ERROR_CLASS_MAX = 6,
} ErrorClass;
extern const char *const ErrorClass_lookup[];
typedef struct ErrorClassList
{
union {
ErrorClass value;
uint64_t padding;
};
struct ErrorClassList *next;
} ErrorClassList;
typedef struct ErrorClassList ErrorClassList;
extern const char *X86CPURegister32_lookup[];
typedef enum X86CPURegister32
{
typedef struct X86CPUFeatureWordInfo X86CPUFeatureWordInfo;
typedef struct X86CPUFeatureWordInfoList X86CPUFeatureWordInfoList;
typedef enum X86CPURegister32 {
X86_CPU_REGISTER32_EAX = 0,
X86_CPU_REGISTER32_EBX = 1,
X86_CPU_REGISTER32_ECX = 2,
@ -176,62 +181,40 @@ typedef enum X86CPURegister32
X86_CPU_REGISTER32_EDI = 7,
X86_CPU_REGISTER32_MAX = 8,
} X86CPURegister32;
extern const char *const X86CPURegister32_lookup[];
typedef struct X86CPURegister32List
{
typedef struct X86CPURegister32List X86CPURegister32List;
struct ErrorClassList {
union {
X86CPURegister32 value;
ErrorClass value;
uint64_t padding;
};
struct X86CPURegister32List *next;
} X86CPURegister32List;
typedef struct X86CPUFeatureWordInfo X86CPUFeatureWordInfo;
typedef struct X86CPUFeatureWordInfoList
{
union {
X86CPUFeatureWordInfo *value;
uint64_t padding;
};
struct X86CPUFeatureWordInfoList *next;
} X86CPUFeatureWordInfoList;
#ifndef QAPI_TYPES_BUILTIN_CLEANUP_DECL_H
#define QAPI_TYPES_BUILTIN_CLEANUP_DECL_H
void qapi_free_int32List(int32List *obj);
void qapi_free_int16List(int16List *obj);
void qapi_free_intList(intList *obj);
void qapi_free_uint8List(uint8List *obj);
void qapi_free_numberList(numberList *obj);
void qapi_free_int8List(int8List *obj);
void qapi_free_sizeList(sizeList *obj);
void qapi_free_uint64List(uint64List *obj);
void qapi_free_uint16List(uint16List *obj);
void qapi_free_boolList(boolList *obj);
void qapi_free_strList(strList *obj);
void qapi_free_int64List(int64List *obj);
void qapi_free_uint32List(uint32List *obj);
#endif /* QAPI_TYPES_BUILTIN_CLEANUP_DECL_H */
struct ErrorClassList *next;
};
void qapi_free_ErrorClassList(ErrorClassList *obj);
void qapi_free_X86CPURegister32List(X86CPURegister32List *obj);
struct X86CPUFeatureWordInfo
{
struct X86CPUFeatureWordInfo {
int64_t cpuid_input_eax;
bool has_cpuid_input_ecx;
int64_t cpuid_input_ecx;
X86CPURegister32 cpuid_register;
int64_t features;
};
void qapi_free_X86CPUFeatureWordInfoList(X86CPUFeatureWordInfoList *obj);
void qapi_free_X86CPUFeatureWordInfo(X86CPUFeatureWordInfo *obj);
struct X86CPUFeatureWordInfoList {
union {
X86CPUFeatureWordInfo *value;
uint64_t padding;
};
struct X86CPUFeatureWordInfoList *next;
};
void qapi_free_X86CPUFeatureWordInfoList(X86CPUFeatureWordInfoList *obj);
struct X86CPURegister32List {
union {
X86CPURegister32 value;
uint64_t padding;
};
struct X86CPURegister32List *next;
};
void qapi_free_X86CPURegister32List(X86CPURegister32List *obj);
#endif

View file

@ -16,316 +16,9 @@
#include "qemu-common.h"
#include "qapi-visit.h"
void visit_type_int32List(Visitor *m, int32List **obj, const char *name, Error **errp)
void visit_type_ErrorClass(Visitor *m, ErrorClass *obj, const char *name, Error **errp)
{
Error *err = NULL;
GenericList *i, **prev;
visit_start_list(m, name, &err);
if (err) {
goto out;
}
for (prev = (GenericList **)obj;
!err && (i = visit_next_list(m, prev)) != NULL;
prev = &i) {
int32List *native_i = (int32List *)i;
visit_type_int32(m, &native_i->value, NULL, &err);
}
error_propagate(errp, err);
err = NULL;
visit_end_list(m);
out:
error_propagate(errp, err);
}
void visit_type_int16List(Visitor *m, int16List **obj, const char *name, Error **errp)
{
Error *err = NULL;
GenericList *i, **prev;
visit_start_list(m, name, &err);
if (err) {
goto out;
}
for (prev = (GenericList **)obj;
!err && (i = visit_next_list(m, prev)) != NULL;
prev = &i) {
int16List *native_i = (int16List *)i;
visit_type_int16(m, &native_i->value, NULL, &err);
}
error_propagate(errp, err);
err = NULL;
visit_end_list(m);
out:
error_propagate(errp, err);
}
void visit_type_intList(Visitor *m, intList **obj, const char *name, Error **errp)
{
Error *err = NULL;
GenericList *i, **prev;
visit_start_list(m, name, &err);
if (err) {
goto out;
}
for (prev = (GenericList **)obj;
!err && (i = visit_next_list(m, prev)) != NULL;
prev = &i) {
intList *native_i = (intList *)i;
visit_type_int(m, &native_i->value, NULL, &err);
}
error_propagate(errp, err);
err = NULL;
visit_end_list(m);
out:
error_propagate(errp, err);
}
void visit_type_uint8List(Visitor *m, uint8List **obj, const char *name, Error **errp)
{
Error *err = NULL;
GenericList *i, **prev;
visit_start_list(m, name, &err);
if (err) {
goto out;
}
for (prev = (GenericList **)obj;
!err && (i = visit_next_list(m, prev)) != NULL;
prev = &i) {
uint8List *native_i = (uint8List *)i;
visit_type_uint8(m, &native_i->value, NULL, &err);
}
error_propagate(errp, err);
err = NULL;
visit_end_list(m);
out:
error_propagate(errp, err);
}
void visit_type_numberList(Visitor *m, numberList **obj, const char *name, Error **errp)
{
Error *err = NULL;
GenericList *i, **prev;
visit_start_list(m, name, &err);
if (err) {
goto out;
}
for (prev = (GenericList **)obj;
!err && (i = visit_next_list(m, prev)) != NULL;
prev = &i) {
numberList *native_i = (numberList *)i;
visit_type_number(m, &native_i->value, NULL, &err);
}
error_propagate(errp, err);
err = NULL;
visit_end_list(m);
out:
error_propagate(errp, err);
}
void visit_type_int8List(Visitor *m, int8List **obj, const char *name, Error **errp)
{
Error *err = NULL;
GenericList *i, **prev;
visit_start_list(m, name, &err);
if (err) {
goto out;
}
for (prev = (GenericList **)obj;
!err && (i = visit_next_list(m, prev)) != NULL;
prev = &i) {
int8List *native_i = (int8List *)i;
visit_type_int8(m, &native_i->value, NULL, &err);
}
error_propagate(errp, err);
err = NULL;
visit_end_list(m);
out:
error_propagate(errp, err);
}
void visit_type_sizeList(Visitor *m, sizeList **obj, const char *name, Error **errp)
{
Error *err = NULL;
GenericList *i, **prev;
visit_start_list(m, name, &err);
if (err) {
goto out;
}
for (prev = (GenericList **)obj;
!err && (i = visit_next_list(m, prev)) != NULL;
prev = &i) {
sizeList *native_i = (sizeList *)i;
visit_type_size(m, &native_i->value, NULL, &err);
}
error_propagate(errp, err);
err = NULL;
visit_end_list(m);
out:
error_propagate(errp, err);
}
void visit_type_uint64List(Visitor *m, uint64List **obj, const char *name, Error **errp)
{
Error *err = NULL;
GenericList *i, **prev;
visit_start_list(m, name, &err);
if (err) {
goto out;
}
for (prev = (GenericList **)obj;
!err && (i = visit_next_list(m, prev)) != NULL;
prev = &i) {
uint64List *native_i = (uint64List *)i;
visit_type_uint64(m, &native_i->value, NULL, &err);
}
error_propagate(errp, err);
err = NULL;
visit_end_list(m);
out:
error_propagate(errp, err);
}
void visit_type_uint16List(Visitor *m, uint16List **obj, const char *name, Error **errp)
{
Error *err = NULL;
GenericList *i, **prev;
visit_start_list(m, name, &err);
if (err) {
goto out;
}
for (prev = (GenericList **)obj;
!err && (i = visit_next_list(m, prev)) != NULL;
prev = &i) {
uint16List *native_i = (uint16List *)i;
visit_type_uint16(m, &native_i->value, NULL, &err);
}
error_propagate(errp, err);
err = NULL;
visit_end_list(m);
out:
error_propagate(errp, err);
}
void visit_type_boolList(Visitor *m, boolList **obj, const char *name, Error **errp)
{
Error *err = NULL;
GenericList *i, **prev;
visit_start_list(m, name, &err);
if (err) {
goto out;
}
for (prev = (GenericList **)obj;
!err && (i = visit_next_list(m, prev)) != NULL;
prev = &i) {
boolList *native_i = (boolList *)i;
visit_type_bool(m, &native_i->value, NULL, &err);
}
error_propagate(errp, err);
err = NULL;
visit_end_list(m);
out:
error_propagate(errp, err);
}
void visit_type_strList(Visitor *m, strList **obj, const char *name, Error **errp)
{
Error *err = NULL;
GenericList *i, **prev;
visit_start_list(m, name, &err);
if (err) {
goto out;
}
for (prev = (GenericList **)obj;
!err && (i = visit_next_list(m, prev)) != NULL;
prev = &i) {
strList *native_i = (strList *)i;
visit_type_str(m, &native_i->value, NULL, &err);
}
error_propagate(errp, err);
err = NULL;
visit_end_list(m);
out:
error_propagate(errp, err);
}
void visit_type_int64List(Visitor *m, int64List **obj, const char *name, Error **errp)
{
Error *err = NULL;
GenericList *i, **prev;
visit_start_list(m, name, &err);
if (err) {
goto out;
}
for (prev = (GenericList **)obj;
!err && (i = visit_next_list(m, prev)) != NULL;
prev = &i) {
int64List *native_i = (int64List *)i;
visit_type_int64(m, &native_i->value, NULL, &err);
}
error_propagate(errp, err);
err = NULL;
visit_end_list(m);
out:
error_propagate(errp, err);
}
void visit_type_uint32List(Visitor *m, uint32List **obj, const char *name, Error **errp)
{
Error *err = NULL;
GenericList *i, **prev;
visit_start_list(m, name, &err);
if (err) {
goto out;
}
for (prev = (GenericList **)obj;
!err && (i = visit_next_list(m, prev)) != NULL;
prev = &i) {
uint32List *native_i = (uint32List *)i;
visit_type_uint32(m, &native_i->value, NULL, &err);
}
error_propagate(errp, err);
err = NULL;
visit_end_list(m);
out:
error_propagate(errp, err);
visit_type_enum(m, (int *)obj, ErrorClass_lookup, "ErrorClass", name, errp);
}
void visit_type_ErrorClassList(Visitor *m, ErrorClassList **obj, const char *name, Error **errp)
@ -352,43 +45,10 @@ out:
error_propagate(errp, err);
}
void visit_type_ErrorClass(Visitor *m, ErrorClass *obj, const char *name, Error **errp)
{
visit_type_enum(m, (int *)obj, ErrorClass_lookup, "ErrorClass", name, errp);
}
void visit_type_X86CPURegister32List(Visitor *m, X86CPURegister32List **obj, const char *name, Error **errp)
{
Error *err = NULL;
GenericList *i, **prev;
visit_start_list(m, name, &err);
if (err) {
goto out;
}
for (prev = (GenericList **)obj;
!err && (i = visit_next_list(m, prev)) != NULL;
prev = &i) {
X86CPURegister32List *native_i = (X86CPURegister32List *)i;
visit_type_X86CPURegister32(m, &native_i->value, NULL, &err);
}
error_propagate(errp, err);
err = NULL;
visit_end_list(m);
out:
error_propagate(errp, err);
}
void visit_type_X86CPURegister32(Visitor *m, X86CPURegister32 *obj, const char *name, Error **errp)
{
visit_type_enum(m, (int *)obj, X86CPURegister32_lookup, "X86CPURegister32", name, errp);
}
static void visit_type_X86CPUFeatureWordInfo_fields(Visitor *m, X86CPUFeatureWordInfo **obj, Error **errp)
{
Error *err = NULL;
visit_type_int(m, &(*obj)->cpuid_input_eax, "cpuid-input-eax", &err);
if (err) {
goto out;
@ -451,3 +111,344 @@ void visit_type_X86CPUFeatureWordInfoList(Visitor *m, X86CPUFeatureWordInfoList
out:
error_propagate(errp, err);
}
void visit_type_X86CPURegister32(Visitor *m, X86CPURegister32 *obj, const char *name, Error **errp)
{
visit_type_enum(m, (int *)obj, X86CPURegister32_lookup, "X86CPURegister32", name, errp);
}
void visit_type_X86CPURegister32List(Visitor *m, X86CPURegister32List **obj, const char *name, Error **errp)
{
Error *err = NULL;
GenericList *i, **prev;
visit_start_list(m, name, &err);
if (err) {
goto out;
}
for (prev = (GenericList **)obj;
!err && (i = visit_next_list(m, prev)) != NULL;
prev = &i) {
X86CPURegister32List *native_i = (X86CPURegister32List *)i;
visit_type_X86CPURegister32(m, &native_i->value, NULL, &err);
}
error_propagate(errp, err);
err = NULL;
visit_end_list(m);
out:
error_propagate(errp, err);
}
void visit_type_boolList(Visitor *m, boolList **obj, const char *name, Error **errp)
{
Error *err = NULL;
GenericList *i, **prev;
visit_start_list(m, name, &err);
if (err) {
goto out;
}
for (prev = (GenericList **)obj;
!err && (i = visit_next_list(m, prev)) != NULL;
prev = &i) {
boolList *native_i = (boolList *)i;
visit_type_bool(m, &native_i->value, NULL, &err);
}
error_propagate(errp, err);
err = NULL;
visit_end_list(m);
out:
error_propagate(errp, err);
}
void visit_type_int16List(Visitor *m, int16List **obj, const char *name, Error **errp)
{
Error *err = NULL;
GenericList *i, **prev;
visit_start_list(m, name, &err);
if (err) {
goto out;
}
for (prev = (GenericList **)obj;
!err && (i = visit_next_list(m, prev)) != NULL;
prev = &i) {
int16List *native_i = (int16List *)i;
visit_type_int16(m, &native_i->value, NULL, &err);
}
error_propagate(errp, err);
err = NULL;
visit_end_list(m);
out:
error_propagate(errp, err);
}
void visit_type_int32List(Visitor *m, int32List **obj, const char *name, Error **errp)
{
Error *err = NULL;
GenericList *i, **prev;
visit_start_list(m, name, &err);
if (err) {
goto out;
}
for (prev = (GenericList **)obj;
!err && (i = visit_next_list(m, prev)) != NULL;
prev = &i) {
int32List *native_i = (int32List *)i;
visit_type_int32(m, &native_i->value, NULL, &err);
}
error_propagate(errp, err);
err = NULL;
visit_end_list(m);
out:
error_propagate(errp, err);
}
void visit_type_int64List(Visitor *m, int64List **obj, const char *name, Error **errp)
{
Error *err = NULL;
GenericList *i, **prev;
visit_start_list(m, name, &err);
if (err) {
goto out;
}
for (prev = (GenericList **)obj;
!err && (i = visit_next_list(m, prev)) != NULL;
prev = &i) {
int64List *native_i = (int64List *)i;
visit_type_int64(m, &native_i->value, NULL, &err);
}
error_propagate(errp, err);
err = NULL;
visit_end_list(m);
out:
error_propagate(errp, err);
}
void visit_type_int8List(Visitor *m, int8List **obj, const char *name, Error **errp)
{
Error *err = NULL;
GenericList *i, **prev;
visit_start_list(m, name, &err);
if (err) {
goto out;
}
for (prev = (GenericList **)obj;
!err && (i = visit_next_list(m, prev)) != NULL;
prev = &i) {
int8List *native_i = (int8List *)i;
visit_type_int8(m, &native_i->value, NULL, &err);
}
error_propagate(errp, err);
err = NULL;
visit_end_list(m);
out:
error_propagate(errp, err);
}
void visit_type_intList(Visitor *m, intList **obj, const char *name, Error **errp)
{
Error *err = NULL;
GenericList *i, **prev;
visit_start_list(m, name, &err);
if (err) {
goto out;
}
for (prev = (GenericList **)obj;
!err && (i = visit_next_list(m, prev)) != NULL;
prev = &i) {
intList *native_i = (intList *)i;
visit_type_int(m, &native_i->value, NULL, &err);
}
error_propagate(errp, err);
err = NULL;
visit_end_list(m);
out:
error_propagate(errp, err);
}
void visit_type_numberList(Visitor *m, numberList **obj, const char *name, Error **errp)
{
Error *err = NULL;
GenericList *i, **prev;
visit_start_list(m, name, &err);
if (err) {
goto out;
}
for (prev = (GenericList **)obj;
!err && (i = visit_next_list(m, prev)) != NULL;
prev = &i) {
numberList *native_i = (numberList *)i;
visit_type_number(m, &native_i->value, NULL, &err);
}
error_propagate(errp, err);
err = NULL;
visit_end_list(m);
out:
error_propagate(errp, err);
}
void visit_type_sizeList(Visitor *m, sizeList **obj, const char *name, Error **errp)
{
Error *err = NULL;
GenericList *i, **prev;
visit_start_list(m, name, &err);
if (err) {
goto out;
}
for (prev = (GenericList **)obj;
!err && (i = visit_next_list(m, prev)) != NULL;
prev = &i) {
sizeList *native_i = (sizeList *)i;
visit_type_size(m, &native_i->value, NULL, &err);
}
error_propagate(errp, err);
err = NULL;
visit_end_list(m);
out:
error_propagate(errp, err);
}
void visit_type_strList(Visitor *m, strList **obj, const char *name, Error **errp)
{
Error *err = NULL;
GenericList *i, **prev;
visit_start_list(m, name, &err);
if (err) {
goto out;
}
for (prev = (GenericList **)obj;
!err && (i = visit_next_list(m, prev)) != NULL;
prev = &i) {
strList *native_i = (strList *)i;
visit_type_str(m, &native_i->value, NULL, &err);
}
error_propagate(errp, err);
err = NULL;
visit_end_list(m);
out:
error_propagate(errp, err);
}
void visit_type_uint16List(Visitor *m, uint16List **obj, const char *name, Error **errp)
{
Error *err = NULL;
GenericList *i, **prev;
visit_start_list(m, name, &err);
if (err) {
goto out;
}
for (prev = (GenericList **)obj;
!err && (i = visit_next_list(m, prev)) != NULL;
prev = &i) {
uint16List *native_i = (uint16List *)i;
visit_type_uint16(m, &native_i->value, NULL, &err);
}
error_propagate(errp, err);
err = NULL;
visit_end_list(m);
out:
error_propagate(errp, err);
}
void visit_type_uint32List(Visitor *m, uint32List **obj, const char *name, Error **errp)
{
Error *err = NULL;
GenericList *i, **prev;
visit_start_list(m, name, &err);
if (err) {
goto out;
}
for (prev = (GenericList **)obj;
!err && (i = visit_next_list(m, prev)) != NULL;
prev = &i) {
uint32List *native_i = (uint32List *)i;
visit_type_uint32(m, &native_i->value, NULL, &err);
}
error_propagate(errp, err);
err = NULL;
visit_end_list(m);
out:
error_propagate(errp, err);
}
void visit_type_uint64List(Visitor *m, uint64List **obj, const char *name, Error **errp)
{
Error *err = NULL;
GenericList *i, **prev;
visit_start_list(m, name, &err);
if (err) {
goto out;
}
for (prev = (GenericList **)obj;
!err && (i = visit_next_list(m, prev)) != NULL;
prev = &i) {
uint64List *native_i = (uint64List *)i;
visit_type_uint64(m, &native_i->value, NULL, &err);
}
error_propagate(errp, err);
err = NULL;
visit_end_list(m);
out:
error_propagate(errp, err);
}
void visit_type_uint8List(Visitor *m, uint8List **obj, const char *name, Error **errp)
{
Error *err = NULL;
GenericList *i, **prev;
visit_start_list(m, name, &err);
if (err) {
goto out;
}
for (prev = (GenericList **)obj;
!err && (i = visit_next_list(m, prev)) != NULL;
prev = &i) {
uint8List *native_i = (uint8List *)i;
visit_type_uint8(m, &native_i->value, NULL, &err);
}
error_propagate(errp, err);
err = NULL;
visit_end_list(m);
out:
error_propagate(errp, err);
}

View file

@ -20,33 +20,49 @@
#include "qapi-types.h"
#ifndef QAPI_VISIT_BUILTIN_VISITOR_DECL_H
#define QAPI_VISIT_BUILTIN_VISITOR_DECL_H
#ifndef QAPI_VISIT_BUILTIN
#define QAPI_VISIT_BUILTIN
void visit_type_boolList(Visitor *m, boolList **obj, const char *name, Error **errp);
void visit_type_int16List(Visitor *m, int16List **obj, const char *name, Error **errp);
void visit_type_int32List(Visitor *m, int32List **obj, const char *name, Error **errp);
void visit_type_int16List(Visitor *m, int16List **obj, const char *name, Error **errp);
void visit_type_intList(Visitor *m, intList **obj, const char *name, Error **errp);
void visit_type_uint8List(Visitor *m, uint8List **obj, const char *name, Error **errp);
void visit_type_numberList(Visitor *m, numberList **obj, const char *name, Error **errp);
void visit_type_int8List(Visitor *m, int8List **obj, const char *name, Error **errp);
void visit_type_sizeList(Visitor *m, sizeList **obj, const char *name, Error **errp);
void visit_type_uint64List(Visitor *m, uint64List **obj, const char *name, Error **errp);
void visit_type_uint16List(Visitor *m, uint16List **obj, const char *name, Error **errp);
void visit_type_boolList(Visitor *m, boolList **obj, const char *name, Error **errp);
void visit_type_strList(Visitor *m, strList **obj, const char *name, Error **errp);
void visit_type_int64List(Visitor *m, int64List **obj, const char *name, Error **errp);
void visit_type_int8List(Visitor *m, int8List **obj, const char *name, Error **errp);
void visit_type_intList(Visitor *m, intList **obj, const char *name, Error **errp);
void visit_type_numberList(Visitor *m, numberList **obj, const char *name, Error **errp);
void visit_type_sizeList(Visitor *m, sizeList **obj, const char *name, Error **errp);
void visit_type_strList(Visitor *m, strList **obj, const char *name, Error **errp);
void visit_type_uint16List(Visitor *m, uint16List **obj, const char *name, Error **errp);
void visit_type_uint32List(Visitor *m, uint32List **obj, const char *name, Error **errp);
#endif /* QAPI_VISIT_BUILTIN_VISITOR_DECL_H */
void visit_type_uint64List(Visitor *m, uint64List **obj, const char *name, Error **errp);
void visit_type_uint8List(Visitor *m, uint8List **obj, const char *name, Error **errp);
#endif /* QAPI_VISIT_BUILTIN */
void visit_type_ErrorClass(Visitor *m, ErrorClass *obj, const char *name, Error **errp);
void visit_type_ErrorClassList(Visitor *m, ErrorClassList **obj, const char *name, Error **errp);
void visit_type_X86CPURegister32(Visitor *m, X86CPURegister32 *obj, const char *name, Error **errp);
void visit_type_X86CPURegister32List(Visitor *m, X86CPURegister32List **obj, const char *name, Error **errp);
void visit_type_X86CPUFeatureWordInfo(Visitor *m, X86CPUFeatureWordInfo **obj, const char *name, Error **errp);
void visit_type_X86CPUFeatureWordInfoList(Visitor *m, X86CPUFeatureWordInfoList **obj, const char *name, Error **errp);
void visit_type_X86CPURegister32(Visitor *m, X86CPURegister32 *obj, const char *name, Error **errp);
void visit_type_X86CPURegister32List(Visitor *m, X86CPURegister32List **obj, const char *name, Error **errp);
#endif

View file

@ -153,63 +153,6 @@ def generate_event_implement(api_name, event_name, params):
return ret
# Following are the functions that generate an enum type for all defined
# events, similar to qapi-types.py. Here we already have enum name and
# values which were generated before and recorded in event_enum_*. It also
# works around the issue that "import qapi-types" can't work.
def generate_event_enum_decl(event_enum_name, event_enum_values):
lookup_decl = mcgen('''
extern const char *%(event_enum_name)s_lookup[];
''',
event_enum_name = event_enum_name)
enum_decl = mcgen('''
typedef enum %(event_enum_name)s {
''',
event_enum_name = event_enum_name)
# append automatically generated _MAX value
enum_max_value = c_enum_const(event_enum_name, "MAX")
enum_values = event_enum_values + [ enum_max_value ]
i = 0
for value in enum_values:
enum_decl += mcgen('''
%(value)s = %(i)d,
''',
value = value,
i = i)
i += 1
enum_decl += mcgen('''
} %(event_enum_name)s;
''',
event_enum_name = event_enum_name)
return lookup_decl + enum_decl
def generate_event_enum_lookup(event_enum_name, event_enum_strings):
ret = mcgen('''
const char *%(event_enum_name)s_lookup[] = {
''',
event_enum_name = event_enum_name)
for string in event_enum_strings:
ret += mcgen('''
"%(string)s",
''',
string = string)
ret += mcgen('''
NULL,
};
''')
return ret
(input_file, output_dir, do_c, do_h, prefix, dummy) = parse_command_line()
c_comment = '''
@ -265,8 +208,7 @@ fdecl.write(mcgen('''
exprs = QAPISchema(input_file).get_exprs()
event_enum_name = c_name(prefix + "QAPIEvent", protect=False)
event_enum_values = []
event_enum_strings = []
event_names = []
for expr in exprs:
if expr.has_key('event'):
@ -285,12 +227,11 @@ for expr in exprs:
fdef.write(ret)
# Record it, and generate enum later
event_enum_values.append(event_enum_value)
event_enum_strings.append(event_name)
event_names.append(event_name)
ret = generate_event_enum_decl(event_enum_name, event_enum_values)
ret = generate_enum(event_enum_name, event_names)
fdecl.write(ret)
ret = generate_event_enum_lookup(event_enum_name, event_enum_strings)
ret = generate_enum_lookup(event_enum_name, event_names)
fdef.write(ret)
close_output(fdef, fdecl)

View file

@ -78,23 +78,6 @@ struct %(name)s {
return ret
def generate_enum_lookup(name, values, prefix=None):
ret = mcgen('''
const char *const %(name)s_lookup[] = {
''',
name=c_name(name))
for value in values:
ret += mcgen('''
"%(value)s",
''',
value=value)
ret += mcgen('''
NULL,
};
''')
return ret
def generate_enum(name, values, prefix=None):
name = c_name(name)
lookup_decl = mcgen('''

View file

@ -1493,6 +1493,61 @@ def guardend(name):
''',
name=guardname(name))
def generate_enum_lookup(name, values, prefix=None):
ret = mcgen('''
const char *const %(name)s_lookup[] = {
''',
name=c_name(name))
for value in values:
index = c_enum_const(name, value, prefix)
ret += mcgen('''
"%(value)s",
''',
index = index, value = value)
max_index = c_enum_const(name, 'MAX', prefix)
ret += mcgen('''
NULL,
};
''',
max_index=max_index)
return ret
def generate_enum(name, values, prefix=None):
name = c_name(name)
lookup_decl = mcgen('''
extern const char *const %(name)s_lookup[];
''',
name=name)
enum_decl = mcgen('''
typedef enum %(name)s {
''',
name=name)
# append automatically generated _MAX value
enum_values = values + [ 'MAX' ]
i = 0
for value in enum_values:
enum_full_value = c_enum_const(name, value, prefix)
enum_decl += mcgen('''
%(enum_full_value)s = %(i)d,
''',
enum_full_value = enum_full_value,
i=i)
i += 1
enum_decl += mcgen('''
} %(name)s;
''',
name=name)
return enum_decl + lookup_decl
#
# Common command line parsing
#