qemu-trivial
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Qemu-trivial] [Qemu-devel] [PATCH v2] add macro file for coccinelle


From: Markus Armbruster
Subject: Re: [Qemu-trivial] [Qemu-devel] [PATCH v2] add macro file for coccinelle
Date: Tue, 08 Sep 2015 20:35:53 +0200
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/24.5 (gnu/linux)

John Snow <address@hidden> writes:

> On 09/07/2015 06:21 AM, Paolo Bonzini wrote:
>> Coccinelle chokes on some idioms from compiler.h and queue.h.
>> Extract those in a macro file, to be used with "--macro-file
>> scripts/cocci-macro-file.h".
>> 
>> Signed-off-by: Paolo Bonzini <address@hidden>
>> ---
>>  scripts/cocci-macro-file.h | 119
>> +++++++++++++++++++++++++++++++++++++++++++++
>>  1 file changed, 119 insertions(+)
>>  create mode 100644 scripts/cocci-macro-file.h
>> 
>> diff --git a/scripts/cocci-macro-file.h b/scripts/cocci-macro-file.h
>> new file mode 100644
>> index 0000000..eceb4be
>> --- /dev/null
>> +++ b/scripts/cocci-macro-file.h
>> @@ -0,0 +1,119 @@
>> +/* Macro file for Coccinelle
>> + *
>> + * Copyright (C) 2015 Red Hat, Inc.
>> + *
>> + * Authors:
>> + *  Paolo Bonzini <address@hidden>
>> + *
>> + * This work is licensed under the terms of the GNU GPL, version 2
>> or, at your
>> + * option, any later version.  See the COPYING file in the
>> top-level directory.
>> + */
>> +
>> +/* Coccinelle only does limited parsing of headers, and chokes on some 
>> idioms
>> + * defined in compiler.h and queue.h.  Macros that Coccinelle must know 
>> about
>> + * in order to parse .c files must be in a separate macro file---which is
>> + * exactly what you're staring at now.
>> + *
>> + * To use this file, add the "--macro-file scripts/cocci-macro-file.h" to 
>> the
>> + * Coccinelle command line.
>> + */
>> +
>> +/* From qemu/compiler.h */
[Stuff cribbed from various headers...]
>
> Having not used Coccinelle yet, what happens if any of these functions
> become desynchronized ?

Coccinelle transforms C to C.  Problem: if you parse C the normal way
(first run preprocessor, then the parser proper), you have to unparse
and unpreprocess at the end to get a useful result.  Unparsing is easy,
but unpreprocessing is hard.

Instead, Coccinelle tries to parse *unpreprocessed* C.  Works most of
the time, because most uses of function-like macros can be treated as if
they were function calls, and most uses of object-like macros can be
treated as if they were values.

When it doesn't work, Coccinelle needs to resort to magic and / or skip
over some code it can't decipher.  The latter is undesirable, because if
the skipped code contains something we'd like to transform, we won't.

Part of the magic is treating "bad" macros specially.  --macro-file
helps with that part: macros defined there are "bad".  Sorry, I can't
really explain it, -EMAGIC.  /usr/share/coccinelle/standard.h is used by
default.

So what happens when the this file gets out of sync?  Worst case is
Coccinelle misses a pattern it could find if it was in sync.

Provided the macro file makes sense initially, a moderately bit-rotten
version is still almost certainly better than nothing.



reply via email to

[Prev in Thread] Current Thread [Next in Thread]