def load_file(path: str) -> InsnsFile: '''Load the YAML file at path. Raises a RuntimeError on syntax or schema error. ''' try: return InsnsFile(path, load_yaml(path, None)) except ValueError as err: raise RuntimeError('Invalid schema in YAML file at {!r}: {}'.format( path, err)) from None
def load(cfg_dir: str, name: str, children: Optional[Set[str]] = None) -> 'Config': if children is not None and name in children: raise ValueError('Dependency loop for config: {} includes itself.' .format(name)) path = os.path.join(cfg_dir, name + '.yml') try: if children is None: known_names = {name} else: known_names = children | {name} return Config(cfg_dir, path, known_names, load_yaml(path, None)) except ValueError as err: raise RuntimeError('Invalid schema in YAML file at {!r}: {}' .format(path, err))
def __init__(self, path: str, encoding_schemes: Optional[EncSchemes], yml: object) -> None: yd = check_keys(yml, 'insn-group', ['key', 'title', 'doc', 'insns'], []) self.key = check_str(yd['key'], 'insn-group key') self.title = check_str(yd['title'], 'insn-group title') self.doc = check_str(yd['doc'], 'insn-group doc') insns_what = 'insns field for {!r} instruction group'.format(self.key) insns_rel_path = check_str(yd['insns'], insns_what) insns_path = os.path.normpath( os.path.join(os.path.dirname(path), insns_rel_path)) insns_yaml = load_yaml(insns_path, insns_what) try: self.insns = [ Insn(i, encoding_schemes) for i in check_list(insns_yaml, insns_what) ] except ValueError as err: raise RuntimeError( 'Invalid schema in YAML file at {!r}: {}'.format( insns_path, err)) from None
def __init__(self, path: str, yml: object) -> None: yd = check_keys(yml, 'top-level', ['insn-groups'], ['encoding-schemes']) enc_scheme_path = get_optional_str(yd, 'encoding-schemes', 'top-level') if enc_scheme_path is None: self.encoding_schemes = None else: src_dir = os.path.dirname(path) es_path = os.path.normpath(os.path.join(src_dir, enc_scheme_path)) es_yaml = load_yaml(es_path, 'encoding schemes') try: self.encoding_schemes = EncSchemes(es_yaml) except ValueError as err: raise RuntimeError( 'Invalid schema in YAML file at {!r}: {}'.format( es_path, err)) from None self.groups = InsnGroups(path, self.encoding_schemes, yd['insn-groups']) # The instructions are grouped by instruction group and stored in # self.groups. Most of the time, however, we just want "an OTBN # instruction" and don't care about the group. Retrieve them here. self.insns = [] for grp in self.groups.groups: self.insns += grp.insns self.mnemonic_to_insn = index_list('insns', self.insns, lambda insn: insn.mnemonic.lower()) masks_exc, ambiguities = self._get_masks() if ambiguities: raise ValueError('Ambiguous instruction encodings: ' + ', '.join(ambiguities)) self._masks = masks_exc