[llvm-dev] How to know the sub-class of a Value class?

Joshua Cranmer via llvm-dev llvm-dev at lists.llvm.org
Sun Jun 11 23:35:53 PDT 2017


On 6/12/17 1:34 AM, Joshua Cranmer 🐧 wrote:
> If you're dead set on actually printing the name of the class of a 
> Value, there's no canned method to do that. Something like this code 
> would work (untested):
> const char *kind_name = nullptr;
> switch(val->getValueID()) {
> #define HANDLE_VALUE(name) case Value::name##Val: kind_name = #name; 
> break;
> default: kind_name = "well this was unexpected";
> }

Arggh, I'm an idiot. The correct code should be:
const char *kind_name = nullptr;
switch(val->getValueID()) {
#define HANDLE_VALUE(name) case Value::name##Val: kind_name = #name; break;
#include "llvm/IR/Value.def"
#undef HANDLE_VALUE
default: kind_name = "well this was unexpected";
}

The #include is kinda the most important part in that statement...

-- 
Joshua Cranmer
Thunderbird module owner
DXR coauthor



More information about the llvm-dev mailing list