00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023 #include <stdlib.h>
00024 #include <stdio.h>
00025 #include <string.h>
00026 #include <stdarg.h>
00027 #include "types.h"
00028 #include "globals.h"
00029 #include "ezxml.h"
00030 #include "read_xml_config_file.h"
00031 #include "read_xml_util.h"
00032
00033 config_t configuration;
00034
00035 void read_verilog_files(ezxml_t a_node, config_t *config);
00036 void read_outputs(ezxml_t a_node, config_t *config);
00037 void read_debug_switches(ezxml_t a_node, config_t *config);
00038 void read_optimizations(ezxml_t a_node, config_t *config);
00039 void set_default_optimization_settings(config_t *config);
00040
00041
00042
00043
00044
00045
00046
00047 void read_config_file(char *file_name)
00048 {
00049 ezxml_t doc, next;
00050
00051
00052 oassert(file_name != NULL);
00053 doc = ezxml_parse_file(file_name);
00054
00055 if (doc == NULL)
00056 {
00057 printf("error: could not parse xml configuration file\n");
00058 return;
00059 }
00060
00061
00062 CheckElement(doc, "config");
00063
00064
00065 next = FindElement(doc, "verilog_files", (boolean)TRUE);
00066 read_verilog_files(next, &configuration);
00067 FreeNode(next);
00068
00069
00070 next = FindElement(doc, "output", (boolean)TRUE);
00071 read_outputs(next, &configuration);
00072 FreeNode(next);
00073
00074
00075 set_default_optimization_settings(&configuration);
00076 next = FindElement(doc, "optimizations", (boolean)FALSE);
00077 if (next)
00078 {
00079 read_optimizations(next, &configuration);
00080 FreeNode(next);
00081 }
00082
00083
00084 next = FindElement(doc, "debug_outputs", (boolean)TRUE);
00085 read_debug_switches(next, &configuration);
00086 FreeNode(next);
00087
00088
00089 FreeNode(doc);
00090 return;
00091 }
00092
00093
00094
00095
00096 void read_verilog_files(ezxml_t a_node, config_t *config)
00097 {
00098 ezxml_t child;
00099 ezxml_t junk;
00100
00101 child = ezxml_child(a_node, "verilog_file");
00102 while (child != NULL)
00103 {
00104 if (global_args.verilog_file == NULL)
00105 {
00106 config->list_of_file_names = (char**)realloc(config->list_of_file_names, sizeof(char*)*(config->num_list_of_file_names+1));
00107 config->list_of_file_names[config->num_list_of_file_names] = strdup(ezxml_txt(child));
00108 config->num_list_of_file_names ++;
00109 }
00110 ezxml_set_txt(child, "");
00111 junk = child;
00112 child = ezxml_next(child);
00113 FreeNode(junk);
00114 }
00115 return;
00116 }
00117
00118
00119
00120
00121 void read_outputs(ezxml_t a_node, config_t *config)
00122 {
00123 ezxml_t child;
00124
00125 child = ezxml_child(a_node, "output_type");
00126 if (child != NULL)
00127 {
00128 config->output_type = strdup(ezxml_txt(child));
00129 ezxml_set_txt(child, "");
00130 FreeNode(child);
00131 }
00132
00133 child = ezxml_child(a_node, "output_path_and_name");
00134 if (child != NULL)
00135 {
00136 global_args.output_file = strdup(ezxml_txt(child));
00137 ezxml_set_txt(child, "");
00138 FreeNode(child);
00139 }
00140
00141 child = ezxml_child(a_node, "target");
00142 if (child != NULL)
00143 {
00144 ezxml_t junk = child;
00145
00146 child = ezxml_child(child, "arch_file");
00147 if (child != NULL)
00148 {
00149
00150 if (global_args.arch_file != NULL)
00151 {
00152 printf("Error: Arch file specified in config file AND command line\n");
00153 exit(-1);
00154 }
00155 global_args.arch_file = strdup(ezxml_txt(child));
00156 ezxml_set_txt(child, "");
00157 FreeNode(child);
00158 }
00159 FreeNode(junk);
00160 }
00161 return;
00162 }
00163
00164
00165
00166
00167 void read_debug_switches(ezxml_t a_node, config_t *config)
00168 {
00169 ezxml_t child;
00170
00171 child = ezxml_child(a_node, "output_ast_graphs");
00172 if (child != NULL)
00173 {
00174 config->output_ast_graphs = atoi(ezxml_txt(child));
00175 ezxml_set_txt(child, "");
00176 FreeNode(child);
00177 }
00178
00179 child = ezxml_child(a_node, "output_netlist_graphs");
00180 if (child != NULL)
00181 {
00182 config->output_netlist_graphs = atoi(ezxml_txt(child));
00183 ezxml_set_txt(child, "");
00184 FreeNode(child);
00185 }
00186
00187 child = ezxml_child(a_node, "debug_output_path");
00188 if (child != NULL)
00189 {
00190 config->debug_output_path = strdup(ezxml_txt(child));
00191 ezxml_set_txt(child, "");
00192 FreeNode(child);
00193 }
00194
00195 child = ezxml_child(a_node, "print_parse_tokens");
00196 if (child != NULL)
00197 {
00198 config->print_parse_tokens = atoi(ezxml_txt(child));
00199 ezxml_set_txt(child, "");
00200 FreeNode(child);
00201 }
00202
00203 child = ezxml_child(a_node, "output_preproc_source");
00204 if (child != NULL)
00205 {
00206 config->output_preproc_source = atoi(ezxml_txt(child));
00207 ezxml_set_txt(child, "");
00208 FreeNode(child);
00209 }
00210
00211 return;
00212 }
00213
00214
00215
00216
00217 void set_default_optimization_settings(config_t *config)
00218 {
00219 config->min_hard_multiplier = 0;
00220 config->fixed_hard_multiplier = 0;
00221 config->fracture_hard_multiplier = 1;
00222 config->split_memory_width = FALSE;
00223 config->split_memory_depth = FALSE;
00224 return;
00225 }
00226
00227
00228
00229
00230 void read_optimizations(ezxml_t a_node, config_t *config)
00231 {
00232 const char *prop;
00233 ezxml_t child;
00234
00235 child = ezxml_child(a_node, "multiply");
00236 if (child != NULL)
00237 {
00238 prop = FindProperty(child, "size", (boolean)FALSE);
00239 if (prop != NULL)
00240 {
00241 config->min_hard_multiplier = atoi(prop);
00242 ezxml_set_attr(child, "size", NULL);
00243 }
00244 else
00245 config->min_hard_multiplier = 0;
00246
00247 prop = FindProperty(child, "fixed", (boolean)FALSE);
00248 if (prop != NULL)
00249 {
00250 config->fixed_hard_multiplier = atoi(prop);
00251 ezxml_set_attr(child, "fixed", NULL);
00252 }
00253 else
00254 config->fixed_hard_multiplier = 0;
00255
00256 prop = FindProperty(child, "fracture", (boolean)FALSE);
00257 if (prop != NULL)
00258 {
00259 config->fracture_hard_multiplier = atoi(prop);
00260 ezxml_set_attr(child, "fracture", NULL);
00261 }
00262 else
00263 config->fracture_hard_multiplier = 1;
00264 FreeNode(child);
00265 }
00266
00267 child = ezxml_child(a_node, "memory");
00268 if (child != NULL)
00269 {
00270 prop = FindProperty(child, "split_memory_width", (boolean)FALSE);
00271 if (prop != NULL)
00272 {
00273 config->split_memory_width = atoi(prop);
00274 ezxml_set_attr(child, "split_memory_width", NULL);
00275 }
00276 else
00277 config->split_memory_width = 0;
00278
00279 prop = FindProperty(child, "split_memory_depth", (boolean)FALSE);
00280 if (prop != NULL)
00281 {
00282 if (strcmp(prop, "min") == 0)
00283 config->split_memory_depth = -1;
00284 else if (strcmp(prop, "max") == 0)
00285 config->split_memory_depth = -2;
00286 else
00287 config->split_memory_depth = atoi(prop);
00288 ezxml_set_attr(child, "split_memory_depth", NULL);
00289 }
00290 else
00291 config->split_memory_depth = 0;
00292
00293 FreeNode(child);
00294 }
00295
00296 return;
00297 }
00298