source: trunk/lib_ir/gen/gen.py @ 3981

Last change on this file since 3981 was 3981, checked in by linmengl, 5 years ago

more testings done, on v64i2 add/sub/mul/eq/lt/gt/ult/ugt/vsll/vsrl/vsra

File size: 2.3 KB
Line 
1# Use Jinja2 template to avoid tiny template strings in this file
2# Jinja2 allows enbedded python logic in template file.
3
4from jinja2 import Template, Environment, FileSystemLoader
5import impl_data
6
7TestTemplate    = "test_llc.pytemplate.cpp"
8TestOutput      = "test_llc.cpp"
9LLTemplate      = "llc_func.pytemplate.ll"
10LLOutput        = "llc_func.ll"
11FuncTemplate    = "ParabixGeneratedFuncs.pytemplate.h"
12FuncOutput      = "ParabixGeneratedFuncs.h"
13
14FunctionList = ["add", "sub", "mult", "eq", "lt", "gt", "ult", "ugt", "vsll", "vsrl", "vsra"]
15
16def C(name):
17    return name + "_2"
18
19def CXX(name):
20    if name in ["vsll", "vsrl", "vsra"]:
21        return "simd<2>::" + name[1:] + "i"
22    return "simd<2>::" + name
23
24def OP(name):
25    if name == "mult":
26        return "mul"
27    if name in ["eq", "ult", "ugt"]:
28        return "icmp " + name
29    if name in ["lt", "gt"]:
30        return "icmp s" + name
31    if name == "vsll":
32        return "shl"
33    if name in ["vsrl", "vsra"]:
34        return name[-1:] + "shr"
35
36    return name
37
38def FLAG(name):
39    if name in ["vsll", "vsrl", "vsra"]:
40        return "shifting"
41    return ""
42
43FunctionNames = [{"c": C(name), "cxx": CXX(name), "op": OP(name), "flag": FLAG(name)}
44                    for name in FunctionList]
45
46#configuring Jinja2
47env = Environment(loader=FileSystemLoader(['.', 'gen/', '../../gen']),
48                  trim_blocks=True,
49                  lstrip_blocks=True)
50
51def fillTemplate(template, output, params):
52    content = env.get_template(template).render(params)
53    with open(output, 'w') as f:
54        f.write(content)
55
56def genTestFile():
57    fillTemplate(template=TestTemplate, output=TestOutput,
58                 params=dict(HeaderComment = "AUTO GENERATED FILE",
59                             FunctionNames = FunctionNames))
60
61def genLLFile():
62    fillTemplate(template=LLTemplate, output=LLOutput,
63                 params=dict(FunctionNames = FunctionNames))
64
65def genFuncFile():
66    fillTemplate(template=FuncTemplate, output=FuncOutput,
67                 params=dict(HeaderComment = "AUTO GENERATED FILE",
68                             FunctionNames = FunctionNames,
69                             Implement = impl_data.getImplements()))
70    # mv ParabixGeneratedFuncs.h ~/llvm_suit/llvm_git/lib/Target/X86/
71
72if __name__ == '__main__':
73    genTestFile()
74    genLLFile()
75    genFuncFile()
76
Note: See TracBrowser for help on using the repository browser.