Commit b63cf3bb authored by Anders Blomdell's avatar Anders Blomdell
Browse files

Major C-code reshuffle.

parent ddb59c80
......@@ -10,14 +10,16 @@ lib/c/liblabcomm2006.a
lib/c/liblabcomm2014.so.1
lib/c/liblabcomm2014.so
lib/c/liblabcomm2014.a
lib/c/test/test_labcomm
lib/c/test/test_labcomm_basic_type_encoding
lib/c/test/test_labcomm_copy
lib/c/test/test_labcomm_generated_encoding
lib/c/test/test_labcomm_pthread_scheduler
lib/c/test/test_signature_numbers
lib/c/20*/test/test_labcomm
lib/c/20*/test/test_labcomm_basic_type_encoding
lib/c/20*/test/test_labcomm_copy
lib/c/20*/test/test_labcomm_generated_encoding
lib/c/20*/test/test_labcomm_pthread_scheduler
lib/c/20*/test/test_signature_numbers
compiler/AST/
compiler/labcomm_compiler.jar
compiler/labcomm2006_compiler.jar
compiler/labcomm2014_compiler.jar
encoded_data
encoded_data06
gen
......
......@@ -339,11 +339,6 @@ aspect Java_Class {
env.println("e.register(dispatcher);");
env.unindent();
env.println("}");
env.println("public static void registerSampleRef(Encoder e) throws IOException{");
env.indent();
env.println("e.registerSampleRef(dispatcher);");
env.unindent();
env.println("}");
env.println();
}
......@@ -435,11 +430,6 @@ aspect Java_Class {
env.println("d.register(dispatcher, h);");
env.unindent();
env.println("}");
env.println("public static void registerSampleRef(Decoder d) throws IOException {");
env.indent();
env.println("d.registerSampleRef(dispatcher);");
env.unindent();
env.println("}");
env.println();
......@@ -652,7 +642,6 @@ aspect Java_Class {
case LABCOMM_FLOAT: { env.print("e.encodeFloat"); } break;
case LABCOMM_DOUBLE: { env.print("e.encodeDouble"); } break;
case LABCOMM_STRING: { env.print("e.encodeString"); } break;
case LABCOMM_SAMPLE: { env.print("e.encodeSampleRef"); } break;
}
env.println("(" + name + ");");
}
......@@ -743,7 +732,6 @@ aspect Java_Class {
case LABCOMM_FLOAT: { env.println("d.decodeFloat();"); } break;
case LABCOMM_DOUBLE: { env.println("d.decodeDouble();"); } break;
case LABCOMM_STRING: { env.println("d.decodeString();"); } break;
case LABCOMM_SAMPLE: { env.println("d.decodeSampleRef();"); } break;
}
}
......
......@@ -127,7 +127,7 @@ public class LabComm {
String coreName = null;
String prefix = null;
boolean verbose = false;
int ver = 2013; //Version 2013 as default
int ver = 2006; // Version 2006 fixed
String cFile = null;
String hFile = null;
Vector cIncludes = new Vector();
......@@ -192,8 +192,8 @@ public class LabComm {
} else if (args[i].equals("-v")) {
verbose=true;
} else if (args[i].startsWith("--ver=")) {
ver = Integer.parseInt(args[i].substring(6));
checkVersion(ver);
/* ver = Integer.parseInt(args[i].substring(6));
checkVersion(ver); */
} else if (args[i].equals("-C")) {
cFile = coreName + ".c";
hFile = coreName + ".h";
......
......@@ -53,8 +53,25 @@
<delete dir="${package}"/>
</target>
<target name="jar_version" depends="build">
<jar destfile="labcomm${version}_compiler.jar">
<fileset dir="gen"
includes="se/lth/control/labcomm${version}/compiler/*.class"/>
<zipfileset src="tools/beaver-rt.jar" includes="beaver/*.class"/>
<manifest>
<attribute name="Main-Class"
value="se.lth.control.labcomm${version}.compiler.LabComm"/>
</manifest>
</jar>
</target>
<target name="jar" depends="build">
<antcall target="jar_version">
<param name="version" value="2006"/>
</antcall>
<antcall target="jar_version">
<param name="version" value="2014"/>
</antcall>
<jar destfile="labcomm_compiler.jar">
<fileset dir="gen" includes="**/*.class"/>
<zipfileset src="tools/beaver-rt.jar" includes="beaver/*.class"/>
......
#!/bin/sh
set -x
set -e
### Example compile script, showing the steps required to build a labcomm application
### (including compiler and libs). Also illustrates how versions 2013 and 2006 coexist
......@@ -10,12 +13,12 @@ java -jar ../../compiler/labcomm_compiler.jar --java=gen --c=gen/simple.c --h=ge
javac -cp ../../lib/java/labcomm2014.jar:. gen/*.java Encoder.java Decoder.java
gcc -Wall -Werror -Wno-unused-function \
-I. -I../../lib/c -L../../lib/c \
-I. -I../../lib/c/2014 -L../../lib/c \
-o example_encoder example_encoder.c gen/simple.c \
-llabcomm2014 -Tlabcomm.linkscript
gcc -Wall -Werror -I . -I ../../lib/c -L../../lib/c \
-llabcomm2014
gcc -Wall -Werror -I . -I ../../lib/c/2014 -L../../lib/c \
-o example_decoder example_decoder.c gen/simple.c \
-llabcomm2014 -Tlabcomm.linkscript
-llabcomm2014
# For version 2006
......@@ -26,10 +29,10 @@ javac -cp ../../lib/java/labcomm2006.jar:. gen06/*.java Encoder06.java Decoder06
gcc -Wall -Werror -I. -I../../lib/c/2006 -L../../lib/c \
-o example_encoder06 example_encoder06.c gen06/simple.c \
-llabcomm -Tlabcomm.linkscript
-llabcomm2006
gcc -Wall -Werror -I . -I ../../lib/c/2006 -L../../lib/c \
-o example_decoder06 example_decoder06.c gen06/simple.c \
-llabcomm -Tlabcomm.linkscript
-llabcomm2006
#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
......
......@@ -2,7 +2,7 @@ TARGETS=client server
LABCOMM_JAR=../../compiler/labcomm_compiler.jar
LABCOMM=java -jar $(LABCOMM_JAR)
CFLAGS=-O3 -g -Wall -Werror -I../../lib/c -I. -Wno-unused-function
CFLAGS=-O3 -g -Wall -Werror -I../../lib/c/2014 -I. -Wno-unused-function
all: $(TARGETS:%=gen/%)
......@@ -26,11 +26,11 @@ gen/%.c gen/%.h: %.lc | gen/.dir
gen/client: client.c
$(CC) -o $@ $(CFLAGS) $^ -lpthread \
-L../../lib/c -llabcomm
-L../../lib/c -llabcomm2014
gen/server: server.c
$(CC) -o $@ $(CFLAGS) $^ -lpthread \
-L../../lib/c -llabcomm
-L../../lib/c -llabcomm2014
.PHONY: clean distclean
clean distclean:
......
......@@ -4,7 +4,7 @@ all:
cd java ; make
test:
$(MAKE) -C c -e run-test
$(MAKE) -C c test
clean:
cd c ; make clean
......
## Macros
VERSION=2006
LIBVERSION=2006
include ../os_compat.mk
ALL_DEPS=../liblabcomm$(LIBVERSION).a ../liblabcomm$(LIBVERSION).so.1
# TODO: Support for Codesourcery ARM toolchain.
OBJS=labcomm$(VERSION).o \
labcomm$(VERSION)_memory.o \
labcomm$(VERSION)_error.o \
labcomm$(VERSION)_default_error_handler.o \
labcomm$(VERSION)_default_memory.o \
labcomm$(VERSION)_default_scheduler.o \
labcomm$(VERSION)_time.o \
labcomm$(VERSION)_scheduler.o \
labcomm$(VERSION)_encoder.o \
labcomm$(VERSION)_decoder.o \
labcomm$(VERSION)_dynamic_buffer_writer.o \
labcomm$(VERSION)_fd_reader.o \
labcomm$(VERSION)_fd_writer.o \
labcomm$(VERSION)_pthread_scheduler.o
LABCOMM_JAR=../../../compiler/labcomm$(VERSION)_compiler.jar
LABCOMM=java -jar $(LABCOMM_JAR)
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_errors
TEST_DIR=test
#VPATH=$(TEST_DIR)
## Targets
.PHONY: all
all: $(ALL_DEPS)
.PHONY: test
test: all $(TESTS:%=run-test-%)
.PHONY: clean
clean:
$(RM) *.o
$(RM) experimental/*.o
$(RM) experimental/ThrottleDrv/*.o
$(RM) test/*.o
$(RM) test/*.gch
$(RM) test/test_labcomm_errors
$(RM) test/testdata/gen/*.[cho]
$(RM) test/gen/*.[cho]
$(RM) -rf test/gen
for x in $(TESTS); do \
$(RM) $(TEST_DIR)/$$x ; \
done
.PHONY: distclean
distclean: clean
$(RM) ../liblabcomm$(LIBVERSION).so.1
$(RM) ../liblabcomm$(LIBVERSION).a
# rules invoked by 'all'
../liblabcomm$(LIBVERSION).so.1: $(OBJS:%.o=%.pic.o)
$(call MAKESHARED,$@,$@,$^)
../liblabcomm$(LIBVERSION).a: $(OBJS)
ar -r $@ $^
# compilation rules
%.pic.o: %.c
$(CC) -fPIC $(CFLAGS) -c -o $@ $<
%.o: %.c %.h
$(CC) $(CFLAGS) -c -o $@ $<
# rules invoked by 'test'
.PHONY: run-test-%
run-test-%: $(TEST_DIR)/gen/% | $(TEST_DIR)/gen
$<
$(TEST_DIR)/gen/%: $(TEST_DIR)/gen/%.o | $(TEST_DIR)/gen
$(LD) $(LDFLAGS) -o $@ $^ $(LDLIBS)
$(TEST_DIR)/gen/%.o: $(TEST_DIR)/%.c | $(TEST_DIR)/gen
$(CC) $(CFLAGS_TEST) -o $@ -c $<
# Extra compilation dependencies
labcomm_fd_reader.o: \
labcomm_private.h
labcomm_fd_writer.o: \
labcomm_private.h
labcomm_dynamic_buffer_writer.o: \
labcomm_private.h
labcomm$(VERSION).o: \
labcomm$(VERSION).c \
labcomm$(VERSION).h \
labcomm$(VERSION)_private.h
labcomm$(VERSION)_fd_reader_writer.o: \
labcomm$(VERSION)_fd_reader_writer.c \
labcomm$(VERSION)_fd_reader_writer.h \
labcomm$(VERSION).h \
labcomm$(VERSION)_private.h
$(TEST_DIR)/gen/test_labcomm_basic_type_encoding.o: \
labcomm$(VERSION)_private.h
$(TEST_DIR)/gen/test_labcomm_generated_encoding.o: \
labcomm$(VERSION)_private.h \
$(TEST_DIR)/gen/generated_encoding.h
$(TEST_DIR)/gen/test_labcomm_generated_encoding: \
$(TEST_DIR)/gen/generated_encoding.o
$(TEST_DIR)/gen/test_signature_numbers.c: \
$(TEST_DIR)/gen/another_encoding.h \
$(TEST_DIR)/gen/generated_encoding.h
$(TEST_DIR)/gen/test_signature_numbers: \
$(TEST_DIR)/gen/another_encoding.o \
$(TEST_DIR)/gen/generated_encoding.o
$(TEST_DIR)/gen/test_labcomm: \
$(TEST_DIR)/gen/test_sample.o
$(TEST_DIR)/gen/test_labcomm_copy: \
$(TEST_DIR)/gen/generated_encoding.o \
$(TEST_DIR)/gen/test_sample.o \
$(TEST_DIR)/gen/more_types.o
#$(TEST_DIR)/labcomm_mem_reader.o: labcomm_fd_reader_writer.c labcomm_fd_reader_writer.h
#$(TEST_DIR)/labcomm_mem_writer.o: labcomm_mem_writer.c labcomm_mem_writer.h cppmacros.h
ethaddr.o: ethaddr.c
.PRECIOUS: $(TEST_DIR)/%
$(TEST_DIR)/gen:
mkdir -p $@
.PRECIOUS: $(TEST_DIR)/gen/%.c
.PRECIOUS: $(TEST_DIR)/gen/%.h
$(TEST_DIR)/gen/%.c $(TEST_DIR)/gen/%.h: $(TEST_DIR)/%.lc | $(TEST_DIR)/gen
$(LABCOMM) \
--c=$(TEST_DIR)/gen/$*.c \
--h=$(TEST_DIR)/gen/$*.h \
$<
$(TEST_GEN_DIR)/%.c $(TEST_GEN_DIR)/%.h: $(TESTDATA_DIR)/%.lc \
$(LABCOMM_JAR) | $(TEST_GEN_DIR)
$(LABCOMM) \
--c=$(patsubst %.h,%.c,$@) --h=$(patsubst %.c,%.h,$@) $<
$(LABCOMM_JAR):
@echo "======Building LabComm compiler======"
cd $(shell dirname $(LABCOMM_JAR)); ant jar
@echo "======End building LabComm compiler======"
......@@ -62,7 +62,7 @@ int labcomm2006_reader_free(struct labcomm2006_reader *r,
int labcomm2006_reader_start(struct labcomm2006_reader *r,
struct labcomm2006_reader_action_context *action_context,
int local_index, int remote_index,
struct labcomm2006_signature *signature,
const struct labcomm2006_signature *signature,
void *value)
{
UNWRAP(start, r, action_context, local_index, remote_index, signature, value);
......@@ -81,10 +81,10 @@ int labcomm2006_reader_fill(struct labcomm2006_reader *r,
}
int labcomm2006_reader_ioctl(struct labcomm2006_reader *r,
struct labcomm2006_reader_action_context *action_context,
int local_index, int remote_index,
struct labcomm2006_signature *signature,
uint32_t ioctl_action, va_list args)
struct labcomm2006_reader_action_context *action_context,
int local_index, int remote_index,
const struct labcomm2006_signature *signature,
uint32_t ioctl_action, va_list args)
{
UNWRAP(ioctl, r, action_context,
local_index, remote_index, signature, ioctl_action, args);
......@@ -104,7 +104,7 @@ int labcomm2006_writer_free(struct labcomm2006_writer *w,
int labcomm2006_writer_start(struct labcomm2006_writer *w,
struct labcomm2006_writer_action_context *action_context,
int index, struct labcomm2006_signature *signature,
int index, const struct labcomm2006_signature *signature,
void *value)
{
UNWRAP(start, w, action_context, index, signature, value);
......@@ -125,7 +125,7 @@ int labcomm2006_writer_flush(struct labcomm2006_writer *w,
int labcomm2006_writer_ioctl(struct labcomm2006_writer *w,
struct labcomm2006_writer_action_context *action_context,
int index,
struct labcomm2006_signature *signature,
const struct labcomm2006_signature *signature,
uint32_t ioctl_action, va_list args)
{
UNWRAP(ioctl, w, action_context, index, signature, ioctl_action, args);
......@@ -156,31 +156,30 @@ const char *labcomm2006_error_get_str(enum labcomm2006_error error_id)
return error_str;
}
#if 0 //XXX hack to avoid name clash. is this really the same as in 2013?
void on_error_fprintf(enum labcomm2006_error error_id, size_t nbr_va_args, ...)
{
#ifndef LABCOMM_NO_STDIO
void labcomm2006_on_error_fprintf(enum labcomm2006_error error_id, size_t nbr_va_args, ...)
{
const char *err_msg = labcomm2006_error_get_str(error_id); // The final string to print.
if (err_msg == NULL) {
err_msg = "Error with an unknown error ID occured.";
}
fprintf(stderr, "%s\n", err_msg);
if (nbr_va_args > 0) {
va_list arg_pointer;
va_start(arg_pointer, nbr_va_args);
fprintf(stderr, "%s\n", "Extra info {");
char *print_format = va_arg(arg_pointer, char *);
vfprintf(stderr, print_format, arg_pointer);
fprintf(stderr, "}\n");
va_end(arg_pointer);
}
if (nbr_va_args > 0) {
va_list arg_pointer;
va_start(arg_pointer, nbr_va_args);
fprintf(stderr, "%s\n", "Extra info {");
char *print_format = va_arg(arg_pointer, char *);
vfprintf(stderr, print_format, arg_pointer);
fprintf(stderr, "}\n");
va_end(arg_pointer);
}
}
#else
; // If labcomm can't be compiled with stdio the user will have to make an own error callback functionif he/she needs error reporting.
#endif
}
#error Define LABCOMM2006_ON_ERROR_FPRINTF
#endif
......@@ -244,22 +243,22 @@ void labcomm2006_set_local_index(struct labcomm2006_signature *signature)
{
if (signature->index != 0) {
labcomm2006_error_fatal_global(LABCOMM_ERROR_SIGNATURE_ALREADY_SET,
"%s", signature->name);
"Signature already set: %s", signature->name);
}
signature->index = local_index;
local_index++;
}
int labcomm2006_get_local_index(struct labcomm2006_signature *signature)
int labcomm2006_get_local_index(const struct labcomm2006_signature *signature)
{
if (signature->index == 0) {
labcomm2006_error_fatal_global(LABCOMM_ERROR_SIGNATURE_NOT_SET,
"%s", signature->name);
"Signature not set: %s", signature->name);
}
return signature->index;
}
int labcomm2006_internal_sizeof(struct labcomm2006_signature *signature,
int labcomm2006_internal_sizeof(const struct labcomm2006_signature *signature,
void *v)
{
int length = signature->encoded_size(v);
......
......@@ -23,8 +23,6 @@
#ifndef _LABCOMM_H_
#define _LABCOMM_H_
#define LABCOMM_VERSION "LabComm2006"
#include <stdarg.h>
#ifdef LABCOMM_COMPAT
......@@ -33,6 +31,7 @@
#include <stdint.h>
#include <unistd.h>
#endif
#include "labcomm2006_error.h"
#include "labcomm2006_scheduler.h"
......@@ -71,7 +70,7 @@ typedef void (*labcomm2006_error_handler_callback)(enum labcomm2006_error error_
/* Default error handler, prints message to stderr.
* Extra info about the error can be supplied as char* as VA-args. Especially user defined errors should supply a describing string. if nbr_va_args > 1 the first variable argument must be a printf format string and the possibly following arguments are passed as va_args to vprintf.
*/
void on_error_fprintf(enum labcomm2006_error error_id, size_t nbr_va_args, ...);
void labcomm2006_on_error_fprintf(enum labcomm2006_error error_id, size_t nbr_va_args, ...);
/* Register a callback for the error handler for this encoder. */
void labcomm2006_register_error_handler_encoder(struct labcomm2006_encoder *encoder, labcomm2006_error_handler_callback callback);
......
#ifndef __VXWORKS__
#ifndef _LABCOMM2006_COMPAT_VXWORKS_H_
#define _LABCOMM2006_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__
#if (CPU == PPC603)
#undef _LITTLE_ENDIAN
#endif
......@@ -10,3 +24,6 @@
#undef _BIG_ENDIAN
#endif
extern unsigned int cpuFrequency;
#endif
......@@ -26,7 +26,7 @@
struct sample_entry {
int remote_index;
struct labcomm2006_signature *signature;
const struct labcomm2006_signature *signature;
labcomm2006_decoder_function decode;
labcomm2006_handler_function handler;
void *context;
......@@ -181,7 +181,8 @@ static int decode_typedef_or_sample(struct labcomm2006_decoder *d, int kind)
.pos = 0,
.error = 0,
};
struct labcomm2006_signature signature, *local_signature;
struct labcomm2006_signature signature;
const struct labcomm2006_signature *local_signature;
int remote_index, local_index, err;
local_signature = NULL;
......@@ -264,7 +265,7 @@ struct call_handler_context {
struct labcomm2006_reader *reader;
int local_index;
int remote_index;
struct labcomm2006_signature *signature;
const struct labcomm2006_signature *signature;
labcomm2006_handler_function handler;
void *context;
};
......@@ -300,7 +301,7 @@ int labcomm2006_decoder_decode_one(struct labcomm2006_decoder *d)
result = d->reader->error;
goto out;
}
if (remote_index == LABCOMM_TYPEDEF || remote_index == LABCOMM_SAMPLE) {
if (remote_index == LABCOMM_SAMPLE) {
result = decode_typedef_or_sample(d, remote_index);
} else {
int *local_index;
......@@ -366,7 +367,7 @@ int labcomm2006_decoder_ioctl(struct labcomm2006_decoder *d,
}
int labcomm2006_internal_decoder_ioctl(struct labcomm2006_decoder *d,
struct labcomm2006_signature *signature,
const struct labcomm2006_signature *signature,
uint32_t action, va_list va)
{
int result;
......@@ -387,7 +388,7 @@ int labcomm2006_internal_decoder_ioctl(struct labcomm2006_decoder *d,
int labcomm2006_internal_decoder_register(
struct labcomm2006_decoder *d,
struct labcomm2006_signature *signature,
const struct labcomm2006_signature *signature,
labcomm2006_decoder_function decode,
labcomm2006_handler_function handler,
void *context)
......
......@@ -21,7 +21,6 @@
#include <stdlib.h>
#include "labcomm2006.h"
#include "labcomm2006_private.h"
extern struct labcomm2006_memory *labcomm2006_default_memory;
......@@ -56,7 +56,7 @@ static int dyn_free(struct labcomm2006_writer *w,
static int dyn_start(struct labcomm2006_writer *w,
struct labcomm2006_writer_action_context *action_context,
int index,
struct labcomm2006_signature *signature,
const struct labcomm2006_signature *signature,
void *value)
{
void *tmp;
......@@ -103,7 +103,7 @@ static int dyn_flush(struct labcomm2006_writer *w,
static int dyn_ioctl(struct labcomm2006_writer *w,
struct labcomm2006_writer_action_context *action_context,
int signature_index,
struct labcomm2006_signature *signature,
const struct labcomm2006_signature *signature,
uint32_t action, va_list arg)
{
int result = -ENOTSUP;
......
......@@ -69,7 +69,7 @@ void labcomm2006_encoder_free(struct labcomm2006_encoder* e)
int labcomm2006_internal_encoder_register(
struct labcomm2006_encoder *e,
struct labcomm2006_signature *signature,
const struct labcomm2006_signature *signature,
labcomm2006_encoder_function encode)
{
int result = -EINVAL;
......@@ -104,7 +104,7 @@ out:
int labcomm2006_internal_encode(
struct labcomm2006_encoder *e,
struct labcomm2006_signature *signature,
const struct labcomm2006_signature *signature,
labcomm2006_encoder_function encode,
void *value)
{
......@@ -150,8 +150,8 @@ out:
}
int labcomm2006_internal_encoder_ioctl(struct labcomm2006_encoder *encoder,
struct labcomm2006_signature *signature,
uint32_t action, va_list va)
const struct labcomm2006_signature *signature,
uint32_t action, va_list va)
{
int result = -ENOTSUP;
int index;
......
......@@ -86,7 +86,7 @@ static int fd_fill(struct labcomm2006_reader *r,
int err;
r->pos = 0;
err = read(fd_reader->fd, (char *) r->data, r->data_size);
err = read(fd_reader->fd, (char *)r->data, r->data_size);