コード例 #1
0
ファイル: printer.cpp プロジェクト: JehandadKhan/roccc-2.0
/* Useful for printing annotations as comments.  Expects that
 * the annotation is a BrickAnnote. */
  void
Printer::print_annote(Annote *annote)
{
  start_comment();

  IdString name = annote->get_name();

  if (name != k_comment)
    fprintf(out, "[%s", name.chars());

  if (is_kind_of<BrickAnnote>(annote)) {
    BrickAnnote *an = (BrickAnnote *)(annote);
    char *separator = ": ";

    for (Iter<SuifBrick*> iter = an->get_brick_iterator();
        iter.is_valid(); iter.next())
    {
      fputs(separator, out);
      separator = ", ";

      SuifBrick *brick = iter.current();
      if (is_a<IntegerBrick>(brick)) {
        Integer i = ((IntegerBrick*)iter.current())->get_value();
        if (i.is_c_string_int())
          fputs(i.chars(), out);
        else
          fprintf(out, "%ld", i.c_long());
      }
      else if (is_a<StringBrick>(brick)) {
        putc('"', out);
        for (const char *p =
            ((StringBrick*)iter.current())->get_value().c_str();
            *p != '\0'; ++p)
        {
          if (*p == '"' || *p == '\\')
            putc('\\', out);
          putc(*p, out);
        }
        putc('"', out);
      }
      else {
        claim(is_a<SuifObjectBrick>(brick));
        SuifObject *so = ((SuifObjectBrick*)brick)->get_object();
        if (is_kind_of<Type>(so))
          fprint(out, (TypeId)so);
        else {
          const char *kind = so ? get_class_name(so) : "NULL";
          fprintf(out, "<<<%s object>>>", kind);
        }
      }
    }
  } else {
    claim(is_kind_of<GeneralAnnote>(annote), "Unexpected kind of Annote");
  }
  if (name != k_comment)
    fputs("]", out);
  fputs("\n", out);
}
コード例 #2
0
ファイル: opnd.cpp プロジェクト: JehandadKhan/roccc-2.0
  size_t
hash(const Opnd opnd)
{
  if (is_reg(opnd)) {
    int reg = get_reg(opnd);
    if (is_virtual_reg(opnd))
      reg = -(reg + 1);
    return reg << 1;
  } else if (is_var(opnd)) {
    return (size_t)get_var(opnd) | 1;
  } else if (is_immed_integer(opnd)) {
    Integer i = get_immed_integer(opnd);
    if (i.is_c_string_int())
      return string_hash(i.chars());
    else
      return i.c_long();
  } else if (is_immed_string(opnd)) {
    return string_hash(get_immed_string(opnd).chars());
  }
  claim(false, "Operand kind %d isn't yet hashable", get_kind(opnd));
  return 0;
}