olofk / ipyxact

Python-based IP-XACT parser
MIT License
121 stars 47 forks source link

Additional fields into ipyxact/ipxact_yaml.py #7

Closed iDoka closed 7 years ago

iDoka commented 7 years ago

I have problem with adding necessary fields into YAML (in ipyxact/ipxact_yaml.py). Can't google what mean CHILD, CHILDREN and MEMBERS in apply to YAML-markup.

I need to parse default reset value, in XML that look as (register -> field -> resets -> reset -> value):

                <ipxact:register>
                    <ipxact:name>IDM</ipxact:name>
                    <ipxact:description>ID Mask</ipxact:description>
                    <ipxact:dim>0</ipxact:dim>
                    <ipxact:addressOffset>'hA0</ipxact:addressOffset>
                    <ipxact:size>32</ipxact:size>
                    <ipxact:volatile>false</ipxact:volatile>
                    <ipxact:access>read-write</ipxact:access>
                    <ipxact:field>
                        <ipxact:name>IDM</ipxact:name>
                        <ipxact:description>ID Mask</ipxact:description>
                        <ipxact:bitOffset>0</ipxact:bitOffset>
                        <ipxact:resets>
                            <ipxact:reset>
                                <ipxact:value>9'h1FF</ipxact:value>
                            </ipxact:reset>
                        </ipxact:resets>
                        <ipxact:bitWidth>9</ipxact:bitWidth>
                        <ipxact:volatile>false</ipxact:volatile>
                        <ipxact:access>read-write</ipxact:access>
                        <ipxact:modifiedWriteValue>modify</ipxact:modifiedWriteValue>
                    </ipxact:field>
                </ipxact:register>

My modification of ipyxact/ipxact_yaml.py:

field:
  MEMBERS:
    name: str
    description: str
    bitOffset: IpxactInt
    bitWidth: IpxactInt
    modifiedWriteValue: str
    testable: str
    volatile: IpxactBool
    access: str
    resets:
      MEMBERS:
        reset:
          MEMBERS:
            value: str

some error after modification:

Traceback (most recent call last):
    component.load(args.xml_path[0].name)
  File "ipyxact/ipyxact/ipyxact.py", line 96, in load
    self.parse_tree(root, self.nsmap[self.nsversion])
  File "ipyxact/ipyxact/ipyxact.py", line 128, in parse_tree
    t.parse_tree(f, ns)
  File "ipyxact/ipyxact/ipyxact.py", line 119, in parse_tree
    t.parse_tree(f, ns)
  File "ipyxact/ipyxact/ipyxact.py", line 119, in parse_tree
    t.parse_tree(f, ns)
  File "ipyxact/ipyxact/ipyxact.py", line 119, in parse_tree
    t.parse_tree(f, ns)
  File "ipyxact/ipyxact/ipyxact.py", line 119, in parse_tree
    t.parse_tree(f, ns)
  File "ipyxact/ipyxact/ipyxact.py", line 107, in parse_tree
    setattr(self, _name, eval(_type)(tmp.text))
TypeError: eval() arg 1 must be a string or code object
iDoka commented 7 years ago

I'm solve it:

reset:
  MEMBERS:
    value: str
resets:
  CHILDREN:
    - reset
field:
  MEMBERS:
    name: str
    description: str
    bitOffset: IpxactInt
    bitWidth: IpxactInt
    modifiedWriteValue: str
    testable: str
    volatile: IpxactBool
    access: str
  CHILDREN:    
    - resets
olofk commented 7 years ago

Hi Dmitry,

Thanks for reporting and fixing the issue. I took the two commits from your ipyxact fork, squashed into one and pushed to my master branch, so you should be able to use my version again now.