Skip to content

Commit

Permalink
Add data_types to builtins
Browse files Browse the repository at this point in the history
  • Loading branch information
kraigher committed Feb 12, 2018
1 parent d1bc00a commit 9379c66
Show file tree
Hide file tree
Showing 41 changed files with 2,676 additions and 306 deletions.
12 changes: 2 additions & 10 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,10 +1,2 @@

examples/vhdl/run/vunit_out/

examples/vhdl/check/vunit_out/

examples/vhdl/uart/vunit_out/

examples/vhdl/user_guide/vunit_out/

vunit/vhdl/check/vunit_out/
**/vunit_out
*.pyc
486 changes: 301 additions & 185 deletions vunit/builtins.py

Large diffs are not rendered by default.

14 changes: 14 additions & 0 deletions vunit/test/acceptance/test_external_run_scripts.py
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,20 @@ def test_vhdl_com_example_project(self):
def test_array_vhdl_2008(self):
self.check(join(VHDL_PATH, "array", "run.py"))

def test_data_types_vhdl_2008(self):
self.check(join(VHDL_PATH, "data_types", "run.py"))

def test_data_types_vhdl_2002(self):
self.check(join(VHDL_PATH, "data_types", "run.py"),
vhdl_standard="2002")

def test_data_types_vhdl_93(self):
self.check(join(VHDL_PATH, "data_types", "run.py"),
vhdl_standard="93")

def test_random_vhdl_2008(self):
self.check(join(VHDL_PATH, "random", "run.py"))

def test_check_vhdl_2008(self):
self.check(join(VHDL_PATH, "check", "run.py"))

Expand Down
58 changes: 58 additions & 0 deletions vunit/test/unit/test_builtins.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this file,
# You can obtain one at http://mozilla.org/MPL/2.0/.
#
# Copyright (c) 2015-2016, Lars Asplund [email protected]

"""
Test builtins.py
"""

import unittest
from vunit.test.mock_2or3 import mock
from vunit.builtins import BuiltinsAdder


class TestBuiltinsAdder(unittest.TestCase):
"""
Test BuiltinsAdder class
"""

@staticmethod
def test_add_type():
adder = BuiltinsAdder()
function = mock.Mock()
adder.add_type("foo", function)
adder.add("foo", dict(argument=1))
function.assert_called_once_with(argument=1)

def test_adds_dependencies(self):
adder = BuiltinsAdder()
function1 = mock.Mock()
function2 = mock.Mock()
function3 = mock.Mock()
function4 = mock.Mock()
adder.add_type("foo1", function1)
adder.add_type("foo2", function2, ["foo1"])
adder.add_type("foo3", function3, ["foo2"])
adder.add_type("foo4", function4)
adder.add("foo3", dict(argument=1))
adder.add("foo2")
function1.assert_called_once_with()
function2.assert_called_once_with()
function3.assert_called_once_with(argument=1)
self.assertFalse(function4.called)

def test_runtime_error_on_add_with_different_args(self):
adder = BuiltinsAdder()
function = mock.Mock()
adder.add_type("foo", function)
adder.add("foo", dict(argument=1))
try:
adder.add("foo", dict(argument=2))
except RuntimeError as exc:
self.assertEqual(str(exc),
"Optional builtin %r added with arguments %r has already been added with arguments %r"
% ("foo", dict(argument=2), dict(argument=1)))
else:
self.fail("RuntimeError not raised")
51 changes: 18 additions & 33 deletions vunit/ui.py
Original file line number Diff line number Diff line change
Expand Up @@ -232,12 +232,9 @@
from vunit.exceptions import CompileError
from vunit.location_preprocessor import LocationPreprocessor
from vunit.check_preprocessor import CheckPreprocessor
from vunit.builtins import (add_vhdl_builtins,
add_verilog_include_dir,
add_array_util,
add_osvvm,
add_com)
from vunit.parsing.encodings import HDL_FILE_ENCODING
from vunit.builtins import (Builtins,
add_verilog_include_dir)
from vunit.com import codec_generator

LOGGER = logging.getLogger(__name__)
Expand Down Expand Up @@ -321,8 +318,9 @@ def test_filter(name):

self._test_bench_list = TestBenchList(database=database)

self._builtins = Builtins(self, self._vhdl_standard, self._simulator_factory)
if compile_builtins:
self.add_builtins(library_name="vunit_lib")
self.add_builtins()

def _create_database(self):
"""
Expand Down Expand Up @@ -869,16 +867,13 @@ def _post_process(self, report):
xml = report.to_junit_xml_str()
ostools.write_file(self._args.xunit_xml, xml)

def add_builtins(self, library_name="vunit_lib", mock_lang=False, mock_log=False):
def add_builtins(self, mock_lang=False, mock_log=False):
"""
Add vunit VHDL builtin libraries
"""
library = self.add_library(library_name)
supports_context = self._simulator_factory.supports_vhdl_2008_contexts()
add_vhdl_builtins(library, self._vhdl_standard, mock_lang, mock_log,
supports_context=supports_context)
self._builtins.add_vhdl_builtins(mock_lang, mock_log)

def add_com(self, library_name="vunit_lib", use_debug_codecs=None):
def add_com(self, use_debug_codecs=None):
"""
Add communication package
Expand All @@ -890,38 +885,28 @@ def add_com(self, library_name="vunit_lib", use_debug_codecs=None):
`True`: Always use debug codecs
"""
if not self._project.has_library(library_name):
library = self.add_library(library_name)
else:
library = self.library(library_name)

if use_debug_codecs is not None:
self._use_debug_codecs = use_debug_codecs

supports_context = self._simulator_factory.supports_vhdl_2008_contexts()
self._builtins.add("com", dict(use_debug_codecs=self._use_debug_codecs))

add_com(library, self._vhdl_standard,
use_debug_codecs=self._use_debug_codecs,
supports_context=supports_context)
def add_array_util(self):
"""
Add array util
"""
self._builtins.add("array_util")

def add_array_util(self, library_name="vunit_lib"):
def add_random(self):
"""
Add array utility package
Add random
"""
library = self.library(library_name)
add_array_util(library, self._vhdl_standard)
self._builtins.add("random")

def add_osvvm(self, library_name="osvvm"):
def add_osvvm(self):
"""
Add osvvm library
"""
if not self._project.has_library(library_name):
library = self.add_library(library_name)
else:
library = self.library(library_name)
simulator_coverage_api = self._simulator_factory.get_osvvm_coverage_api()
supports_vhdl_package_generics = self._simulator_factory.supports_vhdl_package_generics()
add_osvvm(library, simulator_coverage_api, supports_vhdl_package_generics)
self._builtins.add("osvvm")

def get_compile_order(self, source_files=None):
"""
Expand Down
8 changes: 3 additions & 5 deletions vunit/verilog.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,17 +9,15 @@
"""

from vunit.ui import VUnit as VUnitVHDL
from vunit.builtins import add_verilog_builtins


class VUnit(VUnitVHDL):
"""
VUnit Verilog interface
"""

def add_builtins(self, library_name="vunit_lib"): # pylint: disable=arguments-differ
def add_builtins(self): # pylint: disable=arguments-differ
"""
Add vunit VHDL builtin libraries
Add vunit Verilog builtin libraries
"""
library = self.add_library(library_name)
add_verilog_builtins(library)
self._builtins.add_verilog_builtins()
7 changes: 4 additions & 3 deletions vunit/vhdl/array/run.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,14 @@
#
# Copyright (c) 2014-2015, Lars Asplund [email protected]

from os.path import join, dirname
from os.path import join, dirname, basename
from vunit import VUnit
from glob import glob

root = dirname(__file__)

ui = VUnit.from_argv()
lib = ui.add_library("lib")
ui.add_array_util("lib")
ui.add_array_util()
lib = ui.library("vunit_lib")
lib.add_source_files(join(root, "test", "*.vhd"))
ui.main()
2 changes: 1 addition & 1 deletion vunit/vhdl/check/run.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

vhdl_path = join(dirname(__file__), "test")
ui = VUnit.from_argv(compile_builtins=False)
ui.add_builtins('vunit_lib', mock_log=True)
ui.add_builtins(mock_log=True)
lib = ui.add_library('lib')
lib.add_source_files(join(vhdl_path, "test_support.vhd"))

Expand Down
11 changes: 9 additions & 2 deletions vunit/vhdl/core/src/core_pkg.vhd
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,16 @@
-- Copyright (c) 2016, Lars Asplund [email protected]

use std.textio.all;
use work.stop_pkg;

package vunit_core_pkg is
package core_pkg is
procedure setup(file_name : string);
procedure test_start(test_name : string);
procedure test_suite_done;
procedure stop(status : natural);
end package;

package body vunit_core_pkg is
package body core_pkg is
file test_results : text;

procedure setup(file_name : string) is
Expand All @@ -36,4 +38,9 @@ package body vunit_core_pkg is
file_close(test_results);
end procedure;

procedure stop(status : natural) is
begin
stop_pkg.stop(status);
end;

end package body;
7 changes: 5 additions & 2 deletions vunit/vhdl/core/src/stop_body_2008.vhd
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,12 @@
--
-- Copyright (c) 2015-2016, Lars Asplund [email protected]

package body vunit_stop_pkg is
procedure vunit_stop(status : integer) is
package body stop_pkg is
procedure stop(status : integer) is
begin
if status /= 0 then
report "Stopping simulation with status " & integer'image(status) severity failure;
end if;
std.env.stop(status);
end procedure;
end package body;
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@
--
-- Copyright (c) 2015-2016, Lars Asplund [email protected]

package body vunit_stop_pkg is
procedure vunit_stop(status : integer) is
package body stop_pkg is
procedure stop(status : integer) is
begin
assert false severity failure;
report "Stopping simulation with status " & integer'image(status) severity failure;
end procedure;
end package body;
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,6 @@
--
-- Copyright (c) 2015-2016, Lars Asplund [email protected]

package vunit_stop_pkg is
procedure vunit_stop(status : integer);
package stop_pkg is
procedure stop(status : integer);
end package;
20 changes: 20 additions & 0 deletions vunit/vhdl/data_types/run.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this file,
# You can obtain one at http://mozilla.org/MPL/2.0/.
#
# Copyright (c) 2014-2015, Lars Asplund [email protected]

from os.path import join, dirname, basename
from vunit import VUnit
from glob import glob

root = dirname(__file__)

ui = VUnit.from_argv()
lib = ui.library("vunit_lib")
for file_name in glob(join(root, "test", "*")):
if basename(file_name).endswith("2008.vhd") and ui.vhdl_standard != "2008":
continue
lib.add_source_file(file_name)

ui.main()
15 changes: 15 additions & 0 deletions vunit/vhdl/data_types/src/data_types_context.vhd
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
-- This Source Code Form is subject to the terms of the Mozilla Public
-- License, v. 2.0. If a copy of the MPL was not distributed with this file,
-- You can obtain one at http://mozilla.org/MPL/2.0/.
--
-- Copyright (c) 2017, Lars Asplund [email protected]

context data_types_context is
library vunit_lib;
use vunit_lib.integer_vector_ptr_pkg.all;
use vunit_lib.integer_vector_ptr_pool_pkg.all;
use vunit_lib.integer_array_pkg.all;
use vunit_lib.string_ptr_pkg.all;
use vunit_lib.queue_pkg.all;
use vunit_lib.queue_pool_pkg.all;
end context;
Loading

0 comments on commit 9379c66

Please sign in to comment.