Commit 886380c1 authored by Tommy Olofsson's avatar Tommy Olofsson
Browse files

Merge vx into master.

parents 902a557e df72f303
...@@ -16,3 +16,7 @@ encoded_data06 ...@@ -16,3 +16,7 @@ encoded_data06
gen gen
gen06 gen06
*.pyc *.pyc
examples/twoway/gen/
lib/csharp/labcomm.dll
lib/java/gen/
lib/java/labcomm*.jar
...@@ -43,11 +43,16 @@ aspect C_CodeGenEnv { ...@@ -43,11 +43,16 @@ aspect C_CodeGenEnv {
private int indent; private int indent;
public final int depth; public final int depth;
private C_printer printer; private C_printer printer;
public final int nestedLevel;
private boolean rootIsPointer;
private int rootLevel;
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 nestedLevel, int version)
{
this.version = version; this.version = version;
this.verStr = (version == 2006 ? "2006" : ""); this.verStr = (version == 2006 ? "2006" : "");
this.qualid = qualid; this.qualid = qualid;
this.lcName = lcName; this.lcName = lcName;
this.rawPrefix = rawPrefix; this.rawPrefix = rawPrefix;
...@@ -59,21 +64,28 @@ aspect C_CodeGenEnv { ...@@ -59,21 +64,28 @@ aspect C_CodeGenEnv {
this.indent = indent; this.indent = indent;
this.depth = depth; this.depth = depth;
this.printer = printer; this.printer = printer;
this.nestedLevel = nestedLevel;
} }
public C_env(String qualid, String lcName, String rawPrefix, public C_env(String qualid, String lcName, String rawPrefix,
PrintStream out, int version) { PrintStream out, int version)
this(qualid, lcName, rawPrefix, 0, 0, new C_printer(out), version); {
this(qualid, lcName, rawPrefix, 0, 0, new C_printer(out), 0, version);
}
public C_env(String qualid, String lcName, String rawPrefix,
int indent, int depth, C_printer printer, int version) {
this(qualid, lcName, rawPrefix, indent, depth, printer, 0, version);
} }
public C_env nestArray(String suffix) { public C_env nestArray(String suffix) {
return new C_env(qualid + suffix, lcName, rawPrefix, return new C_env(qualid + suffix, lcName, rawPrefix,
indent, depth + 1, printer, version); indent, depth + 1, printer, nestedLevel + 1, version);
} }
public C_env nestStruct(String suffix) { public C_env nestStruct(String suffix) {
return new C_env(qualid + suffix, lcName, rawPrefix, return new C_env(qualid + suffix, lcName, rawPrefix,
indent, depth, printer, version); indent, depth, printer, nestedLevel + 1, version);
} }
public void indent() { public void indent() {
...@@ -96,6 +108,19 @@ aspect C_CodeGenEnv { ...@@ -96,6 +108,19 @@ aspect C_CodeGenEnv {
printer.println(this, s); printer.println(this, s);
} }
public C_env setPointer() {
rootIsPointer = true;
rootLevel = nestedLevel;
return this;
}
public String memberAccessor() {
return (rootIsPointer && (nestedLevel == rootLevel)) ? "->" : ".";
}
public String accessor() {
return (rootIsPointer && (nestedLevel == rootLevel)) ? "*" : "";
}
} }
public C_env ArrayType.C_Nest(C_env env) { public C_env ArrayType.C_Nest(C_env env) {
...@@ -105,7 +130,7 @@ aspect C_CodeGenEnv { ...@@ -105,7 +130,7 @@ aspect C_CodeGenEnv {
} }
public C_env FixedArrayType.C_Nest(C_env env) { public C_env FixedArrayType.C_Nest(C_env env) {
String index = ".a"; String index = env.memberAccessor() + "a";
for (int i = 0 ; i < getNumExp() ; i++) { for (int i = 0 ; i < getNumExp() ; i++) {
index += "[i_" + env.depth + "_" + i + "]"; index += "[i_" + env.depth + "_" + i + "]";
} }
...@@ -113,7 +138,7 @@ aspect C_CodeGenEnv { ...@@ -113,7 +138,7 @@ aspect C_CodeGenEnv {
} }
public C_env VariableArrayType.C_Nest(C_env env) { public C_env VariableArrayType.C_Nest(C_env env) {
return env.nestArray(".a[i_" + env.depth + "]"); return env.nestArray(env.memberAccessor() + "a[i_" + env.depth + "]");
} }
...@@ -156,7 +181,6 @@ aspect C_CodeGen { ...@@ -156,7 +181,6 @@ aspect C_CodeGen {
env.println(""); env.println("");
// Include // Include
env.println("#include <stdint.h>");
env.println("#include \"labcomm"+env.verStr+".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) + "\"");
...@@ -190,6 +214,8 @@ aspect C_CodeGen { ...@@ -190,6 +214,8 @@ aspect C_CodeGen {
getDecl(i).C_emitDecoderDeclaration(env); getDecl(i).C_emitDecoderDeclaration(env);
getDecl(i).C_emitEncoderDeclaration(env); getDecl(i).C_emitEncoderDeclaration(env);
getDecl(i).C_emitSizeofDeclaration(env); getDecl(i).C_emitSizeofDeclaration(env);
getDecl(i).C_emitCopyDeclaration(env);
getDecl(i).C_emitCopyDeallocationDeclaration(env);
env.println(""); env.println("");
} }
C_emitConstructorDeclaration(env); C_emitConstructorDeclaration(env);
...@@ -206,6 +232,8 @@ aspect C_CodeGen { ...@@ -206,6 +232,8 @@ aspect C_CodeGen {
getDecl(i).C_emitEncoderRegisterHandler(env); getDecl(i).C_emitEncoderRegisterHandler(env);
getDecl(i).C_emitEncoderIoctl(env); getDecl(i).C_emitEncoderIoctl(env);
getDecl(i).C_emitSizeof(env); getDecl(i).C_emitSizeof(env);
getDecl(i).C_emitCopy(env);
getDecl(i).C_emitCopyDeallocation(env);
} }
C_emitConstructor(env); C_emitConstructor(env);
} }
...@@ -402,7 +430,7 @@ aspect C_Limit { ...@@ -402,7 +430,7 @@ aspect C_Limit {
} }
public String VariableSize.C_getLimit(C_env env, int i) { public String VariableSize.C_getLimit(C_env env, int i) {
return env.qualid + ".n_" + i; return env.qualid + env.memberAccessor() + "n_" + i;
} }
} }
...@@ -650,6 +678,263 @@ aspect C_Decoder { ...@@ -650,6 +678,263 @@ aspect C_Decoder {
} }
aspect C_copy {
private void SampleDecl.C_emitCopyFunctionParam(C_env env, String src,
String dst)
{
env.println("void labcomm" + env.verStr + "_copy_" +
env.prefix + getName() + "(");
env.indent();
env.println("struct labcomm" + env.verStr + "_memory *mem,");
env.println(env.prefix + getName() + " *" + dst + ",");
env.println(env.prefix + getName() + " *" + src);
env.unindent();
env.print(")");
}
public void Decl.C_emitCopyDeclaration(C_env env) {
}
public void SampleDecl.C_emitCopyDeclaration(C_env env) {
C_emitCopyFunctionParam(env, "src", "dst");
env.println(";");
}
public void Decl.C_emitCopy(C_env env) {
throw new Error(this.getClass().getName() +
".C_emitCopy(C_env env)" +
" not declared");
}
public void TypeDecl.C_emitCopy(C_env env) {
}
public void SampleDecl.C_emitCopy(C_env env) {
final String dst = "dst";
final String src = "src";
C_env env_src = env.nestStruct(src).setPointer();
C_env env_dst = env.nestStruct(dst).setPointer();
C_emitCopyFunctionParam(env_src, src, dst);
env_src.println("");
env_src.println("{");
env_src.indent();
getType().C_emitCopy(env_src, env_dst);
env_src.unindent();
env_src.println("}");
}
public void Type.C_emitCopy(C_env env_src, C_env env_dst) {
throw new Error(this.getClass().getName() +
".C_emitCopy(C_env env)" +
" not declared");
}
public void VoidType.C_emitCopy(C_env env_src, C_env env_dst) {
}
public void PrimType.C_emitCopy(C_env env_src, C_env env_dst) {
if (C_isDynamic()) {
env_src.println(String.format(
"%s%s = labcomm%s_memory_alloc(mem, 1, strlen(%s%s)+1);",
env_dst.accessor(), env_dst.qualid,
env_src.verStr,
env_src.accessor(), env_src.qualid));
env_src.println(String.format(
"memcpy(%s%s, %s%s, strlen(%s%s)+1);",
env_dst.accessor(), env_dst.qualid,
env_src.accessor(), env_src.qualid,
env_src.accessor(), env_src.qualid));
} else {
env_src.println(env_dst.accessor() + env_dst.qualid + " = " +
env_src.accessor() + env_src.qualid + ";");
}
}
public void UserType.C_emitCopy(C_env env_src, C_env env_dst) {
lookupType(getName()).getType().C_emitCopy(env_src, env_dst);
}
public void StructType.C_emitCopy(C_env env_src, C_env env_dst) {
for (int i = 0 ; i < getNumField() ; i++) {
getField(i).C_emitCopy(env_src, env_dst);
}
}
public void ArrayType.C_emitCopy(C_env env_src, C_env env_dst) {
C_emitCopyDecodeLimit(env_src, env_dst);
C_emitCopyArrayAllocate(env_src, env_dst);
env_src.println("{");
env_src.indent();
C_emitLoopVariables(env_src);
for (int i = 0 ; i < getNumExp() ; i++) {
String iterator = "i_" + env_src.depth + "_" + i;
env_src.println("for (" + iterator + " = 0" +
" ; " +
iterator + " < " + getExp(i).C_getLimit(env_src, i) +
" ; " +
iterator + "++) {");
env_src.indent();
}
C_emitCalcIndex(env_src);
getType().C_emitCopy(C_Nest(env_src), C_Nest(env_dst));
for (int i = getNumExp() - 1 ; i >= 0 ; i--) {
env_src.unindent();
env_src.println("}");
}
env_src.unindent();
env_src.println("}");
}
public void Field.C_emitCopy(C_env env_src, C_env env_dst) {
String fnam = env_src.memberAccessor() + getName();
getType().C_emitCopy(env_src.nestStruct(fnam), env_dst.nestStruct(fnam));
}
public void Exp.C_emitCopyDecodeLimit(C_env env_src, C_env env_dst, int i) {
// Ordinary array has no length-member.
}
public void VariableSize.C_emitCopyDecodeLimit(C_env env_src, C_env env_dst, int i) {
String src = env_src.qualid + env_src.memberAccessor() + "n_" + i;
String dst = env_dst.qualid + env_dst.memberAccessor() + "n_" + i;
env_src.println(dst + " = " + src + ";");
}
public void ArrayType.C_emitCopyDecodeLimit(C_env env_src, C_env env_dst) {
for (int i = 0 ; i < getNumExp() ; i++) {
getExp(i).C_emitCopyDecodeLimit(env_src, env_dst, i);
}
}
public void ArrayType.C_emitCopyArrayAllocate(C_env env_src, C_env env_dst) {
}
public void VariableArrayType.C_emitCopyArrayAllocate(C_env env_src,
C_env env_dst)
{
env_src.print(env_dst.qualid + env_dst.memberAccessor() +
"a = labcomm" + env_src.verStr +
"_memory_alloc(mem, 1, sizeof(" +
env_src.qualid + env_src.memberAccessor() + "a[0])");
for (int i = 0 ; i < getNumExp() ; i++) {
env_src.print(" * " + getExp(i).C_getLimit(env_src, i));
}
env_dst.println(");");
}
// Code for deallocation of dynamically allocated data in a copy.
private void SampleDecl.C_emitCopyDeallocationFunctionParam(C_env env,
String par)
{
env.println("void labcomm" + env.verStr + "_copy_free_" +
env.prefix + getName() + "(");
env.indent();
env.println("struct labcomm" + env.verStr + "_memory *mem,");
env.println(env.prefix + getName() + " *" + par);
env.unindent();
env.print(")");
}
public void Decl.C_emitCopyDeallocationDeclaration(C_env env) {
}
public void SampleDecl.C_emitCopyDeallocationDeclaration(C_env env) {
C_emitCopyDeallocationFunctionParam(env, "c");
env.println(";");
}
public void Decl.C_emitCopyDeallocation(C_env env) {
throw new Error(this.getClass().getName() +
".C_emitCopy(C_env env)" +
" not declared");
}
public void TypeDecl.C_emitCopyDeallocation(C_env env) {
}
public void SampleDecl.C_emitCopyDeallocation(C_env env) {
String par = "par";
env = env.nestStruct(par).setPointer();
C_emitCopyDeallocationFunctionParam(env, par);
env.println("");
env.println("{");
env.indent();
getType().C_emitCopyDeallocation(env);
env.unindent();
env.println("}");
}
public void Type.C_emitCopyDeallocation(C_env env) {
throw new Error(this.getClass().getName() +
".C_emitCopyDeallocation(C_env env)" +
" not declared");
}
public void VoidType.C_emitCopyDeallocation(C_env env) {
}
public void PrimType.C_emitCopyDeallocation(C_env env) {
if (C_isDynamic()) {
env.println("labcomm" + env.verStr + "_memory_free(mem, 1, " +
env.accessor() + env.qualid + ");");
}
}
public void UserType.C_emitCopyDeallocation(C_env env) {
if (C_isDynamic()) {
lookupType(getName()).getType().C_emitCopyDeallocation(env);
}
}
public void StructType.C_emitCopyDeallocation(C_env env) {
if (C_isDynamic()) {
for (int i = 0 ; i < getNumField() ; i++) {
getField(i).C_emitCopyDeallocation(env);
}
}
}
public void ArrayType.C_emitCopyDeallocation(C_env env) {
if (getType().C_isDynamic()) {
env.println("{");
env.indent();
C_emitLoopVariables(env);
for (int i = 0 ; i < getNumExp() ; i++) {
String iterator = "i_" + env.depth + "_" + i;
env.println("for (" + iterator + " = 0" +
" ; " +
iterator + " < " + getExp(i).C_getLimit(env, i) +
" ; " +
iterator + "++) {");
env.indent();
}
C_emitCalcIndex(env);
getType().C_emitCopyDeallocation(C_Nest(env));
for (int i = 0 ; i < getNumExp() ; i++) {
env.unindent();
env.println("}");
}
env.unindent();
env.println("}");
}
}
public void VariableArrayType.C_emitCopyDeallocation(C_env env) {
super.C_emitCopyDeallocation(env);
env.println("labcomm" + env.verStr + "_memory_free(mem, 1, " +
env.qualid + env.memberAccessor() + "a);");
}
public void Field.C_emitCopyDeallocation(C_env env) {
getType().C_emitCopyDeallocation(env.nestStruct(env.memberAccessor()
+ getName()));
}
}
aspect C_DecoderIoctl { aspect C_DecoderIoctl {
public void Decl.C_emitDecoderIoctl(C_env env) { public void Decl.C_emitDecoderIoctl(C_env env) {
......
.PHONY: all .PHONY: all
all: all:
echo To be done... echo To be done...
$(MAKE) -C twoway all $(MAKE) -C twoway all
......
...@@ -9,7 +9,8 @@ java -jar ../../compiler/labComm.jar --java=gen --c=gen/simple.c --h=gen/simple. ...@@ -9,7 +9,8 @@ java -jar ../../compiler/labComm.jar --java=gen --c=gen/simple.c --h=gen/simple.
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 -Wno-unused-function \
-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 \
-llabcomm2013 -Tlabcomm.linkscript -llabcomm2013 -Tlabcomm.linkscript
gcc -Wall -Werror -I . -I ../../lib/c -L../../lib/c \ gcc -Wall -Werror -I . -I ../../lib/c -L../../lib/c \
......
...@@ -2,7 +2,7 @@ TARGETS=client server ...@@ -2,7 +2,7 @@ TARGETS=client server
LABCOMM_JAR=../../compiler/labComm.jar LABCOMM_JAR=../../compiler/labComm.jar
LABCOMM=java -jar $(LABCOMM_JAR) LABCOMM=java -jar $(LABCOMM_JAR)
CFLAGS=-O3 -g -Wall -Werror -I../../lib/c -I. CFLAGS=-O3 -g -Wall -Werror -I../../lib/c -I. -Wno-unused-function
all: $(TARGETS:%=gen/%) all: $(TARGETS:%=gen/%)
......
...@@ -26,8 +26,13 @@ ...@@ -26,8 +26,13 @@
#define LABCOMM_VERSION "LabComm2006" #define LABCOMM_VERSION "LabComm2006"
#include <stdarg.h> #include <stdarg.h>
#include <stdint.h>
#include <unistd.h> #ifdef LABCOMM_COMPAT
#include LABCOMM_COMPAT
#else
#include <stdint.h>
#include <unistd.h>
#endif
#include "labcomm2006_error.h" #include "labcomm2006_error.h"
#include "labcomm2006_scheduler.h" #include "labcomm2006_scheduler.h"
......
...@@ -96,7 +96,7 @@ static int fd_fill(struct labcomm2006_reader *r, ...@@ -96,7 +96,7 @@ static int fd_fill(struct labcomm2006_reader *r,
int err; int err;
r->pos = 0; r->pos = 0;
err = read(fd_reader->fd, r->data, r->data_size); err = read(fd_reader->fd, (char *) r->data, r->data_size);
if (err <= 0) { if (err <= 0) {
r->count = 0; r->count = 0;
r->error = -EPIPE; r->error = -EPIPE;
......
...@@ -107,7 +107,7 @@ static int fd_flush(struct labcomm2006_writer *w, ...@@ -107,7 +107,7 @@ static int fd_flush(struct labcomm2006_writer *w,
start = 0; start = 0;
err = 0; err = 0;
while (start < w->pos) { while (start < w->pos) {
err = write(fd_context->fd, &w->data[start], w->pos - start); err = write(fd_context->fd, (char *) &w->data[start], w->pos - start);
if (err <= 0) { if (err <= 0) {
break; break;
} }
......
...@@ -28,12 +28,12 @@ ...@@ -28,12 +28,12 @@
#else #else
#include <endian.h> #include <endian.h>
#include <stdio.h> #include <stdio.h>
#include <stdint.h>
#include <unistd.h>
#endif #endif
#include <stdint.h>
//#include <stdlib.h> //#include <stdlib.h>
#include <string.h> #include <string.h>
#include <unistd.h>
#include "labcomm2006.h" #include "labcomm2006.h"
/* /*
......
...@@ -22,8 +22,12 @@ ...@@ -22,8 +22,12 @@
#ifndef _LABCOMM_SCHEDULER_H_ #ifndef _LABCOMM_SCHEDULER_H_
#define _LABCOMM_SCHEDULER_H_ #define _LABCOMM_SCHEDULER_H_
#include <unistd.h> #ifdef LABCOMM_COMPAT
#include <stdint.h> #include LABCOMM_COMPAT
#else
#include <unistd.h>
#include <stdint.h>
#endif
struct labcomm2006_time; struct labcomm2006_time;
......
## Macros ## Macros
UNAME_S=$(shell uname -s) UNAME_S=$(shell uname -s)
ALL_DEPS=liblabcomm.a liblabcomm.so.1 liblabcomm2006.a liblabcomm2006.so.1 liblabcomm2013.a liblabcomm2013.so.1
ifeq ($(UNAME_S),Linux) ifeq ($(UNAME_S),Linux)
CC=gcc
CFLAGS=-std=c99 -g -Wall -Werror -O3 -I. -Itest -I2006 CFLAGS=-std=c99 -g -Wall -Werror -O3 -I. -Itest -I2006
CC=$(CROSS_COMPILE)gcc
LD=$(CROSS_COMPILE)ld
LDFLAGS=-L. LDFLAGS=-L.
LDLIBS=-llabcomm -llabcomm2006 -lrt LDLIBS=-llabcomm -llabcomm2006 -lrt
MAKESHARED=gcc -o $1 -shared -Wl,-soname,$2 $3 -lc -lrt MAKESHARED=gcc -o $1 -shared -Wl,-soname,$2 $3 -lc -lrt
else ifeq ($(UNAME_S),Darwin) else ifeq ($(UNAME_S),Darwin)
CC=clang CC=$(CROSS_COMPILE)clang
LD=$(CROSS_COMPILE)ld
CFLAGS=-g -Wall -Werror -O3 -I. -Itest \ CFLAGS=-g -Wall -Werror -O3 -I. -Itest \
-DLABCOMM_COMPAT=\"labcomm_compat_osx.h\" \ -DLABCOMM_COMPAT=\"labcomm_compat_osx.h\" \
-Wno-tautological-compare -Wno-unused-function -Wno-tautological-compare -Wno-unused-function
LDFLAGS=-L. LDFLAGS=-L.
LDLIBS=-llabcomm -llabcomm2006 LDLIBS=-llabcomm -llabcomm2006
MAKESHARED=clang -o $1 -shared -Wl,-install_name,$2 $3 -lc MAKESHARED=clang -o $1 -shared -Wl,-install_name,$2 $3 -lc
else ifneq ($(findstring CYGWIN,$(UNAME_S)),)
CFLAGS=-std=c99 -g -Wall -Werror -O3 -I. -Itest
CC=$(CROSS_COMPILE)gcc
LD=$(CROSS_COMPILE)ld
LDFLAGS=-L.
LDLIBS=-llabcomm -lrt
ALL_DEPS:=$(filter-out %.so.1, $(ALL_DEPS)) # No -fPIC supported in windows?
else else
$(error Unknown system $(UNAME_S)) $(error Unknown system $(UNAME_S))
endif endif
ifeq ($(CROSS_COMPILE),i586-wrs-vxworks-)
ALL_DEPS:=$(filter-out %.so.1, $(ALL_DEPS)) # PIC is only supported for RTPs
CFLAGS:=$(CFLAGS) -DLABCOMM_COMPAT=\"labcomm_compat_vxworks.h\"
endif
# TODO: Support for Codesourcery ARM toolchain.
OBJS2006=2006/labcomm2006_memory.o \ OBJS2006=2006/labcomm2006_memory.o \
2006/labcomm2006_error.o \ 2006/labcomm2006_error.o \
2006/labcomm2006_default_error_handler.o \ 2006/labcomm2006_default_error_handler.o \
...@@ -50,6 +67,7 @@ TESTS=test_labcomm_basic_type_encoding test_labcomm_generated_encoding \ ...@@ -50,6 +67,7 @@ TESTS=test_labcomm_basic_type_encoding test_labcomm_generated_encoding \
test_signature_numbers \ test_signature_numbers \