1# Tool init file for vmips.
2
3#
4# Returns the default test case timeout in seconds.
5#
6proc vmips_default_timeout {} {
7	return 3
8}
9
10#
11# Returns "little" or "big" according to the current configured
12# target's endianness.
13#
14proc vmips_target_endian {} {
15	global endian_option
16	if ![info exists endian_option] {
17		perror "endian_option was not set"
18		return "little"
19	}
20	if {$endian_option == "bigendian"} {
21		set target_endian "big"
22	} elseif {$endian_option == "nobigendian"} {
23		set target_endian "little"
24	}
25	return $target_endian
26}
27
28#
29# Removes the extension from FILENAME and returns the result.
30#
31proc vmips_remove_extension {filename} {
32	return [string range $filename 0 [expr [string last . $filename] - 1]]
33}
34
35#
36# Given a FILENAME, returns the same filename modified to have
37# a ".rom" extension instead of its original extension; e.g.,
38# turns "foo.S" into "foo.rom".
39#
40proc vmips_get_romfile_name {filename} {
41	global subdir objdir
42	set base [vmips_basename [vmips_remove_extension $filename]]
43	return "$objdir/$subdir/${base}.rom"
44}
45
46#
47# Runs "make" to build the romfile with given FILENAME, unless a file
48# by that name already exists.
49#
50proc vmips_build_romfile {filename} {
51    global subdir objdir
52	if ![file exists $filename] {
53		# First, chdir to the subdir where configure created
54		# the testcase's makefile.
55		set curdir [pwd]
56		cd "$objdir/$subdir"
57		exec make [vmips_basename $filename]
58		cd $curdir
59	}
60	if ![file exists $filename] {
61		perror "Could not build test ROM file `$filename'"
62	}
63}
64
65#
66# vmips_basename NAME [SUFFIX]
67# Print NAME with any leading directory components removed.
68# If specified, also remove a trailing SUFFIX.
69#
70proc vmips_basename {name args} {
71    set rv [string range $name [expr [string last / $name] + 1] end]
72	if {[llength $args] == 1} {
73		set suffix [lindex $args 0]
74		if {[endswith $rv $suffix]} {
75			set rv [string range $rv 0 [expr [string length $rv] \
76			                            - [string length $suffix] - 1]]
77		}
78	}
79	return $rv
80}
81
82