diff --git a/makefile b/makefile index 2f766eb2b2..f760e2a223 100755 --- a/makefile +++ b/makefile @@ -936,7 +936,7 @@ vm-sources = \ $(src)/finder.cpp \ $(src)/machine.cpp \ $(src)/util.cpp \ - $(src)/heap.cpp \ + $(src)/heap/heap.cpp \ $(src)/$(process).cpp \ $(src)/classpath-$(classpath).cpp \ $(src)/builtin.cpp \ diff --git a/src/bootimage.cpp b/src/bootimage.cpp index 111d850f97..c2879403a2 100644 --- a/src/bootimage.cpp +++ b/src/bootimage.cpp @@ -8,7 +8,7 @@ There is NO WARRANTY for this software. See license.txt for details. */ -#include "heap.h" +#include "heap/heap.h" #include "heapwalk.h" #include "common.h" #include "machine.h" diff --git a/src/heap.cpp b/src/heap/heap.cpp similarity index 99% rename from src/heap.cpp rename to src/heap/heap.cpp index eadb13ef78..119a250572 100644 --- a/src/heap.cpp +++ b/src/heap/heap.cpp @@ -8,7 +8,7 @@ There is NO WARRANTY for this software. See license.txt for details. */ -#include "heap.h" +#include "heap/heap.h" #include "system.h" #include "common.h" #include "arch.h" diff --git a/src/heap.h b/src/heap/heap.h similarity index 100% rename from src/heap.h rename to src/heap/heap.h diff --git a/src/machine.h b/src/machine.h index d31b4bf7b1..1d29cbc88a 100644 --- a/src/machine.h +++ b/src/machine.h @@ -13,7 +13,7 @@ #include "common.h" #include "system.h" -#include "heap.h" +#include "heap/heap.h" #include "finder.h" #include "processor.h" #include "constants.h" diff --git a/src/processor.h b/src/processor.h index 1c1de3e577..47e8d3c02d 100644 --- a/src/processor.h +++ b/src/processor.h @@ -13,7 +13,7 @@ #include "common.h" #include "system.h" -#include "heap.h" +#include "heap/heap.h" #include "bootimage.h" #include "heapwalk.h" #include "zone.h" diff --git a/unittest/codegen/assembler-test.cpp b/unittest/codegen/assembler-test.cpp index d7d09a72d3..3fe8a07427 100644 --- a/unittest/codegen/assembler-test.cpp +++ b/unittest/codegen/assembler-test.cpp @@ -11,27 +11,86 @@ #include #include "common.h" +#include "heap/heap.h" +#include "system.h" +#include "target.h" + #include "codegen/assembler.h" #include "codegen/targets.h" +#include "codegen/lir.h" #include "test-harness.h" -#include "system.h" - using namespace avian::codegen; using namespace vm; -class BasicAssemblerTest : public Test { +class BasicEnv { public: - BasicAssemblerTest(): - Test("BasicAssemblerTest") - {} + System* s; + Heap* heap; + Assembler::Architecture* arch; - virtual void run() { - System* s = makeSystem(0); - Assembler::Architecture* arch = makeArchitectureNative(s, true); + BasicEnv(): + s(makeSystem(0)), + heap(makeHeap(s, 32 * 1024)), + arch(makeArchitectureNative(s, true)) + { + arch->acquire(); + } + + ~BasicEnv() { arch->release(); s->dispose(); } +}; + +class Asm { +public: + Zone zone; + Assembler* a; + + Asm(BasicEnv& env): + zone(env.s, env.heap, 8192), + a(env.arch->makeAssembler(env.heap, &zone)) + { } + + ~Asm() { + a->dispose(); + } +}; + + +class BasicAssemblerTest : public Test { +public: + BasicAssemblerTest(): + Test("BasicAssembler") + {} + + virtual void run() { + BasicEnv env; + Asm a(env); + } } basicAssemblerTest; + +class ArchitecturePlanTest : public Test { +public: + ArchitecturePlanTest(): + Test("ArchitecturePlan") + {} + + virtual void run() { + BasicEnv env; + + for(int op = (int)lir::Call; op < (int)lir::AlignedJump; op++) { + bool thunk; + uint8_t typeMask; + uint64_t registerMask; + env.arch->plan((lir::UnaryOperation)op, vm::TargetBytesPerWord, &typeMask, ®isterMask, &thunk); + assertFalse(thunk); + assertNotEqual(static_cast(0), typeMask); + assertNotEqual(static_cast(0), registerMask); + } + + } +} architecturePlanTest; diff --git a/unittest/test-harness.h b/unittest/test-harness.h index e977c95c02..0b6b5e0fba 100644 --- a/unittest/test-harness.h +++ b/unittest/test-harness.h @@ -27,12 +27,20 @@ private: fprintf(stderr, "%s", value ? "true" : "false"); } + void print(uint8_t value) { + fprintf(stderr, "0x%02x", value); + } + + void print(uint64_t value) { + fprintf(stderr, "0x%" LLD, value); + } + int failures; int runs; protected: template - void assertEquals(T expected, T actual) { + void assertEqual(T expected, T actual) { if(expected != actual) { fprintf(stderr, "assertion failure, expected: "); print(expected); @@ -43,9 +51,26 @@ protected: } runs++; } + + template + void assertNotEqual(T expected, T actual) { + if(expected == actual) { + fprintf(stderr, "assertion failure, expected: not "); + print(expected); + fprintf(stderr, ", actual: "); + print(actual); + fprintf(stderr, "\n"); + failures++; + } + runs++; + } void assertTrue(bool value) { - assertEquals(true, value); + assertEqual(true, value); + } + + void assertFalse(bool value) { + assertEqual(false, value); } public: