diff --git a/Makefile b/Makefile index 6b7d69ddf..a9a168147 100644 --- a/Makefile +++ b/Makefile @@ -31,7 +31,7 @@ SUP_STM32F4 = ./third-party/STM32F4-Discovery_FW_V1.1.0/Libraries/CMSIS/ST/STM32 # Add common-io.c and sensors.c SOURCES = \ $(sort \ - $(wildcard ./src/jerry-libc.c ./src/pretty-printer.c) \ + $(wildcard ./src/libruntime/*.c) \ $(wildcard ./src/libperipherals/actuators.c) \ $(wildcard ./src/libjsparser/*.c) \ $(wildcard ./src/libecmaobjects/*.c) \ @@ -40,11 +40,16 @@ SOURCES = \ $(wildcard ./src/libcoreint/*.c) ) SOURCES_STM32F4 = \ - third-party/STM32F4-Discovery_FW_V1.1.0/Libraries/CMSIS/ST/STM32F4xx/Source/Templates/system_stm32f4xx.c + third-party/STM32F4-Discovery_FW_V1.1.0/Libraries/CMSIS/ST/STM32F4xx/Source/Templates/system_stm32f4xx.c \ + $(wildcard src/libruntime/stm32f4/*) + +SOURCES_LINUX = \ + $(wildcard src/libruntime/linux/*) HEADERS = \ $(sort \ $(wildcard ./src/*.h) \ + $(wildcard ./src/libruntime/*.h) \ $(wildcard ./src/libperipherals/*.h) \ $(wildcard ./src/libjsparser/*.h) \ $(wildcard ./src/libecmaobjects/*.h) \ @@ -54,6 +59,7 @@ HEADERS = \ INCLUDES = \ -I src \ + -I src/libruntime \ -I src/libperipherals \ -I src/libjsparser \ -I src/libecmaobjects \ @@ -129,12 +135,12 @@ debug.stdm32f4.bin: debug.stdm32f4.elf debug: clean mkdir -p $(OUT_DIR)/debug.host/ $(CC) $(CFLAGS) $(DEBUG_OPTIONS) $(DEFINES) $(TARGET_HOST) \ - $(SOURCES) $(MAIN_MODULE_SRC) -o $(OUT_DIR)/debug.host/$(TARGET) + $(SOURCES) $(SOURCES_LINUX) $(MAIN_MODULE_SRC) -o $(OUT_DIR)/debug.host/$(TARGET) release: clean mkdir -p $(OUT_DIR)/release.host/ $(CC) $(CFLAGS) $(RELEASE_OPTIONS) $(DEFINES) $(TARGET_HOST) \ - $(SOURCES) $(MAIN_MODULE_SRC) -o $(OUT_DIR)/release.host/$(TARGET) + $(SOURCES) $(SOURCES_LINUX) $(MAIN_MODULE_SRC) -o $(OUT_DIR)/release.host/$(TARGET) $(STRIP) $(OUT_DIR)/release.host/$(TARGET) tests: @@ -142,7 +148,7 @@ tests: for unit_test in $(UNITTESTS); \ do \ $(CC) -O3 $(CFLAGS) $(DEBUG_OPTIONS) $(DEFINES) $(TARGET_HOST) \ - $(SOURCES) $(UNITTESTS_SRC_DIR)/"$$unit_test".c -o $(OUT_DIR)/tests.host/"$$unit_test"; \ + $(SOURCES) $(SOURCES_LINUX) $(UNITTESTS_SRC_DIR)/"$$unit_test".c -o $(OUT_DIR)/tests.host/"$$unit_test"; \ done clean: diff --git a/src/globals.h b/src/globals.h index 601af677e..c70b1beb5 100644 --- a/src/globals.h +++ b/src/globals.h @@ -16,7 +16,6 @@ #ifndef JERRY_GLOBALS_H #define JERRY_GLOBALS_H -#include #include #include @@ -38,6 +37,7 @@ typedef signed int int32_t; */ #define __unused __attribute__((unused)) #define __packed __attribute__((packed)) +#define __noreturn __attribute__((noreturn)) /** * Constants @@ -68,8 +68,10 @@ typedef signed int int32_t; */ extern uint32_t jerry_UnreferencedExpression; +extern void __noreturn jerry_AssertFail( const char *assertion, const char *file, const uint32_t line); + #ifndef JERRY_NDEBUG -#define JERRY_ASSERT( x ) assert( x ) +#define JERRY_ASSERT( x ) do { if ( __builtin_expect( !( x ), 0 ) ) { jerry_AssertFail( #x, __FILE__, __LINE__); } } while(0) #else /* !JERRY_NDEBUG */ #define JERRY_ASSERT( x ) (void) (x) #endif /* !JERRY_NDEBUG */ diff --git a/src/libjsparser/mappings.h b/src/libjsparser/mappings.h index 6536bca0e..ffcbc76f1 100644 --- a/src/libjsparser/mappings.h +++ b/src/libjsparser/mappings.h @@ -17,7 +17,7 @@ #define MAPPINGS_H #ifndef __HOST -#include "../jerry-libc.h" +#include "jerry-libc.h" #include "allocator.h" #include diff --git a/src/jerry-libc.c b/src/libruntime/jerry-libc.c similarity index 97% rename from src/jerry-libc.c rename to src/libruntime/jerry-libc.c index f8b599a88..94922f0b8 100644 --- a/src/jerry-libc.c +++ b/src/libruntime/jerry-libc.c @@ -22,6 +22,7 @@ #include extern int vprintf (__const char *__restrict __format, __builtin_va_list __arg); +extern void __noreturn exit(int status); /** * memset @@ -115,12 +116,11 @@ __putchar (int c) return __printf ("%c", c); } -/** exit - cause normal process termination. Infinite loop. */ -void -__exit (int status __unused) +/** exit - cause normal process termination */ +void __noreturn +__exit (int status) { - for (;;) - ; + exit( status); } /** Compare two strings. return an integer less than, equal to, or greater than zero diff --git a/src/jerry-libc.h b/src/libruntime/jerry-libc.h similarity index 97% rename from src/jerry-libc.h rename to src/libruntime/jerry-libc.h index 09619e95f..9834e24ef 100644 --- a/src/jerry-libc.h +++ b/src/libruntime/jerry-libc.h @@ -26,7 +26,7 @@ extern int __memcmp (const void *s1, const void *s2, size_t n); extern void *__memcpy (void *s1, const void *s2, size_t n); extern int __printf (const char *format, ...); extern int __putchar (int); -extern void __exit (int); +extern void __noreturn __exit (int); extern int __strcmp (const char *, const char *); extern int __strncmp (const char *, const char *, size_t); diff --git a/src/libruntime/linux/jerry-assert.c b/src/libruntime/linux/jerry-assert.c new file mode 100644 index 000000000..c947f3b21 --- /dev/null +++ b/src/libruntime/linux/jerry-assert.c @@ -0,0 +1,31 @@ +/* Copyright 2014 Samsung Electronics Co., Ltd. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "globals.h" +#include "jerry-libc.h" + +/** + * Handle failed assertion + */ +void __noreturn +jerry_AssertFail( const char *assertion, /**< assertion condition string */ + const char *file, /**< file name */ + const uint32_t line) /** line */ +{ + __printf("Assertion '%s' failed at %s:%u\n", + assertion, file, line); + + __exit( 1); +} /* jerry_AssertFail */ diff --git a/src/pretty-printer.c b/src/libruntime/pretty-printer.c similarity index 100% rename from src/pretty-printer.c rename to src/libruntime/pretty-printer.c diff --git a/src/pretty-printer.h b/src/libruntime/pretty-printer.h similarity index 100% rename from src/pretty-printer.h rename to src/libruntime/pretty-printer.h diff --git a/src/libruntime/stm32f4/jerry-assert.c b/src/libruntime/stm32f4/jerry-assert.c new file mode 100644 index 000000000..949d80110 --- /dev/null +++ b/src/libruntime/stm32f4/jerry-assert.c @@ -0,0 +1,32 @@ +/* Copyright 2014 Samsung Electronics Co., Ltd. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "globals.h" +#include "jerry-libc.h" + +/** + * Handle failed assertion + */ +void __noreturn +jerry_AssertFail( const char *assertion, /**< assertion condition string */ + const char *file, /**< file name */ + const uint32_t line) /** line */ +{ + /** + * TODO: Blink with LEDs. + * Save call stack? + */ + while( true ); +} /* jerry_AssertFail */