From ef8f12c09b830be0cb1378155be137b7d2de7623 Mon Sep 17 00:00:00 2001 From: "Mike D. Lowis" Date: Wed, 11 Sep 2013 15:52:25 -0400 Subject: [PATCH] updated scons file to use separate environments for scheme and C binaries and cleaned up lint in libsof --- SConstruct | 65 ++++++++++++++++++++++++++++-------------- source/libsof/libsof.c | 39 +++++++++++++------------ source/libsof/libsof.h | 1 + 3 files changed, 64 insertions(+), 41 deletions(-) diff --git a/SConstruct b/SConstruct index 5d76812..8de6f45 100644 --- a/SConstruct +++ b/SConstruct @@ -14,62 +14,83 @@ def find_files(path,pattern): matches.append(os.path.join(root, filename)) return matches +#------------------------------------------------------------------------------ +# Compiler Environments +#------------------------------------------------------------------------------ + +# Default C/C++ Environment +#--------------------------- +c_cpp = Environment( + ENV = os.environ, + CCFLAGS = [ '-Wall', '-Werror', '-std=c99' ], + LDFLAGS = [], + TOOLS = [ 'mingw' ]) + +# Chicken Scheme Environment +#--------------------------- # Scheme Source Compiler scheme_compiler = Builder( action = 'csc $CCFLAGS -c -o $TARGET $SOURCE', suffix = '.o', src_suffix = '.scm', - single_source = True - ) + single_source = True) # Scheme Binary Linker scheme_linker = Builder( action = 'csc $LDFLAGS -o $TARGET $SOURCES', suffix = "$PROGSUFFIX", src_suffix = '.o', - src_builder = [ scheme_compiler ] - ) + src_builder = [ scheme_compiler ]) # Scheme Test Linker scheme_tester = Builder( action = 'csc $LDFLAGS -o $TARGET $SOURCES && $TARGET', suffix = "$PROGSUFFIX", src_suffix = '.o', - src_builder = [ scheme_compiler ] - ) + src_builder = [ scheme_compiler ]) # Create the Environment for this project -env = Environment( +scheme = Environment( ENV = os.environ, CCFLAGS = [ '-explicit-use', '-I', 'inc'], LDFLAGS = [], BUILDERS = { - 'SchemeProgram': scheme_linker, - 'SchemeTestRunner': scheme_tester }, - tools = [ 'mingw' ] - ) + 'Program': scheme_linker, + 'TestRunner': scheme_tester }) #------------------------------------------------------------------------------ # SCLPL Targets #------------------------------------------------------------------------------ -# libSOF Shared Library -env.SharedLibrary( +# SOF Shared Library +c_cpp.SharedLibrary( target = 'sof', - source = find_files('source/libsof/','*.scm') - ) + source = find_files('source/libsof/','*.c')) + +# SBC Shared Library +c_cpp.SharedLibrary( + target = 'sbc', + source = find_files('source/libsbc/','*.c')) + +# readsof Command Line Utility +readsof = c_cpp.Clone( + CPPPATH = [ 'source/libsof/' ], + LIBS = [ 'sof' ], + LIBPATH = [ './' ]) +readsof.Program( + target = 'readsof', + source = find_files('source/readsof/','*.c')) +readsof.Depends('readsof', 'sof') # SCLPL Compiler src_files = find_files('source/compiler/','*.scm') -env.SchemeProgram( +scheme.Program( target = 'sclpl-cc', - source = src_files - ) + source = src_files) -# Test Suite -env.SchemeTestRunner( +# Compiler Test Suite +scheme.TestRunner( target = 'sclpl-cc-tests', source = [s for s in src_files if not s.endswith("main.scm")] + - find_files('tests/compiler/','*.scm') - ) + find_files('tests/compiler/','*.scm')) diff --git a/source/libsof/libsof.c b/source/libsof/libsof.c index 869e82e..a822805 100644 --- a/source/libsof/libsof.c +++ b/source/libsof/libsof.c @@ -6,7 +6,8 @@ */ #include "libsof.h" #include -#include +#include +#include static void libsof_read_header(FILE* file, sof_file_t* obj); static void libsof_read_symbols(FILE* file, sof_file_t* obj); @@ -18,7 +19,7 @@ static void libsof_write_symbols(FILE* file, sof_file_t* obj); static void libsof_write_strings(FILE* file, sof_file_t* obj); static void libsof_write_data(FILE* file, sof_file_t* obj); static void libsof_write_code(FILE* file, sof_file_t* obj); -static bool is_big_endian(void); +//static bool is_big_endian(void); /****************************************************************************** * Functions for Reading an SOF file @@ -58,7 +59,7 @@ static void libsof_read_symbols(FILE* file, sof_file_t* obj) { size_t sz = obj->header->sym_tbl_sz * sizeof(sof_st_entry_t); obj->symbols = (sof_st_entry_t*)malloc(sz); - fread(obj->symbols, sizeof(sof_st_entry_t), obj->header->sym_tbl_sz, fhndl); + fread(obj->symbols, sizeof(sof_st_entry_t), obj->header->sym_tbl_sz, file); } } @@ -67,7 +68,7 @@ static void libsof_read_strings(FILE* file, sof_file_t* obj) if (obj->header->sym_str_tbl_sz) { obj->str_tbl = (uint8_t*)malloc( obj->header->sym_str_tbl_sz ); - fread( obj->str_tbl, sizeof(uint8_t), obj->header->sym_str_tbl_sz, fhndl); + fread( obj->str_tbl, sizeof(uint8_t), obj->header->sym_str_tbl_sz, file); } } @@ -76,7 +77,7 @@ static void libsof_read_data(FILE* file, sof_file_t* obj) if (obj->header->data_sz) { obj->data = (uint8_t*)malloc( obj->header->data_sz ); - fread( obj->data, sizeof(uint8_t), obj->header->data_sz, fhndl); + fread( obj->data, sizeof(uint8_t), obj->header->data_sz, file); } } @@ -85,8 +86,8 @@ static void libsof_read_code(FILE* file, sof_file_t* obj) if (obj->header->code_sz) { size_t sz = obj->header->code_sz * sizeof(uint32_t); - obj->code = (sof_st_entry_t*)malloc(sz); - fread(obj->code, sizeof(uint32_t), obj->header->code_sz, fhndl); + obj->code = (uint32_t*)malloc(sz); + fread(obj->code, sizeof(uint32_t), obj->header->code_sz, file); } } @@ -122,7 +123,7 @@ static void libsof_write_symbols(FILE* file, sof_file_t* obj) { if (obj->header->sym_tbl_sz) { - fwrite(obj->symbols, sizeof(sof_st_entry_t), obj->header->sym_tbl_sz, fhndl); + fwrite(obj->symbols, sizeof(sof_st_entry_t), obj->header->sym_tbl_sz, file); } } @@ -130,7 +131,7 @@ static void libsof_write_strings(FILE* file, sof_file_t* obj) { if (obj->header->sym_str_tbl_sz) { - fwrite( obj->str_tbl, sizeof(uint8_t), obj->header->sym_str_tbl_sz, fhndl); + fwrite( obj->str_tbl, sizeof(uint8_t), obj->header->sym_str_tbl_sz, file); } } @@ -138,7 +139,7 @@ static void libsof_write_data(FILE* file, sof_file_t* obj) { if (obj->header->data_sz) { - fwrite( obj->data, sizeof(uint8_t), obj->header->data_sz, fhndl); + fwrite( obj->data, sizeof(uint8_t), obj->header->data_sz, file); } } @@ -146,19 +147,19 @@ static void libsof_write_code(FILE* file, sof_file_t* obj) { if (obj->header->code_sz) { - fwrite(obj->code, sizeof(uint32_t), obj->header->code_sz, fhndl); + fwrite(obj->code, sizeof(uint32_t), obj->header->code_sz, file); } } /****************************************************************************** * Static Helper Functions *****************************************************************************/ -static bool is_big_endian(void) -{ - union { - uint32_t i; - uint8_t c[4]; - } bint = { 0x01020304 }; - return bint.c[0] == 1; -} +//static bool is_big_endian(void) +//{ +// union { +// uint32_t i; +// uint8_t c[4]; +// } bint = { 0x01020304 }; +// return bint.c[0] == 1; +//} diff --git a/source/libsof/libsof.h b/source/libsof/libsof.h index fe879d6..a255e15 100644 --- a/source/libsof/libsof.h +++ b/source/libsof/libsof.h @@ -8,6 +8,7 @@ #define LIBSOF_H #include "sof.h" +#include typedef struct { sof_header_t* header; -- 2.52.0