Skip to content
Snippets Groups Projects
Commit 5f2c6643 authored by Anders Blomdell's avatar Anders Blomdell
Browse files

Minor refatorings and cleanups.

parent e2c2b9d4
No related branches found
No related tags found
No related merge requests found
...@@ -6,7 +6,7 @@ CFLAGS = -g -Wall -Werror -I. -Itest ...@@ -6,7 +6,7 @@ CFLAGS = -g -Wall -Werror -I. -Itest
LDFLAGS = -L. LDFLAGS = -L.
LDLIBS_TEST = -lcunit -llabcomm 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_PATH=../../compiler
LABCOMMC_JAR=$(LABCOMMC_PATH)/labComm.jar LABCOMMC_JAR=$(LABCOMMC_PATH)/labComm.jar
...@@ -55,20 +55,16 @@ run-test: $(TEST_DIR)/test_labcomm $(TEST_DIR)/test_labcomm_errors |$(TEST_DIR) ...@@ -55,20 +55,16 @@ run-test: $(TEST_DIR)/test_labcomm $(TEST_DIR)/test_labcomm_errors |$(TEST_DIR)
test/test_labcomm test/test_labcomm
test/test_labcomm_errors test/test_labcomm_errors
$(TEST_DIR)/test_labcomm_errors: $(TEST_DIR)/test_labcomm_errors.o liblabcomm.a |$(TEST_DIR) $(TEST_DIR)/%.o: $(TEST_DIR)/%.c
$(CC) $(CFLAGS) $(LDFLAGS) -llabcomm -o $@ $^ $(CC) $(CFLAGS) -o $@ -c $<
$(TEST_DIR)/test_labcomm_errors.o: $(TEST_DIR)/test_labcomm_errors.c $(TEST_DIR)/test_labcomm_errors.h |$(TEST_DIR) $(TEST_DIR)/%: $(TEST_DIR)/%.o
cd test; $(CC) $(CFLAGS) -I .. -c $(patsubst $(TEST_DIR)/%, %, $^) $(CC) $(LDFLAGS) -o $@ $^ $(LDLIBS) $(LDLIBS_TEST)
$(TEST_DIR)/test_labcomm.o: $(TEST_DIR)/test_labcomm.c $(TEST_GEN_DIR)/test_sample.h |$(TEST_DIR) $(TEST_GEN_DIR)/%.c $(TEST_GEN_DIR)/%.h: $(TESTDATA_DIR)/%.lc \
$(CC) -c $(CFLAGS) -o $@ $< $(LABCOMMC_JAR) | $(TEST_GEN_DIR)
java -jar $(LABCOMMC_JAR) \
$(TEST_DIR)/test_labcomm: $(TEST_DIR)/test_labcomm.o $(TEST_GEN_DIR)/test_sample.o liblabcomm.a --c=$(patsubst %.h,%.c,$@) --h=$(patsubst %.c,%.h,$@) $<
$(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,$@) $<
$(LABCOMMC_JAR): $(LABCOMMC_JAR):
@echo "======Building LabComm compiler======" @echo "======Building LabComm compiler======"
...@@ -83,7 +79,11 @@ clean: ...@@ -83,7 +79,11 @@ clean:
$(RM) test/*.o $(RM) test/*.o
$(RM) test/*.gch $(RM) test/*.gch
$(RM) test/test_labcomm_errors $(RM) test/test_labcomm_errors
$(RM) test/testdata/gen/*.[cho]
$(RM) $(TEST_DIR)/test_labcomm $(RM) $(TEST_DIR)/test_labcomm
distclean: clean distclean: clean
$(RM) liblabcomm.a $(RM) liblabcomm.a
# Extra dependencies
$(TEST_DIR)/test_labcomm: $(TEST_GEN_DIR)/test_sample.o
#include <errno.h> #ifdef LABCOMM_COMPAT
#include <string.h> #include LABCOMM_COMPAT
#ifndef __VXWORKS__
#ifdef ARM_CORTEXM3_CODESOURCERY
#include <string.h>
#else #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
#include <stdio.h> #include <stdio.h>
#include <strings.h>
#endif #endif
#ifdef __VXWORKS__ #include <errno.h>
#if (CPU == PPC603) #include <string.h>
#undef _LITTLE_ENDIAN
#endif
#if (CPU == PENTIUM4)
#undef _BIG_ENDIAN
#endif
#endif
#include "labcomm.h" #include "labcomm.h"
#include "labcomm_private.h" #include "labcomm_private.h"
#include "labcomm_ioctl.h" #include "labcomm_ioctl.h"
#include "labcomm_dynamic_buffer_reader_writer.h" #include "labcomm_dynamic_buffer_writer.h"
typedef struct labcomm_sample_entry { typedef struct labcomm_sample_entry {
struct labcomm_sample_entry *next; struct labcomm_sample_entry *next;
...@@ -360,7 +340,6 @@ int labcomm_encoder_ioctl(struct labcomm_encoder *encoder, ...@@ -360,7 +340,6 @@ int labcomm_encoder_ioctl(struct labcomm_encoder *encoder,
return result; return result;
} }
static void collect_flat_signature( static void collect_flat_signature(
labcomm_decoder_t *decoder, labcomm_decoder_t *decoder,
labcomm_encoder_t *signature_writer) labcomm_encoder_t *signature_writer)
......
...@@ -155,15 +155,10 @@ struct labcomm_encoder *labcomm_encoder_new( ...@@ -155,15 +155,10 @@ struct labcomm_encoder *labcomm_encoder_new(
void *writer_context); void *writer_context);
void labcomm_encoder_free( void labcomm_encoder_free(
struct labcomm_encoder *encoder); struct labcomm_encoder *encoder);
/* See labcomm_ioctl.h for predefined ioctl_action values */ /* See labcomm_ioctl.h for predefined ioctl_action values */
int labcomm_encoder_ioctl(struct labcomm_encoder *encoder, int labcomm_encoder_ioctl(struct labcomm_encoder *encoder,
int ioctl_action, 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 #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( int labcomm_dynamic_buffer_writer(
labcomm_writer_t *w, labcomm_writer_t *w,
labcomm_writer_action_t action, ...) labcomm_writer_action_t action,
...)
{ {
switch (action) { switch (action) {
case labcomm_writer_alloc: { case labcomm_writer_alloc: {
......
...@@ -9,6 +9,7 @@ extern int labcomm_dynamic_buffer_reader( ...@@ -9,6 +9,7 @@ extern int labcomm_dynamic_buffer_reader(
extern int labcomm_dynamic_buffer_writer( extern int labcomm_dynamic_buffer_writer(
labcomm_writer_t *writer, labcomm_writer_t *writer,
labcomm_writer_action_t action, ...); labcomm_writer_action_t action,
...);
#endif #endif
...@@ -9,6 +9,8 @@ extern int labcomm_fd_reader( ...@@ -9,6 +9,8 @@ extern int labcomm_fd_reader(
extern int labcomm_fd_writer( extern int labcomm_fd_writer(
labcomm_writer_t *writer, labcomm_writer_t *writer,
labcomm_writer_action_t action, ...); labcomm_writer_action_t action,
...);
#endif #endif
#ifndef _LABCOMM_PRIVATE_H_ #ifndef _LABCOMM_PRIVATE_H_
#define _LABCOMM_PRIVATE_H_ #define _LABCOMM_PRIVATE_H_
#ifdef ARM_CORTEXM3_CODESOURCERY #ifdef LABCOMM_COMPAT
#include <machine/endian.h> #include LABCOMM_COMPAT
#else #else
#include <endian.h> #include <endian.h>
#endif
// Some projects can not use stdio.h.
#ifndef LABCOMM_NO_STDIO
#include <stdio.h> #include <stdio.h>
#endif #endif
...@@ -233,6 +229,16 @@ void labcomm_internal_encode( ...@@ -233,6 +229,16 @@ void labcomm_internal_encode(
labcomm_signature_t *signature, labcomm_signature_t *signature,
void *value); 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 #if __BYTE_ORDER == __LITTLE_ENDIAN
#define LABCOMM_ENCODE(name, type) \ #define LABCOMM_ENCODE(name, type) \
...@@ -330,33 +336,4 @@ static inline void labcomm_encode_string(labcomm_encoder_t *e, ...@@ -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); 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 #endif
...@@ -37,7 +37,7 @@ void reset_callback_erro_id() ...@@ -37,7 +37,7 @@ void reset_callback_erro_id()
callback_error_id = -128; callback_error_id = -128;
} }
int encoded_size_mock(void *voidp) int encoded_size_mock(struct labcomm_signature *signature, void *voidp)
{ {
return 0; return 0;
} }
...@@ -50,7 +50,12 @@ int test_enc_not_reg_encoder_sign() ...@@ -50,7 +50,12 @@ int test_enc_not_reg_encoder_sign()
labcomm_encoder_t *encoder = labcomm_encoder_new(labcomm_mem_writer, mcontext); labcomm_encoder_t *encoder = labcomm_encoder_new(labcomm_mem_writer, mcontext);
labcomm_register_error_handler_encoder(encoder, test_callback); 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); encoder->do_encode(encoder, &signature, NULL);
return assert_callback(LABCOMM_ERROR_ENC_NO_REG_SIGNATURE, __FUNCTION__, ""); return assert_callback(LABCOMM_ERROR_ENC_NO_REG_SIGNATURE, __FUNCTION__, "");
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment