From 224c509ff32384189770c6832ebfb2de9d800455 Mon Sep 17 00:00:00 2001 From: Ruben Ayrapetyan Date: Thu, 10 Jul 2014 21:02:48 +0400 Subject: [PATCH] Merge with master. --- Makefile | 4 ++-- src/generated.h | 2 ++ src/libjsparser/lexer.c | 16 +++++++++------- src/libjsparser/parser.c | 15 +++++++++------ src/libruntime/linux/jerry-assert.c | 7 ++++--- src/libruntime/pretty-printer.c | 6 +++--- src/libruntime/stm32f4/jerry-assert.c | 6 +++--- src/main.c | 9 +++++++-- tools/generator.sh | 7 +++++-- 9 files changed, 44 insertions(+), 28 deletions(-) diff --git a/Makefile b/Makefile index 9f36c4aab..b3ce916e5 100644 --- a/Makefile +++ b/Makefile @@ -89,7 +89,7 @@ SIZE = size STRIP = strip # General flags -CFLAGS ?= $(INCLUDES) -std=c99 #-fdiagnostics-color=always +CFLAGS ?= $(INCLUDES) -std=c99 -Werror #-fdiagnostics-color=always CFLAGS += -Wall -Wextra -Wpedantic -Wlogical-op -Winline CFLAGS += -Wformat-nonliteral -Winit-self -Wstack-protector CFLAGS += -Wconversion -Wsign-conversion -Wformat-security @@ -103,7 +103,7 @@ MCU_CFLAGS += -ffunction-sections -fdata-sections -nostdlib -fno-common LDFLAGS = -nostartfiles -T$(LNK_SCRIPT_STM32F4) DEBUG_OPTIONS = -g3 -O0 # -fsanitize=address -RELEASE_OPTIONS = -Os -flto -Werror -DJERRY_NDEBUG +RELEASE_OPTIONS = -Os -flto -DJERRY_NDEBUG DEFINES = -DMEM_HEAP_CHUNK_SIZE=256 -DMEM_HEAP_AREA_SIZE=32768 -DMEM_STATS TARGET_HOST = -D__HOST diff --git a/src/generated.h b/src/generated.h index c45b513df..fae8816bc 100644 --- a/src/generated.h +++ b/src/generated.h @@ -13,6 +13,8 @@ * limitations under the License. */ +#include "globals.h" + static const char* generated_source __unused = "" "while (true) {\n" "LEDToggle (LED3);\n" diff --git a/src/libjsparser/lexer.c b/src/libjsparser/lexer.c index 805e3f1d8..312e1e14d 100644 --- a/src/libjsparser/lexer.c +++ b/src/libjsparser/lexer.c @@ -13,6 +13,7 @@ * limitations under the License. */ +#include "allocator.h" #include "jerry-libc.h" #include "lexer.h" @@ -115,7 +116,7 @@ get_char (size_t i) if (buffer == NULL) { buffer = (char *) malloc (BUFFER_SIZE); - error = fread (buffer, 1, BUFFER_SIZE, file); + error = __fread (buffer, 1, BUFFER_SIZE, file); if (error == 0) return '\0'; if (error < BUFFER_SIZE) @@ -139,7 +140,7 @@ get_char (size_t i) token_start = buffer_start; buffer = buffer_start + token_size; /* Read more characters form input file. */ - error = fread (buffer + tail_size, 1, BUFFER_SIZE - tail_size - token_size, file); + error = __fread (buffer + tail_size, 1, BUFFER_SIZE - tail_size - token_size, file); if (error == 0) return '\0'; if (error < BUFFER_SIZE - tail_size - token_size) @@ -150,7 +151,7 @@ get_char (size_t i) { __memmove (buffer_start, buffer, tail_size); buffer = buffer_start; - error = fread (buffer + tail_size, 1, BUFFER_SIZE - tail_size, file); + error = __fread (buffer + tail_size, 1, BUFFER_SIZE - tail_size, file); if (error == 0) return '\0'; if (error < BUFFER_SIZE - tail_size) @@ -555,7 +556,7 @@ parse_string (void) index++; } - __memset (index, '\0', length - (index - tok)); + __memset (index, '\0', length - (size_t) (index - tok)); token_start = NULL; // Eat up '"' @@ -586,7 +587,7 @@ lexer_set_file (FILE *ex_file) { JERRY_ASSERT (ex_file); file = ex_file; - lexer_debug_log = fopen ("lexer.log", "w"); + lexer_debug_log = __fopen ("lexer.log", "w"); saved_token = empty_token; } #else @@ -690,7 +691,7 @@ lexer_next_token (void) return (token) { .type = TOK_NEWLINE, .data.none = NULL }; else return -#ifdef JERRY_NDEBUG +#ifdef __HOST lexer_next_token_private (); #else lexer_next_token (); @@ -806,4 +807,5 @@ void lexer_dump_buffer_state (void) { __printf ("%s\n", buffer); -} \ No newline at end of file +} + diff --git a/src/libjsparser/parser.c b/src/libjsparser/parser.c index 3ce235bcd..88955be1a 100644 --- a/src/libjsparser/parser.c +++ b/src/libjsparser/parser.c @@ -17,9 +17,11 @@ #include "lexer.h" #include "parser.h" -/* FIXME: */ -extern void lexer_dump_buffer_state(); +extern void lexer_dump_buffer_state(void); + /* FIXME: Make general fatal function call it from libjsparser's fatal */ +extern void fatal(int); + void fatal (int code) { @@ -153,7 +155,7 @@ static void push_scope (int type) { #ifdef __HOST - fprintf (debug_file, "push_scope: 0x%x\n", type); + __fprintf (debug_file, "push_scope: 0x%x\n", type); #endif current_scopes[scope_index++] = (scope) { .type = type, .was_stmt = false }; } @@ -162,7 +164,7 @@ static void pop_scope (void) { #ifdef __HOST - fprintf (debug_file, "pop_scope: 0x%x\n", current_scopes[scope_index - 1].type); + __fprintf (debug_file, "pop_scope: 0x%x\n", current_scopes[scope_index - 1].type); #endif scope_index--; } @@ -173,7 +175,7 @@ assert_keyword (keyword kw) if (tok.type != TOK_KEYWORD || tok.data.kw != kw) { #ifdef __HOST - printf ("assert_keyword: 0x%x\n", kw); + __printf ("assert_keyword: 0x%x\n", kw); #endif JERRY_UNREACHABLE (); } @@ -191,7 +193,7 @@ current_token_must_be(token_type tt) if (tok.type != tt) { #ifdef __HOST - printf ("current_token_must_be: 0x%x\n", tt); + __printf ("current_token_must_be: 0x%x\n", tt); #endif fatal (ERR_PARSER); } @@ -1393,3 +1395,4 @@ parser_init (void) debug_file = __fopen ("parser.log", "w"); #endif } + diff --git a/src/libruntime/linux/jerry-assert.c b/src/libruntime/linux/jerry-assert.c index 6d0d84458..00775bfdf 100644 --- a/src/libruntime/linux/jerry-assert.c +++ b/src/libruntime/linux/jerry-assert.c @@ -20,12 +20,13 @@ * Handle failed assertion */ void __noreturn -jerry_AssertFail( const char *assertion, /**< assertion condition string */ - const char *file, /**< file name */ - const uint32_t line) /** line */ +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( -ERR_GENERAL); } /* jerry_AssertFail */ + diff --git a/src/libruntime/pretty-printer.c b/src/libruntime/pretty-printer.c index 5a8ab75b2..63ab02e84 100644 --- a/src/libruntime/pretty-printer.c +++ b/src/libruntime/pretty-printer.c @@ -404,7 +404,7 @@ pp_keyword (keyword kw) } static void -intend () +intend (void) { for (int i = 0; i < intendation; i++) __putchar (' '); @@ -548,7 +548,7 @@ dump_postfix (operand op, const char *operation) static void pp_assignment_expression (assignment_expression expr) { - if (expr.var) + if (expr.oper != AO_NONE && expr.var) __printf ("%s", expr.var); switch (expr.oper) @@ -1087,7 +1087,7 @@ pp_statement (statement stmt) prev_stmt = stmt.type; } -void pp_finish () +void pp_finish (void) { if (prev_stmt == STMT_BLOCK_END) __putchar ('\n'); diff --git a/src/libruntime/stm32f4/jerry-assert.c b/src/libruntime/stm32f4/jerry-assert.c index b6b3b5952..abe859184 100644 --- a/src/libruntime/stm32f4/jerry-assert.c +++ b/src/libruntime/stm32f4/jerry-assert.c @@ -20,9 +20,9 @@ * Handle failed assertion */ void __noreturn -jerry_AssertFail( const char *assertion, /**< assertion condition string */ - const char *file, /**< file name */ - const uint32_t line) /** line */ +jerry_AssertFail(const char *assertion, /**< assertion condition string */ + const char *file, /**< file name */ + const uint32_t line) /** line */ { __exit( -ERR_GENERAL); } /* jerry_AssertFail */ diff --git a/src/main.c b/src/main.c index a2a89f7d0..292e1d7d2 100644 --- a/src/main.c +++ b/src/main.c @@ -28,7 +28,12 @@ #include "globals.h" #include "interpreter.h" #include "jerry-libc.h" -#include "mem-allocator.h" +#include "lexer.h" +#include "parser.h" +#include "pretty-printer.h" + +/* FIXME: Make general fatal function call it from libjsparser's fatal */ +extern void fatal(int); void fake_exit (void); @@ -119,7 +124,7 @@ main (int argc, char **argv) dump_ast = true; #ifdef __HOST - file = fopen (file_name, "r"); + file = __fopen (file_name, "r"); if (file == NULL) { diff --git a/tools/generator.sh b/tools/generator.sh index b8af8754f..af4ae2fa5 100755 --- a/tools/generator.sh +++ b/tools/generator.sh @@ -14,9 +14,12 @@ #!/bin/bash -echo "static const char* generated_source = \"\"" > "generated.h" +echo "#include \"globals.h\"" > "generated.h" +echo "" >> "generated.h" +echo "static const char* generated_source = \"\"" >> "generated.h" while read line do echo "\"$line\n\"" >> "generated.h" done < $1 -echo ";" >> "generated.h" \ No newline at end of file +echo ";" >> "generated.h" +