clang-test.cpp 542 B

12345678910111213141516171819202122232425262728293031
  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("perf-test.c",
  16. "int myfunc(void) {return 1;}");
  17. if (!M)
  18. return -1;
  19. for (llvm::Function& F : *M)
  20. if (F.getName() == "myfunc")
  21. return 0;
  22. return -1;
  23. }
  24. }