Open j1elo opened 7 years ago
Using the example file func_calls.py from pycparser, with the only modification of instantiating a GnuCParser:
def show_func_calls(filename, funcname): gnu_parser = GnuCParser() ast = parse_file(filename, use_cpp=False, parser=gnu_parser) v = FuncCallVisitor(funcname) v.visit(ast)
Basic "asm" expressions are parsed correctly, such as asm ("foo" ::: "bar"); or __asm__ ("foo" ::: "bar", "bar");
asm ("foo" ::: "bar");
__asm__ ("foo" ::: "bar", "bar");
However, any asm expression with i/o operands will fail with the error: AttributeError: 'Constant' object has no attribute 'name'.
This is the test file I'm using:
#include <stdio.h> void main(void) { // Sample: asm volatile("" ::: "memory") // => WORKS asm ("foo" ::: "bar"); // Sample: __asm__ __volatile__("sub pc, pc, -4" ::: "memory", "cc") // => WORKS __asm__ ("foo" ::: "bar", "bar"); // Sample: __asm__ ("brev\t%0" : "+r" (__value) : : "cc") // => ERROR __asm__ ("foo" : "bar" (5) : : "bar"); // Sample: __asm__ __volatile__ ("ssrf\t%0" : : "i" (OFFSET)) // => ERROR __asm__ ("foo" : : "bar" (5)); // Sample: __asm__ ("max\t%0, %1, %2" : "=r" (__value) : "r" (__arg_a), "r" (__arg_b)) // => ERROR __asm__ ("foo" : "bar" (5) : "bar" (6), "baz" (7)); }
The samples are lines of code taken from a real application, I don't have much knowledge about the syntax of these GCC extension but these lines compile and work correctly with GCC 4.4.7 so I assume they are valid variations of the asm function.
I unfortunately don't have time to work on this myself at the moment, but I'd be happy to take a patch.
This is the bit that would need changing.
Using the example file func_calls.py from pycparser, with the only modification of instantiating a GnuCParser:
Basic "asm" expressions are parsed correctly, such as
asm ("foo" ::: "bar");
or__asm__ ("foo" ::: "bar", "bar");
However, any asm expression with i/o operands will fail with the error: AttributeError: 'Constant' object has no attribute 'name'.
This is the test file I'm using:
The samples are lines of code taken from a real application, I don't have much knowledge about the syntax of these GCC extension but these lines compile and work correctly with GCC 4.4.7 so I assume they are valid variations of the asm function.