mirror of
https://github.com/RRZE-HPC/OSACA.git
synced 2025-12-16 00:50:06 +01:00
removed some unnecessary file checks and fixed up test cases
This commit is contained in:
@@ -6,6 +6,7 @@ from datetime import datetime as dt
|
||||
|
||||
from ruamel import yaml
|
||||
|
||||
from osaca import utils
|
||||
from osaca.semantics import INSTR_FLAGS, KernelDG, SemanticsAppender
|
||||
|
||||
|
||||
@@ -19,28 +20,11 @@ class Frontend(object):
|
||||
self._arch = arch
|
||||
if arch:
|
||||
self._arch = arch.lower()
|
||||
try:
|
||||
with open(self._find_file(self._arch), 'r') as f:
|
||||
self._data = yaml.load(f, Loader=yaml.Loader)
|
||||
except AssertionError:
|
||||
raise ValueError(
|
||||
'Cannot find specified architecture. Make sure the machine file exists.'
|
||||
)
|
||||
with open(utils.find_file(self._arch+'.yml'), 'r') as f:
|
||||
self._data = yaml.load(f, Loader=yaml.Loader)
|
||||
elif path_to_yaml:
|
||||
try:
|
||||
assert os.path.exists(path_to_yaml)
|
||||
with open(path_to_yaml, 'r') as f:
|
||||
self._data = yaml.load(f, Loader=yaml.Loader)
|
||||
except (AssertionError, FileNotFoundError):
|
||||
raise ValueError(
|
||||
'Cannot find specified path to YAML file. Make sure the machine file exists.'
|
||||
)
|
||||
|
||||
def _find_file(self, name):
|
||||
data_dir = os.path.expanduser('~/.osaca/data')
|
||||
name = os.path.join(data_dir, name + '.yml')
|
||||
assert os.path.exists(name)
|
||||
return name
|
||||
with open(path_to_yaml, 'r') as f:
|
||||
self._data = yaml.load(f, Loader=yaml.Loader)
|
||||
|
||||
def _is_comment(self, instruction_form):
|
||||
return instruction_form['comment'] is not None and instruction_form['instruction'] is None
|
||||
|
||||
@@ -6,6 +6,6 @@ Only the classes below will be exported, so please add new semantic tools to __a
|
||||
from .hw_model import MachineModel
|
||||
from .kernel_dg import KernelDG
|
||||
from .marker_utils import reduce_to_section
|
||||
from .semanticsAppender import SemanticsAppender, INSTR_FLAGS
|
||||
from .semantics_appender import SemanticsAppender, INSTR_FLAGS
|
||||
|
||||
__all__ = ['MachineModel', 'KernelDG', 'reduce_to_section', 'SemanticsAppender', 'INSTR_FLAGS']
|
||||
|
||||
@@ -5,6 +5,7 @@ import re
|
||||
|
||||
from ruamel import yaml
|
||||
|
||||
from osaca import utils
|
||||
from osaca.parser import ParserX86ATT
|
||||
|
||||
|
||||
@@ -18,28 +19,11 @@ class MachineModel(object):
|
||||
self._arch = arch
|
||||
if arch:
|
||||
self._arch = arch.lower()
|
||||
try:
|
||||
with open(self._find_file(self._arch), 'r') as f:
|
||||
self._data = yaml.load(f, Loader=yaml.Loader)
|
||||
except AssertionError:
|
||||
raise ValueError(
|
||||
'Cannot find specified architecture. Make sure the machine file exists.'
|
||||
)
|
||||
with open(utils.find_file(self._arch+'.yml'), 'r') as f:
|
||||
self._data = yaml.load(f, Loader=yaml.Loader)
|
||||
elif path_to_yaml:
|
||||
try:
|
||||
assert os.path.exists(self._path)
|
||||
with open(self._path, 'r') as f:
|
||||
self._data = yaml.load(f, Loader=yaml.Loader)
|
||||
except (AssertionError, FileNotFoundError):
|
||||
raise ValueError(
|
||||
'Cannot find specified path to YAML file. Make sure the machine file exists.'
|
||||
)
|
||||
|
||||
def _find_file(self, name):
|
||||
data_dir = os.path.expanduser('~/.osaca/data')
|
||||
name = os.path.join(data_dir, name + '.yml')
|
||||
assert os.path.exists(name)
|
||||
return name
|
||||
with open(self._path, 'r') as f:
|
||||
self._data = yaml.load(f, Loader=yaml.Loader)
|
||||
|
||||
def __getitem__(self, key):
|
||||
"""Return configuration entry."""
|
||||
|
||||
@@ -4,6 +4,7 @@ import os
|
||||
import warnings
|
||||
from functools import reduce
|
||||
|
||||
from osaca import utils
|
||||
from osaca.parser import AttrDict, ParserAArch64v81, ParserX86ATT
|
||||
from osaca.semantics import MachineModel
|
||||
|
||||
@@ -26,19 +27,13 @@ class SemanticsAppender(object):
|
||||
def __init__(self, machine_model: MachineModel, path_to_yaml=None):
|
||||
self._machine_model = machine_model
|
||||
self._isa = machine_model.get_ISA().lower()
|
||||
path = self._find_file(self._isa)
|
||||
path = utils.find_file('isa/'+self._isa+'.yml')
|
||||
self._isa_model = MachineModel(path_to_yaml=path)
|
||||
if self._isa == 'x86':
|
||||
self._parser = ParserX86ATT()
|
||||
elif self._isa == 'aarch64':
|
||||
self._parser = ParserAArch64v81()
|
||||
|
||||
def _find_file(self, isa):
|
||||
data_dir = os.path.expanduser('~/.osaca/data/isa')
|
||||
name = os.path.join(data_dir, isa + '.yml')
|
||||
assert os.path.exists(name)
|
||||
return name
|
||||
|
||||
# SUMMARY FUNCTION
|
||||
def add_semantics(self, kernel):
|
||||
for instruction_form in kernel:
|
||||
|
||||
@@ -0,0 +1,13 @@
|
||||
#!/usr/bin/env python3
|
||||
import os.path
|
||||
|
||||
|
||||
def find_file(name):
|
||||
"""Check for existence of name in user or package data folders and return path."""
|
||||
search_paths = [os.path.expanduser('~/.osaca/data'),
|
||||
os.path.join(os.path.dirname(__file__), 'data')]
|
||||
for dir in search_paths:
|
||||
path = os.path.join(dir, name)
|
||||
if os.path.exists(path):
|
||||
return path
|
||||
raise FileNotFoundError("Could not find {!r} in {!r}.".format(name, search_paths))
|
||||
@@ -10,7 +10,7 @@ from osaca.frontend import Frontend
|
||||
from osaca.parser import ParserAArch64v81, ParserX86ATT
|
||||
from osaca.semantics.hw_model import MachineModel
|
||||
from osaca.semantics.kernel_dg import KernelDG
|
||||
from osaca.semantics.semanticsAppender import SemanticsAppender
|
||||
from osaca.semantics.semantics_appender import SemanticsAppender
|
||||
|
||||
|
||||
class TestFrontend(unittest.TestCase):
|
||||
@@ -60,9 +60,9 @@ class TestFrontend(unittest.TestCase):
|
||||
Frontend()
|
||||
with self.assertRaises(ValueError):
|
||||
Frontend(arch='csx', path_to_yaml=os.path.join(self.MODULE_DATA_DIR, 'csx.yml'))
|
||||
with self.assertRaises(ValueError):
|
||||
with self.assertRaises(FileNotFoundError):
|
||||
Frontend(path_to_yaml=os.path.join(self.MODULE_DATA_DIR, 'THE_MACHINE.yml'))
|
||||
with self.assertRaises(ValueError):
|
||||
with self.assertRaises(FileNotFoundError):
|
||||
Frontend(arch='THE_MACHINE')
|
||||
Frontend(arch='zen1')
|
||||
|
||||
|
||||
@@ -304,9 +304,9 @@ class TestSemanticTools(unittest.TestCase):
|
||||
MachineModel()
|
||||
with self.assertRaises(ValueError):
|
||||
MachineModel(arch='CSX', path_to_yaml=os.path.join(self.MODULE_DATA_DIR, 'csx.yml'))
|
||||
with self.assertRaises(ValueError):
|
||||
with self.assertRaises(FileNotFoundError):
|
||||
MachineModel(arch='THE_MACHINE')
|
||||
with self.assertRaises(ValueError):
|
||||
with self.assertRaises(FileNotFoundError):
|
||||
MachineModel(path_to_yaml=os.path.join(self.MODULE_DATA_DIR, 'THE_MACHINE.yml'))
|
||||
|
||||
def test_MachineModel_getter(self):
|
||||
|
||||
Reference in New Issue
Block a user