Commit 6e6d9700 authored by Sven Gestegård Robertz's avatar Sven Gestegård Robertz
Browse files

non-working libc

parent 118fb412
...@@ -34,6 +34,7 @@ aspect C_CodeGenEnv { ...@@ -34,6 +34,7 @@ aspect C_CodeGenEnv {
} }
public final int version; //labcomm version (2006 or 2013) public final int version; //labcomm version (2006 or 2013)
public final String verStr; // version suffix to append (currently _2006 and empty string)
public final String qualid; public final String qualid;
public final String lcName; public final String lcName;
...@@ -46,6 +47,7 @@ aspect C_CodeGenEnv { ...@@ -46,6 +47,7 @@ aspect C_CodeGenEnv {
private C_env(String qualid, String lcName, String rawPrefix, private C_env(String qualid, String lcName, String rawPrefix,
int indent, int depth, C_printer printer, int version) { int indent, int depth, C_printer printer, int version) {
this.version = version; this.version = version;
this.verStr = (version == 2006 ? "2006" : "");
this.qualid = qualid; this.qualid = qualid;
this.lcName = lcName; this.lcName = lcName;
this.rawPrefix = rawPrefix; this.rawPrefix = rawPrefix;
...@@ -155,7 +157,7 @@ aspect C_CodeGen { ...@@ -155,7 +157,7 @@ aspect C_CodeGen {
// Include // Include
env.println("#include <stdint.h>"); env.println("#include <stdint.h>");
env.println("#include \"labcomm.h\""); env.println("#include \"labcomm"+env.verStr+".h\"");
for (int i = 0 ; i < includes.size() ; i++) { for (int i = 0 ; i < includes.size() ; i++) {
env.println("#include \"" + includes.get(i) + "\""); env.println("#include \"" + includes.get(i) + "\"");
} }
...@@ -171,8 +173,8 @@ aspect C_CodeGen { ...@@ -171,8 +173,8 @@ aspect C_CodeGen {
C_env env = new C_env("", lcName, prefix, out, version); C_env env = new C_env("", lcName, prefix, out, version);
// Include // Include
env.println("#include \"labcomm.h\""); env.println("#include \"labcomm"+env.verStr+".h\"");
env.println("#include \"labcomm_private.h\""); env.println("#include \"labcomm"+env.verStr+"_private.h\"");
for (int i = 0 ; i < includes.size() ; i++) { for (int i = 0 ; i < includes.size() ; i++) {
env.println("#include \"" + includes.get(i) + "\""); env.println("#include \"" + includes.get(i) + "\"");
} }
...@@ -334,10 +336,10 @@ aspect C_Declarations { ...@@ -334,10 +336,10 @@ aspect C_Declarations {
} }
public void SampleDecl.C_emitDecoderDeclaration(C_env env) { public void SampleDecl.C_emitDecoderDeclaration(C_env env) {
env.println("int labcomm_decoder_register_" + env.println("int labcomm"+env.verStr+"_decoder_register_" +
env.prefix + getName() + "("); env.prefix + getName() + "(");
env.indent(); env.indent();
env.println("struct labcomm_decoder *d,"); env.println("struct labcomm"+env.verStr+"_decoder *d,");
env.println("void (*handler)("); env.println("void (*handler)(");
env.indent(); env.indent();
env.println(env.prefix + getName() + " *v,"); env.println(env.prefix + getName() + " *v,");
...@@ -348,9 +350,9 @@ aspect C_Declarations { ...@@ -348,9 +350,9 @@ aspect C_Declarations {
env.unindent(); env.unindent();
env.println(");"); env.println(");");
env.println("int labcomm_decoder_ioctl_" + env.prefix + getName() + "("); env.println("int labcomm"+env.verStr+"_decoder_ioctl_" + env.prefix + getName() + "(");
env.indent(); env.indent();
env.println("struct labcomm_decoder *d,"); env.println("struct labcomm"+env.verStr+"_decoder *d,");
env.println("int ioctl_action,"); env.println("int ioctl_action,");
env.println("..."); env.println("...");
env.unindent(); env.unindent();
...@@ -361,22 +363,22 @@ aspect C_Declarations { ...@@ -361,22 +363,22 @@ aspect C_Declarations {
} }
public void SampleDecl.C_emitEncoderDeclaration(C_env env) { public void SampleDecl.C_emitEncoderDeclaration(C_env env) {
env.println("int labcomm_encoder_register_" + env.println("int labcomm"+env.verStr+"_encoder_register_" +
env.prefix + getName() + "("); env.prefix + getName() + "(");
env.indent(); env.indent();
env.println("struct labcomm_encoder *e);"); env.println("struct labcomm"+env.verStr+"_encoder *e);");
env.unindent(); env.unindent();
env.println("int labcomm_encode_" + env.prefix + getName() + "("); env.println("int labcomm"+env.verStr+"_encode_" + env.prefix + getName() + "(");
env.indent(); env.indent();
env.println("struct labcomm_encoder *e,"); env.println("struct labcomm"+env.verStr+"_encoder *e,");
env.println(env.prefix + getName() + " *v"); env.println(env.prefix + getName() + " *v");
env.unindent(); env.unindent();
env.println(");"); env.println(");");
env.println("int labcomm_encoder_ioctl_" + env.prefix + getName() + "("); env.println("int labcomm"+env.verStr+"_encoder_ioctl_" + env.prefix + getName() + "(");
env.indent(); env.indent();
env.println("struct labcomm_encoder *e,"); env.println("struct labcomm"+env.verStr+"_encoder *e,");
env.println("int ioctl_action,"); env.println("int ioctl_action,");
env.println("..."); env.println("...");
env.unindent(); env.unindent();
...@@ -438,7 +440,7 @@ aspect C_Decoder { ...@@ -438,7 +440,7 @@ aspect C_Decoder {
env = env.nestStruct("v"); env = env.nestStruct("v");
env.println("static void decode_" + env.prefix + getName() + "("); env.println("static void decode_" + env.prefix + getName() + "(");
env.indent(); env.indent();
env.println("struct labcomm_reader *r,"); env.println("struct labcomm"+env.verStr+"_reader *r,");
env.println("void (*handle)("); env.println("void (*handle)(");
env.indent(); env.indent();
env.println(env.prefix + getName() + " *v,"); env.println(env.prefix + getName() + " *v,");
...@@ -474,7 +476,7 @@ aspect C_Decoder { ...@@ -474,7 +476,7 @@ aspect C_Decoder {
} }
public void PrimType.C_emitDecoder(C_env env) { public void PrimType.C_emitDecoder(C_env env) {
env.println(env.qualid + " = labcomm_read_" + getName() + "(r);"); env.println(env.qualid + " = labcomm"+env.verStr+"_read_" + getName() + "(r);");
} }
public void UserType.C_emitDecoder(C_env env) { public void UserType.C_emitDecoder(C_env env) {
...@@ -520,7 +522,7 @@ aspect C_Decoder { ...@@ -520,7 +522,7 @@ aspect C_Decoder {
} }
public void VariableSize.C_emitDecoderDecodeLimit(C_env env, int i) { public void VariableSize.C_emitDecoderDecodeLimit(C_env env, int i) {
env.println(env.qualid + ".n_" + i + " = labcomm_read_packed32(r);"); env.println(env.qualid + ".n_" + i + " = labcomm"+env.verStr+"_read_packed32(r);");
} }
public void ArrayType.C_emitDecoderDecodeLimit(C_env env) { public void ArrayType.C_emitDecoderDecodeLimit(C_env env) {
...@@ -534,7 +536,7 @@ aspect C_Decoder { ...@@ -534,7 +536,7 @@ aspect C_Decoder {
public void VariableArrayType.C_emitDecoderArrayAllocate(C_env env) { public void VariableArrayType.C_emitDecoderArrayAllocate(C_env env) {
env.print(env.qualid + env.print(env.qualid +
".a = labcomm_memory_alloc(r->memory, 1, sizeof(" + ".a = labcomm"+env.verStr+"_memory_alloc(r->memory, 1, sizeof(" +
env.qualid + ".a[0])"); env.qualid + ".a[0])");
for (int i = 0 ; i < getNumExp() ; i++) { for (int i = 0 ; i < getNumExp() ; i++) {
env.print(" * " + getExp(i).C_getLimit(env, i)); env.print(" * " + getExp(i).C_getLimit(env, i));
...@@ -552,7 +554,7 @@ aspect C_Decoder { ...@@ -552,7 +554,7 @@ aspect C_Decoder {
public void PrimType.C_emitDecoderDeallocation(C_env env) { public void PrimType.C_emitDecoderDeallocation(C_env env) {
if (C_isDynamic()) { if (C_isDynamic()) {
env.println("labcomm_memory_free(r->memory, 1, " + env.println("labcomm"+env.verStr+"_memory_free(r->memory, 1, " +
env.qualid + ");"); env.qualid + ");");
} }
} }
...@@ -598,7 +600,7 @@ aspect C_Decoder { ...@@ -598,7 +600,7 @@ aspect C_Decoder {
public void VariableArrayType.C_emitDecoderDeallocation(C_env env) { public void VariableArrayType.C_emitDecoderDeallocation(C_env env) {
super.C_emitDecoderDeallocation(env); super.C_emitDecoderDeallocation(env);
env.println("labcomm_memory_free(r->memory, 1, " + env.println("labcomm"+env.verStr+"_memory_free(r->memory, 1, " +
env.qualid + ".a);"); env.qualid + ".a);");
} }
...@@ -616,10 +618,10 @@ aspect C_Decoder { ...@@ -616,10 +618,10 @@ aspect C_Decoder {
} }
public void SampleDecl.C_emitDecoderRegisterHandler(C_env env) { public void SampleDecl.C_emitDecoderRegisterHandler(C_env env) {
env.println("int labcomm_decoder_register_" + env.println("int labcomm"+env.verStr+"_decoder_register_" +
env.prefix + getName() + "("); env.prefix + getName() + "(");
env.indent(); env.indent();
env.println("struct labcomm_decoder *d,"); env.println("struct labcomm"+env.verStr+"_decoder *d,");
env.println("void (*handler)("); env.println("void (*handler)(");
env.indent(); env.indent();
env.println(env.prefix + getName() + " *v,"); env.println(env.prefix + getName() + " *v,");
...@@ -631,12 +633,12 @@ aspect C_Decoder { ...@@ -631,12 +633,12 @@ aspect C_Decoder {
env.println(")"); env.println(")");
env.println("{"); env.println("{");
env.indent(); env.indent();
env.println("return labcomm_internal_decoder_register("); env.println("return labcomm"+env.verStr+"_internal_decoder_register(");
env.indent(); env.indent();
env.println("d,"); env.println("d,");
env.println("&labcomm_signature_" + env.prefix + getName() + ","); env.println("&labcomm"+env.verStr+"_signature_" + env.prefix + getName() + ",");
env.println("(labcomm_decoder_function)decode_" + env.prefix + getName() + ","); env.println("(labcomm"+env.verStr+"_decoder_function)decode_" + env.prefix + getName() + ",");
env.println("(labcomm_handler_function)handler,"); env.println("(labcomm"+env.verStr+"_handler_function)handler,");
env.println("context"); env.println("context");
env.unindent(); env.unindent();
env.println(");"); env.println(");");
...@@ -658,9 +660,9 @@ aspect C_DecoderIoctl { ...@@ -658,9 +660,9 @@ aspect C_DecoderIoctl {
} }
public void SampleDecl.C_emitDecoderIoctl(C_env env) { public void SampleDecl.C_emitDecoderIoctl(C_env env) {
env.println("int labcomm_decoder_ioctl_" + env.prefix + getName() + "("); env.println("int labcomm"+env.verStr+"_decoder_ioctl_" + env.prefix + getName() + "(");
env.indent(); env.indent();
env.println("struct labcomm_decoder *d,"); env.println("struct labcomm"+env.verStr+"_decoder *d,");
env.println("int ioctl_action,"); env.println("int ioctl_action,");
env.println("..."); env.println("...");
env.unindent(); env.unindent();
...@@ -670,9 +672,9 @@ aspect C_DecoderIoctl { ...@@ -670,9 +672,9 @@ aspect C_DecoderIoctl {
env.println("int result;"); env.println("int result;");
env.println("va_list va;"); env.println("va_list va;");
env.println("va_start(va, ioctl_action);"); env.println("va_start(va, ioctl_action);");
env.println("result = labcomm_internal_decoder_ioctl("); env.println("result = labcomm"+env.verStr+"_internal_decoder_ioctl(");
env.indent(); env.indent();
env.println("d, &labcomm_signature_" + env.prefix + getName() + ", "); env.println("d, &labcomm"+env.verStr+"_signature_" + env.prefix + getName() + ", ");
env.println("ioctl_action, va);"); env.println("ioctl_action, va);");
env.unindent(); env.unindent();
env.println("va_end(va);"); env.println("va_end(va);");
...@@ -698,7 +700,7 @@ aspect C_Encoder { ...@@ -698,7 +700,7 @@ aspect C_Encoder {
env = env.nestStruct("(*v)"); env = env.nestStruct("(*v)");
env.println("static int encode_" + env.prefix + getName() + "("); env.println("static int encode_" + env.prefix + getName() + "(");
env.indent(); env.indent();
env.println("struct labcomm_writer *w,"); env.println("struct labcomm"+env.verStr+"_writer *w,");
env.println(env.prefix + getName() + " *v"); env.println(env.prefix + getName() + " *v");
env.unindent(); env.unindent();
env.println(")"); env.println(")");
...@@ -711,16 +713,16 @@ aspect C_Encoder { ...@@ -711,16 +713,16 @@ aspect C_Encoder {
env.println("}"); env.println("}");
// Typesafe encode wrapper // Typesafe encode wrapper
env.println("int labcomm_encode_" + env.prefix + getName() + "("); env.println("int labcomm"+env.verStr+"_encode_" + env.prefix + getName() + "(");
env.println("struct labcomm_encoder *e,"); env.println("struct labcomm"+env.verStr+"_encoder *e,");
env.println(env.prefix + getName() + " *v"); env.println(env.prefix + getName() + " *v");
env.unindent(); env.unindent();
env.println(")"); env.println(")");
env.println("{"); env.println("{");
env.indent(); env.indent();
env.println("return labcomm_internal_encode(e, &labcomm_signature_" + env.println("return labcomm"+env.verStr+"_internal_encode(e, &labcomm"+env.verStr+"_signature_" +
env.prefix + getName() + env.prefix + getName() +
", (labcomm_encoder_function)encode_" + env.prefix + getName() + ", (labcomm"+env.verStr+"_encoder_function)encode_" + env.prefix + getName() +
", v);"); ", v);");
env.unindent(); env.unindent();
env.println("}"); env.println("}");
...@@ -737,7 +739,7 @@ aspect C_Encoder { ...@@ -737,7 +739,7 @@ aspect C_Encoder {
} }
public void PrimType.C_emitEncoder(C_env env) { public void PrimType.C_emitEncoder(C_env env) {
env.println("result = labcomm_write_" + getName() + env.println("result = labcomm"+env.verStr+"_write_" + getName() +
"(w, " + env.qualid + ");"); "(w, " + env.qualid + ");");
env.println("if (result != 0) { return result; }"); env.println("if (result != 0) { return result; }");
} }
...@@ -784,7 +786,7 @@ aspect C_Encoder { ...@@ -784,7 +786,7 @@ aspect C_Encoder {
} }
public void VariableSize.C_emitEncoderEncodeLimit(C_env env, int i) { public void VariableSize.C_emitEncoderEncodeLimit(C_env env, int i) {
env.println("labcomm_write_packed32(w, " + env.qualid + ".n_" + i + ");"); env.println("labcomm"+env.verStr+"_write_packed32(w, " + env.qualid + ".n_" + i + ");");
} }
public void ArrayType.C_emitEncoderEncodeLimit(C_env env) { public void ArrayType.C_emitEncoderEncodeLimit(C_env env) {
...@@ -803,19 +805,19 @@ aspect C_Encoder { ...@@ -803,19 +805,19 @@ aspect C_Encoder {
} }
public void SampleDecl.C_emitEncoderRegisterHandler(C_env env) { public void SampleDecl.C_emitEncoderRegisterHandler(C_env env) {
env.println("int labcomm_encoder_register_" + env.println("int labcomm"+env.verStr+"_encoder_register_" +
env.prefix + getName() + "("); env.prefix + getName() + "(");
env.indent(); env.indent();
env.println("struct labcomm_encoder *e"); env.println("struct labcomm"+env.verStr+"_encoder *e");
env.unindent(); env.unindent();
env.println(")"); env.println(")");
env.println("{"); env.println("{");
env.indent(); env.indent();
env.println("return labcomm_internal_encoder_register("); env.println("return labcomm"+env.verStr+"_internal_encoder_register(");
env.indent(); env.indent();
env.println("e,"); env.println("e,");
env.println("&labcomm_signature_" + env.prefix + getName() + ","); env.println("&labcomm"+env.verStr+"_signature_" + env.prefix + getName() + ",");
env.println("(labcomm_encoder_function)encode_" + env.prefix + getName()); env.println("(labcomm"+env.verStr+"_encoder_function)encode_" + env.prefix + getName());
env.unindent(); env.unindent();
env.println(");"); env.println(");");
env.unindent(); env.unindent();
...@@ -836,9 +838,9 @@ aspect C_EncoderIoctl { ...@@ -836,9 +838,9 @@ aspect C_EncoderIoctl {
} }
public void SampleDecl.C_emitEncoderIoctl(C_env env) { public void SampleDecl.C_emitEncoderIoctl(C_env env) {
env.println("int labcomm_encoder_ioctl_" + env.prefix + getName() + "("); env.println("int labcomm"+env.verStr+"_encoder_ioctl_" + env.prefix + getName() + "(");
env.indent(); env.indent();
env.println("struct labcomm_encoder *e,"); env.println("struct labcomm"+env.verStr+"_encoder *e,");
env.println("int ioctl_action,"); env.println("int ioctl_action,");
env.println("..."); env.println("...");
env.unindent(); env.unindent();
...@@ -848,9 +850,9 @@ aspect C_EncoderIoctl { ...@@ -848,9 +850,9 @@ aspect C_EncoderIoctl {
env.println("int result;"); env.println("int result;");
env.println("va_list va;"); env.println("va_list va;");
env.println("va_start(va, ioctl_action);"); env.println("va_start(va, ioctl_action);");
env.println("result = labcomm_internal_encoder_ioctl("); env.println("result = labcomm"+env.verStr+"_internal_encoder_ioctl(");
env.indent(); env.indent();
env.println("e, &labcomm_signature_" + env.prefix + getName() + ", "); env.println("e, &labcomm"+env.verStr+"_signature_" + env.prefix + getName() + ", ");
env.println("ioctl_action, va);"); env.println("ioctl_action, va);");
env.unindent(); env.unindent();
env.println("va_end(va);"); env.println("va_end(va);");
...@@ -891,11 +893,11 @@ aspect C_Signature { ...@@ -891,11 +893,11 @@ aspect C_Signature {
} }
} }
env.println("};"); env.println("};");
env.println("struct labcomm_signature labcomm_signature_" + env.println("struct labcomm"+env.verStr+"_signature labcomm"+env.verStr+"_signature_" +
env.prefix + getName() + " = {"); env.prefix + getName() + " = {");
env.indent(); env.indent();
env.println("LABCOMM_SAMPLE, \"" + getName() + "\","); env.println("LABCOMM_SAMPLE, \"" + getName() + "\",");
env.println("(int (*)(struct labcomm_signature *, void *))labcomm_sizeof_" + env.println("(int (*)(struct labcomm"+env.verStr+"_signature *, void *))labcomm"+env.verStr+"_sizeof_" +
env.prefix + getName() + ","); env.prefix + getName() + ",");
env.println("sizeof(signature_bytes_" + env.prefix + getName() + "),"); env.println("sizeof(signature_bytes_" + env.prefix + getName() + "),");
env.println("signature_bytes_" + env.prefix + getName() + ","); env.println("signature_bytes_" + env.prefix + getName() + ",");
...@@ -932,7 +934,7 @@ aspect C_Signature { ...@@ -932,7 +934,7 @@ aspect C_Signature {
} }
public void SampleDecl.C_emitConstructor(C_env env) { public void SampleDecl.C_emitConstructor(C_env env) {
env.println("labcomm_set_local_index(&labcomm_signature_" + env.println("labcomm"+env.verStr+"_set_local_index(&labcomm"+env.verStr+"_signature_" +
env.prefix + getName() + ");"); env.prefix + getName() + ");");
} }
...@@ -955,7 +957,7 @@ aspect C_Sizeof { ...@@ -955,7 +957,7 @@ aspect C_Sizeof {
} }
public void SampleDecl.C_emitSizeofDeclaration(C_env env) { public void SampleDecl.C_emitSizeofDeclaration(C_env env) {
env.println("extern int labcomm_sizeof_" + env.prefix + getName() + env.println("extern int labcomm"+env.verStr+"_sizeof_" + env.prefix + getName() +
"(" + env.prefix + getName() + " *v);"); "(" + env.prefix + getName() + " *v);");
} }
...@@ -1016,11 +1018,11 @@ aspect C_Sizeof { ...@@ -1016,11 +1018,11 @@ aspect C_Sizeof {
public void SampleDecl.C_emitSizeof(C_env env) { public void SampleDecl.C_emitSizeof(C_env env) {
env = env.nestStruct("(*v)"); env = env.nestStruct("(*v)");
env.println("int labcomm_sizeof_" + env.prefix + getName() + env.println("int labcomm"+env.verStr+"_sizeof_" + env.prefix + getName() +
"(" + env.prefix + getName() + " *v)"); "(" + env.prefix + getName() + " *v)");
env.println("{"); env.println("{");
env.indent(); env.indent();
env.println("int result = labcomm_size_packed32(labcomm_signature_" + env.println("int result = labcomm"+env.verStr+"_size_packed32(labcomm"+env.verStr+"_signature_" +
env.prefix + getName() +".index);"); env.prefix + getName() +".index);");
if (C_isDynamic()) { if (C_isDynamic()) {
getType().C_emitSizeof(env); getType().C_emitSizeof(env);
...@@ -1094,7 +1096,7 @@ aspect C_Sizeof { ...@@ -1094,7 +1096,7 @@ aspect C_Sizeof {
env.println("}"); env.println("}");
} else { } else {
for (int i = 0 ; i < getNumExp() ; i++) { for (int i = 0 ; i < getNumExp() ; i++) {
env.println("result += labcomm_size_packed32(" + env.println("result += labcomm"+env.verStr+"_size_packed32(" +
getExp(i).C_getLimit(env, i) + ");"); getExp(i).C_getLimit(env, i) + ");");
} }
env.print("result += " + getType().C_fixedSizeof()); env.print("result += " + getType().C_fixedSizeof());
......
(cd ../..; make all) (cd ../..; make all)
mkdir -p gen mkdir -p gen
java -jar ../../compiler/labComm.jar --ver=2013 --java=gen --c=gen/simple.c --h=gen/simple.h --python=gen/simple.py simple.lc java -jar ../../compiler/labComm.jar --ver=2006 --java=gen --c=gen/simple.c --h=gen/simple.h --python=gen/simple.py simple.lc
javac -cp ../../lib/java:. gen/*.java Encoder.java Decoder.java javac -cp ../../lib/java:. gen/*.java Encoder.java Decoder.java
gcc -Wall -Werror -I. -I../../lib/c -L../../lib/c \ # gcc -Wall -Werror -I. -I../../lib/c -L../../lib/c \
-o example_encoder example_encoder.c gen/simple.c \ # -o example_encoder example_encoder.c gen/simple.c \
# -llabcomm -Tlabcomm.linkscript
#gcc -Wall -Werror -I . -I ../../lib/c -L../../lib/c \
# -o example_decoder example_decoder.c gen/simple.c \
# -llabcomm -Tlabcomm.linkscript
gcc -Wall -Werror -I. -I../../lib/c/2006 -L../../lib/c \
-o example_encoder06 example_encoder06.c gen/simple.c \
-llabcomm -Tlabcomm.linkscript -llabcomm -Tlabcomm.linkscript
gcc -Wall -Werror -I . -I ../../lib/c -L../../lib/c \ gcc -Wall -Werror -I . -I ../../lib/c/2006 -L../../lib/c \
-o example_decoder example_decoder.c gen/simple.c \ -o example_decoder06 example_decoder06.c gen/simple.c \
-llabcomm -Tlabcomm.linkscript -llabcomm -Tlabcomm.linkscript
#gcc -o example_encoder -I . -I ../../lib/c example_encoder.c gen/simple.c ../../lib/c/labcomm.c ../../lib/c/labcomm_fd_reader_writer.c #gcc -o example_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 <labcomm2006_fd_reader.h>
#include <labcomm2006_default_error_handler.h>
#include <labcomm2006_default_memory.h>
#include <labcomm2006_default_scheduler.h>
#include "gen/simple.h"
#include <stdio.h>
static void handle_simple_theTwoInts(simple_TwoInts *v,void *context) {
printf("Got theTwoInts. a=%d, b=%d\n", v->a, v->b);
}
static void handle_simple_anotherTwoInts(simple_TwoInts *v,void *context) {
printf("Got anotherTwoInts. a=%d, b=%d\n", v->a, v->b);
}
static void handle_simple_IntString(simple_IntString *v,void *context) {
printf("Got IntString. x=%d, s=%s\n", v->x, v->s);
}
static void handle_simple_TwoArrays(simple_TwoArrays *d,void *context) {
printf("Got TwoArrays:");
int i,j;
for(i=0; i<2; i++) {
printf("%d ",d->fixed.a[i]);
}
printf("\n");
for(i=0; i<2; i++) {
for(j=0; j<d->variable.n_1; j++) {
printf("%d ",d->variable.a[i *d->variable.n_1 + j]);
}
printf("\n");
}
printf("\n");
}
static void handle_simple_TwoFixedArrays(simple_TwoFixedArrays *d,void *context) {
printf("Got TwoFixedArrays:");
int i,j;
for(i=0; i<2; i++) {
printf("%d ",d->a.a[i]);
}
printf("\n");
for(i=0; i<2; i++) {
for(j=0; j<3; j++) {
printf("%d ",d->b.a[i][j]);
}
printf("\n");
}
}
int main(int argc, char *argv[]) {
int fd;
struct labcomm2006_decoder *decoder;
void *context = NULL;
char *filename = argv[1];
printf("C decoder reading from %s\n", filename);
fd = open(filename, O_RDONLY);
decoder = labcomm2006_decoder_new(labcomm2006_fd_reader_new(
labcomm2006_default_memory, fd, 1),
labcomm2006_default_error_handler,
labcomm2006_default_memory,
labcomm2006_default_scheduler);
if (!decoder) {
printf("Failed to allocate decoder %s:%d\n", __FUNCTION__, __LINE__);
return 1;
}
labcomm2006_decoder_register_simple_theTwoInts(decoder, handle_simple_theTwoInts, context);
labcomm2006_decoder_register_simple_anotherTwoInts(decoder, handle_simple_anotherTwoInts, context);
labcomm2006_decoder_register_simple_IntString(decoder, handle_simple_IntString, context);
labcomm2006_decoder_register_simple_TwoArrays(decoder, handle_simple_TwoArrays, context);
labcomm2006_decoder_register_simple_TwoFixedArrays(decoder, handle_simple_TwoFixedArrays, context);
printf("Decoding:\n");
labcomm2006_decoder_run(decoder);
printf("--- End Of File ---:\n");
labcomm2006_decoder_free(decoder);
return 0;
}
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <labcomm2006_fd_writer.h>
#include <labcomm2006_default_error_handler.h>
#include <labcomm2006_default_memory.h>
#include <labcomm2006_default_scheduler.h>
#include "gen/simple.h"
#include <stdio.h>
int main(int argc, char *argv[]) {
int fd;
struct labcomm2006_encoder *encoder;
char *filename = argv[1];
printf("C encoder writing to %s\n", filename);
fd = open(filename, O_WRONLY|O_CREAT|O_TRUNC, 0644);
encoder = labcomm2006_encoder_new(labcomm2006_fd_writer_new(
labcomm2006_default_memory, fd, 1),
labcomm2006_default_error_handler,
labcomm2006_default_memory,
labcomm2006_default_scheduler);
labcomm2006_encoder_register_simple_theTwoInts(encoder);
labcomm2006_encoder_register_simple_anotherTwoInts(encoder);
labcomm2006_encoder_register_simple_IntString(encoder);
simple_IntString is;