Skip to content

Instantly share code, notes, and snippets.

@o11c
Created October 12, 2013 09:48
Show Gist options
  • Save o11c/6948059 to your computer and use it in GitHub Desktop.
Save o11c/6948059 to your computer and use it in GitHub Desktop.
A method of detecting whether, for a single target, LLVM supports its AsmParser
//#define current_target X86
#define current_target bogus
#define __STDC_LIMIT_MACROS
#define __STDC_CONSTANT_MACROS
#include "llvm-c/Target.h"
#include <stdbool.h>
#define JOIN2(a, b) a ## b
#define JOIN(a, b) JOIN2(a, b)
#define TARGET_VAR(t) JOIN(t, _printer)
int main()
{
// no initializer needed
bool TARGET_VAR(current_target);
{
#define LLVM_ASM_PARSER(target) \
bool TARGET_VAR(target) = false;
#include "llvm/Config/AsmParsers.def"
TARGET_VAR(current_target) = true;
#define LLVM_ASM_PARSER(target) \
if (TARGET_VAR(target)) \
LLVMInitialize ## target ## AsmParser();
#include "llvm/Config/AsmParsers.def"
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment