From 35862fbc6e7315b6c125bfb9708c9423f0c1423f Mon Sep 17 00:00:00 2001 From: bloodstalker Date: Sun, 22 Jul 2018 02:07:34 +0430 Subject: update --- main.py | 18 ++++++++++++++++-- text.py | 18 ++++++++++-------- 2 files changed, 26 insertions(+), 10 deletions(-) diff --git a/main.py b/main.py index e331e1c..c5ff396 100755 --- a/main.py +++ b/main.py @@ -100,6 +100,13 @@ def get_elem_size(elem, elems): else: return 0 +def get_encoding_read(encoding): + if encoding == "leb128u": + return text.c_read_leb_128_u + elif encoding == "leb128s": + return text.c_read_leb_128_s + else: pass + class Argparser(object): def __init__(self): parser = argparse.ArgumentParser() @@ -156,6 +163,7 @@ class CodeGen(object): print(elem.attrib) def gen_reader_funcs(self): + temp_dec_list = [] read_source = open(self.argparser.args.outdir + "/read.c", "w") read_source.write("\n// automatically generated by faultrieber\n") read_source.write("// " + self.dnt + "\n") @@ -213,9 +221,15 @@ class CodeGen(object): if for_dummy_declare: dummy_list.append(for_dummy_declare) for_read = str() if "size" in child.attrib: - for_read = text.c_read_gen_2.replace("XXX", pointer_remover(ref_node_name)+"_ins").replace("YYY", read_size_replacement) + if "encoding" in child.attrib: + for_read = get_encoding_read(child.attrib["encoding"]) + else: + for_read = text.c_read_gen_2.replace("XXX", pointer_remover(ref_node_name)+"_ins").replace("YYY", read_size_replacement) else: - for_read = text.c_read_gen.replace("XXX", pointer_remover(ref_node_name)+"_ins").replace("YYY", pointer_remover(ref_node_name)) + if "encoding" in child.attrib: + for_read = get_encoding_read(child.attrib["encoding"]) + else: + for_read = text.c_read_gen.replace("XXX", pointer_remover(ref_node_name)+"_ins").replace("YYY", ref_node_name) if child_count == 1: for_dummy_assign = "dummy" + access + child.attrib["name"] + "=" +pointer_remover(ref_node_name)+"_ins" + ";\n" read_source.write(for_dummy_declare+for_read+for_dummy_assign) diff --git a/text.py b/text.py index 0de2940..ed4d460 100644 --- a/text.py +++ b/text.py @@ -30,7 +30,7 @@ class text(): c_assign_struct = "XXX.YYY = ZZZ;\n" simple_loop = "for (int i = 0; i < XXX; ++i) {\nYYY}\n" c_read_leb_u_def = """ -uint64_t read_leb128_u(int _fd, int max_size) { +uint64_t read_leb_128_u(int _fd, int max_size) { uint8_t read_bytes = 0U; uint8_t byte = 0; uint64_t result = 0U; @@ -44,11 +44,11 @@ uint64_t read_leb128_u(int _fd, int max_size) { }""" c_read_leb_s_def = """ -int64_t read_leb128_s(int _fd, int max_size) { +int64_t read_leb_128_s(int _fd, int max_size) { uint8_t byte; uint8_t read_bytes = 0U; uint8_t last_byte; - int64_t result = 0; + int64_t result; uint32_t shift = 0U; read(_fd, &byte, 1); do { @@ -62,11 +62,11 @@ int64_t read_leb128_s(int _fd, int max_size) { }""" c_read_leb_macro_defs = """ -#define READ_VAR_UINT_1(FD) read_leb128_u(FD, 1) -#define READ_VAR_UINT_7(FD) read_leb128_u(FD, 1) -#define READ_VAR_UINT_32(FD) read_leb128_u(FD, 5) -#define READ_VAR_INT_1(FD) read_leb128_s(FD, 1) -#define READ_VAR_INT_7(FD) read_leb128_s(FD, 1) +#define READ_VAR_UINT_1(FD) read_leb128_u(FD, 1, XXX) +#define READ_VAR_UINT_7(FD) read_leb128_u(FD, 1, XXX) +#define READ_VAR_UINT_32(FD) read_leb128_u(FD, 5, XXX) +#define READ_VAR_INT_1(FD) read_leb128_s(FD, 1, XXX) +#define READ_VAR_INT_7(FD) read_leb128_s(FD, 1, XXX) """ c_read_leb_macro_varuin1 = "READ_VAR_UINT_1(XXX)" @@ -75,4 +75,6 @@ int64_t read_leb128_s(int _fd, int max_size) { c_read_leb_macro_varin1 = "READ_VAR_INT_1(XXX)" c_read_leb_macro_varin7 = "READ_VAR_INT_7(XXX)" c_read_leb_macro_varin32 = "READ_VAR_INT_32(XXX)" + c_read_leb_128_u = "read_leb_128_u(_fd, 5);\n" + c_read_leb_128_s = "read_leb_128_s(_fd, 5);\n" -- cgit v1.2.3