from __future__ import absolute_import
import srcgen
from cdsl.types import ValueType
import base.types
try:
from typing import Iterable except ImportError:
pass
def emit_type(ty, fmt):
name = ty.name.upper()
fmt.doc_comment(ty.__doc__)
fmt.line(
'pub const {}: Type = Type({:#x});'
.format(name, ty.number))
fmt.line()
def emit_vectors(bits, fmt):
size = bits // 8
for ty in ValueType.all_lane_types:
mb = ty.membytes
if mb == 0 or mb >= size:
continue
emit_type(ty.by(size // mb), fmt)
def emit_types(fmt):
for spec in ValueType.all_special_types:
emit_type(spec, fmt)
for ty in ValueType.all_lane_types:
emit_type(ty, fmt)
emit_vectors(64, fmt)
emit_vectors(128, fmt)
emit_vectors(256, fmt)
emit_vectors(512, fmt)
def generate(out_dir):
fmt = srcgen.Formatter()
emit_types(fmt)
fmt.update_file('types.rs', out_dir)