[prev in list] [next in list] [prev in thread] [next in thread] 

List:       kde-commits
Subject:    [analitza/aucahuasi/analitzajit] /: First upload of components for JIT support.
From:       Percy_Camilo_Triveño_Aucahuasi <percy.camilo.ta () gmail ! com>
Date:       2014-07-01 0:28:32
Message-ID: E1X1lw0-0001QC-Ve () scm ! kde ! org
[Download RAW message or body]

Git commit 0a89ebe0300600a9b7bd5c0845d8102a65e1134d by Percy Camilo Triveño \
Aucahuasi. Committed on 01/07/2014 at 00:17.
Pushed by aucahuasi into branch 'aucahuasi/analitzajit'.

First upload of components for JIT support.

As a first approach we have:

JitAnalyzer: The heart of this feature, this class inherited from Analyzer but \
                additionally can perform calculations with JIT.
LLVMIRExpressionWriter: This component transform the analitza tree into LLVM IR and \
                thus let us perform JIT evaluations by using JitAnalyzer.
AnalitzaJitTest: Here we are going to test JitAnalyzer.
cmake/FindLLVM.cmake: we need this to know if the user have LLVM in his system.

Finally, this feature is optional for the user (at compilation time)

M  +9    -1    CMakeLists.txt
M  +14   -2    analitza/CMakeLists.txt
A  +19   -0    analitza/jitanalyzer.cpp     [License: GPL (v2+)]
A  +41   -0    analitza/jitanalyzer.h     [License: GPL (v2+)]
A  +303  -0    analitza/llvmirexpressionwriter.cpp     [License: GPL (v2+)]
A  +66   -0    analitza/llvmirexpressionwriter.h     [License: GPL (v2+)]
M  +8    -0    analitza/tests/CMakeLists.txt
A  +54   -0    analitza/tests/analitzajittest.cpp     [License: GPL (v2+)]
A  +47   -0    analitza/tests/analitzajittest.h     [License: GPL (v2+)]
A  +109  -0    cmake/FindLLVM.cmake
M  +2    -1    config-analitza.h.cmake

http://commits.kde.org/analitza/0a89ebe0300600a9b7bd5c0845d8102a65e1134d

diff --git a/CMakeLists.txt b/CMakeLists.txt
index 6a3a387..7674409 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -36,13 +36,21 @@ set(HAVE_OPENGL ${OPENGL_FOUND})
 find_package(Eigen3) # find and setup Eigen3 if available
 set(HAVE_EIGEN3 ${EIGEN3_FOUND})
 
-include_directories(${CMAKE_SOURCE_DIR} ${CMAKE_BINARY_DIR} ${EIGEN3_INCLUDE_DIR})
+find_package(LLVM)
+set(HAVE_LLVM ${LLVM_FOUND})
+
+include_directories(${CMAKE_SOURCE_DIR} ${CMAKE_BINARY_DIR} ${EIGEN3_INCLUDE_DIR} \
${LLVM_INCLUDE_DIR})  
 remove_definitions(-DQT_NO_CAST_TO_ASCII)
 remove_definitions(-DQT_NO_CAST_FROM_ASCII)
 remove_definitions(-DQT_NO_CAST_FROM_BYTEARRAY)
 remove_definitions(-DQT_NO_KEYWORDS)
 
+if(LLVM_FOUND)
+	add_definitions(${LLVM_CFLAGS})
+	link_directories(${LLVM_LIBRARY_DIR})
+endif(LLVM_FOUND)
+
 add_subdirectory(analitza)
 add_subdirectory(analitzaplot)
 add_subdirectory(analitzagui)
diff --git a/analitza/CMakeLists.txt b/analitza/CMakeLists.txt
index 3787d84..932940d 100644
--- a/analitza/CMakeLists.txt
+++ b/analitza/CMakeLists.txt
@@ -49,11 +49,23 @@ set(analitza_SRCS
 )
 
 if(EIGEN3_FOUND)
-    list(APPEND analitza_SRCS commands/eigencommands.cpp)
-endif()
+	list(APPEND analitza_SRCS commands/eigencommands.cpp)
+endif(EIGEN3_FOUND)
+
+if(LLVM_FOUND)
+	list(APPEND analitza_SRCS 
+		llvmirexpressionwriter.cpp
+		jitanalyzer.cpp
+	)
+endif(LLVM_FOUND)
 
 add_library(Analitza ${analitza_SRCS})
 target_link_libraries(Analitza Qt5::Core Qt5::Xml)
+
+if(LLVM_FOUND)
+	target_link_libraries(Analitza ${LLVM_MODULE_LIBS})
+endif(LLVM_FOUND)
+
 target_include_directories(Analitza INTERFACE \
"$<INSTALL_INTERFACE:${INCLUDE_INSTALL_DIR}>")  
 set_target_properties(Analitza PROPERTIES VERSION ${ANALITZA_VERSION_STRING} \
                SOVERSION ${ANALITZA_SOVERSION} )
diff --git a/analitza/jitanalyzer.cpp b/analitza/jitanalyzer.cpp
new file mode 100644
index 0000000..7ac2f09
--- /dev/null
+++ b/analitza/jitanalyzer.cpp
@@ -0,0 +1,19 @@
+/*************************************************************************************
 + *  Copyright (C) 2014 by Percy Camilo T. Aucahuasi <percy.camilo.ta@gmail.com>     \
* + *                                                                                 \
* + *  This program is free software; you can redistribute it and/or                  \
* + *  modify it under the terms of the GNU General Public License                    \
* + *  as published by the Free Software Foundation; either version 2                 \
* + *  of the License, or (at your option) any later version.                         \
* + *                                                                                 \
* + *  This program is distributed in the hope that it will be useful,                \
* + *  but WITHOUT ANY WARRANTY; without even the implied warranty of                 \
* + *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the                  \
* + *  GNU General Public License for more details.                                   \
* + *                                                                                 \
* + *  You should have received a copy of the GNU General Public License              \
* + *  along with this program; if not, write to the Free Software                    \
* + *  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA \
* + *************************************************************************************/
 +
+#include "jitanalyzer.h"
diff --git a/analitza/jitanalyzer.h b/analitza/jitanalyzer.h
new file mode 100644
index 0000000..d7a3925
--- /dev/null
+++ b/analitza/jitanalyzer.h
@@ -0,0 +1,41 @@
+/*************************************************************************************
 + *  Copyright (C) 2014 by Percy Camilo T. Aucahuasi <percy.camilo.ta@gmail.com>     \
* + *                                                                                 \
* + *  This program is free software; you can redistribute it and/or                  \
* + *  modify it under the terms of the GNU General Public License                    \
* + *  as published by the Free Software Foundation; either version 2                 \
* + *  of the License, or (at your option) any later version.                         \
* + *                                                                                 \
* + *  This program is distributed in the hope that it will be useful,                \
* + *  but WITHOUT ANY WARRANTY; without even the implied warranty of                 \
* + *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the                  \
* + *  GNU General Public License for more details.                                   \
* + *                                                                                 \
* + *  You should have received a copy of the GNU General Public License              \
* + *  along with this program; if not, write to the Free Software                    \
* + *  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA \
* + *************************************************************************************/
 +
+#ifndef JITANALYZER_H
+#define JITANALYZER_H
+
+#include "analyzer.h"
+
+namespace Analitza
+{
+
+/**
+ * \class LLVMAnalyzer
+ * 
+ * \ingroup AnalitzaModule
+ *
+ * \brief Evaluates math expressions using JIT.
+ */
+
+class ANALITZA_EXPORT JitAnalyzer : public Analyzer
+{
+//TODO
+};
+
+}
+#endif
diff --git a/analitza/llvmirexpressionwriter.cpp \
b/analitza/llvmirexpressionwriter.cpp new file mode 100644
index 0000000..a5281c2
--- /dev/null
+++ b/analitza/llvmirexpressionwriter.cpp
@@ -0,0 +1,303 @@
+/*************************************************************************************
 + *  Copyright (C) 2014 by Percy Camilo T. Aucahuasi <percy.camilo.ta@gmail.com>     \
* + *                                                                                 \
* + *  This program is free software; you can redistribute it and/or                  \
* + *  modify it under the terms of the GNU General Public License                    \
* + *  as published by the Free Software Foundation; either version 2                 \
* + *  of the License, or (at your option) any later version.                         \
* + *                                                                                 \
* + *  This program is distributed in the hope that it will be useful,                \
* + *  but WITHOUT ANY WARRANTY; without even the implied warranty of                 \
* + *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the                  \
* + *  GNU General Public License for more details.                                   \
* + *                                                                                 \
* + *  You should have received a copy of the GNU General Public License              \
* + *  along with this program; if not, write to the Free Software                    \
* + *  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA \
* + *************************************************************************************/
 +
+#include "llvmirexpressionwriter.h"
+
+#include <llvm/IR/Value.h>
+
+#include "value.h"
+#include "vector.h"
+#include "operator.h"
+#include "container.h"
+#include <QStringList>
+#include "list.h"
+#include "variable.h"
+#include "apply.h"
+#include "analitzautils.h"
+#include "matrix.h"
+
+Q_DECLARE_METATYPE(llvm::Value*);
+
+using namespace Analitza;
+
+template <class T>
+QStringList LLVMIRExpressionWriter::allValues(T it, const T& itEnd, \
AbstractExpressionVisitor* writer) +{
+	QStringList elements;
+	for(; it!=itEnd; ++it)
+		elements += (*it)->accept(writer).toString();
+	
+	return elements;
+}
+
+QMap<Operator::OperatorType, QString> llvminitOperators()
+{
+	QMap<Operator::OperatorType, QString> ret;
+	ret.insert(Operator::plus, "+");
+	ret.insert(Operator::times, "*");
+	ret.insert(Operator::divide, "/");
+	ret.insert(Operator::eq, "=");
+	ret.insert(Operator::neq, "!=");
+	ret.insert(Operator::lt, "<");
+	ret.insert(Operator::leq, "<=");
+	ret.insert(Operator::gt, ">");
+	ret.insert(Operator::geq, ">=");
+	ret.insert(Operator::power, "^");
+	ret.insert(Operator::minus, "-");
+	return ret;
+}
+
+const QMap<Operator::OperatorType, QString> \
LLVMIRExpressionWriter::s_operators=llvminitOperators(); +
+LLVMIRExpressionWriter::LLVMIRExpressionWriter(const Object* o)
+{
+    if (o)
+        m_result=o->accept(this);
+}
+
+QVariant LLVMIRExpressionWriter::visit(const Ci* var)
+{
+	return var->name();
+}
+
+QVariant LLVMIRExpressionWriter::visit(const Operator* op)
+{
+	return op->name();
+}
+
+QVariant LLVMIRExpressionWriter::visit(const Vector* vec)
+{
+	return QString("vector { %1 \
}").arg(allValues<Vector::const_iterator>(vec->constBegin(), vec->constEnd(), \
this).join(QString(", "))); +}
+
+QVariant LLVMIRExpressionWriter::visit(const Matrix* m)
+{
+	return QString("matrix { %1 }").arg(allValues(m->constBegin(), m->constEnd(), \
this).join(QString(", "))); +}
+
+QVariant LLVMIRExpressionWriter::visit(const MatrixRow* mr)
+{
+	return QString("matrixrow { %1 }").arg(allValues(mr->constBegin(), mr->constEnd(), \
this).join(QString(", "))); +}
+
+QVariant LLVMIRExpressionWriter::visit(const List* vec)
+{
+	if(!vec->isEmpty() && vec->at(0)->type()==Object::value && \
static_cast<Cn*>(vec->at(0))->format()==Cn::Char) +		return \
QString("\""+AnalitzaUtils::listToString(vec)+"\""); +	else
+		return QString("list { %1 \
}").arg(allValues<List::const_iterator>(vec->constBegin(), vec->constEnd(), \
this).join(QString(", "))); +}
+
+QVariant LLVMIRExpressionWriter::visit(const Cn* var)
+{
+	return QString();
+	//TODO
+// 	if(var->isBoolean())
+// 		return var->isTrue() ? "true" : "false";
+// 	else if(var->isCharacter())
+// 		return QString(var->character());
+// 	else if(var->isComplex()) {
+// 		QString realpart;
+// 		QString imagpart;
+// 		bool realiszero = false;
+// 		if (qAbs(var->complexValue().real()) > MIN_PRINTABLE_VALUE)
+// 			realpart = QString::number(var->complexValue().real(), 'g', 12);
+// 		else
+// 			realiszero = true;
+// 		
+// 		if (var->complexValue().imag() != 1 && var->complexValue().imag() != -1) {
+// 			if (qAbs(var->complexValue().imag()) > MIN_PRINTABLE_VALUE) {
+// 				if (!realiszero && var->complexValue().imag()>0.)
+// 					realpart += QLatin1String("+");
+// 				imagpart = QString::number(var->complexValue().imag(), 'g', 12);
+// 				imagpart += QLatin1String("*i");
+// 			}
+// 		} else  {
+// 			if (var->complexValue().imag() == 1)
+// 				imagpart = QLatin1String("i");
+// 			else if (var->complexValue().imag() == -1)
+// 				imagpart = QLatin1String("-i");
+// 		}
+// 		
+// 		return QVariant::fromValue<QString>(realpart+imagpart);
+// 	}
+// 	else
+// 		return QString::number(var->value(), 'g', 12);
+}
+
+int LLVMIRExpressionWriter::weight(const Operator* op, int size, int pos)
+{
+	switch(op->operatorType()) {
+		case Operator::lt:
+		case Operator::gt:
+		case Operator::eq:
+		case Operator::neq:
+		case Operator::leq:
+		case Operator::geq:
+			return 1;
+		case Operator::plus:
+			return 2;
+		case Operator::minus:
+			return size==1 ? 8 : 3;
+		case Operator::times:
+			return 4;
+		case Operator::divide:
+			return 5 + (pos>0 ? 0 : 1);
+		case Operator::_and:
+		case Operator::_or:
+		case Operator::_xor:
+			return 6;
+		case Operator::power:
+			return 7 + (pos>0 ? 0 : 1);
+		default:
+			return 1000;
+	}
+}
+
+QVariant LLVMIRExpressionWriter::visit(const Analitza::Apply* a)
+{
+	Operator op=a->firstOperator();
+	QStringList ret;
+	QString toret;
+	QString bounds;
+	QStringList bvars=a->bvarStrings();
+	
+	if(a->ulimit() || a->dlimit()) {
+		bounds += '=';
+		if(a->dlimit())
+			bounds += a->dlimit()->accept(this).toString();
+		bounds += "..";
+		if(a->ulimit())
+			bounds += a->ulimit()->accept(this).toString();
+	}
+	else if(a->domain())
+		bounds += '@'+a->domain()->accept(this).toString();
+	
+	int i = 0;
+	foreach(Object* o, a->m_params) {
+		Object::ObjectType type=o->type();
+		switch(type) {
+			case Object::oper:
+				Q_ASSERT(false);
+				break;
+			case Object::variable:
+				ret << static_cast<const Ci*>(o)->accept(this).toString();
+				break;
+			case Object::apply: {
+				const Apply *c = (const Apply*) o;
+				QString s = c->accept(this).toString();
+				if(s_operators.contains(op.operatorType()) && !c->isUnary()) {
+					Operator child_op = c->firstOperator();
+					
+					if(child_op.operatorType() && weight(&op, c->countValues(), \
-1)>weight(&child_op, c->countValues(), i)) +						s=QString("(%1)").arg(s);
+				}
+				ret << s;
+			}	break;
+			default:
+				ret << o->accept(this).toString();
+				break;
+		}
+		++i;
+	}
+	
+	bool func=op.operatorType()==Operator::function;
+	if(func) {
+		QString n = ret.takeFirst();
+		if(a->m_params.first()->type()!=Object::variable)
+			n='('+n+')';
+		
+		toret += QString("%1(%2)").arg(n).arg(ret.join(", "));
+	} else if(op.operatorType()==Operator::selector) {
+		if(a->m_params.last()->isApply()) {
+			const Apply* a1=static_cast<const Apply*>(a->m_params.last());
+			if(s_operators.contains(a1->firstOperator().operatorType()))
+				ret.last()='('+ret.last()+')';
+		}
+		
+		toret += QString("%1[%2]").arg(ret.last()).arg(ret.first());
+	} else if(ret.count()>1 && s_operators.contains(op.operatorType())) {
+		toret += ret.join(s_operators.value(op.operatorType()));
+	} else if(ret.count()==1 && op.operatorType()==Operator::minus)
+		toret += '-'+ret[0];
+	else {
+		QString bounding;
+		if(!bounds.isEmpty() || !bvars.isEmpty()) {
+			if(bvars.count()!=1) bounding +='(';
+			bounding += bvars.join(", ");
+			if(bvars.count()!=1) bounding +=')';
+			
+			bounding = ':'+bounding +bounds;
+		}
+			
+		toret += QString("%1(%2%3)").arg(op.accept(this).toString()).arg(ret.join(", \
")).arg(bounding); +	}
+	
+	return toret;
+}
+
+QVariant LLVMIRExpressionWriter::visit(const Container* var)
+{
+	QStringList ret = allValues(var->constBegin(), var->constEnd(), this);
+	
+	QString toret;
+	switch(var->containerType()) {
+		case Container::declare:
+			toret += ret.join(":=");
+			break;
+		case Container::lambda: {
+			QString last=ret.takeLast();
+			QStringList bvars = var->bvarStrings();
+			if(bvars.count()!=1) toret +='(';
+			toret += bvars.join(", ");
+			if(bvars.count()!=1) toret +=')';
+			toret += "->" + last;
+		}	break;
+		case Container::math:
+			toret += ret.join("; ");
+			break;
+		case Container::uplimit: //x->(n1..n2) is put at the same time
+		case Container::downlimit:
+			break;
+		case Container::bvar:
+			if(ret.count()>1) toret += '(';
+			toret += ret.join(", ");
+			if(ret.count()>1) toret += ')';
+			break;
+		case Container::piece:
+			toret += ret[1]+" ? "+ret[0];
+			break;
+		case Container::otherwise:
+			toret += "? "+ret[0];
+			break;
+		default:
+			toret += var->tagName()+" { "+ret.join(", ")+" }";
+			break;
+	}
+	return toret;
+}
+
+QVariant LLVMIRExpressionWriter::visit(const CustomObject*)
+{
+	return "CustomObject";
+}
+
+QVariant LLVMIRExpressionWriter::visit(const None* )
+{
+	return QString();
+}
diff --git a/analitza/llvmirexpressionwriter.h b/analitza/llvmirexpressionwriter.h
new file mode 100644
index 0000000..effe2a8
--- /dev/null
+++ b/analitza/llvmirexpressionwriter.h
@@ -0,0 +1,66 @@
+/*************************************************************************************
 + *  Copyright (C) 2014 by Percy Camilo T. Aucahuasi <percy.camilo.ta@gmail.com>     \
* + *                                                                                 \
* + *  This program is free software; you can redistribute it and/or                  \
* + *  modify it under the terms of the GNU General Public License                    \
* + *  as published by the Free Software Foundation; either version 2                 \
* + *  of the License, or (at your option) any later version.                         \
* + *                                                                                 \
* + *  This program is distributed in the hope that it will be useful,                \
* + *  but WITHOUT ANY WARRANTY; without even the implied warranty of                 \
* + *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the                  \
* + *  GNU General Public License for more details.                                   \
* + *                                                                                 \
* + *  You should have received a copy of the GNU General Public License              \
* + *  along with this program; if not, write to the Free Software                    \
* + *  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA \
* + *************************************************************************************/
 +
+#ifndef LLVMIREXPRESSIONWRITER_H
+#define LLVMIREXPRESSIONWRITER_H
+
+#include "abstractexpressionvisitor.h"
+#include "operator.h"
+
+//TODO this class is just a copy of stringexpressionwriter ... it need to be \
modified  +namespace Analitza
+{
+
+/**
+ * \class LLVMIRExpressionWriter
+ * 
+ * \ingroup AnalitzaModule
+ *
+ * \brief This class represents the LLVM IR expression writer.//TODO better doc
+ */
+
+class LLVMIRExpressionWriter : public AbstractExpressionVisitor
+{
+	public:
+		LLVMIRExpressionWriter(const Object* o);
+		
+		virtual QVariant visit(const None* var);
+		virtual QVariant visit(const Ci* var);
+		virtual QVariant visit(const Cn* var);
+		virtual QVariant visit(const Container* var);
+		virtual QVariant visit(const Operator* var);
+		virtual QVariant visit(const Vector* var);
+		virtual QVariant visit(const List* l);
+		virtual QVariant visit(const Matrix* m);
+		virtual QVariant visit(const MatrixRow* mr);
+		virtual QVariant visit(const Apply* a);
+		virtual QVariant visit(const CustomObject* c);
+		
+		QVariant result() const { return m_result; }
+		
+		static int weight(const Analitza::Operator* op, int size, int pos);
+		static const QMap<Operator::OperatorType, QString> s_operators;
+	private:
+		template <class T>
+			static QStringList allValues(T it, const T& itEnd, AbstractExpressionVisitor* \
writer); +
+		QVariant m_result;
+};
+
+}
+#endif // LLVMIREXPRESSIONWRITER_H
diff --git a/analitza/tests/CMakeLists.txt b/analitza/tests/CMakeLists.txt
index 0de2e7f..0c8973b 100644
--- a/analitza/tests/CMakeLists.txt
+++ b/analitza/tests/CMakeLists.txt
@@ -14,6 +14,14 @@ ecm_add_tests(
     LINK_LIBRARIES ${testLibs}
 )
 
+if(LLVM_FOUND)
+    ecm_add_tests(
+        analitzajittest.cpp
+
+        LINK_LIBRARIES ${testLibs}
+    )
+endif(LLVM_FOUND)
+
 ecm_add_test(
     TEST_NAME matchingtest
         matchingtest.cpp ../substituteexpression.cpp \
                ../abstractexpressiontransformer.cpp
diff --git a/analitza/tests/analitzajittest.cpp b/analitza/tests/analitzajittest.cpp
new file mode 100644
index 0000000..b16b3eb
--- /dev/null
+++ b/analitza/tests/analitzajittest.cpp
@@ -0,0 +1,54 @@
+/*************************************************************************************
 + *  Copyright (C) 2014 by Percy Camilo T. Aucahuasi <percy.camilo.ta@gmail.com>     \
* + *                                                                                 \
* + *  This program is free software; you can redistribute it and/or                  \
* + *  modify it under the terms of the GNU General Public License                    \
* + *  as published by the Free Software Foundation; either version 2                 \
* + *  of the License, or (at your option) any later version.                         \
* + *                                                                                 \
* + *  This program is distributed in the hope that it will be useful,                \
* + *  but WITHOUT ANY WARRANTY; without even the implied warranty of                 \
* + *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the                  \
* + *  GNU General Public License for more details.                                   \
* + *                                                                                 \
* + *  You should have received a copy of the GNU General Public License              \
* + *  along with this program; if not, write to the Free Software                    \
* + *  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA \
* + *************************************************************************************/
 +
+#include "analitzajittest.h"
+
+#include <QtTest/QTest>
+
+#include "jitanalyzer.h"
+
+QTEST_MAIN( AnalitzaJitTest )
+
+AnalitzaJitTest::AnalitzaJitTest(QObject *parent)
+ : QObject(parent)
+{}
+
+AnalitzaJitTest::~AnalitzaJitTest()
+{}
+
+void AnalitzaJitTest::initTestCase()
+{
+	a=new Analitza::JitAnalyzer;
+}
+
+void AnalitzaJitTest::cleanupTestCase()
+{
+	delete a;
+}
+
+void AnalitzaJitTest::testCalculate_data()
+{
+
+}
+
+void AnalitzaJitTest::testCalculate()
+{
+
+}
+
+#include "analitzajittest.moc"
diff --git a/analitza/tests/analitzajittest.h b/analitza/tests/analitzajittest.h
new file mode 100644
index 0000000..01aed39
--- /dev/null
+++ b/analitza/tests/analitzajittest.h
@@ -0,0 +1,47 @@
+/*************************************************************************************
 + *  Copyright (C) 2014 by Percy Camilo T. Aucahuasi <percy.camilo.ta@gmail.com>     \
* + *                                                                                 \
* + *  This program is free software; you can redistribute it and/or                  \
* + *  modify it under the terms of the GNU General Public License                    \
* + *  as published by the Free Software Foundation; either version 2                 \
* + *  of the License, or (at your option) any later version.                         \
* + *                                                                                 \
* + *  This program is distributed in the hope that it will be useful,                \
* + *  but WITHOUT ANY WARRANTY; without even the implied warranty of                 \
* + *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the                  \
* + *  GNU General Public License for more details.                                   \
* + *                                                                                 \
* + *  You should have received a copy of the GNU General Public License              \
* + *  along with this program; if not, write to the Free Software                    \
* + *  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA \
* + *************************************************************************************/
 +
+#ifndef JITANALITZATEST_H
+#define JITANALITZATEST_H
+
+#include <QObject>
+
+namespace Analitza { class JitAnalyzer; }
+
+/**
+	@author Percy Camilo T. Aucahuasi
+*/
+class AnalitzaJitTest : public QObject
+{
+Q_OBJECT
+	public:
+		AnalitzaJitTest(QObject *parent = 0);
+		~AnalitzaJitTest();
+	
+	private Q_SLOTS:
+		void initTestCase();
+		//TODO
+		void testCalculate_data();
+		void testCalculate();
+		
+		void cleanupTestCase();
+	private:
+		Analitza::JitAnalyzer *a;
+};
+
+#endif
diff --git a/cmake/FindLLVM.cmake b/cmake/FindLLVM.cmake
new file mode 100644
index 0000000..4441779
--- /dev/null
+++ b/cmake/FindLLVM.cmake
@@ -0,0 +1,109 @@
+# Find the native LLVM includes and libraries
+#
+# Defines the following variables
+#  LLVM_INCLUDE_DIR - where to find llvm include files
+#  LLVM_LIBRARY_DIR - where to find llvm libs
+#  LLVM_CFLAGS      - llvm compiler flags
+#  LLVM_LFLAGS      - llvm linker flags
+#  LLVM_MODULE_LIBS - list of llvm libs for working with modules.
+#  LLVM_FOUND       - True if llvm found.
+#  LLVM_VERSION     - Version string ("llvm-config --version")
+#
+# This module reads hints about search locations from variables
+#  LLVM_ROOT        - Preferred LLVM installation prefix (containing bin/, lib/, \
...) +#
+#  Note: One may specify these as environment variables if they are not specified as
+#   CMake variables or cache entries.
+
+#=============================================================================
+# Copyright 2014 Kevin Funk <kfunk@kde.org>
+#
+# Distributed under the OSI-approved BSD License (the "License");
+# see accompanying file Copyright.txt for details.
+#
+# This software is distributed WITHOUT ANY WARRANTY; without even the
+# implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
+# See the License for more information.
+#=============================================================================
+
+if (NOT LLVM_ROOT AND DEFINED ENV{LLVM_ROOT})
+    file(TO_CMAKE_PATH "$ENV{LLVM_ROOT}" LLVM_ROOT)
+endif()
+
+# if the user specified LLVM_ROOT, use that and fail otherwise
+if (LLVM_ROOT)
+  find_program(LLVM_CONFIG_EXECUTABLE NAMES llvm-config HINTS ${LLVM_ROOT}/bin DOC \
"llvm-config executable" NO_DEFAULT_PATH) +else()
+  # find llvm-config, prefer the one with a version suffix, e.g. llvm-config-3.3
+  # note: on some distributions, only 'llvm-config' is shipped, so let's always try \
to fallback on that +  find_program(LLVM_CONFIG_EXECUTABLE NAMES \
llvm-config-${LLVM_FIND_VERSION} llvm-config DOC "llvm-config executable") +
+  # other distributions don't ship llvm-config, but only some llvm-config-VERSION \
binary +  # try to deduce installed LLVM version by looking up llvm-nm in PATH and \
*then* find llvm-config-VERSION via that +  if (NOT LLVM_CONFIG_EXECUTABLE)
+    find_program(_llvmNmExecutable llvm-nm)
+    if (_llvmNmExecutable)
+      execute_process(COMMAND ${_llvmNmExecutable} --version OUTPUT_VARIABLE _out)
+      string(REGEX REPLACE ".*LLVM version ([^ \n]+).*" "\\1" _versionString \
"${_out}") +      find_program(LLVM_CONFIG_EXECUTABLE NAMES \
llvm-config-${_versionString} DOC "llvm-config executable") +    endif()
+  endif()
+endif()
+
+set(LLVM_FOUND FALSE)
+
+if (LLVM_CONFIG_EXECUTABLE)
+  # verify that we've found the correct version of llvm-config
+  execute_process(COMMAND ${LLVM_CONFIG_EXECUTABLE} --version
+    OUTPUT_VARIABLE LLVM_VERSION
+    OUTPUT_STRIP_TRAILING_WHITESPACE)
+
+  if (NOT LLVM_VERSION)
+    set(_LLVM_ERROR_MESSAGE "Failed to parse version from llvm-config")
+  elseif (LLVM_FIND_VERSION VERSION_GREATER LLVM_VERSION)
+    set(_LLVM_ERROR_MESSAGE "LLVM version too old: ${LLVM_VERSION}")
+  else()
+    message(STATUS "Found LLVM (version: ${LLVM_VERSION}): (using \
${LLVM_CONFIG_EXECUTABLE})") +    set(LLVM_FOUND TRUE)
+  endif()
+else()
+  set(_LLVM_ERROR_MESSAGE "Could NOT find 'llvm-config' executable")
+endif()
+
+if (LLVM_FOUND)
+  execute_process(
+    COMMAND ${LLVM_CONFIG_EXECUTABLE} --includedir
+    OUTPUT_VARIABLE LLVM_INCLUDE_DIR
+    OUTPUT_STRIP_TRAILING_WHITESPACE
+  )
+
+  execute_process(
+    COMMAND ${LLVM_CONFIG_EXECUTABLE} --libdir
+    OUTPUT_VARIABLE LLVM_LIBRARY_DIR
+    OUTPUT_STRIP_TRAILING_WHITESPACE
+  )
+
+  execute_process(
+    COMMAND ${LLVM_CONFIG_EXECUTABLE} --cppflags
+    OUTPUT_VARIABLE LLVM_CFLAGS
+    OUTPUT_STRIP_TRAILING_WHITESPACE
+  )
+
+  execute_process(
+    COMMAND ${LLVM_CONFIG_EXECUTABLE} --ldflags
+    OUTPUT_VARIABLE LLVM_LFLAGS
+    OUTPUT_STRIP_TRAILING_WHITESPACE
+  )
+
+  execute_process(
+    COMMAND ${LLVM_CONFIG_EXECUTABLE} --libs core bitreader asmparser analysis
+    OUTPUT_VARIABLE LLVM_MODULE_LIBS
+    OUTPUT_STRIP_TRAILING_WHITESPACE
+  )
+endif()
+
+if (LLVM_FIND_REQUIRED AND NOT LLVM_FOUND)
+  message(FATAL_ERROR "Could not find LLVM: ${_LLVM_ERROR_MESSAGE}")
+elseif(_LLVM_ERROR_MESSAGE)
+  message(STATUS "Could not find LLVM: ${_LLVM_ERROR_MESSAGE}")
+endif()
diff --git a/config-analitza.h.cmake b/config-analitza.h.cmake
index c557d8d..d6950bf 100644
--- a/config-analitza.h.cmake
+++ b/config-analitza.h.cmake
@@ -1,2 +1,3 @@
 #cmakedefine HAVE_OPENGL
-#cmakedefine HAVE_EIGEN3
\ No newline at end of file
+#cmakedefine HAVE_EIGEN3
+#cmakedefine HAVE_LLVM
\ No newline at end of file


[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic