clang-test.cpp 570 B

1234567891011121314151617181920212223242526272829303132
  1. #include "clang.h"
  2. #include "clang-c.h"
  3. #include "llvm/IR/Function.h"
  4. #include "llvm/IR/LLVMContext.h"
  5. class perf_clang_scope {
  6. public:
  7. explicit perf_clang_scope() {perf_clang__init();}
  8. ~perf_clang_scope() {perf_clang__cleanup();}
  9. };
  10. extern "C" {
  11. int test__clang_to_IR(void)
  12. {
  13. perf_clang_scope _scope;
  14. std::unique_ptr<llvm::Module> M =
  15. perf::getModuleFromSource({"-DRESULT=1"},
  16. "perf-test.c",
  17. "int myfunc(void) {return RESULT;}");
  18. if (!M)
  19. return -1;
  20. for (llvm::Function& F : *M)
  21. if (F.getName() == "myfunc")
  22. return 0;
  23. return -1;
  24. }
  25. }