Path: blob/21.2-virgl/src/gallium/drivers/swr/rasterizer/codegen/templates/gen_llvm.hpp
4574 views
/****************************************************************************1* Copyright (C) 2014-2018 Intel Corporation. All Rights Reserved.2*3* Permission is hereby granted, free of charge, to any person obtaining a4* copy of this software and associated documentation files (the "Software"),5* to deal in the Software without restriction, including without limitation6* the rights to use, copy, modify, merge, publish, distribute, sublicense,7* and/or sell copies of the Software, and to permit persons to whom the8* Software is furnished to do so, subject to the following conditions:9*10* The above copyright notice and this permission notice (including the next11* paragraph) shall be included in all copies or substantial portions of the12* Software.13*14* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR15* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,16* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL17* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER18* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING19* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS20* IN THE SOFTWARE.21*22* @file ${filename}23*24* @brief auto-generated file25*26* DO NOT EDIT27*28* Generation Command Line:29* ${'\n * '.join(cmdline)}30*31******************************************************************************/32// clang-format off3334#include <llvm/IR/DerivedTypes.h>3536#pragma once3738namespace SwrJit39{40using namespace llvm;4142%for type in types:43INLINE static StructType* Gen_${type['name']}(JitManager* pJitMgr)44{45%if needs_ctx(type):46LLVMContext& ctx = pJitMgr->mContext;4748%endif49#if LLVM_VERSION_MAJOR >= 1250StructType* pRetType = StructType::getTypeByName(pJitMgr->mContext, "${type['name']}");51#else52StructType* pRetType = pJitMgr->mpCurrentModule->getTypeByName("${type['name']}");53#endif54if (pRetType == nullptr)55{56std::vector<Type*> members =<% (max_type_len, max_name_len) = calc_max_len(type['members']) %>57{58%for member in type['members']:59/* ${member['name']} ${pad(len(member['name']), max_name_len)}*/ ${member['type']},60%endfor61};6263pRetType = StructType::create(members, "${type['name']}", false);6465// Compute debug metadata66llvm::DIBuilder builder(*pJitMgr->mpCurrentModule);67llvm::DIFile* pFile = builder.createFile("${input_file}", "${os.path.normpath(input_dir).replace('\\', '/')}");6869std::vector<std::pair<std::string, uint32_t>> dbgMembers =70{71%for member in type['members']:72std::make_pair("${member['name']}", ${pad(len(member['name']), max_name_len)}${member['lineNum']}),73%endfor74};75pJitMgr->CreateDebugStructType(pRetType, "${type['name']}", pFile, ${type['lineNum']}, dbgMembers);76}7778return pRetType;79}8081%for member in type['members']:82static const uint32_t ${type['name']}_${member['name']} ${pad(len(member['name']), max_name_len)}= ${loop.index};83%endfor8485%endfor86} // namespace SwrJit8788<%! # Global function definitions89import os90def needs_ctx(struct_type):91for m in struct_type.get('members', []):92if '(ctx)' in m.get('type', ''):93return True94return False9596def calc_max_len(fields):97max_type_len = 098max_name_len = 099for f in fields:100if len(f['type']) > max_type_len: max_type_len = len(f['type'])101if len(f['name']) > max_name_len: max_name_len = len(f['name'])102return (max_type_len, max_name_len)103104def pad(cur_len, max_len):105pad_amt = max_len - cur_len106return ' '*pad_amt107%>108// clang-format on109110111