mirror of
https://github.com/corda/corda.git
synced 2025-01-08 14:03:06 +00:00
audit-codegen prototype working
This commit is contained in:
parent
aaa076f1df
commit
d1a149a0a1
@ -45,6 +45,28 @@ public:
|
|||||||
{ }
|
{ }
|
||||||
};
|
};
|
||||||
|
|
||||||
|
class RegisterIterator {
|
||||||
|
public:
|
||||||
|
int index;
|
||||||
|
const RegisterMask& mask;
|
||||||
|
|
||||||
|
inline RegisterIterator(const RegisterMask& mask):
|
||||||
|
index(mask.start),
|
||||||
|
mask(mask) {}
|
||||||
|
|
||||||
|
inline bool hasNext() {
|
||||||
|
return index < mask.limit;
|
||||||
|
}
|
||||||
|
|
||||||
|
inline int next() {
|
||||||
|
int r = index;
|
||||||
|
do {
|
||||||
|
index++;
|
||||||
|
} while(index < mask.limit && !(mask.mask & (1 << index)));
|
||||||
|
return r;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
} // namespace codegen
|
} // namespace codegen
|
||||||
} // namespace avian
|
} // namespace avian
|
||||||
|
|
||||||
|
@ -8,23 +8,80 @@
|
|||||||
There is NO WARRANTY for this software. See license.txt for
|
There is NO WARRANTY for this software. See license.txt for
|
||||||
details. */
|
details. */
|
||||||
|
|
||||||
#include "system.h"
|
#include <avian/vm/system/system.h>
|
||||||
|
|
||||||
#include <avian/util/arg-parser.h>
|
#include <avian/util/arg-parser.h>
|
||||||
|
|
||||||
#include "codegen/lir.h"
|
#include <avian/vm/codegen/lir.h>
|
||||||
#include "codegen/assembler.h"
|
#include <avian/vm/codegen/assembler.h>
|
||||||
#include "codegen/targets.h"
|
#include <avian/vm/codegen/targets.h>
|
||||||
|
#include <avian/vm/codegen/registers.h>
|
||||||
|
|
||||||
|
#include <avian/vm/heap/heap.h>
|
||||||
|
|
||||||
// since we aren't linking against libstdc++, we must implement this
|
// since we aren't linking against libstdc++, we must implement this
|
||||||
// ourselves:
|
// ourselves:
|
||||||
extern "C" void __cxa_pure_virtual(void) { abort(); }
|
extern "C" void __cxa_pure_virtual(void) { abort(); }
|
||||||
|
|
||||||
|
using namespace vm;
|
||||||
using namespace avian::codegen;
|
using namespace avian::codegen;
|
||||||
using namespace avian::util;
|
using namespace avian::util;
|
||||||
|
|
||||||
void generateCode(Assembler::Architecture* arch) {
|
class BasicEnv {
|
||||||
for()
|
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();
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
void generateCode(BasicEnv& env) {
|
||||||
|
Asm a(env);
|
||||||
|
for(RegisterIterator it(env.arch->registerFile()->generalRegisters); it.hasNext(); ) {
|
||||||
|
int r = it.next();
|
||||||
|
lir::Register reg(r);
|
||||||
|
a.a->apply(lir::Add,
|
||||||
|
OperandInfo(4, lir::RegisterOperand, ®),
|
||||||
|
OperandInfo(4, lir::RegisterOperand, ®),
|
||||||
|
OperandInfo(4, lir::RegisterOperand, ®));
|
||||||
|
}
|
||||||
|
unsigned length = a.a->endBlock(false)->resolve(0, 0);
|
||||||
|
printf("length: %d\n", length);
|
||||||
|
uint8_t* data = static_cast<uint8_t*>(env.s->tryAllocate(length));
|
||||||
|
a.a->setDestination(data);
|
||||||
|
a.a->write();
|
||||||
|
for(unsigned i = 0; i < length; i++) {
|
||||||
|
printf("%02x ", data[i]);
|
||||||
|
}
|
||||||
|
printf("\n");
|
||||||
|
env.s->free(data);
|
||||||
}
|
}
|
||||||
|
|
||||||
class Arguments {
|
class Arguments {
|
||||||
@ -51,13 +108,9 @@ public:
|
|||||||
int main(int argc, char** argv) {
|
int main(int argc, char** argv) {
|
||||||
Arguments args(argc, argv);
|
Arguments args(argc, argv);
|
||||||
|
|
||||||
vm::System* s = vm::makeSystem(0);
|
BasicEnv env;
|
||||||
Assembler::Architecture* arch = makeArchitectureNative(s, true);
|
|
||||||
arch->acquire();
|
|
||||||
|
|
||||||
generateCode(arch);
|
generateCode(env);
|
||||||
|
|
||||||
arch->release();
|
|
||||||
s->dispose();
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
44
unittest/codegen/registers-test.cpp
Normal file
44
unittest/codegen/registers-test.cpp
Normal file
@ -0,0 +1,44 @@
|
|||||||
|
/* 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 <avian/vm/codegen/registers.h>
|
||||||
|
|
||||||
|
#include "test-harness.h"
|
||||||
|
|
||||||
|
|
||||||
|
using namespace avian::codegen;
|
||||||
|
using namespace vm;
|
||||||
|
|
||||||
|
|
||||||
|
class RegisterIteratorTest : public Test {
|
||||||
|
public:
|
||||||
|
RegisterIteratorTest():
|
||||||
|
Test("RegisterIterator")
|
||||||
|
{}
|
||||||
|
|
||||||
|
virtual void run() {
|
||||||
|
RegisterMask regs(0x55);
|
||||||
|
assertEqual<unsigned>(0, regs.start);
|
||||||
|
assertEqual<unsigned>(7, regs.limit);
|
||||||
|
|
||||||
|
RegisterIterator it(regs);
|
||||||
|
assertTrue(it.hasNext());
|
||||||
|
assertEqual<unsigned>(0, it.next());
|
||||||
|
assertTrue(it.hasNext());
|
||||||
|
assertEqual<unsigned>(2, it.next());
|
||||||
|
assertTrue(it.hasNext());
|
||||||
|
assertEqual<unsigned>(4, it.next());
|
||||||
|
assertTrue(it.hasNext());
|
||||||
|
assertEqual<unsigned>(6, it.next());
|
||||||
|
assertFalse(it.hasNext());
|
||||||
|
}
|
||||||
|
} registerIteratorTest;
|
Loading…
Reference in New Issue
Block a user