[pypy-svn] r23781 - in pypy/dist/pypy/translator/llvm/pyllvm: . test

rxe at codespeak.net rxe at codespeak.net
Tue Feb 28 21:05:36 CET 2006


Author: rxe
Date: Tue Feb 28 21:05:33 2006
New Revision: 23781

Added:
   pypy/dist/pypy/translator/llvm/pyllvm/__init__.py   (contents, props changed)
   pypy/dist/pypy/translator/llvm/pyllvm/test/
   pypy/dist/pypy/translator/llvm/pyllvm/test/test_ee.py   (contents, props changed)
Removed:
   pypy/dist/pypy/translator/llvm/pyllvm/x.py
Modified:
   pypy/dist/pypy/translator/llvm/pyllvm/pyllvm.cpp
Log:
Some cleanups - use py.test


Added: pypy/dist/pypy/translator/llvm/pyllvm/__init__.py
==============================================================================

Modified: pypy/dist/pypy/translator/llvm/pyllvm/pyllvm.cpp
==============================================================================
--- pypy/dist/pypy/translator/llvm/pyllvm/pyllvm.cpp	(original)
+++ pypy/dist/pypy/translator/llvm/pyllvm/pyllvm.cpp	Tue Feb 28 21:05:33 2006
@@ -1,18 +1,19 @@
 
+// python includes
 #include <Python.h>
 #include <structmember.h>
 
+// llvm includes
+#include "llvm/Type.h"
 #include "llvm/Module.h"
 #include "llvm/ModuleProvider.h"
-#include "llvm/Type.h"
+#include "llvm/Assembly/Parser.h"
 #include "llvm/Bytecode/Reader.h"
-#include "llvm/ExecutionEngine/ExecutionEngine.h"
 #include "llvm/ExecutionEngine/GenericValue.h"
-#include "llvm/Support/CommandLine.h"
-#include "llvm/Support/PluginLoader.h"
-#include "llvm/System/Signals.h"
-#include "llvm/Assembly/Parser.h"
+#include "llvm/ExecutionEngine/ExecutionEngine.h"
 #include "llvm/Analysis/Verifier.h"
+
+// c++ includes
 #include <string>
 #include <iostream>
 
@@ -25,63 +26,19 @@
     return NULL;
   }
 
-  int Result = -1;
-
   try {
-    printf("here1\n");
     Module *mod = new Module((const char *) modulename);
-    printf("here2\n");
-
     ModuleProvider *mp = new ExistingModuleProvider(mod);
-    printf("here3\n");
     ParseAssemblyString((const char *) llcode, mod);// throw (ParseException)
-    printf("here4\n");
     verifyModule(*mod, ThrowExceptionAction);
-    printf("here5\n");
     ExecutionEngine *exec = ExecutionEngine::create(mp, false);
-    printf("here6\n");
     assert(exec && "Couldn't create an ExecutionEngine, not even an interpreter?");
-    printf("here7\n");
     delete exec;
-    printf("here8\n");
-
-//     delete mp;
-//     printf("here9\n");
-//     delete mod;
-//     printf("here10\n");
-
-//     // Call the main function from M as if its signature were:
-//     //   int main (int argc, char **argv, const char **envp)
-//     // using the contents of Args to determine argc & argv, and the contents of
-//     // EnvVars to determine envp.
-//     //
-//     Function *Fn = MP->getModule()->getMainFunction();
-//     if (!Fn) {
-//       std::cerr << "'main' function not found in module.\n";
-//       return -1;
-//     }
-
-//     // Run main...
-//     int Result = EE->runFunctionAsMain(Fn, InputArgv, envp);
-
-//     // If the program didn't explicitly call exit, call exit now, for the program.
-//     // This ensures that any atexit handlers get called correctly.
-//     Function *Exit = MP->getModule()->getOrInsertFunction("exit", Type::VoidTy,
-//                                                           Type::IntTy,
-//                                                           (Type *)0);
-
-//     std::vector<GenericValue> Args;
-//     GenericValue ResultGV;
-//     ResultGV.IntVal = Result;
-//     Args.push_back(ResultGV);
-//     EE->runFunction(Exit, Args);
-
-    std::cerr << "ERROR: exit(" << Result << ") returned!\n";
-  } catch (const std::string& msg) {
-    std::cerr << ": " << msg << "\n";
   } catch (...) {
-    std::cerr << ": Unexpected unknown exception occurred.\n";
+    PyErr_SetString(PyExc_Exception, "Unexpected unknown exception occurred");
+    return NULL;
   }
+
   Py_INCREF(Py_None);
   return Py_None;
 }
@@ -91,13 +48,14 @@
   {NULL, NULL}
 };
 
+
 #ifdef __cplusplus
 extern "C" {
 #endif
 
 void initpyllvm(void) {
-  PyObject *pyllvm = Py_InitModule("pyllvm", pyllvm_functions);
+  Py_InitModule("pyllvm", pyllvm_functions);
 
 }
 
-} // __cplusplus
+}

Added: pypy/dist/pypy/translator/llvm/pyllvm/test/test_ee.py
==============================================================================
--- (empty file)
+++ pypy/dist/pypy/translator/llvm/pyllvm/test/test_ee.py	Tue Feb 28 21:05:33 2006
@@ -0,0 +1,9 @@
+from pypy.translator.llvm.buildllvm import llvm_is_on_path
+if not llvm_is_on_path():
+    py.test.skip("llvm not found")
+
+from pypy.translator.llvm.pyllvm import pyllvm 
+
+def test_execution_context():
+    code = open("hello.s").read()
+    pyllvm.start_ee("modname", code)



More information about the Pypy-commit mailing list