• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /****************************************************************************
2  * Copyright (C) 2014-2018 Intel Corporation.   All Rights Reserved.
3  *
4  * Permission is hereby granted, free of charge, to any person obtaining a
5  * copy of this software and associated documentation files (the "Software"),
6  * to deal in the Software without restriction, including without limitation
7  * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8  * and/or sell copies of the Software, and to permit persons to whom the
9  * Software is furnished to do so, subject to the following conditions:
10  *
11  * The above copyright notice and this permission notice (including the next
12  * paragraph) shall be included in all copies or substantial portions of the
13  * Software.
14  *
15  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
18  * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
20  * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
21  * IN THE SOFTWARE.
22  *
23  * @file ${filename}
24  *
25  * @brief auto-generated file
26  *
27  * DO NOT EDIT
28  *
29  * Generation Command Line:
30  *   ${'\n *     '.join(cmdline)}
31  *
32  ******************************************************************************/
33 // clang-format off
34 
35 #include <llvm/IR/DerivedTypes.h>
36 
37 #pragma once
38 
39 namespace SwrJit
40 {
41     using namespace llvm;
42 
43 %for type in types:
44     INLINE static StructType* Gen_${type['name']}(JitManager* pJitMgr)
45     {
46         %if needs_ctx(type):
47         LLVMContext& ctx = pJitMgr->mContext;
48 
49         %endif
50 #if LLVM_VERSION_MAJOR >= 12
51         StructType* pRetType = StructType::getTypeByName(pJitMgr->mContext, "${type['name']}");
52 #else
53         StructType* pRetType = pJitMgr->mpCurrentModule->getTypeByName("${type['name']}");
54 #endif
55         if (pRetType == nullptr)
56         {
57             std::vector<Type*> members =<% (max_type_len, max_name_len) = calc_max_len(type['members']) %>
58             {
59                 %for member in type['members']:
60                 /* ${member['name']} ${pad(len(member['name']), max_name_len)}*/ ${member['type']},
61                 %endfor
62             };
63 
64             pRetType = StructType::create(members, "${type['name']}", false);
65 
66             // Compute debug metadata
67             llvm::DIBuilder builder(*pJitMgr->mpCurrentModule);
68             llvm::DIFile* pFile = builder.createFile("${input_file}", "${os.path.normpath(input_dir).replace('\\', '/')}");
69 
70             std::vector<std::pair<std::string, uint32_t>> dbgMembers =
71             {
72                 %for member in type['members']:
73                 std::make_pair("${member['name']}", ${pad(len(member['name']), max_name_len)}${member['lineNum']}),
74                 %endfor
75             };
76             pJitMgr->CreateDebugStructType(pRetType, "${type['name']}", pFile, ${type['lineNum']}, dbgMembers);
77         }
78 
79         return pRetType;
80     }
81 
82     %for member in type['members']:
83     static const uint32_t ${type['name']}_${member['name']} ${pad(len(member['name']), max_name_len)}= ${loop.index};
84     %endfor
85 
86 %endfor
87 } // namespace SwrJit
88 
89 <%! # Global function definitions
90     import os
91     def needs_ctx(struct_type):
92         for m in struct_type.get('members', []):
93             if '(ctx)' in m.get('type', ''):
94                 return True
95         return False
96 
97     def calc_max_len(fields):
98         max_type_len = 0
99         max_name_len = 0
100         for f in fields:
101             if len(f['type']) > max_type_len: max_type_len = len(f['type'])
102             if len(f['name']) > max_name_len: max_name_len = len(f['name'])
103         return (max_type_len, max_name_len)
104 
105     def pad(cur_len, max_len):
106         pad_amt = max_len - cur_len
107         return ' '*pad_amt
108 %>
109 // clang-format on
110