1 # Copyright (c) 1999-2008 Mark D. Hill and David A. Wood
2 # Copyright (c) 2009 The Hewlett-Packard Development Company
5 # Redistribution and use in source and binary forms, with or without
6 # modification, are permitted provided that the following conditions are
7 # met: redistributions of source code must retain the above copyright
8 # notice, this list of conditions and the following disclaimer;
9 # redistributions in binary form must reproduce the above copyright
10 # notice, this list of conditions and the following disclaimer in the
11 # documentation and/or other materials provided with the distribution;
12 # neither the name of the copyright holders nor the names of its
13 # contributors may be used to endorse or promote products derived from
14 # this software without specific prior written permission.
16 # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
17 # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
18 # LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
19 # A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
20 # OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
21 # SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
22 # LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23 # DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24 # THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
26 # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28 from slicc
.ast
.ExprAST
import ExprAST
29 from slicc
.symbols
import Func
, Type
31 class FuncCallExprAST(ExprAST
):
32 def __init__(self
, slicc
, proc_name
, exprs
):
33 super(FuncCallExprAST
, self
).__init
__(slicc
)
34 self
.proc_name
= proc_name
38 return "[FuncCallExpr: %s %s]" % (self
.proc_name
, self
.exprs
)
40 def generate(self
, code
):
41 machine
= self
.state_machine
43 if self
.proc_name
== "DPRINTF":
44 # Code for inserting the location of the DPRINTF()
45 # statement in the .sm file in the statement it self.
46 # 'self.exprs[0].location' represents the location.
47 # 'format' represents the second argument of the
48 # original DPRINTF() call. It is left unmodified.
49 # str_list is used for concatenating the argument
50 # list following the format specifier. A DPRINTF()
51 # call may or may not contain any arguments following
52 # the format specifier. These two cases need to be
53 # handled differently. Hence the check whether or not
54 # the str_list is empty.
56 format
= "%s" % (self
.exprs
[1].inline())
57 format_length
= len(format
)
60 for i
in range(2, len(self
.exprs
)):
61 str_list
.append("%s" % self
.exprs
[i
].inline())
63 if len(str_list
) == 0:
64 code('DPRINTF(RubySlicc, "$0: $1")',
65 self
.exprs
[0].location
, format
[2:format_length
-2])
67 code('DPRINTF(RubySlicc, "$0: $1", $2)',
68 self
.exprs
[0].location
, format
[2:format_length
-2],
71 return self
.symtab
.find("void", Type
)
73 # hack for adding comments to profileTransition
74 if self
.proc_name
== "APPEND_TRANSITION_COMMENT":
75 # FIXME - check for number of parameters
76 code("APPEND_TRANSITION_COMMENT($0)", self
.exprs
[0].inline())
77 return self
.symtab
.find("void", Type
)
79 # Look up the function in the symbol table
80 func
= self
.symtab
.find(self
.proc_name
, Func
)
82 # Check the types and get the code for the parameters
84 self
.error("Unrecognized function name: '%s'", self
.proc_name
)
86 if len(self
.exprs
) != len(func
.param_types
):
87 self
.error("Wrong number of arguments passed to function : '%s'" +\
88 " Expected %d, got %d", self
.proc_name
,
89 len(func
.param_types
), len(self
.exprs
))
93 for expr
,expected_type
in zip(self
.exprs
, func
.param_types
):
94 # Check the types of the parameter
95 actual_type
,param_code
= expr
.inline(True)
96 if str(actual_type
) != str(expected_type
):
97 expr
.error("Type mismatch: expected: %s actual: %s" % \
98 (expected_type
, actual_type
))
99 cvec
.append(param_code
)
100 type_vec
.append(expected_type
)
102 # OK, the semantics of "trigger" here is that, ports in the
103 # machine have different priorities. We always check the first
104 # port for doable transitions. If nothing/stalled, we pick one
105 # from the next port.
107 # One thing we have to be careful as the SLICC protocol
108 # writter is : If a port have two or more transitions can be
109 # picked from in one cycle, they must be independent.
110 # Otherwise, if transition A and B mean to be executed in
111 # sequential, and A get stalled, transition B can be issued
112 # erroneously. In practice, in most case, there is only one
113 # transition should be executed in one cycle for a given
114 # port. So as most of current protocols.
116 if self
.proc_name
== "trigger":
119 Address addr = ${{cvec[1]}};
121 if machine
.TBEType
!= None and machine
.EntryType
!= None:
123 TransitionResult result = doTransition(${{cvec[0]}}, ${{cvec[2]}}, ${{cvec[3]}}, addr);
125 elif machine
.TBEType
!= None:
127 TransitionResult result = doTransition(${{cvec[0]}}, ${{cvec[2]}}, addr);
129 elif machine
.EntryType
!= None:
131 TransitionResult result = doTransition(${{cvec[0]}}, ${{cvec[2]}}, addr);
135 TransitionResult result = doTransition(${{cvec[0]}}, addr);
139 if (result == TransitionResult_Valid) {
141 continue; // Check the first port again
144 if (result == TransitionResult_ResourceStall) {
145 scheduleEvent(Cycles(1));
147 // Cannot do anything with this transition, go check next doable transition (mostly likely of next port)
151 elif self
.proc_name
== "error":
152 code("$0", self
.exprs
[0].embedError(cvec
[0]))
153 elif self
.proc_name
== "assert":
154 error
= self
.exprs
[0].embedError('"assert failure"')
157 if (!(${{cvec[0]}})) {
163 elif self
.proc_name
== "continueProcessing":
165 code("continue; // Check the first port again")
167 elif self
.proc_name
== "set_cache_entry":
168 code("set_cache_entry(m_cache_entry_ptr, %s);" %(cvec
[0]));
169 elif self
.proc_name
== "unset_cache_entry":
170 code("unset_cache_entry(m_cache_entry_ptr);");
171 elif self
.proc_name
== "set_tbe":
172 code("set_tbe(m_tbe_ptr, %s);" %(cvec
[0]));
173 elif self
.proc_name
== "unset_tbe":
174 code("unset_tbe(m_tbe_ptr);");
178 if "external" not in func
and not func
.isInternalMachineFunc
:
179 self
.error("Invalid function")
184 for (param_code
, type) in zip(cvec
, type_vec
):
186 params
= str(param_code
)
190 params
+= str(param_code
);
193 code('(${{func.c_ident}}($params))')
196 return func
.return_type