Skip to content

Commit

Permalink
Update to support LLVM 3.2 and Native targets.
Browse files Browse the repository at this point in the history
  • Loading branch information
NTmatter committed Jan 4, 2013
1 parent b2cb088 commit 8326657
Show file tree
Hide file tree
Showing 4 changed files with 56 additions and 31 deletions.
30 changes: 26 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,23 +1,45 @@
# LLBoy

- GameBoy emulator utilizing LLVM for emitting translated bytecode
- GameBoy emulator utilizing LLVM for translating GameBoy bytecode to native
- Sources at https://github.com/NTmatter/LLBoy
- More detailed documentation at http://www.axante.net/projects/llboy
- Based directly upon http://imrannazar.com/GameBoy-Emulation-in-JavaScript

## Dependencies:

- LLVM Core 2.8 (compiled-in to generate native translation)
- Clang 2.8 (binary only, builds LTO opcode bitcode file)
- LLVM Core 3.2 (compiled-in to generate native translation)
- Clang 3.2 (binary only, builds LTO opcode bitcode file)
- CMake 2.8 (binary only, for building)
- QT 4.7.0 (will be required later)

## Compilation Instructions
LLVM and Clang 3.2 headers and binaries should be installed on the system. In
some cases, the development headers will be missing, or the cmake configuration
files may not be present. It is generally easiest to download the latest from llvm.org.

To install LLVM and Clang to the location of your choosing:
<pre>
# Extract llvm and clang sources
tar xzf llvm-3.2.src.tar.gz
tar xzf clang-3.2.src.tar.gz

# Move clang sources into llvm for automatic build
mv clang-3.2.src llvm-3.2.src/tools/clang

# Do an out-of-tree build
mkdir llvm-3.2.build
cd llvm-3.2.build
cmake -DCMAKE_INSTALL_PREFIX:PATH=/example/clang+llvm-3.2 ../llvm-3.2.src
make
sudo make install
</pre>

Build LLboy:
<pre>
cd LLboy
mkdir bin
cd bin
CC=clang CXX=clang++ cmake -DCMAKE_BUILD_TYPE=Debug -DLLVM_ROOT:string=/path/to/llvm/install ../src
CC=clang CXX=clang++ cmake -DCMAKE_BUILD_TYPE=Debug -DLLVM_ROOT:path=/example/clang+llvm-3.2 ../src
make all test
</pre>

Expand Down
4 changes: 2 additions & 2 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ llvm_map_components_to_libraries(REQ_LLVM_LIBRARIES
core jit linker runtimedyld analysis native
transformutils vectorize instcombine ipa ipo instrumentation
engine executionengine
)
bitwriter bitreader)

find_program( LLVM_CLANG clang
DOC "Clang binary from LLVM install"
Expand All @@ -55,4 +55,4 @@ find_program( LLVM_LINKER llvm-ld
add_subdirectory (sys)

add_executable (LLBoy main.cpp)
target_link_libraries (LLBoy ${LLVM_LIBRARIES})
target_link_libraries (LLBoy ${REQ_LLVM_LIBRARIES})
52 changes: 28 additions & 24 deletions src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,43 +21,47 @@
*/


#include <iostream>
#import <iostream>

#include <llvm/LLVMContext.h>
#include <llvm/Function.h>
#include <llvm/Module.h>
#include <llvm/Support/MemoryBuffer.h>
#include <llvm/Bitcode/ReaderWriter.h>
#include <llvm/Analysis/Verifier.h>
#include <llvm/ExecutionEngine/ExecutionEngine.h>
#include <llvm/ExecutionEngine/JIT.h>
#include <llvm/CallingConv.h>

#include <llvm/Target/TargetData.h>
#include <llvm/Target/TargetSelect.h>
#import <llvm/Support/system_error.h>
#import <llvm/LLVMContext.h>
#import <llvm/Function.h>
#import <llvm/Module.h>
#import <llvm/Support/MemoryBuffer.h>
#import <llvm/Bitcode/ReaderWriter.h>
#import <llvm/Analysis/Verifier.h>
#import <llvm/ExecutionEngine/ExecutionEngine.h>
#import <llvm/ExecutionEngine/JIT.h>
#import <llvm/CallingConv.h>
#import <llvm/Target/TargetData.h>
#import <llvm/Support/TargetSelect.h>
#import <llvm/ExecutionEngine/ExecutionEngine.h>
#import <llvm/ExecutionEngine/JIT.h>

extern "C"
{
#include "sys/system.h"
#include "sys/cpu.h"
#include "sys/cpu_functions_names.h"
#import "sys/system.h"
#import "sys/cpu.h"
#import "sys/cpu_functions_names.h"
}

using namespace std;
using namespace llvm;

Module* read_module(LLVMContext* ctx, string path, string* error)
{
error_code err;
MemoryBuffer* buffer;
Module* out = NULL;
if((buffer = MemoryBuffer::getFile(path, error)))
OwningPtr<MemoryBuffer> mb;

err = MemoryBuffer::getFile(path, mb);
if(err)
{
out = ParseBitcodeFile(buffer, *ctx, error);
delete buffer;
} else {
cerr << "Could not find file " << path << endl;
cerr << "Error reading bitcode file: " << err << endl;
return NULL;
}
return out;

return ParseBitcodeFile(mb.get(), *ctx);
}

int main(int argc, char** argv)
Expand All @@ -77,7 +81,7 @@ int main(int argc, char** argv)

// InitializeNativeTarget();
// ExecutionEngine* engine = ExecutionEngine::create(module_system, false, &error);
InitializeAllTargets();
InitializeNativeTarget();
ExecutionEngine* engine = ExecutionEngine::createJIT(module_system, &error);
if(engine)
{
Expand Down
1 change: 0 additions & 1 deletion src/sys/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ add_custom_target(system-bitcode ALL
SOURCES ${SYSTEM_SOURCES}
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR})

add_library (llboy ${SYSTEM_SOURCES})
add_library (llboy_system ${SYSTEM_SOURCES})

# Tests
Expand Down

0 comments on commit 8326657

Please sign in to comment.