Package wyfs.io

Examples of wyfs.io.BinaryOutputStream


  private final HashMap<Constant,Integer> constantCache = new HashMap<Constant,Integer>();
  private final ArrayList<Type> typePool = new ArrayList<Type>();
  private final HashMap<Type,Integer> typeCache = new HashMap<Type,Integer>();

  public WyilFileWriter(OutputStream output) {
    this.out = new BinaryOutputStream(output);
  }
View Full Code Here


   * @throws IOException
   */
  private byte[] generateHeaderBlock(WyilFile module)
      throws IOException {
    ByteArrayOutputStream bytes = new ByteArrayOutputStream();
    BinaryOutputStream output = new BinaryOutputStream(bytes);

    // second, write the file version number
    output.write_uv(MAJOR_VERSION);
    output.write_uv(MINOR_VERSION);

    // third, write the various pool sizes
    output.write_uv(stringPool.size());
    output.write_uv(pathPool.size());
    output.write_uv(namePool.size());
    output.write_uv(typePool.size());
    output.write_uv(constantPool.size());

    // finally, write the number of remaining blocks
    output.write_uv(module.blocks().size());

    writeStringPool(output);
    writePathPool(output);
    writeNamePool(output);
    writeTypePool(output);
    writeConstantPool(output);

    output.close();

    return bytes.toByteArray();
  }
View Full Code Here

    }
  }

  private byte[] generateModuleBlock(WyilFile module) throws IOException {
    ByteArrayOutputStream bytes = new ByteArrayOutputStream();
    BinaryOutputStream output = new BinaryOutputStream(bytes);

    output.write_uv(pathCache.get(module.id())); // FIXME: BROKEN!
    output.write_uv(MODIFIER_Public); // for now
    output.write_uv(module.blocks().size());

    for(WyilFile.Block d : module.blocks()) {
      writeModuleBlock(d,output);
    }

        output.close();

    return bytes.toByteArray();
  }
View Full Code Here

    }
  }

  private byte[] generateConstantBlock(WyilFile.ConstantDeclaration cd) throws IOException {
    ByteArrayOutputStream bytes = new ByteArrayOutputStream();
    BinaryOutputStream output = new BinaryOutputStream(bytes);

    output.write_uv(stringCache.get(cd.name()));
    output.write_uv(generateModifiers(cd.modifiers()));
    output.write_uv(constantCache.get(cd.constant()));
    output.write_uv(0); // no sub-blocks
    // TODO: write annotations

    output.close();
    return bytes.toByteArray();
  }
View Full Code Here

    return bytes.toByteArray();
  }

  private byte[] generateTypeBlock(WyilFile.TypeDeclaration td) throws IOException {
    ByteArrayOutputStream bytes = new ByteArrayOutputStream();
    BinaryOutputStream output = new BinaryOutputStream(bytes);

    output.write_uv(stringCache.get(td.name()));
    output.write_uv(generateModifiers(td.modifiers()));
    output.write_uv(typeCache.get(td.type()));
    Code.Block invariant = td.invariant();

    if(invariant != null) {
      output.write_uv(1);
      writeBlock(BLOCK_Constraint,td.invariant(),output);
    } else {
      output.write_uv(0);
    }

    output.close();
    return bytes.toByteArray();
  }
View Full Code Here

    return bytes.toByteArray();
  }

  private byte[] generateFunctionOrMethodBlock(WyilFile.FunctionOrMethodDeclaration md) throws IOException {
    ByteArrayOutputStream bytes = new ByteArrayOutputStream();
    BinaryOutputStream output = new BinaryOutputStream(bytes);

    output.write_uv(stringCache.get(md.name()));
    output.write_uv(generateModifiers(md.modifiers()));
    output.write_uv(typeCache.get(md.type()));
    output.write_uv(md.cases().size());

    for(WyilFile.Case c : md.cases()) {
      writeBlock(BLOCK_Case,c,output);
    }

    // TODO: write annotations
    output.close();
    return bytes.toByteArray();
  }
View Full Code Here

    return bytes.toByteArray();
  }

  private byte[] generateFunctionOrMethodCaseBlock(WyilFile.Case c) throws IOException {
    ByteArrayOutputStream bytes = new ByteArrayOutputStream();
    BinaryOutputStream output = new BinaryOutputStream(bytes);

    int bodyCount = c.body() == null ? 0 : 1;

    output.write_uv(c.precondition().size() + c.postcondition().size() + bodyCount);
    for(Code.Block requires : c.precondition()) {
      writeBlock(BLOCK_Precondition,requires,output);
    }
    for(Code.Block ensures : c.postcondition()) {
      writeBlock(BLOCK_Postcondition,ensures,output);
    }
    if(c.body() != null) {
      writeBlock(BLOCK_Body,c.body(),output);
    }
    // TODO: write annotations

    output.close();
    return bytes.toByteArray();
  }
View Full Code Here

    return bytes.toByteArray();
  }

  private byte[] generateCodeBlock(Code.Block block) throws IOException {
    ByteArrayOutputStream bytes = new ByteArrayOutputStream();
    BinaryOutputStream output = new BinaryOutputStream(bytes);

    HashMap<String,Integer> labels = new HashMap<String,Integer>();

    int nlabels = 0;
    int offset = 0;
    for(Code.Block.Entry e : block) {
      Code code = e.code;
      if(code instanceof Codes.Label) {
        Codes.Label l = (Codes.Label) code;
        labels.put(l.label, offset);
        nlabels++;
      } else {
        offset++;
      }
    }

    output.write_uv(block.size()-nlabels); // instruction count (not same as block size!)
    offset = 0;
    for(Code.Block.Entry e : block) {
      if(e.code instanceof Codes.Label) {

      } else {
        writeCode(e.code, offset++, labels, output);
      }
    }

    output.close();
    return bytes.toByteArray();
  }
View Full Code Here

        }
        index++;
      }

      if(binary) {
        BinaryOutputStream bos = new BinaryOutputStream(out);
        writer = new BinaryAutomataWriter(bos);
      } else {
        writer = new TextAutomataWriter(out);
      }
      for(int i=minSize;i<=maxSize;++i) {
View Full Code Here

        reader = new BinaryAutomataReader(bis);
      } else {
        reader = null; // TODO
      }
      if(binaryOut) {
        BinaryOutputStream bos = new BinaryOutputStream(output);
        writer = new BinaryAutomataWriter(bos);
      } else {
        writer = new TextAutomataWriter(output);
      }
      int nread = 0;
View Full Code Here

TOP

Related Classes of wyfs.io.BinaryOutputStream

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.