mirror of
https://github.com/corda/corda.git
synced 2025-02-10 12:51:37 +00:00
type-generator now builds
This commit is contained in:
parent
f35d89cfa4
commit
2d44143944
25
makefile
25
makefile
@ -34,18 +34,22 @@ stdcpp-cflags = $(fast) $(cflags)
|
|||||||
type-headers = \
|
type-headers = \
|
||||||
$(bld)/type-header.h \
|
$(bld)/type-header.h \
|
||||||
$(bld)/type-enums.h \
|
$(bld)/type-enums.h \
|
||||||
$(bld)/type-op-enums.h \
|
|
||||||
$(bld)/type-enum-cases.h \
|
$(bld)/type-enum-cases.h \
|
||||||
$(bld)/type-op-enum-cases.h \
|
|
||||||
$(bld)/type-declarations.h \
|
$(bld)/type-declarations.h \
|
||||||
$(bld)/type-constructors.h \
|
$(bld)/type-constructors.h \
|
||||||
$(bld)/type-primary-inits.h
|
$(bld)/type-primary-inits.h
|
||||||
interpreter-headers = $(type-headers)
|
interpreter-headers = \
|
||||||
|
$(type-headers) \
|
||||||
|
$(src)/heap.h \
|
||||||
|
$(src)/system.h
|
||||||
interpreter-sources = \
|
interpreter-sources = \
|
||||||
$(src)/compile.cpp
|
$(src)/vm.cpp
|
||||||
interpreter-objects = $(call cpp-objects,$(interpreter-sources),$(src))
|
interpreter-objects = $(call cpp-objects,$(interpreter-sources),$(src))
|
||||||
interpreter-cflags = $(slow) $(cflags)
|
interpreter-cflags = $(slow) $(cflags)
|
||||||
|
|
||||||
|
generator-headers = \
|
||||||
|
$(src)/input.h \
|
||||||
|
$(src)/output.h
|
||||||
generator-sources = \
|
generator-sources = \
|
||||||
$(src)/type-generator.cpp
|
$(src)/type-generator.cpp
|
||||||
generator-objects = $(call cpp-objects,$(generator-sources),$(src))
|
generator-objects = $(call cpp-objects,$(generator-sources),$(src))
|
||||||
@ -117,11 +121,14 @@ $(type-headers): %.h: $(src)/types.def $(generator-executable)
|
|||||||
@echo "generating $(@)"
|
@echo "generating $(@)"
|
||||||
$(generator-executable) $(call gen-arg,$(@)) < $(<) > $(@)
|
$(generator-executable) $(call gen-arg,$(@)) < $(<) > $(@)
|
||||||
|
|
||||||
$(bld)/compile.o \
|
$(bld)/vm.o \
|
||||||
$(bld)/test-compile.o \
|
$(bld)/test-vm.o \
|
||||||
$(bld)/stress-compile.o \
|
$(bld)/stress-vm.o \
|
||||||
$(bld)/fast-compile.o: \
|
$(bld)/fast-vm.o: \
|
||||||
$(interpreter-headers)
|
$(interpreter-headers)
|
||||||
|
|
||||||
|
$(bld)/type-generator.o: \
|
||||||
|
$(generator-headers)
|
||||||
|
|
||||||
$(stdcpp-objects): $(bld)/%.o: $(src)/%.cpp
|
$(stdcpp-objects): $(bld)/%.o: $(src)/%.cpp
|
||||||
@echo "compiling $(@)"
|
@echo "compiling $(@)"
|
||||||
|
@ -146,12 +146,8 @@ class Scalar : public Object {
|
|||||||
|
|
||||||
class Array : public Scalar {
|
class Array : public Scalar {
|
||||||
public:
|
public:
|
||||||
const char* lengthString;
|
|
||||||
const char* positionString;
|
|
||||||
|
|
||||||
static Array* make(Object* owner, Object* typeObject, const char* typeName,
|
static Array* make(Object* owner, Object* typeObject, const char* typeName,
|
||||||
const char* name, const char* lengthString,
|
const char* name, unsigned elementSize)
|
||||||
const char* positionString, unsigned elementSize)
|
|
||||||
{
|
{
|
||||||
Array* o = allocate<Array>();
|
Array* o = allocate<Array>();
|
||||||
o->type = Object::Array;
|
o->type = Object::Array;
|
||||||
@ -159,8 +155,6 @@ class Array : public Scalar {
|
|||||||
o->typeObject = typeObject;
|
o->typeObject = typeObject;
|
||||||
o->typeName = typeName;
|
o->typeName = typeName;
|
||||||
o->name = name;
|
o->name = name;
|
||||||
o->lengthString = lengthString;
|
|
||||||
o->positionString = positionString;
|
|
||||||
o->elementSize = elementSize;
|
o->elementSize = elementSize;
|
||||||
return o;
|
return o;
|
||||||
}
|
}
|
||||||
@ -178,30 +172,6 @@ arrayElementSize(Object* o)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const char*
|
|
||||||
arrayLengthString(Object* o)
|
|
||||||
{
|
|
||||||
switch (o->type) {
|
|
||||||
case Object::Array:
|
|
||||||
return static_cast<Array*>(o)->lengthString;
|
|
||||||
|
|
||||||
default:
|
|
||||||
UNREACHABLE;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
const char*
|
|
||||||
arrayPositionString(Object* o)
|
|
||||||
{
|
|
||||||
switch (o->type) {
|
|
||||||
case Object::Array:
|
|
||||||
return static_cast<Array*>(o)->positionString;
|
|
||||||
|
|
||||||
default:
|
|
||||||
UNREACHABLE;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
Object*
|
Object*
|
||||||
memberOwner(Object* o)
|
memberOwner(Object* o)
|
||||||
{
|
{
|
||||||
@ -766,6 +736,10 @@ sizeOf(const char* type, Object* declarations)
|
|||||||
return sizeof(uint8_t);
|
return sizeof(uint8_t);
|
||||||
} else if (equal(type, "int16_t") or equal(type, "uint16_t")) {
|
} else if (equal(type, "int16_t") or equal(type, "uint16_t")) {
|
||||||
return sizeof(uint16_t);
|
return sizeof(uint16_t);
|
||||||
|
} else if (equal(type, "int32_t") or equal(type, "uint32_t")) {
|
||||||
|
return sizeof(uint32_t);
|
||||||
|
} else if (equal(type, "int64_t") or equal(type, "uint64_t")) {
|
||||||
|
return sizeof(uint64_t);
|
||||||
} else if (equal(type, "char")) {
|
} else if (equal(type, "char")) {
|
||||||
return sizeof(char);
|
return sizeof(char);
|
||||||
} else if (namesPointer(type)) {
|
} else if (namesPointer(type)) {
|
||||||
@ -780,7 +754,7 @@ sizeOf(const char* type, Object* declarations)
|
|||||||
}
|
}
|
||||||
|
|
||||||
Object*
|
Object*
|
||||||
parseArray(Object::ObjectType type, Object* t, Object* p, Object* declarations)
|
parseArray(Object* t, Object* p, Object* declarations)
|
||||||
{
|
{
|
||||||
const char* typeName = string(car(p));
|
const char* typeName = string(car(p));
|
||||||
|
|
||||||
@ -788,8 +762,7 @@ parseArray(Object::ObjectType type, Object* t, Object* p, Object* declarations)
|
|||||||
const char* name = string(car(p));
|
const char* name = string(car(p));
|
||||||
|
|
||||||
return Array::make(t, declaration(typeName, declarations),
|
return Array::make(t, declaration(typeName, declarations),
|
||||||
typeName, name, length, position,
|
typeName, name, sizeOf(typeName, declarations));
|
||||||
sizeOf(typeName, declarations));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Object*
|
Object*
|
||||||
@ -797,7 +770,7 @@ parseMember(Object* t, Object* p, Object* declarations)
|
|||||||
{
|
{
|
||||||
const char* spec = string(car(p));
|
const char* spec = string(car(p));
|
||||||
if (equal(spec, "array")) {
|
if (equal(spec, "array")) {
|
||||||
return parseArray(Object::Array, t, cdr(p), declarations);
|
return parseArray(t, cdr(p), declarations);
|
||||||
} else if (equal(spec, "noassert")) {
|
} else if (equal(spec, "noassert")) {
|
||||||
Object* member = parseMember(t, cdr(p), declarations);
|
Object* member = parseMember(t, cdr(p), declarations);
|
||||||
memberNoAssert(member) = true;
|
memberNoAssert(member) = true;
|
||||||
@ -928,10 +901,6 @@ parseDeclaration(Object* p, Object* declarations)
|
|||||||
const char* spec = string(car(p));
|
const char* spec = string(car(p));
|
||||||
if (equal(spec, "type")) {
|
if (equal(spec, "type")) {
|
||||||
return parseType(Object::Type, cdr(p), declarations);
|
return parseType(Object::Type, cdr(p), declarations);
|
||||||
} else if (equal(spec, "op")) {
|
|
||||||
Object* t = parseType(Object::Type, cdr(p), declarations);
|
|
||||||
typeOp(t) = true;
|
|
||||||
return t;
|
|
||||||
} else if (equal(spec, "pod")) {
|
} else if (equal(spec, "pod")) {
|
||||||
return parseType(Object::Pod, cdr(p), declarations);
|
return parseType(Object::Pod, cdr(p), declarations);
|
||||||
} else {
|
} else {
|
||||||
@ -989,14 +958,12 @@ writeOffset(Output* out, Object* offset, bool allocationStyle = false)
|
|||||||
} break;
|
} break;
|
||||||
|
|
||||||
case Object::Array: {
|
case Object::Array: {
|
||||||
const char* lengthString = arrayLengthString(o);
|
|
||||||
|
|
||||||
out->write("pad((");
|
out->write("pad((");
|
||||||
if (allocationStyle) {
|
if (allocationStyle) {
|
||||||
out->write(lengthString);
|
out->write("length");
|
||||||
} else {
|
} else {
|
||||||
out->write(typeShortName(memberOwner(o)));
|
out->write(typeShortName(memberOwner(o)));
|
||||||
out->write(capitalize(lengthString));
|
out->write(capitalize("length"));
|
||||||
out->write("(o)");
|
out->write("(o)");
|
||||||
}
|
}
|
||||||
out->write(" * ");
|
out->write(" * ");
|
||||||
@ -1373,24 +1340,6 @@ writeEnums(Output* out, Object* declarations)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
|
||||||
writeOpEnums(Output* out, Object* declarations)
|
|
||||||
{
|
|
||||||
for (Object* p = declarations; p; p = cdr(p)) {
|
|
||||||
Object* o = car(p);
|
|
||||||
switch (o->type) {
|
|
||||||
case Object::Type: {
|
|
||||||
if (typeOp(o)) {
|
|
||||||
out->write(capitalize(typeName(o)));
|
|
||||||
out->write(",\n");
|
|
||||||
}
|
|
||||||
} break;
|
|
||||||
|
|
||||||
default: break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
const char*
|
const char*
|
||||||
lispStyle(const char* s)
|
lispStyle(const char* s)
|
||||||
{
|
{
|
||||||
@ -1434,37 +1383,6 @@ writeEnumCases(Output* out, Object* declarations)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
|
||||||
writeOpEnumCases(Output* out, Object* declarations)
|
|
||||||
{
|
|
||||||
for (Object* p = declarations; p; p = cdr(p)) {
|
|
||||||
Object* o = car(p);
|
|
||||||
switch (o->type) {
|
|
||||||
case Object::Type: {
|
|
||||||
if (typeOp(o)) {
|
|
||||||
out->write("case ");
|
|
||||||
out->write(capitalize(typeName(o)));
|
|
||||||
out->write(": return \"");
|
|
||||||
out->write(lispStyle(typeName(o)));
|
|
||||||
out->write("\";\n");
|
|
||||||
}
|
|
||||||
} break;
|
|
||||||
|
|
||||||
default: break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
const char*
|
|
||||||
opName(const char* s)
|
|
||||||
{
|
|
||||||
unsigned length = strlen(s);
|
|
||||||
assert(length > 2);
|
|
||||||
const char* r = strndup(s, length - 2);
|
|
||||||
assert(r);
|
|
||||||
return r;
|
|
||||||
}
|
|
||||||
|
|
||||||
void
|
void
|
||||||
writeDeclarations(Output* out, Object* declarations)
|
writeDeclarations(Output* out, Object* declarations)
|
||||||
{
|
{
|
||||||
@ -1499,7 +1417,7 @@ void
|
|||||||
set(uint32_t* mask, unsigned index)
|
set(uint32_t* mask, unsigned index)
|
||||||
{
|
{
|
||||||
if (index < 32) {
|
if (index < 32) {
|
||||||
mask |= 1 << index;
|
*mask |= 1 << index;
|
||||||
} else {
|
} else {
|
||||||
UNREACHABLE;
|
UNREACHABLE;
|
||||||
}
|
}
|
||||||
@ -1509,7 +1427,7 @@ unsigned
|
|||||||
typeFixedSize(Object* type)
|
typeFixedSize(Object* type)
|
||||||
{
|
{
|
||||||
unsigned length = 0;
|
unsigned length = 0;
|
||||||
for (MemberIterator it(o); it.hasMore();) {
|
for (MemberIterator it(type); it.hasMore();) {
|
||||||
Object* m = it.next();
|
Object* m = it.next();
|
||||||
switch (m->type) {
|
switch (m->type) {
|
||||||
case Object::Scalar: {
|
case Object::Scalar: {
|
||||||
@ -1521,19 +1439,19 @@ typeFixedSize(Object* type)
|
|||||||
default: UNREACHABLE;
|
default: UNREACHABLE;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return length;
|
return length / 4;
|
||||||
}
|
}
|
||||||
|
|
||||||
unsigned
|
unsigned
|
||||||
typeArrayElementSize(Object* type)
|
typeArrayElementSize(Object* type)
|
||||||
{
|
{
|
||||||
for (MemberIterator it(o); it.hasMore();) {
|
for (MemberIterator it(type); it.hasMore();) {
|
||||||
Object* m = it.next();
|
Object* m = it.next();
|
||||||
switch (m->type) {
|
switch (m->type) {
|
||||||
case Object::Scalar: break;
|
case Object::Scalar: break;
|
||||||
|
|
||||||
case Object::Array: {
|
case Object::Array: {
|
||||||
return memberElementSize(m);
|
return memberElementSize(m) / 4;
|
||||||
} break;
|
} break;
|
||||||
|
|
||||||
default: UNREACHABLE;
|
default: UNREACHABLE;
|
||||||
@ -1545,11 +1463,11 @@ typeArrayElementSize(Object* type)
|
|||||||
uint32_t
|
uint32_t
|
||||||
typeObjectMask(Object* type)
|
typeObjectMask(Object* type)
|
||||||
{
|
{
|
||||||
assert(typeFixedMaskLength(type) + typeArrayElementMaskLength(type) < 32);
|
assert(typeFixedSize(type) + typeArrayElementSize(type) < 32);
|
||||||
|
|
||||||
uint32_t mask = 0;
|
uint32_t mask = 0;
|
||||||
|
|
||||||
for (MemberIterator it(o); it.hasMore();) {
|
for (MemberIterator it(type); it.hasMore();) {
|
||||||
Object* m = it.next();
|
Object* m = it.next();
|
||||||
unsigned offset = it.offset() / sizeof(void*);
|
unsigned offset = it.offset() / sizeof(void*);
|
||||||
|
|
||||||
@ -1566,7 +1484,7 @@ typeObjectMask(Object* type)
|
|||||||
} else if (memberTypeObject(m)
|
} else if (memberTypeObject(m)
|
||||||
and memberTypeObject(m)->type == Object::Pod)
|
and memberTypeObject(m)->type == Object::Pod)
|
||||||
{
|
{
|
||||||
for (MemberIterator it(m); it.hasMore();) {
|
for (MemberIterator it(memberTypeObject(m)); it.hasMore();) {
|
||||||
Object* m = it.next();
|
Object* m = it.next();
|
||||||
if (equal(memberTypeName(m), "object")) {
|
if (equal(memberTypeName(m), "object")) {
|
||||||
set(&mask, offset + (it.offset() / sizeof(void*)));
|
set(&mask, offset + (it.offset() / sizeof(void*)));
|
||||||
@ -1578,6 +1496,8 @@ typeObjectMask(Object* type)
|
|||||||
default: UNREACHABLE;
|
default: UNREACHABLE;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return mask;
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
@ -1642,9 +1562,7 @@ main(int ac, char** av)
|
|||||||
or (ac == 2
|
or (ac == 2
|
||||||
and not equal(av[1], "header")
|
and not equal(av[1], "header")
|
||||||
and not equal(av[1], "enums")
|
and not equal(av[1], "enums")
|
||||||
and not equal(av[1], "op-enums")
|
|
||||||
and not equal(av[1], "enum-cases")
|
and not equal(av[1], "enum-cases")
|
||||||
and not equal(av[1], "op-enum-cases")
|
|
||||||
and not equal(av[1], "declarations")
|
and not equal(av[1], "declarations")
|
||||||
and not equal(av[1], "constructors")
|
and not equal(av[1], "constructors")
|
||||||
and not equal(av[1], "primary-inits")))
|
and not equal(av[1], "primary-inits")))
|
||||||
@ -1668,18 +1586,10 @@ main(int ac, char** av)
|
|||||||
writeEnums(&out, declarations);
|
writeEnums(&out, declarations);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (ac == 1 or equal(av[1], "op-enums")) {
|
|
||||||
writeOpEnums(&out, declarations);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (ac == 1 or equal(av[1], "enum-cases")) {
|
if (ac == 1 or equal(av[1], "enum-cases")) {
|
||||||
writeEnumCases(&out, declarations);
|
writeEnumCases(&out, declarations);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (ac == 1 or equal(av[1], "op-enum-cases")) {
|
|
||||||
writeOpEnumCases(&out, declarations);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (ac == 1 or equal(av[1], "declarations")) {
|
if (ac == 1 or equal(av[1], "declarations")) {
|
||||||
writeDeclarations(&out, declarations);
|
writeDeclarations(&out, declarations);
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user