Change the way to manage the variables and operations:
Calixte DENIZET [Thu, 26 Sep 2013 16:46:16 +0000 (18:46 +0200)]
* Use the Scilab native function instead of LLVM operations (we don't want to reimplement matrices operations in LLVM).
* Management of the allocation (a=1+1). The display of "a" does not work yet
* Add missing includes the llvm-wrapper.cpp creation

Change-Id: I25580d6532ad35fa352c0715896aae2e8c046c1f

scilab/modules/jit/Makefile.am
scilab/modules/jit/Makefile.in
scilab/modules/jit/includes/JITvisitor.hxx
scilab/modules/jit/src/cpp/llvm-wrapper-generated.cpp
scilab/modules/jit/src/cpp/llvm-wrapper.cpp

index ef54799..f47d78a 100644 (file)
@@ -71,8 +71,7 @@ testControlExp_LDADD  = $(check_LDADD)
 # This target transforms a basic code to llvm + clang code for the JIT
 BUILT_SOURCES = src/cpp/llvm-wrapper-generated.cpp
 src/cpp/llvm-wrapper-generated.cpp: src/cpp/llvm-wrapper.cpp
-       clang++ -emit-llvm  -I$(top_srcdir)/modules/types/includes/ -I$(top_srcdir)/modules/operations/includes/ -I$(top_srcdir)/modules/core/includes/  -I$(top_srcdir)/modules/ast/includes/ -I$(top_srcdir)/modules/localization/includes/ $(EIGEN_CPPFLAGS) -c src/cpp/llvm-wrapper.cpp -o - | llc-3.3 -march=cpp -cppgen=contents -o src/cpp/llvm-wrapper-generated.cpp
-
+       clang++ -emit-llvm  -I$(top_srcdir)/modules/types/includes/ -I$(top_srcdir)/modules/operations/includes/ -I$(top_srcdir)/modules/core/includes/  -I$(top_srcdir)/modules/ast/includes/ -I$(top_srcdir)/modules/localization/includes/ -I$(top_srcdir)/modules/symbol/includes/ -I$(top_srcdir)/modules/dynamic_link/includes/ $(EIGEN_CPPFLAGS) -c src/cpp/llvm-wrapper.cpp -o - |  llc-3.3 -march=cpp -cppgen=contents -o src/cpp/llvm-wrapper-generated.cpp || exit 1
 
 include $(top_srcdir)/Makefile.incl.am
 
index cb99c72..61d49ac 100644 (file)
@@ -990,7 +990,7 @@ uninstall-am: uninstall-libscijit_la_includeHEADERS \
        uninstall-pkglibLTLIBRARIES
 
 src/cpp/llvm-wrapper-generated.cpp: src/cpp/llvm-wrapper.cpp
-       clang++ -emit-llvm  -I$(top_srcdir)/modules/types/includes/ -I$(top_srcdir)/modules/operations/includes/ -I$(top_srcdir)/modules/core/includes/  -I$(top_srcdir)/modules/ast/includes/ -I$(top_srcdir)/modules/localization/includes/ $(EIGEN_CPPFLAGS) -c src/cpp/llvm-wrapper.cpp -o - | llc-3.3 -march=cpp -cppgen=contents -o src/cpp/llvm-wrapper-generated.cpp
+       clang++ -emit-llvm  -I$(top_srcdir)/modules/types/includes/ -I$(top_srcdir)/modules/operations/includes/ -I$(top_srcdir)/modules/core/includes/  -I$(top_srcdir)/modules/ast/includes/ -I$(top_srcdir)/modules/localization/includes/ -I$(top_srcdir)/modules/symbol/includes/ -I$(top_srcdir)/modules/dynamic_link/includes/ $(EIGEN_CPPFLAGS) -c src/cpp/llvm-wrapper.cpp -o - |  llc-3.3 -march=cpp -cppgen=contents -o src/cpp/llvm-wrapper-generated.cpp || exit 1
 
 # This target enables tests for Scilab
 check-local: $(top_builddir)/scilab-bin test
index 51240b7..caaadda 100644 (file)
@@ -57,10 +57,14 @@ extern "C" {
 
 #undef ID
 #undef LT
+#undef GT
+
+#include "llvm/IR/Constants.h"
 #include "llvm/IR/DerivedTypes.h"
 #include "llvm/IR/IRBuilder.h"
 #include "llvm/IR/LLVMContext.h"
 #include "llvm/IR/Module.h"
+#include "llvm/IR/Type.h"
 
 #include "llvm/Analysis/Verifier.h"
 #include "llvm/Support/TargetSelect.h"
@@ -70,490 +74,609 @@ extern "C" {
 #include "llvm/IR/DataLayout.h"
 #include "vmkit_core.h"
 
-namespace ast
-{
-       typedef double (*jitptr_t) ();
-
-       class JITVisitor : public ConstVisitor
-       {
-       private:
-               /*
-                * Attributes
-                */
-               llvm::Value* _result;
-               bool m_bSingleResult;
-               llvm::LLVMContext *context;
-               llvm::Module *TheModule;
-               llvm::IRBuilder<> *Builder;
-               llvm::ExecutionEngine* ee;
-               llvm::FunctionPassManager* pm;
-
-
-        void visit (const SeqExp  &e)
-        {
-            visitprivate(e);
-        }
-
-        void visit (const IntExp &e)
-        {
-            visitprivate(e);
-        }
-
-        void visit (const FloatExp &e)
-        {
-            visitprivate(e);
-        }
-
-        void visit (const DoubleExp &e)
-        {
-            visitprivate(e);
-        }
-
-        void visit (const OpExp &e)
-        {
-            visitprivate(e);
-        }
-
-        void visit (const SimpleVar &e)
-        {
-            visitprivate(e);
-        }
-
-
-       public:
-        JITVisitor() : ConstVisitor() {
-               llvm::InitializeNativeTarget();
-               context = &llvm::getGlobalContext();
-               Builder = new llvm::IRBuilder<> (*context);
-               _result = NULL;
-               m_bSingleResult = false;
-               TheModule = new llvm::Module("scilab jit", *context);
-
-               std::string err;
-               llvm::EngineBuilder engine (TheModule);
-               llvm::TargetOptions options;
-               options.NoFramePointerElim = true;
-               engine.setTargetOptions(options);
-               engine.setEngineKind(llvm::EngineKind::JIT);
-               engine.setErrorStr(&err);
-
-               ee = engine.create();
-               if (!ee) {
-                       fprintf(stderr, "Could not create ExecutionEngine: %s\n", err.c_str());
-                       exit(1);
-               }
-               ee->DisableLazyCompilation(0);
-               ee->addModule(TheModule);
-               TheModule->setDataLayout(ee->getDataLayout()->getStringRepresentation());
-               pm = NULL; /* TODO : init */
-        }
-
-        void result_set(llvm::Value* const gtVal)
-        {
-            m_bSingleResult = true;
-            _result = gtVal;
-        }
-
-        llvm::Value* result_get()
-        {
-               return  _result;
-        }
-
-        void visitprivate(const DoubleExp &e) {
-               if (e.getBigDouble() == NULL)
-               {
-                       Double *pdbl = new Double(e.value_get());
-                       (const_cast<DoubleExp *>(&e))->setBigDouble(pdbl);
-               }
-               llvm::Value* res = llvm::ConstantFP::get(llvm::getGlobalContext(), llvm::APFloat(e.getBigDouble()->get(0)));
-               result_set(res);
-               _result->dump();
-        }
-
-       void visitprivate(const FloatExp &e) {
-       }
-
-       void visitprivate(const IntExp &e) {
-       }
-
-       void visitprivate(const SeqExp &e) {
-
-            //T execMe;
-            std::list<Exp *>::const_iterator   itExp;
-
-            for (itExp = e.exps_get().begin (); itExp != e.exps_get().end (); ++itExp)
-            {
-               //reset default values
-               result_set(NULL);
-               llvm::FunctionType *FT = llvm::FunctionType::get(llvm::Type::getDoubleTy(*context), false);
-               llvm::Function *TheFunction = llvm::Function::Create(FT, llvm::Function::ExternalLinkage, "TheFunction", TheModule);
-               llvm::BasicBlock *BB = llvm::BasicBlock::Create(llvm::getGlobalContext(), "entry", TheFunction);
-               Builder->SetInsertPoint(BB);
+#undef WHITE
+#undef Max
 
-               (*itExp)->accept(*this);
+#include <sys/types.h>
 
+#include "llvm/IR/Attributes.h"
+#include "llvm/IR/Function.h"
+#include "llvm/IR/Instructions.h"
+#include "llvm/CodeGen/GCStrategy.h"
+#include "llvm/CodeGen/JITCodeEmitter.h"
+#include "llvm/CodeGen/MachineFunction.h"
+#include "llvm/ExecutionEngine/ExecutionEngine.h"
+#include "llvm/Support/CommandLine.h"
+#include "llvm/Support/ManagedStatic.h"
+//#include "llvm/Support/Debug.h"
+//#include "llvm/Support/raw_ostream.h"
+#include <llvm/LinkAllPasses.h>
 
-                if (result_get() != NULL)
-                {
-                       Builder->CreateRet(result_get());
-                       TheFunction->dump();
-                       void* res = ee->getPointerToFunction(TheFunction);
-                       jitptr_t myJit = (jitptr_t) res;
-                       double result = myJit();
-                       std::cout << "result : " << result << std::endl;
-                }
-            }
-       }
-
-               llvm::Value* const llvm_value_one = llvm::ConstantFP::get(llvm::getGlobalContext(),llvm::APFloat(1.0));
-               llvm::Value* llvm_rec_power (llvm::Value* x, llvm::Value* n)
-               {
-                       llvm::ConstantFP* ncfp = llvm::dyn_cast<llvm::ConstantFP>(n);
-
-                       if (ncfp->isZero())
-                       {
-                               // return 1
-                               return llvm_value_one;
-                       }
-                       if (ncfp->isNegative()){
-                               llvm::Value* moduloN = Builder->CreateFMul(llvm::ConstantFP::get(llvm::getGlobalContext(),llvm::APFloat(-1.0)), n);
-                               // return 1 / (x * llvm_rec_power(x, (-1 * n)-1))
-                               return Builder->CreateFDiv(llvm_value_one, Builder->CreateFMul(x, llvm_rec_power(x, Builder->CreateFSub(moduloN, llvm_value_one, "OpExp::minus")), "OpExp::times"), "OpExp::rdivide");
-                       } else {
-                               // return x * llvm_rec_power(x, n-1)
-                               return Builder->CreateFMul(x, llvm_rec_power(x,Builder->CreateFSub(n, llvm_value_one, "OpExp::minus")), "OpExp::times");
-                       }
-               }
-       void visitprivate(const OpExp &e) {
-               /*
-            switch (e.kind_get())
-            {
-               case OpExp::invalid_kind :
-               {
-                       std::cout << "OpExp::invalid_kind" << std::endl;
-                       break;
-               }
-               case OpExp::bool_kind :
-               {
-                       std::cout << "OpExp::bool_kind" << std::endl;
-                       break;
-               }
-               case OpExp::string_kind :
-               {
-                       std::cout << "OpExp::string_kind" << std::endl;
-                       break;
-               }
-               case OpExp::integer_kind :
-               {
-                       std::cout << "OpExp::integer_kind" << std::endl;
-                       break;
-               }
-               case OpExp::float_kind :
-               {
-                       std::cout << "OpExp::float_kind" << std::endl;
-                       break;
-               }
-               case OpExp::double_kind :
-               {
-                       std::cout << "OpExp::double_kind" << std::endl;
-                       break;
-               }
-               case OpExp::float_complex_kind :
-               {
-                       break;
-               }
-               case OpExp::double_complex_kind :
-               {
-                       break;
-               }
-               case OpExp::bool_matrix_kind :
-               {
-                       break;
-               }
-               case OpExp::string_matrix_kind :
-               {
-                       break;
-               }
-               case OpExp::integer_matrix_kind :
-               {
-                       break;
-               }
-               case OpExp::float_matrix_kind :
-               {
-                       break;
-               }
-               case OpExp::double_matrix_kind :
-               {
-                       break;
-               }
-               case OpExp::float_complex_matrix_kind :
-               {
-                       break;
-               }
-               case OpExp::double_complex_matrix_kind :
-               {
-                       break;
-               }
-               case OpExp::matrix_kind :
-               {
-                       break;
-               }
-            }
-                */
-
-               /*getting what to assign*/
-               e.left_get().accept(*this);
-               llvm::Value *pITL = result_get();
+namespace llvm
+{
+#include "../src/cpp/llvm-wrapper-generated.cpp"
+}
 
-            /*getting what to assign*/
-            e.right_get().accept(*this);
-            llvm::Value *pITR = result_get();
+namespace ast
+{
+typedef double (*jitptr_t) ();
 
-            llvm::Value *pResult = NULL;
-            switch (e.oper_get())
+class JITVisitor : public ConstVisitor
+{
+private:
+    /*
+     * Attributes
+     */
+    llvm::Value* _result;
+    bool m_bSingleResult;
+    llvm::LLVMContext *context;
+    llvm::Module *TheModule;
+    llvm::IRBuilder<> *Builder;
+    llvm::ExecutionEngine* ee;
+    llvm::FunctionPassManager* pm;
+    llvm::Type* uintptrType;
+    symbol::Context * scilabContext;
+
+
+    void visit (const SeqExp  &e)
+    {
+        visitprivate(e);
+    }
+
+    void visit (const IntExp &e)
+    {
+        visitprivate(e);
+    }
+
+    void visit (const FloatExp &e)
+    {
+        visitprivate(e);
+    }
+
+    void visit (const DoubleExp &e)
+    {
+        visitprivate(e);
+    }
+
+    void visit (const OpExp &e)
+    {
+        visitprivate(e);
+    }
+
+    void visit (const SimpleVar &e)
+    {
+        visitprivate(e);
+    }
+
+
+public:
+    JITVisitor() : ConstVisitor()
+    {
+        llvm::InitializeNativeTarget();
+        context = &llvm::getGlobalContext();
+        Builder = new llvm::IRBuilder<> (*context);
+        _result = NULL;
+        m_bSingleResult = false;
+        TheModule = new llvm::Module("scilab jit", *context);
+
+        std::string err;
+        llvm::EngineBuilder engine (TheModule);
+        llvm::TargetOptions options;
+        options.NoFramePointerElim = true;
+        engine.setTargetOptions(options);
+        engine.setEngineKind(llvm::EngineKind::JIT);
+        engine.setErrorStr(&err);
+
+        ee = engine.create();
+        if (!ee)
+        {
+            fprintf(stderr, "Could not create ExecutionEngine: %s\n", err.c_str());
+            exit(1);
+        }
+        ee->DisableLazyCompilation(0);
+        ee->addModule(TheModule);
+        TheModule->setDataLayout(ee->getDataLayout()->getStringRepresentation());
+        pm = NULL; /* TODO : init */
+
+        uintptrType = TheModule->getPointerSize() == llvm::Module::Pointer32 ?
+                      llvm::Type::getInt32Ty(*context) : llvm::Type::getInt64Ty(*context);
+
+        TheModule = llvm::makeLLVMModuleContents(TheModule);
+        //TheModule->dump();
+
+        for (llvm::Module::iterator cur = TheModule->begin(), end = TheModule->end(); cur != end; cur++)
+        {
+            void* ptr = dlsym(RTLD_DEFAULT, cur->getName().data());
+            //printf("%s ---> %p\n", cur->getName().data(), ptr);
+            if (ptr)
             {
-               case OpExp::plus :
-               {
-                       pResult = Builder->CreateFAdd(pITL, pITR, "OpExp::plus");
-                       break;
-               }
-               case OpExp::minus :
-               {
-                       pResult = Builder->CreateFSub(pITL, pITR, "OpExp::minus");
-                       break;
-               }
-               case OpExp::times :
-               {
-                       pResult = Builder->CreateFMul(pITL, pITR, "OpExp::times");
-                       break;
-               }
-               case OpExp::rdivide :
-               {
-                       pResult = Builder->CreateFDiv(pITL, pITR, "OpExp::rdivide");
-                       break;
-               }
-               case OpExp::ldivide :
-               {
-                       pResult = Builder->CreateFDiv(pITR, pITL, "OpExp::ldivide");
-                       break;
-               }
-               case OpExp::power :
-               {
-                       pResult = llvm_rec_power(pITL, pITR);
-                       break;
-               }
-               case OpExp::unaryMinus :
-               {
-                       pResult = Builder->CreateFSub(pITL, pITR, "OpExp::unaryMinus");
-                       break;
-               }
-               case OpExp::eq :
-               {
-                       pResult = Builder->CreateUIToFP(Builder->CreateFCmpUEQ(pITL, pITR, "OpExp::eq"), llvm::Type::getDoubleTy(llvm::getGlobalContext()), "booltodouble");
-                       break;
-               }
-               case OpExp::ne :
-               {
-                       pResult = Builder->CreateUIToFP(Builder->CreateNot(Builder->CreateFCmpUEQ(pITL, pITR, "OpExp::eq"),"not"), llvm::Type::getDoubleTy(llvm::getGlobalContext()), "booltodouble");
-                       break;
-               }
-               case OpExp::lt :
-               {
-                       pResult = Builder->CreateUIToFP(Builder->CreateFCmpULT(pITL, pITR, "OpExp::lt"), llvm::Type::getDoubleTy(llvm::getGlobalContext()), "booltodouble");
-                       break;
-               }
-               case OpExp::le :
-               {
-                       pResult = Builder->CreateUIToFP(Builder->CreateFCmpULE(pITL, pITR, "OpExp::le"), llvm::Type::getDoubleTy(llvm::getGlobalContext()), "booltodouble");
-                       break;
-               }
-               case OpExp::gt :
-               {
-                       pResult = Builder->CreateUIToFP(Builder->CreateFCmpUGT(pITL, pITR, "OpExp::gt"), llvm::Type::getDoubleTy(llvm::getGlobalContext()), "booltodouble");
-                       break;
-               }
-               case OpExp::ge :
-               {
-                       pResult = Builder->CreateUIToFP(Builder->CreateFCmpUGE(pITL, pITR, "OpExp::ge"), llvm::Type::getDoubleTy(llvm::getGlobalContext()), "booltodouble");
-                       break;
-               }
-               default:
-               {
-                       std::cout << "Operation not supported, returning 42..." << std::endl;
-                       pResult = llvm::ConstantFP::get(llvm::getGlobalContext(),llvm::APFloat(42.0));
-                       break;
-               }
+                ee->updateGlobalMapping(cur, ptr);
             }
-
-            if(pResult == NULL) {
-               result_set(llvm::ConstantFP::get(llvm::getGlobalContext(), llvm::APFloat(42.0)));
-            }
-            result_set(pResult);
-       }
-
-       void visitprivate (const SimpleVar &e)
-       {
-             /* Not implemented. It only exits Scilab... */
-             std::cout << "VISIT SIMPLEVAR, EXITING NOW..." << std::endl;
-             ConfigVariable::setExitStatus(0);
-             ConfigVariable::setForceQuit(true);
-       }
-
-        void visit (const BoolExp &e)
-        {
-//            visitprivate(e);
-        }
-
-        void visit (const NilExp &e)
-        {
-//            visitprivate(e);
-        }
-
-        void visit (const ColonVar &e)
-        {
-//            visitprivate(e);
         }
 
-        void visit (const DollarVar &e)
-        {
-//            visitprivate(e);
-        }
-
-        void visit (const ArrayListVar &e)
-        {
-//            visitprivate(e);
-        }
+        scilabContext = symbol::Context::getInstance();
+    }
 
-        void visit (const FieldExp &e)
-        {
-//            visitprivate(e);
-        }
+    void result_set(llvm::Value* const gtVal)
+    {
+        m_bSingleResult = true;
+        _result = gtVal;
+    }
 
+    llvm::Value* result_get()
+    {
+        return  _result;
+    }
 
-        void visit (const LogicalOpExp &e)
+    void visitprivate(const DoubleExp &e)
+    {
+        if (e.getBigDouble() == NULL)
         {
-//            visitprivate(e);
+            Double *pdbl = new Double(e.value_get());
+            (const_cast<DoubleExp *>(&e))->setBigDouble(pdbl);
         }
 
-        void visit (const AssignExp &e)
-        {
-//            visitprivate(e);
-        }
+        //              llvm::Value* res = llvm::ConstantFP::get(llvm::getGlobalContext(), llvm::APFloat(e.getBigDouble()));
+        llvm::Value* res = llvm::ConstantInt::get(uintptrType, (uintptr_t)e.getBigDouble());
+        res = Builder->CreateIntToPtr(res, llvm::PointerType::getUnqual(TheModule->getTypeByName("class.types::Double")));
+        res->dump();
+        result_set(res);
+        _result->dump();
+    }
 
-        void visit (const CellCallExp &e)
-        {
-//            visitprivate(e);
-        }
+    void visitprivate(const FloatExp &e)
+    {
+    }
 
-        void visit (const CallExp &e)
-        {
-//            visitprivate(e);
-        }
+    void visitprivate(const IntExp &e)
+    {
+    }
 
-        void visit (const IfExp &e)
-        {
-//            visitprivate(e);
-        }
+    void visitprivate(const SeqExp &e)
+    {
 
-        void visit (const TryCatchExp &e)
-        {
-//            visitprivate(e);
-        }
+        //T execMe;
+        std::list<Exp *>::const_iterator    itExp;
 
-        void visit (const WhileExp &e)
+        for (itExp = e.exps_get().begin (); itExp != e.exps_get().end (); ++itExp)
         {
-//            visitprivate(e);
-        }
+            //reset default values
+            result_set(NULL);
+            llvm::FunctionType *FT = llvm::FunctionType::get(llvm::Type::getDoubleTy(*context), false);
+            llvm::Function *TheFunction = llvm::Function::Create(FT, llvm::Function::ExternalLinkage, "TheFunction", TheModule);
+            llvm::BasicBlock *BB = llvm::BasicBlock::Create(llvm::getGlobalContext(), "entry", TheFunction);
+            Builder->SetInsertPoint(BB);
 
-        void visit (const ForExp &e)
-        {
-//            visitprivate(e);
-        }
+            (*itExp)->accept(*this);
 
-        void visit (const BreakExp &e)
-        {
-//            visitprivate(e);
+            if (1 || result_get() != NULL)
+            {
+                Builder->CreateRet(result_get());
+                TheFunction->dump();
+                void* res = ee->getPointerToFunction(TheFunction);
+                jitptr_t myJit = (jitptr_t) res;
+                double result = myJit();
+                std::cout << "coucou result : " << result << std::endl;
+            }
         }
+    }
+
+    llvm::Value* const llvm_value_one = llvm::ConstantFP::get(llvm::getGlobalContext(), llvm::APFloat(1.0));
+    llvm::Value* llvm_rec_power (llvm::Value* x, llvm::Value* n)
+    {
+        llvm::ConstantFP* ncfp = llvm::dyn_cast<llvm::ConstantFP>(n);
+
+        if (ncfp->isZero())
+        {
+            // return 1
+            return llvm_value_one;
+        }
+        if (ncfp->isNegative())
+        {
+            llvm::Value* moduloN = Builder->CreateFMul(llvm::ConstantFP::get(llvm::getGlobalContext(), llvm::APFloat(-1.0)), n);
+            // return 1 / (x * llvm_rec_power(x, (-1 * n)-1))
+            return Builder->CreateFDiv(llvm_value_one, Builder->CreateFMul(x, llvm_rec_power(x, Builder->CreateFSub(moduloN, llvm_value_one, "OpExp::minus")), "OpExp::times"), "OpExp::rdivide");
+        }
+        else
+        {
+            // return x * llvm_rec_power(x, n-1)
+            return Builder->CreateFMul(x, llvm_rec_power(x, Builder->CreateFSub(n, llvm_value_one, "OpExp::minus")), "OpExp::times");
+        }
+    }
+    void visitprivate(const OpExp &e)
+    {
+        /*
+          switch (e.kind_get())
+          {
+          case OpExp::invalid_kind :
+          {
+          std::cout << "OpExp::invalid_kind" << std::endl;
+          break;
+          }
+          case OpExp::bool_kind :
+          {
+          std::cout << "OpExp::bool_kind" << std::endl;
+          break;
+          }
+          case OpExp::string_kind :
+          {
+          std::cout << "OpExp::string_kind" << std::endl;
+          break;
+          }
+          case OpExp::integer_kind :
+          {
+          std::cout << "OpExp::integer_kind" << std::endl;
+          break;
+          }
+          case OpExp::float_kind :
+          {
+          std::cout << "OpExp::float_kind" << std::endl;
+          break;
+          }
+          case OpExp::double_kind :
+          {
+          std::cout << "OpExp::double_kind" << std::endl;
+          break;
+          }
+          case OpExp::float_complex_kind :
+          {
+          break;
+          }
+          case OpExp::double_complex_kind :
+          {
+          break;
+          }
+          case OpExp::bool_matrix_kind :
+          {
+          break;
+          }
+          case OpExp::string_matrix_kind :
+          {
+          break;
+          }
+          case OpExp::integer_matrix_kind :
+          {
+          break;
+          }
+          case OpExp::float_matrix_kind :
+          {
+          break;
+          }
+          case OpExp::double_matrix_kind :
+          {
+          break;
+          }
+          case OpExp::float_complex_matrix_kind :
+          {
+          break;
+          }
+          case OpExp::double_complex_matrix_kind :
+          {
+          break;
+          }
+          case OpExp::matrix_kind :
+          {
+          break;
+          }
+          }
+        */
+
+        /*getting what to assign*/
+        e.left_get().accept(*this);
+        llvm::Value *pITL = result_get();
+
+        /*getting what to assign*/
+        e.right_get().accept(*this);
+        llvm::Value *pITR = result_get();
+
+        llvm::Value *pResult = NULL;
+        switch (e.oper_get())
+        {
+            case OpExp::plus :
+            {
+                //%5 = call i32 @_Z17AddDoubleToDoublePN5types6DoubleES1_PS1_(%"class.types::Double"* %3, %"class.types::Double"* %4, %"class.types::Double"** %pdbl1)
+                //                      pResult = Builder->CreateFAdd(pITL, pITR, "OpExp::plus");
 
-        void visit (const ContinueExp &e)
-        {
-//            visitprivate(e);
-        }
+                llvm::Value * tmp = Builder->CreateAlloca(llvm::PointerType::getUnqual(TheModule->getTypeByName("class.types::Double")));
 
-        void visit (const ReturnExp &e)
-        {
-//            visitprivate(e);
-        }
+                //printf("%p \n",TheModule->getFunction("_Z17AddDoubleToDoublePN5types6DoubleES1_PS1_"));
 
-        void visit (const SelectExp &e)
-        {
-//            visitprivate(e);
-        }
+                Builder->CreateCall3(TheModule->getFunction("_Z17AddDoubleToDoublePN5types6DoubleES1_PS1_"), pITR, pITL, tmp);
 
-        void visit (const CaseExp &e)
-        {
-//            visitprivate(e);
+                pResult = Builder->CreateLoad(tmp);
+                break;
+            }
+            case OpExp::minus :
+            {
+                pResult = Builder->CreateFSub(pITL, pITR, "OpExp::minus");
+                break;
+            }
+            case OpExp::times :
+            {
+                pResult = Builder->CreateFMul(pITL, pITR, "OpExp::times");
+                break;
+            }
+            case OpExp::rdivide :
+            {
+                pResult = Builder->CreateFDiv(pITL, pITR, "OpExp::rdivide");
+                break;
+            }
+            case OpExp::ldivide :
+            {
+                pResult = Builder->CreateFDiv(pITR, pITL, "OpExp::ldivide");
+                break;
+            }
+            case OpExp::power :
+            {
+                pResult = llvm_rec_power(pITL, pITR);
+                break;
+            }
+            case OpExp::unaryMinus :
+            {
+                pResult = Builder->CreateFSub(pITL, pITR, "OpExp::unaryMinus");
+                break;
+            }
+            case OpExp::eq :
+            {
+                pResult = Builder->CreateUIToFP(Builder->CreateFCmpUEQ(pITL, pITR, "OpExp::eq"), llvm::Type::getDoubleTy(llvm::getGlobalContext()), "booltodouble");
+                break;
+            }
+            case OpExp::ne :
+            {
+                pResult = Builder->CreateUIToFP(Builder->CreateNot(Builder->CreateFCmpUEQ(pITL, pITR, "OpExp::eq"), "not"), llvm::Type::getDoubleTy(llvm::getGlobalContext()), "booltodouble");
+                break;
+            }
+            case OpExp::lt :
+            {
+                pResult = Builder->CreateUIToFP(Builder->CreateFCmpULT(pITL, pITR, "OpExp::lt"), llvm::Type::getDoubleTy(llvm::getGlobalContext()), "booltodouble");
+                break;
+            }
+            case OpExp::le :
+            {
+                pResult = Builder->CreateUIToFP(Builder->CreateFCmpULE(pITL, pITR, "OpExp::le"), llvm::Type::getDoubleTy(llvm::getGlobalContext()), "booltodouble");
+                break;
+            }
+            case OpExp::gt :
+            {
+                pResult = Builder->CreateUIToFP(Builder->CreateFCmpUGT(pITL, pITR, "OpExp::gt"), llvm::Type::getDoubleTy(llvm::getGlobalContext()), "booltodouble");
+                break;
+            }
+            case OpExp::ge :
+            {
+                pResult = Builder->CreateUIToFP(Builder->CreateFCmpUGE(pITL, pITR, "OpExp::ge"), llvm::Type::getDoubleTy(llvm::getGlobalContext()), "booltodouble");
+                break;
+            }
+            default:
+            {
+                std::cout << "Operation not supported, returning 42..." << std::endl;
+                pResult = llvm::ConstantFP::get(llvm::getGlobalContext(), llvm::APFloat(42.0));
+                break;
+            }
         }
 
-        void visit (const ArrayListExp &e)
+        if (pResult == NULL)
         {
-//            visitprivate(e);
+            result_set(llvm::ConstantFP::get(llvm::getGlobalContext(), llvm::APFloat(42.0)));
         }
+        result_set(pResult);
+    }
 
-        void visit (const AssignListExp &e)
-        {
-//            visitprivate(e);
-        }
+    void visitprivate (const AssignExp &e)
+    {
+        /*getting what to assign*/
 
-        void visit (const NotExp &e)
+        const SimpleVar *pVar = dynamic_cast<const SimpleVar*>(&e.left_exp_get());
+        if (pVar)
         {
-//            visitprivate(e);
-        }
+            // x = ?
+            /*getting what to assign*/
+            e.right_exp_get().accept(*this);
 
-        void visit (const TransposeExp &e)
-        {
-//            visitprivate(e);
-        }
+            llvm::Value *pITR = result_get();
+            //reset result
+            result_set(NULL);
 
-        void visit (const VarDec &e)
-        {
-//            visitprivate(e);
-        }
+            //mod->getFunction("_ZN6symbol7Context3putERKNS_6SymbolERN5types12InternalTypeE");
+            llvm::Value * llvmScilabContext = llvm::ConstantInt::get(uintptrType, (uintptr_t)scilabContext);
+            llvmScilabContext = Builder->CreateIntToPtr(llvmScilabContext, llvm::PointerType::getUnqual(TheModule->getTypeByName("class.symbol::Context")));
 
-        void visit (const FunctionDec &e)
-        {
-//            visitprivate(e);
-        }
+            llvm::Value * llvmSym = llvm::ConstantInt::get(uintptrType, (uintptr_t)&pVar->name_get());
+            llvmSym = Builder->CreateIntToPtr(llvmSym, llvm::PointerType::getUnqual(TheModule->getTypeByName("class.symbol::Symbol")));
+            llvmSym->dump();
 
-        void visit(const ListExp &e)
-        {
-//            visitprivate(e);
-        }
-        void visit (const MatrixExp &e)
-        {
-//            visitprivate(e);
-        }
+            Builder->CreateCall3(TheModule->getFunction("_ZN6symbol7Context3putERKNS_6SymbolERN5types12InternalTypeE"), llvmScilabContext, llvmSym, pITR);
 
-        void visit (const MatrixLineExp &e)
-        {
-//            visitprivate(e);
+            //symbol::Context::getInstance()->put(pVar->name_get(), *pIT);
+            return;
         }
 
-        void visit (const CellExp &e)
-        {
-//            visitprivate(e);
-        }
+        llvm::Value *pResult = NULL;
+    }
 
-        void visit (const StringExp &e)
-        {
-//            visitprivate(e);
-        }
+    void visitprivate (const SimpleVar &e)
+    {
+        /*               InternalType * pI = symbol::Context::getInstance()->get(e.name_get());
+                result_set(pI);
+                if (pI != NULL)
+                {
+                    if (e.is_verbose() && pI->isCallable() == false && ConfigVariable::isPromptShow())
+                    {
+                        std::wostringstream ostr;
+                        ostr << e.name_get().name_get() << L"  = " << L"(" << pI->getRef() << L")" << std::endl;
+                        ostr << std::endl;
+                        scilabWriteW(ostr.str().c_str());
+                        VariableToString(pI);
+                    }
+            else
+            {
 
-        void visit (const CommentExp &e)
-        {
-//            visitprivate(e);
-        }
-       };
+            }
+                }
+                else
+                {
+                    wchar_t szError[bsiz];
+                    os_swprintf(szError, bsiz, _W("Undefined variable: %ls\n"), e.name_get().name_get().c_str());
+                    throw ScilabError(szError, 999, e.location_get());
+                    //Err, SimpleVar doesn't exist in Scilab scopes.
+            }*/
+    }
+
+    void visit (const BoolExp &e)
+    {
+        //            visitprivate(e);
+    }
+
+    void visit (const NilExp &e)
+    {
+        //            visitprivate(e);
+    }
+
+    void visit (const ColonVar &e)
+    {
+        //            visitprivate(e);
+    }
+
+    void visit (const DollarVar &e)
+    {
+        //            visitprivate(e);
+    }
+
+    void visit (const ArrayListVar &e)
+    {
+        //            visitprivate(e);
+    }
+
+    void visit (const FieldExp &e)
+    {
+        //            visitprivate(e);
+    }
+
+
+    void visit (const LogicalOpExp &e)
+    {
+        //            visitprivate(e);
+    }
+
+    void visit (const AssignExp &e)
+    {
+        visitprivate(e);
+    }
+
+    void visit (const CellCallExp &e)
+    {
+        //            visitprivate(e);
+    }
+
+    void visit (const CallExp &e)
+    {
+        //            visitprivate(e);
+    }
+
+    void visit (const IfExp &e)
+    {
+        //            visitprivate(e);
+    }
+
+    void visit (const TryCatchExp &e)
+    {
+        //            visitprivate(e);
+    }
+
+    void visit (const WhileExp &e)
+    {
+        //            visitprivate(e);
+    }
+
+    void visit (const ForExp &e)
+    {
+        //            visitprivate(e);
+    }
+
+    void visit (const BreakExp &e)
+    {
+        //            visitprivate(e);
+    }
+
+    void visit (const ContinueExp &e)
+    {
+        //            visitprivate(e);
+    }
+
+    void visit (const ReturnExp &e)
+    {
+        //            visitprivate(e);
+    }
+
+    void visit (const SelectExp &e)
+    {
+        //            visitprivate(e);
+    }
+
+    void visit (const CaseExp &e)
+    {
+        //            visitprivate(e);
+    }
+
+    void visit (const ArrayListExp &e)
+    {
+        //            visitprivate(e);
+    }
+
+    void visit (const AssignListExp &e)
+    {
+        //            visitprivate(e);
+    }
+
+    void visit (const NotExp &e)
+    {
+        //            visitprivate(e);
+    }
+
+    void visit (const TransposeExp &e)
+    {
+        //            visitprivate(e);
+    }
+
+    void visit (const VarDec &e)
+    {
+        //            visitprivate(e);
+    }
+
+    void visit (const FunctionDec &e)
+    {
+        //            visitprivate(e);
+    }
+
+    void visit(const ListExp &e)
+    {
+        //            visitprivate(e);
+    }
+    void visit (const MatrixExp &e)
+    {
+        //            visitprivate(e);
+    }
+
+    void visit (const MatrixLineExp &e)
+    {
+        //            visitprivate(e);
+    }
+
+    void visit (const CellExp &e)
+    {
+        //            visitprivate(e);
+    }
+
+    void visit (const StringExp &e)
+    {
+        //            visitprivate(e);
+    }
+
+    void visit (const CommentExp &e)
+    {
+        //            visitprivate(e);
+    }
+};
 }
 #endif // !AST_JITVISITOR_HXX
 
+
index 7668c95..f4d76e4 100644 (file)
@@ -7,384 +7,18 @@ Module* makeLLVMModuleContents(Module *mod)
     mod->setModuleIdentifier("<stdin>");
 
     // Type Definitions
-    StructType *StructTy_class_std__ios_base__Init = mod->getTypeByName("class.std::ios_base::Init");
-    if (!StructTy_class_std__ios_base__Init)
-    {
-        StructTy_class_std__ios_base__Init = StructType::create(mod->getContext(), "class.std::ios_base::Init");
-    }
-    std::vector<Type*>StructTy_class_std__ios_base__Init_fields;
-    StructTy_class_std__ios_base__Init_fields.push_back(IntegerType::get(mod->getContext(), 8));
-    if (StructTy_class_std__ios_base__Init->isOpaque())
-    {
-        StructTy_class_std__ios_base__Init->setBody(StructTy_class_std__ios_base__Init_fields, /*isPacked=*/false);
-    }
-
-    PointerType* PointerTy_0 = PointerType::get(StructTy_class_std__ios_base__Init, 0);
-
-    PointerType* PointerTy_1 = PointerType::get(IntegerType::get(mod->getContext(), 8), 0);
-
-    std::vector<Type*>StructTy_3_fields;
-    StructTy_3_fields.push_back(IntegerType::get(mod->getContext(), 32));
-    std::vector<Type*>FuncTy_5_args;
-    FunctionType* FuncTy_5 = FunctionType::get(
-                                 /*Result=*/Type::getVoidTy(mod->getContext()),
-                                 /*Params=*/FuncTy_5_args,
-                                 /*isVarArg=*/false);
-
-    PointerType* PointerTy_4 = PointerType::get(FuncTy_5, 0);
-
-    StructTy_3_fields.push_back(PointerTy_4);
-    StructType *StructTy_3 = StructType::get(mod->getContext(), StructTy_3_fields, /*isPacked=*/false);
-
-    ArrayType* ArrayTy_2 = ArrayType::get(StructTy_3, 1);
-
-    PointerType* PointerTy_6 = PointerType::get(ArrayTy_2, 0);
-
-    std::vector<Type*>FuncTy_8_args;
-    FuncTy_8_args.push_back(PointerTy_0);
-    FunctionType* FuncTy_8 = FunctionType::get(
-                                 /*Result=*/Type::getVoidTy(mod->getContext()),
-                                 /*Params=*/FuncTy_8_args,
-                                 /*isVarArg=*/false);
-
-    PointerType* PointerTy_7 = PointerType::get(FuncTy_8, 0);
-
-    std::vector<Type*>FuncTy_10_args;
-    FuncTy_10_args.push_back(PointerTy_1);
-    FunctionType* FuncTy_10 = FunctionType::get(
-                                  /*Result=*/Type::getVoidTy(mod->getContext()),
-                                  /*Params=*/FuncTy_10_args,
-                                  /*isVarArg=*/false);
-
-    PointerType* PointerTy_9 = PointerType::get(FuncTy_10, 0);
-
-    std::vector<Type*>FuncTy_12_args;
-    FuncTy_12_args.push_back(PointerTy_9);
-    FuncTy_12_args.push_back(PointerTy_1);
-    FuncTy_12_args.push_back(PointerTy_1);
-    FunctionType* FuncTy_12 = FunctionType::get(
-                                  /*Result=*/IntegerType::get(mod->getContext(), 32),
-                                  /*Params=*/FuncTy_12_args,
-                                  /*isVarArg=*/false);
-
-    PointerType* PointerTy_11 = PointerType::get(FuncTy_12, 0);
-
-    std::vector<Type*>FuncTy_13_args;
-    FunctionType* FuncTy_13 = FunctionType::get(
-                                  /*Result=*/IntegerType::get(mod->getContext(), 32),
-                                  /*Params=*/FuncTy_13_args,
-                                  /*isVarArg=*/false);
-
-    StructType *StructTy_class_types__Double = mod->getTypeByName("class.types::Double");
-    if (!StructTy_class_types__Double)
-    {
-        StructTy_class_types__Double = StructType::create(mod->getContext(), "class.types::Double");
-    }
-    std::vector<Type*>StructTy_class_types__Double_fields;
-    StructType *StructTy_class_types__ArrayOf = mod->getTypeByName("class.types::ArrayOf");
-    if (!StructTy_class_types__ArrayOf)
-    {
-        StructTy_class_types__ArrayOf = StructType::create(mod->getContext(), "class.types::ArrayOf");
-    }
-    std::vector<Type*>StructTy_class_types__ArrayOf_fields;
-    StructType *StructTy_class_types__GenericType = mod->getTypeByName("class.types::GenericType");
-    if (!StructTy_class_types__GenericType)
-    {
-        StructTy_class_types__GenericType = StructType::create(mod->getContext(), "class.types::GenericType");
-    }
-    std::vector<Type*>StructTy_class_types__GenericType_fields;
-    ArrayType* ArrayTy_16 = ArrayType::get(IntegerType::get(mod->getContext(), 8), 36);
-
-    StructTy_class_types__GenericType_fields.push_back(ArrayTy_16);
-    StructTy_class_types__GenericType_fields.push_back(IntegerType::get(mod->getContext(), 32));
-    StructTy_class_types__GenericType_fields.push_back(IntegerType::get(mod->getContext(), 32));
-    StructTy_class_types__GenericType_fields.push_back(IntegerType::get(mod->getContext(), 32));
-    StructTy_class_types__GenericType_fields.push_back(IntegerType::get(mod->getContext(), 32));
-    ArrayType* ArrayTy_17 = ArrayType::get(IntegerType::get(mod->getContext(), 32), 50);
-
-    StructTy_class_types__GenericType_fields.push_back(ArrayTy_17);
-    StructTy_class_types__GenericType_fields.push_back(IntegerType::get(mod->getContext(), 32));
-    if (StructTy_class_types__GenericType->isOpaque())
-    {
-        StructTy_class_types__GenericType->setBody(StructTy_class_types__GenericType_fields, /*isPacked=*/false);
-    }
-
-    StructTy_class_types__ArrayOf_fields.push_back(StructTy_class_types__GenericType);
-    StructTy_class_types__ArrayOf_fields.push_back(IntegerType::get(mod->getContext(), 8));
-    PointerType* PointerTy_18 = PointerType::get(Type::getDoubleTy(mod->getContext()), 0);
-
-    StructTy_class_types__ArrayOf_fields.push_back(PointerTy_18);
-    StructTy_class_types__ArrayOf_fields.push_back(PointerTy_18);
-    if (StructTy_class_types__ArrayOf->isOpaque())
-    {
-        StructTy_class_types__ArrayOf->setBody(StructTy_class_types__ArrayOf_fields, /*isPacked=*/false);
-    }
-
-    StructTy_class_types__Double_fields.push_back(StructTy_class_types__ArrayOf);
-    StructTy_class_types__Double_fields.push_back(IntegerType::get(mod->getContext(), 8));
-    StructTy_class_types__Double_fields.push_back(IntegerType::get(mod->getContext(), 8));
-    if (StructTy_class_types__Double->isOpaque())
-    {
-        StructTy_class_types__Double->setBody(StructTy_class_types__Double_fields, /*isPacked=*/false);
-    }
-
-    PointerType* PointerTy_15 = PointerType::get(StructTy_class_types__Double, 0);
-
-    PointerType* PointerTy_14 = PointerType::get(PointerTy_15, 0);
-
-    PointerType* PointerTy_19 = PointerType::get(IntegerType::get(mod->getContext(), 32), 0);
-
-    std::vector<Type*>FuncTy_21_args;
-    FunctionType* FuncTy_21 = FunctionType::get(
-                                  /*Result=*/PointerTy_15,
-                                  /*Params=*/FuncTy_21_args,
-                                  /*isVarArg=*/false);
-
-    PointerType* PointerTy_20 = PointerType::get(FuncTy_21, 0);
-
-    std::vector<Type*>FuncTy_23_args;
-    FuncTy_23_args.push_back(PointerTy_15);
-    FuncTy_23_args.push_back(PointerTy_15);
-    FuncTy_23_args.push_back(PointerTy_14);
-    FunctionType* FuncTy_23 = FunctionType::get(
-                                  /*Result=*/IntegerType::get(mod->getContext(), 32),
-                                  /*Params=*/FuncTy_23_args,
-                                  /*isVarArg=*/false);
-
-    PointerType* PointerTy_22 = PointerType::get(FuncTy_23, 0);
-
 
     // Function Declarations
 
-    Function* func___cxx_global_var_init = mod->getFunction("__cxx_global_var_init");
-    if (!func___cxx_global_var_init)
-    {
-        func___cxx_global_var_init = Function::Create(
-                                         /*Type=*/FuncTy_5,
-                                         /*Linkage=*/GlobalValue::InternalLinkage,
-                                         /*Name=*/"__cxx_global_var_init", mod);
-        func___cxx_global_var_init->setCallingConv(CallingConv::C);
-        func___cxx_global_var_init->setSection(".text.startup");
-    }
-    AttrListPtr func___cxx_global_var_init_PAL;
-    func___cxx_global_var_init->setAttributes(func___cxx_global_var_init_PAL);
-
-    Function* func__ZNSt8ios_base4InitC1Ev = mod->getFunction("_ZNSt8ios_base4InitC1Ev");
-    if (!func__ZNSt8ios_base4InitC1Ev)
-    {
-        func__ZNSt8ios_base4InitC1Ev = Function::Create(
-                                           /*Type=*/FuncTy_8,
-                                           /*Linkage=*/GlobalValue::ExternalLinkage,
-                                           /*Name=*/"_ZNSt8ios_base4InitC1Ev", mod); // (external, no body)
-        func__ZNSt8ios_base4InitC1Ev->setCallingConv(CallingConv::C);
-    }
-    AttrListPtr func__ZNSt8ios_base4InitC1Ev_PAL;
-    func__ZNSt8ios_base4InitC1Ev->setAttributes(func__ZNSt8ios_base4InitC1Ev_PAL);
-
-    Function* func__ZNSt8ios_base4InitD1Ev = mod->getFunction("_ZNSt8ios_base4InitD1Ev");
-    if (!func__ZNSt8ios_base4InitD1Ev)
-    {
-        func__ZNSt8ios_base4InitD1Ev = Function::Create(
-                                           /*Type=*/FuncTy_8,
-                                           /*Linkage=*/GlobalValue::ExternalLinkage,
-                                           /*Name=*/"_ZNSt8ios_base4InitD1Ev", mod); // (external, no body)
-        func__ZNSt8ios_base4InitD1Ev->setCallingConv(CallingConv::C);
-    }
-    AttrListPtr func__ZNSt8ios_base4InitD1Ev_PAL;
-    func__ZNSt8ios_base4InitD1Ev->setAttributes(func__ZNSt8ios_base4InitD1Ev_PAL);
-
-    Function* func___cxa_atexit = mod->getFunction("__cxa_atexit");
-    if (!func___cxa_atexit)
-    {
-        func___cxa_atexit = Function::Create(
-                                /*Type=*/FuncTy_12,
-                                /*Linkage=*/GlobalValue::ExternalLinkage,
-                                /*Name=*/"__cxa_atexit", mod); // (external, no body)
-        func___cxa_atexit->setCallingConv(CallingConv::C);
-    }
-    AttrListPtr func___cxa_atexit_PAL;
-    func___cxa_atexit->setAttributes(func___cxa_atexit_PAL);
-
-    Function* func__Z3foov = mod->getFunction("_Z3foov");
-    if (!func__Z3foov)
-    {
-        func__Z3foov = Function::Create(
-                           /*Type=*/FuncTy_13,
-                           /*Linkage=*/GlobalValue::ExternalLinkage,
-                           /*Name=*/"_Z3foov", mod);
-        func__Z3foov->setCallingConv(CallingConv::C);
-    }
-    AttrListPtr func__Z3foov_PAL;
-    func__Z3foov->setAttributes(func__Z3foov_PAL);
-
-    Function* func__ZN5types6Double5EmptyEv = mod->getFunction("_ZN5types6Double5EmptyEv");
-    if (!func__ZN5types6Double5EmptyEv)
-    {
-        func__ZN5types6Double5EmptyEv = Function::Create(
-                                            /*Type=*/FuncTy_21,
-                                            /*Linkage=*/GlobalValue::ExternalLinkage,
-                                            /*Name=*/"_ZN5types6Double5EmptyEv", mod); // (external, no body)
-        func__ZN5types6Double5EmptyEv->setCallingConv(CallingConv::C);
-    }
-    AttrListPtr func__ZN5types6Double5EmptyEv_PAL;
-    func__ZN5types6Double5EmptyEv->setAttributes(func__ZN5types6Double5EmptyEv_PAL);
-
-    Function* func__Z17AddDoubleToDoublePN5types6DoubleES1_PS1_ = mod->getFunction("_Z17AddDoubleToDoublePN5types6DoubleES1_PS1_");
-    if (!func__Z17AddDoubleToDoublePN5types6DoubleES1_PS1_)
-    {
-        func__Z17AddDoubleToDoublePN5types6DoubleES1_PS1_ = Function::Create(
-                    /*Type=*/FuncTy_23,
-                    /*Linkage=*/GlobalValue::ExternalLinkage,
-                    /*Name=*/"_Z17AddDoubleToDoublePN5types6DoubleES1_PS1_", mod); // (external, no body)
-        func__Z17AddDoubleToDoublePN5types6DoubleES1_PS1_->setCallingConv(CallingConv::C);
-    }
-    AttrListPtr func__Z17AddDoubleToDoublePN5types6DoubleES1_PS1__PAL;
-    func__Z17AddDoubleToDoublePN5types6DoubleES1_PS1_->setAttributes(func__Z17AddDoubleToDoublePN5types6DoubleES1_PS1__PAL);
-
-    Function* func__GLOBAL__I_a = mod->getFunction("_GLOBAL__I_a");
-    if (!func__GLOBAL__I_a)
-    {
-        func__GLOBAL__I_a = Function::Create(
-                                /*Type=*/FuncTy_5,
-                                /*Linkage=*/GlobalValue::InternalLinkage,
-                                /*Name=*/"_GLOBAL__I_a", mod);
-        func__GLOBAL__I_a->setCallingConv(CallingConv::C);
-        func__GLOBAL__I_a->setSection(".text.startup");
-    }
-    AttrListPtr func__GLOBAL__I_a_PAL;
-    func__GLOBAL__I_a->setAttributes(func__GLOBAL__I_a_PAL);
-
     // Global Variable Declarations
 
 
-    GlobalVariable* gvar_struct__ZStL8__ioinit = new GlobalVariable(/*Module=*/*mod,
-            /*Type=*/StructTy_class_std__ios_base__Init,
-            /*isConstant=*/false,
-            /*Linkage=*/GlobalValue::InternalLinkage,
-            /*Initializer=*/0, // has initializer, specified below
-            /*Name=*/"_ZStL8__ioinit");
-    gvar_struct__ZStL8__ioinit->setAlignment(1);
-
-    GlobalVariable* gvar_int8___dso_handle = new GlobalVariable(/*Module=*/*mod,
-            /*Type=*/IntegerType::get(mod->getContext(), 8),
-            /*isConstant=*/false,
-            /*Linkage=*/GlobalValue::ExternalLinkage,
-            /*Initializer=*/0,
-            /*Name=*/"__dso_handle");
-
-    GlobalVariable* gvar_array_llvm_global_ctors = new GlobalVariable(/*Module=*/*mod,
-            /*Type=*/ArrayTy_2,
-            /*isConstant=*/false,
-            /*Linkage=*/GlobalValue::AppendingLinkage,
-            /*Initializer=*/0, // has initializer, specified below
-            /*Name=*/"llvm.global_ctors");
-
     // Constant Definitions
-    ConstantAggregateZero* const_struct_24 = ConstantAggregateZero::get(StructTy_class_std__ios_base__Init);
-    std::vector<Constant*> const_array_25_elems;
-    std::vector<Constant*> const_struct_26_fields;
-    ConstantInt* const_int32_27 = ConstantInt::get(mod->getContext(), APInt(32, StringRef("65535"), 10));
-    const_struct_26_fields.push_back(const_int32_27);
-    const_struct_26_fields.push_back(func__GLOBAL__I_a);
-    Constant* const_struct_26 = ConstantStruct::get(StructTy_3, const_struct_26_fields);
-    const_array_25_elems.push_back(const_struct_26);
-    Constant* const_array_25 = ConstantArray::get(ArrayTy_2, const_array_25_elems);
-    Constant* const_ptr_28 = ConstantExpr::getCast(Instruction::BitCast, func__ZNSt8ios_base4InitD1Ev, PointerTy_9);
-    std::vector<Constant*> const_ptr_29_indices;
-    ConstantInt* const_int32_30 = ConstantInt::get(mod->getContext(), APInt(32, StringRef("0"), 10));
-    const_ptr_29_indices.push_back(const_int32_30);
-    const_ptr_29_indices.push_back(const_int32_30);
-    Constant* const_ptr_29 = ConstantExpr::getGetElementPtr(gvar_struct__ZStL8__ioinit, const_ptr_29_indices);
-    ConstantInt* const_int32_31 = ConstantInt::get(mod->getContext(), APInt(32, StringRef("1"), 10));
 
     // Global Variable Definitions
-    gvar_struct__ZStL8__ioinit->setInitializer(const_struct_24);
-    gvar_array_llvm_global_ctors->setInitializer(const_array_25);
 
     // Function Definitions
 
-    // Function: __cxx_global_var_init (func___cxx_global_var_init)
-    {
-
-        BasicBlock* label_32 = BasicBlock::Create(mod->getContext(), "", func___cxx_global_var_init, 0);
-
-        // Block  (label_32)
-        CallInst* void_33 = CallInst::Create(func__ZNSt8ios_base4InitC1Ev, gvar_struct__ZStL8__ioinit, "", label_32);
-        void_33->setCallingConv(CallingConv::C);
-        void_33->setTailCall(false);
-        AttrListPtr void_33_PAL;
-        void_33->setAttributes(void_33_PAL);
-
-        std::vector<Value*> int32_34_params;
-        int32_34_params.push_back(const_ptr_28);
-        int32_34_params.push_back(const_ptr_29);
-        int32_34_params.push_back(gvar_int8___dso_handle);
-        CallInst* int32_34 = CallInst::Create(func___cxa_atexit, int32_34_params, "", label_32);
-        int32_34->setCallingConv(CallingConv::C);
-        int32_34->setTailCall(false);
-        AttrListPtr int32_34_PAL;
-        int32_34->setAttributes(int32_34_PAL);
-
-        ReturnInst::Create(mod->getContext(), label_32);
-
-    }
-
-    // Function: _Z3foov (func__Z3foov)
-    {
-
-        BasicBlock* label_36 = BasicBlock::Create(mod->getContext(), "", func__Z3foov, 0);
-
-        // Block  (label_36)
-        AllocaInst* ptr_pdbl1 = new AllocaInst(PointerTy_15, "pdbl1", label_36);
-        ptr_pdbl1->setAlignment(8);
-        AllocaInst* ptr_res = new AllocaInst(IntegerType::get(mod->getContext(), 32), "res", label_36);
-        ptr_res->setAlignment(4);
-        CallInst* ptr_37 = CallInst::Create(func__ZN5types6Double5EmptyEv, "", label_36);
-        ptr_37->setCallingConv(CallingConv::C);
-        ptr_37->setTailCall(false);
-        AttrListPtr ptr_37_PAL;
-        ptr_37->setAttributes(ptr_37_PAL);
-
-        StoreInst* void_38 = new StoreInst(ptr_37, ptr_pdbl1, false, label_36);
-        void_38->setAlignment(8);
-        LoadInst* ptr_39 = new LoadInst(ptr_pdbl1, "", false, label_36);
-        ptr_39->setAlignment(8);
-        LoadInst* ptr_40 = new LoadInst(ptr_pdbl1, "", false, label_36);
-        ptr_40->setAlignment(8);
-        std::vector<Value*> int32_41_params;
-        int32_41_params.push_back(ptr_39);
-        int32_41_params.push_back(ptr_40);
-        int32_41_params.push_back(ptr_pdbl1);
-        CallInst* int32_41 = CallInst::Create(func__Z17AddDoubleToDoublePN5types6DoubleES1_PS1_, int32_41_params, "", label_36);
-        int32_41->setCallingConv(CallingConv::C);
-        int32_41->setTailCall(false);
-        AttrListPtr int32_41_PAL;
-        int32_41->setAttributes(int32_41_PAL);
-
-        StoreInst* void_42 = new StoreInst(int32_41, ptr_res, false, label_36);
-        void_42->setAlignment(4);
-        LoadInst* int32_43 = new LoadInst(ptr_res, "", false, label_36);
-        int32_43->setAlignment(4);
-        ReturnInst::Create(mod->getContext(), int32_43, label_36);
-
-    }
-
-    // Function: _GLOBAL__I_a (func__GLOBAL__I_a)
-    {
-
-        BasicBlock* label_45 = BasicBlock::Create(mod->getContext(), "", func__GLOBAL__I_a, 0);
-
-        // Block  (label_45)
-        CallInst* void_46 = CallInst::Create(func___cxx_global_var_init, "", label_45);
-        void_46->setCallingConv(CallingConv::C);
-        void_46->setTailCall(false);
-        AttrListPtr void_46_PAL;
-        void_46->setAttributes(void_46_PAL);
-
-        ReturnInst::Create(mod->getContext(), label_45);
-
-    }
-
     return mod;
 
 }
index a8cefaf..95b109b 100644 (file)
@@ -21,6 +21,9 @@ int foo()
 {
     types::Double* pdbl1 = types::Double::Empty();
     int res = AddDoubleToDouble(pdbl1, pdbl1, &pdbl1);
+    symbol::Symbol * sym = 0;// = symbol::Symbol(L"a"); => This declaration makes llc fails
+
+    symbol::Context::getInstance()->put(*sym, *pdbl1);
 
     return res;
 }