From 64e286f766c65adeca431dd8381e8d37a1717133 Mon Sep 17 00:00:00 2001 From: Ilmir Usmanov Date: Tue, 14 Oct 2014 15:05:48 +0400 Subject: [PATCH] Enable pretty-printer only on host and debug --- src/globals.h | 7 +++++++ src/liboptimizer/pretty-printer.c | 3 +++ src/liboptimizer/pretty-printer.h | 3 +++ src/liboptimizer/serializer.c | 10 ++++++++++ src/main.c | 5 +++++ 5 files changed, 28 insertions(+) diff --git a/src/globals.h b/src/globals.h index 0dc8318b9..df797806f 100644 --- a/src/globals.h +++ b/src/globals.h @@ -177,4 +177,11 @@ extern void __noreturn jerry_exit (jerry_status_t code); #define JERRY_MIN(v1, v2) ((v1 < v2) ? v1 : v2) #define JERRY_MAX(v1, v2) ((v1 < v2) ? v2 : v1) +/** + * Enable --show-opcodes key. + */ +#if defined (__TARGET_HOST_x64) && !defined (JERRY_NDEBUG) +#define JERRY_ENABLE_PP +#endif + #endif /* !JERRY_GLOBALS_H */ diff --git a/src/liboptimizer/pretty-printer.c b/src/liboptimizer/pretty-printer.c index 861c244bc..0de99865b 100644 --- a/src/liboptimizer/pretty-printer.c +++ b/src/liboptimizer/pretty-printer.c @@ -13,6 +13,8 @@ * limitations under the License. */ +#include "globals.h" +#ifdef JERRY_ENABLE_PP #include "pretty-printer.h" #include "jerry-libc.h" #include "lexer.h" @@ -646,3 +648,4 @@ pp_opcode (opcode_counter_t oc, opcode_t opcode, bool is_rewrite) __printf ("\n"); } +#endif /* JERRY_ENABLE_PP */ diff --git a/src/liboptimizer/pretty-printer.h b/src/liboptimizer/pretty-printer.h index e430b9140..b6ad246e3 100644 --- a/src/liboptimizer/pretty-printer.h +++ b/src/liboptimizer/pretty-printer.h @@ -16,11 +16,14 @@ #ifndef PRETTY_PRINTER #define PRETTY_PRINTER +#include "globals.h" +#ifdef JERRY_ENABLE_PP #include "interpreter.h" #include "lp-string.h" void pp_opcode (opcode_counter_t, opcode_t, bool); void pp_strings (const lp_string *, uint8_t); void pp_nums (const ecma_number_t *, uint8_t, uint8_t); +#endif // JERRY_ENABLE_PP #endif // PRETTY_PRINTER diff --git a/src/liboptimizer/serializer.c b/src/liboptimizer/serializer.c index b83b1f26e..118edaa85 100644 --- a/src/liboptimizer/serializer.c +++ b/src/liboptimizer/serializer.c @@ -13,6 +13,7 @@ * limitations under the License. */ +#include "globals.h" #include "serializer.h" #include "parser.h" #include "jerry-libc.h" @@ -39,10 +40,13 @@ void serializer_dump_strings_and_nums (const lp_string strings[], uint8_t strs_count, const ecma_number_t nums[], uint8_t nums_count) { +#ifdef JERRY_ENABLE_PP if (print_opcodes) { pp_strings (strings, strs_count); + pp_nums (nums, nums_count, strs_count); } +#endif bytecode_data.strs_count = strs_count; bytecode_data.nums_count = nums_count; @@ -55,10 +59,12 @@ serializer_dump_opcode (opcode_t opcode) { JERRY_ASSERT (scopes_tree_opcodes_num (current_scope) < MAX_OPCODES); +#ifdef JERRY_ENABLE_PP if (print_opcodes) { pp_opcode (scopes_tree_opcodes_num (current_scope), opcode, false); } +#endif scopes_tree_add_opcode (current_scope, opcode); } @@ -74,15 +80,18 @@ serializer_rewrite_opcode (const opcode_counter_t loc, opcode_t opcode) { scopes_tree_set_opcode (current_scope, loc, opcode); +#ifdef JERRY_ENABLE_PP if (print_opcodes) { pp_opcode (loc, opcode, true); } +#endif } void serializer_print_opcodes (void) { +#ifdef JERRY_ENABLE_PP opcode_counter_t loc; if (!print_opcodes) @@ -96,6 +105,7 @@ serializer_print_opcodes (void) { pp_opcode (loc, bytecode_data.opcodes[loc], false); } +#endif } /* Make lp_strings also zero-terminated. */ diff --git a/src/main.c b/src/main.c index 80ad55828..ec41a81ab 100644 --- a/src/main.c +++ b/src/main.c @@ -172,7 +172,12 @@ main (int argc __unused, } else if (!__strcmp ("--show-opcodes", argv[i])) { +#ifdef JERRY_ENABLE_PP show_opcodes = true; +#else + __printf ("Ignoring --show-opcodes since target is not x86_64 or debug is not enabled.\n"); + show_opcodes = false; +#endif } else {