Refactoring of libcoreint part1

This commit is contained in:
e.gavrin
2014-08-22 21:13:35 +04:00
parent 6fbf3e4eed
commit d4a9d9430e
26 changed files with 1874 additions and 1959 deletions
+4 -4
View File
@@ -19,7 +19,7 @@
#define NAME_TO_ID(op) (__op__idx_##op)
#define OPCODE_SIZE(op) \
sizeof (struct __op_##op) + 1,
sizeof (__op_##op) + 1,
static uint8_t opcode_sizes[] = {
OP_LIST (OPCODE_SIZE)
@@ -28,7 +28,7 @@ static uint8_t opcode_sizes[] = {
static bool
opcodes_equal (const OPCODE *opcodes1, OPCODE *opcodes2, uint16_t size)
{
{
uint16_t i;
for (i = 0; i < size; i++)
{
@@ -37,11 +37,11 @@ opcodes_equal (const OPCODE *opcodes1, OPCODE *opcodes2, uint16_t size)
if (opcode_num1 != opcode_num2)
return false;
if (opcode_num1 == NAME_TO_ID (nop) || opcode_num1 == NAME_TO_ID (ret)
|| opcode_num1 == NAME_TO_ID (end_with))
return true;
for (j = 1; j < opcode_sizes[opcode_num1]; j++)
if (((uint8_t*)&opcodes1[i])[j] != ((uint8_t*)&opcodes2[i])[j])
return false;
@@ -16,7 +16,7 @@
#include "globals.h"
#include "interpreter.h"
#include "mem-allocator.h"
#include "opcodes.h"
#include "opcodes-support.h"
#include "serializer.h"
/**
+1 -1
View File
@@ -16,7 +16,7 @@
#include "globals.h"
#include "interpreter.h"
#include "mem-allocator.h"
#include "opcodes.h"
#include "opcodes-support.h"
#include "serializer.h"
/**
+1 -1
View File
@@ -16,7 +16,7 @@
#include "globals.h"
#include "interpreter.h"
#include "mem-allocator.h"
#include "opcodes.h"
#include "opcodes-support.h"
#include "serializer.h"
/**
+1 -1
View File
@@ -16,7 +16,7 @@
#include "globals.h"
#include "interpreter.h"
#include "mem-allocator.h"
#include "opcodes.h"
#include "opcodes-support.h"
#include "serializer.h"
/**
+2 -2
View File
@@ -16,7 +16,7 @@
#include "globals.h"
#include "interpreter.h"
#include "mem-allocator.h"
#include "opcodes.h"
#include "opcodes-support.h"
#include "serializer.h"
#include "optimizer-passes.h"
#include "jerry-libc.h"
@@ -91,4 +91,4 @@ main( int __unused argc,
return 1;
return 0;
}
}
+31 -30
View File
@@ -22,6 +22,7 @@
#include "lexer.h"
#include "parser.h"
#include "mem-allocator.h"
#include "opcodes-support.h"
#define MAX_STRINGS 100
#define MAX_NUMS 25
@@ -55,43 +56,43 @@ main( int __unused argc,
offset = serializer_dump_strings (strings, strings_num);
serializer_dump_nums (nums, nums_count, offset, strings_num);
parser_init ();
parser_parse_program ();
opcodes = deserialize_bytecode ();
serializer_print_opcodes ();
if (!opcodes_equal (opcodes, (OPCODE[]) {
[0] = getop_reg_var_decl (2, 5), // var tmp2 .. tmp5;
[1] = getop_var_decl (0), // var i;
[2] = getop_var_decl (1), // var j;
[3] = getop_assignment (2, 1, 0), // tmp2 = 0;
[4] = getop_assignment (0, 4, 2), // i = tmp2;
[5] = getop_assignment (4, 1, 10),// tmp4 = 10;
[6] = getop_less_than (3, 0, 4), // tmp3 = i < tmp4;
[7] = getop_is_false_jmp (3, 14), // if (!tmp3) goto 14;
[8] = getop_jmp_down (3), // goto 11;
[9] = getop_post_incr (5, 0), // tmp5 = i ++;
[10] = getop_jmp_up (5), // goto 5;
[11] = getop_assignment (2, 1, 10),// tmp2 = 10;
[12] = getop_assignment (1, 4, 2), // j = tmp2;
[13] = getop_jmp_up (5), // goto 8;
[14] = getop_nop (), // ;
[15] = getop_assignment (2, 1, 0), // tmp2 = 0;
[16] = getop_assignment (0, 4, 2), // i = tmp2;
[17] = getop_assignment (4, 1, 10),// tmp7 = 10;
[18] = getop_less_than (3, 0, 4), // tmp3 = i < tmp7;
[19] = getop_is_false_jmp (3, 27), // if (!tmp3) goto 27;
[20] = getop_jmp_down (3), // goto 23;
[21] = getop_post_incr (5, 0), // tmp5 = i ++;
[22] = getop_jmp_up (5), // goto 17;
[23] = getop_nop (), // ;
[24] = getop_assignment (2, 1, 10),// tmp2 = 10;
[25] = getop_assignment (1, 4, 5), // j = tmp2;
[26] = getop_jmp_up (5), // goto 21;
[27] = getop_exitval (0) // exit 0;
[0] = getop_reg_var_decl (2, 5), // var tmp2 .. tmp5;
[1] = getop_var_decl (0), // var i;
[2] = getop_var_decl (1), // var j;
[3] = getop_assignment (2, 1, 0), // tmp2 = 0;
[4] = getop_assignment (0, 4, 2), // i = tmp2;
[5] = getop_assignment (4, 1, 10),// tmp4 = 10;
[6] = getop_less_than (3, 0, 4), // tmp3 = i < tmp4;
[7] = getop_is_false_jmp (3, 14), // if (!tmp3) goto 14;
[8] = getop_jmp_down (3), // goto 11;
[9] = getop_post_incr (5, 0), // tmp5 = i ++;
[10] = getop_jmp_up (5), // goto 5;
[11] = getop_assignment (2, 1, 10),// tmp2 = 10;
[12] = getop_assignment (1, 4, 2), // j = tmp2;
[13] = getop_jmp_up (5), // goto 8;
[14] = getop_nop (), // ;
[15] = getop_assignment (2, 1, 0), // tmp2 = 0;
[16] = getop_assignment (0, 4, 2), // i = tmp2;
[17] = getop_assignment (4, 1, 10),// tmp7 = 10;
[18] = getop_less_than (3, 0, 4), // tmp3 = i < tmp7;
[19] = getop_is_false_jmp (3, 27), // if (!tmp3) goto 27;
[20] = getop_jmp_down (3), // goto 23;
[21] = getop_post_incr (5, 0), // tmp5 = i ++;
[22] = getop_jmp_up (5), // goto 17;
[23] = getop_nop (), // ;
[24] = getop_assignment (2, 1, 10),// tmp2 = 10;
[25] = getop_assignment (1, 4, 5), // j = tmp2;
[26] = getop_jmp_up (5), // goto 21;
[27] = getop_exitval (0) // exit 0;
}, 28))
return 1;
return 0;
}
}
+6 -6
View File
@@ -16,7 +16,7 @@
#include "globals.h"
#include "interpreter.h"
#include "mem-allocator.h"
#include "opcodes.h"
#include "opcodes-support.h"
#include "serializer.h"
#include "optimizer-passes.h"
#include "jerry-libc.h"
@@ -35,12 +35,12 @@ main( int __unused argc,
[0] = getop_reg_var_decl (5, 5), // tmp6
[1] = getop_assignment (0, OPCODE_ARG_TYPE_STRING, 1), // a = "b"
[2] = getop_var_decl (1), // var b
[3] = getop_func_decl_0 (2), // function c()
[3] = getop_func_decl_0 (2), // function c()
[4] = getop_jmp_down (3), // {
[5] = getop_var_decl (1), // var b
[6] = getop_retval (1), // return b; }
[7] = getop_assignment (5, OPCODE_ARG_TYPE_STRING, 3), // "use strict"
[8] = getop_exitval (0)
[8] = getop_exitval (0)
};
mem_init();
@@ -60,16 +60,16 @@ main( int __unused argc,
if (!opcodes_equal (opcodes, (OPCODE[]) {
[0] = getop_reg_var_decl (5, 5), // tmp6
[1] = getop_assignment (5, OPCODE_ARG_TYPE_STRING, 3), // "use strict"
[2] = getop_func_decl_0 (2), // function c()
[2] = getop_func_decl_0 (2), // function c()
[3] = getop_jmp_down (3), // {
[4] = getop_var_decl (1), // var b
[5] = getop_retval (1), // return b; }
[6] = getop_var_decl (1), // var b
[7] = getop_assignment (0, OPCODE_ARG_TYPE_STRING, 1), // a = "b"
[8] = getop_exitval (0)
[8] = getop_exitval (0)
}, 9))
return 1;
return 0;
}
}
+1 -1
View File
@@ -16,7 +16,7 @@
#include "globals.h"
#include "interpreter.h"
#include "mem-allocator.h"
#include "opcodes.h"
#include "opcodes-support.h"
#include "serializer.h"
/**
+1 -1
View File
@@ -16,7 +16,7 @@
#include "globals.h"
#include "interpreter.h"
#include "mem-allocator.h"
#include "opcodes.h"
#include "opcodes-support.h"
#include "serializer.h"
/**
@@ -16,7 +16,7 @@
#include "globals.h"
#include "interpreter.h"
#include "mem-allocator.h"
#include "opcodes.h"
#include "opcodes-support.h"
#include "serializer.h"
/**