inducer / pycparserext

Extensions for Eli Bendersky's pycparser
http://pypi.python.org/pypi/pycparserext
Other
83 stars 28 forks source link

Problems with parsing "Extended Asm" #3

Open Druidos opened 11 years ago

Druidos commented 11 years ago

When I was tried to parse source with several asm instructions (described at http://gcc.gnu.org/onlinedocs/gcc/Extended-Asm.html) I faced with fails to parse similar pieces:

1 . void read_tsc(void) { long val; asm("rdtsc" : "=A" (val)); }

whereas asm(''nothing") mistakenly recognized as function call.

2 . void read_tsc(void) { long val; asm volatile("rdtsc" : "=A" (val)); }

3 . void read_tsc(void) { long fpenv; asm(""mtfsf 255,%0" : : "f" (fpenv)); }

I suppose that highlighted parts are different states for context-free grammar used by pycparserext in whole.

inducer commented 11 years ago

Here's the code that parses that stuff. Can you try and cook up a patch?

Druidos commented 11 years ago

There is my patch for this issue: (probably it isn't accurate) https://github.com/Druidos/pycparserext/commit/8f8201a6aa85c7a36a852257918a52350bbc4fd1

Also tests are shown that GNUCGenerator has problem with reconstruction asm notation.

inducer commented 11 years ago

I've merged your changes, thanks! How would I reproduce the asm notation reconstruction issue?

Druidos commented 11 years ago

Sorry for late response.

Example illustrated problem with GnuCGenerator is in test_asm_volatile_2():

I have source: void read_tsc(void) { long val; asm volatile("rdtsc" : "=A" (val)); }

but as result of generation I have output with 4 components in asm: void read_tsc(void) { long val; asm volatile("rdtsc" : "=A"(val) : : ) ; }

I suppose that problem corresponds to visit_Asm() because it extends components by 3 independently on witch asm components are None. After this generic_visit() method from on node=None returns empty string.

        if (n.output_operands is not None
                or n.input_operands is not None
                or n.clobbered_regs is not None):
            components.extend([
                n.output_operands,
                n.input_operands,
                n.clobbered_regs,
                ])
inducer commented 11 years ago

Sorry for the dumb question: Is the four-component version with two empty components not equivalent to the two-component version?