00001 /* ==================================================================== 00002 * The Kannel Software License, Version 1.0 00003 * 00004 * Copyright (c) 2001-2008 Kannel Group 00005 * Copyright (c) 1998-2001 WapIT Ltd. 00006 * All rights reserved. 00007 * 00008 * Redistribution and use in source and binary forms, with or without 00009 * modification, are permitted provided that the following conditions 00010 * are met: 00011 * 00012 * 1. Redistributions of source code must retain the above copyright 00013 * notice, this list of conditions and the following disclaimer. 00014 * 00015 * 2. Redistributions in binary form must reproduce the above copyright 00016 * notice, this list of conditions and the following disclaimer in 00017 * the documentation and/or other materials provided with the 00018 * distribution. 00019 * 00020 * 3. The end-user documentation included with the redistribution, 00021 * if any, must include the following acknowledgment: 00022 * "This product includes software developed by the 00023 * Kannel Group (http://www.kannel.org/)." 00024 * Alternately, this acknowledgment may appear in the software itself, 00025 * if and wherever such third-party acknowledgments normally appear. 00026 * 00027 * 4. The names "Kannel" and "Kannel Group" must not be used to 00028 * endorse or promote products derived from this software without 00029 * prior written permission. For written permission, please 00030 * contact org@kannel.org. 00031 * 00032 * 5. Products derived from this software may not be called "Kannel", 00033 * nor may "Kannel" appear in their name, without prior written 00034 * permission of the Kannel Group. 00035 * 00036 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED 00037 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 00038 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 00039 * DISCLAIMED. IN NO EVENT SHALL THE KANNEL GROUP OR ITS CONTRIBUTORS 00040 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, 00041 * OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT 00042 * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR 00043 * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 00044 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE 00045 * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, 00046 * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 00047 * ==================================================================== 00048 * 00049 * This software consists of voluntary contributions made by many 00050 * individuals on behalf of the Kannel Group. For more information on 00051 * the Kannel Group, please see <http://www.kannel.org/>. 00052 * 00053 * Portions of this software are based upon software originally written at 00054 * WapIT Ltd., Helsinki, Finland for the Kannel project. 00055 */ 00056 00057 /* 00058 * 00059 * ws.h 00060 * 00061 * Author: Markku Rossi <mtr@iki.fi> 00062 * 00063 * Copyright (c) 1999-2000 WAPIT OY LTD. 00064 * All rights reserved. 00065 * 00066 * Public header file for the WMLScript compiler library. 00067 * 00068 * The compiler is written for WMLScript version 1.1. 00069 * 00070 */ 00071 00072 #ifndef WS_H 00073 #define WS_H 00074 00075 #include "wsutf8.h" 00076 00077 /********************* Creating and destroying compiler *****************/ 00078 00079 /* A callback function of this type is called to output compiler's 00080 diagnostic, error, and warning messages. The argument `data' has 00081 `len' bytes of data that should be output somehow to user. The 00082 argument `context' is the user-specified context data for the 00083 callback function. */ 00084 typedef void (*WsIOProc)(const char *data, size_t len, void *context); 00085 00086 /* A callback function of this type is called for each `use meta name' 00087 and `use meta http equiv' pragma, found from the current 00088 compilation unit. The arguments `property_name', `content', and 00089 `scheme' are the meta-body arguments of the pragma. They can be 00090 manipulated with the functions of the `wsutf8.h' module. The 00091 argument `scheme' can have the value NULL if the pragma did not 00092 specify it. The string arguments belong to the WMLScript compiler 00093 and you should not modify or free them. The argument `context' is 00094 the user-specified context data for the callback function. */ 00095 typedef void (*WsPragmaMetaProc)(const WsUtf8String *property_name, 00096 const WsUtf8String *content, 00097 const WsUtf8String *scheme, 00098 void *context); 00099 00100 /* Parameters for a WMLScript copiler. */ 00101 struct WsCompilerParamsRec 00102 { 00103 /* Features. */ 00104 00105 /* Store string constants in ISO-8859/1 (ISO latin1) format. The 00106 default format is UTF-8. This option makes a bit smaller 00107 byte-code files but it loses information for non-latin1 00108 languages. */ 00109 unsigned int use_latin1_strings : 1; 00110 00111 00112 /* Warning flags. */ 00113 00114 /* Warn if a standard library function is called with mismatching 00115 argument types. */ 00116 unsigned int warn_stdlib_type_mismatch : 1; 00117 00118 00119 /* Optimization flags. */ 00120 00121 /* Do not perform constant folding. */ 00122 unsigned int no_opt_constant_folding : 1; 00123 00124 /* Do not sort byte-code functions by their usage counts. */ 00125 unsigned int no_opt_sort_bc_functions : 1; 00126 00127 /* Do not perform peephole optimization. */ 00128 unsigned int no_opt_peephole : 1; 00129 00130 /* Do not optimize jumps to jump instructions to jump directly to 00131 the target label of the next instruction. */ 00132 unsigned int no_opt_jumps_to_jumps : 1; 00133 00134 /* Do not optimize jumps to the next instruction. */ 00135 unsigned int no_opt_jumps_to_next_instruction : 1; 00136 00137 /* Do not remove unreachable code. */ 00138 unsigned int no_opt_dead_code : 1; 00139 00140 /* Do not remove useless conversions */ 00141 unsigned int no_opt_conv : 1; 00142 00143 /* Perform expensive optimizations which require liveness 00144 analyzation of the local variables. */ 00145 unsigned int opt_analyze_variable_liveness : 1; 00146 00147 00148 /* Output flags. */ 00149 00150 /* Print verbose progress messages. */ 00151 unsigned int verbose : 1; 00152 00153 /* Print symbolic assembler to the stdout. */ 00154 unsigned int print_symbolic_assembler : 1; 00155 00156 /* Disassemble the resulting byte-code instructions. */ 00157 unsigned int print_assembler : 1; 00158 00159 /* Function pointers to receive standard output and error messages. 00160 If these are unset, the outputs are directed to the system's 00161 standard output and error streams. */ 00162 00163 /* Standard output. */ 00164 WsIOProc stdout_cb; 00165 void *stdout_cb_context; 00166 00167 /* Standard error. */ 00168 WsIOProc stderr_cb; 00169 void *stderr_cb_context; 00170 00171 /* A callback function which is called for each `use meta name' 00172 pragma, found from the current compilation unit. */ 00173 WsPragmaMetaProc meta_name_cb; 00174 void *meta_name_cb_context; 00175 00176 /* A callback function which is called for each `use meta http 00177 equiv' pragma, found from the current compilation unit. */ 00178 WsPragmaMetaProc meta_http_equiv_cb; 00179 void *meta_http_equiv_cb_context; 00180 }; 00181 00182 typedef struct WsCompilerParamsRec WsCompilerParams; 00183 00184 /* A compiler handle. */ 00185 typedef struct WsCompilerRec *WsCompilerPtr; 00186 00187 /* Create a new WMLScript compiler. The argument `params' specifies 00188 initialization parameters for the compiler. If the argument 00189 `params' is NULL or any of its fiels have value 0 or NULL, the 00190 default values will be used for those parameters. The function 00191 takes a copy of the value of the `params' argument. You can free 00192 it after this call. The function returns NULL if the operation 00193 fails (out of memory). */ 00194 WsCompilerPtr ws_create(WsCompilerParams *params); 00195 00196 /* Destroy the WMLScript compiler `compiler' and free all resources it 00197 has allocated. */ 00198 void ws_destroy(WsCompilerPtr compiler); 00199 00200 /********************* Compiling WMLScript ******************************/ 00201 00202 /* Returns codes for the compiler functions. */ 00203 typedef enum 00204 { 00205 /* Successful termination */ 00206 WS_OK, 00207 00208 /* The compiler ran out of memory. */ 00209 WS_ERROR_OUT_OF_MEMORY, 00210 00211 /* The input was not syntactically correct. */ 00212 WS_ERROR_SYNTAX, 00213 00214 /* The input was not semantically correct. */ 00215 WS_ERROR_SEMANTIC, 00216 00217 /* IO error. */ 00218 WS_ERROR_IO, 00219 00220 /* A generic `catch-all' error code. This should not be used. More 00221 descriptive error messages should be generated instead. */ 00222 WS_ERROR 00223 } WsResult; 00224 00225 /* Compile the WMLScript input file `input' with the compiler 00226 `compiler' and save the generated byte-code output to the file 00227 `output'. The argument `input_name' is the name of the input file 00228 `input'. It is used in error messages. The function returns a 00229 success code that describes the result of the compilation. The 00230 output file `output' is modified only if the result code is 00231 `WS_OK'. */ 00232 WsResult ws_compile_file(WsCompilerPtr compiler, const char *input_name, 00233 FILE *input, FILE *output); 00234 00235 /* Compile the `input_len' bytes of WMLScript data in `input' with the 00236 compiler `compiler'. The data is assumed to be in the ISO-8859/1 00237 (ISO latin1) format. The resulting byte-code is returned in 00238 `output_return' and its length is returned in `output_len_return'. 00239 The argument `input_name' is the name of the input data 00240 `input_data'. It is used in error messages. The function returns 00241 a success code that describes the result of the compilation. The 00242 output in `output_return' is valid only if the result code is 00243 `WS_OK'. The byte-code, returned in `output_return', must be freed 00244 with the ws_free_byte_code() function after it is not needed 00245 anymore. It is a fatal error to free it with any other function, 00246 like free(). */ 00247 WsResult ws_compile_data(WsCompilerPtr compiler, const char *input_name, 00248 const unsigned char *input, size_t input_len, 00249 unsigned char **output_return, 00250 size_t *output_len_return); 00251 00252 /* Free the byte-code buffer `byte_code', returned by 00253 ws_compiler_data() function. The byte-code `byte_code' must not be 00254 used after this function has been called. */ 00255 void ws_free_byte_code(unsigned char *byte_code); 00256 00257 /* Convert the result code `result' into human readable 7 bit ASCII 00258 string. */ 00259 const char *ws_result_to_string(WsResult result); 00260 00261 #endif /* not WS_H */