Created
May 17, 2021 18:20
-
-
Save kant2002/2df45dff14696ab076acbfe0d1b2f7eb to your computer and use it in GitHub Desktop.
DGML to Dot file conversion for NativeAOT analysis
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python3 | |
import re | |
import sys | |
import xml.etree.ElementTree as ET | |
########################################### | |
def to_dot(fd): | |
'''TODO | |
''' | |
xml_in = "" | |
while True: | |
line = fd.readline() | |
if not line: break | |
xml_in += line + "\n" | |
xml_in = re.sub(' xmlns="[^"]+"', '', xml_in, count=1) | |
root = ET.fromstring(xml_in) | |
print("Digraph G {") | |
for node in root.findall("Nodes/Node"): | |
# print(node.attrib) | |
print('n{} [label=\"{}"];'.format(node.attrib['Id'], node.attrib['Label'])) | |
for link in root.findall("Links/Link"): | |
# print(link.attrib) | |
print('n{} -> n{} [label="{}"];'.format( | |
link.attrib['Source'], link.attrib['Target'], link.attrib['Reason'])) | |
print('}') | |
return | |
############################### | |
if __name__ == '__main__': | |
argc = len(sys.argv) | |
if argc == 1: | |
fd = sys.stdin | |
elif argc == 2: | |
fd = open(sys.argv[1], "r") | |
else: | |
print("Invalid number of arguments: either 0 or 1 required") | |
sys.exit(1) | |
to_dot(fd) | |
if argc == 2: | |
fd.close() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment