Search in sources :

Example 1 with StructureReader

use of com.ibm.j9ddr.StructureReader in project openj9 by eclipse.

the class PointerGenerator method generateClasses.

private void generateClasses() {
    String fileName = opts.get("-f");
    String supersetFileName = opts.get("-s");
    try {
        J9DDRStructureStore store = new J9DDRStructureStore(fileName, supersetFileName);
        System.out.println("superset directory name : " + fileName);
        System.out.println("superset file name : " + store.getSuperSetFileName());
        InputStream inputStream = store.getSuperset();
        structureReader = new StructureReader(inputStream);
        inputStream.close();
    } catch (IOException e) {
        System.out.println("Problem with file: " + fileName);
        e.printStackTrace();
        return;
    }
    outputDir = getOutputDir("-p");
    if (opts.get("-h") != null) {
        // where to write the helpers to if the option is set
        outputDirHelpers = getOutputDir("-h");
    }
    typeManager = new StructureTypeManager(structureReader.getStructures());
    for (StructureDescriptor structure : structureReader.getStructures()) {
        try {
            if (FlagStructureList.isFlagsStructure(structure.getName())) {
                generateBuildFlags(structure);
            } else {
                generateClass(structure);
            }
        } catch (FileNotFoundException e) {
            String error = String.format("File Not Found processing: %s: %s", structure.getPointerName(), e.getMessage());
            System.out.println(error);
        } catch (IOException e) {
            String error = String.format("IOException processing: %s: %s", structure.getPointerName(), e.getMessage());
            System.out.println(error);
        }
    }
}
Also used : StructureTypeManager(com.ibm.j9ddr.StructureTypeManager) J9DDRStructureStore(com.ibm.j9ddr.tools.store.J9DDRStructureStore) FileInputStream(java.io.FileInputStream) InputStream(java.io.InputStream) StructureReader(com.ibm.j9ddr.StructureReader) FileNotFoundException(java.io.FileNotFoundException) IOException(java.io.IOException) StructureDescriptor(com.ibm.j9ddr.StructureReader.StructureDescriptor)

Example 2 with StructureReader

use of com.ibm.j9ddr.StructureReader in project openj9 by eclipse.

the class StructureStubGenerator method generateClasses.

private void generateClasses() {
    String supersetDirectoryName = opts.get("-f");
    String supersetFileName = opts.get("-s");
    try {
        J9DDRStructureStore store = new J9DDRStructureStore(supersetDirectoryName, supersetFileName);
        System.out.println("superset directory name : " + supersetDirectoryName);
        System.out.println("superset file name : " + store.getSuperSetFileName());
        InputStream inputStream = store.getSuperset();
        structureReader = new StructureReader(inputStream);
        inputStream.close();
    } catch (IOException e) {
        System.out.println("Could not find file: " + supersetDirectoryName + "/" + supersetFileName);
        return;
    }
    outputDir = getOutputDir();
    for (StructureDescriptor structure : structureReader.getStructures()) {
        try {
            if (FlagStructureList.isFlagsStructure(structure.getName())) {
            // generateBuildFlags(structure);
            } else {
                generateClass(structure);
            }
        } catch (FileNotFoundException e) {
            String error = String.format("File Not Found processing: %s: %s", structure.getName(), e.getMessage());
            System.out.println(error);
        } catch (IOException e) {
            String error = String.format("IOException processing: %s: %s", structure.getName(), e.getMessage());
            System.out.println(error);
        }
    }
}
Also used : J9DDRStructureStore(com.ibm.j9ddr.tools.store.J9DDRStructureStore) FileInputStream(java.io.FileInputStream) InputStream(java.io.InputStream) StructureReader(com.ibm.j9ddr.StructureReader) FileNotFoundException(java.io.FileNotFoundException) IOException(java.io.IOException) StructureDescriptor(com.ibm.j9ddr.StructureReader.StructureDescriptor)

Example 3 with StructureReader

use of com.ibm.j9ddr.StructureReader in project openj9 by eclipse.

the class J9DDRStructureStore method updateSuperset.

public void updateSuperset() throws IOException {
    StructureReader reader = null;
    if ((structureBytes.length > 2) && (structureBytes[0] == SUPERSET_ID[0]) && (structureBytes[1] == SUPERSET_ID[1])) {
        // creating a reader using an input stream treats it as a superset input i.e. text
        InputStream in = new ByteArrayInputStream(structureBytes);
        reader = new StructureReader(in);
    } else {
        // using an image input stream to the reader indicates that is in binary blob format
        ImageInputStream inputStream = new MemoryCacheImageInputStream(new ByteArrayInputStream(structureBytes));
        reader = new StructureReader(inputStream);
    }
    for (StructureDescriptor structure : reader.getStructures()) {
        String structureHeader = structure.deflate();
        HashSet<String> structureContents = superset.get(structureHeader);
        if (structureContents == null) {
            structureContents = new HashSet<String>();
            superset.put(structureHeader, structureContents);
        }
        for (FieldDescriptor field : structure.getFields()) {
            addFieldToSuperset(structureContents, field);
        }
        for (ConstantDescriptor constant : structure.getConstants()) {
            String constantHeader = constant.deflate();
            structureContents.add(constantHeader);
        }
    }
    writeSuperset();
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) MemoryCacheImageInputStream(javax.imageio.stream.MemoryCacheImageInputStream) ByteArrayInputStream(java.io.ByteArrayInputStream) FileInputStream(java.io.FileInputStream) ImageInputStream(javax.imageio.stream.ImageInputStream) DigestInputStream(java.security.DigestInputStream) InputStream(java.io.InputStream) ConstantDescriptor(com.ibm.j9ddr.StructureReader.ConstantDescriptor) StructureReader(com.ibm.j9ddr.StructureReader) MemoryCacheImageInputStream(javax.imageio.stream.MemoryCacheImageInputStream) ImageInputStream(javax.imageio.stream.ImageInputStream) MemoryCacheImageInputStream(javax.imageio.stream.MemoryCacheImageInputStream) StructureDescriptor(com.ibm.j9ddr.StructureReader.StructureDescriptor) FieldDescriptor(com.ibm.j9ddr.StructureReader.FieldDescriptor)

Example 4 with StructureReader

use of com.ibm.j9ddr.StructureReader in project openj9 by eclipse.

the class PrintBlob method main.

/**
 * @param args
 */
public static void main(String[] args) throws Exception {
    if (args.length != 1) {
        System.err.println("Expected 1 argument. Got " + args.length);
        System.exit(1);
    }
    File blobFile = new File(args[0]);
    ImageInputStream iis = new FileImageInputStream(blobFile);
    iis.setByteOrder(ByteOrder.LITTLE_ENDIAN);
    StructureReader structReader = new StructureReader(iis);
    List<StructureDescriptor> structures = new ArrayList<StructureDescriptor>(structReader.getStructures());
    Collections.sort(structures, new Comparator<StructureDescriptor>() {

        public int compare(StructureDescriptor o1, StructureDescriptor o2) {
            return o1.getName().compareTo(o2.getName());
        }
    });
    for (StructureDescriptor thisStruct : structures) {
        String superClass = thisStruct.getSuperName();
        if (superClass != null && superClass.length() > 0) {
            System.out.println("Structure: " + thisStruct.getName() + " extends " + superClass);
        } else {
            System.out.println("Structure: " + thisStruct.getName());
        }
    // List<FieldDescriptor> fields = new ArrayList<FieldDescriptor>(thisStruct.getFields());
    // 
    // Collections.sort(fields, new Comparator<FieldDescriptor>(){
    // 
    // public int compare(FieldDescriptor o1, FieldDescriptor o2)
    // {
    // return o1.getName().compareTo(o2.getName());
    // }});
    // 
    // System.out.println("\tFields");
    // 
    // for (FieldDescriptor thisField : fields) {
    // System.out.println("\t\t" + thisField.getName() + " - " + thisField.getType());
    // }
    // 
    // List<ConstantDescriptor> constants = new ArrayList<ConstantDescriptor>(thisStruct.getConstants());
    // 
    // Collections.sort(constants, new Comparator<ConstantDescriptor>(){
    // 
    // public int compare(ConstantDescriptor o1, ConstantDescriptor o2)
    // {
    // return o1.getName().compareTo(o2.getName());
    // }});
    // 
    // System.out.println("\tConstants:");
    // for (ConstantDescriptor thisConstant : constants) {
    // System.out.println("\t\t" + thisConstant.getName());
    // }
    }
}
Also used : FileImageInputStream(javax.imageio.stream.FileImageInputStream) FileImageInputStream(javax.imageio.stream.FileImageInputStream) ImageInputStream(javax.imageio.stream.ImageInputStream) StructureReader(com.ibm.j9ddr.StructureReader) ArrayList(java.util.ArrayList) File(java.io.File) StructureDescriptor(com.ibm.j9ddr.StructureReader.StructureDescriptor)

Aggregations

StructureReader (com.ibm.j9ddr.StructureReader)4 StructureDescriptor (com.ibm.j9ddr.StructureReader.StructureDescriptor)4 FileInputStream (java.io.FileInputStream)3 InputStream (java.io.InputStream)3 J9DDRStructureStore (com.ibm.j9ddr.tools.store.J9DDRStructureStore)2 FileNotFoundException (java.io.FileNotFoundException)2 IOException (java.io.IOException)2 ImageInputStream (javax.imageio.stream.ImageInputStream)2 ConstantDescriptor (com.ibm.j9ddr.StructureReader.ConstantDescriptor)1 FieldDescriptor (com.ibm.j9ddr.StructureReader.FieldDescriptor)1 StructureTypeManager (com.ibm.j9ddr.StructureTypeManager)1 ByteArrayInputStream (java.io.ByteArrayInputStream)1 File (java.io.File)1 DigestInputStream (java.security.DigestInputStream)1 ArrayList (java.util.ArrayList)1 FileImageInputStream (javax.imageio.stream.FileImageInputStream)1 MemoryCacheImageInputStream (javax.imageio.stream.MemoryCacheImageInputStream)1