Commit 2c1ef4dc authored by Anders Blomdell's avatar Anders Blomdell
Browse files

Preparing to remove need for decoder->reader and encoder->writer

indirection in generated C-code.
parent f0f8cc6e
...@@ -224,17 +224,17 @@ static int get_encoder_index( ...@@ -224,17 +224,17 @@ static int get_encoder_index(
#endif #endif
} }
void labcomm_encode_signature(struct labcomm_encoder *e, static void labcomm_encode_signature(struct labcomm_encoder *e,
labcomm_signature_t *signature) labcomm_signature_t *signature)
{ {
int i, index; int i, index;
index = get_encoder_index(e, signature); index = get_encoder_index(e, signature);
e->writer.action.start(&e->writer, e, index, signature, NULL); e->writer.action.start(&e->writer, e, index, signature, NULL);
labcomm_encode_packed32(e, signature->type); labcomm_write_packed32(&e->writer, signature->type);
labcomm_encode_packed32(e, index); labcomm_write_packed32(&e->writer, index);
labcomm_encode_string(e, signature->name); labcomm_write_string(&e->writer, signature->name);
for (i = 0 ; i < signature->size ; i++) { for (i = 0 ; i < signature->size ; i++) {
if (e->writer.pos >= e->writer.count) { if (e->writer.pos >= e->writer.count) {
e->writer.action.flush(&e->writer); e->writer.action.flush(&e->writer);
...@@ -406,7 +406,7 @@ int labcomm_internal_encode( ...@@ -406,7 +406,7 @@ int labcomm_internal_encode(
result = e->writer.action.start(&e->writer, e, index, signature, value); result = e->writer.action.start(&e->writer, e, index, signature, value);
if (result == -EALREADY) { result = 0; goto no_end; } if (result == -EALREADY) { result = 0; goto no_end; }
if (result != 0) { goto out; } if (result != 0) { goto out; }
result = labcomm_encode_packed32(e, index); result = labcomm_write_packed32(&e->writer, index);
if (result != 0) { goto out; } if (result != 0) { goto out; }
result = encode(e, value); result = encode(e, value);
out: out:
...@@ -469,36 +469,32 @@ static void collect_flat_signature( ...@@ -469,36 +469,32 @@ static void collect_flat_signature(
labcomm_decoder_t *decoder, labcomm_decoder_t *decoder,
labcomm_encoder_t *signature_writer) labcomm_encoder_t *signature_writer)
{ {
//int type = labcomm_decode_int(decoder); int type = labcomm_read_packed32(&decoder->reader);
int type = labcomm_decode_packed32(decoder);
// printf("%s: type=%x\n", __FUNCTION__, type);
if (type >= LABCOMM_USER) { if (type >= LABCOMM_USER) {
decoder->on_error(LABCOMM_ERROR_UNIMPLEMENTED_FUNC, 3, decoder->on_error(LABCOMM_ERROR_UNIMPLEMENTED_FUNC, 3,
"Implement %s ... (1) for type 0x%x\n", __FUNCTION__, type); "Implement %s ... (1) for type 0x%x\n", __FUNCTION__, type);
} else { } else {
//labcomm_encode_int(signature_writer, type); labcomm_write_packed32(&signature_writer->writer, type);
labcomm_encode_packed32(signature_writer, type);
switch (type) { switch (type) {
case LABCOMM_ARRAY: { case LABCOMM_ARRAY: {
int dimensions, i; int dimensions, i;
dimensions = labcomm_decode_packed32(decoder); //labcomm_decode_int(decoder); //unpack32 dimensions = labcomm_read_packed32(&decoder->reader);
labcomm_encode_packed32(signature_writer, dimensions); //pack32 labcomm_write_packed32(&signature_writer->writer, dimensions);
for (i = 0 ; i < dimensions ; i++) { for (i = 0 ; i < dimensions ; i++) {
int n = labcomm_decode_packed32(decoder); //labcomm_decode_int(decoder); int n = labcomm_read_packed32(&decoder->reader);
labcomm_encode_packed32(signature_writer, n); // labcomm_encode_int(signature_writer, n); labcomm_write_packed32(&signature_writer->writer, n);
} }
collect_flat_signature(decoder, signature_writer); collect_flat_signature(decoder, signature_writer);
} break; } break;
case LABCOMM_STRUCT: { case LABCOMM_STRUCT: {
int fields, i; int fields, i;
//fields = labcomm_decode_int(decoder);
//labcomm_encode_int(signature_writer, fields); fields = labcomm_read_packed32(&decoder->reader);
fields = labcomm_decode_packed32(decoder); labcomm_write_packed32(&signature_writer->writer, fields);
labcomm_encode_packed32(signature_writer, fields);
for (i = 0 ; i < fields ; i++) { for (i = 0 ; i < fields ; i++) {
char *name = labcomm_decode_string(decoder); char *name = labcomm_read_string(&decoder->reader);
labcomm_encode_string(signature_writer, name); labcomm_write_string(&signature_writer->writer, name);
free(name); free(name);
collect_flat_signature(decoder, signature_writer); collect_flat_signature(decoder, signature_writer);
} }
...@@ -580,9 +576,7 @@ int labcomm_decoder_decode_one(labcomm_decoder_t *d) ...@@ -580,9 +576,7 @@ int labcomm_decoder_decode_one(labcomm_decoder_t *d)
if (result > 0) { if (result > 0) {
labcomm_decoder_context_t *context = d->context; labcomm_decoder_context_t *context = d->context;
// printf("do_decode_one: result = %x\n", result); result = labcomm_read_packed32(&d->reader);
result = labcomm_decode_packed32(d);
// printf("do_decode_one: result(2) = %x\n", result);
if (result == LABCOMM_TYPEDEF || result == LABCOMM_SAMPLE) { if (result == LABCOMM_TYPEDEF || result == LABCOMM_SAMPLE) {
/* TODO: should the labcomm_dynamic_buffer_writer be /* TODO: should the labcomm_dynamic_buffer_writer be
a permanent part of labcomm_decoder? */ a permanent part of labcomm_decoder? */
...@@ -592,12 +586,10 @@ int labcomm_decoder_decode_one(labcomm_decoder_t *d) ...@@ -592,12 +586,10 @@ int labcomm_decoder_decode_one(labcomm_decoder_t *d)
labcomm_sample_entry_t *entry = NULL; labcomm_sample_entry_t *entry = NULL;
int index, err; int index, err;
index = labcomm_decode_packed32(d); //int index = labcomm_read_packed32(&d->reader); //int
signature.name = labcomm_decode_string(d); signature.name = labcomm_read_string(&d->reader);
signature.type = result; signature.type = result;
e->writer.action.start(&e->writer, NULL, 0, NULL, NULL); e->writer.action.start(&e->writer, NULL, 0, NULL, NULL);
/* printf("do_decode_one: result = %x, index = %x, name=%s\n",
result, index, signature.name); */
collect_flat_signature(d, e); collect_flat_signature(d, e);
e->writer.action.end(&e->writer); e->writer.action.end(&e->writer);
err = labcomm_encoder_ioctl(e, LABCOMM_IOCTL_WRITER_GET_BYTES_WRITTEN, err = labcomm_encoder_ioctl(e, LABCOMM_IOCTL_WRITER_GET_BYTES_WRITTEN,
......
...@@ -127,7 +127,7 @@ LABCOMM_DECODE(long, long long) ...@@ -127,7 +127,7 @@ LABCOMM_DECODE(long, long long)
LABCOMM_DECODE(float, float) LABCOMM_DECODE(float, float)
LABCOMM_DECODE(double, double) LABCOMM_DECODE(double, double)
static inline unsigned int labcomm_read_unpacked32(labcomm_reader_t *r) static inline unsigned int labcomm_read_packed32(labcomm_reader_t *r)
{ {
unsigned int result = 0; unsigned int result = 0;
...@@ -149,7 +149,7 @@ static inline unsigned int labcomm_read_unpacked32(labcomm_reader_t *r) ...@@ -149,7 +149,7 @@ static inline unsigned int labcomm_read_unpacked32(labcomm_reader_t *r)
static inline unsigned int labcomm_decode_packed32(labcomm_decoder_t *d) static inline unsigned int labcomm_decode_packed32(labcomm_decoder_t *d)
{ {
return labcomm_read_unpacked32(&d->reader); return labcomm_read_packed32(&d->reader);
} }
static inline char *labcomm_read_string(labcomm_reader_t *r) static inline char *labcomm_read_string(labcomm_reader_t *r)
...@@ -157,7 +157,7 @@ static inline char *labcomm_read_string(labcomm_reader_t *r) ...@@ -157,7 +157,7 @@ static inline char *labcomm_read_string(labcomm_reader_t *r)
char *result; char *result;
int length, i; int length, i;
length = labcomm_read_unpacked32(r); length = labcomm_read_packed32(r);
result = malloc(length + 1); result = malloc(length + 1);
for (i = 0 ; i < length ; i++) { for (i = 0 ; i < length ; i++) {
if (r->pos >= r->count) { if (r->pos >= r->count) {
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment