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
gen
gen06
*.pyc
examples/twoway/gen/
lib/csharp/labcomm.dll
lib/java/gen/
lib/java/labcomm*.jar
......@@ -43,11 +43,16 @@ aspect C_CodeGenEnv {
private int indent;
public final int depth;
private C_printer printer;
public final int nestedLevel;
private boolean rootIsPointer;
private int rootLevel;
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.verStr = (version == 2006 ? "2006" : "");
this.verStr = (version == 2006 ? "2006" : "");
this.qualid = qualid;
this.lcName = lcName;
this.rawPrefix = rawPrefix;
......@@ -59,21 +64,28 @@ aspect C_CodeGenEnv {
this.indent = indent;
this.depth = depth;
this.printer = printer;
this.nestedLevel = nestedLevel;
}
public C_env(String qualid, String lcName, String rawPrefix,
PrintStream out, int version) {
this(qualid, lcName, rawPrefix, 0, 0, new C_printer(out), version);
public C_env(String qualid, String lcName, String rawPrefix,
PrintStream out, int 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) {
return new C_env(qualid + suffix, lcName, rawPrefix,
indent, depth + 1, printer, version);
return new C_env(qualid + suffix, lcName, rawPrefix,
indent, depth + 1, printer, nestedLevel + 1, version);
}
public C_env nestStruct(String suffix) {
return new C_env(qualid + suffix, lcName, rawPrefix,
indent, depth, printer, version);
indent, depth, printer, nestedLevel + 1, version);
}
public void indent() {
......@@ -96,6 +108,19 @@ aspect C_CodeGenEnv {
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) {
......@@ -105,7 +130,7 @@ aspect C_CodeGenEnv {
}
public C_env FixedArrayType.C_Nest(C_env env) {
String index = ".a";
String index = env.memberAccessor() + "a";
for (int i = 0 ; i < getNumExp() ; i++) {
index += "[i_" + env.depth + "_" + i + "]";
}
......@@ -113,7 +138,7 @@ aspect C_CodeGenEnv {
}
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 {
env.println("");
// Include
env.println("#include <stdint.h>");
env.println("#include \"labcomm"+env.verStr+".h\"");
for (int i = 0 ; i < includes.size() ; i++) {
env.println("#include \"" + includes.get(i) + "\"");
......@@ -190,6 +214,8 @@ aspect C_CodeGen {
getDecl(i).C_emitDecoderDeclaration(env);
getDecl(i).C_emitEncoderDeclaration(env);
getDecl(i).C_emitSizeofDeclaration(env);
getDecl(i).C_emitCopyDeclaration(env);
getDecl(i).C_emitCopyDeallocationDeclaration(env);
env.println("");
}
C_emitConstructorDeclaration(env);
......@@ -206,6 +232,8 @@ aspect C_CodeGen {
getDecl(i).C_emitEncoderRegisterHandler(env);
getDecl(i).C_emitEncoderIoctl(env);
getDecl(i).C_emitSizeof(env);
getDecl(i).C_emitCopy(env);
getDecl(i).C_emitCopyDeallocation(env);
}
C_emitConstructor(env);
}
......@@ -402,7 +430,7 @@ aspect C_Limit {
}
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 {
}
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 {
public void Decl.C_emitDecoderIoctl(C_env env) {
......
.PHONY: all
all:
echo To be done...
$(MAKE) -C twoway all
......
......@@ -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
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 \
-llabcomm2013 -Tlabcomm.linkscript
gcc -Wall -Werror -I . -I ../../lib/c -L../../lib/c \
......
......@@ -2,7 +2,7 @@ TARGETS=client server
LABCOMM_JAR=../../compiler/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/%)
......
......@@ -26,8 +26,13 @@
#define LABCOMM_VERSION "LabComm2006"
#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_scheduler.h"
......
......@@ -96,7 +96,7 @@ static int fd_fill(struct labcomm2006_reader *r,
int err;
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) {
r->count = 0;
r->error = -EPIPE;
......
......@@ -107,7 +107,7 @@ static int fd_flush(struct labcomm2006_writer *w,
start = 0;
err = 0;
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) {
break;
}
......
......@@ -28,12 +28,12 @@
#else
#include <endian.h>
#include <stdio.h>
#include <stdint.h>
#include <unistd.h>
#endif
#include <stdint.h>
//#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include "labcomm2006.h"
/*
......
......@@ -22,8 +22,12 @@
#ifndef _LABCOMM_SCHEDULER_H_
#define _LABCOMM_SCHEDULER_H_
#include <unistd.h>
#include <stdint.h>
#ifdef LABCOMM_COMPAT
#include LABCOMM_COMPAT
#else
#include <unistd.h>
#include <stdint.h>
#endif
struct labcomm2006_time;
......
## Macros
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)
CC=gcc
CFLAGS=-std=c99 -g -Wall -Werror -O3 -I. -Itest -I2006
CC=$(CROSS_COMPILE)gcc
LD=$(CROSS_COMPILE)ld
LDFLAGS=-L.
LDLIBS=-llabcomm -llabcomm2006 -lrt
MAKESHARED=gcc -o $1 -shared -Wl,-soname,$2 $3 -lc -lrt
else ifeq ($(UNAME_S),Darwin)
CC=clang
CC=$(CROSS_COMPILE)clang
LD=$(CROSS_COMPILE)ld
CFLAGS=-g -Wall -Werror -O3 -I. -Itest \
-DLABCOMM_COMPAT=\"labcomm_compat_osx.h\" \
-Wno-tautological-compare -Wno-unused-function
LDFLAGS=-L.
LDLIBS=-llabcomm -llabcomm2006
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
$(error Unknown system $(UNAME_S))
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 \
2006/labcomm2006_error.o \
2006/labcomm2006_default_error_handler.o \
......@@ -50,6 +67,7 @@ TESTS=test_labcomm_basic_type_encoding test_labcomm_generated_encoding \
test_signature_numbers \
test_labcomm \
test_labcomm_pthread_scheduler \
test_labcomm_copy
#
#FIXME: test_labcomm test_labcomm_errors
TEST_DIR=test
......@@ -69,7 +87,7 @@ endif
.PHONY: all run-test clean distclean
all: liblabcomm.a liblabcomm.so.1 liblabcomm2006.a liblabcomm2006.so.1 liblabcomm2013.a liblabcomm2013.so.1
all: $(ALL_DEPS)
liblabcomm.a: $(OBJS) $(OBJS2006)
ar -r $@ $^
......@@ -150,6 +168,7 @@ clean:
$(RM) test/testdata/gen/*.[cho]
$(RM) test/gen/*.[cho]
$(RM) $(TEST_DIR)/test_labcomm
$(RM) $(TEST_DIR)/test_labcomm_copy
distclean: clean
$(RM) liblabcomm.so.1
......@@ -169,6 +188,7 @@ $(TEST_DIR)/test_signature_numbers.c: $(TEST_DIR)/gen/another_encoding.h
$(TEST_DIR)/test_signature_numbers.c: $(TEST_DIR)/gen/generated_encoding.h
$(TEST_DIR)/test_signature_numbers: $(TEST_DIR)/gen/another_encoding.o
$(TEST_DIR)/test_signature_numbers: $(TEST_DIR)/gen/generated_encoding.o
$(TEST_DIR)/test_labcomm_copy: $(TEST_DIR)/gen/generated_encoding.o $(TEST_DIR)/gen/test_sample.o $(TEST_DIR)/gen/more_types.o
labcomm_fd_reader.o: labcomm_private.h
labcomm_fd_writer.o: labcomm_private.h
labcomm_dynamic_buffer_writer.o: labcomm_private.h
......@@ -246,7 +246,7 @@ void labcomm_set_local_index(struct labcomm_signature *signature)
{
if (signature->index != 0) {
labcomm_error_fatal_global(LABCOMM_ERROR_SIGNATURE_ALREADY_SET,
"%s", signature->name);
"Signature already set: %s\n", signature->name);
}
signature->index = local_index;
local_index++;
......@@ -256,7 +256,7 @@ int labcomm_get_local_index(struct labcomm_signature *signature)
{
if (signature->index == 0) {
labcomm_error_fatal_global(LABCOMM_ERROR_SIGNATURE_NOT_SET,
"%s", signature->name);
"Signature not set: %s\n", signature->name);
}
return signature->index;
}
......@@ -24,8 +24,14 @@
#define _LABCOMM_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 "labcomm_error.h"
#include "labcomm_scheduler.h"
......
#ifndef _LABCOMM_COMPAT_VXWORKS_H_
#define _LABCOMM_COMPAT_VXWORKS_H_
#ifndef __VXWORKS__
#error "__VXWORKS__" not defined
#endif
#include <types/vxTypes.h>
#include <selectLib.h>
#include <types.h>
#include <timers.h>
#include <stdio.h>
#include <private/stdioP.h>
#ifdef __INT64_MAX__
#undef INT64_MAX
#define INT64_MAX __INT64_MAX__
#endif
#if (CPU == PPC603)
#undef _LITTLE_ENDIAN
#endif
......@@ -10,3 +25,6 @@
#undef _BIG_ENDIAN
#endif
extern unsigned int cpuFrequency;
#endif
......@@ -67,6 +67,7 @@ struct labcomm_decoder *labcomm_decoder_new(
result->error = error;
result->memory = memory;
result->scheduler = scheduler;
result->on_error = on_error_fprintf;
LABCOMM_SIGNATURE_ARRAY_INIT(result->local, struct sample_entry);
LABCOMM_SIGNATURE_ARRAY_INIT(result->remote_to_local, int);
}
......@@ -94,7 +95,8 @@ static int collect_flat_signature(
if (result < 0) { goto out; }
if (type >= LABCOMM_USER) {
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 {
labcomm_write_packed32(writer, type);
switch (type) {
......@@ -134,8 +136,9 @@ static int collect_flat_signature(
} break;
default: {