1/* 2 * Copyright 2010, The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17#ifndef _FRAMEWORKS_COMPILE_SLANG_SLANG_RS_METADATA_SPEC_H_ // NOLINT 18#define _FRAMEWORKS_COMPILE_SLANG_SLANG_RS_METADATA_SPEC_H_ 19 20// Design Philosophy: 21// Expensive encoding but cheap decoding process. 22// 23// 1. A string table concatenates ALL strings (including '\0' in t) 24// 2. A string index table which is an integer array containg the offset 25// to access each string in the string table. 26// 3. All ->name field in RSType/RSVar/RSFunction now refer to an index in the 27// string index table for offset lookup. 28// 4. RSType information is encoded as a byte stream like: 29// 30// [RSType #1][RSType #2] ... [RSType #N] 31// 32// All ->type or ->base_type in RS*Type now becomes an index to RSType array. 33// 34// 5. RSVar => an string table index plus RSType array index 35// 6. RSFunction => an string table index 36 37namespace llvm { 38 class Module; 39} 40 41// Forward declaration 42union RSType; 43 44struct RSVar { 45 const char *name; // variable name 46 const union RSType *type; 47}; 48 49struct RSFunction { 50 const char *name; // function name 51}; 52 53// Opaque pointer 54typedef int RSMetadataEncoder; 55 56// Create a context associated with M for encoding metadata. 57RSMetadataEncoder *CreateRSMetadataEncoder(llvm::Module *M); 58 59// Encode V as a metadata in M. Return 0 if every thing goes well. 60int RSEncodeVarMetadata(RSMetadataEncoder *E, const RSVar *V); 61// Encode F as a metadata in M. Return 0 if every thing goes well. 62int RSEncodeFunctionMetadata(RSMetadataEncoder *E, const RSFunction *F); 63 64// Release the memory allocation of Encoder without flushing things. 65void DestroyRSMetadataEncoder(RSMetadataEncoder *E); 66 67// Flush metadata in E to its associated module and Destroy it. Return 0 if 68// every thing goes well. This will also call the DestroyRSMetadataEncoder(). 69int FinalizeRSMetadataEncoder(RSMetadataEncoder *E); 70 71// TODO(slang): Decoder 72struct RSMetadata { 73 unsigned num_vars; 74 unsigned num_funcs; 75 76 RSVar *vars; 77 RSFunction *funcs; 78 79 void *context; 80}; 81 82// struct RSMetadata *RSDecodeMetadata(llvm::Module *M); 83// void RSReleaseMetadata(struct RSMetadata *MD); 84 85#endif // _FRAMEWORKS_COMPILE_SLANG_SLANG_RS_METADATA_SPEC_H_ NOLINT 86