aboutsummaryrefslogtreecommitdiffstats
path: root/bfd/codegen.py
blob: fbac4a8d16d995ed837304e6414e74fea2387b8d (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
#!/bin/python3

import argparse
import code
import readline

default_header="#include <stdint.h>\n"
main_sig="int main(int argc, char** argv)>"
def_kw="#define "
def_name = []
separator="fff"
def_value = []

class Argparser(object):
    def __init__(self):
        parser = argparse.ArgumentParser()
        parser.add_argument("--arglist", nargs="+", type=str, help="list of args")
        parser.add_argument("--hex", action="store_true", help="generate hex(string) code, otherwise generate int", default=False)
        self.args = parser.parse_args()
        self.code = {}

class CodeGen_Arg(object):
    def __init__(self, arglist):
        self.arglist = arglist
        self.def_name = []
        self.def_value = []

    def get_ret_type(self, type):
        pass

    def gen_cast(self):
        for argtype in self.arglist:
            if argtype == "int8": self.def_name.append("i8")
            elif argtype == "uint8":self.def_name.append("u8")
            elif argtype == "uchar":self.def_name.append("c")
            elif argtype == "char":self.def_name.append("c")
            elif argtype == "lightuserdata":self.def_name.append("p")
            elif argtype == "bool":self.def_name.append("b")
            elif argtype == "int16":self.def_name.append("i16")
            elif argtype == "uint16":self.def_name.append("u16")
            elif argtype == "int32":self.def_name.append("i32")
            elif argtype == "uint32":self.def_name.append("u32")
            elif argtype == "int64":self.def_name.append("i64")
            elif argtype == "uint64":self.def_name.append("u64")
            elif argtype == "int128":self.def_name.append("i128")
            elif argtype == "uint128":self.def_name.append("u128")
            elif argtype == "float":self.def_name.append("f")
            elif argtype == "double":self.def_name.append("d")
            elif argtype == "long double":self.def_name.append("ld")
            elif argtype == "string":self.def_name.append("s")
            elif argtype == "custom":self.def_name.append("x")
            else:
                raise Exception("codegen : unknown type")

    def debugdump(self):
        for argtype in self.arglist:
            print(argtype)

    def genhex():
        pass

    def genint():
        pass

# write code here
def premain():
    argparser = Argparser()
    codegen = CodeGen_Arg(argparser.args.arglist)
    codegen.debugdump()

def main():
    try:
        premain()
    except:
        variables = globals().copy()
        variables.update(locals())
        shell = code.InteractiveConsole(variables)
        shell.interact(banner="DEBUG REPL")

if __name__ == "__main__":
    main()