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

OKL incorrect macro expansion #750

Open
IuriiKobein opened this issue Mar 29, 2024 · 0 comments
Open

OKL incorrect macro expansion #750

IuriiKobein opened this issue Mar 29, 2024 · 0 comments
Labels
bug Use this label when reporting bugs! OKL parser

Comments

@IuriiKobein
Copy link

Hello,
My team currently testing a new OKL transpiler based on clang frontend against different libraries that using OCCA.

We have found the bug in legacy OKL preprocessor.
Input :

#define MYSTR my_fn_

inline void my_fn_1() {}
inline void my_fn_2() {}


@directive("#define MYMACRO(idx) MYSTR ## idx")

@kernel void hello_kern() {
    for (int i = 0; i < 10; ++i; @outer) {
        for (int j = 0; j < 10; ++j; @inner) {


            MYMACRO(1)();
            MYMACRO(2)();

        }
    }
}

OKL legacy outputs:

inline void my_fn_1() {}

inline void my_fn_2() {}

extern "C" void hello_kern() {
#pragma omp parallel for
  for (int i = 0; i < 10; ++i) {
    for (int j = 0; j < 10; ++j) {
      my_fn_1();
      my_fn_2();
    }
  }
}

New OKL transpiler output:

inline void my_fn_1() {}

inline void my_fn_2() {}

extern "C" void hello_kern() {
#pragma omp parallel for
  for (int i = 0; i < 10; ++i) {
    for (int j = 0; j < 10; ++j) {
      MYSTR1();
      MYSTR2();
    }
  }

Actually to the latest one is correct according to C preprocessor spec.
To archive desire behavior additional level of macro directive is required
#define CONCAT(id1, id2) id1##id2
#define MYMACRO(idx) CONCAT(MYSTR, idx)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Use this label when reporting bugs! OKL parser
Projects
None yet
Development

No branches or pull requests

2 participants