Browse code

initial support for llvm codegen.

Török Edvin authored on 2009/08/27 17:58:45
Showing 1 changed files
... ...
@@ -20,6 +20,7 @@
20 20
  *  MA 02110-1301, USA.
21 21
  */
22 22
 
23
+#include "llvm/ADT/DenseMap.h"
23 24
 #include "llvm/Support/DataTypes.h"
24 25
 #include "llvm/System/Threading.h"
25 26
 #include "llvm/Support/ErrorHandling.h"
... ...
@@ -43,10 +44,11 @@
43 43
 #define MODULE "libclamav JIT: "
44 44
 
45 45
 using namespace llvm;
46
+typedef DenseMap<const struct cli_bc_func*, void*> FunctionMapTy;
46 47
 struct cli_bcengine {
47 48
     ExecutionEngine *EE;
48 49
     LLVMContext Context;
49
-     
50
+    FunctionMapTy compiledFunctions; 
50 51
 };
51 52
 
52 53
 namespace {
... ...
@@ -56,7 +58,28 @@ namespace {
56 56
     }
57 57
     void llvm_error_handler(void *user_data, const std::string &reason)
58 58
     {
59
+    
59 60
     }
61
+
62
+    void generateLLVM(const struct cli_bc *bc, Module *M, 
63
+		      FunctionMapTy &compiledFunctions) {
64
+
65
+	Type *TypeMap = new Type*[bc->num_types];
66
+
67
+	for (unsigned j=0;j<bc->num_types;j++) {
68
+
69
+	}
70
+
71
+	for (unsigned j=0;j<bc->num_func;j++) {
72
+	    const struct cli_bc_func *func = &bc->funcs[j];
73
+	    std::vector<const Type*> argTypes;
74
+	    for (unsigned a=0;a<func->numArgs;a++) {
75
+		argTypes.push_back(mapType(func->types[a], TypeMap));
76
+	    }
77
+	}
78
+	delete TypeMap;
79
+    }
80
+
60 81
 }
61 82
 
62 83
 int cli_vm_execute_jit(const struct cli_bc *bc, struct cli_bc_ctx *ctx, const struct cli_bc_func *func, const struct cli_bc_inst *inst)
... ...
@@ -64,6 +87,7 @@ int cli_vm_execute_jit(const struct cli_bc *bc, struct cli_bc_ctx *ctx, const st
64 64
     return 0;
65 65
 }
66 66
 
67
+
67 68
 int cli_bytecode_prepare_jit(struct cli_all_bc *bcs)
68 69
 {
69 70
   // LLVM itself never throws exceptions, but operator new may throw bad_alloc
... ...
@@ -84,8 +108,15 @@ int cli_bytecode_prepare_jit(struct cli_all_bc *bcs)
84 84
 		errs() << MODULE << "JIT not registered?\n";
85 85
 	    return CL_EBYTECODE;
86 86
 	}
87
+
88
+	EE->RegisterJITEventListener(createOProfileJITEventListener());
87 89
 	EE->DisableLazyCompilation();
88 90
 
91
+	for (unsigned i=0;i<bcs->count;i++) {
92
+	    const struct cli_bc *bc = bcs->all_bcs[i];
93
+	    generateLLVM(bc, M);
94
+	}
95
+
89 96
 	// compile all functions now, not lazily!
90 97
 	for (Module::iterator I = M->begin(), E = M->end(); I != E; ++I) {
91 98
 	    Function *Fn = &*I;