This commit is contained in:
Ilmir Usmanov
2014-07-24 19:50:37 +04:00
parent c2f82eefc0
commit 1f3b5a4c29
14 changed files with 182 additions and 34 deletions
+1
View File
@@ -22,6 +22,7 @@ nbproject
*~ *~
js.files js.files
core core
**.orig
# ctags and ID database # ctags and ID database
tags tags
+3 -1
View File
@@ -162,7 +162,8 @@ SOURCES_JERRY = \
$(wildcard ./src/libecmaobjects/*.c) \ $(wildcard ./src/libecmaobjects/*.c) \
$(wildcard ./src/libecmaoperations/*.c) \ $(wildcard ./src/libecmaoperations/*.c) \
$(wildcard ./src/liballocator/*.c) \ $(wildcard ./src/liballocator/*.c) \
$(wildcard ./src/libcoreint/*.c) ) \ $(wildcard ./src/libcoreint/*.c) \
$(wildcard ./src/liboptimizer/*.c) ) \
$(wildcard src/libruntime/target/$(TARGET_SYSTEM)/*.c) $(wildcard src/libruntime/target/$(TARGET_SYSTEM)/*.c)
INCLUDES_JERRY = \ INCLUDES_JERRY = \
@@ -173,6 +174,7 @@ INCLUDES_JERRY = \
-I src/libecmaobjects \ -I src/libecmaobjects \
-I src/libecmaoperations \ -I src/libecmaoperations \
-I src/liballocator \ -I src/liballocator \
-I src/liboptimizer \
-I src/libcoreint -I src/libcoreint
ifeq ($(OPTION_NDEBUG),enable) ifeq ($(OPTION_NDEBUG),enable)
+20
View File
@@ -256,6 +256,26 @@ OP_CODE_DECL (in, T_IDX_IDX_IDX,
var_left, var_left,
var_right) var_right)
/** dst = var_right++. */
OP_CODE_DECL (post_incr, T_IDX_IDX,
dst,
var_right)
/** dst = var_right--. */
OP_CODE_DECL (post_decr, T_IDX_IDX,
dst,
var_right)
/** dst = ++var_right. */
OP_CODE_DECL (pre_incr, T_IDX_IDX,
dst,
var_right)
/** dst = --var_right. */
OP_CODE_DECL (pre_decr, T_IDX_IDX,
dst,
var_right)
// Assignment operators. // Assignment operators.
// Assign value to LEFT operand based on value of RIGHT operand. // Assign value to LEFT operand based on value of RIGHT operand.
+8
View File
@@ -409,6 +409,10 @@ do_number_arithmetic(struct __int_data *int_data, /**< interpreter context */
op(b_not) \ op(b_not) \
op(instanceof) \ op(instanceof) \
op(in) \ op(in) \
op(post_incr) \
op(post_decr) \
op(pre_incr) \
op(pre_decr) \
static char __unused unimplemented_list_end static char __unused unimplemented_list_end
#define DEFINE_UNIMPLEMENTED_OP(op) \ #define DEFINE_UNIMPLEMENTED_OP(op) \
@@ -950,6 +954,10 @@ GETOP_IMPL_1 (jmp, opcode_idx)
GETOP_IMPL_1 (jmp_up, opcode_count) GETOP_IMPL_1 (jmp_up, opcode_count)
GETOP_IMPL_1 (jmp_down, opcode_count) GETOP_IMPL_1 (jmp_down, opcode_count)
GETOP_IMPL_3 (addition, dst, var_left, var_right) GETOP_IMPL_3 (addition, dst, var_left, var_right)
GETOP_IMPL_2 (post_incr, dst, var_right)
GETOP_IMPL_2 (post_decr, dst, var_right)
GETOP_IMPL_2 (pre_incr, dst, var_right)
GETOP_IMPL_2 (pre_decr, dst, var_right)
GETOP_IMPL_3 (substraction, dst, var_left, var_right) GETOP_IMPL_3 (substraction, dst, var_left, var_right)
GETOP_IMPL_3 (division, dst, var_left, var_right) GETOP_IMPL_3 (division, dst, var_left, var_right)
GETOP_IMPL_3 (multiplication, dst, var_left, var_right) GETOP_IMPL_3 (multiplication, dst, var_left, var_right)
+4
View File
@@ -110,6 +110,10 @@ typedef ecma_completion_value_t (*opfunc)(OPCODE, struct __int_data *);
op(in) op(in)
#define OP_ARITHMETIC(op) \ #define OP_ARITHMETIC(op) \
op(post_incr) \
op(post_decr) \
op(pre_incr) \
op(pre_decr) \
op(addition) \ op(addition) \
op(substraction) \ op(substraction) \
op(division) \ op(division) \
+12 -30
View File
@@ -23,9 +23,8 @@
#define INVALID_VALUE 255 #define INVALID_VALUE 255
static token tok; static token tok;
static OPCODE opcode, opcodes_buffer[MAX_OPCODES]; static OPCODE opcode;
static uint8_t current_opcode_in_buffer = 0; static T_IDX opcode_counter = 0;
static uint8_t opcode_counter = 0;
static T_IDX temp_name_stack[MAX_OPCODES], temp_name_stack_head = 0, max_temp_name; static T_IDX temp_name_stack[MAX_OPCODES], temp_name_stack_head = 0, max_temp_name;
#ifdef __HOST #ifdef __HOST
@@ -172,23 +171,6 @@ integer_one (void)
return lhs; return lhs;
} }
static void
save_opcode (void)
{
JERRY_ASSERT (current_opcode_in_buffer < MAX_OPCODES);
opcodes_buffer[current_opcode_in_buffer++] = opcode;
}
static void
dump_saved_opcodes (void)
{
uint8_t i;
for (i = 0; i < current_opcode_in_buffer; i++)
serializer_dump_opcode (&opcodes_buffer[i]);
current_opcode_in_buffer = 0;
}
/* property_name /* property_name
: Identifier : Identifier
| StringLiteral | StringLiteral
@@ -859,18 +841,18 @@ parse_left_hand_side_expression (void)
static T_IDX static T_IDX
parse_postfix_expression (void) parse_postfix_expression (void)
{ {
T_IDX expr = parse_left_hand_side_expression (); T_IDX expr = parse_left_hand_side_expression (), lhs;
tok = lexer_next_token (); tok = lexer_next_token ();
if (tok.type == TOK_DOUBLE_PLUS) if (tok.type == TOK_DOUBLE_PLUS)
{ {
opcode = getop_addition (expr, expr, integer_one ()); lhs = next_temp_name ();
save_opcode (); DUMP_OPCODE (post_incr, lhs, expr);
} }
else if (tok.type == TOK_DOUBLE_MINUS) else if (tok.type == TOK_DOUBLE_MINUS)
{ {
opcode = getop_substraction (expr, expr, integer_one ()); lhs = next_temp_name ();
save_opcode (); DUMP_OPCODE (post_decr, lhs, expr);
} }
else else
lexer_save_token (tok); lexer_save_token (tok);
@@ -890,13 +872,15 @@ parse_unary_expression (void)
switch (tok.type) switch (tok.type)
{ {
case TOK_DOUBLE_PLUS: case TOK_DOUBLE_PLUS:
lhs = next_temp_name ();
NEXT (expr, unary_expression); NEXT (expr, unary_expression);
DUMP_OPCODE (addition, expr, expr, integer_one ()); DUMP_OPCODE (pre_incr, lhs, expr);
return expr; return expr;
case TOK_DOUBLE_MINUS: case TOK_DOUBLE_MINUS:
lhs = next_temp_name ();
NEXT (expr, unary_expression); NEXT (expr, unary_expression);
DUMP_OPCODE (substraction, expr, expr, integer_one ()); DUMP_OPCODE (pre_decr, lhs, expr);
return expr; return expr;
case TOK_PLUS: case TOK_PLUS:
@@ -1198,7 +1182,7 @@ parse_assignment_expression (void)
lhs = parse_conditional_expression (&was_conditional); lhs = parse_conditional_expression (&was_conditional);
if (was_conditional) if (was_conditional)
{ {
goto end; return lhs;
} }
skip_newlines (); skip_newlines ();
@@ -1268,8 +1252,6 @@ parse_assignment_expression (void)
lexer_save_token (tok); lexer_save_token (tok);
} }
end:
dump_saved_opcodes ();
return lhs; return lhs;
} }
+57
View File
@@ -0,0 +1,57 @@
/* 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 "optimizer-passes.h"
#include "opcodes.h"
#include "deserializer.h"
#define NAME_TO_ID(op) (__op__idx_##op)
/* Reorder bytecode like
call_n ...
assignment ... +
var_?_end
to
assignment ... +
call_n ...
var_?_end
*/
static void
optimize_calls (OPCODE *opcodes)
{
OPCODE *current_opcode;
for (current_opcode = opcodes;
current_opcode->op_idx != NAME_TO_ID (exitval);
current_opcode++)
{
if (current_opcode->op_idx == NAME_TO_ID (call_n)
&& (current_opcode + 1)->op_idx == NAME_TO_ID (assignment))
{
OPCODE temp = *current_opcode;
*current_opcode = *(current_opcode + 1);
*(current_opcode + 1) = temp;
}
}
}
void
optimizer_run_passes (OPCODE* opcodes)
{
optimize_calls (opcodes);
}
+24
View File
@@ -0,0 +1,24 @@
/* 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.
*/
#ifndef OPTIMIZER_PASSES_H
#define OPTIMIZER_PASSES_H
#include "globals.h"
#include "opcodes.h"
void optimizer_run_passes (OPCODE *);
#endif // OPTIMIZER_PASSES_H
+2
View File
@@ -16,9 +16,11 @@
#pragma GCC diagnostic push #pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wpedantic" #pragma GCC diagnostic ignored "-Wpedantic"
#pragma GCC diagnostic ignored "-Wsign-conversion" #pragma GCC diagnostic ignored "-Wsign-conversion"
#ifdef __TARGET_MCU
#include "stm32f4xx.h" #include "stm32f4xx.h"
#include "stm32f4xx_gpio.h" #include "stm32f4xx_gpio.h"
#include "stm32f4xx_rcc.h" #include "stm32f4xx_rcc.h"
#endif
#pragma GCC diagnostic pop #pragma GCC diagnostic pop
#include "actuators.h" #include "actuators.h"
+2
View File
@@ -28,4 +28,6 @@ void serializer_dump_opcode (const void *);
void serializer_rewrite_opcode (const uint8_t, const void *); void serializer_rewrite_opcode (const uint8_t, const void *);
void serializer_print_opcodes (void);
#endif // SERIALIZER_H #endif // SERIALIZER_H
+8 -1
View File
@@ -22,11 +22,18 @@ uint8_t num_size = 0;
const ecma_char_t * const ecma_char_t *
deserialize_string_by_id (uint8_t id) deserialize_string_by_id (uint8_t id)
{ {
uint8_t size = *bytecode_data, *data = bytecode_data, offset; uint8_t size, *data, offset;
if (bytecode_data == NULL)
return NULL;
size = *bytecode_data;
if (id >= size) if (id >= size)
return NULL; return NULL;
data = bytecode_data;
data += id + 1; data += id + 1;
offset = *data; offset = *data;
+24
View File
@@ -146,3 +146,27 @@ serializer_rewrite_opcode (const uint8_t loc, const void *opcode)
__printf ("// REWRITE\n"); __printf ("// REWRITE\n");
} }
void
serializer_print_opcodes (void)
{
int loc = -1, i;
OPCODE* opcode;
int opcode_num;
__printf ("AFTER OPTIMIZER:\n");
do
{
loc++;
opcode = bytecode_opcodes + loc;
opcode_num = (int)((char*)opcode)[0];
__printf ("%03d: %20s ", loc, opcode_names[opcode_num]);
for (i = 1; i < opcode_sizes[opcode_num]; i++)
__printf ("%4d ", ((char*)opcode)[i]);
__printf ("\n");
}
while (opcode->op_idx != __op__idx_exitval);
}
@@ -46,5 +46,10 @@ serializer_rewrite_opcode (const uint8_t offset, const void *opcode)
JERRY_UNIMPLEMENTED_REF_UNUSED_VARS( offset, opcode); JERRY_UNIMPLEMENTED_REF_UNUSED_VARS( offset, opcode);
} }
void
serializer_print_opcodes (void)
{
JERRY_UNREACHABLE ();
}
TODO (Dump memory) TODO (Dump memory)
+12 -2
View File
@@ -27,9 +27,9 @@
#define LED_ORANGE 13 #define LED_ORANGE 13
#define LED_RED 14 #define LED_RED 14
#define LED_BLUE 15 #define LED_BLUE 15
#include "generated.h"
#endif #endif
#include "generated.h"
#include "globals.h" #include "globals.h"
#include "interpreter.h" #include "interpreter.h"
#include "jerry-libc.h" #include "jerry-libc.h"
@@ -37,6 +37,7 @@
#include "parser.h" #include "parser.h"
#include "serializer.h" #include "serializer.h"
#include "deserializer.h" #include "deserializer.h"
#include "optimizer-passes.h"
#define MAX_STRINGS 100 #define MAX_STRINGS 100
#define MAX_NUMS 25 #define MAX_NUMS 25
@@ -49,6 +50,7 @@ jerry_run( const char *script_source,
int nums[MAX_NUMS]; int nums[MAX_NUMS];
uint8_t strings_num, nums_count; uint8_t strings_num, nums_count;
uint8_t offset; uint8_t offset;
const OPCODE *opcodes;
mem_init(); mem_init();
@@ -68,7 +70,15 @@ jerry_run( const char *script_source,
parser_init (); parser_init ();
parser_parse_program (); parser_parse_program ();
init_int (deserialize_bytecode ()); opcodes = deserialize_bytecode ();
optimizer_run_passes ((OPCODE *) opcodes);
#ifdef __HOST
serializer_print_opcodes ();
#endif
init_int (opcodes);
run_int (); run_int ();
} /* jerry_run */ } /* jerry_run */