Commit 5f2c6643 authored by Anders Blomdell's avatar Anders Blomdell
Browse files

Minor refatorings and cleanups.

parent e2c2b9d4
......@@ -3,10 +3,10 @@
# Use LLVM clang if it's found.
CC = $(shell hash clang 2>/dev/null && echo clang || echo gcc)
CFLAGS = -g -Wall -Werror -I. -Itest
LDFLAGS = -L .
LDFLAGS = -L.
LDLIBS_TEST = -lcunit -llabcomm
OBJS= labcomm.o labcomm_dynamic_buffer_reader_writer.o labcomm_fd_reader_writer.o labcomm_mem_reader.o labcomm_mem_writer.o
OBJS= labcomm.o labcomm_dynamic_buffer_writer.o labcomm_fd_reader_writer.o labcomm_mem_reader.o labcomm_mem_writer.o
LABCOMMC_PATH=../../compiler
LABCOMMC_JAR=$(LABCOMMC_PATH)/labComm.jar
......@@ -55,20 +55,16 @@ run-test: $(TEST_DIR)/test_labcomm $(TEST_DIR)/test_labcomm_errors |$(TEST_DIR)
test/test_labcomm
test/test_labcomm_errors
$(TEST_DIR)/test_labcomm_errors: $(TEST_DIR)/test_labcomm_errors.o liblabcomm.a |$(TEST_DIR)
$(CC) $(CFLAGS) $(LDFLAGS) -llabcomm -o $@ $^
$(TEST_DIR)/%.o: $(TEST_DIR)/%.c
$(CC) $(CFLAGS) -o $@ -c $<
$(TEST_DIR)/test_labcomm_errors.o: $(TEST_DIR)/test_labcomm_errors.c $(TEST_DIR)/test_labcomm_errors.h |$(TEST_DIR)
cd test; $(CC) $(CFLAGS) -I .. -c $(patsubst $(TEST_DIR)/%, %, $^)
$(TEST_DIR)/%: $(TEST_DIR)/%.o
$(CC) $(LDFLAGS) -o $@ $^ $(LDLIBS) $(LDLIBS_TEST)
$(TEST_DIR)/test_labcomm.o: $(TEST_DIR)/test_labcomm.c $(TEST_GEN_DIR)/test_sample.h |$(TEST_DIR)
$(CC) -c $(CFLAGS) -o $@ $<
$(TEST_DIR)/test_labcomm: $(TEST_DIR)/test_labcomm.o $(TEST_GEN_DIR)/test_sample.o liblabcomm.a
$(CC) $(CFLAGS) $(LDFLAGS) $(filter-out %.a,$^) $(LDLIBS) $(LDLIBS_TEST) -o $@
$(TEST_GEN_DIR)/%.c $(TEST_GEN_DIR)/%.h: $(TESTDATA_DIR)/%.lc $(LABCOMMC_JAR) |$(TEST_GEN_DIR)
java -jar $(LABCOMMC_JAR) --c=$(patsubst %.h,%.c,$@) --h=$(patsubst %.c,%.h,$@) $<
$(TEST_GEN_DIR)/%.c $(TEST_GEN_DIR)/%.h: $(TESTDATA_DIR)/%.lc \
$(LABCOMMC_JAR) | $(TEST_GEN_DIR)
java -jar $(LABCOMMC_JAR) \
--c=$(patsubst %.h,%.c,$@) --h=$(patsubst %.c,%.h,$@) $<
$(LABCOMMC_JAR):
@echo "======Building LabComm compiler======"
......@@ -83,7 +79,11 @@ clean:
$(RM) test/*.o
$(RM) test/*.gch
$(RM) test/test_labcomm_errors
$(RM) test/testdata/gen/*.[cho]
$(RM) $(TEST_DIR)/test_labcomm
distclean: clean
$(RM) liblabcomm.a
# Extra dependencies
$(TEST_DIR)/test_labcomm: $(TEST_GEN_DIR)/test_sample.o
#include <errno.h>
#include <string.h>
#ifndef __VXWORKS__
#ifdef ARM_CORTEXM3_CODESOURCERY
#include <string.h>
#else
#include <strings.h>
#endif
#endif
#ifndef ARM_CORTEXM3_CODESOURCERY
#include <stdlib.h>
#endif
// Some projects can not use stdio.h.
#ifndef LABCOMM_NO_STDIO
#ifdef LABCOMM_COMPAT
#include LABCOMM_COMPAT
#else
#include <stdio.h>
#include <strings.h>
#endif
#ifdef __VXWORKS__
#if (CPU == PPC603)
#undef _LITTLE_ENDIAN
#endif
#if (CPU == PENTIUM4)
#undef _BIG_ENDIAN
#endif
#endif
#include <errno.h>
#include <string.h>
#include "labcomm.h"
#include "labcomm_private.h"
#include "labcomm_ioctl.h"
#include "labcomm_dynamic_buffer_reader_writer.h"
#include "labcomm_dynamic_buffer_writer.h"
typedef struct labcomm_sample_entry {
struct labcomm_sample_entry *next;
......@@ -360,7 +340,6 @@ int labcomm_encoder_ioctl(struct labcomm_encoder *encoder,
return result;
}
static void collect_flat_signature(
labcomm_decoder_t *decoder,
labcomm_encoder_t *signature_writer)
......
......@@ -155,15 +155,10 @@ struct labcomm_encoder *labcomm_encoder_new(
void *writer_context);
void labcomm_encoder_free(
struct labcomm_encoder *encoder);
/* See labcomm_ioctl.h for predefined ioctl_action values */
int labcomm_encoder_ioctl(struct labcomm_encoder *encoder,
int ioctl_action,
...);
void labcomm_encoder_start(struct labcomm_encoder *e,
labcomm_signature_t *s) ;
//HERE BE DRAGONS: is the signature_t* needed here?
void labcomm_encoder_end(struct labcomm_encoder *e,
labcomm_signature_t *s) ;
#endif
#ifndef ARM_CORTEXM3_CODESOURCERY
#error "ARM_CORTEXM3_CODESOURCERY" not defined
#endif
#include <machine/endian.h>
#ifndef __VXWORKS__
#error "__VXWORKS__" not defined
#endif
#if (CPU == PPC603)
#undef _LITTLE_ENDIAN
#endif
#if (CPU == PENTIUM4)
#undef _BIG_ENDIAN
#endif
#include "labcomm_dynamic_buffer_reader_writer.h"
#include "labcomm_dynamic_buffer_writer.h"
int labcomm_dynamic_buffer_writer(
labcomm_writer_t *w,
labcomm_writer_action_t action, ...)
labcomm_writer_action_t action,
...)
{
switch (action) {
case labcomm_writer_alloc: {
......
......@@ -9,6 +9,7 @@ extern int labcomm_dynamic_buffer_reader(
extern int labcomm_dynamic_buffer_writer(
labcomm_writer_t *writer,
labcomm_writer_action_t action, ...);
labcomm_writer_action_t action,
...);
#endif
......@@ -9,6 +9,8 @@ extern int labcomm_fd_reader(
extern int labcomm_fd_writer(
labcomm_writer_t *writer,
labcomm_writer_action_t action, ...);
labcomm_writer_action_t action,
...);
#endif
#ifndef _LABCOMM_PRIVATE_H_
#define _LABCOMM_PRIVATE_H_
#ifdef ARM_CORTEXM3_CODESOURCERY
#include <machine/endian.h>
#ifdef LABCOMM_COMPAT
#include LABCOMM_COMPAT
#else
#include <endian.h>
#endif
// Some projects can not use stdio.h.
#ifndef LABCOMM_NO_STDIO
#include <stdio.h>
#endif
......@@ -233,6 +229,16 @@ void labcomm_internal_encode(
labcomm_signature_t *signature,
void *value);
/* Should these really be visible? */
void labcomm_encoder_start(struct labcomm_encoder *e,
labcomm_signature_t *s) ;
//HERE BE DRAGONS: is the signature_t* needed here?
void labcomm_encoder_end(struct labcomm_encoder *e,
labcomm_signature_t *s) ;
#if __BYTE_ORDER == __LITTLE_ENDIAN
#define LABCOMM_ENCODE(name, type) \
......@@ -330,33 +336,4 @@ static inline void labcomm_encode_string(labcomm_encoder_t *e,
void labcomm_encode_type_index(labcomm_encoder_t *e, labcomm_signature_t *s);
static inline int labcomm_buffer_write(struct labcomm_writer *w,
labcomm_writer_action_t action, ...)
{
// If this gets called, it is an error,
// so note error and let producer proceed
w->context = w;
w->pos = 0;
return 0;
}
static inline int labcomm_buffer_writer_error(struct labcomm_writer *w)
{
return w->context != NULL;
}
static inline void labcomm_buffer_writer_setup(struct labcomm_writer *w,
void *data,
int length)
{
w->context = NULL; // Used as error flag
w->data = data;
w->data_size = length;
w->count = length;
w->pos = 0;
w->write = labcomm_buffer_write;
}
#endif
......@@ -37,7 +37,7 @@ void reset_callback_erro_id()
callback_error_id = -128;
}
int encoded_size_mock(void *voidp)
int encoded_size_mock(struct labcomm_signature *signature, void *voidp)
{
return 0;
}
......@@ -50,7 +50,12 @@ int test_enc_not_reg_encoder_sign()
labcomm_encoder_t *encoder = labcomm_encoder_new(labcomm_mem_writer, mcontext);
labcomm_register_error_handler_encoder(encoder, test_callback);
labcomm_signature_t signature = {.type = 0, .name = "test_signature", .encoded_size = encoded_size_mock, .size = 0, .signature = (unsigned char *) "0"};
labcomm_signature_t signature = {
.type = 0,
.name = "test_signature",
.encoded_size = encoded_size_mock,
.size = 0,
.signature = (unsigned char *) "0"};
encoder->do_encode(encoder, &signature, NULL);
return assert_callback(LABCOMM_ERROR_ENC_NO_REG_SIGNATURE, __FUNCTION__, "");
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment