summaryrefslogtreecommitdiff
path: root/ast2json/imachine2json.py
blob: e865a73d5636a4b3832b4733954a41d311448b7f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
#!/usr/bin/env python3

import json
import sys

def imachine2json(ast):
    ret = {}
    if ast[0]['_type'] != 'Label':
        raise TypeError('obj does not start with Label, wrong file?')
    for label in ast:
        if label['parameters'] is not None:
            raise NotImplementedError()
        ret[label['name']] = label['block']
    return ret

with open(sys.argv[1], 'r') as f:
    output = imachine2json(json.load(f))

json.dump(output, open(sys.argv[2], 'w'), separators=(',', ':'))