aboutsummaryrefslogtreecommitdiffstats
path: root/main.py
diff options
context:
space:
mode:
Diffstat (limited to 'main.py')
-rwxr-xr-xmain.py78
1 files changed, 7 insertions, 71 deletions
diff --git a/main.py b/main.py
index 565e598..6985132 100755
--- a/main.py
+++ b/main.py
@@ -17,8 +17,6 @@ import datetime
# TODO-doesnt support non-byte-sized reads
# TODO-doesnt support big-endian normal reads
-# TODO-memory management!!
-# TODO-conditional for READs
def type_resolver(elem, elem_list):
type_str = elem.attrib["type"]
type_name = elem.attrib["name"]
@@ -204,8 +202,8 @@ def dupemake(path, main_name):
class CodeGen(object):
def __init__(self, argparser):
self.argparser = argparser
- #self.struct_json = json.load(open(self.argparser.args.structs))
self.dnt = datetime.datetime.now().isoformat()
+ print(self.dnt)
self.elems = []
self.def_elems = []
self.read_elems = []
@@ -444,7 +442,6 @@ class CodeGen(object):
read_source.write("dummy = malloc(sizeof(" + elem.attrib["name"] + "));\n")
read_source.write(text.c_void_manager_proto.replace("XXX", "dummy"));
read_source.write(text.c_read_gen.replace("XXX", "dummy->" + elem.attrib["name"]).replace("YYY", type_resolver(elem, self.def_elems)))
- #read_source.write(text.c_function_return_type)
read_source.write("return dummy;\n")
read_source.write(text.c_function_close + "\n")
read_source_header = open(self.argparser.args.outdir + "/read.h", "w")
@@ -457,7 +454,6 @@ class CodeGen(object):
read_source_header.write("#endif //end of header guard\n\n")
def gen_void_train(self):
- #void_source = open(self.argparser.args.outdir + "/void.h", "w")
void_source = open(self.aggregate_source, "w")
void_source_h = open(self.aggregate_source_h, "w")
void_source.write("\n// automatically generated by faultreiber\n")
@@ -468,7 +464,6 @@ class CodeGen(object):
void_source.write("void** void_train;\n")
void_source.write("uint64_t current_void_size = 0U;\n")
void_source.write("uint64_t current_void_count = 0U;\n")
- #void_source.write("void** void_train(void) {\n")
void_source_h.write('#ifndef FT_AGGREGATE_H\n#define FT_AGGREGATE_H\n')
void_source_h.write('#ifdef __cplusplus\nextern "C" {\n#endif\n')
void_source_h.write('#include "./structs.h"\n')
@@ -482,32 +477,15 @@ class CodeGen(object):
else:
void_source_h.write("extern " + elem.attrib["name"] + "* " + elem.attrib["name"] + "_container;\n")
void_source.write(elem.attrib["name"] + "* " + elem.attrib["name"] + "_container;\n")
- '''
- for child in elem:
- ref_node_name = type_resolver(child, self.def_elems)
- ref_node = get_def_node(ref_node_name, self.def_elems)
- if ref_node:
- count = get_elem_count(child)
- size = get_elem_size(child)
- if count != 1:
- void_source_h.write("extern " + ref_node.attrib["name"] + "** " + elem.attrib["name"] + "_" + child.attrib["name"] + "_container;\n")
- void_source.write(ref_node.attrib["name"] + "** " + elem.attrib["name"] + "_" + child.attrib["name"] + "_container;\n")
- else:
- void_source_h.write("extern " + ref_node.attrib["name"] + "* " + elem.attrib["name"] + "_" + child.attrib["name"] + "_container;\n")
- void_source.write(ref_node.attrib["name"] + "* " + elem.attrib["name"] + "_" + child.attrib["name"] + "_container;\n")
- '''
# end
void_source.write("void malloc_all(void) {\n")
void_source_h.write("void malloc_all(void);\n")
count_int = int()
count_void = int()
read_count = len(self.read_elems)
- #extern = "extern "
extern = ""
- #void_source.write("//TODO-assign sub-containers to contrainers here\n")
# FIXME-count and size present together is not being handled at all
for elem in self.read_elems:
- #for elem in self.read_elems + self.def_elems:
if "isaggregate" in elem.attrib:
for child in elem:
ref_node_name = type_resolver(child, self.def_elems)
@@ -516,15 +494,11 @@ class CodeGen(object):
count = get_elem_count(child)
size = get_elem_size(child)
type_width = get_type_width(child)
- #print(elem.tag + " " + child.tag + " " + "count:" + str(count) + " " + "size:" + str(size) + " " + "typ_width:" + str(type_width))
if count > 0: count_int+=count*type_width
if count < 0: count_void+=1
if size > 0: count_int+=size
if size < 0: count_void+=1
sizeof = (str(count_int) if count_int > 0 else ("")) + ("+" if count_void>0 and count_int>0 else "") + ((str(count_void)+"*"+"sizeof(void*)") if count_void > 0 else "")
- #self.mem_size[elem.attrib["name"]] = text.c_reserve_void_ptr.replace("XXX", sizeof)
- #void_source.write(elem.attrib["name"] + "* " + elem.attrib["name"] + "_container" + " = " + text.c_reserve_void_ptr.replace("XXX", sizeof) + ";\n")
- #void_source.write(elem.attrib["name"] + "_container" + " = " + text.c_reserve_void_ptr.replace("XXX", sizeof) + ";\n")
count_int = 0
count_void = 0
else:
@@ -540,9 +514,6 @@ class CodeGen(object):
if size > 0: count_int+=size
else: count_void+=1
sizeof = (str(count_int)+"+" if count_int > 0 else "") + (str(count_void)+"*"+"sizeof(void*)") if count_void > 0 else ""
- #self.mem_size[elem.attrib["name"]] = text.c_reserve_void_ptr.replace("XXX", sizeof)
- #void_source.write(elem.attrib["name"] + "* " + elem.attrib["name"] + "_container" + " = " + text.c_reserve_void_ptr.replace("XXX", sizeof) + ";\n")
- #void_source.write(elem.attrib["name"] + "_container" + " = " + text.c_reserve_void_ptr.replace("XXX", sizeof) + ";\n")
count_int = 0
count_void = 0
void_source.write("}\n")
@@ -647,18 +618,16 @@ class CodeGen(object):
def gen_struct_header_xml(self):
struct_source = open(self.struct_source_h, "w")
struct_source_c = open(get_full_path(self.argparser.args.outdir, "structs.c"), "w")
+ struct_source.write(text.autogen_warning)
+ struct_source_c.write(text.autogen_warning)
+ struct_source.write("// " + self.dnt + "\n")
+ struct_source_c.write("// " + self.dnt + "\n")
struct_source.write("#ifndef FT_STRUCTS_H\n#define FT_STRUCTS_H\n")
+ struct_source.write('#ifdef __cplusplus__\nextern "C" {\n#endif\n')
struct_source_c.write('#include "structs.h"\n')
struct_source_c.write('#include "stdlib.h"\n')
struct_source_c.write('#include "stdio.h"\n')
struct_source.write('#include <unistd.h>\n')
- struct_source.write(text.pre_header_guard)
- struct_source.write(text.autogen_warning)
- struct_source_c.write(text.autogen_warning)
- if self.argparser.args.datetime:
- struct_source.write("// " + self.dnt + "\n")
- struct_source_c.write("// " + self.dnt + "\n")
- struct_source.write(text.header_guard_begin.replace("XXX", "structs".upper()))
struct_source.write(text.header_inttype)
struct_source_c.write(text.c_read_leb_u_def + "\n")
struct_source_c.write(text.c_read_leb_s_def + "\n")
@@ -671,7 +640,6 @@ class CodeGen(object):
struct_source.write(text.c_read_leb_128_s_sig + "\n")
struct_source.write(text.c_read_until_delimiter_sig + "\n")
struct_source.write(text.c_void_manager_sig + "\n")
- #struct_source.write(text.c_read_leb_macro_defs + "\n")
if self.argparser.args.structsinclude:
copy(self.argparser.args.structsinclude, self.argparser.args.outdir)
pos = self.argparser.args.structsinclude.rfind("/")
@@ -702,32 +670,7 @@ class CodeGen(object):
else:
struct_source.write(ref_type + pointer + " " + childer.attrib["name"] + ";\n")
struct_source.write("}" + child.attrib["name"] + ";\n\n")
- struct_source.write(text.pragma_endif)
- struct_source.write("#endif //end of header guard\n")
- #struct_source.write(text.last_comment)
-
- def gen_struct_header(self):
- struct_source = open(get_full_path(self.argparser.args.outdir, "structs.h"), "w")
- struct_source_c = open(get_full_path(self.argparser.args.outdir, "structs.c"), "w")
- struct_source_c.write('#include "structs.h"')
- struct_source.write(text.pre_header_guard)
- struct_source.write(text.autogen_warning)
- if self.argparser.args.datetime: struct_source.write("// " + self.dnt + "\n")
- struct_source.write(text.header_guard_begin.replace("XXX", "structs".upper()))
- struct_source.write(text.header_inttype)
- if self.argparser.args.structsinclude:
- copy(self.argparser.args.structsinclude, self.argparser.args.outdir)
- pos = self.argparser.args.structsinclude.rfind("/")
- sub = self.argparser.args.structsinclude[pos+1:]
- struct_source.write('#include "' + sub + '"\n')
- for k,v in self.struct_json.items():
- struct_name = k
- field_names = v["field_name"]
- field_typess = v["field_type"]
- struct_source.write("typedef struct {\n")
- for i, j in zip(field_names, field_typess):
- struct_source.write("\t" + j + " " + i + ";\n")
- struct_source.write("}" + struct_name + ";\n\n")
+ struct_source.write('#ifdef __cplusplus__\n}\n#endif\n')
struct_source.write(text.pragma_endif)
struct_source.write(text.last_comment)
@@ -735,20 +678,13 @@ class CodeGen(object):
self.init()
self.init_hook()
self.file_manager()
- #self.gen_struct_header()
self.read_xml()
self.gen_reader_funcs()
self.gen_struct_header_xml()
- #self.dump_def_elems()
- #self.dump_read_elems()
self.gen_void_train()
self.gen_aggregate_read()
- #self.dump_mem_dict()
- #self.dump_all_childs()
self.gen_release()
self.gen_return()
- #self.dump_malloc()
-
# write code here
def premain(argparser):