Brian Osman | 5aa11fb | 2019-04-08 16:40:36 -0400 | [diff] [blame^] | 1 | # Copyright 2019 The Chromium Authors. All rights reserved. |
| 2 | # Use of this source code is governed by a BSD-style license that can be |
| 3 | # found in the LICENSE file. |
| 4 | |
| 5 | import json |
| 6 | import os |
| 7 | import subprocess |
| 8 | import sys |
| 9 | |
| 10 | if len(sys.argv) != 3: |
| 11 | print sys.argv[0], ' <compiler> <folder>' |
| 12 | sys.exit(1) |
| 13 | |
| 14 | compiler = sys.argv[1] |
| 15 | folder = sys.argv[2] |
| 16 | |
| 17 | FRAG_JSON = os.path.join(folder, 'frag.json') |
| 18 | |
| 19 | with open(FRAG_JSON) as f: |
| 20 | frags = json.load(f) |
| 21 | |
| 22 | if not frags: |
| 23 | print 'No JSON data' |
| 24 | sys.exit(1) |
| 25 | |
| 26 | for fragAndCount in frags: |
| 27 | source = os.path.join(folder, fragAndCount[0] + '.frag') |
| 28 | try: |
| 29 | output = subprocess.check_output([compiler, source]) |
| 30 | except subprocess.CalledProcessError: |
| 31 | continue |
| 32 | for line in output.splitlines(): |
| 33 | if line.startswith('Instructions Emitted'): |
| 34 | inst = line.split(':')[1].split() |
| 35 | print '{0} {1} {2} {3} {4}'.format( |
| 36 | fragAndCount[0], fragAndCount[1], inst[0], inst[1], inst[2]) |