summaryrefslogtreecommitdiffstats
path: root/tools/perf/util/c++/clang-test.cpp
blob: 0f484fbb2b585af2472fb0b707a5710ce8c2def0 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
#include "clang.h"
#include "clang-c.h"
#include "llvm/IR/Function.h"
#include "llvm/IR/LLVMContext.h"

class perf_clang_scope {
public:
	explicit perf_clang_scope() {perf_clang__init();}
	~perf_clang_scope() {perf_clang__cleanup();}
};

extern "C" {

int test__clang_to_IR(void)
{
	perf_clang_scope _scope;

	std::unique_ptr<llvm::Module> M =
		perf::getModuleFromSource({"-DRESULT=1"},
					  "perf-test.c",
					  "int myfunc(void) {return RESULT;}");

	if (!M)
		return -1;

	for (llvm::Function& F : *M)
		if (F.getName() == "myfunc")
			return 0;
	return -1;
}

}
OpenPOWER on IntegriCloud