corda/unittest/codegen/assembler-test.cpp

96 lines
1.8 KiB
C++
Raw Normal View History

2013-02-15 03:54:20 +00:00
/* Copyright (c) 2008-2011, Avian Contributors
Permission to use, copy, modify, and/or distribute this software
for any purpose with or without fee is hereby granted, provided
that the above copyright notice and this permission notice appear
in all copies.
There is NO WARRANTY for this software. See license.txt for
details. */
#include <stdio.h>
#include "common.h"
2013-02-20 17:23:20 +00:00
#include <avian/vm/heap/heap.h>
2013-02-21 03:42:09 +00:00
#include <avian/vm/system/system.h>
2013-02-15 14:35:17 +00:00
#include "target.h"
2013-02-20 05:12:28 +00:00
#include <avian/vm/codegen/assembler.h>
#include <avian/vm/codegen/targets.h>
#include <avian/vm/codegen/lir.h>
2013-02-15 03:54:20 +00:00
#include "test-harness.h"
using namespace avian::codegen;
using namespace vm;
2013-02-15 14:35:17 +00:00
class BasicEnv {
public:
System* s;
Heap* heap;
Assembler::Architecture* arch;
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();
}
};
2013-02-15 03:54:20 +00:00
class BasicAssemblerTest : public Test {
public:
BasicAssemblerTest():
2013-02-15 14:35:17 +00:00
Test("BasicAssembler")
2013-02-15 03:54:20 +00:00
{}
virtual void run() {
2013-02-15 14:35:17 +00:00
BasicEnv env;
Asm a(env);
2013-02-15 03:54:20 +00:00
}
} basicAssemblerTest;
2013-02-15 14:35:17 +00:00
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;
OperandMask mask;
env.arch->plan((lir::UnaryOperation)op, vm::TargetBytesPerWord, mask, &thunk);
2013-02-15 14:35:17 +00:00
assertFalse(thunk);
assertNotEqual(static_cast<uint8_t>(0), mask.typeMask);
assertNotEqual(static_cast<uint64_t>(0), mask.registerMask);
2013-02-15 14:35:17 +00:00
}
}
} architecturePlanTest;