Search in sources :

Example 1 with MemoryMapConfigMemoryItem

use of net.praqma.jenkins.memorymap.result.MemoryMapConfigMemoryItem in project memory-map-plugin by Praqma.

the class GccMemoryMapParser method getSections.

/*
     * SECTIONS {
     * ---
     * secname start BLOCK(align) (NOLOAD) : AT ( ldadr )
     { contents } >region =fill
     ...
     }
     *
     */
public List<MemoryMapConfigMemoryItem> getSections(CharSequence m) {
    List<MemoryMapConfigMemoryItem> items = new ArrayList<>();
    Pattern section = Pattern.compile("SECTIONS\\s?\\r?\\n?\\{([\\s\\S]*)\\n\\}", Pattern.MULTILINE);
    Matcher sectionMatched = section.matcher(m);
    String sectionString = null;
    while (sectionMatched.find()) {
        sectionString = sectionMatched.group(1);
    }
    // Find the good stuff (SECTION): *SECTIONS\n\{(.*)\n\}
    Matcher fm = MEM_SECTIONS.matcher(sectionString);
    while (fm.find()) {
        MemoryMapConfigMemoryItem it = new MemoryMapConfigMemoryItem(fm.group(1), "0");
        items.add(it);
    }
    return items;
}
Also used : Pattern(java.util.regex.Pattern) MemoryMapConfigMemoryItem(net.praqma.jenkins.memorymap.result.MemoryMapConfigMemoryItem) Matcher(java.util.regex.Matcher) ArrayList(java.util.ArrayList) HexifiableString(net.praqma.jenkins.memorymap.util.HexUtils.HexifiableString)

Example 2 with MemoryMapConfigMemoryItem

use of net.praqma.jenkins.memorymap.result.MemoryMapConfigMemoryItem in project memory-map-plugin by Praqma.

the class GccMemoryMapParser method getMemory.

/**
 * Parses the MEMORY section of the GCC file. Throws an abort exception
 * which will be shown in the Jenkins console log.
 *
 * @param seq The content of the map file
 * @return a list of the defined MEMORY in the map file
 * @throws hudson.AbortException when a illegal value of memory found
 */
public MemoryMapConfigMemory getMemory(CharSequence seq) throws AbortException {
    Pattern allMemory = Pattern.compile("^\\s*(\\S+).*?(?:ORIGIN|org|o)\\s*=\\s*([^,]*).*?(?:LENGTH|len|l)\\s*\\=\\s*([^\\s]*)", Pattern.MULTILINE);
    Matcher match = allMemory.matcher(seq);
    MemoryMapConfigMemory memory = new MemoryMapConfigMemory();
    while (match.find()) {
        try {
            String hexLength = new HexUtils.HexifiableString(match.group(3)).toValidHexString().rawString;
            MemoryMapConfigMemoryItem item = new MemoryMapConfigMemoryItem(match.group(1), match.group(2), hexLength);
            memory.add(item);
        } catch (Throwable ex) {
            logger.log(Level.SEVERE, "Unable to convert %s to a valid hex string.", ex);
            throw new AbortException(String.format("Unable to convert %s to a valid hex string.", match.group(3)));
        }
    }
    return memory;
}
Also used : Pattern(java.util.regex.Pattern) MemoryMapConfigMemoryItem(net.praqma.jenkins.memorymap.result.MemoryMapConfigMemoryItem) Matcher(java.util.regex.Matcher) MemoryMapConfigMemory(net.praqma.jenkins.memorymap.result.MemoryMapConfigMemory) HexifiableString(net.praqma.jenkins.memorymap.util.HexUtils.HexifiableString) HexifiableString(net.praqma.jenkins.memorymap.util.HexUtils.HexifiableString) AbortException(hudson.AbortException)

Example 3 with MemoryMapConfigMemoryItem

use of net.praqma.jenkins.memorymap.result.MemoryMapConfigMemoryItem in project memory-map-plugin by Praqma.

the class TexasInstrumentsMemoryMapParser method parseMapFile.

@Override
public MemoryMapConfigMemory parseMapFile(File f, MemoryMapConfigMemory config) throws IOException {
    CharSequence sequence = createCharSequenceFromFile(f);
    for (MemoryMapConfigMemoryItem item : config) {
        Matcher matcher = MemoryMapMapParserDelegate.getPatternForMemorySection(item.getName()).matcher(sequence);
        boolean found = false;
        while (matcher.find()) {
            item.setUsed(matcher.group(8));
            item.setUnused(matcher.group(10));
            found = true;
        }
        if (!found) {
            logger.logp(Level.WARNING, "parseMapFile", AbstractMemoryMapParser.class.getName(), String.format("parseMapFile(File f, MemoryMapConfigMemory configuration) non existing item: %s", item));
            throw new MemoryMapMemorySelectionError(String.format("Linker command element %s not found in .map file", item));
        }
    }
    return config;
}
Also used : MemoryMapMemorySelectionError(net.praqma.jenkins.memorymap.util.MemoryMapMemorySelectionError) MemoryMapConfigMemoryItem(net.praqma.jenkins.memorymap.result.MemoryMapConfigMemoryItem) Matcher(java.util.regex.Matcher) AbstractMemoryMapParser(net.praqma.jenkins.memorymap.parser.AbstractMemoryMapParser)

Example 4 with MemoryMapConfigMemoryItem

use of net.praqma.jenkins.memorymap.result.MemoryMapConfigMemoryItem in project memory-map-plugin by Praqma.

the class TexasInstrumentsMemoryMapParser method parseConfigFile.

@Override
public MemoryMapConfigMemory parseConfigFile(File f) throws IOException {
    MemoryMapConfigMemory config = new MemoryMapConfigMemory();
    CharSequence sequence = createCharSequenceFromFile(f);
    for (MemoryMapGraphConfiguration graph : getGraphConfiguration()) {
        String[] split = graph.getGraphDataList().split(",");
        for (String s : split) {
            String[] multiSections = s.trim().split("\\+");
            for (String ms : multiSections) {
                Matcher m = MemoryMapConfigFileParserDelegate.getPatternForMemoryLayout(ms.replace(" ", "")).matcher(sequence);
                MemoryMapConfigMemoryItem item = null;
                while (m.find()) {
                    item = new MemoryMapConfigMemoryItem(m.group(1), m.group(3), m.group(5));
                    config.add(item);
                }
                if (item == null) {
                    logger.logp(Level.WARNING, "parseConfigFile", AbstractMemoryMapParser.class.getName(), String.format("parseConfigFile(List<MemoryMapGraphConfiguration> graphConfig, File f) non existing item: %s", s));
                    throw new MemoryMapMemorySelectionError(String.format("No match found for program memory named %s", s));
                }
            }
        }
    }
    return config;
}
Also used : MemoryMapGraphConfiguration(net.praqma.jenkins.memorymap.graph.MemoryMapGraphConfiguration) MemoryMapMemorySelectionError(net.praqma.jenkins.memorymap.util.MemoryMapMemorySelectionError) MemoryMapConfigMemoryItem(net.praqma.jenkins.memorymap.result.MemoryMapConfigMemoryItem) Matcher(java.util.regex.Matcher) MemoryMapConfigMemory(net.praqma.jenkins.memorymap.result.MemoryMapConfigMemory) AbstractMemoryMapParser(net.praqma.jenkins.memorymap.parser.AbstractMemoryMapParser)

Example 5 with MemoryMapConfigMemoryItem

use of net.praqma.jenkins.memorymap.result.MemoryMapConfigMemoryItem in project memory-map-plugin by Praqma.

the class TexasInstrumentsMemoryMapParserTest method testParseMapFile.

@Test
public void testParseMapFile() throws IOException {
    TexasInstrumentsMemoryMapParser parser = new TexasInstrumentsMemoryMapParser();
    String file = TexasInstrumentsMemoryMapParserTest.class.getResource("TexasInstrumentsMapFile.txt").getFile();
    File f = new File(file);
    MemoryMapConfigMemory configMemory = new MemoryMapConfigMemory();
    configMemory.add(new MemoryMapConfigMemoryItem("RAMM0", "00000050", "000003b0", "00000195", "0000021b"));
    configMemory = parser.parseMapFile(f, configMemory);
    assertTrue(configMemory.size() > 0);
    configMemory.stream().filter(item -> item.getName().equals("RAMM0")).forEach(item -> {
        assertEquals(item.getUsed(), "00000195");
        assertEquals(item.getUnused(), "0000021b");
    });
}
Also used : MemoryMapConfigMemoryItem(net.praqma.jenkins.memorymap.result.MemoryMapConfigMemoryItem) TexasInstrumentsMemoryMapParser(net.praqma.jenkins.memorymap.parser.ti.TexasInstrumentsMemoryMapParser) IOException(java.io.IOException) Test(org.junit.Test) Assert(org.junit.Assert) File(java.io.File) MemoryMapConfigMemory(net.praqma.jenkins.memorymap.result.MemoryMapConfigMemory) MemoryMapConfigMemoryItem(net.praqma.jenkins.memorymap.result.MemoryMapConfigMemoryItem) MemoryMapConfigMemory(net.praqma.jenkins.memorymap.result.MemoryMapConfigMemory) TexasInstrumentsMemoryMapParser(net.praqma.jenkins.memorymap.parser.ti.TexasInstrumentsMemoryMapParser) File(java.io.File) Test(org.junit.Test)

Aggregations

MemoryMapConfigMemoryItem (net.praqma.jenkins.memorymap.result.MemoryMapConfigMemoryItem)14 Matcher (java.util.regex.Matcher)5 MemoryMapConfigMemory (net.praqma.jenkins.memorymap.result.MemoryMapConfigMemory)4 File (java.io.File)3 HashMap (java.util.HashMap)3 Pattern (java.util.regex.Pattern)2 AbstractMemoryMapParser (net.praqma.jenkins.memorymap.parser.AbstractMemoryMapParser)2 HexifiableString (net.praqma.jenkins.memorymap.util.HexUtils.HexifiableString)2 MemoryMapMemorySelectionError (net.praqma.jenkins.memorymap.util.MemoryMapMemorySelectionError)2 Document (org.w3c.dom.Document)2 NodeList (org.w3c.dom.NodeList)2 AbortException (hudson.AbortException)1 FreeStyleBuild (hudson.model.FreeStyleBuild)1 ChartUtil (hudson.util.ChartUtil)1 IOException (java.io.IOException)1 ArrayList (java.util.ArrayList)1 Map (java.util.Map)1 MemoryMapGraphConfiguration (net.praqma.jenkins.memorymap.graph.MemoryMapGraphConfiguration)1 TexasInstrumentsMemoryMapParser (net.praqma.jenkins.memorymap.parser.ti.TexasInstrumentsMemoryMapParser)1 HexUtils (net.praqma.jenkins.memorymap.util.HexUtils)1