• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1#!/usr/bin/env python
2# coding:utf-8
3# Copyright (c) 2020 HiSilicon (Shanghai) Technologies CO., LIMITED.
4# Licensed under the Apache License, Version 2.0 (the "License");
5# you may not use this file except in compliance with the License.
6# You may obtain a copy of the License at
7#
8#     http://www.apache.org/licenses/LICENSE-2.0
9#
10# Unless required by applicable law or agreed to in writing, software
11# distributed under the License is distributed on an "AS IS" BASIS,
12# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13# See the License for the specific language governing permissions and
14# limitations under the License.
15
16import sys,string,re,os
17from ctypes import *
18import json
19from xml.etree import ElementTree  as  ET
20
21
22def _xml_parse_tree(file):
23    tree = ET.parse(file)
24    root = tree.getroot()
25    return (tree,root)
26
27
28def _xml_find_son_by_tag(parent,tag_name):
29    match_list=[]
30    for child in parent:
31        if(child.tag==tag_name):
32            match_list.append(child)
33    return match_list
34
35
36def _xml_find_child_by_tag(match_list,parent,tag_name):
37    for child in parent:
38        if(child.tag==tag_name):
39            match_list.append(child)
40        _xml_find_child_by_tag(match_list,child,tag_name)
41
42def _parse_create_struct_file(struct_list,debug_info_file,out_file):
43    #print(struct_list)
44    #print(out_file)
45    with open(out_file,'w+') as fp:
46        print(struct_list,file=fp)
47
48def parse_tools_xml(xml_file,debug_info_file,out_idr):
49    (tree,root)=_xml_parse_tree(xml_file)
50    list=_xml_find_son_by_tag(root,'GROUP')
51    item_list=[]
52    for item in list:
53        if 'AUTO_STRUCT' in item.attrib and item.attrib['AUTO_STRUCT']=="YES":
54            item_list.append(item)
55    result_list = []
56    for item in item_list:
57        req_list=[]
58        ind_list=[]
59        struct_list=[]
60        _xml_find_child_by_tag(req_list,item,'REQ')
61        _xml_find_child_by_tag(ind_list,item,'IND')
62        for req in req_list:
63            struct_list.append(req.attrib['STRUCTURE'])
64        for ind in ind_list:
65            struct_list.append(ind.attrib['STRUCTURE'])
66        #_parse_create_struct_file(struct_list,debug_info_file,os.path.join(out_idr,item.attrib['DATA_STRUCT_FILE']))
67        result_list.extend(struct_list)
68    return result_list
69