Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Assembler fails if using input/output operands #24

Open
j1elo opened this issue Jan 10, 2017 · 1 comment
Open

Assembler fails if using input/output operands #24

j1elo opened this issue Jan 10, 2017 · 1 comment

Comments

@j1elo
Copy link

j1elo commented Jan 10, 2017

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");

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.

@inducer
Copy link
Owner

inducer commented Jan 11, 2017

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants