olofk / ipyxact

Python-based IP-XACT parser

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Ipxact Items can't have their own children

saschasalles opened this issue · comments

Hello @olofk,

I use your library in my company, and I'm new to it.
I noticed with surprise that if we add an object to another object that contains a children property then each object of that type will have the child in question.

Can an object that contains children have its own objects? Or am I using your library wrong?

Here is an example that illustrates my problem :

import ipyxact.ipyxact

f = open("/Users/saschasalles/Desktop/out.xml", "w")
component = ipyxact.ipyxact.Component()
component.name = "testname"
component.version = "1.0"
component.description = "desc"
component.vendor = "BIG COMPANY"
component.library = "library"

component.memoryMaps = ipyxact.ipyxact.MemoryMaps()
memoryMap = ipyxact.ipyxact.MemoryMap()
memoryMap.name = "RegisterMap"
memoryMap.addressUnitBits = 32
component.memoryMaps.memoryMap.append(memoryMap)

addressBlock = ipyxact.ipyxact.AddressBlock()
addressBlock.name = "FUNC"
addressBlock.width = 32
addressBlock.baseAddress = 2684485632

addressBlock2 = ipyxact.ipyxact.AddressBlock()
addressBlock2.name = "FUNC2"
addressBlock2.width = 24
addressBlock2.baseAddress = 2684485631

register1 = ipyxact.ipyxact.Register()
register1.name = "REG1"
register1.description = "desc"
register1.access = "read-write"
register1.addressOffset = 0
register1.dim = 0

addressBlock.register.append(register1)

memoryMap.addressBlock.append(addressBlock)
memoryMap.addressBlock.append(addressBlock2)
component.write(f)

generate this :

<?xml version='1.0' encoding='UTF-8'?>
<ipxact:component xmlns:ipxact="http://www.accellera.org/XMLSchema/IPXACT/1685-2014">
    <ipxact:description>desc</ipxact:description>
    <ipxact:vendor>BIG COMPANY</ipxact:vendor>
    <ipxact:library>library</ipxact:library>
    <ipxact:name>testname</ipxact:name>
    <ipxact:version>1.0</ipxact:version>
    <ipxact:memoryMaps>
        <ipxact:memoryMap>
            <ipxact:name>RegisterMap</ipxact:name>
            <ipxact:addressUnitBits>32</ipxact:addressUnitBits>
            <ipxact:addressBlock>
                <ipxact:name>FUNC</ipxact:name>
                <ipxact:baseAddress>2684485632</ipxact:baseAddress>
                <ipxact:width>32</ipxact:width>
                <ipxact:register>
                    <ipxact:name>REG1</ipxact:name>
                    <ipxact:description>desc</ipxact:description>
                    <ipxact:access>read-write</ipxact:access>
                    <ipxact:addressOffset>0</ipxact:addressOffset>
                    <ipxact:dim>0</ipxact:dim>
                </ipxact:register>
            </ipxact:addressBlock>
            <ipxact:addressBlock>
                <ipxact:name>FUNC2</ipxact:name>
                <ipxact:baseAddress>2684485631</ipxact:baseAddress>
                <ipxact:width>24</ipxact:width>
                <ipxact:register>
                    <ipxact:name>REG1</ipxact:name>
                    <ipxact:description>desc</ipxact:description>
                    <ipxact:access>read-write</ipxact:access>
                    <ipxact:addressOffset>0</ipxact:addressOffset>
                    <ipxact:dim>0</ipxact:dim>
                </ipxact:register>
            </ipxact:addressBlock>
        </ipxact:memoryMap>
    </ipxact:memoryMaps>
</ipxact:component>

In this case I don't want my addressBlock2 to contain my register1.

Thank you in advance for your help,
Best Regards,
Sascha Salles

I found the solution ... it's a little bit strange behaviour 😅

You must do:

addressBlock.register = [register1]

and not:

addressBlock.register.append(register1)

By doing this we can safely add an object without populate other objects of the same type.
Sascha