#!/usr/bin/env python3
# Calculate type sizes.
#
# (c) Mit authors 2019-2020
#
# The package is distributed under the MIT/X11 License.
#
# THIS PROGRAM IS PROVIDED AS IS, WITH NO WARRANTY. USE IS AT THE USER’S
# RISK.

import sys
import re
from pprint import pformat

import stack
stack.TYPE_SIZE_UNKNOWN = 0

from traps import *


# Read list of types
types = []
for line in open('type-sizes.ac').readlines():
    m = re.match(r"^AC_CHECK_SIZEOF\(\[(.*)\]\)", line)
    if m:
        types.append(m.group(1))

# Read sizes from stdin
sizes = [int(line.rstrip()) for line in sys.stdin]

# Make output dict
assert len(types) == len(sizes)
type_size = {}
for (type, size) in zip(types, sizes):
    if size == 0:
        raise ValueError(f"Invalid type `{type}'")
    type_size[type] = size

# Print output
print('type_sizes = ' + pformat(type_size))
