pike.git / bin / mkpeep.pike

version» Context lines:

pike.git/bin/mkpeep.pike:141:    break;       // condition    case '[':    {    int i=find_end(line);    t += ({ line[0..i] });    line = line[i+1..];    }    break; +  +  // Error message +  case '"': +  int i; +  for (i = 1; (i < sizeof(line)); i++) { +  if (line[i] == '"') break; +  if (line[i] == '\\') i++;    } -  +  t += ({ line[..i] }); +  line = line[i+1..]; +  break;    -  +  case ' ': case '\t': case '\r': case '\n': +  break; +  +  default: +  werror("Unsupported character: '%c' (%d)\n", +  line[0], line[0]); +  line = line[1..]; +  break; +  } +     SKIPWHITE(line);    }       return t;   }      class Rule {    array(string) from;    array(string) to;    int opcodes;
pike.git/bin/mkpeep.pike:281:    if(sizeof(cases[c])==1 && cases[c][0]->is_switch)    ([object(Switch)]cases[c][0])->make_fun();    else    foreach(cases[c], object(Switch)|object(Breakable) b)    if(b->is_switch)    ([object(Switch)]b)->make_child_fun();    }       void make_fun() {    made_fun = ++function_serial; -  functions += "INLINE static int _asm_peep_"+made_fun+"(void)\n{\n"; +  functions += "static int _asm_peep_"+made_fun+"(void)\n{\n";    functions += make_switch(2);    functions +=    " return 0;\n"    "}\n"    "\n";    }       int made_fun;    string get_string(int(0..) ind) {    if(made_fun) {
pike.git/bin/mkpeep.pike:307:    return ret;    }    return make_switch(ind);    }       string make_switch(int(0..) ind) {    string ret = "";    ret += sprintf("%*nswitch(%s)\n", ind, test);    ret += sprintf("%*n{\n", ind);    +  mapping(string:array(string)) rev = ([]); +  foreach(sort(indices(cases)), string c) +  { +  if(`+(@cases[c]->is_switch)) continue; +  string code = cases[c]->get_string(0)*""; +  while( sscanf(code, "%s/*%*s*/%s", code, string tail)==3 ) +  code = code+tail; +  rev[ code ] += ({ c }); +  } +  mapping(string:array(string)) alias = ([]); +  foreach(rev;; array(string) cs) +  { +  if( sizeof(cs)>1 ) +  { +  alias[cs[0]] = cs[1..]; +  foreach(cs[1..], string c) +  m_delete(cases, c); +  } +  } +     foreach(sort(indices(cases)), string c) {    ret += sprintf("%*ncase %s:\n", ind, c); -  +  if( alias[c] ) +  foreach( alias[c], string c ) +  ret += sprintf("%*ncase %s:\n", ind, c); +     foreach(cases[c], object(Switch)|object(Breakable) b)    ret += b->get_string([int(0..)](ind+2));    ret += sprintf("%*n break;\n"    "\n",    ind);    }       ret += sprintf("%*n}\n", ind);    return ret;    }
pike.git/bin/mkpeep.pike:336:    lines += ({ ({ a,b,c }) });    else    lines += ({ a });    }       string get_string(int(0..) ind) {    string ret = "";    foreach(lines, string|array(string) line)    if(stringp(line)) {    if(String.trim_all_whites([string]line)=="") -  ret += line; +  ret += [string]line;    else    ret += sprintf("%*n%s\n", ind, [string]line);    }    else {    array(string) line = [array(string)]line;    ret += make_multiline(" "*ind+line[0], line[1], line[2]);    }    return ret;    }   }
pike.git/bin/mkpeep.pike:443:    for(int i=0; i<sizeof(d->to); i++)    {    array(string) args=({});    string fcode=d->to[i];    if(i+1<sizeof(d->to) && d->to[i+1][0]=='(')    {    string tmp=d->to[i+1];    args=explode_comma_expr(tmp[1..sizeof(tmp)-2]);    i++;    } +  if (fcode[0] == '"') { +  buf->add_line(" "*ind+"my_yyerror(", +  ({ fcode, @map(args,treat)[*]+"" }) * ", ", +  ");"); +  continue; +  }    ops += ({ ({ sizeof(args)+1+", ", fcode+", ",    @map(args,treat)[*]+", " }) });    }    opargs += ({ sizeof(ops) + ", " }) + reverse(ops) * ({});    buf->add_line(" "*ind+"do_optimization(", opargs, "0);");       buf->add_line( sprintf("%*nreturn 1;", ind) );    ind -= 2;    buf->add_line( sprintf("%*n}", ind) );    }    ret += ({ buf });    }    return ret;   }    -  + void check_duplicates(array(Rule) data) + { +  int err; +  mapping(string:Rule) froms = ([]); +  foreach(data;; Rule r) +  { +  if(froms[r->from*","]) +  { +  werror("Collision between\n %O and\n %O.\n", +  froms[r->from*","]->line, r->line); +  err=1; +  } +  froms[r->from*","] = r; +  }    -  +  if(err) +  exit(1, "Found %d rule collisions.\n", err); + } +    int main(int argc, array(string) argv)   {    array(Rule) data=({});       // Read input file    string f=cpp(Stdio.read_file(argv[1]), argv[1]);    foreach(f/"\n",f)    {    if(f=="" || f[0]=='#') continue;       // Parse expressions    foreach(f/";",f) {    f = String.trim_all_whites(f);    if(!sizeof(f)) continue;    data += ({ Rule(f) });    }    }    -  +  check_duplicates(data); +     write("\n\n/* Generated from %s by mkpeep.pike\n %s\n*/\n\n",    argv[1], Calendar.ISO.now()->format_time());       array(Switch) a = [array(Switch)]make_switches(data);       a->make_child_fun();       write( functions );    -  write("INLINE static int low_asm_opt(void) {\n"); +  write("static int low_asm_opt(void) {\n");    map(a->get_string(2), write);       write(" return 0;\n"    "}\n");       return 0;   }