update generated type code and fix most link errors

This commit is contained in:
Joel Dice 2007-06-18 13:23:44 -06:00
parent d595a2fd61
commit 6756ade3bd
7 changed files with 76 additions and 80 deletions

View File

@ -31,13 +31,13 @@ stdcpp-sources = $(src)/stdc++.cpp
stdcpp-objects = $(call cpp-objects,$(stdcpp-sources),$(src)) stdcpp-objects = $(call cpp-objects,$(stdcpp-sources),$(src))
stdcpp-cflags = $(fast) $(cflags) stdcpp-cflags = $(fast) $(cflags)
type-headers = \ generated-code = \
$(bld)/type-header.h \ $(bld)/type-declarations.cpp \
$(bld)/type-declarations.h \ $(bld)/type-members.cpp \
$(bld)/type-constructors.h \ $(bld)/type-constructors.cpp \
$(bld)/type-primary-inits.h $(bld)/type-initializations.cpp
interpreter-headers = \ interpreter-depends = \
$(type-headers) \ $(generated-code) \
$(src)/heap.h \ $(src)/heap.h \
$(src)/system.h $(src)/system.h
interpreter-sources = \ interpreter-sources = \
@ -114,8 +114,8 @@ clean:
@echo "removing $(bld)" @echo "removing $(bld)"
rm -r $(bld) rm -r $(bld)
gen-arg = $(shell echo $(1) | sed -e 's:$(bld)/type-\(.*\)\.h:\1:') gen-arg = $(shell echo $(1) | sed -e 's:$(bld)/type-\(.*\)\.cpp:\1:')
$(type-headers): %.h: $(src)/types.def $(generator-executable) $(generated-code): %.cpp: $(src)/types.def $(generator-executable)
@echo "generating $(@)" @echo "generating $(@)"
$(generator-executable) $(call gen-arg,$(@)) < $(<) > $(@) $(generator-executable) $(call gen-arg,$(@)) < $(<) > $(@)
@ -123,7 +123,7 @@ $(bld)/vm.o \
$(bld)/test-vm.o \ $(bld)/test-vm.o \
$(bld)/stress-vm.o \ $(bld)/stress-vm.o \
$(bld)/fast-vm.o: \ $(bld)/fast-vm.o: \
$(interpreter-headers) $(interpreter-depends)
$(bld)/type-generator.o: \ $(bld)/type-generator.o: \
$(generator-headers) $(generator-headers)

View File

@ -1,6 +1,8 @@
#ifndef CONSTANTS_H #ifndef CONSTANTS_H
#define CONSTANTS_H #define CONSTANTS_H
namespace vm {
enum OpCode { enum OpCode {
aaload, aaload,
aastore, aastore,
@ -175,7 +177,7 @@ enum OpCode {
new_, new_,
newarray, newarray,
nop, nop,
pop_, pop,
pop2, pop2,
putfield, putfield,
putstatic, putstatic,
@ -225,4 +227,6 @@ const unsigned ACC_TRANSIENT = 1 << 7;
const unsigned ACC_INTERFACE = 1 << 9; const unsigned ACC_INTERFACE = 1 << 9;
const unsigned ACC_ABSTRACT = 1 << 10; const unsigned ACC_ABSTRACT = 1 << 10;
} // namespace vm
#endif//CONSTANTS_H #endif//CONSTANTS_H

View File

@ -1,6 +1,8 @@
#ifndef HEAP_H #ifndef HEAP_H
#define HEAP_H #define HEAP_H
namespace vm {
class Heap { class Heap {
public: public:
enum CollectionType { enum CollectionType {
@ -26,4 +28,6 @@ class Heap {
virtual void mark(void** p); virtual void mark(void** p);
}; };
} // namespace vm
#endif//HEAP_H #endif//HEAP_H

View File

@ -3,6 +3,8 @@
#include "common.h" #include "common.h"
namespace vm {
class Stream { class Stream {
public: public:
class Client { class Client {
@ -75,4 +77,6 @@ class Stream {
unsigned position; unsigned position;
}; };
} // namespace vm
#endif//STREAM_H #endif//STREAM_H

View File

@ -3,6 +3,8 @@
#include "common.h" #include "common.h"
namespace vm {
class System { class System {
public: public:
typedef int Status; typedef int Status;
@ -60,4 +62,6 @@ class System {
virtual void abort() = 0; virtual void abort() = 0;
}; };
} // namespace vm
#endif//SYSTEM_H #endif//SYSTEM_H

View File

@ -1209,7 +1209,7 @@ writeConstructorInitializations(Output* out, Object* t)
case Object::Scalar: { case Object::Scalar: {
out->write(" "); out->write(" ");
writeAccessorName(out, m, true); writeAccessorName(out, m, true);
out->write("(o) = "); out->write("(t, o) = ");
out->write(obfuscate(memberName(m))); out->write(obfuscate(memberName(m)));
out->write(";\n"); out->write(";\n");
} break; } break;
@ -1250,39 +1250,6 @@ writeConstructorDeclarations(Output* out, Object* declarations)
} }
} }
unsigned
typeProtectedMemberCount(Object* o)
{
unsigned count = 0;
for (MemberIterator it(o); it.hasMore();) {
Object* m = it.next();
if (m->type == Object::Scalar
and equal(memberTypeName(m), "object"))
{
++ count;
}
}
return count;
}
void
writeProtected(Output* out, Object* o)
{
bool wrote = false;
for (MemberIterator it(o); it.hasMore();) {
Object* m = it.next();
if (m->type == Object::Scalar
and equal(memberTypeName(m), "object"))
{
if (wrote) {
out->write(", ");
}
out->write(obfuscate(memberName(m)));
wrote = true;
}
}
}
void void
writeConstructors(Output* out, Object* declarations) writeConstructors(Output* out, Object* declarations)
{ {
@ -1301,20 +1268,22 @@ writeConstructors(Output* out, Object* declarations)
out->write(")\n{\n"); out->write(")\n{\n");
unsigned protectedCount = typeProtectedMemberCount(o); for (MemberIterator it(o); it.hasMore();) {
if (protectedCount) { Object* m = it.next();
out->write(" PROTECT"); if (m->type == Object::Scalar
out->write(protectedCount); and equal(memberTypeName(m), "object"))
out->write("("); {
writeProtected(out, o); out->write(" PROTECT(t, ");
out->write(obfuscate(memberName(m)));
out->write(");\n"); out->write(");\n");
} }
}
out->write(" object o = allocate(t, "); out->write(" object o = allocate(t, ");
writeOffset(out, typeOffset(o), true); writeOffset(out, typeOffset(o), true);
out->write(");\n"); out->write(");\n");
out->write(" objectClass(o) = system->"); out->write(" objectClass(o) = t->vm->");
out->write(typeName(o)); out->write(typeName(o));
out->write("Class;\n"); out->write("Class;\n");
@ -1329,7 +1298,7 @@ writeConstructors(Output* out, Object* declarations)
} }
void void
writeDeclarations(Output* out, Object* declarations) writeMembers(Output* out, Object* declarations)
{ {
for (Object* p = declarations; p; p = cdr(p)) { for (Object* p = declarations; p; p = cdr(p)) {
Object* o = car(p); Object* o = car(p);
@ -1446,7 +1415,7 @@ typeObjectMask(Object* type)
} }
void void
writePrimaryInitialization(Output* out, Object* type) writeInitialization(Output* out, Object* type)
{ {
unsigned memberCount = ::memberCount(type); unsigned memberCount = ::memberCount(type);
if (memberCount == 0) return; if (memberCount == 0) return;
@ -1456,34 +1425,32 @@ writePrimaryInitialization(Output* out, Object* type)
if (typeObjectMask(type)) { if (typeObjectMask(type)) {
out->write(" object mask = makeIntArray(t, 1);\n"); out->write(" object mask = makeIntArray(t, 1);\n");
out->write(" objectMaskBody(mask)[0] = "); out->write(" intArrayBody(t, mask)[0] = ");
out->write(typeObjectMask(type)); out->write(typeObjectMask(type));
out->write(";\n"); out->write(";\n");
} else { } else {
out->write(" object mask = 0;\n"); out->write(" object mask = 0;\n");
} }
out->write(" object "); out->write(" t->vm->");
out->write(typeName(type)); out->write(typeName(type));
out->write("Class = makeClass"); out->write("Class = makeClass");
out->write("(t, "); out->write("(t, 0, ");
out->write(capitalize(typeName(type)));
out->write("Type, ");
out->write(typeFixedSize(type)); out->write(typeFixedSize(type));
out->write(", "); out->write(", ");
out->write(typeArrayElementSize(type)); out->write(typeArrayElementSize(type));
out->write(", mask, 0, 0, 0, 0, 0);\n"); out->write(", mask, 0, 0, 0, 0, 0, 0, 0, 0);\n");
out->write("}\n\n"); out->write("}\n\n");
} }
void void
writePrimaryInitializations(Output* out, Object* declarations) writeInitializations(Output* out, Object* declarations)
{ {
for (Object* p = declarations; p; p = cdr(p)) { for (Object* p = declarations; p; p = cdr(p)) {
Object* o = car(p); Object* o = car(p);
if (o->type == Object::Type) { if (o->type == Object::Type) {
writePrimaryInitialization(out, o); writeInitialization(out, o);
} }
} }
} }
@ -1492,7 +1459,7 @@ void
usageAndExit(const char* command) usageAndExit(const char* command)
{ {
fprintf(stderr, fprintf(stderr,
"usage: %s {header,declarations,constructors,primary-inits}\n", "usage: %s {declarations,members,constructors,initializations}\n",
command); command);
exit(-1); exit(-1);
} }
@ -1504,10 +1471,10 @@ main(int ac, char** av)
{ {
if ((ac != 1 and ac != 2) if ((ac != 1 and ac != 2)
or (ac == 2 or (ac == 2
and not equal(av[1], "header")
and not equal(av[1], "declarations") and not equal(av[1], "declarations")
and not equal(av[1], "members")
and not equal(av[1], "constructors") and not equal(av[1], "constructors")
and not equal(av[1], "primary-inits"))) and not equal(av[1], "initializations")))
{ {
usageAndExit(av[0]); usageAndExit(av[0]);
} }
@ -1518,22 +1485,22 @@ main(int ac, char** av)
FileOutput out(0, stdout, false); FileOutput out(0, stdout, false);
if (ac == 1 or equal(av[1], "header")) { if (ac == 1 or equal(av[1], "declarations")) {
writePods(&out, declarations); writePods(&out, declarations);
writeAccessors(&out, declarations); writeAccessors(&out, declarations);
writeConstructorDeclarations(&out, declarations); writeConstructorDeclarations(&out, declarations);
} }
if (ac == 1 or equal(av[1], "declarations")) { if (ac == 1 or equal(av[1], "members")) {
writeDeclarations(&out, declarations); writeMembers(&out, declarations);
} }
if (ac == 1 or equal(av[1], "constructors")) { if (ac == 1 or equal(av[1], "constructors")) {
writeConstructors(&out, declarations); writeConstructors(&out, declarations);
} }
if (ac == 1 or equal(av[1], "primary-inits")) { if (ac == 1 or equal(av[1], "initializations")) {
writePrimaryInitializations(&out, declarations); writeInitializations(&out, declarations);
} }
return 0; return 0;

View File

@ -3,6 +3,7 @@
#include "heap.h" #include "heap.h"
#include "class_finder.h" #include "class_finder.h"
#include "stream.h" #include "stream.h"
#include "constants.h"
#define PROTECT(thread, name) \ #define PROTECT(thread, name) \
Thread::Protector MAKE_NAME(protector_) (thread, &name); Thread::Protector MAKE_NAME(protector_) (thread, &name);
@ -10,17 +11,25 @@
#define ACQUIRE(t, x) MonitorResource MAKE_NAME(monitorResource_) (t, x) #define ACQUIRE(t, x) MonitorResource MAKE_NAME(monitorResource_) (t, x)
#define ACQUIRE_RAW(t, x) RawMonitorResource MAKE_NAME(monitorResource_) (t, x) #define ACQUIRE_RAW(t, x) RawMonitorResource MAKE_NAME(monitorResource_) (t, x)
using namespace vm;
namespace { namespace {
typedef void* object; typedef void* object;
typedef unsigned Type; typedef unsigned Type;
#include "constants.h"
class Thread; class Thread;
void assert(Thread*, bool); void assert(Thread*, bool);
object resolveClass(Thread*, object); object resolveClass(Thread*, object);
object allocate(Thread* t, unsigned size);
inline unsigned
pad(unsigned n)
{
unsigned extra = n % sizeof(void*);
return (extra ? n + sizeof(void*) - extra : n);
}
template <class T> template <class T>
inline T& inline T&
@ -49,7 +58,7 @@ class Machine {
System::Monitor* classLock; System::Monitor* classLock;
object classMap; object classMap;
#include "type-declarations.h" #include "type-members.cpp"
}; };
class Thread { class Thread {
@ -97,7 +106,8 @@ class Thread {
Protector* protector; Protector* protector;
}; };
#include "type-header.h" #include "type-declarations.cpp"
#include "type-constructors.cpp"
void enter(Thread* t, Thread::State state); void enter(Thread* t, Thread::State state);
@ -171,10 +181,12 @@ dispose(Machine* m)
void void
init(Thread* t, Machine* m) init(Thread* t, Machine* m)
{ {
memset(m, 0, sizeof(Thread)); memset(t, 0, sizeof(Thread));
t->vm = m; t->vm = m;
m->rootThread = t; m->rootThread = t;
t->state = Thread::NoState; t->state = Thread::NoState;
#include "type-initializations.cpp"
} }
void void
@ -993,8 +1005,9 @@ parseFieldTable(Thread* t, Stream& s, object class_, object pool)
if (flags & ACC_STATIC) { if (flags & ACC_STATIC) {
fieldOffset(t, value) = staticOffset++; fieldOffset(t, value) = staticOffset++;
} else { } else {
if (memberOffset % sizeof(void*) and isReferenceField(t, value)) { unsigned excess = memberOffset % sizeof(void*);
while (memberOffset % sizeof(void*)) ++ memberOffset; if (excess and isReferenceField(t, value)) {
memberOffset += sizeof(void*) - excess;
} }
fieldOffset(t, value) = memberOffset; fieldOffset(t, value) = memberOffset;
@ -2452,7 +2465,7 @@ run(Thread* t)
push(t, arrayBody(t, codePool(t, code))[(index1 << 8) | index2]); push(t, arrayBody(t, codePool(t, code))[(index1 << 8) | index2]);
} goto loop; } goto loop;
case ldiv: { case vm::ldiv: {
object b = pop(t); object b = pop(t);
object a = pop(t); object a = pop(t);
@ -2609,7 +2622,7 @@ run(Thread* t)
case nop: goto loop; case nop: goto loop;
case pop_: { case vm::pop: {
-- sp; -- sp;
} goto loop; } goto loop;