[LLVMdev] [llvm-c] enum conversion approaches

Tim Besard tim.besard at elis.ugent.be
Fri Jul 17 01:33:57 PDT 2015


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



More information about the llvm-dev mailing list