Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
Erik Jansson
LabComm
Commits
5f2c6643
Commit
5f2c6643
authored
Apr 18, 2013
by
Anders Blomdell
Browse files
Minor refatorings and cleanups.
parent
e2c2b9d4
Changes
10
Hide whitespace changes
Inline
Side-by-side
lib/c/Makefile
View file @
5f2c6643
...
...
@@ -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)
$(
C
FLAGS)
-
I
..
-c
$(
patsubst
$(TEST_DIR)
/%, %,
$^
)
$(TEST_DIR)/
%
:
$(TEST_DIR)/%.o
$(CC)
$(
LD
FLAGS)
-
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
lib/c/labcomm.c
View file @
5f2c6643
#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
)
...
...
lib/c/labcomm.h
View file @
5f2c6643
...
...
@@ -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
lib/c/labcomm_compat_arm_cortexm3.h
0 → 100644
View file @
5f2c6643
#ifndef ARM_CORTEXM3_CODESOURCERY
#error "ARM_CORTEXM3_CODESOURCERY" not defined
#endif
#include <machine/endian.h>
lib/c/labcomm_compat_vxworks.h
0 → 100644
View file @
5f2c6643
#ifndef __VXWORKS__
#error "__VXWORKS__" not defined
#endif
#if (CPU == PPC603)
#undef _LITTLE_ENDIAN
#endif
#if (CPU == PENTIUM4)
#undef _BIG_ENDIAN
#endif
lib/c/labcomm_dynamic_buffer_
reader_
writer.c
→
lib/c/labcomm_dynamic_buffer_writer.c
View file @
5f2c6643
#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
:
{
...
...
lib/c/labcomm_dynamic_buffer_
reader_
writer.h
→
lib/c/labcomm_dynamic_buffer_writer.h
View file @
5f2c6643
...
...
@@ -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
lib/c/labcomm_fd_reader_writer.h
View file @
5f2c6643
...
...
@@ -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
lib/c/labcomm_private.h
View file @
5f2c6643
#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
lib/c/test/test_labcomm_errors.c
View file @
5f2c6643
...
...
@@ -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__
,
""
);
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment