Skip to content

Commit 68904e6

Browse files
Update to LLVM 2.7 API.
git-svn-id: http://llvm-lua.googlecode.com/svn/trunk@117 f87b780f-1855-0410-a4d3-fd11cda3f415
1 parent 1788be5 commit 68904e6

14 files changed

+72
-49
lines changed

CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -188,6 +188,7 @@ set(FORCE_ALIGNMENT "4" CACHE STRING "Force byte alignment, for clang-cc hack.")
188188
#
189189
option(COCO_USE_SETJMP "Coco: Force use of setjmp (instead of gccasm)" OFF)
190190
option(COCO_USE_UCONTEXT "Coco: Force use of ucontext (instead of gccasm or setjmp)" OFF)
191+
option(COCO_USE_VALGRIND "Enable valgrind debugging support" OFF)
191192
option(COCO_DISABLE "Disable coco" OFF)
192193
set(COCO_DEFAULT_CSTACKSIZE "" CACHE STRING "Coco default cstacksize")
193194

ChangeLog

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,26 @@
1+
2009-11-05 Robert G. Jakabosky <[email protected]>
2+
3+
* llvm-lua/CMakeLists.txt, llvm-lua/run_tests.sh, src/ldo.c,
4+
src/lgc.c, src/lgc.h, src/lobject.h, src/lvm.c, src/lzio.h:
5+
Emergency GC fixes.
6+
7+
2009-10-18 Robert G. Jakabosky <[email protected]>
8+
9+
* CMakeLists.txt:
10+
Fixed bug
11+
* AUTHORS, ChangeLog, gen_changelog.sh, llvm-lua/CMakeLists.txt,
12+
llvm-lua/lua-compiler, llvm-lua/lua-compiler.in,
13+
llvm-lua/lua-cross-compiler.in, llvm-lua/lua_compiler.c,
14+
llvm-lua/run_tests.sh:
15+
Added ChangeLog, Improved lua-compiler & lua-cross-compiler.
16+
17+
Added -mcpu option to *-compiler scripts.
18+
Changed -arch to -target option.
19+
Embed the install prefix into lua-compiler so it can find
20+
liblua_main.a
21+
Added gen_changelog.sh script to generate ChangeLog from svn
22+
history.
23+
124
2009-10-17 Robert G. Jakabosky <[email protected]>
225

326
* CMakeLists.txt, README.llvm-lua, src/loadlib.c:

TODO

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,10 @@
11
TODO:
22
* handle coroutine c-stack alignment issues on x86_64 when compiling in DEBUG mode.
3+
* Add option to compile liblua_main.a without lua parser, lundump/ldump code.
4+
5+
lua-compiler script:
6+
* fix linking bug reported by DigitalKiwi:
7+
<DigitalKiwi> #CFLAGS=" -ggdb -O3 -fomit-frame-pointer -pipe -Wall "
8+
<DigitalKiwi> CFLAGS=" -O3 -fomit-frame-pointer -pipe -Wl,-E "
9+
<DigitalKiwi> http://www.tecgraf.puc-rio.br/~lhf/ftp/lua/install.html
310

llvm-lua/LLVMCompiler.cpp

Lines changed: 8 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@
2626
#include "llvm/DerivedTypes.h"
2727
#include "llvm/ExecutionEngine/ExecutionEngine.h"
2828
#include "llvm/Module.h"
29-
#include "llvm/ModuleProvider.h"
3029
#include "llvm/PassManager.h"
3130
#include "llvm/Analysis/Verifier.h"
3231
#include "llvm/Target/TargetData.h"
@@ -247,8 +246,7 @@ LLVMCompiler::LLVMCompiler(int useJIT) {
247246
NoLazyCompilation = true;
248247
}
249248
// load vm op functions
250-
MP = load_vm_ops(getCtx(), NoLazyCompilation);
251-
M = MP->getModule();
249+
M = load_vm_ops(getCtx(), NoLazyCompilation);
252250

253251
// get important struct types.
254252
Ty_TValue = M->getTypeByName("struct.lua_TValue");
@@ -358,7 +356,7 @@ LLVMCompiler::LLVMCompiler(int useJIT) {
358356
if(llvm::TimePassesIsEnabled) load_jit.startTimer();
359357
// Create the JIT.
360358
if(useJIT) {
361-
llvm::EngineBuilder engine(MP);
359+
llvm::EngineBuilder engine(M);
362360
llvm::CodeGenOpt::Level optLevel = llvm::CodeGenOpt::Aggressive;
363361
if(Fast) {
364362
optLevel = llvm::CodeGenOpt::Default;
@@ -390,7 +388,7 @@ LLVMCompiler::LLVMCompiler(int useJIT) {
390388
}
391389

392390
if(OptLevel > 1) {
393-
TheFPM = new llvm::FunctionPassManager(MP);
391+
TheFPM = new llvm::FunctionPassManager(M);
394392

395393
/*
396394
* Function Pass Manager.
@@ -454,7 +452,6 @@ void print_opcode_stats(int *stats, const char *stats_name) {
454452
}
455453

456454
LLVMCompiler::~LLVMCompiler() {
457-
llvm::Module *mod = NULL;
458455
std::string error;
459456
// print opcode stats.
460457
if(OpCodeStats) {
@@ -486,23 +483,15 @@ LLVMCompiler::~LLVMCompiler() {
486483
TheExecutionEngine->freeMachineCodeForFunction(vm_set_number);
487484
TheExecutionEngine->freeMachineCodeForFunction(vm_set_long);
488485
TheExecutionEngine->runStaticConstructorsDestructors(true);
489-
mod = TheExecutionEngine->removeModuleProvider(MP, &error);
490-
if(!mod) {
491-
printf("Failed cleanup ModuleProvider: %s\n", error.c_str());
486+
if(!TheExecutionEngine->removeModule(M)) {
487+
printf("Failed find Module in execution engine.\n");
492488
exit(1);
493489
}
494490
delete TheExecutionEngine;
495-
} else if(MP) {
496-
mod = MP->releaseModule(&error);
497-
if(!mod) {
498-
printf("Failed cleanup ModuleProvider: %s\n", error.c_str());
499-
exit(1);
500-
}
501-
delete MP;
502-
MP = NULL;
503491
}
504-
if(mod) {
505-
delete mod;
492+
if(M) {
493+
delete M;
494+
M = NULL;
506495
}
507496
}
508497

llvm-lua/LLVMCompiler.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,8 @@
2626
#define LLVMCOMPILER_h
2727

2828
#include "llvm/Support/IRBuilder.h"
29-
#include "llvm/ModuleProvider.h"
3029
#include "llvm/Module.h"
30+
#include "llvm/LLVMContext.h"
3131

3232
#include "lua_core.h"
3333

@@ -66,7 +66,6 @@ class LLVMCompiler {
6666
};
6767
private:
6868
llvm::LLVMContext Context;
69-
llvm::ModuleProvider *MP;
7069
llvm::Module *M;
7170
llvm::FunctionPassManager *TheFPM;
7271
llvm::ExecutionEngine *TheExecutionEngine;

llvm-lua/LLVMDumper.cpp

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -24,13 +24,13 @@
2424

2525
#include "llvm/DerivedTypes.h"
2626
#include "llvm/Module.h"
27-
#include "llvm/ModuleProvider.h"
2827
#include "llvm/Target/TargetData.h"
2928
#include "llvm/Linker.h"
3029
#include "llvm/TypeSymbolTable.h"
3130
#include "llvm/Analysis/Verifier.h"
3231
#include "llvm/Bitcode/ReaderWriter.h"
3332
#include "llvm/Support/CommandLine.h"
33+
#include "llvm/Support/raw_ostream.h"
3434
#include <string>
3535
#include <vector>
3636
#include <fstream>
@@ -182,12 +182,12 @@ LLVMDumper::LLVMDumper(LLVMCompiler *compiler) : compiler(compiler) {
182182
}
183183

184184
void LLVMDumper::dump(const char *output, lua_State *L, Proto *p, int stripping) {
185-
std::ofstream OS(output, std::ios_base::out|std::ios::trunc|std::ios::binary);
186-
llvm::ModuleProvider *MP = NULL;
187-
llvm::Module *liblua_main = NULL;
185+
llvm::raw_fd_ostream *out;
188186
std::string error;
187+
llvm::Module *liblua_main = NULL;
189188

190-
if(!OS.fail()) {
189+
out = new llvm::raw_fd_ostream(output, error, llvm::raw_fd_ostream::F_Binary);
190+
if(error.empty()) {
191191
compiler->setStripCode(stripping);
192192
// Internalize all opcode functions.
193193
for (llvm::Module::iterator I = M->begin(), E = M->end(); I != E; ++I) {
@@ -207,8 +207,7 @@ void LLVMDumper::dump(const char *output, lua_State *L, Proto *p, int stripping)
207207
//M->dump();
208208
// link with liblua_main.bc
209209
if(!NoMain) {
210-
MP = load_liblua_main(getCtx(), true);
211-
liblua_main = MP->getModule();
210+
liblua_main = load_liblua_main(getCtx(), true);
212211
if(llvm::Linker::LinkModules(M, liblua_main, &error)) {
213212
fprintf(stderr, "Failed to link compiled Lua script with embedded 'liblua_main.bc': %s",
214213
error.c_str());
@@ -218,7 +217,13 @@ void LLVMDumper::dump(const char *output, lua_State *L, Proto *p, int stripping)
218217
}
219218
//M->dump();
220219
llvm::verifyModule(*M);
221-
llvm::WriteBitcodeToFile(M, OS);
220+
llvm::WriteBitcodeToFile(M, *out);
221+
delete out;
222+
} else {
223+
delete out;
224+
fprintf(stderr, "Failed to open output file: %s",
225+
error.c_str());
226+
exit(1);
222227
}
223228
}
224229

llvm-lua/llvm-luac.cpp

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,13 +24,11 @@
2424

2525
#include "llvm/LLVMContext.h"
2626
#include "llvm/Module.h"
27-
#include "llvm/ModuleProvider.h"
2827
#include "llvm/PassManager.h"
2928
#include "llvm/Pass.h"
3029
#include "llvm/ADT/Triple.h"
3130
#include "llvm/Analysis/Verifier.h"
3231
#include "llvm/Bitcode/ReaderWriter.h"
33-
#include "llvm/CodeGen/FileWriters.h"
3432
#include "llvm/CodeGen/LinkAllAsmWriterComponents.h"
3533
#include "llvm/CodeGen/LinkAllCodegenComponents.h"
3634
#include "llvm/CodeGen/ObjectCodeEmitter.h"

llvm-lua/load_embedded_bc.cpp

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@
2626
#include <stdio.h>
2727

2828
#include "llvm/Module.h"
29-
#include "llvm/ModuleProvider.h"
3029
#include "llvm/LLVMContext.h"
3130

3231
#include "llvm/Support/MemoryBuffer.h"
@@ -36,10 +35,9 @@
3635

3736
#include "load_embedded_bc.h"
3837

39-
llvm::ModuleProvider *load_embedded_bc(llvm::LLVMContext &context,
38+
llvm::Module *load_embedded_bc(llvm::LLVMContext &context,
4039
const char *name, const unsigned char *start, size_t len, bool NoLazyCompilation)
4140
{
42-
llvm::ModuleProvider *MP = NULL;
4341
llvm::Module *module = NULL;
4442
const char *end = (const char *)start + len - 1;
4543
std::string error;
@@ -50,22 +48,23 @@ llvm::ModuleProvider *load_embedded_bc(llvm::LLVMContext &context,
5048
llvm::MemoryBuffer* buffer;
5149
buffer= llvm::MemoryBuffer::getMemBuffer((const char *)start, end, name);
5250
if(buffer != NULL) {
53-
MP = llvm::getBitcodeModuleProvider(buffer, context, &error);
54-
if(!MP) delete buffer;
51+
module = llvm::getLazyBitcodeModule(buffer, context, &error);
52+
if(!module) {
53+
delete buffer;
54+
}
5555
}
56-
if(!MP) {
56+
if(!module) {
5757
printf("Failed to parse embedded '%s' file: %s\n", name, error.c_str());
5858
exit(1);
5959
}
60-
// Get Module from ModuleProvider.
60+
// Materialize module
6161
if(NoLazyCompilation) {
62-
module = MP->materializeModule(&error);
63-
if(!module) {
62+
if(module->MaterializeAll(&error)) {
6463
printf("Failed to materialize embedded '%s' file: %s\n", name, error.c_str());
6564
exit(1);
6665
}
6766
}
6867

69-
return MP;
68+
return module;
7069
}
7170

llvm-lua/load_embedded_bc.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
#ifndef load_embedded_bc_h
2626
#define load_embedded_bc_h
2727

28-
extern llvm::ModuleProvider *load_embedded_bc(llvm::LLVMContext &context,
28+
extern llvm::Module *load_embedded_bc(llvm::LLVMContext &context,
2929
const char *name, const unsigned char *start, size_t len, bool NoLazyCompilation);
3030

3131
#endif

llvm-lua/load_liblua_main.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,15 +24,15 @@
2424

2525
#include <stdlib.h>
2626

27-
#include "llvm/ModuleProvider.h"
27+
#include "llvm/Module.h"
2828
#include "llvm/LLVMContext.h"
2929

3030
#include "load_liblua_main.h"
3131
#include "load_embedded_bc.h"
3232

3333
#include "liblua_main_bc.h"
3434

35-
llvm::ModuleProvider *load_liblua_main(llvm::LLVMContext &context, bool NoLazyCompilation) {
35+
llvm::Module *load_liblua_main(llvm::LLVMContext &context, bool NoLazyCompilation) {
3636
return load_embedded_bc(context, "liblua_main_bc", liblua_main_bc,
3737
sizeof(liblua_main_bc), NoLazyCompilation);
3838
}

llvm-lua/load_liblua_main.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
#ifndef load_liblua_main_h
2626
#define load_liblua_main_h
2727

28-
extern llvm::ModuleProvider *load_liblua_main(llvm::LLVMContext &context, bool NoLazyCompilation);
28+
extern llvm::Module *load_liblua_main(llvm::LLVMContext &context, bool NoLazyCompilation);
2929

3030
#endif
3131

llvm-lua/load_vm_ops.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,15 +24,15 @@
2424

2525
#include <stdlib.h>
2626

27-
#include "llvm/ModuleProvider.h"
2827
#include "llvm/LLVMContext.h"
28+
#include "llvm/Module.h"
2929

3030
#include "load_vm_ops.h"
3131
#include "load_embedded_bc.h"
3232

3333
#include "lua_vm_ops_bc.h"
3434

35-
llvm::ModuleProvider *load_vm_ops(llvm::LLVMContext &context, bool NoLazyCompilation) {
35+
llvm::Module *load_vm_ops(llvm::LLVMContext &context, bool NoLazyCompilation) {
3636
return load_embedded_bc(context, "lua_vm_ops_bc", lua_vm_ops_bc,
3737
sizeof(lua_vm_ops_bc), NoLazyCompilation);
3838
}

llvm-lua/load_vm_ops.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
#ifndef load_vm_ops_h
2626
#define load_vm_ops_h
2727

28-
extern llvm::ModuleProvider *load_vm_ops(llvm::LLVMContext &context, bool NoLazyCompilation);
28+
extern llvm::Module *load_vm_ops(llvm::LLVMContext &context, bool NoLazyCompilation);
2929

3030
#endif
3131

llvm-lua/run_tests.sh

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,9 @@
33

44
for script in `ls tests/*.lua`; do
55
echo "run test: $script"
6-
llvm-lua -g -O0 $script >/dev/null
6+
llvm-lua -g -O0 $script >/dev/null || {
7+
echo "Failed to run: $script"
8+
}
79
#llvm-lua -g -O0 $script
810
#lua $script
911
#llvm-lua -O3 $script >/dev/null

0 commit comments

Comments
 (0)