Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

LLVM 3.2 compatibility and fixed compiler warnings

  • Loading branch information...
commit 056f3425bbc38ee95ddc37cd6e72b08c14f2376b 1 parent 39bc4a9
@NTmatter authored
View
3  README.md
@@ -39,7 +39,8 @@ Build LLboy:
cd LLboy
mkdir bin
cd bin
- CC=clang CXX=clang++ cmake -DCMAKE_BUILD_TYPE=Debug -DLLVM_ROOT:path=/example/clang+llvm-3.2 ../src
+ CC=/example/clang+llvm-3.2/bin/clang CXX=/example/clang+llvm-3.2/bin/clang++ \
+ cmake -DCMAKE_BUILD_TYPE=Debug -DLLVM_ROOT:path=/example/clang+llvm-3.2 ../src
make all test
</pre>
View
2  src/CMakeLists.txt
@@ -55,4 +55,4 @@ find_program( LLVM_LINK llvm-link
add_subdirectory (sys)
add_executable (LLBoy main.cpp)
-target_link_libraries (LLBoy ${REQ_LLVM_LIBRARIES})
+target_link_libraries (LLBoy ${REQ_LLVM_LIBRARIES} llboy_system)
View
30 src/main.cpp
@@ -33,7 +33,6 @@
#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>
@@ -41,7 +40,6 @@
extern "C"
{
#import "sys/system.h"
- #import "sys/cpu.h"
#import "sys/cpu_functions_names.h"
}
@@ -70,17 +68,17 @@ int main(int argc, char** argv)
MemoryBuffer* buffer;
LLVMContext* context = &(getGlobalContext());
- cout << "Loading System and CPU code...";
- Module* module_cpu = read_module(context, "sys/cpu.o", &error);
- if(!module_cpu) cerr << "Failed to load CPU module: " << error << endl;
- Module* module_mmu = NULL;
- // if(!module_mmu) cerr << "Failed to load MMU module: " << error << endl;
- Module* module_system = read_module(context, "sys/system.o", &error);
- if(!module_system) cerr << "Failed to load System module: " << error << endl;
- cout << "Complete." << endl;
+ cout << "Loading System implementation bitcode...";
+ Module* module_system = read_module(context, "sys/llboy.bc", &error);
+ if(module_system)
+ {
+ cout << "Complete." << endl;
+ } else {
+ cerr << "Failed to load system module: " << error << endl;
+ return -1;
+ }
- // InitializeNativeTarget();
- // ExecutionEngine* engine = ExecutionEngine::create(module_system, false, &error);
+ // Create JIT for native target
InitializeNativeTarget();
ExecutionEngine* engine = ExecutionEngine::createJIT(module_system, &error);
if(engine)
@@ -90,10 +88,8 @@ int main(int argc, char** argv)
cerr << "Failed to create Execution Engine: " << error << endl;
return -1;
}
-
- engine->addModule(module_cpu);
-
- Function* op_ADDr_b = module_cpu->getFunction(cpu_op_names_basic[0x80]);
+
+ Function* op_ADDr_b = module_system->getFunction(cpu_op_names_basic[0x80]);
if(op_ADDr_b)
{
cout << "Found ADDr_b function" << endl;
@@ -111,7 +107,7 @@ int main(int argc, char** argv)
return -1;
}
- system_t* state = (system_t*) malloc(sizeof(system_t));
+ system_t* state = initialize_system();
state->cpu.a = 1;
state->cpu.b = 2;
void (*ADDr_b)(system_t*) = (void (*)(system_t*)) p_ADDr_b;
View
7 src/sys/cpu.c
@@ -119,14 +119,11 @@ void cpu_execute(system_t* state)
// -- Ops -- //
void cpu_op_undefined(system_t* state)
{
- printf("Hit unknown instruction $%x", state->cpu.pc);
state->cpu.stop = true;
}
void cpu_op_unimplemented(system_t* state)
{
- printf("Hit unimplemented instruction 0x%02x at 0x%04x\n",
- mmu_rb(state, state->cpu.pc), state->cpu.pc);
state->cpu.halt = true;
}
@@ -191,7 +188,7 @@ LDRR(l,a); LDRR(l,b); LDRR(l,c); LDRR(l,d); LDRR(l,e); LDRR(l,h); LDRR(l,l);
#define LDRHLM(to) CPU_OP(LDrHLm_##to) \
{\
CPU_INSTRUCTION_PRE; \
- uint16_t address = state->cpu.h << 8 + state->cpu.l; \
+ uint16_t address = (state->cpu.h << 8) + state->cpu.l; \
state->cpu.to = mmu_rb(state, address); \
state->cpu.m = 2; \
CPU_INSTRUCTION_POST; \
@@ -203,7 +200,7 @@ LDRHLM(a); LDRHLM(b); LDRHLM(c); LDRHLM(d); LDRHLM(e); LDRHLM(h); LDRHLM(l);
#define LDHLMR(from) CPU_OP(LDHLmr_##from)\
{\
CPU_INSTRUCTION_PRE; \
- uint16_t address = state->cpu.h << 8 + state->cpu.l; \
+ uint16_t address = (state->cpu.h << 8) + state->cpu.l; \
mmu_wb(state, address, state->cpu.from); \
state->cpu.m = 2; \
CPU_INSTRUCTION_POST; \
View
1  src/sys/system.c
@@ -18,6 +18,7 @@
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.
+#include <stdlib.h>
#include "system.h"
#include "cpu_functions.h"
#include "mmu_functions.h"
View
2  src/sys/system.h
@@ -21,8 +21,6 @@
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.
-
-#include <stdlib.h>
#include "cpu.h"
#include "mmu.h"
View
2  src/sys/test_cpu_basic.c
@@ -19,10 +19,12 @@
// THE SOFTWARE.
#import <assert.h>
+#import <stdlib.h>
#import "cpu.h"
#import "cpu_functions.h"
#import "system.h"
+/// Execute a simple NOP function to sanity-check the CPU
int main(int argc, char** argv)
{
system_t* sys = (system_t*) malloc(sizeof(system_t));
View
13 src/sys/test_mmu_contiguous.c
@@ -20,6 +20,7 @@
#include <stdio.h>
#include <stdint.h>
+#include <assert.h>
#include "system.h"
#include "mmu.h"
#include "mmu_functions.h"
@@ -28,17 +29,13 @@
int main (int argc, char const *argv[])
{
system_t* state = initialize_system();
- uint16_t i = 0;
- do {
+ for(uint16_t i = 0; i < 0xFFFF; i++) {
if(i % 0x100 == 0) {
printf("Reading 0x%04x...\n", i);
}
- uint32_t index = mmu_memory_offset(state, i);
- if(index < 0) {
- printf("Hit unimplemented memory at 0x%04x\n", i);
- return 1;
- }
- } while(i++ != 0xFFFF);
+
+ assert(mmu_memory_offset(state, i) != -1);
+ }
return 0;
}
Please sign in to comment.
Something went wrong with that request. Please try again.