예제 #1
0
  public void flush(MemoryStream output, Temp temp) {
    output.writeString(m_field);
    int fields_count = m_values.size();
    output.writeVInt(fields_count);
    // 1. write dictionary
    int[] remap = m_values.sort();
    MemoryStream s_pfx = temp.getStream(0);
    MemoryStream s_sfx = temp.getStream(1);
    MemoryStream s_len = temp.getStream(2);
    MemoryStream s_dat = temp.getStream(3);
    BSTR last = temp.getBSTR();

    int[] m_doc_to_val = new int[remap.length];

    for (int i = 0; i < fields_count; i++) {
      m_doc_to_val[remap[i]] = i;
      BSTR next = m_values.get(remap[i]);
      int l = Math.min(last.length, next.length);
      int pfx = 0;
      while (pfx < l && last.buffer[pfx] == next.buffer[pfx]) pfx++;
      int sfx = 0;
      while (sfx < l - pfx
          && last.buffer[last.length - sfx - 1] == next.buffer[next.length - sfx - 1]) sfx++;
      s_pfx.writeVInt(pfx);
      s_sfx.writeVInt(sfx);
      s_len.writeVInt(next.length);
      s_dat.write(next.buffer, pfx, next.length - sfx - pfx);
      last.set(next);
    }

    Temp.writeCompressed(output, s_pfx);
    Temp.writeCompressed(output, s_sfx);
    Temp.writeCompressed(output, s_len);
    Temp.writeCompressed(output, s_dat);

    // 2. Write indexes
    MemoryStream s_lst = temp.getStream(0);
    MemoryStream s_fst = temp.getStream(1);

    for (int i = 0; i < m_docs.length; i++) {
      int index = m_doc_to_val[m_docs[i]];
      s_lst.writeByte((byte) index);
      if (fields_count >= 256) {
        s_fst.writeVInt(index >> 8);
      }
    }
    Temp.writeCompressed(output, s_lst);
    if (fields_count >= 256) {
      Temp.writeCompressed(output, s_fst);
    }
  }
예제 #2
0
  public String toCode() {
    if (rs.num == rd.num) return null;

    if (rs.toCode(this) == null && rd.toCode(this) == null) {
      return "\tlw $t0, " + (rs.num * 4) + "($sp)\n" + "\tsw $t0, " + (rd.num * 4) + "($sp)";
    } else if (rs.toCode(this) == null && rd.toCode(this) != null) {
      return "\tlw " + rd.toCode(this) + ", " + (rs.num * 4) + "($sp)";
    } else if (rs.toCode(this) != null && rd.toCode(this) == null) {
      return "\tsw " + rs.toCode(this) + ", " + (rd.num * 4) + "($sp)";
    } else {
      if (rs.toCode(this) == rd.toCode(this)) return null;
      return "\tmove " + rd.toCode(this) + ", " + rs.toCode(this);
    }
  }
예제 #3
0
 @Override
 public void replaceUseOf(Temp old, Temp t) {
   if (x.equals(old)) {
     x = t;
   }
 }
예제 #4
0
파일: Op.java 프로젝트: robertacnm/CompTP
 public Expression reduce() {
   Expression x = gen();
   Temp t = new Temp(type);
   emit(t.toString() + " = " + x.toString());
   return t;
 }