diff --git a/src/crushtool.cc b/src/crushtool.cc index aa6431c9b47..016337db7c8 100644 --- a/src/crushtool.cc +++ b/src/crushtool.cc @@ -24,6 +24,7 @@ #include "crush/CrushWrapper.h" #include "crush/grammar.h" + #include #include #include @@ -40,92 +41,63 @@ typedef char const* iterator_t; typedef tree_match parse_tree_match_t; typedef parse_tree_match_t::tree_iterator iter_t; -long eval_term(iter_t const& i); -long evaluate(parse_tree_match_t hit); -long eval_expression(iter_t const& i); -long evaluate(tree_parse_info<> info) -{ - std::cout << "t_id(info.trees.begin()).name(): " << typeid(info.trees.begin()).name() << '\n'; - std::cout << "info.trees.size(): " << info.trees.size() <) - //for (iter_t j = chi->value.begin(); j != chi->value.end(); ij+) { - //std::cout << "here: " << *j <value.begin()); - //std::cout << chi->value <children.size(); + string id_str = string(i->children[1].value.begin(), i->children[1].value.end()); + istringstream idStream(id_str);; + int id; + if (idStream>>id) { + cout << "id: " << id << std::endl; } - cout << "should never get here." << std::endl; - return -1; -} + string name = string(i->children[2].value.begin(), i->children[2].value.end()); + cout << "name: " << name << std::endl; + + float offload = 0; + bool have_offload = false; + if (size == 5) { + have_offload = true; + string offload_str = string(i->children[4].value.begin(), i->children[4].value.end()); + istringstream offloadStream(offload_str); + if (offloadStream>>offload) { + cout << "offload: " << offload << std::endl; + } + } +} + + +void walk_crush_config(iter_t const& i, CrushWrapper &crush, int ind=1) +{ + cout << "dump"; + for (int j=0; jvalue.id().to_long(); + cout << id << "\t"; + cout << "'" << string(i->value.begin(), i->value.end()) + << "' " << i->children.size() << " children" << std::endl; + + switch (i->value.id().to_long()) { + case crush_grammar::_device: + cout << "device" << std::endl; + parse_device(i, crush); + break; + case crush_grammar::_bucket_type: + cout << "type" << std::endl; + //parse_bucket_type(i->children.begin(), crush); + break; + case crush_grammar::_bucket: + cout << "bucket" << std::endl; + //parse_bucket(i->children.begin(), crush); + break; + case crush_grammar::_crushrule: + cout << "rule" << std::endl; + //parse_rule(i->children.begin(), crush); + break; + default: + for (unsigned int j = 0; j < i->children.size(); j++) + walk_crush_config(i->children.begin() + j, crush, ind+1); + } +} const char *infn = "stdin"; @@ -168,14 +140,14 @@ int compile_crush_file(const char *infn, CrushWrapper &crush) line++; big += str; } - + if (verbose >= 2) cout << "whole file is: \"" << big << "\"" << std::endl; crush_grammar crushg; const char *start = big.c_str(); //tree_parse_info info = ast_parse(start, crushg, space_p); tree_parse_info<> info = ast_parse(start, crushg, space_p); - + // parse error? if (!info.full) { int cpos = info.stop - start; @@ -190,32 +162,10 @@ int compile_crush_file(const char *infn, CrushWrapper &crush) << " error: parse error at '" << line_val[line].substr(pos) << "'" << std::endl; return 1; } - { - // dump parse tree as XML - std::map rule_names; - rule_names[crush_grammar::_int] = "int"; - rule_names[crush_grammar::_posint] = "posint"; - rule_names[crush_grammar::_name] = "name"; - rule_names[crush_grammar::_device] = "device"; - rule_names[crush_grammar::_bucket_type] = "bucket_type"; - rule_names[crush_grammar::_bucket_id] = "bucket_id"; - rule_names[crush_grammar::_bucket_alg] = "bucket_alg"; - rule_names[crush_grammar::_bucket_item] = "bucket_item"; - rule_names[crush_grammar::_bucket] = "bucket"; - rule_names[crush_grammar::_step_take] = "step_take"; - rule_names[crush_grammar::_step_choose_indep] = "step_choose_indep"; - rule_names[crush_grammar::_step_choose_firstn] = "step_choose_firstn"; - rule_names[crush_grammar::_step_emit] = "step_emit"; - rule_names[crush_grammar::_crushrule] = "rule"; - rule_names[crush_grammar::_crushmap] = "map"; - //tree_to_xml(cout, info.trees, big.c_str(), rule_names); - - - // print the result - cout << "parsing succeeded\n"; - cout << "result = " << evaluate(info) << "\n\n"; - } + cout << "parsing succeeded\n"; + walk_crush_config(info.trees.begin(), crush); + return 0; }