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

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

Create a template system to generate lowering logic for v64i2 and the test cases.

File size: 1.9 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"]
15
16def C(name):
17    return name + "_2"
18
19def CXX(name):
20    return "simd<2>::" + name
21
22def OP(name):
23    if name == "mult":
24        return "mul"
25    if name in ["eq", "ult", "ugt"]:
26        return "icmp " + name
27    if name in ["lt", "gt"]:
28        return "icmp s" + name
29
30    return name
31
32FunctionNames = [{"c": C(name), "cxx": CXX(name), "op": OP(name)}
33                    for name in FunctionList]
34
35#configuring Jinja2
36env = Environment(loader=FileSystemLoader(['.', 'gen/', '../../gen']),
37                  trim_blocks=True)
38
39def fillTemplate(template, output, params):
40    content = env.get_template(template).render(params)
41    with open(output, 'w') as f:
42        f.write(content)
43
44def genTestFile():
45    fillTemplate(template=TestTemplate, output=TestOutput,
46                 params=dict(HeaderComment = "AUTO GENERATED FILE",
47                             FunctionNames = FunctionNames))
48
49def genLLFile():
50    fillTemplate(template=LLTemplate, output=LLOutput,
51                 params=dict(FunctionNames = FunctionNames))
52
53def genFuncFile():
54    fillTemplate(template=FuncTemplate, output=FuncOutput,
55                 params=dict(HeaderComment = "AUTO GENERATED FILE",
56                             FunctionNames = FunctionNames,
57                             Implement = impl_data.getImplements()))
58    # mv ParabixGeneratedFuncs.h ~/llvm_suit/llvm_git/lib/Target/X86/
59
60if __name__ == '__main__':
61    genTestFile()
62    genLLFile()
63    #genFuncFile()
64
Note: See TracBrowser for help on using the repository browser.