[llvm-c] enum conversion approaches

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

[llvm-c] enum conversion approaches

Tim Besard
Hi all,

I was looking at the C API (adding some missing Build* methods) and was
wondering about how to move between C++ and C enums. There seem to be multiple
ways of doing this:
* dedicated method: eg LLVMAtomicOrdering->AtomicOrdering in mapFromLLVMOrdering
* local switch statement: eg. LLVMAtomicRMWBinOp->AtomicRMWInst in
  LLVMBuildAtomicRMW
* static cast: eg. LLVMVisibility->GlobalValue::VisibilityTypes in
  LLVMSetVisibility

Are there specific reasons for these different approaches? At first sight, it
seems like the C enums can be one-on-one mapped to their C++ counterpart, so a
static_cast should suffice. Sanity checking the input enum doesn't seem like a
reason either, because only some of the manual conversion fragments end with
a fatal error.

What is the preferred way of doing this? Does it make sense to convert the other
approaches?

Best,
Tim
_______________________________________________
LLVM Developers mailing list
[hidden email]         http://llvm.cs.uiuc.edu
http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev
Reply | Threaded
Open this post in threaded view
|

Re: [llvm-c] enum conversion approaches

Reid Kleckner-2
The reason is that we want to keep the C API stable. Sorting the C++ enums alphabetically or logically shouldn't impact the C API.

On Fri, Jul 17, 2015 at 1:33 AM, Tim Besard <[hidden email]> wrote:
Hi all,

I was looking at the C API (adding some missing Build* methods) and was
wondering about how to move between C++ and C enums. There seem to be multiple
ways of doing this:
* dedicated method: eg LLVMAtomicOrdering->AtomicOrdering in mapFromLLVMOrdering
* local switch statement: eg. LLVMAtomicRMWBinOp->AtomicRMWInst in
  LLVMBuildAtomicRMW
* static cast: eg. LLVMVisibility->GlobalValue::VisibilityTypes in
  LLVMSetVisibility

Are there specific reasons for these different approaches? At first sight, it
seems like the C enums can be one-on-one mapped to their C++ counterpart, so a
static_cast should suffice. Sanity checking the input enum doesn't seem like a
reason either, because only some of the manual conversion fragments end with
a fatal error.

What is the preferred way of doing this? Does it make sense to convert the other
approaches?

Best,
Tim
_______________________________________________
LLVM Developers mailing list
[hidden email]         http://llvm.cs.uiuc.edu
http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev


_______________________________________________
LLVM Developers mailing list
[hidden email]         http://llvm.cs.uiuc.edu
http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev