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

Doesn't seem to work with simple file #2

Open
X-Ryl669 opened this issue Jul 7, 2022 · 4 comments
Open

Doesn't seem to work with simple file #2

X-Ryl669 opened this issue Jul 7, 2022 · 4 comments

Comments

@X-Ryl669
Copy link

X-Ryl669 commented Jul 7, 2022

I'm using this file as an example for input: https://github.com/espressif/esp-idf/blob/master/components/driver/include/driver/rmt_common.h

Like this:

$ clang -I ../esp-idf/components/driver/include/driver/ ../esp-idf/components/driver/include/driver/rmt_common.h -Xclang -load -Xclang build/libcrefl.so       -Xclang -plugin -Xclang crefl       -Xclang -plugin-arg-crefl -Xclang -dump
id   attr next link type      name           props          detail              
--------------------------------------------------------------------------------
23   0    0    24   source    rmt_common.h                  typedef("__u_char") 
24   0    25   5    typedef   __u_char                      intrinsic("ubyte")  
25   0    26   7    typedef   __u_short                     intrinsic("ushort") 
26   0    27   9    typedef   __u_int                       intrinsic("uint")   
27   0    28   11   typedef   __u_long                      intrinsic("ulong")  
28   0    29   6    typedef   __int8_t                      intrinsic("byte")   
29   0    30   5    typedef   __uint8_t                     intrinsic("ubyte")  
30   0    31   8    typedef   __int16_t                     intrinsic("short")  
31   0    32   7    typedef   __uint16_t                    intrinsic("ushort") 
32   0    33   10   typedef   __int32_t                     intrinsic("int")    
33   0    34   9    typedef   __uint32_t                    intrinsic("uint")   
34   0    35   12   typedef   __int64_t                     intrinsic("long")   
35   0    36   11   typedef   __uint64_t                    intrinsic("ulong")  
36   0    37   6    typedef   __int_least8_t                intrinsic("byte")   
37   0    38   5    typedef   __uint_least8_…               intrinsic("ubyte")  
38   0    39   8    typedef   __int_least16_…               intrinsic("short")  
39   0    40   7    typedef   __uint_least16…               intrinsic("ushort") 
40   0    41   10   typedef   __int_least32_…               intrinsic("int")    
41   0    42   9    typedef   __uint_least32…               intrinsic("uint")   
42   0    43   12   typedef   __int_least64_…               intrinsic("long")   
43   0    44   11   typedef   __uint_least64…               intrinsic("ulong")  
44   0    45   12   typedef   __quad_t                      intrinsic("long")   
45   0    46   11   typedef   __u_quad_t                    intrinsic("ulong")  
46   0    47   12   typedef   __intmax_t                    intrinsic("long")   
47   0    48   11   typedef   __uintmax_t                   intrinsic("ulong")  
48   0    49   11   typedef   __dev_t                       intrinsic("ulong")  
49   0    50   9    typedef   __uid_t                       intrinsic("uint")   
50   0    51   9    typedef   __gid_t                       intrinsic("uint")   
51   0    52   11   typedef   __ino_t                       intrinsic("ulong")  
52   0    53   11   typedef   __ino64_t                     intrinsic("ulong")  
53   0    54   9    typedef   __mode_t                      intrinsic("uint")   
54   0    55   11   typedef   __nlink_t                     intrinsic("ulong")  
55   0    56   12   typedef   __off_t                       intrinsic("long")   
56   0    57   12   typedef   __off64_t                     intrinsic("long")   
57   0    58   10   typedef   __pid_t                       intrinsic("int")    
58   0    61   59   struct    (anonymous)                   field("__val")      
59   0    0    60   field     __val                         array("[2]int")     
60   0    0    10   array     [2]int         size=2         intrinsic("int")    
61   0    62   58   typedef   __fsid_t                      struct("anonymous") 
62   0    63   12   typedef   __clock_t                     intrinsic("long")   
63   0    64   11   typedef   __rlim_t                      intrinsic("ulong")  
64   0    65   11   typedef   __rlim64_t                    intrinsic("ulong")  
65   0    66   9    typedef   __id_t                        intrinsic("uint")   
66   0    67   12   typedef   __time_t                      intrinsic("long")   
67   0    68   9    typedef   __useconds_t                  intrinsic("uint")   
68   0    69   12   typedef   __suseconds_t                 intrinsic("long")   
69   0    70   12   typedef   __suseconds64_…               intrinsic("long")   
70   0    71   10   typedef   __daddr_t                     intrinsic("int")    
71   0    72   10   typedef   __key_t                       intrinsic("int")    
72   0    73   10   typedef   __clockid_t                   intrinsic("int")    
73   0    75   74   typedef   __timer_t                     pointer("*void")    
74   0    0    1    pointer   *void          width=64       intrinsic("void")   
75   0    76   12   typedef   __blksize_t                   intrinsic("long")   
76   0    77   12   typedef   __blkcnt_t                    intrinsic("long")   
77   0    78   12   typedef   __blkcnt64_t                  intrinsic("long")   
78   0    79   11   typedef   __fsblkcnt_t                  intrinsic("ulong")  
79   0    80   11   typedef   __fsblkcnt64_t                intrinsic("ulong")  
80   0    81   11   typedef   __fsfilcnt_t                  intrinsic("ulong")  
81   0    82   11   typedef   __fsfilcnt64_t                intrinsic("ulong")  
82   0    83   12   typedef   __fsword_t                    intrinsic("long")   
83   0    84   12   typedef   __ssize_t                     intrinsic("long")   
84   0    85   12   typedef   __syscall_slon…               intrinsic("long")   
85   0    86   11   typedef   __syscall_ulon…               intrinsic("ulong")  
86   0    87   12   typedef   __loff_t                      intrinsic("long")   
87   0    89   88   typedef   __caddr_t                     pointer("*byte")    
88   0    0    6    pointer   *byte          width=64       intrinsic("byte")   
89   0    90   12   typedef   __intptr_t                    intrinsic("long")   
90   0    91   9    typedef   __socklen_t                   intrinsic("uint")   
91   0    92   10   typedef   __sig_atomic_t                intrinsic("int")    
92   0    93   6    typedef   int8_t                        intrinsic("byte")   
93   0    94   8    typedef   int16_t                       intrinsic("short")  
94   0    95   10   typedef   int32_t                       intrinsic("int")    
95   0    96   12   typedef   int64_t                       intrinsic("long")   
96   0    97   5    typedef   uint8_t                       intrinsic("ubyte")  
97   0    98   7    typedef   uint16_t                      intrinsic("ushort") 
98   0    99   9    typedef   uint32_t                      intrinsic("uint")   
99   0    100  11   typedef   uint64_t                      intrinsic("ulong")  
100  0    101  6    typedef   int_least8_t                  intrinsic("byte")   
101  0    102  8    typedef   int_least16_t                 intrinsic("short")  
102  0    103  10   typedef   int_least32_t                 intrinsic("int")    
103  0    104  12   typedef   int_least64_t                 intrinsic("long")   
104  0    105  5    typedef   uint_least8_t                 intrinsic("ubyte")  
105  0    106  7    typedef   uint_least16_t                intrinsic("ushort") 
106  0    107  9    typedef   uint_least32_t                intrinsic("uint")   
107  0    108  11   typedef   uint_least64_t                intrinsic("ulong")  
108  0    109  6    typedef   int_fast8_t                   intrinsic("byte")   
109  0    110  12   typedef   int_fast16_t                  intrinsic("long")   
110  0    111  12   typedef   int_fast32_t                  intrinsic("long")   
111  0    112  12   typedef   int_fast64_t                  intrinsic("long")   
112  0    113  5    typedef   uint_fast8_t                  intrinsic("ubyte")  
113  0    114  11   typedef   uint_fast16_t                 intrinsic("ulong")  
114  0    115  11   typedef   uint_fast32_t                 intrinsic("ulong")  
115  0    116  11   typedef   uint_fast64_t                 intrinsic("ulong")  
116  0    117  12   typedef   intptr_t                      intrinsic("long")   
117  0    118  11   typedef   uintptr_t                     intrinsic("ulong")  
118  0    119  12   typedef   intmax_t                      intrinsic("long")   
119  0    120  11   typedef   uintmax_t                     intrinsic("ulong")  
120  0    127  121  struct    (anonymous)                   field("frequency_hz…
121  0    122  9    field     frequency_hz                  intrinsic("uint")   
122  0    123  16   field     duty_cycle                    intrinsic("float")  
123  0    126  124  struct    (anonymous)                   field("polarity_act…
124  0    125  9    field     polarity_activ…width=1        intrinsic("uint")   
125  0    0    9    field     always_on      width=1        intrinsic("uint")   
126  0    0    123  field     flags                         struct("anonymous") 
127  0    0    120  typedef   rmt_carrier_co…               struct("anonymous") 
--------------------------------------------------------------------------------

The functions declared in the file aren't listed in the output dump.

@X-Ryl669
Copy link
Author

X-Ryl669 commented Jul 7, 2022

It seems to work if run with preprocessor's argument like this:

$ clang -E -xc -I ../esp-idf/components/esp_common/include/ -I ../esp-idf/components/driver/include/ ../esp-idf/components/driver/include/driver/rmt_common.h -Xclang -load -Xclang build/libcrefl.so       -Xclang -plugin -Xclang crefl       -Xclang -plugin-arg-crefl -Xclang -dump

But obviously, it gets all the garbage from the other include files

@X-Ryl669
Copy link
Author

X-Ryl669 commented Jul 7, 2022

In fact, even running the creflcc.py script, the source of the symbol is not set in the database. Is there a way to get only the declarations that are in the input file ? Said differently, how can I filter decl by source file ? Right now, I'm getting all the functions declared in the stdlib so that's a lot of noise I'm not interested about.

@michaeljclark
Copy link
Owner

you should always get everything that is included, unless there are parse errors due to incorrect flags. there is a merge step in crefltool that combines the metadata from multiple source files and it is designed to de-duplicate common nodes but they need to be there because they are dependencies. there should be only one copy of these in the final linked binary due to the merge.

but I think this may be a different problem.

currently if there are errors during the parse, the plugin will continue but the AST will be incomplete and some nodes may have errors and thus not be emitted in the reflection metadata. it would be nice to see errors when invoking the plugin but I did not figure that out yet. common problems are not having the correct language (i.e. -xc or -xc++) on the command line.

you'll notice that scripts/run_tests.py and scripts/creflcc.py have a --cpp argument. I'd have to dig through the scripts to see how one passes additional flags to creflcc.py that might be missing and causing a compilation error but given you are able to invoke the plugin directly you might be able to figure that out.

hope this helps.

@X-Ryl669
Copy link
Author

Ideally, each symbol in the database should refer to the source where it's declared (or defined?). That way, it could be possible to filter symbols that aren't in the current compilation unit. I think it's ok to use --cpp or -E or whatever argument to clang as long as it's matching the final API that'll likely not be compiled by clang anyway.

In the preprocessor output, there are #line XXX file YYYY lines that could be used to maintain the source file's origin when a symbol is created.

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