00001 /* 00002 * libexo.h - EXO library interfaces (NEVER write another scanf()!) 00003 * 00004 * This file is a part of the SimpleScalar tool suite written by 00005 * Todd M. Austin as a part of the Multiscalar Research Project. 00006 * 00007 * The tool suite is currently maintained by Doug Burger and Todd M. Austin. 00008 * 00009 * Copyright (C) 1997 by Todd M. Austin 00010 * 00011 * This source file is distributed "as is" in the hope that it will be 00012 * useful. The tool set comes with no warranty, and no author or 00013 * distributor accepts any responsibility for the consequences of its 00014 * use. 00015 * 00016 * Everyone is granted permission to copy, modify and redistribute 00017 * this tool set under the following conditions: 00018 * 00019 * This source code is distributed for non-commercial use only. 00020 * Please contact the maintainer for restrictions applying to 00021 * commercial use. 00022 * 00023 * Permission is granted to anyone to make or distribute copies 00024 * of this source code, either as received or modified, in any 00025 * medium, provided that all copyright notices, permission and 00026 * nonwarranty notices are preserved, and that the distributor 00027 * grants the recipient permission for further redistribution as 00028 * permitted by this document. 00029 * 00030 * Permission is granted to distribute this file in compiled 00031 * or executable form under the same conditions that apply for 00032 * source code, provided that either: 00033 * 00034 * A. it is accompanied by the corresponding machine-readable 00035 * source code, 00036 * B. it is accompanied by a written offer, with no time limit, 00037 * to give anyone a machine-readable copy of the corresponding 00038 * source code in return for reimbursement of the cost of 00039 * distribution. This written offer must permit verbatim 00040 * duplication by anyone, or 00041 * C. it is distributed by someone who received only the 00042 * executable form, and is accompanied by a copy of the 00043 * written offer of source code that they received concurrently. 00044 * 00045 * In other words, you are welcome to use, share and improve this 00046 * source file. You are forbidden to forbid anyone else to use, share 00047 * and improve what you give them. 00048 * 00049 * INTERNET: dburger@cs.wisc.edu 00050 * US Mail: 1210 W. Dayton Street, Madison, WI 53706 00051 * 00052 * $Id: libexo.h,v 1.1.1.1 2003/09/18 00:57:55 panalyzer Exp $ 00053 * 00054 * $Log: libexo.h,v $ 00055 * Revision 1.1.1.1 2003/09/18 00:57:55 panalyzer 00056 * 00057 * 00058 * Revision 1.1.1.1 2003/09/18 00:18:44 panalyzer 00059 * 00060 * 00061 * Revision 1.1.1.1 2003/09/16 18:48:14 gdm 00062 * 00063 * 00064 * Revision 1.1.1.1 2000/11/29 14:53:54 cu-cs 00065 * Grand unification of arm sources. 00066 * 00067 * 00068 * Revision 1.1.1.1 2000/05/26 15:21:53 taustin 00069 * SimpleScalar Tool Set 00070 * 00071 * 00072 * Revision 1.1 1998/08/27 08:55:28 taustin 00073 * Initial revision 00074 * 00075 * 00076 */ 00077 00078 /* 00079 * EXO(-skeletal) definitions: 00080 * 00081 * The EXO format is used to store and retrieve data structures from text 00082 * files. The following BNF definition defines the contents of an EXO file: 00083 * 00084 * <exo_file> := <exo_term> 00085 * 00086 * <exo_term> := <exo_term_list> 00087 * | INTEGER 00088 * | FLOAT 00089 * | CHAR 00090 * | STRING 00091 * 00092 * <exo_term_list> := (<exo_term_list> ',' <exo_term>) 00093 * | <exo_term> 00094 */ 00095 00096 #ifndef EXO_H 00097 #define EXO_H 00098 00099 #include "host.h" 00100 #include "misc.h" 00101 #include "machine.h" 00102 00103 /* EXO file format versions */ 00104 #define EXO_FMT_MAJOR 1 00105 #define EXO_FMT_MINOR 0 00106 00107 /* EXO term classes, keep this in sync with EXO_CLASS_STR */ 00108 enum exo_class_t { 00109 ec_integer, /* EXO int value */ 00110 ec_address, /* EXO address value */ 00111 ec_float, /* EXO FP value */ 00112 ec_char, /* EXO character value */ 00113 ec_string, /* EXO string value */ 00114 ec_list, /* EXO list */ 00115 ec_array, /* EXO array */ 00116 ec_token, /* EXO token value */ 00117 ec_blob, /* EXO blob (Binary Large OBject) */ 00118 ec_null, /* used internally */ 00119 ec_NUM 00120 }; 00121 00122 /* EXO term classes print strings */ 00123 extern char *exo_class_str[ec_NUM]; 00124 00125 /* EXO token table entry */ 00126 struct exo_token_t { 00127 struct exo_token_t *next; /* next element in a hash buck chain */ 00128 char *str; /* token string */ 00129 int token; /* token value */ 00130 }; 00131 00132 struct exo_term_t { 00133 struct exo_term_t *next; /* next element, when in a list */ 00134 enum exo_class_t ec; /* term node class */ 00135 union { 00136 struct as_integer_t { 00137 exo_integer_t val; /* integer value */ 00138 } as_integer; 00139 struct as_address_t { 00140 exo_address_t val; /* address value */ 00141 } as_address; 00142 struct as_float_t { 00143 exo_float_t val; /* floating point value */ 00144 } as_float; 00145 struct as_char_t { 00146 char val; /* character value */ 00147 } as_char; 00148 struct as_string_t { 00149 unsigned char *str; /* string value */ 00150 } as_string; 00151 struct as_list_t { 00152 struct exo_term_t *head; /* list head pointer */ 00153 } as_list; 00154 struct as_array_t { 00155 int size; /* size of the array */ 00156 struct exo_term_t **array; /* list head pointer */ 00157 } as_array; 00158 struct as_token_t { 00159 struct exo_token_t *ent; /* token table entry */ 00160 } as_token; 00161 struct as_blob_t { 00162 int size; /* byte size of object */ 00163 unsigned char *data; /* pointer to blob data */ 00164 } as_blob; 00165 } variant; 00166 }; 00167 /* short-cut accessors */ 00168 #define as_integer variant.as_integer 00169 #define as_address variant.as_address 00170 #define as_float variant.as_float 00171 #define as_char variant.as_char 00172 #define as_string variant.as_string 00173 #define as_list variant.as_list 00174 #define as_array variant.as_array 00175 #define as_token variant.as_token 00176 #define as_blob variant.as_blob 00177 00178 /* EXO array accessor, may be used as an L-value or R-value */ 00179 /* EXO array accessor, may be used as an L-value or R-value */ 00180 #define EXO_ARR(E,N) \ 00181 ((E)->ec != ec_array \ 00182 ? (fatal("not an array"), *(struct exo_term_t **)(NULL)) \ 00183 : ((N) >= (E)->as_array.size \ 00184 ? (fatal("array bounds error"), *(struct exo_term_t **)(NULL)) \ 00185 : (E)->as_array.array[(N)])) 00186 #define SET_EXO_ARR(E,N,V) \ 00187 ((E)->ec != ec_array \ 00188 ? (void)fatal("not an array") \ 00189 : ((N) >= (E)->as_array.size \ 00190 ? (void)fatal("array bounds error") \ 00191 : (void)((E)->as_array.array[(N)] = (V)))) 00192 00193 /* intern token TOKEN_STR */ 00194 struct exo_token_t * 00195 exo_intern(char *token_str); /* string to intern */ 00196 00197 /* intern token TOKEN_STR as value TOKEN */ 00198 struct exo_token_t * 00199 exo_intern_as(char *token_str, /* string to intern */ 00200 int token); /* internment value */ 00201 00202 /* 00203 * create a new EXO term, usage: 00204 * 00205 * exo_new(ec_integer, (exo_integer_t)<int>); 00206 * exo_new(ec_address, (exo_address_t)<int>); 00207 * exo_new(ec_float, (exo_float_t)<float>); 00208 * exo_new(ec_char, (int)<char>); 00209 * exo_new(ec_string, "<string>"); 00210 * exo_new(ec_list, <list_ent>..., NULL); 00211 * exo_new(ec_array, <size>, <array_ent>..., NULL); 00212 * exo_new(ec_token, "<token>"); 00213 * exo_new(ec_blob, <size>, <data_ptr>); 00214 */ 00215 struct exo_term_t * 00216 exo_new(enum exo_class_t ec, ...); 00217 00218 /* release an EXO term */ 00219 void 00220 exo_delete(struct exo_term_t *exo); 00221 00222 /* chain two EXO lists together, FORE is attached on the end of AFT */ 00223 struct exo_term_t * 00224 exo_chain(struct exo_term_t *fore, struct exo_term_t *aft); 00225 00226 /* copy an EXO node */ 00227 struct exo_term_t * 00228 exo_copy(struct exo_term_t *exo); 00229 00230 /* deep copy an EXO structure */ 00231 struct exo_term_t * 00232 exo_deepcopy(struct exo_term_t *exo); 00233 00234 /* print an EXO term */ 00235 void 00236 exo_print(struct exo_term_t *exo, FILE *stream); 00237 00238 /* read one EXO term from STREAM */ 00239 struct exo_term_t * 00240 exo_read(FILE *stream); 00241 00242 /* lexor components */ 00243 enum lex_t { 00244 lex_integer = 256, 00245 lex_address, 00246 lex_float, 00247 lex_char, 00248 lex_string, 00249 lex_token, 00250 lex_byte, 00251 lex_eof 00252 }; 00253 00254 #endif /* EXO_H */