• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /****************************************************************************
2 * Copyright (C) 2014-2017 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 #pragma once
34 
35 namespace SwrJit
36 {
37     using namespace llvm;
38 
39 %for type in types:
40     INLINE static StructType *Gen_${type['name']}(JitManager* pJitMgr)
41     {
42         LLVMContext& ctx = pJitMgr->mContext;
43 	(void) ctx;
44 
45         StructType* pRetType = pJitMgr->mpCurrentModule->getTypeByName("${type['name']}");
46         if (pRetType == nullptr)
47         {
48             std::vector<Type*> members;
49             <%
50                 (max_type_len, max_name_len) = calc_max_len(type['members'])
51             %>
52             %for member in type['members']:
53             /* ${member['name']} ${pad(len(member['name']), max_name_len)}*/ members.push_back(${ member['type'] });
54             %endfor
55 
56             pRetType = StructType::create(members, "${type['name']}", false);
57 
58             // Compute debug metadata
59             llvm::DIBuilder builder(*pJitMgr->mpCurrentModule);
60             llvm::DIFile* pFile = builder.createFile("${input_file}", "${input_dir}");
61 
62             std::vector<std::pair<std::string, uint32_t>> dbgMembers;
63             %for member in type['members']:
64             dbgMembers.push_back(std::make_pair("${member['name']}", ${ member['lineNum'] }));
65             %endfor
66 
67             pJitMgr->CreateDebugStructType(pRetType, "${type['name']}", pFile, ${type['lineNum']}, dbgMembers);
68 
69         }
70 
71         return pRetType;
72     }
73 
74     %for member in type['members']:
75     static const uint32_t ${type['name']}_${member['name']} ${pad(len(member['name']), max_name_len)}= ${loop.index};
76     %endfor
77 
78 %endfor
79 } // ns SwrJit
80 
81 <%! # Global function definitions
82     def calc_max_len(fields):
83         max_type_len = 0
84         max_name_len = 0
85         for f in fields:
86             if len(f['type']) > max_type_len: max_type_len = len(f['type'])
87             if len(f['name']) > max_name_len: max_name_len = len(f['name'])
88         return (max_type_len, max_name_len)
89 
90     def pad(cur_len, max_len):
91         pad_amt = max_len - cur_len
92         return ' '*pad_amt
93 %>
94