Skip to content
This repository has been archived by the owner on Jun 3, 2021. It is now read-only.

Commit

Permalink
[core]fix opcode rax parser error (#1588)
Browse files Browse the repository at this point in the history
  • Loading branch information
jianhan-he authored and YorkShen committed Sep 27, 2018
1 parent 23f9a20 commit 7736aed
Show file tree
Hide file tree
Showing 3 changed files with 55 additions and 0 deletions.
1 change: 1 addition & 0 deletions weex_core/Source/core/data_render/binary_file.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ namespace data_render {
FUNCTION_SECTION,
START_SECTION,
GLOBAL_SECTION,
GLOBAL_VARIABLE_SECTION,
STYLE_SECTION,
ARRAY_SECTION,
REF_SECTION,
Expand Down
52 changes: 52 additions & 0 deletions weex_core/Source/core/data_render/exec_state.cc
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,7 @@ void ExecState::startEncode() {
encodeFunctionSection();
encodeStartSection();
encodeGlobalSection();
encodeGlobalVariableSection();
encodeStyleSection();
encodeArraySection();
encodeRefSection();
Expand Down Expand Up @@ -220,6 +221,10 @@ void ExecState::encodeFunctionSection() {
super_index = static_cast<int>(it - func_states.begin());
}
file->write((char*)&super_index, sizeof(int));

bool is_class_func = func_state->is_class_func();
file->write((char*)&is_class_func, sizeof(int));

unsigned opcodeSize = static_cast<unsigned>(func_state->instructions().size());
file->write((char*)&opcodeSize, sizeof(unsigned));
for (int i=0; i<opcodeSize; i++) {
Expand Down Expand Up @@ -261,6 +266,20 @@ void ExecState::encodeGlobalSection() {
}
}

void ExecState::encodeGlobalVariableSection() {
BinaryFile* file = BinaryFile::instance();
unsigned id = Section::GLOBAL_VARIABLE_SECTION;
unsigned size = static_cast<unsigned>(global_variables_.size());

file->write((char*)&id, sizeof(unsigned));
file->write((char*)&size, sizeof(unsigned));
for (auto variable : global_variables_) {
unsigned length = static_cast<unsigned>(variable.first.length()) + 1;
file->write(variable.first.c_str(), static_cast<unsigned int>(sizeof(char) * length));
file->write((char*)&variable.second, sizeof(long));
}
}

void ExecState::encodeStyleSection() {
unsigned id = Section::STYLE_SECTION;
std::map<std::string, json11::Json>& styles = render_context_->style_json();
Expand Down Expand Up @@ -490,6 +509,9 @@ bool ExecState::startDecode() {
case GLOBAL_SECTION:
decodeGlobalSection();
break;
case GLOBAL_VARIABLE_SECTION:
decodeGlobalVariableSection();
break;
case STYLE_SECTION:
decodeStyleSection();
break;
Expand Down Expand Up @@ -580,6 +602,10 @@ void ExecState::decodeFunctionSection() {
file->read((char*)&super_index, sizeof(int));
func_state->set_super_index(super_index);

bool is_class_func = false;
file->read((char*)&is_class_func, sizeof(bool));
func_state->set_is_class_func(is_class_func);

unsigned op_code_count = 0;
file->read((char*)&op_code_count, sizeof(unsigned));
for (int j=0; j<op_code_count; j++) {
Expand Down Expand Up @@ -639,6 +665,32 @@ void ExecState::decodeGlobalSection() {
}
}

void ExecState::decodeGlobalVariableSection() {
BinaryFile* file = BinaryFile::instance();

unsigned count = 0;
file->read((char*)&count, sizeof(unsigned));
if (count == 0) {
return;
}

for (int i=0; i<count; i++) {
std::string key;
char c;
while (true) {
file->read(&c, sizeof(char));
if (c == 0) {
break;
}
key += c;
}

long value;
file->read((char*)&value, sizeof(long));
global_variables_.insert(std::pair<std::string, long>(key, value));
}
}

void ExecState::decodeStyleSection() {
BinaryFile* file = BinaryFile::instance();

Expand Down
2 changes: 2 additions & 0 deletions weex_core/Source/core/data_render/exec_state.h
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,7 @@ class ExecState {
friend class CodeGenerator;

void encodeGlobalSection();
void encodeGlobalVariableSection();
void encodeFunctionSection();
void encodeStartSection();
void encodeTableSection();
Expand All @@ -183,6 +184,7 @@ class ExecState {
void decodeFunctionSection();
void decodeStartSection();
void decodeGlobalSection();
void decodeGlobalVariableSection();
void decodeStyleSection();
void decodeArraySection();
void decodeRefSection();
Expand Down

0 comments on commit 7736aed

Please sign in to comment.