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

preproc: support arbitrary expressions in enums #2026

Merged
merged 1 commit into from
Aug 26, 2024

Conversation

mrgriffin
Copy link
Collaborator

@mrgriffin mrgriffin commented Aug 21, 2024

Fixes #2019

There are probably still cases that don't work. Anything involving sizeof comes to mind, or any expressions which are handled differently by as than gcc... But this hopefully should fix most—if not all—of the realistic examples?

Tested with SBird's example:

enum Bar {
    BAR_0 = 0,
    BAR_1 = 1,
};

enum {
    VALUE_0 = 0,
    VALUE_1, // 1
    VALUE_2, // 2
    VALUE_2a = BAR_1,
    VALUE_3
};
$ tools/preproc/preproc example.s charmap.txt | cpp -I include - | tools/preproc/preproc -ie example.s charmap.txt
# 1 "example.s"
# 0 "<stdin>"
# 0 "<built-in>"
# 0 "<command-line>"
# 1 "/nix/store/0c5jp9d9h9818arr6s21xibgjl1ybql0-glibc-2.39-52-dev/include/stdc-predef.h" 1 3 4
# 0 "<command-line>" 2
# 1 "<stdin>"
# 1 "example.s"
# 2 "example.s"
.equiv BAR_0, (0) + 0
# 3 "example.s"
.equiv BAR_1, (1) + 0

# 7 "example.s"
.equiv VALUE_0, (0) + 0
# 8 "example.s"
.equiv VALUE_1, (0) + 1
# 9 "example.s"
.equiv VALUE_2, (0) + 2
# 10 "example.s"
.equiv VALUE_2a, (BAR_1) + 0
# 11 "example.s"
.equiv VALUE_3, (BAR_1) + 1

$ tools/preproc/preproc example.s charmap.txt | cpp -I include - | tools/preproc/preproc -ie example.s charmap.txt | arm-none-eabi-as
$ readelf -s a.out

Symbol table '.symtab' contains 12 entries:
   Num:    Value  Size Type    Bind   Vis      Ndx Name
     0: 00000000     0 NOTYPE  LOCAL  DEFAULT  UND 
     1: 00000000     0 SECTION LOCAL  DEFAULT    1 .text
     2: 00000000     0 SECTION LOCAL  DEFAULT    2 .data
     3: 00000000     0 SECTION LOCAL  DEFAULT    3 .bss
     4: 00000000     0 NOTYPE  LOCAL  DEFAULT  ABS BAR_0
     5: 00000001     0 NOTYPE  LOCAL  DEFAULT  ABS BAR_1
     6: 00000000     0 NOTYPE  LOCAL  DEFAULT  ABS VALUE_0
     7: 00000001     0 NOTYPE  LOCAL  DEFAULT  ABS VALUE_1
     8: 00000002     0 NOTYPE  LOCAL  DEFAULT  ABS VALUE_2
     9: 00000001     0 NOTYPE  LOCAL  DEFAULT  ABS VALUE_2a
    10: 00000002     0 NOTYPE  LOCAL  DEFAULT  ABS VALUE_3
    11: 00000000     0 SECTION LOCAL  DEFAULT    4 .ARM.attributes

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

Successfully merging this pull request may close these issues.

Pre-processing of enums for inclusion in assembly files does not handle non-numeric definitions
2 participants