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 #pragma once 36 37 namespace SwrJit 38 { 39 using namespace llvm; 40 41 %for type in types: 42 INLINE static StructType* Gen_${type['name']}(JitManager* pJitMgr) 43 { 44 %if needs_ctx(type): 45 LLVMContext& ctx = pJitMgr->mContext; 46 47 %endif 48 StructType* pRetType = pJitMgr->mpCurrentModule->getTypeByName("${type['name']}"); 49 if (pRetType == nullptr) 50 { 51 std::vector<Type*> members =<% (max_type_len, max_name_len) = calc_max_len(type['members']) %> 52 { 53 %for member in type['members']: 54 /* ${member['name']} ${pad(len(member['name']), max_name_len)}*/ ${member['type']}, 55 %endfor 56 }; 57 58 pRetType = StructType::create(members, "${type['name']}", false); 59 60 // Compute debug metadata 61 llvm::DIBuilder builder(*pJitMgr->mpCurrentModule); 62 llvm::DIFile* pFile = builder.createFile("${input_file}", "${os.path.normpath(input_dir).replace('\\', '/')}"); 63 64 std::vector<std::pair<std::string, uint32_t>> dbgMembers = 65 { 66 %for member in type['members']: 67 std::make_pair("${member['name']}", ${pad(len(member['name']), max_name_len)}${member['lineNum']}), 68 %endfor 69 }; 70 pJitMgr->CreateDebugStructType(pRetType, "${type['name']}", pFile, ${type['lineNum']}, dbgMembers); 71 } 72 73 return pRetType; 74 } 75 76 %for member in type['members']: 77 static const uint32_t ${type['name']}_${member['name']} ${pad(len(member['name']), max_name_len)}= ${loop.index}; 78 %endfor 79 80 %endfor 81 } // namespace SwrJit 82 83 <%! # Global function definitions 84 import os 85 def needs_ctx(struct_type): 86 for m in struct_type.get('members', []): 87 if '(ctx)' in m.get('type', ''): 88 return True 89 return False 90 91 def calc_max_len(fields): 92 max_type_len = 0 93 max_name_len = 0 94 for f in fields: 95 if len(f['type']) > max_type_len: max_type_len = len(f['type']) 96 if len(f['name']) > max_name_len: max_name_len = len(f['name']) 97 return (max_type_len, max_name_len) 98 99 def pad(cur_len, max_len): 100 pad_amt = max_len - cur_len 101 return ' '*pad_amt 102 %> 103 // clang-format on 104