File: intrgen.py

package info (click to toggle)
llvm-py 0.6%2Bsvn105-2
  • links: PTS, VCS
  • area: main
  • in suites: wheezy
  • size: 2,060 kB
  • sloc: python: 3,844; ansic: 1,963; cpp: 508; pascal: 87; makefile: 9; sh: 1
file content (32 lines) | stat: -rwxr-xr-x 777 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
#!/usr/bin/env python
#
# Script to generate intrinsic IDs (found in core.py) from
# <llvm>/include/llvm/Intrinsics.gen. Call with path to the
# latter.

import sys

def gen(f):
    intr = []
    maxw = 0
    flag = False
    for line in open(f):
        if line.startswith('#ifdef GET_INTRINSIC_ENUM_VALUES'):
            flag = True
        elif flag:
            if line.startswith('#endif'):
                break
            else:
                item = line.split()[0].replace(',', '')
                if len(item) > maxw:
                    maxw = len(item)
                intr.append(item)

    maxw = len('INTR_') + maxw
    idx = 1
    for i in intr:
        s = 'INTR_' + i.upper()
        print '%s = %d' % (s.ljust(maxw), idx)
        idx += 1

gen(sys.argv[1])