José Fonseca | 8c7c108 | 2009-08-23 06:18:28 +0100 | [diff] [blame] | 1 | /************************************************************************** |
| 2 | * |
| 3 | * Copyright 2009 VMware, Inc. |
| 4 | * All Rights Reserved. |
| 5 | * |
| 6 | * Permission is hereby granted, free of charge, to any person obtaining a |
| 7 | * copy of this software and associated documentation files (the |
| 8 | * "Software"), to deal in the Software without restriction, including |
| 9 | * without limitation the rights to use, copy, modify, merge, publish, |
| 10 | * distribute, sub license, and/or sell copies of the Software, and to |
| 11 | * permit persons to whom the Software is furnished to do so, subject to |
| 12 | * the following conditions: |
| 13 | * |
| 14 | * The above copyright notice and this permission notice (including the |
| 15 | * next paragraph) shall be included in all copies or substantial portions |
| 16 | * of the Software. |
| 17 | * |
| 18 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS |
| 19 | * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF |
| 20 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. |
| 21 | * IN NO EVENT SHALL VMWARE AND/OR ITS SUPPLIERS BE LIABLE FOR |
| 22 | * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, |
| 23 | * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE |
| 24 | * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. |
| 25 | * |
| 26 | **************************************************************************/ |
| 27 | |
| 28 | |
| 29 | /** |
| 30 | * @file |
| 31 | * Helper functions for manipulation structures. |
| 32 | * |
| 33 | * @author Jose Fonseca <jfonseca@vmware.com> |
| 34 | */ |
| 35 | |
| 36 | |
| 37 | #include "util/u_debug.h" |
| 38 | #include "util/u_memory.h" |
| 39 | |
José Fonseca | d4806c6 | 2009-08-25 06:40:22 +0100 | [diff] [blame] | 40 | #include "lp_bld_debug.h" |
José Fonseca | 8c7c108 | 2009-08-23 06:18:28 +0100 | [diff] [blame] | 41 | #include "lp_bld_struct.h" |
| 42 | |
| 43 | |
| 44 | LLVMValueRef |
José Fonseca | b1eff01 | 2009-09-07 14:25:02 +0100 | [diff] [blame] | 45 | lp_build_struct_get_ptr(LLVMBuilderRef builder, |
| 46 | LLVMValueRef ptr, |
| 47 | unsigned member, |
| 48 | const char *name) |
| 49 | { |
| 50 | LLVMValueRef indices[2]; |
| 51 | LLVMValueRef member_ptr; |
| 52 | indices[0] = LLVMConstInt(LLVMInt32Type(), 0, 0); |
| 53 | indices[1] = LLVMConstInt(LLVMInt32Type(), member, 0); |
| 54 | member_ptr = LLVMBuildGEP(builder, ptr, indices, Elements(indices), ""); |
| 55 | lp_build_name(member_ptr, "%s.%s_ptr", LLVMGetValueName(ptr), name); |
| 56 | return member_ptr; |
| 57 | } |
| 58 | |
| 59 | |
| 60 | LLVMValueRef |
José Fonseca | 8c7c108 | 2009-08-23 06:18:28 +0100 | [diff] [blame] | 61 | lp_build_struct_get(LLVMBuilderRef builder, |
| 62 | LLVMValueRef ptr, |
| 63 | unsigned member, |
| 64 | const char *name) |
| 65 | { |
José Fonseca | d4806c6 | 2009-08-25 06:40:22 +0100 | [diff] [blame] | 66 | LLVMValueRef member_ptr; |
| 67 | LLVMValueRef res; |
José Fonseca | b1eff01 | 2009-09-07 14:25:02 +0100 | [diff] [blame] | 68 | member_ptr = lp_build_struct_get_ptr(builder, ptr, member, name); |
José Fonseca | d4806c6 | 2009-08-25 06:40:22 +0100 | [diff] [blame] | 69 | res = LLVMBuildLoad(builder, member_ptr, ""); |
| 70 | lp_build_name(res, "%s.%s", LLVMGetValueName(ptr), name); |
| 71 | return res; |
José Fonseca | 8c7c108 | 2009-08-23 06:18:28 +0100 | [diff] [blame] | 72 | } |