inducer / inducer/pycparserext

Assembler fails if using input/output operands

Open
#24 1 comment 0 reactions 0 assignees View on GitHub
Dominant language
Python
Stars
91
Forks
30
PR merge metrics
No merged PRs in 30d

Description

Using the example file [func_calls.py](https://github.com/eliben/pycparser/blob/master/examples/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
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.

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.