Commit ca5b4caf authored by Sven Robertz's avatar Sven Robertz
Browse files

added C encoder

parent 38464828
java -jar ../../labComm.jar --java=gen simple.lc
java -jar ../../labComm.jar --java=gen --c=gen/simple.c --h=gen/simple.h simple.lc
javac -cp ../../lib/java:. gen/*.java Encoder.java Decoder.java
gcc -o encoder -I . -I ../../lib/c example_encoder.c gen/simple.c ../../lib/c/labcomm.c ../../lib/c/labcomm_fd_reader_writer.c
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <labcomm_fd_reader_writer.h>
#include "gen/simple.h"
int main(int argc, char *argv[]) {
int fd;
struct labcomm_encoder *encoder;
int i, j;
char *filename = argv[1];
printf("C encoder writing to %s\n", filename);
fd = open(filename, O_WRONLY|O_CREAT|O_TRUNC, 0644);
encoder = labcomm_encoder_new(labcomm_fd_writer, &fd);
labcomm_encoder_register_simple_TwoInts(encoder);
labcomm_encoder_register_simple_IntString(encoder);
simple_IntString is;
is.x = 24;
is.s = "Hello, LabComm!";
labcomm_encode_simple_IntString(encoder, &is);
simple_TwoInts ti;
ti.a = 13;
ti.b = 37;
labcomm_encode_simple_TwoInts(encoder, &ti);
}
This diff is collapsed.
/* LabComm declarations:
typedef int int_array_ss[1][_, 3, _][5];
sample struct {
int aa;
boolean bb;
int_array_ss ias;
} struct_array_ss[1][_][_];
typedef int int_t;
typedef int int_array_t[1][2][3, 4];
typedef struct {
int a;
} struct_t;
typedef struct {
int a;
} struct_array_t[2];
typedef struct {
struct {
int a;
} a;
} struct_struct_t;
sample int int_s;
sample int int_array_s[1][_, 3, _][5];
sample struct {
int a;
double bcd;
} struct_s;
sample struct {
int a;
} struct_array_s[2];
sample struct {
struct {
int a;
} a;
} struct_struct_s;
sample int_t int_t_s;
sample int_array_t int_array_t_s;
sample struct_t struct_t_s;
sample struct_array_t struct_array_t_s;
sample struct_struct_t struct_struct_t_s;
*/
#ifndef __LABCOMM_nested_H__
#define __LABCOMM_nested_H__
#include "labcomm.h"
#ifndef PREDEFINED_nested_int_array_ss
typedef struct {
struct {
int n_0;
// n_1=3
int n_2;
struct {
int a[5];
} *a;
} a[1];
} nested_int_array_ss;
#endif
#ifndef PREDEFINED_nested_struct_array_ss
typedef struct {
struct {
int n_0;
struct {
int n_0;
struct {
int aa;
unsigned char bb;
nested_int_array_ss ias;
} *a;
} *a;
} a[1];
} nested_struct_array_ss;
#endif
void labcomm_decoder_register_nested_struct_array_ss(
struct labcomm_decoder *d,
void (*handler)(
nested_struct_array_ss *v,
void *context
),
void *context
);
void labcomm_encoder_register_nested_struct_array_ss(
struct labcomm_encoder *e);
void labcomm_encode_nested_struct_array_ss(
struct labcomm_encoder *e,
nested_struct_array_ss *v
);
extern int labcomm_sizeof_nested_struct_array_ss(nested_struct_array_ss *v);
#ifndef PREDEFINED_nested_int_t
typedef int nested_int_t;
#endif
#ifndef PREDEFINED_nested_int_array_t
typedef struct {
struct {
struct {
int a[3][4];
} a[2];
} a[1];
} nested_int_array_t;
#endif
#ifndef PREDEFINED_nested_struct_t
typedef struct {
int a;
} nested_struct_t;
#endif
#ifndef PREDEFINED_nested_struct_array_t
typedef struct {
struct {
int a;
} a[2];
} nested_struct_array_t;
#endif
#ifndef PREDEFINED_nested_struct_struct_t
typedef struct {
struct {
int a;
} a;
} nested_struct_struct_t;
#endif
#ifndef PREDEFINED_nested_int_s
typedef int nested_int_s;
#endif
void labcomm_decoder_register_nested_int_s(
struct labcomm_decoder *d,
void (*handler)(
nested_int_s *v,
void *context
),
void *context
);
void labcomm_encoder_register_nested_int_s(
struct labcomm_encoder *e);
void labcomm_encode_nested_int_s(
struct labcomm_encoder *e,
nested_int_s *v
);
extern int labcomm_sizeof_nested_int_s(nested_int_s *v);
#ifndef PREDEFINED_nested_int_array_s
typedef struct {
struct {
int n_0;
// n_1=3
int n_2;
struct {
int a[5];
} *a;
} a[1];
} nested_int_array_s;
#endif
void labcomm_decoder_register_nested_int_array_s(
struct labcomm_decoder *d,
void (*handler)(
nested_int_array_s *v,
void *context
),
void *context
);
void labcomm_encoder_register_nested_int_array_s(
struct labcomm_encoder *e);
void labcomm_encode_nested_int_array_s(
struct labcomm_encoder *e,
nested_int_array_s *v
);
extern int labcomm_sizeof_nested_int_array_s(nested_int_array_s *v);
#ifndef PREDEFINED_nested_struct_s
typedef struct {
int a;
double bcd;
} nested_struct_s;
#endif
void labcomm_decoder_register_nested_struct_s(
struct labcomm_decoder *d,
void (*handler)(
nested_struct_s *v,
void *context
),
void *context
);
void labcomm_encoder_register_nested_struct_s(
struct labcomm_encoder *e);
void labcomm_encode_nested_struct_s(
struct labcomm_encoder *e,
nested_struct_s *v
);
extern int labcomm_sizeof_nested_struct_s(nested_struct_s *v);
#ifndef PREDEFINED_nested_struct_array_s
typedef struct {
struct {
int a;
} a[2];
} nested_struct_array_s;
#endif
void labcomm_decoder_register_nested_struct_array_s(
struct labcomm_decoder *d,
void (*handler)(
nested_struct_array_s *v,
void *context
),
void *context
);
void labcomm_encoder_register_nested_struct_array_s(
struct labcomm_encoder *e);
void labcomm_encode_nested_struct_array_s(
struct labcomm_encoder *e,
nested_struct_array_s *v
);
extern int labcomm_sizeof_nested_struct_array_s(nested_struct_array_s *v);
#ifndef PREDEFINED_nested_struct_struct_s
typedef struct {
struct {
int a;
} a;
} nested_struct_struct_s;
#endif
void labcomm_decoder_register_nested_struct_struct_s(
struct labcomm_decoder *d,
void (*handler)(
nested_struct_struct_s *v,
void *context
),
void *context
);
void labcomm_encoder_register_nested_struct_struct_s(
struct labcomm_encoder *e);
void labcomm_encode_nested_struct_struct_s(
struct labcomm_encoder *e,
nested_struct_struct_s *v
);
extern int labcomm_sizeof_nested_struct_struct_s(nested_struct_struct_s *v);
#ifndef PREDEFINED_nested_int_t_s
typedef nested_int_t nested_int_t_s;
#endif
void labcomm_decoder_register_nested_int_t_s(
struct labcomm_decoder *d,
void (*handler)(
nested_int_t_s *v,
void *context
),
void *context
);
void labcomm_encoder_register_nested_int_t_s(
struct labcomm_encoder *e);
void labcomm_encode_nested_int_t_s(
struct labcomm_encoder *e,
nested_int_t_s *v
);
extern int labcomm_sizeof_nested_int_t_s(nested_int_t_s *v);
#ifndef PREDEFINED_nested_int_array_t_s
typedef nested_int_array_t nested_int_array_t_s;
#endif
void labcomm_decoder_register_nested_int_array_t_s(
struct labcomm_decoder *d,
void (*handler)(
nested_int_array_t_s *v,
void *context
),
void *context
);
void labcomm_encoder_register_nested_int_array_t_s(
struct labcomm_encoder *e);
void labcomm_encode_nested_int_array_t_s(
struct labcomm_encoder *e,
nested_int_array_t_s *v
);
extern int labcomm_sizeof_nested_int_array_t_s(nested_int_array_t_s *v);
#ifndef PREDEFINED_nested_struct_t_s
typedef nested_struct_t nested_struct_t_s;
#endif
void labcomm_decoder_register_nested_struct_t_s(
struct labcomm_decoder *d,
void (*handler)(
nested_struct_t_s *v,
void *context
),
void *context
);
void labcomm_encoder_register_nested_struct_t_s(
struct labcomm_encoder *e);
void labcomm_encode_nested_struct_t_s(
struct labcomm_encoder *e,
nested_struct_t_s *v
);
extern int labcomm_sizeof_nested_struct_t_s(nested_struct_t_s *v);
#ifndef PREDEFINED_nested_struct_array_t_s
typedef nested_struct_array_t nested_struct_array_t_s;
#endif
void labcomm_decoder_register_nested_struct_array_t_s(
struct labcomm_decoder *d,
void (*handler)(
nested_struct_array_t_s *v,
void *context
),
void *context
);
void labcomm_encoder_register_nested_struct_array_t_s(
struct labcomm_encoder *e);
void labcomm_encode_nested_struct_array_t_s(
struct labcomm_encoder *e,
nested_struct_array_t_s *v
);
extern int labcomm_sizeof_nested_struct_array_t_s(nested_struct_array_t_s *v);
#ifndef PREDEFINED_nested_struct_struct_t_s
typedef nested_struct_struct_t nested_struct_struct_t_s;
#endif
void labcomm_decoder_register_nested_struct_struct_t_s(
struct labcomm_decoder *d,
void (*handler)(
nested_struct_struct_t_s *v,
void *context
),
void *context
);
void labcomm_encoder_register_nested_struct_struct_t_s(
struct labcomm_encoder *e);
void labcomm_encode_nested_struct_struct_t_s(
struct labcomm_encoder *e,
nested_struct_struct_t_s *v
);
extern int labcomm_sizeof_nested_struct_struct_t_s(nested_struct_struct_t_s *v);
#define LABCOMM_FORALL_SAMPLES_nested(func, sep) \
func(struct_array_ss, nested_struct_array_ss) sep \
func(int_s, nested_int_s) sep \
func(int_array_s, nested_int_array_s) sep \
func(struct_s, nested_struct_s) sep \
func(struct_array_s, nested_struct_array_s) sep \
func(struct_struct_s, nested_struct_struct_s) sep \
func(int_t_s, nested_int_t_s) sep \
func(int_array_t_s, nested_int_array_t_s) sep \
func(struct_t_s, nested_struct_t_s) sep \
func(struct_array_t_s, nested_struct_array_t_s) sep \
func(struct_struct_t_s, nested_struct_struct_t_s)
#endif
This diff is collapsed.
/* LabComm declarations:
sample int an_int;
sample int a_fixed_int_array[2];
sample int a_fixed_int_multi_array[2, 2, 2];
sample int a_fixed_int_array_array_array[2][2][2];
sample int a_variable_int_array[_];
sample int a_variable_int_multi_array[_, _, _];
sample int a_variable_int_array_array_array[_][_][_];
sample struct {
int a;
int b;
} an_int_struct;
sample void a_void;
*/
#ifndef __LABCOMM_simple_H__
#define __LABCOMM_simple_H__
#include "labcomm.h"
#ifndef PREDEFINED_simple_an_int
typedef int simple_an_int;
#endif
void labcomm_decoder_register_simple_an_int(
struct labcomm_decoder *d,
void (*handler)(
simple_an_int *v,
void *context
),
void *context
);
void labcomm_encoder_register_simple_an_int(
struct labcomm_encoder *e);
void labcomm_encode_simple_an_int(
struct labcomm_encoder *e,
simple_an_int *v
);
extern int labcomm_sizeof_simple_an_int(simple_an_int *v);
#ifndef PREDEFINED_simple_a_fixed_int_array
typedef struct {
int a[2];
} simple_a_fixed_int_array;
#endif
void labcomm_decoder_register_simple_a_fixed_int_array(
struct labcomm_decoder *d,
void (*handler)(
simple_a_fixed_int_array *v,
void *context
),
void *context
);
void labcomm_encoder_register_simple_a_fixed_int_array(
struct labcomm_encoder *e);
void labcomm_encode_simple_a_fixed_int_array(
struct labcomm_encoder *e,
simple_a_fixed_int_array *v
);
extern int labcomm_sizeof_simple_a_fixed_int_array(simple_a_fixed_int_array *v);
#ifndef PREDEFINED_simple_a_fixed_int_multi_array
typedef struct {
int a[2][2][2];
} simple_a_fixed_int_multi_array;
#endif
void labcomm_decoder_register_simple_a_fixed_int_multi_array(
struct labcomm_decoder *d,
void (*handler)(
simple_a_fixed_int_multi_array *v,
void *context
),
void *context
);
void labcomm_encoder_register_simple_a_fixed_int_multi_array(
struct labcomm_encoder *e);
void labcomm_encode_simple_a_fixed_int_multi_array(
struct labcomm_encoder *e,
simple_a_fixed_int_multi_array *v
);
extern int labcomm_sizeof_simple_a_fixed_int_multi_array(simple_a_fixed_int_multi_array *v);
#ifndef PREDEFINED_simple_a_fixed_int_array_array_array
typedef struct {
struct {
struct {
int a[2];
} a[2];
} a[2];
} simple_a_fixed_int_array_array_array;
#endif
void labcomm_decoder_register_simple_a_fixed_int_array_array_array(
struct labcomm_decoder *d,
void (*handler)(
simple_a_fixed_int_array_array_array *v,
void *context
),
void *context
);
void labcomm_encoder_register_simple_a_fixed_int_array_array_array(
struct labcomm_encoder *e);
void labcomm_encode_simple_a_fixed_int_array_array_array(
struct labcomm_encoder *e,
simple_a_fixed_int_array_array_array *v
);
extern int labcomm_sizeof_simple_a_fixed_int_array_array_array(simple_a_fixed_int_array_array_array *v);
#ifndef PREDEFINED_simple_a_variable_int_array
typedef struct {
int n_0;
int *a;
} simple_a_variable_int_array;
#endif
void labcomm_decoder_register_simple_a_variable_int_array(
struct labcomm_decoder *d,
void (*handler)(
simple_a_variable_int_array *v,
void *context
),
void *context
);
void labcomm_encoder_register_simple_a_variable_int_array(
struct labcomm_encoder *e);
void labcomm_encode_simple_a_variable_int_array(
struct labcomm_encoder *e,
simple_a_variable_int_array *v
);
extern int labcomm_sizeof_simple_a_variable_int_array(simple_a_variable_int_array *v);
#ifndef PREDEFINED_simple_a_variable_int_multi_array
typedef struct {
int n_0;
int n_1;
int n_2;
int *a;
} simple_a_variable_int_multi_array;
#endif
void labcomm_decoder_register_simple_a_variable_int_multi_array(
struct labcomm_decoder *d,
void (*handler)(
simple_a_variable_int_multi_array *v,
void *context
),
void *context
);
void labcomm_encoder_register_simple_a_variable_int_multi_array(
struct labcomm_encoder *e);
void labcomm_encode_simple_a_variable_int_multi_array(
struct labcomm_encoder *e,
simple_a_variable_int_multi_array *v
);
extern int labcomm_sizeof_simple_a_variable_int_multi_array(simple_a_variable_int_multi_array *v);
#ifndef PREDEFINED_simple_a_variable_int_array_array_array
typedef struct {
int n_0;
struct {
int n_0;
struct {
int n_0;
int *a;
} *a;
} *a;
} simple_a_variable_int_array_array_array;
#endif
void labcomm_decoder_register_simple_a_variable_int_array_array_array(
struct labcomm_decoder *d,
void (*handler)(
simple_a_variable_int_array_array_array *v,
void *context
),
void *context
);
void labcomm_encoder_register_simple_a_variable_int_array_array_array(
struct labcomm_encoder *e);
void labcomm_encode_simple_a_variable_int_array_array_array(
struct labcomm_encoder *e,
simple_a_variable_int_array_array_array *v
);
extern int labcomm_sizeof_simple_a_variable_int_array_array_array(simple_a_variable_int_array_array_array *v);
#ifndef PREDEFINED_simple_an_int_struct
typedef struct {
int a;
int b;
} simple_an_int_struct;
#endif
void labcomm_decoder_register_simple_an_int_struct(
struct labcomm_decoder *d,
void (*handler)(
simple_an_int_struct *v,
void *context
),
void *context
);
void labcomm_encoder_register_simple_an_int_struct(
struct labcomm_encoder *e);
void labcomm_encode_simple_an_int_struct(
struct labcomm_encoder *e,
simple_an_int_struct *v
);
extern int labcomm_sizeof_simple_an_int_struct(simple_an_int_struct *v);
#ifndef PREDEFINED_simple_a_void
typedef char simple_a_void;
#endif
void labcomm_decoder_register_simple_a_void(
struct labcomm_decoder *d,
void (*handler)(
simple_a_void *v,
void *context
),
void *context
);
void labcomm_encoder_register_simple_a_void(
struct labcomm_encoder *e);
void labcomm_encode_simple_a_void(
struct labcomm_encoder *e,
simple_a_void *v
);
extern int labcomm_sizeof_simple_a_void(simple_a_void *v);
#define LABCOMM_FORALL_SAMPLES_simple(func, sep) \
func(an_int, simple_an_int) sep \
func(a_fixed_int_array, simple_a_fixed_int_array) sep \
func(a_fixed_int_multi_array, simple_a_fixed_int_multi_array) sep \
func(a_fixed_int_array_array_array, simple_a_fixed_int_array_array_array) sep \
func(a_variable_int_array, simple_a_variable_int_array) sep \
func(a_variable_int_multi_array, simple_a_variable_int_multi_array) sep \
func(a_variable_int_array_array_array, simple_a_variable_int_array_array_array) sep \
func(an_int_struct, simple_an_int_struct) sep \
func(a_void, simple_a_void)
#endif
This diff is collapsed.
using System;
using se.lth.control.labcomm;
/*
sample int an_int;
*/
public class an_int : LabCommSample {