Skip to contentSkip to conversation

new to qemu with a simple question

Qemu-devel Wang Dong 3 participants 5 messages May 24, 2017 – May 26, 2017

lore
Share & tools
lore

Wang Dong

author
#0 lore raw

Hi guys,

I am new to qemu. But I need do some job in it right now.

When I try read qmp code. I found a interesting part against it.

Some C source code is generate from json file.

I wonder why this? What is the benefits of this?

Thanks in advance.

Signature · 1 line
Best regards. Wang Dong
#1 lore raw
Quoted 3 lines · Wang Dong

Some C source code is generate from json file.

I wonder why this? What is the benefits of this?

This allows you to concentrate on the high level semantics of the QMP API, without worrying about C syntax and structural code here and there. In one word, more conciseness and little code duplication.

If done in C, it would be much more lines of code and hardly readable.

Fam

author
#2 lore raw

Thank you, Fam.

Quoted 12 lines · Fam Zheng
Quoted 3 lines · Wang Dong

Some C source code is generate from json file.

I wonder why this? What is the benefits of this?

This allows you to concentrate on the high level semantics of the QMP API, without worrying about C syntax and structural code here and there. In one word, more conciseness and little code duplication.

If done in C, it would be much more lines of code and hardly readable.

Fam

Signature · 1 line
Best regards. Wang Dong
#3 lore raw
In reply to Wang Dong
Quoted 10 lines · Wang Dong

Hi guys,

I am new to qemu. But I need do some job in it right now.

When I try read qmp code. I found a interesting part against it.

Some C source code is generate from json file.

I wonder why this? What is the benefits of this?

Boring and repetitive code that is easy to typo is best written by a computer, which excels at boring and repetitive tasks. Writing our description in a more concise higher language and generating C code from that lets us focus on the actual design, rather than the mundane correctness of the code implementing the design.

It's the same reason that people use bison/yacc rather than hand-written parsers for complex grammars - you isolate the correctness of the code to the correctness of the generator, and free yourself to now only have to worry about the bigger picture of the input you feed to the generator. And on another level, it's why we write programs in C instead of assembly. Abstraction is good.

Signature · 3 lines
Eric Blake, Principal Software Engineer
Red Hat, Inc.           +1-919-301-3266
Virtualization:  qemu.org | libvirt.org
author
#4 lore raw
Quoted 16 lines · Eric Blake
Quoted 9 lines · Wang Dong

Hi guys,

I am new to qemu. But I need do some job in it right now.

When I try read qmp code. I found a interesting part against it.

Some C source code is generate from json file.

I wonder why this? What is the benefits of this?

Boring and repetitive code that is easy to typo is best written by computer, which excels at boring and repetitive tasks. Writing our description in a more concise higher language and generating C code from that lets us focus on the actual design, rather than the mundane correctness of the code implementing the design.

Quoted 7 lines

It's the same reason that people use bison/yacc rather than hand-written parsers for complex grammars - you isolate the correctness of the code to the correctness of the generator, and free yourself to now only have to worry about the bigger picture of the input you feed to the generator. And on another level, it's why we write programs in C instead of assembly. Abstraction is good.

Thanks for your reply. I really appreciate it.

Signature · 1 line
Best regards. Wang Dong