diff options
Diffstat (limited to 'src/mem/slicc')
114 files changed, 15443 insertions, 0 deletions
diff --git a/src/mem/slicc/README b/src/mem/slicc/README new file mode 100644 index 000000000..fb7f52dac --- /dev/null +++ b/src/mem/slicc/README @@ -0,0 +1,114 @@ +Overview +======== +This is SLICC, a domain specific language to specify cache coherence protocol +we have developed in Multifacet group. + +It is developed by Milo Martin <milo@cs.wisc.edu> +This document is prepared by Min Xu <mxu@cae.wisc.edu> while I am learning the +system. With minor correctness updates by Brad Beckmann <beckmann@cs.wisc.edu> + +It can be used to generate C++ code that works with RUBY cache simulator as +well as generate HTML and other document to describe the target protocol. + +Some user document is available in doc directory. + +Tech details +============ +SLICC take a text input with similar syntax to C++ language and use the lexer +and parser in parser directory to construct a Abstract Syntax Tree (AST) +internally. After having done this first pass, the AST is traversed to fill +several interval table, such as symbol table, type table, etc. Finally the code +is generated by traversing the tree once again. + +Note, by Milo's good coding habit, almost all C++ class define their private +copy/assignment constructor. This prevents accidentally copying/assigning an +object by its address. + +The AST basically looks like a hierarchical representation of the text input. +At the highest level, it has the "Machine", each Machine has several "states" +and "events" and "actions" and "transistions". + +Since the language is domain specific, many assumptions of the target system is +hardcoded in SLICC. For example, ruby would expect the generated code for each +system node, has the following components: + processor(sequencer, not generated?) + cache + directory (with memory block value, only when compiled with tester) + network interface (NI) + +Directory generator/ contains routines to generate HTML/MIF format output. +fileio.[Ch] has a routine to conditionally write a file only when the original +content of the file is different from what is going to be written, this avoid +re-make those file after regenerate the protocol. html_gen.[Ch] contains the +symbol name munge and index page generation. mif_gen.[Ch] contains the entire +MIF output generation routine, mainly a table buildup. + +Directory symbol/ contains classes to represent symbols in the slicc input +file. Base class is "Symbol". Derived subclasses are "Action Event Func State +StateMachine Transition Type Var". "Symbol" has knowledge about its locations +in the source file and short name, long name. "SymbolTable" is a list of +symbols and g_sym_table is the global SymbolTable of the slicc system. +One can query a SymbolTable by symbol's id. Also SymbolTable is responsible for +keeping track of Symbol's declaration in correct scope. The current +implementation uses a stack which dynamically determine the scope of symbol +lookups. Global scope is at bottom of the stack (vector[0]). SymbolTable is +also the main place to write out the generated C++/HTML/MIF files. +SymbolTable::writeNodeFiles() is one of the place to look for hardcoded C++ +code for node.[Ch]. And Type.[Ch] is the place where generating enumeration and +Message/NetworkMessage declaration and implementation. Func.[Ch] is used to +generate function of the class Chip. StateMachine.[Ch] wrap the whole thing +up by putting States, Actions, Events together. It actually has a two dimension +table like the one represented in the HTML output. Actions are indexed with +the initial state and observed event. After the tabel being built, the +StateMachine class can write out Transitions/Controller/wakeup_logic into C++ +outputs. Finally, in symbol directory, Var.[Ch] seem to incomplete? + +Demystify all those "predefined" external types, like "Address". Where are +they defined? They are in ../protocol/RubySlicc-*.sm and +../protocol/RubySlicc_interfaces.slicc is include in the slicc invocation +command in ../ruby/Makefile. + +Another myth: "trigger" method is hardcoded in ast/InPortDeclAST.C and +ast/FuncCallExprAST.C. The function is similar to inlined function in the +output generated code, so you cannot find any occurance of string "trigger" in +the generated code. "trigger" also increment a counter that is checked every +time a transition is done. In one ruby cycle, only TRANSITIONS_PER_RUBY_CYCLE +number of transitions can be done. ast/FuncCallExprAST.C also contains some +code for function "error" and "assert" and "DEBUG_EXPR", all in the same +manner. Ruby always issues transitions from the first port while there is any. +Stalled transition in Ruby does not consume a sub-cycle. This models the +hardware that probe all port in parallel, pick one transition from the highest +priority queue if the transistion was not stalled by any resources constraint. + +Another note: scheduleEvent() call of ruby make sure a consumer is woken up at +specified cycle, and only once per cycle. + +Action z_stall, where is it? It is hardcoded in symbols/StateMachine.C. In +function StateMachine::printCSwitch(), z_stall cause the generated code return +TransitionResult_ProtocolStall. Also the HTML output for z_stall has to be +consequently hardcoded. I am not sure that's really a good idea or not. :-) + +Question: How comes there is no "for" loop statement in slicc? +Answer: Been there, done that. That is easy to add, first of all. But unbound +loop make slicc eventually un-synthesizable. We want to avoid that. If you want +to loop through a bounded array do something, make the action done in a +external interface in RubySlicc_Util.h. Inside, you just pass the vector as +parameter to the external interface to achieve the same effects. + +Another bad thing of using loop statement like for is that we can not determine +how many buffer space to allocate before the transition. With a vector, if it +easy to understand we can always allocate the worst case number of hardware +resources. + +Question: Wait! It seems statement check_allocate does nothing! +Answer: No, it does call areNSoltsAvailable() function of the object before any +statement is executed in one action. It does *NOT* generate code in its +original place in the code, instead, it scan the body of the action code and +determine how many slots are needed to allocated before hand. So the +transaction is all done or nothing done. I had tried to make all actions return +boolean values and the false return cause a transition to abort with +ResourceStall. But it is later on deemed to be too flexible in its semantics. +We should never introduce control flow inside the transitions, so that each +transition is either "all" or "nothing". Just that simple. BTW, if you call +check_allocate twice, areNSoltsAvailable(2) is generated, three times generates +areNSoltsAvailable(3), etc. diff --git a/src/mem/slicc/ast/AST.cc b/src/mem/slicc/ast/AST.cc new file mode 100644 index 000000000..9342cd2e8 --- /dev/null +++ b/src/mem/slicc/ast/AST.cc @@ -0,0 +1,39 @@ + +/* + * Copyright (c) 1999-2008 Mark D. Hill and David A. Wood + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer; + * redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution; + * neither the name of the copyright holders nor the names of its + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +/* + * AST.C + * + * Description: See AST.h + * + * $Id$ + * + */ + +#include "AST.hh" diff --git a/src/mem/slicc/ast/AST.hh b/src/mem/slicc/ast/AST.hh new file mode 100644 index 000000000..b20bbebe2 --- /dev/null +++ b/src/mem/slicc/ast/AST.hh @@ -0,0 +1,94 @@ + +/* + * Copyright (c) 1999-2008 Mark D. Hill and David A. Wood + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer; + * redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution; + * neither the name of the copyright holders nor the names of its + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +/* + * AST.h + * + * Description: + * + * $Id$ + * + */ + +#ifndef AST_H +#define AST_H + +#include "slicc_global.hh" +#include "Vector.hh" +#include "Map.hh" +#include "Location.hh" +#include "SymbolTable.hh" + +class AST { +public: + // Constructors + AST(Map<string, string> pairs) { m_pairs = pairs; }; + AST() {}; + + // Destructor + virtual ~AST() {}; + + // Public Methods + virtual void print(ostream& out) const = 0; + void error(string err_msg) const { m_location.error(err_msg); }; + string embedError(string err_msg) const { return m_location.embedError(err_msg); }; + void warning(string err_msg) const { m_location.warning(err_msg); }; + + const Location& getLocation() const { return m_location; }; + + const Map<string, string>& getPairs() const { return m_pairs; }; + Map<string, string>& getPairs() { return m_pairs; }; + +private: + // Private Methods + + // Private copy constructor and assignment operator + // AST(const AST& obj); + // AST& operator=(const AST& obj); + + // Data Members (m_ prefix) + Location m_location; + Map<string, string> m_pairs; +}; + +// Output operator declaration +ostream& operator<<(ostream& out, const AST& obj); + +// ******************* Definitions ******************* + +// Output operator definition +extern inline +ostream& operator<<(ostream& out, const AST& obj) +{ + obj.print(out); + out << flush; + return out; +} + +#endif //AST_H diff --git a/src/mem/slicc/ast/ASTs.hh b/src/mem/slicc/ast/ASTs.hh new file mode 100644 index 000000000..77b055a80 --- /dev/null +++ b/src/mem/slicc/ast/ASTs.hh @@ -0,0 +1,90 @@ + +/* + * Copyright (c) 1999-2008 Mark D. Hill and David A. Wood + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer; + * redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution; + * neither the name of the copyright holders nor the names of its + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +/* + * $Id$ + * + */ + +#ifndef ASTs_H +#define ASTs_H + +#include "slicc_global.hh" +#include "main.hh" +#include "StateMachine.hh" +#include "AST.hh" + +#include "MachineAST.hh" + +#include "TypeAST.hh" +#include "FormalParamAST.hh" + +#include "DeclListAST.hh" +#include "DeclAST.hh" +#include "ActionDeclAST.hh" +#include "InPortDeclAST.hh" +#include "OutPortDeclAST.hh" +#include "TransitionDeclAST.hh" +#include "EnumDeclAST.hh" +#include "TypeDeclAST.hh" +#include "ObjDeclAST.hh" +#include "FuncDeclAST.hh" + +#include "TypeFieldAST.hh" +#include "TypeFieldMethodAST.hh" +#include "TypeFieldMemberAST.hh" +#include "TypeFieldEnumAST.hh" + +#include "PairAST.hh" +#include "PairListAST.hh" + +#include "ExprAST.hh" +#include "VarExprAST.hh" +#include "EnumExprAST.hh" +#include "LiteralExprAST.hh" +#include "MemberExprAST.hh" +#include "InfixOperatorExprAST.hh" +#include "FuncCallExprAST.hh" +#include "MethodCallExprAST.hh" + +#include "ChipComponentAccessAST.hh" + +#include "StatementListAST.hh" +#include "StatementAST.hh" +#include "ExprStatementAST.hh" +#include "AssignStatementAST.hh" +#include "EnqueueStatementAST.hh" +#include "IfStatementAST.hh" +#include "PeekStatementAST.hh" +#include "CopyHeadStatementAST.hh" +#include "CheckAllocateStatementAST.hh" +#include "CheckStopSlotsStatementAST.hh" +#include "ReturnStatementAST.hh" + +#endif //ASTs_H diff --git a/src/mem/slicc/ast/ActionDeclAST.cc b/src/mem/slicc/ast/ActionDeclAST.cc new file mode 100644 index 000000000..6514b9afd --- /dev/null +++ b/src/mem/slicc/ast/ActionDeclAST.cc @@ -0,0 +1,96 @@ + +/* + * Copyright (c) 1999-2008 Mark D. Hill and David A. Wood + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer; + * redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution; + * neither the name of the copyright holders nor the names of its + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +/* + * ActionDeclAST.C + * + * Description: See ActionDeclAST.h + * + * $Id$ + * + */ + +#include "ActionDeclAST.hh" +#include "Action.hh" + +ActionDeclAST::ActionDeclAST(string* ident_ptr, + PairListAST* pairs_ptr, + StatementListAST* statement_list_ptr) + : DeclAST(pairs_ptr) +{ + m_ident_ptr = ident_ptr; + m_statement_list_ptr = statement_list_ptr; +} + +ActionDeclAST::~ActionDeclAST() +{ + delete m_ident_ptr; + delete m_statement_list_ptr; +} + +void ActionDeclAST::generate() +{ + Map<Var*, string> resource_list; + if (m_statement_list_ptr != NULL) { + string code; + + // Add new local vars + g_sym_table.pushFrame(); + + Type* type_ptr = g_sym_table.getType("Address"); + + if (type_ptr == NULL) { + error("Type 'Address' not declared."); + } + + g_sym_table.newSym(new Var("address", getLocation(), type_ptr, "addr", getPairs())); + + // Don't allows returns in actions + m_statement_list_ptr->generate(code, NULL); + + getPairs().add("c_code", code); + + m_statement_list_ptr->findResources(resource_list); + + g_sym_table.popFrame(); + } + + StateMachine* machine_ptr = g_sym_table.getStateMachine(); + if (machine_ptr == NULL) { + error("Action declaration not part of a machine."); + } else { + machine_ptr->addAction(new Action(*m_ident_ptr, resource_list, getLocation(), getPairs())); + } + +} + +void ActionDeclAST::print(ostream& out) const +{ + out << "[ActionDecl: " << *m_ident_ptr << "]"; +} diff --git a/src/mem/slicc/ast/ActionDeclAST.hh b/src/mem/slicc/ast/ActionDeclAST.hh new file mode 100644 index 000000000..cc020a95f --- /dev/null +++ b/src/mem/slicc/ast/ActionDeclAST.hh @@ -0,0 +1,85 @@ + +/* + * Copyright (c) 1999-2008 Mark D. Hill and David A. Wood + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer; + * redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution; + * neither the name of the copyright holders nor the names of its + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +/* + * ActionDeclAST.h + * + * Description: + * + * $Id: ActionDeclAST.h,v 3.2 2003/07/10 18:08:06 milo Exp $ + * + */ + +#ifndef ActionDeclAST_H +#define ActionDeclAST_H + +#include "slicc_global.hh" +#include "DeclAST.hh" +#include "StatementListAST.hh" + +class ActionDeclAST : public DeclAST { +public: + // Constructors + ActionDeclAST(string* ident_ptr, + PairListAST* pairs_ptr, + StatementListAST* statement_list_ptr); + + // Destructor + ~ActionDeclAST(); + + // Public Methods + void generate(); + void print(ostream& out) const; +private: + // Private Methods + + // Private copy constructor and assignment operator + ActionDeclAST(const ActionDeclAST& obj); + ActionDeclAST& operator=(const ActionDeclAST& obj); + + // Data Members (m_ prefix) + string* m_ident_ptr; + StatementListAST* m_statement_list_ptr; +}; + +// Output operator declaration +ostream& operator<<(ostream& out, const ActionDeclAST& obj); + +// ******************* Definitions ******************* + +// Output operator definition +extern inline +ostream& operator<<(ostream& out, const ActionDeclAST& obj) +{ + obj.print(out); + out << flush; + return out; +} + +#endif //ActionDeclAST_H diff --git a/src/mem/slicc/ast/AssignStatementAST.cc b/src/mem/slicc/ast/AssignStatementAST.cc new file mode 100644 index 000000000..2d72e583e --- /dev/null +++ b/src/mem/slicc/ast/AssignStatementAST.cc @@ -0,0 +1,76 @@ + +/* + * Copyright (c) 1999-2008 Mark D. Hill and David A. Wood + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer; + * redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution; + * neither the name of the copyright holders nor the names of its + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +/* + * AssignStatementAST.C + * + * Description: See AssignStatementAST.h + * + * $Id: AssignStatementAST.C,v 3.2 2003/08/01 18:38:19 beckmann Exp $ + * + */ + +#include "AssignStatementAST.hh" + +AssignStatementAST::AssignStatementAST(ExprAST* lvalue_ptr, ExprAST* rvalue_ptr) + : StatementAST() +{ + m_lvalue_ptr = lvalue_ptr; + m_rvalue_ptr = rvalue_ptr; +} + +AssignStatementAST::~AssignStatementAST() +{ + delete m_lvalue_ptr; + delete m_rvalue_ptr; +} + +void AssignStatementAST::generate(string& code, Type* return_type_ptr) const +{ + code += indent_str(); + Type* lvalue_type_ptr = m_lvalue_ptr->generate(code); + code += " = "; + Type* rvalue_type_ptr = m_rvalue_ptr->generate(code); + code += ";\n"; + + if (lvalue_type_ptr != rvalue_type_ptr) { + // FIXME - beckmann + // the following if statement is a hack to allow NetDest objects to be assigned to Sets + // this allows for the previous NetworkMessage Destiantion 'Set class' to migrate to the + // new NetworkMessage Destiantion 'NetDest class' + if (lvalue_type_ptr->toString() != "NetDest" && rvalue_type_ptr->toString() != "Set") { + error("Assignment type mismatch '" + lvalue_type_ptr->toString() + "' and '" + rvalue_type_ptr->toString() + "'"); + } + } +} + +void AssignStatementAST::print(ostream& out) const +{ + out << "[AssignStatementAST: " << *m_lvalue_ptr << " := " << *m_rvalue_ptr << "]"; +} diff --git a/src/mem/slicc/ast/AssignStatementAST.hh b/src/mem/slicc/ast/AssignStatementAST.hh new file mode 100644 index 000000000..c249c8a75 --- /dev/null +++ b/src/mem/slicc/ast/AssignStatementAST.hh @@ -0,0 +1,85 @@ + +/* + * Copyright (c) 1999-2008 Mark D. Hill and David A. Wood + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer; + * redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution; + * neither the name of the copyright holders nor the names of its + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +/* + * AssignStatementAST.h + * + * Description: + * + * $Id: AssignStatementAST.h,v 3.2 2001/12/12 01:00:09 milo Exp $ + * + */ + +#ifndef ASSIGNSTATEMENTAST_H +#define ASSIGNSTATEMENTAST_H + +#include "slicc_global.hh" +#include "StatementAST.hh" +#include "ExprAST.hh" + + + +class AssignStatementAST : public StatementAST { +public: + // Constructors + AssignStatementAST(ExprAST* lvalue_ptr, ExprAST* rvalue_ptr); + + // Destructor + ~AssignStatementAST(); + + // Public Methods + void generate(string& code, Type* return_type_ptr) const; + void print(ostream& out) const; +private: + // Private Methods + + // Private copy constructor and assignment operator + AssignStatementAST(const AssignStatementAST& obj); + AssignStatementAST& operator=(const AssignStatementAST& obj); + + // Data Members (m_ prefix) + ExprAST* m_lvalue_ptr; + ExprAST* m_rvalue_ptr; +}; + +// Output operator declaration +ostream& operator<<(ostream& out, const AssignStatementAST& obj); + +// ******************* Definitions ******************* + +// Output operator definition +extern inline +ostream& operator<<(ostream& out, const AssignStatementAST& obj) +{ + obj.print(out); + out << flush; + return out; +} + +#endif //ASSIGNSTATEMENTAST_H diff --git a/src/mem/slicc/ast/CheckAllocateStatementAST.cc b/src/mem/slicc/ast/CheckAllocateStatementAST.cc new file mode 100644 index 000000000..25fd4d2e7 --- /dev/null +++ b/src/mem/slicc/ast/CheckAllocateStatementAST.cc @@ -0,0 +1,72 @@ + +/* + * Copyright (c) 1999-2008 Mark D. Hill and David A. Wood + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer; + * redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution; + * neither the name of the copyright holders nor the names of its + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +/* + * $Id$ + * + */ + +#include "CheckAllocateStatementAST.hh" +#include "SymbolTable.hh" +#include "VarExprAST.hh" +#include "util.hh" + +CheckAllocateStatementAST::CheckAllocateStatementAST(VarExprAST* variable) + : StatementAST() +{ + m_variable = variable; +} + +CheckAllocateStatementAST::~CheckAllocateStatementAST() +{ + delete m_variable; +} + +void CheckAllocateStatementAST::generate(string& code, Type* return_type_ptr) const +{ + // FIXME - check the type of the variable + + // Make sure the variable is valid + m_variable->getVar(); +} + +void CheckAllocateStatementAST::findResources(Map<Var*, string>& resource_list) const +{ + Var* var_ptr = m_variable->getVar(); + int res_count = 0; + if (resource_list.exist(var_ptr)) { + res_count = atoi((resource_list.lookup(var_ptr)).c_str()); + } + resource_list.add(var_ptr, int_to_string(res_count+1)); +} + +void CheckAllocateStatementAST::print(ostream& out) const +{ + out << "[CheckAllocateStatementAst: " << *m_variable << "]"; +} diff --git a/src/mem/slicc/ast/CheckAllocateStatementAST.hh b/src/mem/slicc/ast/CheckAllocateStatementAST.hh new file mode 100644 index 000000000..8df08a086 --- /dev/null +++ b/src/mem/slicc/ast/CheckAllocateStatementAST.hh @@ -0,0 +1,82 @@ + +/* + * Copyright (c) 1999-2008 Mark D. Hill and David A. Wood + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer; + * redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution; + * neither the name of the copyright holders nor the names of its + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +/* + * $Id$ + * + */ + +#ifndef CHECKALLOCATESTATEMENTAST_H +#define CHECKALLOCATESTATEMENTAST_H + +#include "slicc_global.hh" +#include "StatementAST.hh" +#include "TypeAST.hh" + +class VarExprAST; +class Var; + +class CheckAllocateStatementAST : public StatementAST { +public: + // Constructors + CheckAllocateStatementAST(VarExprAST* variable); + + // Destructor + ~CheckAllocateStatementAST(); + + // Public Methods + void generate(string& code, Type* return_type_ptr) const; + void findResources(Map<Var*, string>& resource_list) const; + void print(ostream& out) const; +private: + // Private Methods + + // Private copy constructor and assignment operator + CheckAllocateStatementAST(const CheckAllocateStatementAST& obj); + CheckAllocateStatementAST& operator=(const CheckAllocateStatementAST& obj); + + // Data Members (m_ prefix) + VarExprAST* m_variable; +}; + +// Output operator declaration +ostream& operator<<(ostream& out, const CheckAllocateStatementAST& obj); + +// ******************* Definitions ******************* + +// Output operator definition +extern inline +ostream& operator<<(ostream& out, const CheckAllocateStatementAST& obj) +{ + obj.print(out); + out << flush; + return out; +} + +#endif //CHECKALLOCATESTATEMENTAST_H diff --git a/src/mem/slicc/ast/CheckStopSlotsStatementAST.cc b/src/mem/slicc/ast/CheckStopSlotsStatementAST.cc new file mode 100644 index 000000000..f102e8894 --- /dev/null +++ b/src/mem/slicc/ast/CheckStopSlotsStatementAST.cc @@ -0,0 +1,115 @@ + +/* + * Copyright (c) 1999-2008 Mark D. Hill and David A. Wood + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer; + * redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution; + * neither the name of the copyright holders nor the names of its + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +/* + * $Id$ + * + */ + +#include "CheckStopSlotsStatementAST.hh" +#include "SymbolTable.hh" +#include "VarExprAST.hh" +#include "PairListAST.hh" + +CheckStopSlotsStatementAST::CheckStopSlotsStatementAST(VarExprAST* variable, string* condStr, string* bankStr) + : StatementAST() +{ + m_variable = variable; + m_condStr_ptr = condStr; + m_bankStr_ptr = bankStr; +} + +CheckStopSlotsStatementAST::~CheckStopSlotsStatementAST() +{ + delete m_variable; + delete m_condStr_ptr; + delete m_bankStr_ptr; +} + +void CheckStopSlotsStatementAST::generate(string& code, Type* return_type_ptr) const +{ + + // Make sure the variable is valid + m_variable->getVar(); + +} + +void CheckStopSlotsStatementAST::findResources(Map<Var*, string>& resource_list) const +{ + Type* type_ptr; + + Var* var_ptr = m_variable->getVar(); + string check_code; + + if (*m_condStr_ptr == "((*in_msg_ptr)).m_isOnChipSearch") { + check_code += " const Response9Msg* in_msg_ptr;\n"; + check_code += " in_msg_ptr = dynamic_cast<const Response9Msg*>(((*(m_chip_ptr->m_L2Cache_responseToL2Cache9_vec[m_version]))).peek());\n"; + check_code += " assert(in_msg_ptr != NULL);\n"; + } + + check_code += " if ("; + check_code += *m_condStr_ptr; + check_code += ") {\n"; + + check_code += " if (!"; + type_ptr = m_variable->generate(check_code); + check_code += ".isDisableSPossible((((*(m_chip_ptr->m_DNUCAmover_ptr))).getBankPos("; + check_code += *m_bankStr_ptr; + check_code += ")))) {\n"; + if(CHECK_INVALID_RESOURCE_STALLS) { + check_code += " assert(priority >= "; + type_ptr = m_variable->generate(check_code); + check_code += ".getPriority());\n"; + } + check_code += " return TransitionResult_ResourceStall;\n"; + check_code += " }\n"; + check_code += " } else {\n"; + check_code += " if (!"; + type_ptr = m_variable->generate(check_code); + check_code += ".isDisableFPossible((((*(m_chip_ptr->m_DNUCAmover_ptr))).getBankPos("; + check_code += *m_bankStr_ptr; + check_code += ")))) {\n"; + if(CHECK_INVALID_RESOURCE_STALLS) { + check_code += " assert(priority >= "; + type_ptr = m_variable->generate(check_code); + check_code += ".getPriority());\n"; + } + check_code += " return TransitionResult_ResourceStall;\n"; + check_code += " }\n"; + check_code += " }\n"; + + assert(!resource_list.exist(var_ptr)); + resource_list.add(var_ptr, check_code); + +} + +void CheckStopSlotsStatementAST::print(ostream& out) const +{ + out << "[CheckStopSlotsStatementAst: " << *m_variable << "]"; +} diff --git a/src/mem/slicc/ast/CheckStopSlotsStatementAST.hh b/src/mem/slicc/ast/CheckStopSlotsStatementAST.hh new file mode 100644 index 000000000..131b8cf4d --- /dev/null +++ b/src/mem/slicc/ast/CheckStopSlotsStatementAST.hh @@ -0,0 +1,85 @@ + +/* + * Copyright (c) 1999-2008 Mark D. Hill and David A. Wood + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer; + * redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution; + * neither the name of the copyright holders nor the names of its + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +/* + * $Id$ + * + */ + +#ifndef CHECKSTOPSLOTSSTATEMENTAST_H +#define CHECKSTOPSLOTSSTATEMENTAST_H + +#include "slicc_global.hh" +#include "ExprAST.hh" +#include "StatementAST.hh" +#include "TypeAST.hh" + +class VarExprAST; +class Var; + +class CheckStopSlotsStatementAST : public StatementAST { +public: + // Constructors + CheckStopSlotsStatementAST(VarExprAST* variable, string* condStr, string* bankStr); + + // Destructor + ~CheckStopSlotsStatementAST(); + + // Public Methods + void generate(string& code, Type* return_type_ptr) const; + void findResources(Map<Var*, string>& resource_list) const; + void print(ostream& out) const; +private: + // Private Methods + + // Private copy constructor and assignment operator + CheckStopSlotsStatementAST(const CheckStopSlotsStatementAST& obj); + CheckStopSlotsStatementAST& operator=(const CheckStopSlotsStatementAST& obj); + + // Data Members (m_ prefix) + VarExprAST* m_variable; + string* m_condStr_ptr; + string* m_bankStr_ptr; +}; + +// Output operator declaration +ostream& operator<<(ostream& out, const CheckStopSlotsStatementAST& obj); + +// ******************* Definitions ******************* + +// Output operator definition +extern inline +ostream& operator<<(ostream& out, const CheckStopSlotsStatementAST& obj) +{ + obj.print(out); + out << flush; + return out; +} + +#endif //CHECKSTOPSLOTSSTATEMENTAST_H diff --git a/src/mem/slicc/ast/ChipComponentAccessAST.cc b/src/mem/slicc/ast/ChipComponentAccessAST.cc new file mode 100644 index 000000000..1ba1b98f2 --- /dev/null +++ b/src/mem/slicc/ast/ChipComponentAccessAST.cc @@ -0,0 +1,244 @@ + +/* + * Copyright (c) 1999-2008 Mark D. Hill and David A. Wood + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer; + * redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution; + * neither the name of the copyright holders nor the names of its + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +/* + * ChipComponentAccessAST.C + * + * Description: See ChipComponentAccessAST.h + * + * $Id: ChipComponentAccessAST.C 1.9 04/06/18 21:00:08-00:00 beckmann@cottons.cs.wisc.edu $ + * + */ + +#include "ChipComponentAccessAST.hh" + +ChipComponentAccessAST::ChipComponentAccessAST(VarExprAST* machine, ExprAST* mach_version, VarExprAST* component, string* proc_name, Vector<ExprAST*>* expr_vec_ptr) + + : ExprAST() +{ + m_chip_ver_expr_ptr = NULL; + m_mach_var_ptr = machine; + m_comp_var_ptr = component; + m_mach_ver_expr_ptr = mach_version; + m_expr_vec_ptr = expr_vec_ptr; + m_proc_name_ptr = proc_name; + m_field_name_ptr = NULL; +} + +ChipComponentAccessAST::ChipComponentAccessAST(VarExprAST* machine, ExprAST* mach_version, VarExprAST* component, string* field_name) + + : ExprAST() +{ + m_chip_ver_expr_ptr = NULL; + m_mach_var_ptr = machine; + m_comp_var_ptr = component; + m_mach_ver_expr_ptr = mach_version; + m_expr_vec_ptr = NULL; + m_proc_name_ptr = NULL; + m_field_name_ptr = field_name; +} + +ChipComponentAccessAST::ChipComponentAccessAST(ExprAST* chip_version, VarExprAST* machine, ExprAST* mach_version, VarExprAST* component, string* proc_name, Vector<ExprAST*>* expr_vec_ptr) + + : ExprAST() +{ + m_chip_ver_expr_ptr = chip_version; + m_mach_var_ptr = machine; + m_comp_var_ptr = component; + m_mach_ver_expr_ptr = mach_version; + m_expr_vec_ptr = expr_vec_ptr; + m_proc_name_ptr = proc_name; + m_field_name_ptr = NULL; +} + +ChipComponentAccessAST::ChipComponentAccessAST(ExprAST* chip_version, VarExprAST* machine, ExprAST* mach_version, VarExprAST* component, string* field_name) + + : ExprAST() +{ + m_chip_ver_expr_ptr = chip_version; + m_mach_var_ptr = machine; + m_comp_var_ptr = component; + m_mach_ver_expr_ptr = mach_version; + m_expr_vec_ptr = NULL; + m_proc_name_ptr = NULL; + m_field_name_ptr = field_name; +} + + + +ChipComponentAccessAST::~ChipComponentAccessAST() +{ + if (m_expr_vec_ptr != NULL) { + int size = m_expr_vec_ptr->size(); + for(int i=0; i<size; i++) { + delete (*m_expr_vec_ptr)[i]; + } + } + + delete m_mach_var_ptr; + delete m_comp_var_ptr; + delete m_mach_ver_expr_ptr; + + if (m_proc_name_ptr != NULL) { + delete m_proc_name_ptr; + } + + if (m_field_name_ptr != NULL) { + delete m_field_name_ptr; + } + + if (m_chip_ver_expr_ptr != NULL) { + delete m_chip_ver_expr_ptr; + } +} + +Type* ChipComponentAccessAST::generate(string& code) const +{ + Type* void_type_ptr = g_sym_table.getType("void"); + Type* ret_type_ptr; + + + code += "("; + + Var* v = g_sym_table.getMachComponentVar(m_mach_var_ptr->getName(), m_comp_var_ptr->getName()); + + string orig_code = v->getCode(); + string working_code; + + if (m_chip_ver_expr_ptr != NULL) { + // replace m_chip_ptr with specified chip + + unsigned int t = orig_code.find("m_chip_ptr"); + assert(t != string::npos); + string code_temp0 = orig_code.substr(0, t); + string code_temp1 = orig_code.substr(t+10); + + working_code += code_temp0; + working_code += "g_system_ptr->getChip("; + m_chip_ver_expr_ptr->generate(working_code); + working_code += ")"; + working_code += code_temp1; + } + else { + working_code += orig_code; + } + + // replace default "m_version" with the version we really want + unsigned int tmp_uint = working_code.find("m_version"); + assert(tmp_uint != string::npos); + string code_temp2 = working_code.substr(0, tmp_uint); + string code_temp3 = working_code.substr(tmp_uint+9); + + code += code_temp2; + code += "("; + m_mach_ver_expr_ptr->generate(code); + code += ")"; + code += code_temp3; + code += ")"; + + if (m_proc_name_ptr != NULL) { + // method call + code += "."; + + Vector <Type*> paramTypes; + + // generate code + int actual_size = m_expr_vec_ptr->size(); + code += (*m_proc_name_ptr) + "("; + for(int i=0; i<actual_size; i++) { + if (i != 0) { + code += ", "; + } + // Check the types of the parameter + Type* actual_type_ptr = (*m_expr_vec_ptr)[i]->generate(code); + paramTypes.insertAtBottom(actual_type_ptr); + } + code += ")"; + + Type* obj_type_ptr = v->getType(); + string methodId = obj_type_ptr->methodId(*m_proc_name_ptr, paramTypes); + + // Verify that this is a method of the object + if (!obj_type_ptr->methodExist(methodId)) { + error("Invalid method call: Type '" + obj_type_ptr->toString() + "' does not have a method '" + methodId + "'"); + } + + int expected_size = obj_type_ptr->methodParamType(methodId).size(); + if (actual_size != expected_size) { + // Right number of parameters + ostringstream err; + err << "Wrong number of parameters for function name: '" << *m_proc_name_ptr << "'"; + err << ", expected: "; + err << expected_size; + err << ", actual: "; + err << actual_size; + error(err.str()); + } + + for(int i=0; i<actual_size; i++) { + // Check the types of the parameter + Type* actual_type_ptr = paramTypes[i]; + Type* expected_type_ptr = obj_type_ptr->methodParamType(methodId)[i]; + if (actual_type_ptr != expected_type_ptr) { + (*m_expr_vec_ptr)[i]->error("Type mismatch: expected: " + expected_type_ptr->toString() + + " actual: " + actual_type_ptr->toString()); + } + } + + // Return the return type of the method + ret_type_ptr = obj_type_ptr->methodReturnType(methodId); + } + else if (m_field_name_ptr != NULL) { + Type* obj_type_ptr = v->getType(); + code += ").m_" + (*m_field_name_ptr); + + // Verify that this is a valid field name for this type + if (!obj_type_ptr->dataMemberExist(*m_field_name_ptr)) { + error("Invalid object field: Type '" + obj_type_ptr->toString() + "' does not have data member " + *m_field_name_ptr); + } + + // Return the type of the field + ret_type_ptr = obj_type_ptr->dataMemberType(*m_field_name_ptr); + } + else { + assert(0); + } + + return ret_type_ptr; +} + +void ChipComponentAccessAST::findResources(Map<Var*, string>& resource_list) const +{ + +} + +void ChipComponentAccessAST::print(ostream& out) const +{ + out << "[ChipAccessExpr: " << *m_expr_vec_ptr << "]"; +} diff --git a/src/mem/slicc/ast/ChipComponentAccessAST.hh b/src/mem/slicc/ast/ChipComponentAccessAST.hh new file mode 100644 index 000000000..039fece2b --- /dev/null +++ b/src/mem/slicc/ast/ChipComponentAccessAST.hh @@ -0,0 +1,101 @@ + +/* + * Copyright (c) 1999-2008 Mark D. Hill and David A. Wood + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer; + * redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution; + * neither the name of the copyright holders nor the names of its + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +/* + * + * + * Description: + * + * $Id: ChipComponentAccessAST.h 1.8 04/06/18 21:00:08-00:00 beckmann@cottons.cs.wisc.edu $ + * + */ + +#ifndef ChipComponentAccessAST_H +#define ChipComponentAccessAST_H + +#include "slicc_global.hh" +#include "StatementAST.hh" +#include "ExprAST.hh" +#include "VarExprAST.hh" +#include "TypeAST.hh" + +class ChipComponentAccessAST : public ExprAST { +public: + // Constructors + + // method call from local chip + ChipComponentAccessAST(VarExprAST* machine, ExprAST* mach_version, VarExprAST* component, string* proc_name, Vector<ExprAST*>* expr_vec_ptr); + // member access from local chip + ChipComponentAccessAST(VarExprAST* machine, ExprAST* mach_version, VarExprAST* component, string* field_name); + + // method call from specified chip + ChipComponentAccessAST(ExprAST* chip_version, VarExprAST* machine, ExprAST* mach_version, VarExprAST* component, string* proc_name, Vector<ExprAST*>* expr_vec_ptr); + + // member access from specified chip + ChipComponentAccessAST(ExprAST* chip_version, VarExprAST* machine, ExprAST* mach_version, VarExprAST* component, string* field_name); + + // Destructor + ~ChipComponentAccessAST(); + + // Public Methods + Type* generate(string& code) const; + void findResources(Map<Var*, string>& resource_list) const; + void print(ostream& out) const; +private: + // Private Methods + + // Private copy constructor and assignment operator + ChipComponentAccessAST(const ChipComponentAccessAST& obj); + ChipComponentAccessAST& operator=(const ChipComponentAccessAST& obj); + + // Data Members (m_ prefix) + VarExprAST* m_mach_var_ptr; + VarExprAST* m_comp_var_ptr; + ExprAST* m_mach_ver_expr_ptr; + ExprAST* m_chip_ver_expr_ptr; + Vector<ExprAST*>* m_expr_vec_ptr; + string* m_proc_name_ptr; + string* m_field_name_ptr; +}; + +// Output operator declaration +ostream& operator<<(ostream& out, const ChipComponentAccessAST& obj); + +// ******************* Definitions ******************* + +// Output operator definition +extern inline +ostream& operator<<(ostream& out, const ChipComponentAccessAST& obj) +{ + obj.print(out); + out << flush; + return out; +} + +#endif // ChipComponentAccessAST_H diff --git a/src/mem/slicc/ast/CopyHeadStatementAST.cc b/src/mem/slicc/ast/CopyHeadStatementAST.cc new file mode 100644 index 000000000..40e61dc07 --- /dev/null +++ b/src/mem/slicc/ast/CopyHeadStatementAST.cc @@ -0,0 +1,85 @@ + +/* + * Copyright (c) 1999-2008 Mark D. Hill and David A. Wood + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer; + * redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution; + * neither the name of the copyright holders nor the names of its + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +/* + * $Id$ + * + */ + +#include "CopyHeadStatementAST.hh" +#include "SymbolTable.hh" +#include "VarExprAST.hh" +#include "util.hh" + +CopyHeadStatementAST::CopyHeadStatementAST(VarExprAST* in_queue_ptr, + VarExprAST* out_queue_ptr, + PairListAST* pairs_ptr) + : StatementAST(pairs_ptr->getPairs()) +{ + m_in_queue_ptr = in_queue_ptr; + m_out_queue_ptr = out_queue_ptr; +} + +CopyHeadStatementAST::~CopyHeadStatementAST() +{ + delete m_in_queue_ptr; + delete m_out_queue_ptr; +} + +void CopyHeadStatementAST::generate(string& code, Type* return_type_ptr) const +{ + m_in_queue_ptr->assertType("InPort"); + m_out_queue_ptr->assertType("OutPort"); + + code += indent_str(); + code += m_out_queue_ptr->getVar()->getCode() + ".enqueue(" + m_in_queue_ptr->getVar()->getCode() + ".getMsgPtrCopy()"; + + if (getPairs().exist("latency")) { + code += ", " + getPairs().lookup("latency"); + } else { + code += ", COPY_HEAD_LATENCY"; + } + + code += ");\n"; +} + +void CopyHeadStatementAST::findResources(Map<Var*, string>& resource_list) const +{ + Var* var_ptr = m_out_queue_ptr->getVar(); + int res_count = 0; + if (resource_list.exist(var_ptr)) { + res_count = atoi((resource_list.lookup(var_ptr)).c_str()); + } + resource_list.add(var_ptr, int_to_string(res_count+1)); +} + +void CopyHeadStatementAST::print(ostream& out) const +{ + out << "[CopyHeadStatementAst: " << *m_in_queue_ptr << " " << *m_out_queue_ptr << "]"; +} diff --git a/src/mem/slicc/ast/CopyHeadStatementAST.hh b/src/mem/slicc/ast/CopyHeadStatementAST.hh new file mode 100644 index 000000000..1631395fc --- /dev/null +++ b/src/mem/slicc/ast/CopyHeadStatementAST.hh @@ -0,0 +1,87 @@ + +/* + * Copyright (c) 1999-2008 Mark D. Hill and David A. Wood + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer; + * redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution; + * neither the name of the copyright holders nor the names of its + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +/* + * $Id$ + * + */ + +#ifndef COPYHEADSTATEMENTAST_H +#define COPYHEADTATEMENTAST_H + +#include "slicc_global.hh" +#include "StatementAST.hh" +#include "StatementListAST.hh" +#include "TypeAST.hh" +#include "PairListAST.hh" + +class VarExprAST; +class Var; + +class CopyHeadStatementAST : public StatementAST { +public: + // Constructors + CopyHeadStatementAST(VarExprAST* in_queue_ptr, + VarExprAST* out_queue_ptr, + PairListAST* pairs_ptr); + + // Destructor + ~CopyHeadStatementAST(); + + // Public Methods + void generate(string& code, Type* return_type_ptr) const; + void findResources(Map<Var*, string>& resource_list) const; + void print(ostream& out) const; +private: + // Private Methods + + // Private copy constructor and assignment operator + CopyHeadStatementAST(const CopyHeadStatementAST& obj); + CopyHeadStatementAST& operator=(const CopyHeadStatementAST& obj); + + // Data Members (m_ prefix) + VarExprAST* m_in_queue_ptr; + VarExprAST* m_out_queue_ptr; +}; + +// Output operator declaration +ostream& operator<<(ostream& out, const CopyHeadStatementAST& obj); + +// ******************* Definitions ******************* + +// Output operator definition +extern inline +ostream& operator<<(ostream& out, const CopyHeadStatementAST& obj) +{ + obj.print(out); + out << flush; + return out; +} + +#endif //COPYHEADSTATEMENTAST_H diff --git a/src/mem/slicc/ast/DeclAST.cc b/src/mem/slicc/ast/DeclAST.cc new file mode 100644 index 000000000..4269ed9f4 --- /dev/null +++ b/src/mem/slicc/ast/DeclAST.cc @@ -0,0 +1,39 @@ + +/* + * Copyright (c) 1999-2008 Mark D. Hill and David A. Wood + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer; + * redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution; + * neither the name of the copyright holders nor the names of its + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +/* + * DeclAST.C + * + * Description: See DeclAST.h + * + * $Id$ + * + */ + +#include "DeclAST.hh" diff --git a/src/mem/slicc/ast/DeclAST.hh b/src/mem/slicc/ast/DeclAST.hh new file mode 100644 index 000000000..e7c8467d6 --- /dev/null +++ b/src/mem/slicc/ast/DeclAST.hh @@ -0,0 +1,85 @@ + +/* + * Copyright (c) 1999-2008 Mark D. Hill and David A. Wood + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer; + * redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution; + * neither the name of the copyright holders nor the names of its + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +/* + * DeclAST.h + * + * Description: + * + * $Id$ + * + */ + +#ifndef DECLAST_H +#define DECLAST_H + +#include "slicc_global.hh" +#include "AST.hh" +#include "PairListAST.hh" +#include "StateMachine.hh" +#include "TypeAST.hh" + +class DeclAST : public AST { +public: + // Constructors + DeclAST(PairListAST* pairs_ptr) : AST(pairs_ptr->getPairs()) {} + + // Destructor + virtual ~DeclAST() {} + + // Public Methods + virtual void generate() = 0; + virtual void findMachines() {}; + + // void print(ostream& out) const; +private: + // Private Methods + + // Private copy constructor and assignment operator + // DeclAST(const DeclAST& obj); + // DeclAST& operator=(const DeclAST& obj); + + // Data Members (m_ prefix) +}; + +// Output operator declaration +ostream& operator<<(ostream& out, const DeclAST& obj); + +// ******************* Definitions ******************* + +// Output operator definition +extern inline +ostream& operator<<(ostream& out, const DeclAST& obj) +{ + obj.print(out); + out << flush; + return out; +} + +#endif //DECLAST_H diff --git a/src/mem/slicc/ast/DeclListAST.cc b/src/mem/slicc/ast/DeclListAST.cc new file mode 100644 index 000000000..6dacd5435 --- /dev/null +++ b/src/mem/slicc/ast/DeclListAST.cc @@ -0,0 +1,86 @@ + +/* + * Copyright (c) 1999-2008 Mark D. Hill and David A. Wood + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer; + * redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution; + * neither the name of the copyright holders nor the names of its + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +/* + * DeclListAST.C + * + * Description: See DeclListAST.h + * + * $Id$ + * + */ + +#include "DeclListAST.hh" + +DeclListAST::DeclListAST(Vector<DeclAST*>* vec_ptr) + : AST() +{ + assert(vec_ptr != NULL); + m_vec_ptr = vec_ptr; +} + +// Singleton constructor. +DeclListAST::DeclListAST(DeclAST* Decl_ptr) + : AST() +{ + assert(Decl_ptr != NULL); + m_vec_ptr = new Vector<DeclAST*>; + m_vec_ptr->insertAtTop(Decl_ptr); +} + +DeclListAST::~DeclListAST() +{ + int size = m_vec_ptr->size(); + for(int i=0; i<size; i++) { + delete (*m_vec_ptr)[i]; + } + delete m_vec_ptr; +} + +void DeclListAST::generate() const +{ + int size = m_vec_ptr->size(); + for(int i=0; i<size; i++) { + (*m_vec_ptr)[i]->generate(); + } +} + +void DeclListAST::findMachines() const +{ + int size = m_vec_ptr->size(); + for(int i=0; i<size; i++) { + (*m_vec_ptr)[i]->findMachines(); + } +} + +void DeclListAST::print(ostream& out) const +{ + assert(m_vec_ptr != NULL); + out << "[DeclListAST: " << *m_vec_ptr << "]"; +} diff --git a/src/mem/slicc/ast/DeclListAST.hh b/src/mem/slicc/ast/DeclListAST.hh new file mode 100644 index 000000000..80c7fffcc --- /dev/null +++ b/src/mem/slicc/ast/DeclListAST.hh @@ -0,0 +1,84 @@ + +/* + * Copyright (c) 1999-2008 Mark D. Hill and David A. Wood + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer; + * redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution; + * neither the name of the copyright holders nor the names of its + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +/* + * DeclListAST.h + * + * Description: + * + * $Id: DeclListAST.h,v 3.1 2001/12/12 01:00:12 milo Exp $ + * + */ + +#ifndef DeclListAST_H +#define DeclListAST_H + +#include "slicc_global.hh" +#include "AST.hh" +#include "DeclAST.hh" + +class DeclListAST : public AST { +public: + // Constructors + DeclListAST(Vector<DeclAST*>* vec_ptr); + DeclListAST(DeclAST* statement_ptr); + + // Destructor + ~DeclListAST(); + + // Public Methods + void generate() const; + void findMachines() const; + void print(ostream& out) const; +private: + // Private Methods + + // Private copy constructor and assignment operator + DeclListAST(const DeclListAST& obj); + DeclListAST& operator=(const DeclListAST& obj); + + // Data Members (m_ prefix) + Vector<DeclAST*>* m_vec_ptr; +}; + +// Output operator declaration +ostream& operator<<(ostream& out, const DeclListAST& obj); + +// ******************* Definitions ******************* + +// Output operator definition +extern inline +ostream& operator<<(ostream& out, const DeclListAST& obj) +{ + obj.print(out); + out << flush; + return out; +} + +#endif //DeclListAST_H diff --git a/src/mem/slicc/ast/EnqueueStatementAST.cc b/src/mem/slicc/ast/EnqueueStatementAST.cc new file mode 100644 index 000000000..49f2a9233 --- /dev/null +++ b/src/mem/slicc/ast/EnqueueStatementAST.cc @@ -0,0 +1,104 @@ + +/* + * Copyright (c) 1999-2008 Mark D. Hill and David A. Wood + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer; + * redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution; + * neither the name of the copyright holders nor the names of its + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +/* + * $Id$ + * + */ + +#include "EnqueueStatementAST.hh" +#include "SymbolTable.hh" +#include "VarExprAST.hh" +#include "PairListAST.hh" +#include "util.hh" + +EnqueueStatementAST::EnqueueStatementAST(VarExprAST* queue_name_ptr, + TypeAST* type_name_ptr, + PairListAST* pairs_ptr, + StatementListAST* statement_list_ast_ptr) + : StatementAST(pairs_ptr->getPairs()) +{ + m_queue_name_ptr = queue_name_ptr; + m_type_name_ptr = type_name_ptr; + m_statement_list_ast_ptr = statement_list_ast_ptr; +} + +EnqueueStatementAST::~EnqueueStatementAST() +{ + delete m_queue_name_ptr; + delete m_type_name_ptr; + delete m_statement_list_ast_ptr; +} + +void EnqueueStatementAST::generate(string& code, Type* return_type_ptr) const +{ + code += indent_str() + "{\n"; // Start scope + inc_indent(); + g_sym_table.pushFrame(); + + Type* msg_type_ptr = m_type_name_ptr->lookupType(); + + // Add new local var to symbol table + g_sym_table.newSym(new Var("out_msg", getLocation(), msg_type_ptr, "out_msg", getPairs())); + + code += indent_str() + msg_type_ptr->cIdent() + " out_msg;\n"; // Declare message + m_statement_list_ast_ptr->generate(code, NULL); // The other statements + + code += indent_str(); + + m_queue_name_ptr->assertType("OutPort"); + code += "(" + m_queue_name_ptr->getVar()->getCode() + ")"; + code += ".enqueue(out_msg"; + + if (getPairs().exist("latency")) { + code += ", " + getPairs().lookup("latency"); + } + + code += ");\n"; + + dec_indent(); + g_sym_table.popFrame(); + code += indent_str() + "}\n"; // End scope +} + +void EnqueueStatementAST::findResources(Map<Var*, string>& resource_list) const +{ + Var* var_ptr = m_queue_name_ptr->getVar(); + int res_count = 0; + if (resource_list.exist(var_ptr)) { + res_count = atoi((resource_list.lookup(var_ptr)).c_str()); + } + resource_list.add(var_ptr, int_to_string(res_count+1)); +} + +void EnqueueStatementAST::print(ostream& out) const +{ + out << "[EnqueueStatementAst: " << *m_queue_name_ptr << " " + << m_type_name_ptr->toString() << " " << *m_statement_list_ast_ptr << "]"; +} diff --git a/src/mem/slicc/ast/EnqueueStatementAST.hh b/src/mem/slicc/ast/EnqueueStatementAST.hh new file mode 100644 index 000000000..eb7dad9af --- /dev/null +++ b/src/mem/slicc/ast/EnqueueStatementAST.hh @@ -0,0 +1,93 @@ + +/* + * Copyright (c) 1999-2008 Mark D. Hill and David A. Wood + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer; + * redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution; + * neither the name of the copyright holders nor the names of its + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +/* + * EnqueueStatementAST.h + * + * Description: + * + * $Id$ + * + */ + +#ifndef ENQUEUESTATEMENTAST_H +#define ENQUEUESTATEMENTAST_H + +#include "slicc_global.hh" +#include "StatementAST.hh" +#include "StatementListAST.hh" +#include "TypeAST.hh" + +class VarExprAST; +class Var; +class PairListAST; + +class EnqueueStatementAST : public StatementAST { +public: + // Constructors + EnqueueStatementAST(VarExprAST* queue_name_ptr, + TypeAST* type_name_ptr, + PairListAST* pairs_ptr, + StatementListAST* statement_list_ast_ptr); + + // Destructor + ~EnqueueStatementAST(); + + // Public Methods + void generate(string& code, Type* return_type_ptr) const; + void findResources(Map<Var*, string>& resource_list) const; + void print(ostream& out) const; +private: + // Private Methods + + // Private copy constructor and assignment operator + EnqueueStatementAST(const EnqueueStatementAST& obj); + EnqueueStatementAST& operator=(const EnqueueStatementAST& obj); + + // Data Members (m_ prefix) + VarExprAST* m_queue_name_ptr; + TypeAST* m_type_name_ptr; + StatementListAST* m_statement_list_ast_ptr; +}; + +// Output operator declaration +ostream& operator<<(ostream& out, const EnqueueStatementAST& obj); + +// ******************* Definitions ******************* + +// Output operator definition +extern inline +ostream& operator<<(ostream& out, const EnqueueStatementAST& obj) +{ + obj.print(out); + out << flush; + return out; +} + +#endif //ENQUEUESTATEMENTAST_H diff --git a/src/mem/slicc/ast/EnumDeclAST.cc b/src/mem/slicc/ast/EnumDeclAST.cc new file mode 100644 index 000000000..c8e033095 --- /dev/null +++ b/src/mem/slicc/ast/EnumDeclAST.cc @@ -0,0 +1,98 @@ + +/* + * Copyright (c) 1999-2008 Mark D. Hill and David A. Wood + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer; + * redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution; + * neither the name of the copyright holders nor the names of its + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +/* + * EnumDeclAST.C + * + * Description: See EnumDeclAST.h + * + * $Id$ + * + */ + +#include "EnumDeclAST.hh" +#include "main.hh" +#include "SymbolTable.hh" + +EnumDeclAST::EnumDeclAST(TypeAST* type_ast_ptr, + PairListAST* pairs_ptr, + Vector<TypeFieldAST*>* field_vec_ptr) + : DeclAST(pairs_ptr) +{ + m_type_ast_ptr = type_ast_ptr; + m_field_vec_ptr = field_vec_ptr; +} + +EnumDeclAST::~EnumDeclAST() +{ + delete m_type_ast_ptr; + if (m_field_vec_ptr != NULL) { + int size = m_field_vec_ptr->size(); + for(int i=0; i<size; i++) { + delete (*m_field_vec_ptr)[i]; + } + delete m_field_vec_ptr; + } +} + +void EnumDeclAST::generate() +{ + string machine_name; + string id = m_type_ast_ptr->toString(); + + Vector<Type*> param_type_vec; // used by to_string func call + + // Make the new type + Type* new_type_ptr = new Type(id, getLocation(), getPairs(), + g_sym_table.getStateMachine()); + g_sym_table.newSym(new_type_ptr); + + // Add all of the fields of the type to it + if (m_field_vec_ptr != NULL) { + int size = m_field_vec_ptr->size(); + for(int i=0; i<size; i++) { + (*m_field_vec_ptr)[i]->generate(new_type_ptr); + } + } + + // Add the implicit State_to_string method - FIXME, this is a bit dirty + param_type_vec.insertAtBottom(new_type_ptr); // add state to param vector + string func_id = new_type_ptr->cIdent()+"_to_string"; + + Map<string, string> pairs; + pairs.add("external", "yes"); + Vector<string> string_vec; + g_sym_table.newSym(new Func(func_id, getLocation(), g_sym_table.getType("string"), param_type_vec, string_vec, string(""), pairs, NULL)); +} + +void EnumDeclAST::print(ostream& out) const +{ + out << "[EnumDecl: " << m_type_ast_ptr->toString() << "]"; +} + diff --git a/src/mem/slicc/ast/EnumDeclAST.hh b/src/mem/slicc/ast/EnumDeclAST.hh new file mode 100644 index 000000000..4474b69cc --- /dev/null +++ b/src/mem/slicc/ast/EnumDeclAST.hh @@ -0,0 +1,86 @@ + +/* + * Copyright (c) 1999-2008 Mark D. Hill and David A. Wood + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer; + * redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution; + * neither the name of the copyright holders nor the names of its + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +/* + * EnummDeclAST.h + * + * Description: + * + * $Id$ + * + */ + +#ifndef EnumDeclAST_H +#define EnumDeclAST_H + +#include "slicc_global.hh" +#include "DeclAST.hh" +#include "TypeAST.hh" +#include "TypeFieldAST.hh" + +class EnumDeclAST : public DeclAST { +public: + // Constructors + EnumDeclAST(TypeAST* type_ast_ptr, + PairListAST* pairs_ptr, + Vector<TypeFieldAST*>* field_vec_ptr); + + // Destructor + ~EnumDeclAST(); + + // Public Methods + virtual void generate(); + void print(ostream& out) const; +private: + // Private Methods + + // Private copy constructor and assignment operator + EnumDeclAST(const EnumDeclAST& obj); + EnumDeclAST& operator=(const EnumDeclAST& obj); + + // Data Members (m_ prefix) + TypeAST* m_type_ast_ptr; + Vector<TypeFieldAST*>* m_field_vec_ptr; +}; + +// Output operator declaration +ostream& operator<<(ostream& out, const EnumDeclAST& obj); + +// ******************* Definitions ******************* + +// Output operator definition +extern inline +ostream& operator<<(ostream& out, const EnumDeclAST& obj) +{ + obj.print(out); + out << flush; + return out; +} + +#endif //EnumDeclAST_H diff --git a/src/mem/slicc/ast/EnumExprAST.cc b/src/mem/slicc/ast/EnumExprAST.cc new file mode 100644 index 000000000..90dc4bebf --- /dev/null +++ b/src/mem/slicc/ast/EnumExprAST.cc @@ -0,0 +1,76 @@ + +/* + * Copyright (c) 1999-2008 Mark D. Hill and David A. Wood + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer; + * redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution; + * neither the name of the copyright holders nor the names of its + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +/* + * EnumExprAST.C + * + * Description: See EnumExprAST.h + * + * $Id: EnumExprAST.C,v 3.1 2003/07/10 18:08:06 milo Exp $ + * + */ + +#include "EnumExprAST.hh" + +EnumExprAST::EnumExprAST(TypeAST* type_ast_ptr, + string* value_ptr) + : ExprAST() +{ + assert(value_ptr != NULL); + assert(type_ast_ptr != NULL); + m_type_ast_ptr = type_ast_ptr; + m_value_ptr = value_ptr; +} + +EnumExprAST::~EnumExprAST() +{ + delete m_type_ast_ptr; + delete m_value_ptr; +} + +Type* EnumExprAST::generate(string& code) const +{ + Type* type_ptr = m_type_ast_ptr->lookupType(); + code += type_ptr->cIdent() + "_" + (*m_value_ptr); + + // Make sure the enumeration value exists + if (!type_ptr->enumExist(*m_value_ptr)) { + error("Type '" + m_type_ast_ptr->toString() + "' does not have enumeration '" + *m_value_ptr + "'"); + } + + // Return the proper type + return type_ptr; +} + +void EnumExprAST::print(ostream& out) const +{ + string str; + str += m_type_ast_ptr->toString()+":"+(*m_value_ptr); + out << "[EnumExpr: " << str << "]"; +} diff --git a/src/mem/slicc/ast/EnumExprAST.hh b/src/mem/slicc/ast/EnumExprAST.hh new file mode 100644 index 000000000..492f9ac33 --- /dev/null +++ b/src/mem/slicc/ast/EnumExprAST.hh @@ -0,0 +1,85 @@ + +/* + * Copyright (c) 1999-2008 Mark D. Hill and David A. Wood + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer; + * redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution; + * neither the name of the copyright holders nor the names of its + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +/* + * EnumExprAST.h + * + * Description: + * + * $Id: EnumExprAST.h,v 3.2 2003/07/10 18:08:06 milo Exp $ + * + */ + +#ifndef EnumExprAST_H +#define EnumExprAST_H + +#include "slicc_global.hh" +#include "ExprAST.hh" +#include "TypeAST.hh" + + +class EnumExprAST : public ExprAST { +public: + // Constructors + EnumExprAST(TypeAST* type_ast_ptr, + string* value_ptr); + + // Destructor + ~EnumExprAST(); + + // Public Methods + Type* generate(string& code) const; + void print(ostream& out) const; +private: + // Private Methods + + // Private copy constructor and assignment operator + EnumExprAST(const EnumExprAST& obj); + EnumExprAST& operator=(const EnumExprAST& obj); + + // Data Members (m_ prefix) + TypeAST* m_type_ast_ptr; + string* m_value_ptr; +}; + +// Output operator declaration +ostream& operator<<(ostream& out, const EnumExprAST& obj); + +// ******************* Definitions ******************* + +// Output operator definition +extern inline +ostream& operator<<(ostream& out, const EnumExprAST& obj) +{ + obj.print(out); + out << flush; + return out; +} + +#endif //EnumExprAST_H diff --git a/src/mem/slicc/ast/ExprAST.cc b/src/mem/slicc/ast/ExprAST.cc new file mode 100644 index 000000000..e910d688a --- /dev/null +++ b/src/mem/slicc/ast/ExprAST.cc @@ -0,0 +1,39 @@ + +/* + * Copyright (c) 1999-2008 Mark D. Hill and David A. Wood + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer; + * redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution; + * neither the name of the copyright holders nor the names of its + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +/* + * ExprAST.C + * + * Description: See ExprAST.h + * + * $Id$ + * + */ + +#include "ExprAST.hh" diff --git a/src/mem/slicc/ast/ExprAST.hh b/src/mem/slicc/ast/ExprAST.hh new file mode 100644 index 000000000..0015cebaa --- /dev/null +++ b/src/mem/slicc/ast/ExprAST.hh @@ -0,0 +1,84 @@ + +/* + * Copyright (c) 1999-2008 Mark D. Hill and David A. Wood + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer; + * redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution; + * neither the name of the copyright holders nor the names of its + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +/* + * ExprAST.h + * + * Description: + * + * $Id$ + * + */ + +#ifndef EXPRAST_H +#define EXPRAST_H + +#include "slicc_global.hh" +#include "AST.hh" + + +class ExprAST : public AST { +public: + // Constructors + ExprAST() : AST() { } + + // Destructor + virtual ~ExprAST() { } + + // Public Methods + virtual Type* generate(string& code) const = 0; + virtual void findResources(Map<Var*, string>& resource_list) const {} // The default is no resources + + // void print(ostream& out) const; +private: + // Private Methods + + // Private copy constructor and assignment operator + // ExprAST(const ExprAST& obj); + // ExprAST& operator=(const ExprAST& obj); + + // Data Members (m_ prefix) + +}; + +// Output operator declaration +ostream& operator<<(ostream& out, const ExprAST& obj); + +// ******************* Definitions ******************* + +// Output operator definition +extern inline +ostream& operator<<(ostream& out, const ExprAST& obj) +{ + obj.print(out); + out << flush; + return out; +} + +#endif //EXPRAST_H diff --git a/src/mem/slicc/ast/ExprStatementAST.cc b/src/mem/slicc/ast/ExprStatementAST.cc new file mode 100644 index 000000000..5eb1ce7b4 --- /dev/null +++ b/src/mem/slicc/ast/ExprStatementAST.cc @@ -0,0 +1,73 @@ + +/* + * Copyright (c) 1999-2008 Mark D. Hill and David A. Wood + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer; + * redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution; + * neither the name of the copyright holders nor the names of its + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +/* + * ExprStatementAST.C + * + * Description: See ExprStatementAST.h + * + * $Id$ + * + */ + +#include "ExprStatementAST.hh" + +ExprStatementAST::ExprStatementAST(ExprAST* expr_ptr) + : StatementAST() +{ + m_expr_ptr = expr_ptr; +} + +ExprStatementAST::~ExprStatementAST() +{ + delete m_expr_ptr; +} + +void ExprStatementAST::generate(string& code, Type* return_type_ptr) const +{ + code += indent_str(); + Type* actual_type_ptr = m_expr_ptr->generate(code); + code += ";\n"; + + // The return type must be void + Type* expected_type_ptr = g_sym_table.getType("void"); + if (expected_type_ptr != actual_type_ptr) { + m_expr_ptr->error("Non-void return must not be ignored, return type is '" + actual_type_ptr->toString() + "'"); + } +} + +void ExprStatementAST::findResources(Map<Var*, string>& resource_list) const +{ + m_expr_ptr->findResources(resource_list); +} + +void ExprStatementAST::print(ostream& out) const +{ + out << "[ExprStatementAST: " << *m_expr_ptr << "]"; +} diff --git a/src/mem/slicc/ast/ExprStatementAST.hh b/src/mem/slicc/ast/ExprStatementAST.hh new file mode 100644 index 000000000..925ded72a --- /dev/null +++ b/src/mem/slicc/ast/ExprStatementAST.hh @@ -0,0 +1,83 @@ + +/* + * Copyright (c) 1999-2008 Mark D. Hill and David A. Wood + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer; + * redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution; + * neither the name of the copyright holders nor the names of its + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +/* + * ExprStatementAST.h + * + * Description: + * + * $Id$ + * + */ + +#ifndef ExprStatementAST_H +#define ExprStatementAST_H + +#include "slicc_global.hh" +#include "StatementAST.hh" +#include "ExprAST.hh" + +class ExprStatementAST : public StatementAST { +public: + // Constructors + ExprStatementAST(ExprAST* expr_ptr); + + // Destructor + ~ExprStatementAST(); + + // Public Methods + void generate(string& code, Type* return_type_ptr) const; + void findResources(Map<Var*, string>& resource_list) const; + void print(ostream& out) const; +private: + // Private Methods + + // Private copy constructor and assignment operator + ExprStatementAST(const ExprStatementAST& obj); + ExprStatementAST& operator=(const ExprStatementAST& obj); + + // Data Members (m_ prefix) + ExprAST* m_expr_ptr; +}; + +// Output operator declaration +ostream& operator<<(ostream& out, const ExprStatementAST& obj); + +// ******************* Definitions ******************* + +// Output operator definition +extern inline +ostream& operator<<(ostream& out, const ExprStatementAST& obj) +{ + obj.print(out); + out << flush; + return out; +} + +#endif //ExprStatementAST_H diff --git a/src/mem/slicc/ast/FormalParamAST.cc b/src/mem/slicc/ast/FormalParamAST.cc new file mode 100644 index 000000000..b7dacf8a1 --- /dev/null +++ b/src/mem/slicc/ast/FormalParamAST.cc @@ -0,0 +1,61 @@ + +/* + * Copyright (c) 1999-2008 Mark D. Hill and David A. Wood + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer; + * redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution; + * neither the name of the copyright holders nor the names of its + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +/* + * FormalParamAST.C + * + * Description: See FormalParamAST.h + * + * $Id: FormalParamAST.C,v 3.1 2000/10/05 21:22:20 milo Exp $ + * + */ + +#include "FormalParamAST.hh" +#include "StatementAST.hh" +#include "SymbolTable.hh" + +FormalParamAST::~FormalParamAST() +{ + delete m_ident_ptr; + delete m_type_ast_ptr; +} + +Type* FormalParamAST::generate(string& code) const +{ + string param = "param_" + *m_ident_ptr; + + Type* type_ptr = m_type_ast_ptr->lookupType(); + code += type_ptr->cIdent(); + code += " "; + code += param; + + // Add to symbol table + g_sym_table.newSym(new Var(*m_ident_ptr, getLocation(), type_ptr, param, getPairs())); + return type_ptr; +} diff --git a/src/mem/slicc/ast/FormalParamAST.hh b/src/mem/slicc/ast/FormalParamAST.hh new file mode 100644 index 000000000..0dc08fabe --- /dev/null +++ b/src/mem/slicc/ast/FormalParamAST.hh @@ -0,0 +1,84 @@ + +/* + * Copyright (c) 1999-2008 Mark D. Hill and David A. Wood + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer; + * redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution; + * neither the name of the copyright holders nor the names of its + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +/* + * FormalParamAST.h + * + * Description: + * + * $Id: FormalParamAST.h,v 3.1 2001/12/12 01:00:15 milo Exp $ + * + */ + +#ifndef FORMALPARAMAST_H +#define FORMALPARAMAST_H + +#include "slicc_global.hh" +#include "TypeAST.hh" + + +class FormalParamAST : public AST { +public: + // Constructors + FormalParamAST(TypeAST* type_ast_ptr, string* ident_ptr) : AST() { m_type_ast_ptr = type_ast_ptr; m_ident_ptr = ident_ptr; } + + // Destructor + ~FormalParamAST(); + + // Public Methods + Type* generate(string& code) const; + void print(ostream& out) const { out << "[FormalParamAST: " << *m_ident_ptr << "]"; } + string getName() const { return *m_ident_ptr; } +private: + // Private Methods + + // Private copy constructor and assignment operator + FormalParamAST(const FormalParamAST& obj); + FormalParamAST& operator=(const FormalParamAST& obj); + + // Data Members (m_ prefix) + string* m_ident_ptr; + TypeAST* m_type_ast_ptr; +}; + +// Output operator declaration +ostream& operator<<(ostream& out, const FormalParamAST& obj); + +// ******************* Definitions ******************* + +// Output operator definition +extern inline +ostream& operator<<(ostream& out, const FormalParamAST& obj) +{ + obj.print(out); + out << flush; + return out; +} + +#endif //FORMALPARAMAST_H diff --git a/src/mem/slicc/ast/FuncCallExprAST.cc b/src/mem/slicc/ast/FuncCallExprAST.cc new file mode 100644 index 000000000..845d0c8e3 --- /dev/null +++ b/src/mem/slicc/ast/FuncCallExprAST.cc @@ -0,0 +1,224 @@ + +/* + * Copyright (c) 1999-2008 Mark D. Hill and David A. Wood + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer; + * redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution; + * neither the name of the copyright holders nor the names of its + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +/* + * FuncCallExprAST.C + * + * Description: See FuncCallExprAST.h + * + * $Id$ + * + */ + +#include "FuncCallExprAST.hh" +#include "SymbolTable.hh" + +FuncCallExprAST::FuncCallExprAST(string* proc_name_ptr, + Vector<ExprAST*>* expr_vec_ptr) + : ExprAST() +{ + m_proc_name_ptr = proc_name_ptr; + m_expr_vec_ptr = expr_vec_ptr; +} + +FuncCallExprAST::~FuncCallExprAST() +{ + delete m_proc_name_ptr; + int size = m_expr_vec_ptr->size(); + for(int i=0; i<size; i++) { + delete (*m_expr_vec_ptr)[i]; + } + delete m_expr_vec_ptr; +} + +Type* FuncCallExprAST::generate(string& code) const +{ + // DEBUG_EXPR is strange since it takes parameters of multiple types + if (*m_proc_name_ptr == "DEBUG_EXPR") { + // FIXME - check for number of parameters + code += "DEBUG_SLICC(MedPrio, \""; + code += (*m_expr_vec_ptr)[0]->getLocation().toString(); + code += ": \", "; + (*m_expr_vec_ptr)[0]->generate(code); + code += ");\n"; + Type* void_type_ptr = g_sym_table.getType("void"); + assert(void_type_ptr != NULL); + return void_type_ptr; + } + + // hack for adding comments to profileTransition + if (*m_proc_name_ptr == "APPEND_TRANSITION_COMMENT") { + // FIXME - check for number of parameters + code += "APPEND_TRANSITION_COMMENT("; + //code += (*m_expr_vec_ptr)[0]->getLocation().toString(); + //code += ": \", "; + (*m_expr_vec_ptr)[0]->generate(code); + code += ");\n"; + Type* void_type_ptr = g_sym_table.getType("void"); + assert(void_type_ptr != NULL); + return void_type_ptr; + } + + // Look up the function in the symbol table + Vector<string> code_vec; + Func* func_ptr = g_sym_table.getFunc(*m_proc_name_ptr); + + // Check the types and get the code for the parameters + if (func_ptr == NULL) { + error("Unrecognized function name: '" + *m_proc_name_ptr + "'"); + } else { + int size = m_expr_vec_ptr->size(); + + Vector<Type*> f = func_ptr->getParamTypes(); + + if (size != f.size() ) { + error("Wrong number of arguments passed to function : '" + *m_proc_name_ptr + "'"); + } + else { + for(int i=0; i<size; i++) { + + // Check the types of the parameter + string param_code; + Type* actual_type_ptr = (*m_expr_vec_ptr)[i]->generate(param_code); + Type* expected_type_ptr = func_ptr->getParamTypes()[i]; + if (actual_type_ptr != expected_type_ptr) { + (*m_expr_vec_ptr)[i]->error("Type mismatch: expected: " + expected_type_ptr->toString() + + " actual: " + actual_type_ptr->toString()); + } + code_vec.insertAtBottom(param_code); + } + } + } + + /* OK, the semantics of "trigger" here is that, ports in the machine have + * different priorities. We always check the first port for doable + * transitions. If nothing/stalled, we pick one from the next port. + * + * One thing we have to be careful as the SLICC protocol writter is : + * If a port have two or more transitions can be picked from in one cycle, + * they must be independent. Otherwise, if transition A and B mean to be + * executed in sequential, and A get stalled, transition B can be issued + * erroneously. In practice, in most case, there is only one transition + * should be executed in one cycle for a given port. So as most of current + * protocols. + */ + + if (*m_proc_name_ptr == "trigger") { + code += indent_str() + "{\n"; + code += indent_str() + " Address addr = "; + code += code_vec[1]; + code += ";\n"; + code += indent_str() + " TransitionResult result = doTransition("; + code += code_vec[0]; + code += ", " + g_sym_table.getStateMachine()->toString() + "_getState(addr), addr"; + if(CHECK_INVALID_RESOURCE_STALLS) { + // FIXME - the current assumption is that in_buffer_rank is declared in the msg buffer peek statement + code += ", in_buffer_rank"; + } + code += ");\n"; + code += indent_str() + " if (result == TransitionResult_Valid) {\n"; + code += indent_str() + " counter++;\n"; + code += indent_str() + " continue; // Check the first port again\n"; + code += indent_str() + " }\n"; + code += indent_str() + " if (result == TransitionResult_ResourceStall) {\n"; + code += indent_str() + " g_eventQueue_ptr->scheduleEvent(this, 1);\n"; + code += indent_str() + " // Cannot do anything with this transition, go check next doable transition (mostly likely of next port)\n"; + code += indent_str() + " }\n"; + code += indent_str() + "}\n"; + } else if (*m_proc_name_ptr == "doubleTrigger") { + // NOTE: Use the doubleTrigger call with extreme caution + // the key to double trigger is the second event triggered cannot fail becuase the first event cannot be undone + assert(code_vec.size() == 4); + code += indent_str() + "{\n"; + code += indent_str() + " Address addr1 = "; + code += code_vec[1]; + code += ";\n"; + code += indent_str() + " TransitionResult result1 = doTransition("; + code += code_vec[0]; + code += ", " + g_sym_table.getStateMachine()->toString() + "_getState(addr1), addr1"; + if(CHECK_INVALID_RESOURCE_STALLS) { + // FIXME - the current assumption is that in_buffer_rank is declared in the msg buffer peek statement + code += ", in_buffer_rank"; + } + code += ");\n"; + code += indent_str() + " if (result1 == TransitionResult_Valid) {\n"; + code += indent_str() + " //this second event cannont fail because the first event already took effect\n"; + code += indent_str() + " Address addr2 = "; + code += code_vec[3]; + code += ";\n"; + code += indent_str() + " TransitionResult result2 = doTransition("; + code += code_vec[2]; + code += ", " + g_sym_table.getStateMachine()->toString() + "_getState(addr2), addr2"; + if(CHECK_INVALID_RESOURCE_STALLS) { + // FIXME - the current assumption is that in_buffer_rank is declared in the msg buffer peek statement + code += ", in_buffer_rank"; + } + code += ");\n"; + code += indent_str() + " assert(result2 == TransitionResult_Valid); // ensure the event suceeded\n"; + code += indent_str() + " counter++;\n"; + code += indent_str() + " continue; // Check the first port again\n"; + code += indent_str() + " }\n"; + code += indent_str() + " if (result1 == TransitionResult_ResourceStall) {\n"; + code += indent_str() + " g_eventQueue_ptr->scheduleEvent(this, 1);\n"; + code += indent_str() + " // Cannot do anything with this transition, go check next doable transition (mostly likely of next port)\n"; + code += indent_str() + " }\n"; + code += indent_str() + "}\n"; + } else if (*m_proc_name_ptr == "error") { + code += indent_str() + (*m_expr_vec_ptr)[0]->embedError(code_vec[0]) + "\n"; + } else if (*m_proc_name_ptr == "assert") { + code += indent_str() + "if (ASSERT_FLAG && !(" + code_vec[0] + ")) {\n"; + code += indent_str() + " " + (*m_expr_vec_ptr)[0]->embedError("\"assert failure\"") + "\n"; + code += indent_str() + "}\n"; + } else if (*m_proc_name_ptr == "continueProcessing") { + code += "counter++; continue; // Check the first port again"; + } else { + // Normal function + code += "("; + // if the func is internal to the chip but not the machine then it can only be + // accessed through the chip pointer + if (!func_ptr->existPair("external") && !func_ptr->isInternalMachineFunc()) { + code += "m_chip_ptr->"; + } + code += func_ptr->cIdent() + "("; + int size = code_vec.size(); + for(int i=0; i<size; i++) { + if (i != 0) { + code += ", "; + } + code += code_vec[i]; + } + code += "))"; + } + return func_ptr->getReturnType(); +} + +void FuncCallExprAST::print(ostream& out) const +{ + out << "[FuncCallExpr: " << *m_proc_name_ptr << " " << *m_expr_vec_ptr << "]"; +} diff --git a/src/mem/slicc/ast/FuncCallExprAST.hh b/src/mem/slicc/ast/FuncCallExprAST.hh new file mode 100644 index 000000000..edac97a04 --- /dev/null +++ b/src/mem/slicc/ast/FuncCallExprAST.hh @@ -0,0 +1,89 @@ + +/* + * Copyright (c) 1999-2008 Mark D. Hill and David A. Wood + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer; + * redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution; + * neither the name of the copyright holders nor the names of its + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +/* + * FuncCallExprAST.h + * + * Description: + * + * $Id$ + * + */ + +#ifndef FUNCCALLEXPRAST_H +#define FUNCCALLEXPRAST_H + +#include "slicc_global.hh" +#include "StatementAST.hh" +#include "ExprAST.hh" + + +// ProcGen decl +class FuncGen; + +class FuncCallExprAST : public ExprAST { +public: + // Constructors + FuncCallExprAST(string* proc_name_ptr, + Vector<ExprAST*>* expr_vec_ptr); + + // Destructor + ~FuncCallExprAST(); + + // Public Methods + Type* generate(string& code) const; + void print(ostream& out) const; + +private: + // Private Methods + + // Private copy constructor and assignment operator + FuncCallExprAST(const FuncCallExprAST& obj); + FuncCallExprAST& operator=(const FuncCallExprAST& obj); + + // Data Members (m_ prefix) + string* m_proc_name_ptr; + Vector<ExprAST*>* m_expr_vec_ptr; +}; + +// Output operator declaration +ostream& operator<<(ostream& out, const FuncCallExprAST& obj); + +// ******************* Definitions ******************* + +// Output operator definition +extern inline +ostream& operator<<(ostream& out, const FuncCallExprAST& obj) +{ + obj.print(out); + out << flush; + return out; +} + +#endif //FUNCCALLEXPRAST_H diff --git a/src/mem/slicc/ast/FuncDeclAST.cc b/src/mem/slicc/ast/FuncDeclAST.cc new file mode 100644 index 000000000..9f9dd1f8e --- /dev/null +++ b/src/mem/slicc/ast/FuncDeclAST.cc @@ -0,0 +1,111 @@ + +/* + * Copyright (c) 1999-2008 Mark D. Hill and David A. Wood + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer; + * redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution; + * neither the name of the copyright holders nor the names of its + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +/* + * FuncDeclAST.C + * + * Description: See FuncDeclAST.h + * + * $Id: FuncDeclAST.C,v 3.4 2003/08/22 18:19:34 beckmann Exp $ + * + */ + +#include "FuncDeclAST.hh" +#include "SymbolTable.hh" +#include "main.hh" + +FuncDeclAST::FuncDeclAST(TypeAST* return_type_ast_ptr, + string* ident_ptr, + Vector<FormalParamAST*>* formal_vec_ptr, + PairListAST* pairs_ptr, + StatementListAST* statement_list_ptr) + : DeclAST(pairs_ptr) +{ + m_return_type_ast_ptr = return_type_ast_ptr; + m_ident_ptr = ident_ptr; + m_formal_vec_ptr = formal_vec_ptr; + m_statement_list_ptr = statement_list_ptr; +} + +FuncDeclAST::~FuncDeclAST() +{ + delete m_return_type_ast_ptr; + delete m_ident_ptr; + + int size = m_formal_vec_ptr->size(); + for(int i=0; i<size; i++) { + delete (*m_formal_vec_ptr)[i]; + } + delete m_formal_vec_ptr; + delete m_statement_list_ptr; +} + +void FuncDeclAST::generate() +{ + Vector<Type*> type_vec; + Vector<string> param_vec; + Type* void_type_ptr = g_sym_table.getType("void"); + + // Generate definition code + g_sym_table.pushFrame(); + + // Lookup return type + Type* return_type_ptr = m_return_type_ast_ptr->lookupType(); + + // Generate function header + int size = m_formal_vec_ptr->size(); + for(int i=0; i<size; i++) { + // Lookup parameter types + string ident; + Type* type_ptr = (*m_formal_vec_ptr)[i]->generate(ident); + type_vec.insertAtBottom(type_ptr); + param_vec.insertAtBottom(ident); + } + + string body; + if (m_statement_list_ptr == NULL) { + getPairs().add("external", "yes"); + } else { + m_statement_list_ptr->generate(body, return_type_ptr); + } + g_sym_table.popFrame(); + + StateMachine* machine_ptr = g_sym_table.getStateMachine(); + if (machine_ptr != NULL) { + machine_ptr->addFunc(new Func(*m_ident_ptr, getLocation(), return_type_ptr, type_vec, param_vec, body, getPairs(), machine_ptr)); + } else { + g_sym_table.newSym(new Func(*m_ident_ptr, getLocation(), return_type_ptr, type_vec, param_vec, body, getPairs(), machine_ptr)); + } + +} + +void FuncDeclAST::print(ostream& out) const +{ + out << "[FuncDecl: " << *m_ident_ptr << "]"; +} diff --git a/src/mem/slicc/ast/FuncDeclAST.hh b/src/mem/slicc/ast/FuncDeclAST.hh new file mode 100644 index 000000000..4096a8b66 --- /dev/null +++ b/src/mem/slicc/ast/FuncDeclAST.hh @@ -0,0 +1,90 @@ + +/* + * Copyright (c) 1999-2008 Mark D. Hill and David A. Wood + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer; + * redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution; + * neither the name of the copyright holders nor the names of its + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +/* + * FuncDeclAST.h + * + * Description: + * + * $Id: FuncDeclAST.h,v 3.2 2003/07/10 18:08:06 milo Exp $ + * + */ + +#ifndef FuncDeclAST_H +#define FuncDeclAST_H + +#include "slicc_global.hh" +#include "DeclAST.hh" +#include "TypeFieldAST.hh" +#include "TypeAST.hh" +#include "FormalParamAST.hh" + +class FuncDeclAST : public DeclAST { +public: + // Constructors + FuncDeclAST(TypeAST* return_type_ptr, + string* ident_ptr, + Vector<FormalParamAST*>* formal_vec_ptr, + PairListAST* pairs_ptr, + StatementListAST* statement_list_ptr); + // Destructor + ~FuncDeclAST(); + + // Public Methods + void generate(); + void print(ostream& out) const; +private: + // Private Methods + + // Private copy constructor and assignment operator + FuncDeclAST(const FuncDeclAST& obj); + FuncDeclAST& operator=(const FuncDeclAST& obj); + + // Data Members (m_ prefix) + string* m_ident_ptr; + TypeAST* m_return_type_ast_ptr; + Vector<FormalParamAST*>* m_formal_vec_ptr; + StatementListAST* m_statement_list_ptr; +}; + +// Output operator declaration +ostream& operator<<(ostream& out, const FuncDeclAST& obj); + +// ******************* Definitions ******************* + +// Output operator definition +extern inline +ostream& operator<<(ostream& out, const FuncDeclAST& obj) +{ + obj.print(out); + out << flush; + return out; +} + +#endif //FuncDeclAST_H diff --git a/src/mem/slicc/ast/IfStatementAST.cc b/src/mem/slicc/ast/IfStatementAST.cc new file mode 100644 index 000000000..372b213d8 --- /dev/null +++ b/src/mem/slicc/ast/IfStatementAST.cc @@ -0,0 +1,98 @@ + +/* + * Copyright (c) 1999-2008 Mark D. Hill and David A. Wood + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer; + * redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution; + * neither the name of the copyright holders nor the names of its + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +/* + * IfStatementAST.C + * + * Description: See IfStatementAST.h + * + * $Id$ + * + */ + +#include "IfStatementAST.hh" + +IfStatementAST::IfStatementAST(ExprAST* cond_ptr, + StatementListAST* then_ptr, + StatementListAST* else_ptr) + : StatementAST() +{ + assert(cond_ptr != NULL); + assert(then_ptr != NULL); + m_cond_ptr = cond_ptr; + m_then_ptr = then_ptr; + m_else_ptr = else_ptr; +} + +IfStatementAST::~IfStatementAST() +{ + delete m_cond_ptr; + delete m_then_ptr; + delete m_else_ptr; +} + + +void IfStatementAST::generate(string& code, Type* return_type_ptr) const +{ + Type* type_ptr; + + // Conditional + code += indent_str() + "if ("; + type_ptr = m_cond_ptr->generate(code); + if (type_ptr != g_sym_table.getType("bool")) { + m_cond_ptr->error("Condition of if statement must be boolean, type was '" + type_ptr->toString() + "'"); + } + code += ") {\n"; + // Then part + inc_indent(); + m_then_ptr->generate(code, return_type_ptr); + dec_indent(); + // Else part + if (m_else_ptr != NULL) { + code += indent_str() + "} else {\n"; + inc_indent(); + m_else_ptr->generate(code, return_type_ptr); + dec_indent(); + } + code += indent_str() + "}\n"; // End scope +} + +void IfStatementAST::findResources(Map<Var*, string>& resource_list) const +{ + // Take a worse case look at both paths + m_then_ptr->findResources(resource_list); + if (m_else_ptr != NULL) { + m_else_ptr->findResources(resource_list); + } +} + +void IfStatementAST::print(ostream& out) const +{ + out << "[IfStatement: " << *m_cond_ptr << *m_then_ptr << *m_else_ptr << "]"; +} diff --git a/src/mem/slicc/ast/IfStatementAST.hh b/src/mem/slicc/ast/IfStatementAST.hh new file mode 100644 index 000000000..bad7a286d --- /dev/null +++ b/src/mem/slicc/ast/IfStatementAST.hh @@ -0,0 +1,89 @@ + +/* + * Copyright (c) 1999-2008 Mark D. Hill and David A. Wood + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer; + * redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution; + * neither the name of the copyright holders nor the names of its + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +/* + * IfStatementAST.h + * + * Description: + * + * $Id$ + * + */ + +#ifndef IFSTATEMENTAST_H +#define IFSTATEMENTAST_H + +#include "slicc_global.hh" +#include "ExprAST.hh" +#include "StatementAST.hh" +#include "StatementListAST.hh" + + +class IfStatementAST : public StatementAST { +public: + // Constructors + IfStatementAST(ExprAST* cond_ptr, + StatementListAST* then_ptr, + StatementListAST* else_ptr); + + // Destructor + ~IfStatementAST(); + + // Public Methods + void generate(string& code, Type* return_type_ptr) const; + void findResources(Map<Var*, string>& resource_list) const; + void print(ostream& out) const; +private: + // Private Methods + + // Private copy constructor and assignment operator + IfStatementAST(const IfStatementAST& obj); + IfStatementAST& operator=(const IfStatementAST& obj); + + // Data Members (m_ prefix) + ExprAST* m_cond_ptr; + StatementListAST* m_then_ptr; + StatementListAST* m_else_ptr; +}; + +// Output operator declaration +ostream& operator<<(ostream& out, const IfStatementAST& obj); + +// ******************* Definitions ******************* + +// Output operator definition +extern inline +ostream& operator<<(ostream& out, const IfStatementAST& obj) +{ + obj.print(out); + out << flush; + return out; +} + +#endif //IFSTATEMENTAST_H diff --git a/src/mem/slicc/ast/InPortDeclAST.cc b/src/mem/slicc/ast/InPortDeclAST.cc new file mode 100644 index 000000000..6b13fec51 --- /dev/null +++ b/src/mem/slicc/ast/InPortDeclAST.cc @@ -0,0 +1,149 @@ + +/* + * Copyright (c) 1999-2008 Mark D. Hill and David A. Wood + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer; + * redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution; + * neither the name of the copyright holders nor the names of its + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +/* + * InPortDeclAST.C + * + * Description: See InPortDeclAST.h + * + * $Id$ + * + */ + +#include "InPortDeclAST.hh" +#include "SymbolTable.hh" +#include "Var.hh" + +InPortDeclAST::InPortDeclAST(string* ident_ptr, + TypeAST* msg_type_ptr, + ExprAST* var_expr_ptr, + PairListAST* pairs_ptr, + StatementListAST* statement_list_ptr) + : DeclAST(pairs_ptr) +{ + m_ident_ptr = ident_ptr; + m_msg_type_ptr = msg_type_ptr; + m_var_expr_ptr = var_expr_ptr; + m_statement_list_ptr = statement_list_ptr; + m_queue_type_ptr = new TypeAST(new string("InPort")); +} + +InPortDeclAST::~InPortDeclAST() +{ + delete m_ident_ptr; + delete m_msg_type_ptr; + delete m_var_expr_ptr; + delete m_statement_list_ptr; + delete m_queue_type_ptr; +} + +void InPortDeclAST::generate() +{ + string code; + Type* queue_type_ptr = m_var_expr_ptr->generate(code); + if (!queue_type_ptr->isInPort()) { + error("Inport queues must be of a type that has the 'inport' attribute. The type '" + + queue_type_ptr->toString() + "' does not have this attribute."); + } + + Type* type_ptr = m_queue_type_ptr->lookupType(); + Var* in_port_ptr = new Var(*m_ident_ptr, getLocation(), type_ptr, code, getPairs()); + g_sym_table.newSym(in_port_ptr); + + g_sym_table.pushFrame(); + Vector<Type*> param_type_vec; + + // Check for Event + type_ptr = g_sym_table.getType("Event"); + if (type_ptr == NULL) { + error("in_port declarations require 'Event' enumeration to be defined"); + } + param_type_vec.insertAtBottom(type_ptr); + + // Check for Address + type_ptr = g_sym_table.getType("Address"); + if (type_ptr == NULL) { + error("in_port declarations require 'Address' type to be defined"); + } + param_type_vec.insertAtBottom(type_ptr); + + // Add the trigger method - FIXME, this is a bit dirty + Map<string, string> pairs; + pairs.add("external", "yes"); + Vector<string> string_vec; + g_sym_table.newSym(new Func("trigger", getLocation(), g_sym_table.getType("void"), param_type_vec, string_vec, string(""), pairs, NULL)); + + // Check for Event2 + type_ptr = g_sym_table.getType("Event"); + if (type_ptr == NULL) { + error("in_port declarations require 'Event' enumeration to be defined"); + } + param_type_vec.insertAtBottom(type_ptr); + + // Check for Address2 + type_ptr = g_sym_table.getType("Address"); + if (type_ptr == NULL) { + error("in_port declarations require 'Address' type to be defined"); + } + param_type_vec.insertAtBottom(type_ptr); + + // Add the doubleTrigger method - this hack supports tiggering two simulateous events + // The key is that the second transistion cannot fail because the first event cannot be undone + // therefore you must do some checks before calling double trigger to ensure that won't happen + g_sym_table.newSym(new Func("doubleTrigger", getLocation(), g_sym_table.getType("void"), param_type_vec, string_vec, string(""), pairs, NULL)); + + // Add the continueProcessing method - this hack supports messages that don't trigger events + Vector<Type*> empty_param_type_vec; + Vector<string> empty_string_vec; + g_sym_table.newSym(new Func("continueProcessing", getLocation(), g_sym_table.getType("void"), empty_param_type_vec, empty_string_vec, string(""), pairs, NULL)); + + if (m_statement_list_ptr != NULL) { + inc_indent(); + inc_indent(); + string code; + m_statement_list_ptr->generate(code, NULL); + in_port_ptr->addPair("c_code_in_port", code); + dec_indent(); + dec_indent(); + } + g_sym_table.popFrame(); + + // Add port to state machine + StateMachine* machine_ptr = g_sym_table.getStateMachine(); + if (machine_ptr == NULL) { + error("InPort declaration not part of a machine."); + } + machine_ptr->addInPort(in_port_ptr); +} + + +void InPortDeclAST::print(ostream& out) const +{ + out << "[InPortDecl: " << *m_ident_ptr << "]"; +} diff --git a/src/mem/slicc/ast/InPortDeclAST.hh b/src/mem/slicc/ast/InPortDeclAST.hh new file mode 100644 index 000000000..4f3c25f93 --- /dev/null +++ b/src/mem/slicc/ast/InPortDeclAST.hh @@ -0,0 +1,91 @@ + +/* + * Copyright (c) 1999-2008 Mark D. Hill and David A. Wood + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer; + * redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution; + * neither the name of the copyright holders nor the names of its + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +/* + * InPortDeclAST.h + * + * Description: + * + * $Id: InPortDeclAST.h,v 3.2 2003/07/10 18:08:06 milo Exp $ + * + */ + +#ifndef InPortDeclAST_H +#define InPortDeclAST_H + +#include "slicc_global.hh" +#include "DeclAST.hh" +#include "StatementListAST.hh" +#include "VarExprAST.hh" + +class InPortDeclAST : public DeclAST { +public: + // Constructors + InPortDeclAST(string* ident_ptr, + TypeAST* msg_type_ptr, + ExprAST* var_expr_ptr, + PairListAST* pairs_ptr, + StatementListAST* statement_list_ptr); + + // Destructor + ~InPortDeclAST(); + + // Public Methods + void generate(); + void print(ostream& out) const; +private: + // Private Methods + + // Private copy constructor and assignment operator + InPortDeclAST(const InPortDeclAST& obj); + InPortDeclAST& operator=(const InPortDeclAST& obj); + + // Data Members (m_ prefix) + string* m_ident_ptr; + TypeAST* m_msg_type_ptr; + ExprAST* m_var_expr_ptr; + StatementListAST* m_statement_list_ptr; + TypeAST* m_queue_type_ptr; +}; + +// Output operator declaration +ostream& operator<<(ostream& out, const InPortDeclAST& obj); + +// ******************* Definitions ******************* + +// Output operator definition +extern inline +ostream& operator<<(ostream& out, const InPortDeclAST& obj) +{ + obj.print(out); + out << flush; + return out; +} + +#endif //InPortDeclAST_H diff --git a/src/mem/slicc/ast/InfixOperatorExprAST.cc b/src/mem/slicc/ast/InfixOperatorExprAST.cc new file mode 100644 index 000000000..ba3aa1245 --- /dev/null +++ b/src/mem/slicc/ast/InfixOperatorExprAST.cc @@ -0,0 +1,121 @@ + +/* + * Copyright (c) 1999-2008 Mark D. Hill and David A. Wood + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer; + * redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution; + * neither the name of the copyright holders nor the names of its + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +/* + * InfixOperatorExprAST.C + * + * Description: See InfixOperatorExprAST.h + * + * $Id: InfixOperatorExprAST.C,v 3.2 2004/01/31 20:46:15 milo Exp $ + * + */ + +#include "InfixOperatorExprAST.hh" + +InfixOperatorExprAST::InfixOperatorExprAST(ExprAST* left_ptr, + string* op_ptr, + ExprAST* right_ptr) + : ExprAST() +{ + m_left_ptr = left_ptr; + m_op_ptr = op_ptr; + m_right_ptr = right_ptr; +} + +InfixOperatorExprAST::~InfixOperatorExprAST() +{ + delete m_left_ptr; + delete m_op_ptr; + delete m_right_ptr; +} + +Type* InfixOperatorExprAST::generate(string& code) const +{ + code += "("; + Type* left_type_ptr = m_left_ptr->generate(code); + code += " " + *m_op_ptr + " "; + Type* right_type_ptr = m_right_ptr->generate(code); + code += ")"; + + string inputs, output; + // Figure out what the input and output types should be + if ((*m_op_ptr == "==" || + *m_op_ptr == "!=")) { + output = "bool"; + if (left_type_ptr != right_type_ptr) { + error("Type mismatch: left & right operand of operator '" + *m_op_ptr + + "' must be the same type." + + "left: '" + left_type_ptr->toString() + + "', right: '" + right_type_ptr->toString() + "'"); + } + } else { + if ((*m_op_ptr == "&&" || + *m_op_ptr == "||")) { + // boolean inputs and output + inputs = "bool"; + output = "bool"; + } else if ((*m_op_ptr == "==" || + *m_op_ptr == "!=" || + *m_op_ptr == ">=" || + *m_op_ptr == "<=" || + *m_op_ptr == ">" || + *m_op_ptr == "<")) { + // Integer inputs, boolean output + inputs = "int"; + output = "bool"; + } else { + // integer inputs and output + inputs = "int"; + output = "int"; + } + + Type* inputs_type = g_sym_table.getType(inputs); + + if (inputs_type != left_type_ptr) { + m_left_ptr->error("Type mismatch: left operand of operator '" + *m_op_ptr + + "' expects input type '" + inputs + "', actual was " + left_type_ptr->toString() + "'"); + } + + if (inputs_type != right_type_ptr) { + m_right_ptr->error("Type mismatch: right operand of operator '" + *m_op_ptr + + "' expects input type '" + inputs + "', actual was '" + right_type_ptr->toString() + "'"); + } + } + + // All is well + Type* output_type = g_sym_table.getType(output); + return output_type; +} + + +void InfixOperatorExprAST::print(ostream& out) const +{ + out << "[InfixExpr: " << *m_left_ptr + << *m_op_ptr << *m_right_ptr << "]"; +} diff --git a/src/mem/slicc/ast/InfixOperatorExprAST.hh b/src/mem/slicc/ast/InfixOperatorExprAST.hh new file mode 100644 index 000000000..451156f6d --- /dev/null +++ b/src/mem/slicc/ast/InfixOperatorExprAST.hh @@ -0,0 +1,85 @@ + +/* + * Copyright (c) 1999-2008 Mark D. Hill and David A. Wood + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer; + * redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution; + * neither the name of the copyright holders nor the names of its + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +/* + * InfixOperatorExprAST.h + * + * Description: + * + * $Id: InfixOperatorExprAST.h,v 3.1 2001/12/12 01:00:19 milo Exp $ + * + */ + +#ifndef INFIXOPERATOREXPRAST_H +#define INFIXOPERATOREXPRAST_H + +#include "slicc_global.hh" +#include "ExprAST.hh" + + +class InfixOperatorExprAST : public ExprAST { +public: + // Constructors + InfixOperatorExprAST(ExprAST* left_ptr, string* op_ptr, ExprAST* right_ptr); + + // Destructor + ~InfixOperatorExprAST(); + + // Public Methods + Type* generate(string& code) const; + void print(ostream& out) const; +private: + // Private Methods + + // Private copy constructor and assignment operator + InfixOperatorExprAST(const InfixOperatorExprAST& obj); + InfixOperatorExprAST& operator=(const InfixOperatorExprAST& obj); + + // Data Members (m_ prefix) + ExprAST* m_left_ptr; + string* m_op_ptr; + ExprAST* m_right_ptr; + +}; + +// Output operator declaration +ostream& operator<<(ostream& out, const InfixOperatorExprAST& obj); + +// ******************* Definitions ******************* + +// Output operator definition +extern inline +ostream& operator<<(ostream& out, const InfixOperatorExprAST& obj) +{ + obj.print(out); + out << flush; + return out; +} + +#endif //INFIXOPERATOREXPRAST_H diff --git a/src/mem/slicc/ast/LiteralExprAST.cc b/src/mem/slicc/ast/LiteralExprAST.cc new file mode 100644 index 000000000..b3b415bc9 --- /dev/null +++ b/src/mem/slicc/ast/LiteralExprAST.cc @@ -0,0 +1,55 @@ + +/* + * Copyright (c) 1999-2008 Mark D. Hill and David A. Wood + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer; + * redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution; + * neither the name of the copyright holders nor the names of its + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +/* + * LiteralExprAST.C + * + * Description: See LiteralExprAST.h + * + * $Id: LiteralExprAST.C,v 3.1 2002/10/22 21:27:52 milo Exp $ + * + */ + +#include "LiteralExprAST.hh" + +Type* LiteralExprAST::generate(string& code) const +{ + if (m_type == "string") { + code += "(\"" + *m_lit_ptr + "\")"; + } else { + code += "(" + *m_lit_ptr + ")"; + } + + Type* type_ptr = g_sym_table.getType(m_type); + if (type_ptr == NULL) { + // Can't find the type + error("Internal: can't primitive type '" + m_type + "'"); + } + return type_ptr; +} diff --git a/src/mem/slicc/ast/LiteralExprAST.hh b/src/mem/slicc/ast/LiteralExprAST.hh new file mode 100644 index 000000000..be433a1e3 --- /dev/null +++ b/src/mem/slicc/ast/LiteralExprAST.hh @@ -0,0 +1,83 @@ + +/* + * Copyright (c) 1999-2008 Mark D. Hill and David A. Wood + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer; + * redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution; + * neither the name of the copyright holders nor the names of its + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +/* + * LiteralExprAST.h + * + * Description: + * + * $Id: LiteralExprAST.h,v 3.1 2001/12/12 01:00:20 milo Exp $ + * + */ + +#ifndef LITERALEXPRAST_H +#define LITERALEXPRAST_H + +#include "slicc_global.hh" +#include "ExprAST.hh" + + +class LiteralExprAST : public ExprAST { +public: + // Constructors + LiteralExprAST(string* lit_ptr, string type) : ExprAST() { m_lit_ptr = lit_ptr; m_type = type; } + + // Destructor + ~LiteralExprAST() { delete m_lit_ptr; } + + // Public Methods + Type* generate(string& code) const; + void print(ostream& out) const { out << "[Literal: " << *m_lit_ptr << "]"; } +private: + // Private Methods + + // Private copy constructor and assignment operator + LiteralExprAST(const LiteralExprAST& obj); + LiteralExprAST& operator=(const LiteralExprAST& obj); + + // Data Members (m_ prefix) + string* m_lit_ptr; + string m_type; +}; + +// Output operator declaration +ostream& operator<<(ostream& out, const LiteralExprAST& obj); + +// ******************* Definitions ******************* + +// Output operator definition +extern inline +ostream& operator<<(ostream& out, const LiteralExprAST& obj) +{ + obj.print(out); + out << flush; + return out; +} + +#endif //LITERALEXPRAST_H diff --git a/src/mem/slicc/ast/Location.cc b/src/mem/slicc/ast/Location.cc new file mode 100644 index 000000000..91b8dbd28 --- /dev/null +++ b/src/mem/slicc/ast/Location.cc @@ -0,0 +1,83 @@ + +/* + * Copyright (c) 1999-2008 Mark D. Hill and David A. Wood + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer; + * redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution; + * neither the name of the copyright holders nor the names of its + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +/* + * Location.C + * + * Description: See Location.h + * + * $Id: Location.C,v 3.3 2004/05/30 22:19:02 kmoore Exp $ + * + */ + +#include "Location.hh" + +int g_line_number = 0; +string g_file_name(""); + +Location::Location() +{ + m_file_name = g_file_name; + m_line_number = g_line_number; + + ostringstream sstr; + sstr << getLineNumber(); + m_line_number_str = sstr.str(); +} + +void Location::error(string err_msg) const +{ + cerr << endl; + cerr << toString() << ": Error: " << err_msg << endl; + exit(1); +} + +string Location::embedError(string err_msg) const +{ + string code; + code += "cerr << \"Runtime Error at "; + code += toString() + ", Ruby Time: \" << "; + code += "g_eventQueue_ptr->getTime() << \": \" << "; + code += err_msg; + code += " << \", PID: \" << getpid() << endl;\n"; + code += "char c; cerr << \"press return to continue.\" << endl; cin.get(c); abort();\n"; + + return code; +} + +void Location::warning(string err_msg) const +{ + cerr << toString() << ": Warning: " + << err_msg << endl; +} + +string Location::toString() const +{ + return m_file_name + ":" + m_line_number_str; +} diff --git a/src/mem/slicc/ast/Location.hh b/src/mem/slicc/ast/Location.hh new file mode 100644 index 000000000..6cf2df5a4 --- /dev/null +++ b/src/mem/slicc/ast/Location.hh @@ -0,0 +1,93 @@ + +/* + * Copyright (c) 1999-2008 Mark D. Hill and David A. Wood + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer; + * redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution; + * neither the name of the copyright holders nor the names of its + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +/* + * Location.h + * + * Description: + * + * $Id: Location.h,v 3.1 2001/12/12 01:00:20 milo Exp $ + * + */ + +#ifndef LOCATION_H +#define LOCATION_H + +#include "slicc_global.hh" + +extern int g_line_number; +extern string g_file_name; + +class Location { +public: + // Constructors + Location(); + + // Destructor + //~Location(); + + // Public Methods + + void print(ostream& out) const; + void error(string err_msg) const; + string embedError(string err_msg) const; + void warning(string err_msg) const; + string toString() const; + +private: + // Private Methods + const string& getFileName() const { return m_file_name; } + int getLineNumber() const { return m_line_number; } + string getLineNumberStr() const { return m_line_number_str; } + + // Private copy constructor and assignment operator + //Location(const Location& obj); + //Location& operator=(const Location& obj); + + // Data Members (m_ prefix) + string m_file_name; + int m_line_number; + string m_line_number_str; +}; + +// Output operator declaration +ostream& operator<<(ostream& out, const Location& obj); + +// ******************* Definitions ******************* + +// Output operator definition +extern inline +ostream& operator<<(ostream& out, const Location& obj) +{ + obj.print(out); + out << flush; + return out; +} + +#endif //LOCATION_H diff --git a/src/mem/slicc/ast/MachineAST.cc b/src/mem/slicc/ast/MachineAST.cc new file mode 100644 index 000000000..3ee97bc38 --- /dev/null +++ b/src/mem/slicc/ast/MachineAST.cc @@ -0,0 +1,96 @@ + +/* + * Copyright (c) 1999-2008 Mark D. Hill and David A. Wood + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer; + * redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution; + * neither the name of the copyright holders nor the names of its + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +/* + * MachineAST.C + * + * Description: See MachineAST.h + * + * $Id: MachineAST.C,v 3.1 2003/03/17 01:54:25 xu Exp $ + * + */ + +#include "MachineAST.hh" +#include "SymbolTable.hh" + +MachineAST::MachineAST(string* ident_ptr, + PairListAST* pairs_ptr, + DeclListAST* decl_list_ptr) + + : DeclAST(pairs_ptr) +{ + m_ident_ptr = ident_ptr; + m_pairs_ptr = pairs_ptr; + m_decl_list_ptr = decl_list_ptr; +} + +MachineAST::~MachineAST() +{ + delete m_ident_ptr; + delete m_pairs_ptr; + delete m_decl_list_ptr; +} + +void MachineAST::generate() +{ + StateMachine* machine_ptr; + + // Make a new frame + g_sym_table.pushFrame(); + + // Create a new machine + machine_ptr = new StateMachine(*m_ident_ptr, getLocation(), getPairs()); + g_sym_table.newCurrentMachine(machine_ptr); + + // Generate code for all the internal decls + m_decl_list_ptr->generate(); + + // Build the transition table + machine_ptr->buildTable(); + + // Pop the frame + g_sym_table.popFrame(); +} + +void MachineAST::findMachines() +{ + // Add to MachineType enumeration + Type* type_ptr = g_sym_table.getType("MachineType"); + if (!type_ptr->enumAdd(*m_ident_ptr, m_pairs_ptr->getPairs())) { + error("Duplicate machine name: " + type_ptr->toString() + ":" + *m_ident_ptr); + } + + // Generate code for all the internal decls + m_decl_list_ptr->findMachines(); +} + +void MachineAST::print(ostream& out) const +{ + out << "[Machine: " << *m_ident_ptr << "]"; +} diff --git a/src/mem/slicc/ast/MachineAST.hh b/src/mem/slicc/ast/MachineAST.hh new file mode 100644 index 000000000..c05bcc5f2 --- /dev/null +++ b/src/mem/slicc/ast/MachineAST.hh @@ -0,0 +1,88 @@ + +/* + * Copyright (c) 1999-2008 Mark D. Hill and David A. Wood + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer; + * redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution; + * neither the name of the copyright holders nor the names of its + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +/* + * ActionDeclAST.h + * + * Description: + * + * $Id: MachineAST.h,v 3.2 2003/07/10 18:08:06 milo Exp $ + * + */ + +#ifndef MachineAST_H +#define MachineAST_H + +#include "slicc_global.hh" +#include "DeclAST.hh" +#include "DeclListAST.hh" +#include "StateMachine.hh" + +class MachineAST : public DeclAST { +public: + // Constructors + MachineAST(string* ident_ptr, + PairListAST* pairs_ptr, + DeclListAST* decl_list_ptr); + + // Destructor + ~MachineAST(); + + // Public Methods + void print(ostream& out) const; + void generate(); + void findMachines(); +private: + // Private Methods + + // Private copy constructor and assignment operator + MachineAST(const MachineAST& obj); + MachineAST& operator=(const MachineAST& obj); + + // Data Members (m_ prefix) + string* m_ident_ptr; + DeclListAST* m_decl_list_ptr; + PairListAST* m_pairs_ptr; +}; + +// Output operator declaration +ostream& operator<<(ostream& out, const MachineAST& obj); + +// ******************* Definitions ******************* + +// Output operator definition +extern inline +ostream& operator<<(ostream& out, const MachineAST& obj) +{ + obj.print(out); + out << flush; + return out; +} + +#endif //MachineAST_H diff --git a/src/mem/slicc/ast/MemberExprAST.cc b/src/mem/slicc/ast/MemberExprAST.cc new file mode 100644 index 000000000..c4e9ce24b --- /dev/null +++ b/src/mem/slicc/ast/MemberExprAST.cc @@ -0,0 +1,72 @@ + +/* + * Copyright (c) 1999-2008 Mark D. Hill and David A. Wood + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer; + * redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution; + * neither the name of the copyright holders nor the names of its + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +/* + * FieldExprAST.C + * + * Description: See FieldExprAST.h + * + * $Id$ + * + */ + +#include "MemberExprAST.hh" + +MemberExprAST::MemberExprAST(ExprAST* expr_ast_ptr, string* field_ptr) + : ExprAST() +{ + m_expr_ast_ptr = expr_ast_ptr; + m_field_ptr = field_ptr; +} + +MemberExprAST::~MemberExprAST() +{ + delete m_expr_ast_ptr; + delete m_field_ptr; +} + +Type* MemberExprAST::generate(string& code) const +{ + code += "("; + Type* type_ptr = m_expr_ast_ptr->generate(code); + code += ").m_" + (*m_field_ptr); + + // Verify that this is a valid field name for this type + if (!type_ptr->dataMemberExist(*m_field_ptr)) { + error("Invalid object field: Type '" + type_ptr->toString() + "' does not have data member " + *m_field_ptr); + } + + // Return the type of the field + return type_ptr->dataMemberType(*m_field_ptr); +} + +void MemberExprAST::print(ostream& out) const +{ + out << "[MemberExprAST: " << *m_expr_ast_ptr << "." << *m_field_ptr << "]"; +} diff --git a/src/mem/slicc/ast/MemberExprAST.hh b/src/mem/slicc/ast/MemberExprAST.hh new file mode 100644 index 000000000..c5fd3d0dd --- /dev/null +++ b/src/mem/slicc/ast/MemberExprAST.hh @@ -0,0 +1,83 @@ + +/* + * Copyright (c) 1999-2008 Mark D. Hill and David A. Wood + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer; + * redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution; + * neither the name of the copyright holders nor the names of its + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +/* + * MemberExprAST.h + * + * Description: + * + * $Id: MemberExprAST.h,v 3.1 2001/12/12 01:00:21 milo Exp $ + * + */ + +#ifndef MemberExprAST_H +#define MemberExprAST_H + +#include "slicc_global.hh" +#include "ExprAST.hh" + + +class MemberExprAST : public ExprAST { +public: + // Constructors + MemberExprAST(ExprAST* expr_ast_ptr, string* field_ptr); + + // Destructor + ~MemberExprAST(); + + // Public Methods + Type* generate(string& code) const; + void print(ostream& out) const; +private: + // Private Methods + + // Private copy constructor and assignment operator + MemberExprAST(const MemberExprAST& obj); + MemberExprAST& operator=(const MemberExprAST& obj); + + // Data Members (m_ prefix) + ExprAST* m_expr_ast_ptr; + string* m_field_ptr; +}; + +// Output operator declaration +ostream& operator<<(ostream& out, const MemberExprAST& obj); + +// ******************* Definitions ******************* + +// Output operator definition +extern inline +ostream& operator<<(ostream& out, const MemberExprAST& obj) +{ + obj.print(out); + out << flush; + return out; +} + +#endif //MemberExprAST_H diff --git a/src/mem/slicc/ast/MethodCallExprAST.cc b/src/mem/slicc/ast/MethodCallExprAST.cc new file mode 100644 index 000000000..fe6505a1a --- /dev/null +++ b/src/mem/slicc/ast/MethodCallExprAST.cc @@ -0,0 +1,150 @@ + +/* + * Copyright (c) 1999-2008 Mark D. Hill and David A. Wood + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer; + * redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution; + * neither the name of the copyright holders nor the names of its + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +/* + * MethodCallExprAST.C + * + * Description: See MethodCallExprAST.h + * + * $Id$ + * + */ + +#include "MethodCallExprAST.hh" + +MethodCallExprAST::MethodCallExprAST(ExprAST* obj_expr_ptr, + string* proc_name_ptr, + Vector<ExprAST*>* expr_vec_ptr) + : ExprAST() +{ + m_obj_expr_ptr = obj_expr_ptr; + m_type_ptr = NULL; + m_proc_name_ptr = proc_name_ptr; + m_expr_vec_ptr = expr_vec_ptr; +} + +MethodCallExprAST::MethodCallExprAST(TypeAST* type_ptr, + string* proc_name_ptr, + Vector<ExprAST*>* expr_vec_ptr) + : ExprAST() +{ + m_obj_expr_ptr = NULL; + m_type_ptr = type_ptr; + m_proc_name_ptr = proc_name_ptr; + m_expr_vec_ptr = expr_vec_ptr; +} + +MethodCallExprAST::~MethodCallExprAST() +{ + delete m_obj_expr_ptr; + delete m_type_ptr; + delete m_proc_name_ptr; + int size = m_expr_vec_ptr->size(); + for(int i=0; i<size; i++) { + delete (*m_expr_vec_ptr)[i]; + } + delete m_expr_vec_ptr; +} + +Type* MethodCallExprAST::generate(string& code) const +{ + Type* obj_type_ptr = NULL; + + if(m_obj_expr_ptr) { + // member method call + code += "(("; + obj_type_ptr = m_obj_expr_ptr->generate(code); + + code += ")."; + } else if (m_type_ptr) { + // class method call + code += "(" + m_type_ptr->toString() + "::"; + obj_type_ptr = m_type_ptr->lookupType(); + } else { + // impossible + assert(0); + } + + Vector <Type*> paramTypes; + + // generate code + int actual_size = m_expr_vec_ptr->size(); + code += (*m_proc_name_ptr) + "("; + for(int i=0; i<actual_size; i++) { + if (i != 0) { + code += ", "; + } + // Check the types of the parameter + Type* actual_type_ptr = (*m_expr_vec_ptr)[i]->generate(code); + paramTypes.insertAtBottom(actual_type_ptr); + } + code += "))"; + + string methodId = obj_type_ptr->methodId(*m_proc_name_ptr, paramTypes); + + // Verify that this is a method of the object + if (!obj_type_ptr->methodExist(methodId)) { + error("Invalid method call: Type '" + obj_type_ptr->toString() + "' does not have a method '" + methodId + "'"); + } + + int expected_size = obj_type_ptr->methodParamType(methodId).size(); + if (actual_size != expected_size) { + // Right number of parameters + ostringstream err; + err << "Wrong number of parameters for function name: '" << *m_proc_name_ptr << "'"; + err << ", expected: "; + err << expected_size; + err << ", actual: "; + err << actual_size; + error(err.str()); + } + + for(int i=0; i<actual_size; i++) { + // Check the types of the parameter + Type* actual_type_ptr = paramTypes[i]; + Type* expected_type_ptr = obj_type_ptr->methodParamType(methodId)[i]; + if (actual_type_ptr != expected_type_ptr) { + (*m_expr_vec_ptr)[i]->error("Type mismatch: expected: " + expected_type_ptr->toString() + + " actual: " + actual_type_ptr->toString()); + } + } + + // Return the return type of the method + return obj_type_ptr->methodReturnType(methodId); +} + +void MethodCallExprAST::findResources(Map<Var*, string>& resource_list) const +{ + +} + +void MethodCallExprAST::print(ostream& out) const +{ + out << "[MethodCallExpr: " << *m_proc_name_ptr << *m_obj_expr_ptr << " " << *m_expr_vec_ptr << "]"; +} diff --git a/src/mem/slicc/ast/MethodCallExprAST.hh b/src/mem/slicc/ast/MethodCallExprAST.hh new file mode 100644 index 000000000..22766e922 --- /dev/null +++ b/src/mem/slicc/ast/MethodCallExprAST.hh @@ -0,0 +1,93 @@ + +/* + * Copyright (c) 1999-2008 Mark D. Hill and David A. Wood + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer; + * redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution; + * neither the name of the copyright holders nor the names of its + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +/* + * MethodCallExprAST.h + * + * Description: + * + * $Id$ + * + */ + +#ifndef MethodCallExprAST_H +#define MethodCallExprAST_H + +#include "slicc_global.hh" +#include "StatementAST.hh" +#include "ExprAST.hh" +#include "TypeAST.hh" + +class MethodCallExprAST : public ExprAST { +public: + // Constructors + MethodCallExprAST(ExprAST* m_obj_expr_ptr, + string* proc_name_ptr, + Vector<ExprAST*>* expr_vec_ptr); + + MethodCallExprAST(TypeAST* type_ptr, + string* proc_name_ptr, + Vector<ExprAST*>* expr_vec_ptr); + + // Destructor + ~MethodCallExprAST(); + + // Public Methods + Type* generate(string& code) const; + void findResources(Map<Var*, string>& resource_list) const; + void print(ostream& out) const; +private: + // Private Methods + + // Private copy constructor and assignment operator + MethodCallExprAST(const MethodCallExprAST& obj); + MethodCallExprAST& operator=(const MethodCallExprAST& obj); + + // Data Members (m_ prefix) + ExprAST* m_obj_expr_ptr; + TypeAST* m_type_ptr; + string* m_proc_name_ptr; + Vector<ExprAST*>* m_expr_vec_ptr; +}; + +// Output operator declaration +ostream& operator<<(ostream& out, const MethodCallExprAST& obj); + +// ******************* Definitions ******************* + +// Output operator definition +extern inline +ostream& operator<<(ostream& out, const MethodCallExprAST& obj) +{ + obj.print(out); + out << flush; + return out; +} + +#endif // MethodCallExprAST_H diff --git a/src/mem/slicc/ast/ObjDeclAST.cc b/src/mem/slicc/ast/ObjDeclAST.cc new file mode 100644 index 000000000..106c18cac --- /dev/null +++ b/src/mem/slicc/ast/ObjDeclAST.cc @@ -0,0 +1,148 @@ + +/* + * Copyright (c) 1999-2008 Mark D. Hill and David A. Wood + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer; + * redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution; + * neither the name of the copyright holders nor the names of its + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +/* + * ObjDeclAST.C + * + * Description: See ObjDeclAST.h + * + * $Id: ObjDeclAST.C,v 3.13 2004/06/24 15:56:14 beckmann Exp $ + * + */ + +#include "ObjDeclAST.hh" +#include "SymbolTable.hh" +#include "main.hh" + +ObjDeclAST::ObjDeclAST(TypeAST* type_ptr, + string* ident_ptr, + PairListAST* pairs_ptr) + : DeclAST(pairs_ptr) +{ + m_type_ptr = type_ptr; + m_ident_ptr = ident_ptr; +} + +ObjDeclAST::~ObjDeclAST() +{ + delete m_type_ptr; + delete m_ident_ptr; +} + +void ObjDeclAST::generate() +{ + + bool machineComponentSym = false; + + getPairs().add("chip_object", "yes"); + + string c_code; + + + if (getPairs().exist("hack")) { + warning("'hack=' is now deprecated"); + } + + if (getPairs().exist("network")) { + if (!getPairs().exist("virtual_network")) { + error("Network queues require a 'virtual_network' attribute."); + } + } + + Type* type_ptr = m_type_ptr->lookupType(); + if (type_ptr->isBuffer()) { + if (!getPairs().exist("ordered")) { + error("Buffer object declarations require an 'ordered' attribute."); + } + } + + if (getPairs().exist("ordered")) { + string value = getPairs().lookup("ordered"); + if (value != "true" && value != "false") { + error("The 'ordered' attribute must be 'true' or 'false'."); + } + } + + if (getPairs().exist("random")) { + string value = getPairs().lookup("random"); + if (value != "true" && value != "false") { + error("The 'random' attribute must be 'true' or 'false'."); + } + } + + string machine; + if (g_sym_table.getStateMachine() != NULL) { + machine = g_sym_table.getStateMachine()->getIdent() + "_"; + } + + // FIXME : should all use accessors here to avoid public member variables + if (*m_ident_ptr == "id") { + c_code = "m_chip_ptr->getID()"; + } else if (*m_ident_ptr == "version") { + c_code = "m_version"; + } else if (*m_ident_ptr == "machineID") { + c_code = "m_machineID"; + } else if (*m_ident_ptr == "sequencer") { + c_code = "*(dynamic_cast<"+m_type_ptr->toString()+"*>(m_chip_ptr->getSequencer(m_version)))"; + machineComponentSym = true; + } /*else if (*m_ident_ptr == "xfdr_record_mgr") { + c_code = "*(dynamic_cast<"+m_type_ptr->toString()+"*>(m_chip_ptr->getXfdrManager(m_version)))"; + machineComponentSym = true; + } */else if (// getPairs().exist("network") || (m_type_ptr->lookupType()->existPair("cache")) +// || (m_type_ptr->lookupType()->existPair("tbe")) || +// (m_type_ptr->lookupType()->existPair("newtbe")) || +// (m_type_ptr->lookupType()->existPair("timer")) || +// (m_type_ptr->lookupType()->existPair("dir")) || +// (m_type_ptr->lookupType()->existPair("persistent")) || +// (m_type_ptr->lookupType()->existPair("filter")) || +// (getPairs().exist("trigger_queue")) + getPairs().exist("no_vector")) { + c_code = "(*(m_chip_ptr->m_" + machine + *m_ident_ptr + "_ptr))"; + machineComponentSym = true; + } else { + c_code = "(*(m_chip_ptr->m_" + machine + *m_ident_ptr + "_vec[m_version]))"; + machineComponentSym = true; + } + + Var* v = new Var(*m_ident_ptr, getLocation(), type_ptr, c_code, + getPairs(), g_sym_table.getStateMachine()); + + g_sym_table.newSym(v); + + // used to cheat-- that is, access components in other machines + if (machineComponentSym) { + g_sym_table.newMachComponentSym(v); + } + +} + +void ObjDeclAST::print(ostream& out) const +{ + out << "[ObjDecl: " << *m_ident_ptr << "]"; +} diff --git a/src/mem/slicc/ast/ObjDeclAST.hh b/src/mem/slicc/ast/ObjDeclAST.hh new file mode 100644 index 000000000..2d4ac9714 --- /dev/null +++ b/src/mem/slicc/ast/ObjDeclAST.hh @@ -0,0 +1,86 @@ + +/* + * Copyright (c) 1999-2008 Mark D. Hill and David A. Wood + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer; + * redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution; + * neither the name of the copyright holders nor the names of its + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +/* + * ObjDeclAST.h + * + * Description: + * + * $Id: ObjDeclAST.h,v 3.2 2003/07/10 18:08:06 milo Exp $ + * + */ + +#ifndef ObjDeclAST_H +#define ObjDeclAST_H + +#include "slicc_global.hh" +#include "DeclAST.hh" +#include "TypeFieldAST.hh" +#include "TypeAST.hh" + +class ObjDeclAST : public DeclAST { +public: + // Constructors + ObjDeclAST(TypeAST* type_ptr, + string* ident_ptr, + PairListAST* pairs_ptr); + + // Destructor + ~ObjDeclAST(); + + // Public Methods + void generate(); + void print(ostream& out) const; +private: + // Private Methods + + // Private copy constructor and assignment operator + ObjDeclAST(const ObjDeclAST& obj); + ObjDeclAST& operator=(const ObjDeclAST& obj); + + // Data Members (m_ prefix) + string* m_ident_ptr; + TypeAST* m_type_ptr; +}; + +// Output operator declaration +ostream& operator<<(ostream& out, const ObjDeclAST& obj); + +// ******************* Definitions ******************* + +// Output operator definition +extern inline +ostream& operator<<(ostream& out, const ObjDeclAST& obj) +{ + obj.print(out); + out << flush; + return out; +} + +#endif //ObjDeclAST_H diff --git a/src/mem/slicc/ast/OutPortDeclAST.cc b/src/mem/slicc/ast/OutPortDeclAST.cc new file mode 100644 index 000000000..1aa0363aa --- /dev/null +++ b/src/mem/slicc/ast/OutPortDeclAST.cc @@ -0,0 +1,79 @@ + +/* + * Copyright (c) 1999-2008 Mark D. Hill and David A. Wood + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer; + * redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution; + * neither the name of the copyright holders nor the names of its + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +/* + * OutPortDeclAST.C + * + * Description: See OutPortDeclAST.h + * + * $Id: OutPortDeclAST.C,v 3.3 2004/02/02 22:37:51 milo Exp $ + * + */ + +#include "OutPortDeclAST.hh" +#include "SymbolTable.hh" + +OutPortDeclAST::OutPortDeclAST(string* ident_ptr, + TypeAST* msg_type_ptr, + ExprAST* var_expr_ptr, + PairListAST* pairs_ptr) + : DeclAST(pairs_ptr) +{ + m_ident_ptr = ident_ptr; + m_msg_type_ptr = msg_type_ptr; + m_var_expr_ptr = var_expr_ptr; + m_queue_type_ptr = new TypeAST(new string("OutPort")); +} + +OutPortDeclAST::~OutPortDeclAST() +{ + delete m_ident_ptr; + delete m_msg_type_ptr; + delete m_var_expr_ptr; + delete m_queue_type_ptr; +} + +void OutPortDeclAST::generate() +{ + string code; + Type* queue_type_ptr = m_var_expr_ptr->generate(code); + if (!queue_type_ptr->isOutPort()) { + error("Outport queues must be of a type that has the 'outport' attribute. The type '" + + queue_type_ptr->toString() + "' does not have this attribute."); + } + + Type* type_ptr = m_queue_type_ptr->lookupType(); + g_sym_table.newSym(new Var(*m_ident_ptr, getLocation(), type_ptr, code, getPairs())); +} + + +void OutPortDeclAST::print(ostream& out) const +{ + out << "[OutPortDecl: " << *m_ident_ptr << "]"; +} diff --git a/src/mem/slicc/ast/OutPortDeclAST.hh b/src/mem/slicc/ast/OutPortDeclAST.hh new file mode 100644 index 000000000..3fcd755ef --- /dev/null +++ b/src/mem/slicc/ast/OutPortDeclAST.hh @@ -0,0 +1,89 @@ + +/* + * Copyright (c) 1999-2008 Mark D. Hill and David A. Wood + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer; + * redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution; + * neither the name of the copyright holders nor the names of its + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +/* + * OutPortDeclAST.h + * + * Description: + * + * $Id: OutPortDeclAST.h,v 3.2 2003/07/10 18:08:06 milo Exp $ + * + */ + +#ifndef OutPortDeclAST_H +#define OutPortDeclAST_H + +#include "slicc_global.hh" +#include "DeclAST.hh" +#include "StatementListAST.hh" +#include "VarExprAST.hh" + +class OutPortDeclAST : public DeclAST { +public: + // Constructors + OutPortDeclAST(string* ident_ptr, + TypeAST* msg_type_ptr, + ExprAST* var_expr_ptr, + PairListAST* pairs_ptr); + + // Destructor + ~OutPortDeclAST(); + + // Public Methods + void generate(); + void print(ostream& out) const; +private: + // Private Methods + + // Private copy constructor and assignment operator + OutPortDeclAST(const OutPortDeclAST& obj); + OutPortDeclAST& operator=(const OutPortDeclAST& obj); + + // Data Members (m_ prefix) + string* m_ident_ptr; + TypeAST* m_msg_type_ptr; + TypeAST* m_queue_type_ptr; + ExprAST* m_var_expr_ptr; +}; + +// Output operator declaration +ostream& operator<<(ostream& out, const OutPortDeclAST& obj); + +// ******************* Definitions ******************* + +// Output operator definition +extern inline +ostream& operator<<(ostream& out, const OutPortDeclAST& obj) +{ + obj.print(out); + out << flush; + return out; +} + +#endif //OutPortDeclAST_H diff --git a/src/mem/slicc/ast/PairAST.cc b/src/mem/slicc/ast/PairAST.cc new file mode 100644 index 000000000..da71bdd01 --- /dev/null +++ b/src/mem/slicc/ast/PairAST.cc @@ -0,0 +1,72 @@ + +/* + * Copyright (c) 1999-2008 Mark D. Hill and David A. Wood + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer; + * redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution; + * neither the name of the copyright holders nor the names of its + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +/* + * PairAST.C + * + * Description: See PairAST.h + * + * $Id$ + * + */ + +#include "PairAST.hh" + +PairAST::PairAST(string* key_ptr, string* value_ptr) + : AST() +{ + m_key_ptr = key_ptr; + m_value_ptr = value_ptr; +} + +PairAST::PairAST(string key, string* value_ptr) + : AST() +{ + m_key_ptr = new string(key); + m_value_ptr = value_ptr; +} + +PairAST::PairAST(string key, string value) + : AST() +{ + m_key_ptr = new string(key); + m_value_ptr = new string(value); +} + +PairAST::~PairAST() +{ + delete m_key_ptr; + delete m_value_ptr; +} + +void PairAST::print(ostream& out) const +{ + out << "[" << *m_key_ptr << "=" << *m_value_ptr << "]" << endl; +} + diff --git a/src/mem/slicc/ast/PairAST.hh b/src/mem/slicc/ast/PairAST.hh new file mode 100644 index 000000000..4cc297dc1 --- /dev/null +++ b/src/mem/slicc/ast/PairAST.hh @@ -0,0 +1,86 @@ + +/* + * Copyright (c) 1999-2008 Mark D. Hill and David A. Wood + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer; + * redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution; + * neither the name of the copyright holders nor the names of its + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +/* + * PairAST.h + * + * Description: + * + * $Id: PairAST.h,v 3.1 2001/12/12 01:00:24 milo Exp $ + * + */ + +#ifndef PAIRAST_H +#define PAIRAST_H + +#include "slicc_global.hh" +#include "AST.hh" + +class PairAST : public AST { +public: + // Constructors + PairAST(string* key_ptr, string* value_ptr); + PairAST(string key, string* value_ptr); + PairAST(string key, string value); + + // Destructor + ~PairAST(); + + // Public Methods + string key() const { return *m_key_ptr; } + string value() const { return *m_value_ptr; } + + virtual void print(ostream& out) const; +private: + // Private Methods + + // Private copy constructor and assignment operator + // PairAST(const PairAST& obj); + // PairAST& operator=(const PairAST& obj); + + // Data Members (m_ prefix) + string* m_key_ptr; + string* m_value_ptr; +}; + +// Output operator declaration +ostream& operator<<(ostream& out, const PairAST& obj); + +// ******************* Definitions ******************* + +// Output operator definition +extern inline +ostream& operator<<(ostream& out, const PairAST& obj) +{ + obj.print(out); + out << flush; + return out; +} + +#endif //PAIRAST_H diff --git a/src/mem/slicc/ast/PairListAST.cc b/src/mem/slicc/ast/PairListAST.cc new file mode 100644 index 000000000..9af8b3898 --- /dev/null +++ b/src/mem/slicc/ast/PairListAST.cc @@ -0,0 +1,49 @@ + +/* + * Copyright (c) 1999-2008 Mark D. Hill and David A. Wood + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer; + * redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution; + * neither the name of the copyright holders nor the names of its + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +/* + * PairListAST.C + * + * Description: See PairListAST.h + * + * $Id$ + * + */ + +#include "PairListAST.hh" + +void PairListAST::addPair(PairAST* pair_ptr) +{ + getPairs().add(pair_ptr->key(), pair_ptr->value()); +} + +void PairListAST::print(ostream& out) const +{ + out << "[PairListAST] " << getPairs(); +} diff --git a/src/mem/slicc/ast/PairListAST.hh b/src/mem/slicc/ast/PairListAST.hh new file mode 100644 index 000000000..9d2700277 --- /dev/null +++ b/src/mem/slicc/ast/PairListAST.hh @@ -0,0 +1,82 @@ + +/* + * Copyright (c) 1999-2008 Mark D. Hill and David A. Wood + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer; + * redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution; + * neither the name of the copyright holders nor the names of its + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +/* + * PairListAST.h + * + * Description: + * + * $Id$ + * + */ + +#ifndef PairListAST_H +#define PairListAST_H + +#include "slicc_global.hh" +#include "AST.hh" +#include "PairAST.hh" + + +class PairListAST : public AST { +public: + // Constructors + PairListAST() : AST() {} + + // Destructor + //~PairListAST(); + + // Public Methods + void addPair(PairAST* pair_ptr); + void print(ostream& out) const; +private: + // Private Methods + + // Private copy constructor and assignment operator + PairListAST(const PairListAST& obj); + PairListAST& operator=(const PairListAST& obj); + + // Data Members (m_ prefix) +}; + +// Output operator declaration +ostream& operator<<(ostream& out, const PairListAST& obj); + +// ******************* Definitions ******************* + +// Output operator definition +extern inline +ostream& operator<<(ostream& out, const PairListAST& obj) +{ + obj.print(out); + out << flush; + return out; +} + +#endif //PairListAST_H diff --git a/src/mem/slicc/ast/PeekStatementAST.cc b/src/mem/slicc/ast/PeekStatementAST.cc new file mode 100644 index 000000000..627e85ae8 --- /dev/null +++ b/src/mem/slicc/ast/PeekStatementAST.cc @@ -0,0 +1,115 @@ + +/* + * Copyright (c) 1999-2008 Mark D. Hill and David A. Wood + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer; + * redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution; + * neither the name of the copyright holders nor the names of its + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +/* + * PeekStatementAST.C + * + * Description: See PeekStatementAST.h + * + * $Id$ + * + */ + +#include "PeekStatementAST.hh" +#include "SymbolTable.hh" +#include "StatementListAST.hh" +#include "TypeAST.hh" +#include "VarExprAST.hh" + +PeekStatementAST::PeekStatementAST(VarExprAST* queue_name_ptr, + TypeAST* type_ptr, + StatementListAST* statementlist_ptr, + string method) + : StatementAST() +{ + m_queue_name_ptr = queue_name_ptr; + m_type_ptr = type_ptr; + m_statementlist_ptr = statementlist_ptr; + m_method = method; +} + +PeekStatementAST::~PeekStatementAST() +{ + delete m_queue_name_ptr; + delete m_type_ptr; + delete m_statementlist_ptr; +} + +void PeekStatementAST::generate(string& code, Type* return_type_ptr) const +{ + code += indent_str() + "{\n"; // Start scope + inc_indent(); + g_sym_table.pushFrame(); + + Type* msg_type_ptr = m_type_ptr->lookupType(); + + // Add new local var to symbol table + g_sym_table.newSym(new Var("in_msg", getLocation(), msg_type_ptr, "(*in_msg_ptr)", getPairs())); + + // Check the queue type + m_queue_name_ptr->assertType("InPort"); + + // Declare the new "in_msg_ptr" variable + code += indent_str() + "const " + msg_type_ptr->cIdent() + "* in_msg_ptr;\n"; // Declare message + // code += indent_str() + "in_msg_ptr = static_cast<const "; + code += indent_str() + "in_msg_ptr = dynamic_cast<const "; + code += msg_type_ptr->cIdent() + "*>("; + code += "(" + m_queue_name_ptr->getVar()->getCode() + ")"; + code += "."; + code += m_method; + code += "());\n"; + + code += indent_str() + "assert(in_msg_ptr != NULL);\n"; // Check the cast result + + if(CHECK_INVALID_RESOURCE_STALLS) { + // Declare the "in_buffer_rank" variable + code += indent_str() + "int in_buffer_rank = "; // Declare message + code += "(" + m_queue_name_ptr->getVar()->getCode() + ")"; + code += ".getPriority();\n"; + } + + m_statementlist_ptr->generate(code, return_type_ptr); // The other statements + dec_indent(); + g_sym_table.popFrame(); + code += indent_str() + "}\n"; // End scope +} + +void PeekStatementAST::findResources(Map<Var*, string>& resource_list) const +{ + m_statementlist_ptr->findResources(resource_list); +} + +void PeekStatementAST::print(ostream& out) const +{ + out << "[PeekStatementAST: " << m_method + << " queue_name: " << *m_queue_name_ptr + << " type: " << m_type_ptr->toString() + << " " << *m_statementlist_ptr + << "]"; +} diff --git a/src/mem/slicc/ast/PeekStatementAST.hh b/src/mem/slicc/ast/PeekStatementAST.hh new file mode 100644 index 000000000..e51a0a6a4 --- /dev/null +++ b/src/mem/slicc/ast/PeekStatementAST.hh @@ -0,0 +1,91 @@ + +/* + * Copyright (c) 1999-2008 Mark D. Hill and David A. Wood + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer; + * redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution; + * neither the name of the copyright holders nor the names of its + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +/* + * PeekStatementAST.h + * + * Description: + * + * $Id$ + * + */ + +#ifndef PEEKSTATEMENTAST_H +#define PEEKSTATEMENTAST_H + +#include "slicc_global.hh" +#include "StatementAST.hh" + +class StatementListAST; +class TypeAST; +class VarExprAST; + +class PeekStatementAST : public StatementAST { +public: + // Constructors + PeekStatementAST(VarExprAST* queue_name_ptr, + TypeAST* type_ptr, + StatementListAST* statementlist_ptr, + string method); + // Destructor + ~PeekStatementAST(); + + // Public Methods + void generate(string& code, Type* return_type_ptr) const; + void findResources(Map<Var*, string>& resource_list) const; + void print(ostream& out) const; +private: + // Private Methods + + // Private copy constructor and assignment operator + PeekStatementAST(const PeekStatementAST& obj); + PeekStatementAST& operator=(const PeekStatementAST& obj); + + // Data Members (m_ prefix) + VarExprAST* m_queue_name_ptr; + TypeAST* m_type_ptr; + StatementListAST* m_statementlist_ptr; + string m_method; +}; + +// Output operator declaration +ostream& operator<<(ostream& out, const PeekStatementAST& obj); + +// ******************* Definitions ******************* + +// Output operator definition +extern inline +ostream& operator<<(ostream& out, const PeekStatementAST& obj) +{ + obj.print(out); + out << flush; + return out; +} + +#endif //PEEKSTATEMENTAST_H diff --git a/src/mem/slicc/ast/ReturnStatementAST.cc b/src/mem/slicc/ast/ReturnStatementAST.cc new file mode 100644 index 000000000..68e81b834 --- /dev/null +++ b/src/mem/slicc/ast/ReturnStatementAST.cc @@ -0,0 +1,79 @@ + +/* + * Copyright (c) 1999-2008 Mark D. Hill and David A. Wood + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer; + * redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution; + * neither the name of the copyright holders nor the names of its + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +/* + * ReturnStatementAST.C + * + * Description: See ReturnStatementAST.h + * + * $Id$ + * + */ + +#include "ReturnStatementAST.hh" + +ReturnStatementAST::ReturnStatementAST(ExprAST* expr_ptr) + : StatementAST() +{ + m_expr_ptr = expr_ptr; +} + +ReturnStatementAST::~ReturnStatementAST() +{ + delete m_expr_ptr; +} + +void ReturnStatementAST::generate(string& code, Type* return_type_ptr) const +{ + code += indent_str(); + code += "return "; + Type* actual_type_ptr = m_expr_ptr->generate(code); + code += ";\n"; + + // Is return valid here? + if (return_type_ptr == NULL) { + error("Invalid 'return' statement"); + } + + // The return type must match the return_type_ptr + if (return_type_ptr != actual_type_ptr) { + m_expr_ptr->error("Return type miss-match, expected return type is '" + return_type_ptr->toString() + + "', actual is '" + actual_type_ptr->toString() + "'"); + } +} + +void ReturnStatementAST::findResources(Map<Var*, string>& resource_list) const +{ + m_expr_ptr->findResources(resource_list); +} + +void ReturnStatementAST::print(ostream& out) const +{ + out << "[ReturnStatementAST: " << *m_expr_ptr << "]"; +} diff --git a/src/mem/slicc/ast/ReturnStatementAST.hh b/src/mem/slicc/ast/ReturnStatementAST.hh new file mode 100644 index 000000000..f8c4812cf --- /dev/null +++ b/src/mem/slicc/ast/ReturnStatementAST.hh @@ -0,0 +1,83 @@ + +/* + * Copyright (c) 1999-2008 Mark D. Hill and David A. Wood + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer; + * redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution; + * neither the name of the copyright holders nor the names of its + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +/* + * ReturnStatementAST.h + * + * Description: + * + * $Id$ + * + */ + +#ifndef ReturnStatementAST_H +#define ReturnStatementAST_H + +#include "slicc_global.hh" +#include "StatementAST.hh" +#include "ExprAST.hh" + +class ReturnStatementAST : public StatementAST { +public: + // Constructors + ReturnStatementAST(ExprAST* expr_ptr); + + // Destructor + ~ReturnStatementAST(); + + // Public Methods + void generate(string& code, Type* return_type_ptr) const; + void findResources(Map<Var*, string>& resource_list) const; + void print(ostream& out) const; +private: + // Private Methods + + // Private copy constructor and assignment operator + ReturnStatementAST(const ReturnStatementAST& obj); + ReturnStatementAST& operator=(const ReturnStatementAST& obj); + + // Data Members (m_ prefix) + ExprAST* m_expr_ptr; +}; + +// Output operator declaration +ostream& operator<<(ostream& out, const ReturnStatementAST& obj); + +// ******************* Definitions ******************* + +// Output operator definition +extern inline +ostream& operator<<(ostream& out, const ReturnStatementAST& obj) +{ + obj.print(out); + out << flush; + return out; +} + +#endif //ReturnStatementAST_H diff --git a/src/mem/slicc/ast/StatementAST.cc b/src/mem/slicc/ast/StatementAST.cc new file mode 100644 index 000000000..1f3c02474 --- /dev/null +++ b/src/mem/slicc/ast/StatementAST.cc @@ -0,0 +1,60 @@ + +/* + * Copyright (c) 1999-2008 Mark D. Hill and David A. Wood + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer; + * redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution; + * neither the name of the copyright holders nor the names of its + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +/* + * StatementAST.C + * + * Description: See StatementAST.h + * + * $Id$ + * + */ + +#include "StatementAST.hh" + +static int indentation_depth = 1; + +void inc_indent() +{ + indentation_depth++; +} + +void dec_indent() +{ + indentation_depth--; +} + +string indent_str() +{ + string temp; + for(int i=0; i<indentation_depth; i++) { + temp += " "; + } + return temp; +} diff --git a/src/mem/slicc/ast/StatementAST.hh b/src/mem/slicc/ast/StatementAST.hh new file mode 100644 index 000000000..16a1ecafe --- /dev/null +++ b/src/mem/slicc/ast/StatementAST.hh @@ -0,0 +1,88 @@ + +/* + * Copyright (c) 1999-2008 Mark D. Hill and David A. Wood + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer; + * redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution; + * neither the name of the copyright holders nor the names of its + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +/* + * StatementAST.h + * + * Description: + * + * $Id$ + * + */ + +#ifndef STATEMENTAST_H +#define STATEMENTAST_H + +#include "slicc_global.hh" +#include "AST.hh" + +void inc_indent(); +void dec_indent(); +string indent_str(); + +class StatementAST : public AST { +public: + // Constructors + StatementAST() : AST() {} + StatementAST(Map<string, string> pairs) : AST(pairs) {} + + // Destructor + //~StatementAST(); + + // Public Methods + virtual void generate(string& code, Type* return_type_ptr) const = 0; + virtual void findResources(Map<Var*, string>& resource_list) const { } + + //void print(ostream& out) const; +private: + // Private Methods + + // Private copy constructor and assignment operator + //StatementAST(const StatementAST& obj); + //StatementAST& operator=(const StatementAST& obj); + + // Data Members (m_ prefix) + +}; + +// Output operator declaration +ostream& operator<<(ostream& out, const StatementAST& obj); + +// ******************* Definitions ******************* + +// Output operator definition +extern inline +ostream& operator<<(ostream& out, const StatementAST& obj) +{ + obj.print(out); + out << flush; + return out; +} + +#endif //STATEMENTAST_H diff --git a/src/mem/slicc/ast/StatementListAST.cc b/src/mem/slicc/ast/StatementListAST.cc new file mode 100644 index 000000000..f70d5b1fa --- /dev/null +++ b/src/mem/slicc/ast/StatementListAST.cc @@ -0,0 +1,86 @@ + +/* + * Copyright (c) 1999-2008 Mark D. Hill and David A. Wood + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer; + * redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution; + * neither the name of the copyright holders nor the names of its + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +/* + * StatementListAST.C + * + * Description: See StatementListAST.h + * + * $Id$ + * + */ + +#include "StatementListAST.hh" + +StatementListAST::StatementListAST(Vector<StatementAST*>* vec_ptr) + : AST() +{ + assert(vec_ptr != NULL); + m_vec_ptr = vec_ptr; +} + +// Singleton constructor. +StatementListAST::StatementListAST(StatementAST* statement_ptr) + : AST() +{ + assert(statement_ptr != NULL); + m_vec_ptr = new Vector<StatementAST*>; + m_vec_ptr->insertAtTop(statement_ptr); +} + +StatementListAST::~StatementListAST() +{ + int size = m_vec_ptr->size(); + for(int i=0; i<size; i++) { + delete (*m_vec_ptr)[i]; + } + delete m_vec_ptr; +} + +void StatementListAST::generate(string& code, Type* return_type_ptr) const +{ + int size = m_vec_ptr->size(); + for(int i=0; i<size; i++) { + (*m_vec_ptr)[i]->generate(code, return_type_ptr); + } +} + +void StatementListAST::findResources(Map<Var*, string>& resource_list) const +{ + int size = m_vec_ptr->size(); + for(int i=0; i<size; i++) { + (*m_vec_ptr)[i]->findResources(resource_list); + } +} + +void StatementListAST::print(ostream& out) const +{ + assert(m_vec_ptr != NULL); + out << "[StatementListAST: " << *m_vec_ptr << "]"; +} diff --git a/src/mem/slicc/ast/StatementListAST.hh b/src/mem/slicc/ast/StatementListAST.hh new file mode 100644 index 000000000..3b3968211 --- /dev/null +++ b/src/mem/slicc/ast/StatementListAST.hh @@ -0,0 +1,85 @@ + +/* + * Copyright (c) 1999-2008 Mark D. Hill and David A. Wood + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer; + * redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution; + * neither the name of the copyright holders nor the names of its + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +/* + * StatementListAST.h + * + * Description: + * + * $Id$ + * + */ + +#ifndef STATEMENTLISTAST_H +#define STATEMENTLISTAST_H + +#include "slicc_global.hh" +#include "AST.hh" +#include "StatementAST.hh" +class Var; + +class StatementListAST : public AST { +public: + // Constructors + StatementListAST(Vector<StatementAST*>* vec_ptr); + StatementListAST(StatementAST* statement_ptr); + + // Destructor + ~StatementListAST(); + + // Public Methods + void generate(string& code, Type* return_type_ptr) const; + void findResources(Map<Var*, string>& resource_list) const; + void print(ostream& out) const; +private: + // Private Methods + + // Private copy constructor and assignment operator + StatementListAST(const StatementListAST& obj); + StatementListAST& operator=(const StatementListAST& obj); + + // Data Members (m_ prefix) + Vector<StatementAST*>* m_vec_ptr; +}; + +// Output operator declaration +ostream& operator<<(ostream& out, const StatementListAST& obj); + +// ******************* Definitions ******************* + +// Output operator definition +extern inline +ostream& operator<<(ostream& out, const StatementListAST& obj) +{ + obj.print(out); + out << flush; + return out; +} + +#endif //STATEMENTLISTAST_H diff --git a/src/mem/slicc/ast/TransitionDeclAST.cc b/src/mem/slicc/ast/TransitionDeclAST.cc new file mode 100644 index 000000000..83361e233 --- /dev/null +++ b/src/mem/slicc/ast/TransitionDeclAST.cc @@ -0,0 +1,89 @@ + +/* + * Copyright (c) 1999-2008 Mark D. Hill and David A. Wood + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer; + * redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution; + * neither the name of the copyright holders nor the names of its + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +/* + * TransitionDeclAST.C + * + * Description: See TransitionDeclAST.h + * + * $Id$ + * + */ + +#include "TransitionDeclAST.hh" +#include "Transition.hh" + +TransitionDeclAST::TransitionDeclAST(Vector<string>* state_list_ptr, + Vector<string>* event_list_ptr, + string* next_state_ptr, + PairListAST* pairs_ptr, + Vector<string>* action_list_ptr) + : DeclAST(pairs_ptr) +{ + m_state_list_ptr = state_list_ptr; + m_event_list_ptr = event_list_ptr; + m_next_state_ptr = next_state_ptr; + m_action_list_ptr = action_list_ptr; +} + +TransitionDeclAST::~TransitionDeclAST() +{ + delete m_state_list_ptr; + delete m_event_list_ptr; + delete m_next_state_ptr; + delete m_action_list_ptr; +} + +void TransitionDeclAST::generate() +{ + Vector<string>& states = *m_state_list_ptr; + Vector<string>& events = *m_event_list_ptr; + + StateMachine* machine_ptr = g_sym_table.getStateMachine(); + if (machine_ptr == NULL) { + error("Transition declaration not part of a machine."); + } else if (m_next_state_ptr == NULL) { + for (int i=0; i<states.size(); i++) { + for (int j=0; j<events.size(); j++) { + machine_ptr->addTransition(new Transition(states[i], events[j], states[i], *m_action_list_ptr, getLocation(), getPairs())); + } + } + } else { + for (int i=0; i<states.size(); i++) { + for (int j=0; j<events.size(); j++) { + machine_ptr->addTransition(new Transition(states[i], events[j], *m_next_state_ptr, *m_action_list_ptr, getLocation(), getPairs())); + } + } + } +} + +void TransitionDeclAST::print(ostream& out) const +{ + out << "[TransitionDecl: ]"; +} diff --git a/src/mem/slicc/ast/TransitionDeclAST.hh b/src/mem/slicc/ast/TransitionDeclAST.hh new file mode 100644 index 000000000..10ca067d3 --- /dev/null +++ b/src/mem/slicc/ast/TransitionDeclAST.hh @@ -0,0 +1,89 @@ + +/* + * Copyright (c) 1999-2008 Mark D. Hill and David A. Wood + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer; + * redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution; + * neither the name of the copyright holders nor the names of its + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +/* + * TransistionDeclAST.h + * + * Description: + * + * $Id: TransitionDeclAST.h,v 3.2 2003/07/10 18:08:07 milo Exp $ + * + */ + +#ifndef TransitionDeclAST_H +#define TransitionDeclAST_H + +#include "slicc_global.hh" +#include "DeclAST.hh" +#include "StatementListAST.hh" + +class TransitionDeclAST : public DeclAST { +public: + // Constructors + TransitionDeclAST(Vector<string>* state_list_ptr, + Vector<string>* event_list_ptr, + string* next_state_ptr, + PairListAST* pairs_ptr, + Vector<string>* action_list_ptr); + + // Destructor + ~TransitionDeclAST(); + + // Public Methods + void generate(); + void print(ostream& out) const; +private: + // Private Methods + + // Private copy constructor and assignment operator + TransitionDeclAST(const TransitionDeclAST& obj); + TransitionDeclAST& operator=(const TransitionDeclAST& obj); + + // Data Members (m_ prefix) + Vector<string>* m_state_list_ptr; + Vector<string>* m_event_list_ptr; + string* m_next_state_ptr; + Vector<string>* m_action_list_ptr; +}; + +// Output operator declaration +ostream& operator<<(ostream& out, const TransitionDeclAST& obj); + +// ******************* Definitions ******************* + +// Output operator definition +extern inline +ostream& operator<<(ostream& out, const TransitionDeclAST& obj) +{ + obj.print(out); + out << flush; + return out; +} + +#endif //TransitionDeclAST_H diff --git a/src/mem/slicc/ast/TypeAST.cc b/src/mem/slicc/ast/TypeAST.cc new file mode 100644 index 000000000..82364732b --- /dev/null +++ b/src/mem/slicc/ast/TypeAST.cc @@ -0,0 +1,67 @@ + +/* + * Copyright (c) 1999-2008 Mark D. Hill and David A. Wood + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer; + * redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution; + * neither the name of the copyright holders nor the names of its + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +/* + * TypeAST.C + * + * Description: See TypeAST.h + * + * $Id: TypeAST.C,v 3.1 2003/03/22 15:15:16 xu Exp $ + * + */ + +#include "TypeAST.hh" + +TypeAST::TypeAST(string* ident_ptr) + : AST() +{ + m_ident_ptr = ident_ptr; +} + +TypeAST::~TypeAST() +{ + delete m_ident_ptr; + +} + +string TypeAST::toString() const +{ + return *m_ident_ptr; +} + +Type* TypeAST::lookupType() const +{ + Type* type_ptr = g_sym_table.getType(*m_ident_ptr); + if (type_ptr != NULL) { + return type_ptr; + } else { + error("Type '" + *m_ident_ptr + "' not declared."); + } + return NULL; // Not reached +} diff --git a/src/mem/slicc/ast/TypeAST.hh b/src/mem/slicc/ast/TypeAST.hh new file mode 100644 index 000000000..a0fea56c3 --- /dev/null +++ b/src/mem/slicc/ast/TypeAST.hh @@ -0,0 +1,83 @@ + +/* + * Copyright (c) 1999-2008 Mark D. Hill and David A. Wood + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer; + * redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution; + * neither the name of the copyright holders nor the names of its + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +/* + * TypeAST.h + * + * Description: + * + * $Id: TypeAST.h,v 3.2 2003/03/22 15:15:17 xu Exp $ + * + */ + +#ifndef TYPEAST_H +#define TYPEAST_H + +#include "slicc_global.hh" +#include "AST.hh" + +class TypeAST : public AST { +public: + // Constructors + TypeAST(string* ident_ptr); + + // Destructor + ~TypeAST(); + + // Public Methods + string toString() const; + Type* lookupType() const; + + virtual void print(ostream& out) const {} +private: + // Private Methods + + // Private copy constructor and assignment operator + TypeAST(const TypeAST& obj); + TypeAST& operator=(const TypeAST& obj); + + // Data Members (m_ prefix) + string* m_ident_ptr; +}; + +// Output operator declaration +ostream& operator<<(ostream& out, const TypeAST& obj); + +// ******************* Definitions ******************* + +// Output operator definition +extern inline +ostream& operator<<(ostream& out, const TypeAST& obj) +{ + obj.print(out); + out << flush; + return out; +} + +#endif //TYPEAST_H diff --git a/src/mem/slicc/ast/TypeDeclAST.cc b/src/mem/slicc/ast/TypeDeclAST.cc new file mode 100644 index 000000000..5d2b19bac --- /dev/null +++ b/src/mem/slicc/ast/TypeDeclAST.cc @@ -0,0 +1,86 @@ + +/* + * Copyright (c) 1999-2008 Mark D. Hill and David A. Wood + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer; + * redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution; + * neither the name of the copyright holders nor the names of its + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +/* + * TypeDeclAST.C + * + * Description: See TypeDeclAST.h + * + * $Id: TypeDeclAST.C,v 3.1 2003/03/22 15:15:17 xu Exp $ + * + */ + +#include "TypeDeclAST.hh" +#include "main.hh" +#include "SymbolTable.hh" + +TypeDeclAST::TypeDeclAST(TypeAST* type_ast_ptr, + PairListAST* pairs_ptr, + Vector<TypeFieldAST*>* field_vec_ptr) + : DeclAST(pairs_ptr) +{ + m_type_ast_ptr = type_ast_ptr; + m_field_vec_ptr = field_vec_ptr; +} + +TypeDeclAST::~TypeDeclAST() +{ + delete m_type_ast_ptr; + if (m_field_vec_ptr != NULL) { + int size = m_field_vec_ptr->size(); + for(int i=0; i<size; i++) { + delete (*m_field_vec_ptr)[i]; + } + delete m_field_vec_ptr; + } +} + +void TypeDeclAST::generate() +{ + string machine_name; + string id = m_type_ast_ptr->toString(); + + // Make the new type + Type* new_type_ptr = new Type(id, getLocation(), getPairs(), + g_sym_table.getStateMachine()); + g_sym_table.newSym(new_type_ptr); + + // Add all of the fields of the type to it + if (m_field_vec_ptr != NULL) { + int size = m_field_vec_ptr->size(); + for(int i=0; i<size; i++) { + (*m_field_vec_ptr)[i]->generate(new_type_ptr); + } + } +} + +void TypeDeclAST::print(ostream& out) const +{ + out << "[TypeDecl: " << m_type_ast_ptr->toString() << "]"; +} diff --git a/src/mem/slicc/ast/TypeDeclAST.hh b/src/mem/slicc/ast/TypeDeclAST.hh new file mode 100644 index 000000000..1928c1bde --- /dev/null +++ b/src/mem/slicc/ast/TypeDeclAST.hh @@ -0,0 +1,86 @@ + +/* + * Copyright (c) 1999-2008 Mark D. Hill and David A. Wood + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer; + * redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution; + * neither the name of the copyright holders nor the names of its + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +/* + * TypeDeclAST.h + * + * Description: + * + * $Id: TypeDeclAST.h,v 3.2 2003/03/17 01:55:28 xu Exp $ + * + */ + +#ifndef TypeDeclAST_H +#define TypeDeclAST_H + +#include "slicc_global.hh" +#include "DeclAST.hh" +#include "TypeAST.hh" +#include "TypeFieldAST.hh" + +class TypeDeclAST : public DeclAST { +public: + // Constructors + TypeDeclAST(TypeAST* type_ast_ptr, + PairListAST* pairs_ptr, + Vector<TypeFieldAST*>* field_vec_ptr); + + // Destructor + ~TypeDeclAST(); + + // Public Methods + virtual void generate(); + void print(ostream& out) const; +private: + // Private Methods + + // Private copy constructor and assignment operator + TypeDeclAST(const TypeDeclAST& obj); + TypeDeclAST& operator=(const TypeDeclAST& obj); + + // Data Members (m_ prefix) + TypeAST* m_type_ast_ptr; + Vector<TypeFieldAST*>* m_field_vec_ptr; +}; + +// Output operator declaration +ostream& operator<<(ostream& out, const TypeDeclAST& obj); + +// ******************* Definitions ******************* + +// Output operator definition +extern inline +ostream& operator<<(ostream& out, const TypeDeclAST& obj) +{ + obj.print(out); + out << flush; + return out; +} + +#endif //TypeDeclAST_H diff --git a/src/mem/slicc/ast/TypeFieldAST.cc b/src/mem/slicc/ast/TypeFieldAST.cc new file mode 100644 index 000000000..9dfe45397 --- /dev/null +++ b/src/mem/slicc/ast/TypeFieldAST.cc @@ -0,0 +1,44 @@ + +/* + * Copyright (c) 1999-2008 Mark D. Hill and David A. Wood + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer; + * redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution; + * neither the name of the copyright holders nor the names of its + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +/* + * TypeFieldAST.C + * + * Description: See TypeFieldAST.h + * + * $Id$ + * + */ + +#include "TypeFieldAST.hh" + +TypeFieldAST::TypeFieldAST(PairListAST* pairs_ptr) + : AST(pairs_ptr->getPairs()) { +} + diff --git a/src/mem/slicc/ast/TypeFieldAST.hh b/src/mem/slicc/ast/TypeFieldAST.hh new file mode 100644 index 000000000..69d6d8b87 --- /dev/null +++ b/src/mem/slicc/ast/TypeFieldAST.hh @@ -0,0 +1,83 @@ + +/* + * Copyright (c) 1999-2008 Mark D. Hill and David A. Wood + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer; + * redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution; + * neither the name of the copyright holders nor the names of its + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +/* + * TypeFieldAST.h + * + * Description: + * + * $Id$ + * + */ + +#ifndef TypeFieldAST_H +#define TypeFieldAST_H + +#include "slicc_global.hh" +#include "StateMachine.hh" +#include "StatementListAST.hh" +#include "PairListAST.hh" +#include "ExprAST.hh" + +class TypeFieldAST : public AST { +public: + // Constructors + TypeFieldAST(PairListAST* pairs_ptr); + + // Destructor + virtual ~TypeFieldAST() {} + + // Public Methods + virtual void generate(Type *type_ptr) = 0; + virtual void print(ostream& out) const = 0; +private: + // Private Methods + + // Private copy constructor and assignment operator + // TypeFieldAST(const TypeFieldAST& obj); + // TypeFieldAST& operator=(const TypeFieldAST& obj); + + // Data Members (m_ prefix) +}; + +// Output operator declaration +ostream& operator<<(ostream& out, const TypeFieldAST& obj); + +// ******************* Definitions ******************* + +// Output operator definition +extern inline +ostream& operator<<(ostream& out, const TypeFieldAST& obj) +{ + obj.print(out); + out << flush; + return out; +} + +#endif //TypeFieldAST_H diff --git a/src/mem/slicc/ast/TypeFieldEnumAST.cc b/src/mem/slicc/ast/TypeFieldEnumAST.cc new file mode 100644 index 000000000..dbb27c3ae --- /dev/null +++ b/src/mem/slicc/ast/TypeFieldEnumAST.cc @@ -0,0 +1,82 @@ + +/* + * Copyright (c) 1999-2008 Mark D. Hill and David A. Wood + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer; + * redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution; + * neither the name of the copyright holders nor the names of its + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +/* + * TypeFieldEnumAST.C + * + * Description: See TypeFieldEnumAST.h + * + * $Id$ + * + */ + +#include "TypeFieldEnumAST.hh" +#include "State.hh" +#include "Event.hh" + +TypeFieldEnumAST::TypeFieldEnumAST(string* field_id_ptr, + PairListAST* pairs_ptr) + : TypeFieldAST(pairs_ptr) +{ + m_field_id_ptr = field_id_ptr; + m_pairs_ptr = pairs_ptr; +} + +TypeFieldEnumAST::~TypeFieldEnumAST() +{ + delete m_field_id_ptr; +} + +void TypeFieldEnumAST::generate(Type *type_ptr) +{ + // Add enumeration + if (!type_ptr->enumAdd(*m_field_id_ptr, m_pairs_ptr->getPairs())) { + error("Duplicate enumeration: " + type_ptr->toString() + ":" + *m_field_id_ptr); + } + + // Fill machine info + StateMachine* machine_ptr = g_sym_table.getStateMachine(); + if (type_ptr->toString() == "State") { + if (machine_ptr == NULL) { + error("State declaration not part of a machine."); + } + machine_ptr->addState(new State(*m_field_id_ptr, getLocation(), getPairs())); + } + if (type_ptr->toString() == "Event") { + if (machine_ptr == NULL) { + error("Event declaration not part of a machine."); + } + machine_ptr->addEvent(new Event(*m_field_id_ptr, getLocation(), getPairs())); + } +} + +void TypeFieldEnumAST::print(ostream& out) const +{ + out << "[TypeFieldEnum: " << *m_field_id_ptr << "]"; +} diff --git a/src/mem/slicc/ast/TypeFieldEnumAST.hh b/src/mem/slicc/ast/TypeFieldEnumAST.hh new file mode 100644 index 000000000..f9c111762 --- /dev/null +++ b/src/mem/slicc/ast/TypeFieldEnumAST.hh @@ -0,0 +1,86 @@ + +/* + * Copyright (c) 1999-2008 Mark D. Hill and David A. Wood + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer; + * redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution; + * neither the name of the copyright holders nor the names of its + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +/* + * TypeFieldEnumAST.h + * + * Description: + * + * $Id: TypeFieldEnumAST.h,v 3.2 2003/07/10 18:08:07 milo Exp $ + * + */ + +#ifndef TypeFieldEnumAST_H +#define TypeFieldEnumAST_H + +#include "slicc_global.hh" +#include "StateMachine.hh" +#include "TypeFieldAST.hh" +#include "StatementListAST.hh" +#include "PairListAST.hh" + +class TypeFieldEnumAST : public TypeFieldAST { +public: + // Constructors + TypeFieldEnumAST(string* field_id_ptr, + PairListAST* pairs_ptr); + + // Destructor + ~TypeFieldEnumAST(); + + // Public Methods + void generate(Type *type_ptr); + void print(ostream& out) const; +private: + // Private Methods + + // Private copy constructor and assignment operator + TypeFieldEnumAST(const TypeFieldEnumAST& obj); + TypeFieldEnumAST& operator=(const TypeFieldEnumAST& obj); + + // Data Members (m_ prefix) + string* m_field_id_ptr; + PairListAST* m_pairs_ptr; +}; + +// Output operator declaration +ostream& operator<<(ostream& out, const TypeFieldEnumAST& obj); + +// ******************* Definitions ******************* + +// Output operator definition +extern inline +ostream& operator<<(ostream& out, const TypeFieldEnumAST& obj) +{ + obj.print(out); + out << flush; + return out; +} + +#endif //TypeFieldEnumAST_H diff --git a/src/mem/slicc/ast/TypeFieldMemberAST.cc b/src/mem/slicc/ast/TypeFieldMemberAST.cc new file mode 100644 index 000000000..40109851b --- /dev/null +++ b/src/mem/slicc/ast/TypeFieldMemberAST.cc @@ -0,0 +1,84 @@ + +/* + * Copyright (c) 1999-2008 Mark D. Hill and David A. Wood + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer; + * redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution; + * neither the name of the copyright holders nor the names of its + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +/* + * TypeFieldMemberAST.C + * + * Description: See TypeFieldMemberAST.h + * + * $Id: TypeFieldMemberAST.C,v 3.1 2003/03/27 22:58:54 xu Exp $ + * + */ + +#include "TypeFieldMemberAST.hh" + +TypeFieldMemberAST::TypeFieldMemberAST(TypeAST* type_ast_ptr, + string* field_id_ptr, + PairListAST* pairs_ptr, + ExprAST* rvalue_ptr) + : TypeFieldAST(pairs_ptr) +{ + m_type_ast_ptr = type_ast_ptr; + m_field_id_ptr = field_id_ptr; + m_rvalue_ptr = rvalue_ptr; +} + +TypeFieldMemberAST::~TypeFieldMemberAST() +{ + delete m_type_ast_ptr; + delete m_field_id_ptr; + if(m_rvalue_ptr) delete m_rvalue_ptr; +} + +void TypeFieldMemberAST::generate(Type *type_ptr) +{ + // Lookup type + Type* field_type_ptr = m_type_ast_ptr->lookupType(); + + // check type if this is a initialization + string* init_code = NULL; + if(m_rvalue_ptr) { + init_code = new string(); + Type* rvalue_type_ptr = m_rvalue_ptr->generate(*init_code); + if(field_type_ptr != rvalue_type_ptr) { + error("Initialization type mismatch '" + field_type_ptr->toString() + "' and '" + rvalue_type_ptr->toString() + "'"); + } + } + + // Add data member to the parent type + if (!type_ptr->dataMemberAdd(*m_field_id_ptr, field_type_ptr, getPairs(), + init_code)) { + error("Duplicate data member: " + type_ptr->toString() + ":" + *m_field_id_ptr); + } +} + +void TypeFieldMemberAST::print(ostream& out) const +{ + out << "[TypeFieldMember: " << *m_field_id_ptr << "]"; +} diff --git a/src/mem/slicc/ast/TypeFieldMemberAST.hh b/src/mem/slicc/ast/TypeFieldMemberAST.hh new file mode 100644 index 000000000..5e275bb96 --- /dev/null +++ b/src/mem/slicc/ast/TypeFieldMemberAST.hh @@ -0,0 +1,91 @@ + +/* + * Copyright (c) 1999-2008 Mark D. Hill and David A. Wood + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer; + * redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution; + * neither the name of the copyright holders nor the names of its + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +/* + * TypeFieldMemberAST.h + * + * Description: + * + * $Id$ + * + */ + +#ifndef TypeFieldMemberAST_H +#define TypeFieldMemberAST_H + +#include "slicc_global.hh" +#include "TypeFieldAST.hh" +#include "StateMachine.hh" +#include "StatementListAST.hh" +#include "PairListAST.hh" +#include "ExprAST.hh" +#include "TypeAST.hh" + +class TypeFieldMemberAST : public TypeFieldAST { +public: + // Constructors + TypeFieldMemberAST(TypeAST* type_ast_ptr, + string* field_id_ptr, + PairListAST* pairs_ptr, + ExprAST* rvalue_ptr); + + // Destructor + ~TypeFieldMemberAST(); + + // Public Methods + void generate(Type *type_ptr); + void print(ostream& out) const; +private: + // Private Methods + + // Private copy constructor and assignment operator + TypeFieldMemberAST(const TypeFieldMemberAST& obj); + TypeFieldMemberAST& operator=(const TypeFieldMemberAST& obj); + + // Data Members (m_ prefix) + TypeAST* m_type_ast_ptr; + string* m_field_id_ptr; + ExprAST* m_rvalue_ptr; +}; + +// Output operator declaration +ostream& operator<<(ostream& out, const TypeFieldMemberAST& obj); + +// ******************* Definitions ******************* + +// Output operator definition +extern inline +ostream& operator<<(ostream& out, const TypeFieldMemberAST& obj) +{ + obj.print(out); + out << flush; + return out; +} + +#endif //TypeFieldMemberAST_H diff --git a/src/mem/slicc/ast/TypeFieldMethodAST.cc b/src/mem/slicc/ast/TypeFieldMethodAST.cc new file mode 100644 index 000000000..5229d4a08 --- /dev/null +++ b/src/mem/slicc/ast/TypeFieldMethodAST.cc @@ -0,0 +1,81 @@ + +/* + * Copyright (c) 1999-2008 Mark D. Hill and David A. Wood + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer; + * redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution; + * neither the name of the copyright holders nor the names of its + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +/* + * TypeFieldMethodAST.C + * + * Description: See TypeFieldMethodAST.h + * + * $Id: TypeFieldMethodAST.C,v 3.1 2003/07/10 18:08:07 milo Exp $ + * + */ + +#include "TypeFieldMethodAST.hh" + +TypeFieldMethodAST::TypeFieldMethodAST(TypeAST* return_type_ast_ptr, + string* ident_ptr, + Vector<TypeAST*>* type_ast_vec_ptr, + PairListAST* pairs_ptr) + : TypeFieldAST(pairs_ptr) +{ + m_return_type_ast_ptr = return_type_ast_ptr; + m_ident_ptr = ident_ptr; + m_type_ast_vec_ptr = type_ast_vec_ptr; +} + +TypeFieldMethodAST::~TypeFieldMethodAST() +{ + delete m_return_type_ast_ptr; + delete m_ident_ptr; + + int size = m_type_ast_vec_ptr->size(); + for(int i=0; i<size; i++) { + delete (*m_type_ast_vec_ptr)[i]; + } + delete m_type_ast_vec_ptr; +} + +void TypeFieldMethodAST::generate(Type *type_ptr) +{ + // Lookup return type + Type* return_type_ptr = m_return_type_ast_ptr->lookupType(); + + // Lookup parameter types + Vector<Type*> type_vec; + int size = m_type_ast_vec_ptr->size(); + for(int i=0; i<size; i++) { + Type* type_ptr = (*m_type_ast_vec_ptr)[i]->lookupType(); + type_vec.insertAtBottom(type_ptr); + } + + // Add method + if (!type_ptr->methodAdd(*m_ident_ptr, return_type_ptr, type_vec)) { // Return false on error + error("Duplicate method: " + type_ptr->toString() + ":" + *m_ident_ptr + "()"); + } +} diff --git a/src/mem/slicc/ast/TypeFieldMethodAST.hh b/src/mem/slicc/ast/TypeFieldMethodAST.hh new file mode 100644 index 000000000..a276cc5f8 --- /dev/null +++ b/src/mem/slicc/ast/TypeFieldMethodAST.hh @@ -0,0 +1,87 @@ + +/* + * Copyright (c) 1999-2008 Mark D. Hill and David A. Wood + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer; + * redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution; + * neither the name of the copyright holders nor the names of its + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +/* + * TypeFieldMethodAST.h + * + * Description: + * + * $Id: TypeFieldMethodAST.h,v 3.2 2003/07/10 18:08:07 milo Exp $ + * + */ + +#ifndef TYPEFIELDMETHODAST_H +#define TYPEFIELDMETHODAST_H + +#include "slicc_global.hh" +#include "TypeFieldAST.hh" +#include "TypeAST.hh" + +class TypeFieldMethodAST : public TypeFieldAST { +public: + // Constructors + TypeFieldMethodAST(TypeAST* return_type_ast_ptr, + string* ident_ptr, + Vector<TypeAST*>* type_ast_vec_ptr, + PairListAST* pairs_ptr); + // Destructor + ~TypeFieldMethodAST(); + + // Public Methods + + void generate(Type *type_ptr); + void print(ostream& out) const {} +private: + // Private Methods + + // Private copy constructor and assignment operator + TypeFieldMethodAST(const TypeFieldMethodAST& obj); + TypeFieldMethodAST& operator=(const TypeFieldMethodAST& obj); + + // Data Members (m_ prefix) + TypeAST* m_return_type_ast_ptr; + string* m_ident_ptr; + Vector<TypeAST*>* m_type_ast_vec_ptr; +}; + +// Output operator declaration +ostream& operator<<(ostream& out, const TypeFieldMethodAST& obj); + +// ******************* Definitions ******************* + +// Output operator definition +extern inline +ostream& operator<<(ostream& out, const TypeFieldMethodAST& obj) +{ + obj.print(out); + out << flush; + return out; +} + +#endif //TYPEFIELDMETHODAST_H diff --git a/src/mem/slicc/ast/VarExprAST.cc b/src/mem/slicc/ast/VarExprAST.cc new file mode 100644 index 000000000..865cc71b0 --- /dev/null +++ b/src/mem/slicc/ast/VarExprAST.cc @@ -0,0 +1,76 @@ + +/* + * Copyright (c) 1999-2008 Mark D. Hill and David A. Wood + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer; + * redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution; + * neither the name of the copyright holders nor the names of its + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +/* + * VarExprAST.C + * + * Description: See VarExprAST.h + * + * $Id$ + * + */ + +#include "VarExprAST.hh" +#include "StatementAST.hh" +#include "SymbolTable.hh" + +VarExprAST::~VarExprAST() +{ + delete m_var_ptr; +} + + +Var* VarExprAST::getVar() const +{ + string var = *m_var_ptr; + Var* var_ptr = g_sym_table.getVar(var); + if (var_ptr == NULL) { + error("Unrecognized variable: " + var); + } + return var_ptr; +} + +void VarExprAST::assertType(string type_ident) const +{ + Type* expected_type_ptr = g_sym_table.getType(type_ident); + if (expected_type_ptr == NULL) { + error("There must be a type '" + type_ident + "' declared in this scope"); + } + + if (getVar()->getType() != expected_type_ptr) { + error("Incorrect type: '" + getVar()->getIdent() + "' is expected to be type '" + expected_type_ptr->toString() + "'"); + } +} + +Type* VarExprAST::generate(string& code) const +{ + Var* var_ptr = getVar(); + code += var_ptr->getCode(); + return var_ptr->getType(); +} diff --git a/src/mem/slicc/ast/VarExprAST.hh b/src/mem/slicc/ast/VarExprAST.hh new file mode 100644 index 000000000..ce2f68875 --- /dev/null +++ b/src/mem/slicc/ast/VarExprAST.hh @@ -0,0 +1,86 @@ + +/* + * Copyright (c) 1999-2008 Mark D. Hill and David A. Wood + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer; + * redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution; + * neither the name of the copyright holders nor the names of its + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +/* + * VarExprAST.h + * + * Description: + * + * $Id$ + * + */ + +#ifndef VAREXPRAST_H +#define VAREXPRAST_H + +#include "slicc_global.hh" +#include "ExprAST.hh" +class Var; + +class VarExprAST : public ExprAST { +public: + // Constructors + VarExprAST(string* var_ptr) : ExprAST() { m_var_ptr = var_ptr; } + + // Destructor + ~VarExprAST(); + + // Public Methods + Type* generate(string& code) const; + void print(ostream& out) const { out << "[VarExprAST: " << *m_var_ptr << "]"; } + string getName() const { return *m_var_ptr; } + Var* getVar() const; + void assertType(string type_ident) const; +private: + // Private Methods + + // Private copy constructor and assignment operator + VarExprAST(const VarExprAST& obj); + VarExprAST& operator=(const VarExprAST& obj); + + // Data Members (m_ prefix) + string* m_var_ptr; + +}; + +// Output operator declaration +ostream& operator<<(ostream& out, const VarExprAST& obj); + +// ******************* Definitions ******************* + +// Output operator definition +extern inline +ostream& operator<<(ostream& out, const VarExprAST& obj) +{ + obj.print(out); + out << flush; + return out; +} + +#endif //VAREXPRAST_H diff --git a/src/mem/slicc/doc/SLICC_V03.txt b/src/mem/slicc/doc/SLICC_V03.txt new file mode 100644 index 000000000..1c2a95a39 --- /dev/null +++ b/src/mem/slicc/doc/SLICC_V03.txt @@ -0,0 +1,307 @@ +SLICC - Version 0.3 Design Document - January 17, 1999 +Milo Martin and Dan Sorin + +Question: Rethinking of support for profiling the transactions + +Question: How do we deal with functions/methods and resources + +Comment: We need to discuss the sequencer interface so it can work now + and for the speculative version buffer. + +Overview +-------- + +We are in the process of designing and implementing SLICC v0.3, an +evolution of SLICC v0.2. The new design includes capabilities for +design of multilevel cache hierarchies including the specification of +multiple protocol state machines (PSMs) and the queues which connect +these PSMs and the network. We actually believe that most of the +network and network topology, including the ordered network, can be +expressed using the new hierarchical extensions to the language. + +In addition, many implicit aspects of the language will be eliminated +in favor of explicit declarations. For example functions, queues, and +objects declarations such as "cacheMemory" and "TBETable" will be +explicitly declared. This will allow for full static type checking +and easier extension for the language. Event triggering will be part +of "in_port" declarations and not "event" declarations. Finally, many +less fundamental, but important, features and internal code +improvements will be enhanced. + +SLICC History +------------- + +v0.1 - Initially the language only handled the generation of the PSM + transition table logic. All actions and event triggering were + still coded in C++. At this point it was still called, "the + language." + +v0.2 - Extended the language to include a simple C like syntax for + specifying actions, event triggering, and manipulating queues + and state elements. This version was the first version of the + language known as SLICC (suggested by Amir) and was used for + the Multifacet ISCA 2000 submission. + +v0.3 - Development effort started January 2000. Intended features and + enhancements are described by this document. + +Specifying Hierarchical Designs +------------------------------- + +Right now all of our protocols have two tables, a processor/cache PSM +and a directory PSM. In v0.2 this is a rigid requirement and +the names are implicit. SLICC v0.3 will allow for an arbitrary number +of different PSMs. + +The most significant improvement in v0.3 is the ability for the user +to define an arbitrary set of interconnected PSMs. PSMs may include +an L1 cache controller, L2 cache controller, directory controller, +speculative version buffer, network interface, etc. There are a +couple of "primitive PSMs" such as the sequencer. + +There will be a notion of a "node" of the system. In a node, each PSM +will be instantiated and connected together with queues. For example, +assume we define a PSMs and want to create a queue of RequestMessages +to communicate between it and the network. + + machine(CacheController) { + ... + out_port(to_network, RequestMessage, "To the network", desc="..."); + ... + } + + CacheController cache, desc="..."; + + connect(cache.to_network, network.from_cache, ordered="yes", desc="..."); + +Explicit State Manipulation +--------------------------- + +As before, PSMs have states, events, and transitions. New in v0.3 each +PSM must have user defined methods for get_state(address) and +set_state(address, state), and these methods are written explicitly, +instead of being implicit functions of memory states (e.g., our +current implementation which implicitly uses the TBE state if there is +a TBE or uses the cache state). Functions have a return value, +procedures do not. Function calls are expressions, procedure calls +are statements. All function and procedure parameters are considered +pass-by-value. + + procedure set_state(Address addr, State state) { + ... + } + + function State get_state(Address addr) { + ... + } + +Explicit Declaration +-------------------- + +PSMs reference or declare structures, such as queues, ports, cache +memories, main memory, TBEs, write buffers, etc. These primitive +types and structures are written in C++, and their semantics are still +specified by the C++ coder. Examples of these primitive types include +"CacheMemory," "TBETable," as well as various types of queues. + +One major difference is that in v0.3 the interface for all of these +primitive objects will be declared (but not defined) in the SLICC +language. This also allows adding primitive structures by defining a +C++ implementation and a SLICC interface specification. This will +make the language much more extensible. Specifying the interface of +these primitive types, structures, and queues in SLICC will eliminate +much of the implicit semantics that is currently hiding in the +controllers. + +The interface declaration might be in one file and shared between all +protocols. The object instantiation would be internal to each PSM +that requires a cache memory. The syntax for messages will also be +enhanced by using this new syntax. Notice the support for default +values. + + structure(CacheMemory, "Cache memory", desc="...") { + void cache_change_state(Address addr, State state), desc="..."; + Data dataBlk, default="", desc=""; + bool cache_avail(Address addr), desc="..."; + Address cache_probe(Address addr), desc="..."; + void cache_allocate(Address addr), desc="..."; + } + + CacheMemory L1cacheMemory, desc="..."; + +Structure specification is going to require the introduction of an +object model in the language. The "." (dot) operator is going to be +extended beyond the use as structure element access, but also allow +for a object method call syntax similar to C++ and Java. + + L1cacheMemory.cache_allocate(addr); + +Polymorphism +------------ + +We are also going to want to allow for polymorphism for many of the +structures. We already have a limited degree of polymorphism between +different protocols by using the same cache memory structure with +different "CacheEntry" types in each protocol. Now that we are going +to have multiple levels of cache, each requiring slightly different +state bits, we are going to want to specify cache memory structures +which have different "CacheEntry" types in the same protocol. To do +this right, this is going to require adding full polymorphism support +to the language. Right now we imagine something like C++'s templates, +since they are a more natural fit to hardware synthesis in the future. + +Type Checker +------------ + +All of the above substantially complicates our type system by +requiring more types and scoping rules. As a step towards +understanding the implications of the type system, a type checking +system will be implemented. This is a hard requirement if we are ever +to distribute the system since receiving compile time errors in the +generated code is not acceptable. In order to ensure that we don't +accidentally design a language that is not statically type checkable, +it is important to add the type checker sooner rather than later. + +Event Triggering +---------------- + +In v0.2, PSM events were individually specified as sets of conditions. +The following SLICC v0.2 code is a simplified example from the origin +protocol. + + event(Dir_data_ack_0, "Data ack 0", desc="... ack count == 0") { + if (queue_ready(responseNetwork)) { + peek(responseNetwork, ResponseMsg) { + if(in_msg.NumPendingAcks == 0) { + trigger(in_msg.Address); + } + } + } + } + + event(Dir_data_ack_not_0, "Data ack not 0", desc="... ack count != 0") { + if (queue_ready(responseNetwork)) { + peek(responseNetwork, ResponseMsg) { + if(in_msg.NumPendingAcks != 0) { + trigger(in_msg.Address); + } + } + } + } + +The above code defines the exact conditions for the events to be +triggered. This type of event specification led to redundant code and +numerous bugs where conditions for different events were not +completely orthogonal. + +In v0.3, events will be declared with no accompanying code (similar to +how states are specified). Instead, the code that determines which +event is triggered will be part of each incoming port's declaration. +This approach should eliminate redundancy and bugs in trigger +conditions. The v0.3 code for the above would look like: + + event(Dir_data_ack_0, "Data ack 0", desc="... ack count = 0"); + event(Dir_data_ack_not_0, "Data ack not 0", desc="... ack count != 0"); + + in_port(responseNetwork, ResponseMsg, "Response Network", desc="...") { + if(in_msg.NumPendingAcks == 0) { + trigger(Dir_data_ack_0, in_msg.Address); + } else { + trigger(Dir_data_ack_not_0, in_msg.Address); + } + } + +Notice that one no longer needs to explicitly check if the queue is +ready or to perform the peek operation. + +Also notice that the type of messages that arrives on the port is +explicitly declared. All ports, incoming and outgoing, are now +explicitly type channels. You will still be required to include the +type of message when manipulating the queue. The type specified will +be statically type checked and also acts as self-documenting code. + +Other Improvements +------------------ + +There will be a number of other improvements in v0.3 such as general +performance tuning and clean up of the internals of the compiler. The +compiler will be modified to operate on multiple files. In addition, +the abstract syntax tree internal to the code will need to be extended +to encompass more information, including information parsed in from +multiple files. + +The affiliates talk and the document for the language should also be +updated to reflect the changes in the new version. + +Looking Forward +--------------- + +When designing v0.3 we are keeping future plans in mind. + +- When our designs of the multilevel cache hierarchy are complete, we + expect to have a large amount of replication between the protocols + and caches controllers within a protocol. For v0.4 we hope to look + at the patterns that have evolved and look for ways in which the + language can capture these patterns. Exploiting reuse will provide + quicker protocol development and maintainability. + +- By keeping the specification structural, we are looking towards + generating VHDL/Verilog from SLICC. The type system will help this, + as will more explicit instantiation and declaration of types and + structures. The structures now written in C++ (sequencer, network, + cache arrays) will be ported to the HDL we select. The rest of the + controllers will be generated by the compiler. At first the + generated controller will not be optimized. I believe that with + more effort we can automatically generate reasonably optimized, + pipelined implementation of the controllers. + +Implementation Plan +------------------- + +- HTML generator +- Extend internal parser AST nodes +- Add get_state function and set_state procedure declarations +- Move trigger logic from events to in_ports +- Types + - Change type declaration syntax + - Declare primitive types and corresponding C++ types + - Add default values to structures and types + - Add object method call syntax + - Write type checker +- Documentation + - Revise document + - Update presentation + +Document History +---------------- + +$Id: SLICC_V03.txt,v 3.0 2000/09/12 20:27:59 sorin Exp $ + +$Log: SLICC_V03.txt,v $ +Revision 3.0 2000/09/12 20:27:59 sorin +Version 3.0 signifies a checkpoint of the source tree right after the +final draft of the ASPLOS '00 paper. + +Revision 1.1.1.1 2000/03/09 10:18:38 milo +Initial import + +Revision 2.0 2000/01/19 07:21:13 milo +Version 2.0 + +Revision 1.5 2000/01/18 10:26:24 milo +Changed the SLICC parser so that it generates a full AST. This is the +first step in moving towards v0.3 + +Revision 1.4 2000/01/17 18:36:15 sorin +*** empty log message *** + +Revision 1.3 2000/01/15 10:30:16 milo +Added implementation list + +Revision 1.2 2000/01/15 08:11:44 milo +Minor revisions + +Revision 1.1 2000/01/15 07:14:17 milo +Converted Dan's first draft into a text file. Significant +modifications were made. + diff --git a/src/mem/slicc/doc/tutorial.tex b/src/mem/slicc/doc/tutorial.tex new file mode 100644 index 000000000..c20dba156 --- /dev/null +++ b/src/mem/slicc/doc/tutorial.tex @@ -0,0 +1,574 @@ +%& latex +\documentclass[11pt]{article} +\usepackage{graphics} +\usepackage{color} + +\textheight 9.0 in +\topmargin -0.5 in +\textwidth 6.5 in +\oddsidemargin -0.0 in +\evensidemargin -0.0 in + +\begin{document} + +\definecolor{dark}{gray}{0.5} + +\newcommand{\syntax}[1]{% +\begin{center} +\fbox{\tt \small +\begin{tabular}{l} +#1\end{tabular}}\end{center}} + +\begin{center} +{\LARGE Tutorial for SLICC v0.2} \\ +\vspace{.25in} +{\large Milo Martin} \\ +{\large 8/25/1999} +\end{center} + +\section*{Overview} + +This document attempts to illustrate the syntax and expressiveness of +the cache coherence protocol specification language through a small +example. A ``stupido'' cache coherence protocol is described in prose +and then expressed in the language. + +The protocol used as the running example is described. Then each of +the elements of the protocol is discussed and expressed in the +language: states, events, transitions, and actions. + +\section*{Protocol Description} + +In order to make this example a simple as possible, the protocol +described is a simple as possible and makes many simplifying +assumptions. These simplifications were made only to clarify the +exposition and are not indications of limitations of the +expressiveness of the description language. We have already specified +a more complicated MSI broadcast snooping protocol, a multicast +snooping protocol, and a directory protocol. The simplifying +assumptions are listed below. The remaining details of the protocol +are described in the sections where we give the syntax of the +language. + +\begin{itemize} + +\item +The protocol uses broadcast snooping that assumes that a broadcast can +only occur if all processors have processed all of their incoming +address transactions. In essence, when a processor issue an address +request, that request will be next in the global order. This allows +us to avoid needed to handle the cases before we have observed our +request in the global order. + +\item +The protocol has only Modified and Idle stable states. (Note: Even +the Shared state is omitted.) + +\item +To avoid describing replacement (PutX's) and writebacks, the caches +are in treated as infinite in size. + +\item +No forward progress bit is used, so the protocol as specified does not +guarantee forward progress. + +\item +Only the mandatory request queue is used. No optional or prefetch +queue is described. + +\item +The above simplifications reduce the need for TBEs (Translation Buffer +Entries) and thus the idea of a TBE is not include. + +\item +Each memory module is assumed to have some state associated with each +cache block in the memory. This requires a simple directory/memory +state machine to work as a compliment to the processor state machine. +Traditional broadcast snooping protocols often have no ``directory'' +state in the memory. + +\end{itemize} + +\section*{Protocol Messages} + +Cache coherence protocols communicate by sending well defined +messages. To fully specify a cache coherence protocol we need to be +able to specify the message types and fields. For this protocol we +have address messages ({\tt AddressMsg}) which are broadcast, and data +messages ({\tt DataMsg}) which are point-to-point. Address messages +have an address field ({\tt Address}), a request type ({\tt Type}), +and which processor made the request ({\tt Requestor}). Data message +have an address field ({\tt Address}), a destination ({\tt +Destination}), and the actual cache block being transfered ({\tt +DataBlk}). The names in parenthesis are important because those are +the names which code later in the specification will reference various +message types and fields in the messages. + +Messages are declared by creating types with {\tt new\_type()} and +adding fields with {\tt type\_field()}. The exact syntax for +declaring types and message is a bit ugly right now and is going to be +changed in the near future. If you wish, please see the appendix for +an example of the current syntax. + + + +\section*{Cache States} + +Idle and Modified are the two stable states in our protocol. In +addition the we have a single transient processor state. This state +is used after a processor has issued a request and is waiting for the +data response to arrive. + +Declaring states in the language is the first of a number of +declarations we will be using. All of these declarations have a +similar format. Below is the format for a state declaration. + +\syntax{ +{\tt state({\em identifier}, {\em shorthand}, {\em pair1}, {\em pair2}, ...);} +} + +{\em identifier} is a name that is used later to +refer to this state later in the description. It must start with a +letter and after than can have any combination of letters, numbers, +and the underscore character. {\em shorthand} is a quoted string +which contains the shorthand that should be used for the state when +generating tables and such. + +The {\em pair}'s are used to associate arbitrary information with each +state. Zero or more pairs can be included in each declaration. For +example we want to have a more verbose description of each state when +we generate the table which contains the states and descriptions. +This information is encoded in the language by adding a {\tt desc} +parameter to a declaration. The name of the parameter is followed by +an equal sign and a string with the description. The {\tt desc} pair +technically optional, however the table generation tool will complain +about a missing description if it is not present. + +The three states for our protocol are expressed as follows: + +\begin{verbatim} +state(I, "I", desc="Idle"); +state(M, "M", desc="Modified"); +state(IM, "IM", desc="Idle, issued request but have not seen data yet"); +\end{verbatim} + +\section*{Cache Events} + +Events are external stimulus that cause the state machine to take +action. This is most often a message in one of the queues from the +network or processor. Events form the columns of the protocol table. +Our simple protocol has one event per incoming queue. When a message +is waiting in one of these queues and event can occur. We can see a +request from the processor in the mandatory queue, another processor's +request, or a data response. + +Events are declared in the language similarly to states. The {\em +identifier}, {\em shorthand}, and {\em pair}'s have the same purpose +as in a state declaration. + +\syntax{ +event({\em identifier}, {\em shorthand}, {\em pair1}, {\em pair2}, ...) \{ \\ +\hspace{.1in} {\em statement\_list} \\ +\} \\ +} + +Events are different in that they have a list of statements which +allows exact specification of when the event should ``trigger'' a +transition. These statements are mini-programming language with +syntax similar to that of C. For example the {\tt peek} construct in +this context checks to see if there is a message at the head of the +specified queue, and if so, conceptually copies the message to a +temporary variable accessed as {\tt in\_msg}. The language also +supports various procedure calls, functions, conditional statements, +assignment, and queue operations such as peek, enqueue and dequeue. +The {\tt trigger()} construct takes an address as the only parameter. +This is the address that should be triggered for the event. To give +you a feel for what this code looks like, the three events for our +simple protocol are below. + +\begin{verbatim} +event(LoadStore, "LoadStore", desc="Load or Store request from local processor") { + peek(mandatoryQueue_ptr, CacheMsg) { + trigger(in_msg.Address); + } +} + +event(Other_GETX, "Other GETX", desc="Observed a GETX request from another processor") { + peek(addressNetwork_ptr, AddressMsg) { + if (in_msg.Requestor != id) { + trigger(in_msg.Address); + } + } +} + +event(Data, "Data", desc="Data for this block from the data network") { + peek(dataNetwork_ptr, DataMsg) { + trigger(in_msg.Address); + } +} +\end{verbatim} + +\section*{Cache Actions} + +Actions are the privative operations that are performed by various +state transitions. These correspond (by convention) to the lower case +letters in the tables. We need several actions in our protocol +including issuing a GetX request, servicing a cache hit, send data +from the cache to the requestor, writing data into the cache, and +popping the various queues. + +The syntax of an action declaration is similar to an event +declaration. The difference is that statements in the statement list +are used to implement the desired action, and not triggering an event. + +\syntax{action({\em identifier}, {\em shorthand}, {\em pair1}, {\em pair2}, ...) \{ \\ +\hspace{.1in} {\em statement\_list} \\ +\} +} + +The actions for this protocol use more of the features of the +language. Some of the interesting case are discussed below. + +\begin{itemize} + +\item +To manipulate values we need assignment statements (notice the use of +{\verb+:=+} as the assignment operator). The action to write data +into the cache looks at the incoming data message and puts the data in +the cache. Notice the use of square brackets to lookup the block in +the cache based on the address of the block. + +\begin{verbatim} +action(w_writeDataToCache, "w", desc="Write data from data message into cache") { + peek(dataNetwork_ptr, DataMsg) { + cacheMemory_ptr[address].DataBlk := in_msg.DataBlk; + } +} +\end{verbatim} + +\item +In addition to peeking at queues, we also enqueue messages. The {\tt +enqueue} construct works similarly to the {\tt peek} construct. {\tt +enqueue} creates a temporary called {\tt out\_msg}. You can assign +the fields of this message. At the end of the {\tt enqueue} construct +the message is implicitly inserted in the outgoing queue of the +specified network. Notice also how the type of the message is +specified and how the assignment statements use the names of the +fields of the messages. {\tt address} is the address for which the +event was {\tt trigger}ed. + +\begin{verbatim} +action(g_issueGETX, "g", desc="Issue GETX.") { + enqueue(addressNetwork_ptr, AddressMsg) { + out_msg.Address := address; + out_msg.Type := "GETX"; + out_msg.Requestor := id; + } +} +\end{verbatim} + +\item +Some times we need to use both {\tt peek} and {\tt enqueue} together. +In this example we look at an incoming address request to figure out +who to whom to forward the data value. + +\begin{verbatim} +action(r_cacheToRequestor, "r", desc="Send data from the cache to the requestor") { + peek(addressNetwork_ptr, AddressMsg) { + enqueue(dataNetwork_ptr, DataMsg) { + out_msg.Address := address; + out_msg.Destination := in_msg.Requestor; + out_msg.DataBlk := cacheMemory_ptr[address].DataBlk; + } + } +} +\end{verbatim} + +\item +We also need to pop the various queues. +\begin{verbatim} +action(k_popMandatoryQueue, "k", desc="Pop mandatory queue.") { + dequeue(mandatoryQueue_ptr); +} +\end{verbatim} + +\item +Finally we have the ability to call procedures and functions. The +following is an example of a procedure call. Currently all of the +procedures and functions are used to handle all of the more specific +operations. These are currently hard coded into the generator. + +\begin{verbatim} +action(h_hit, "h", desc="Service load/store from the cache.") { + serviceLdSt(address, cacheMemory_ptr[address].DataBlk); +} +\end{verbatim} + +\end{itemize} + +\section*{Cache Transitions} + +The cross product of states and events gives us the set of possible +transitions. For example, for our example protocol the empty would +be: + +\begin{center} +\begin{tabular}{|l||l|l|l|} \hline + & LoadStore & Other GETX & Data \\ \hline \hline +I & & & \\ \hline +M & & & \\ \hline +IM & & & \\ \hline +\end{tabular} +\end{center} + + +Transitions are atomic and are the heart of the protocol +specification. The transition specifies both what the next state, and +also what actions are performed for each unique state/event pair. The +transition declaration looks different from the other declarations: + +\syntax{ +transition({\em state}, {\em event}, {\em new\_state}, {\em pair1}, {\em pair2}, ...) \{ \\ +\hspace{.1in} {\em action\_identifier\_list}\\ +\} +} + +{\em state} and {\em event} are the pair which uniquely identifies the +transition. {\em state} correspond to the row where {\em event} +selects the column. {\em new\_state} is an optional parameter. If +{\em new\_state} is specified, that is the state when the atomic +transition is completed. If the parameter is omitted there is assumed +to be no state change. An impossible transition is specified by +simply not declaring an event for that state/event pair. + +We also place list of actions in the curly braces. The {\em +action\_identifier}'s correspond to the identifier specified as the +first parameter of an action declaration. The action list is a list +of operations to be performed when this transition occurs. The +actions also knows what preconditions are necessary are required for +the action to be performed. For example a necessary precondition for +an action which sends a message is that there is a space available in +the outgoing queue. Each transition is considered atomic, and thus +the generated code ensures that all of the actions can be completed +before performing and of the actions. + +In our running example protocol it is only possible to receive data in +the {\em IM} state. The other seven cases can occur and are declared +as follows. Below are a couple of examples. See the appendix for a +complete list. + +\newpage +\begin{verbatim} +transition(I, LoadStore, IM) { + g_issueGETX; +} + +transition(M, LoadStore) { + h_hit; + k_popMandatoryQueue; +} + +transition(M, Other_GETX, I) { + r_cacheToRequestor; + i_popAddressQueue; +} +\end{verbatim} + +From the above declarations we can generate a table. Each box can +have lower case letters which corresponds to the list of actions +possibly followed by a slash and a state (in uppercase letters). If +there is no slash and state, the transition does not change the state. + +\begin{center} +\begin{tabular}{|l||l|l|l|} \hline + & LoadStore & Other GETX & Data \\ \hline \hline +I & g/IM & i & (impossible)\\ \hline +M & hk & ri/I & (impossible)\\ \hline +IM & z & z & wj/M \\ \hline +\end{tabular} +\end{center} + +There is a useful shorthand for specifying many transitions with the +same action. One or both of {\em event} and {\em state} can be a list +in curly braces. This defines the cross product of the sets in one +declaration. If no {\em new\_state} is specified none of the +transitions cause a state change. If {\em new\_state} is specified, +all of the transitions in the cross product of the sets has the same +next state. For example, in the below transitions both IM/LoadStore +and IM/Other\_GETX have the action {\tt z\_delayTrans}. +\begin{verbatim} +transition(IM, LoadStore) { + z_delayTrans; +} + +transition(IM, Other_GETX) { + z_delayTrans; +} +\end{verbatim} +These can be specified in a single declaration: +\begin{verbatim} +transition(IM, {LoadStore, Other_GETX}) { + z_delayTrans; +} +\end{verbatim} + + +\newpage +\section*{Appendix - Sample Cache Controller Specification} + +{\small +\begin{verbatim} +machine(processor, "Simple MI Processor") { + + // AddressMsg + new_type(AddressMsg, "AddressMsg", message="yes", desc=""); + type_field(AddressMsg, Address, "address", + desc="Physical address for this request", + c_type=PhysAddress, c_include="Address.hh", murphi_type=""); + type_field(AddressMsg, Type, "type", + desc="Type of request (GetS, GetX, PutX, etc)", + c_type=CoherenceRequestType, c_include="CoherenceRequestType.hh", murphi_type=""); + type_field(AddressMsg, Requestor, "requestor", + desc="Node who initiated the request", + c_type=ComponentID, c_include="ComponentID.hh", murphi_type=""); + + // DataMsg + new_type(DataMsg, "DataMsg", message="yes", desc=""); + type_field(DataMsg, Address, "address", + desc="Physical address for this request", + c_type=PhysAddress, c_include="Address.hh", murphi_type=""); + type_field(DataMsg, Destination, "destination", + desc="Node to whom the data is sent", + c_type=Set, c_include="Set.hh", murphi_type=""); + type_field(DataMsg, DataBlk, "data", + desc="Node to whom the data is sent", + c_type=DataBlock, c_include="DataBlock.hh", murphi_type=""); + + // CacheEntry + new_type(CacheEntry, "CacheEntry"); + type_field(CacheEntry, CacheState, "Cache state", desc="cache state", + c_type=CacheState, c_include="CacheState.hh", murphi_type=""); + type_field(CacheEntry, DataBlk, "data", desc="data for the block", + c_type=DataBlock, c_include="DataBlock.hh", murphi_type=""); + + // DirectoryEntry + new_type(DirectoryEntry, "DirectoryEntry"); + type_field(DirectoryEntry, DirectoryState, "Directory state", desc="Directory state", + c_type=DirectoryState, c_include="DirectoryState.hh", murphi_type=""); + type_field(DirectoryEntry, DataBlk, "data", desc="data for the block", + c_type=DataBlock, c_include="DataBlock.hh", murphi_type=""); + +\end{verbatim} +\newpage +\begin{verbatim} + // STATES + state(I, "I", desc="Idle"); + state(M, "M", desc="Modified"); + state(IM, "IM", desc="Idle, issued request but have not seen data yet"); + + // EVENTS + + // From processor + event(LoadStore, "LoadStore", desc="Load or Store request from local processor") { + peek(mandatoryQueue_ptr, CacheMsg) { + trigger(in_msg.Address); + } + } + + // From Address network + event(Other_GETX, "Other GETX", desc="Observed a GETX request from another processor") { + peek(addressNetwork_ptr, AddressMsg) { + if (in_msg.Requestor != id) { + trigger(in_msg.Address); + } + } + } + + // From Data network + event(Data, "Data", desc="Data for this block from the data network") { + peek(dataNetwork_ptr, DataMsg) { + trigger(in_msg.Address); + } + } + + // ACTIONS + action(g_issueGETX, "g", desc="Issue GETX.") { + enqueue(addressNetwork_ptr, AddressMsg) { + out_msg.Address := address; + out_msg.Type := "GETX"; + out_msg.Requestor := id; + } + } + + action(h_hit, "h", desc="Service load/store from the cache.") { + serviceLdSt(address, cacheMemory_ptr[address].DataBlk); + } + + action(i_popAddressQueue, "i", desc="Pop incoming address queue.") { + dequeue(addressNetwork_ptr); + } + + action(j_popDataQueue, "j", desc="Pop incoming data queue.") { + dequeue(dataNetwork_ptr); + } + + action(k_popMandatoryQueue, "k", desc="Pop mandatory queue.") { + dequeue(mandatoryQueue_ptr); + } + + action(r_cacheToRequestor, "r", desc="Send data from the cache to the requestor") { + peek(addressNetwork_ptr, AddressMsg) { + enqueue(dataNetwork_ptr, DataMsg) { + out_msg.Address := address; + out_msg.Destination := in_msg.Requestor; + out_msg.DataBlk := cacheMemory_ptr[address].DataBlk; + } + } + } + + action(w_writeDataToCache, "w", desc="Write data from data message into cache") { + peek(dataNetwork_ptr, DataMsg) { + cacheMemory_ptr[address].DataBlk := in_msg.DataBlk; + } + } + + action(z_delayTrans, "z", desc="Cannot be handled right now.") { + stall(); + } + + // TRANSITIONS + + // Transitions from Idle + transition(I, LoadStore, IM) { + g_issueGETX; + } + + transition(I, Other_GETX) { + i_popAddressQueue; + } + + // Transitions from Modified + transition(M, LoadStore) { + h_hit; + k_popMandatoryQueue; + } + + transition(M, Other_GETX, I) { + r_cacheToRequestor; + i_popAddressQueue; + } + + // Transitions from IM + transition(IM, {LoadStore, Other_GETX}) { + z_delayTrans; + } + + transition(IM, Data, M) { + w_writeDataToCache; + j_popDataQueue; + } +} +\end{verbatim} +} +\end{document} + diff --git a/src/mem/slicc/generator/fileio.cc b/src/mem/slicc/generator/fileio.cc new file mode 100644 index 000000000..1707e5b7a --- /dev/null +++ b/src/mem/slicc/generator/fileio.cc @@ -0,0 +1,66 @@ + +/* + * Copyright (c) 1999-2008 Mark D. Hill and David A. Wood + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer; + * redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution; + * neither the name of the copyright holders nor the names of its + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +/* + * fileio.C + * + * Description: See fileio.h + * + * $Id: fileio.C,v 3.3 2003/07/10 18:08:08 milo Exp $ + * + * */ + +#include "fileio.hh" + +void conditionally_write_file(string filename, ostringstream& sstr) +{ + ofstream out; + ifstream in; + string input_file; + + // Read in the file if it exists + in.open(filename.c_str()); + char c; + while (in.get(c)) { + input_file += c; + } + in.close(); + + // Check to see if the file is the same as what we want to write + if (input_file != sstr.str()) { + cout << " Overwriting file: " << filename << endl; + // Overwrite the old file with the new file + out.open(filename.c_str()); + out << sstr.str(); + out.close(); + } else { + //cout << " Keeping old file: " << filename << endl; + } +} + diff --git a/src/mem/slicc/generator/fileio.hh b/src/mem/slicc/generator/fileio.hh new file mode 100644 index 000000000..3cca7ccaa --- /dev/null +++ b/src/mem/slicc/generator/fileio.hh @@ -0,0 +1,46 @@ + +/* + * Copyright (c) 1999-2008 Mark D. Hill and David A. Wood + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer; + * redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution; + * neither the name of the copyright holders nor the names of its + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +/* + * fileio.h + * + * Description: + * + * $Id: fileio.h,v 3.2 2003/02/24 20:54:25 xu Exp $ + * + * */ + +#ifndef FILEIO_H +#define FILEIO_H + +#include "slicc_global.hh" + +void conditionally_write_file(string filename, ostringstream& sstr); + +#endif //FILEIO_H diff --git a/src/mem/slicc/generator/html_gen.cc b/src/mem/slicc/generator/html_gen.cc new file mode 100644 index 000000000..3d17018e1 --- /dev/null +++ b/src/mem/slicc/generator/html_gen.cc @@ -0,0 +1,125 @@ + +/* + * Copyright (c) 1999-2008 Mark D. Hill and David A. Wood + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer; + * redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution; + * neither the name of the copyright holders nor the names of its + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +/* + * html_gen.C + * + * Description: See html_gen.h + * + * $Id: html_gen.C,v 3.4 2004/01/31 20:46:50 milo Exp $ + * + * */ + +#include "html_gen.hh" +#include "fileio.hh" +#include "SymbolTable.hh" + +string formatHTMLShorthand(const string shorthand); + + +void createHTMLSymbol(const Symbol& sym, string title, ostream& out) +{ + out << "<HTML><BODY><BIG>" << endl; + out << title << ": " << endl; + out << formatHTMLShorthand(sym.getShorthand()) << " - "; + out << sym.getDescription(); + out << "</BIG></BODY></HTML>" << endl; +} + +void createHTMLindex(string title, ostream& out) +{ + out << "<html>" << endl; + out << "<head>" << endl; + out << "<title>" << title << "</title>" << endl; + out << "</head>" << endl; + out << "<frameset rows=\"*,30\">" << endl; + Vector<StateMachine*> machine_vec = g_sym_table.getStateMachines(); + if (machine_vec.size() > 1) { + string machine = machine_vec[0]->getIdent(); + out << " <frame name=\"Table\" src=\"" << machine << "_table.html\">" << endl; + } else { + out << " <frame name=\"Table\" src=\"empty.html\">" << endl; + } + + out << " <frame name=\"Status\" src=\"empty.html\">" << endl; + out << "</frameset>" << endl; + out << "</html>" << endl; +} + +string formatHTMLShorthand(const string shorthand) +{ + string munged_shorthand = ""; + bool mode_is_normal = true; + + // -- Walk over the string, processing superscript directives + for(unsigned int i = 0; i < shorthand.length(); i++) { + if(shorthand[i] == '!') { + // -- Reached logical end of shorthand name + break; + } else if( shorthand[i] == '_') { + munged_shorthand += " "; + } else if( shorthand[i] == '^') { + // -- Process super/subscript formatting + mode_is_normal = !mode_is_normal; + if(mode_is_normal) { + // -- Back to normal mode + munged_shorthand += "</SUP>"; + } else { + // -- Going to superscript mode + munged_shorthand += "<SUP>"; + } + } else if(shorthand[i] == '\\') { + // -- Process Symbol character set + if((i + 1) < shorthand.length()) { + i++; // -- Proceed to next char. Yes I know that changing the loop var is ugly! + munged_shorthand += "<B><FONT size=+1>"; + munged_shorthand += shorthand[i]; + munged_shorthand += "</FONT></B>"; + } else { + // -- FIXME: Add line number info later + cerr << "Encountered a `\\` without anything following it!" << endl; + exit( -1 ); + } + } else { + // -- Pass on un-munged + munged_shorthand += shorthand[i]; + } + } // -- end for all characters in shorthand + + // -- Do any other munging + if(!mode_is_normal) { + // -- Back to normal mode + munged_shorthand += "</SUP>"; + } + + // -- Return the formatted shorthand name + return munged_shorthand; +} + + diff --git a/src/mem/slicc/generator/html_gen.hh b/src/mem/slicc/generator/html_gen.hh new file mode 100644 index 000000000..3f0de8df9 --- /dev/null +++ b/src/mem/slicc/generator/html_gen.hh @@ -0,0 +1,49 @@ + +/* + * Copyright (c) 1999-2008 Mark D. Hill and David A. Wood + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer; + * redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution; + * neither the name of the copyright holders nor the names of its + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +/* + * html_gen.h + * + * Description: + * + * $Id: html_gen.h,v 3.1 2001/12/12 01:00:35 milo Exp $ + * + * */ + +#ifndef HTML_GEN_H +#define HTML_GEN_H + +#include "slicc_global.hh" +#include "StateMachine.hh" + +string formatHTMLShorthand(const string shorthand); +void createHTMLindex(string title, ostream& out); +void createHTMLSymbol(const Symbol& sym, string title, ostream& out); + +#endif //HTML_GEN_H diff --git a/src/mem/slicc/generator/mif_gen.cc b/src/mem/slicc/generator/mif_gen.cc new file mode 100644 index 000000000..0e6253654 --- /dev/null +++ b/src/mem/slicc/generator/mif_gen.cc @@ -0,0 +1,1718 @@ + +/* + * Copyright (c) 1999-2008 Mark D. Hill and David A. Wood + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer; + * redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution; + * neither the name of the copyright holders nor the names of its + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +/* + * $Id$ + * + */ + +#include "mif_gen.hh" +#include "State.hh" +#include "Event.hh" +#include "Action.hh" +#include "Transition.hh" + +// -- Helper functions +string formatShorthand(const string shorthand); +string formatCellRuling(const string shorthand); + +void printStateTableMIF(const StateMachine& sm, ostream& out) +{ + const string mif_prolog1 = +"<MIFFile 5.50> # Generated by Multifacet MIF Mungers Inc\n\ +<Tbls\n\ + <Tbl\n\ + <TblID 1>\n\ + <TblTag `Format A'>\n\ + <TblFormat\n\ +\n\ + <TblAlignment Center>\n\ +\n\ + # <TblXColumnNum 0>\n\ + <TblXColumnRuling `Medium'>\n\ +\n\ + <TblLRuling `Medium'>\n\ + <TblRRuling `Medium'>\n\ + <TblTRuling `Medium'>\n\ + <TblBRuling `Medium'>\n\ +\n\ + <TblColumn\n\ + <TblColumnNum 0>\n\ + <TblColumnWidth 0.51\">\n\ + <TblColumnH\n\ + <PgfTag `CellHeading'>\n\ + > # end of TblColumnH\n\ + <TblColumnBody\n\ + <PgfTag `CellBody'>\n\ + > # end of TblColumnBody\n\ + <TblColumnF\n\ + <PgfTag `CellHeading'>\n\ + > # end of TblColumnF\n\ + > # end of TblColumn\n\ + <TblColumn\n\ + <TblColumnNum 1>\n\ + <TblColumnWidth 0.51\">\n\ + <TblColumnH\n\ + <PgfTag `CellHeading'>\n\ + > # end of TblColumnH\n\ + <TblColumnBody\n\ + <PgfTag `CellBody'>\n\ + > # end of TblColumnBody\n\ + <TblColumnF\n\ + <PgfTag `CellHeading'>\n\ + > # end of TblColumnF\n\ + > # end of TblColumn\n\ + > # end of TblFormat\n\ +\n\ + <TblNumColumns 2>\n\ + <TblColumnWidth 0.51\">\n\ + <TblColumnWidth 6.00\">\n\ + <TblTitle\n\ + <TblTitleContent\n\ + <Para\n\ + <PgfTag `TableTitle'>\n\ + <Pgf\n\ + <PgfAlignment Center>\n\ + <PgfFont \n\ + <FTag `'>\n\ + <FFamily `Times'>\n\ + <FVar `Regular'>\n\ + <FWeight `Regular'>\n\ + <FAngle `Regular'>\n\ + <FPostScriptName `Times-Roman'>\n\ + <FEncoding `FrameRoman'>\n\ + <FSize 11.0 pt>\n\ + <FUnderlining FNoUnderlining>\n\ + <FOverline No>\n\ + <FStrike No>\n\ + <FChangeBar No>\n\ + <FOutline No>\n\ + <FShadow No>\n\ + <FPairKern Yes>\n\ + <FTsume No>\n\ + <FCase FAsTyped>\n\ + <FPosition FNormal>\n\ + <FDX 0.0%>\n\ + <FDY 0.0%>\n\ + <FDW 0.0%>\n\ + <FStretch 100.0%>\n\ + <FLanguage USEnglish>\n\ + <FLocked No>\n\ + <FSeparation 0>\n\ + <FColor `Black'>\n\ + > # end of PgfFont\n\ + > # end of Pgf\n\ + <PgfNumString `TABLE 1. '>\n\ + <ParaLine\n\ + <Marker\n\ + <MType 9>\n\ + <MTypeName `Cross-Ref'>\n\ + <MCurrPage `1'>\n\ + > # end of Marker\n\ + <String `"; + + const string mif_prolog2 = + "'>\n\ + > # end of ParaLine\n\ + > # end of Para\n\ + > # end of TblTitleContent\n\ + > # end of TblTitle\n\ +\n\ + <TblH\n\ + <Row\n\ + <RowMaxHeight 14.0\">\n\ + <RowHeight 0.44444\">\n\ + <Cell\n\ + <CellLRuling `Medium'>\n\ + <CellBRuling `Medium'>\n\ + <CellRRuling `Medium'>\n\ + <CellTRuling `Medium'>\n\ + <CellContent\n\ + <Para\n\ + <PgfTag `CellHeading'>\n\ + <Pgf\n\ + <PgfAlignment Center>\n\ + <PgfFont \n\ + <FTag `'>\n\ + <FFamily `Times'>\n\ + <FVar `Regular'>\n\ + <FWeight `Regular'>\n\ + <FAngle `Regular'>\n\ + <FPostScriptName `Times-Roman'>\n\ + <FEncoding `FrameRoman'>\n\ + <FSize 11.0 pt>\n\ + <FUnderlining FNoUnderlining>\n\ + <FOverline No>\n\ + <FStrike No>\n\ + <FChangeBar No>\n\ + <FOutline No>\n\ + <FShadow No>\n\ + <FPairKern Yes>\n\ + <FTsume No>\n\ + <FCase FAsTyped>\n\ + <FPosition FNormal>\n\ + <FDX 0.0%>\n\ + <FDY 0.0%>\n\ + <FDW 0.0%>\n\ + <FStretch 100.0%>\n\ + <FLanguage USEnglish>\n\ + <FLocked No>\n\ + <FSeparation 0>\n\ + <FColor `Black'>\n\ + > # end of PgfFont\n\ + >\n\ + <ParaLine\n\ + <String `State'>\n\ + > # end of ParaLine\n\ + > # end of Para\n\ + > # end of CellContent\n\ + > # end of Cell\n\ + <Cell\n\ + <CellLRuling `Medium'>\n\ + <CellBRuling `Medium'>\n\ + <CellRRuling `Medium'>\n\ + <CellTRuling `Medium'>\n\ + <CellContent\n\ + <Para\n\ + <PgfTag `CellHeading'>\n\ + <PgfFont \n\ + <FTag `'>\n\ + <FFamily `Times'>\n\ + <FVar `Regular'>\n\ + <FWeight `Regular'>\n\ + <FAngle `Regular'>\n\ + <FPostScriptName `Times-Roman'>\n\ + <FEncoding `FrameRoman'>\n\ + <FSize 11.0 pt>\n\ + <FUnderlining FNoUnderlining>\n\ + <FOverline No>\n\ + <FStrike No>\n\ + <FChangeBar No>\n\ + <FOutline No>\n\ + <FShadow No>\n\ + <FPairKern Yes>\n\ + <FTsume No>\n\ + <FCase FAsTyped>\n\ + <FPosition FNormal>\n\ + <FDX 0.0%>\n\ + <FDY 0.0%>\n\ + <FDW 0.0%>\n\ + <FStretch 100.0%>\n\ + <FLanguage USEnglish>\n\ + <FLocked No>\n\ + <FSeparation 0>\n\ + <FColor `Black'>\n\ + > # end of PgfFont\n\ + <ParaLine\n\ + <String `Description'>\n\ + > # end of ParaLine\n\ + > # end of Para\n\ + > # end of CellContent\n\ + > # end of Cell\n\ + > # end of Row\n\ + > # end of TblH\n\ +\n\ + <TblBody\n\ +"; + + const string row_before_state = +" <Row\n\ + <RowMaxHeight 14.0\">\n\ + <RowHeight 0.22222\">\n\ + <Cell\n\ + <CellContent\n\ + <Para\n\ + <PgfTag `CellBody'>\n\ + <Pgf\n\ + <PgfAlignment Center>\n\ + <PgfFont \n\ + <FTag `'>\n\ + <FFamily `Times'>\n\ + <FVar `Regular'>\n\ + <FWeight `Regular'>\n\ + <FAngle `Regular'>\n\ + <FPostScriptName `Times-Roman'>\n\ + <FEncoding `FrameRoman'>\n\ + <FSize 11.0 pt>\n\ + <FUnderlining FNoUnderlining>\n\ + <FOverline No>\n\ + <FStrike No>\n\ + <FChangeBar No>\n\ + <FOutline No>\n\ + <FShadow No>\n\ + <FPairKern Yes>\n\ + <FTsume No>\n\ + <FCase FAsTyped>\n\ + <FPosition FNormal>\n\ + <FDX 0.0%>\n\ + <FDY 0.0%>\n\ + <FDW 0.0%>\n\ + <FStretch 100.0%>\n\ + <FLanguage USEnglish>\n\ + <FLocked No>\n\ + <FSeparation 0>\n\ + <FColor `Black'>\n\ + > # end of PgfFont\n\ + >\n\ + <ParaLine\n\ + <String `"; + + const string row_between_state_desc = + "'>\n\ + > # end of ParaLine\n\ + > # end of Para\n\ + > # end of CellContent\n\ + > # end of Cell\n\ + <Cell\n\ + <CellContent\n\ + <Para\n\ + <PgfTag `CellBody'>\n\ + <ParaLine\n\ + <String `"; + + const string row_after_desc = + "'>\n\ + > # end of ParaLine\n\ + > # end of Para\n\ + > # end of CellContent\n\ + > # end of Cell\n\ + > # end of Row\n\ +"; + + const string mif_epilog = +" > # end of TblBody\n\ + > # end of Tbl\n\ +> # end of Tbls\n\ +\n\ + <Para\n\ + <ParaLine\n\ + <ATbl 1>\n\ + > # end of ParaLine\n\ + > # end of Para\n\ +\n\ +# End of MIFFile\n\ +"; + + out << mif_prolog1; + out << formatShorthand( sm.getShorthand() ); + out << " states"; + out << mif_prolog2; + + for( int i = 0; i < sm.numStates(); i++ ) + { + out << row_before_state; + out << formatShorthand( sm.getState( i ).getShorthand() ); + out << row_between_state_desc; + out << sm.getState( i ).getDescription(); + out << row_after_desc; + } + + out << mif_epilog; +} + + +void printEventTableMIF(const StateMachine& sm, ostream& out) +{ + const string mif_prolog1 = +"<MIFFile 5.50> # Generated by Multifacet MIF Mungers Inc\n\ +<Tbls\n\ + <Tbl\n\ + <TblID 1>\n\ + <TblTag `Format A'>\n\ + <TblFormat\n\ +\n\ + <TblAlignment Center>\n\ +\n\ + # <TblXColumnNum 0>\n\ + <TblXColumnRuling `Medium'>\n\ +\n\ + <TblLRuling `Medium'>\n\ + <TblRRuling `Medium'>\n\ + <TblTRuling `Medium'>\n\ + <TblBRuling `Medium'>\n\ +\n\ + <TblColumn\n\ + <TblColumnNum 0>\n\ + <TblColumnWidth 0.51\">\n\ + <TblColumnH\n\ + <PgfTag `CellHeading'>\n\ + > # end of TblColumnH\n\ + <TblColumnBody\n\ + <PgfTag `CellBody'>\n\ + > # end of TblColumnBody\n\ + <TblColumnF\n\ + <PgfTag `CellHeading'>\n\ + > # end of TblColumnF\n\ + > # end of TblColumn\n\ + <TblColumn\n\ + <TblColumnNum 1>\n\ + <TblColumnWidth 0.51\">\n\ + <TblColumnH\n\ + <PgfTag `CellHeading'>\n\ + > # end of TblColumnH\n\ + <TblColumnBody\n\ + <PgfTag `CellBody'>\n\ + > # end of TblColumnBody\n\ + <TblColumnF\n\ + <PgfTag `CellHeading'>\n\ + > # end of TblColumnF\n\ + > # end of TblColumn\n\ + > # end of TblFormat\n\ +\n\ + <TblNumColumns 2>\n\ + <TblColumnWidth 0.51\">\n\ + <TblColumnWidth 6.00\">\n\ + <TblTitle\n\ + <TblTitleContent\n\ + <Para\n\ + <PgfTag `TableTitle'>\n\ + <Pgf\n\ + <PgfAlignment Center>\n\ + <PgfFont \n\ + <FTag `'>\n\ + <FFamily `Times'>\n\ + <FVar `Regular'>\n\ + <FWeight `Regular'>\n\ + <FAngle `Regular'>\n\ + <FPostScriptName `Times-Roman'>\n\ + <FEncoding `FrameRoman'>\n\ + <FSize 11.0 pt>\n\ + <FUnderlining FNoUnderlining>\n\ + <FOverline No>\n\ + <FStrike No>\n\ + <FChangeBar No>\n\ + <FOutline No>\n\ + <FShadow No>\n\ + <FPairKern Yes>\n\ + <FTsume No>\n\ + <FCase FAsTyped>\n\ + <FPosition FNormal>\n\ + <FDX 0.0%>\n\ + <FDY 0.0%>\n\ + <FDW 0.0%>\n\ + <FStretch 100.0%>\n\ + <FLanguage USEnglish>\n\ + <FLocked No>\n\ + <FSeparation 0>\n\ + <FColor `Black'>\n\ + > # end of PgfFont\n\ + > # end of Pgf\n\ + <PgfNumString `TABLE 1. '>\n\ + <ParaLine\n\ + <Marker\n\ + <MType 9>\n\ + <MTypeName `Cross-Ref'>\n\ + <MCurrPage `1'>\n\ + > # end of Marker\n\ + <String `"; + const string mif_prolog2 = +"'>\n\ + > # end of ParaLine\n\ + > # end of Para\n\ + > # end of TblTitleContent\n\ + > # end of TblTitle\n\ +\n\ + <TblH\n\ + <Row\n\ + <RowMaxHeight 14.0\">\n\ + <RowHeight 0.44444\">\n\ + <Cell\n\ + <CellLRuling `Medium'>\n\ + <CellBRuling `Medium'>\n\ + <CellRRuling `Medium'>\n\ + <CellTRuling `Medium'>\n\ + <CellContent\n\ + <Para\n\ + <PgfTag `CellHeading'>\n\ + <PgfFont \n\ + <FTag `'>\n\ + <FFamily `Times'>\n\ + <FVar `Regular'>\n\ + <FWeight `Regular'>\n\ + <FAngle `Regular'>\n\ + <FPostScriptName `Times-Roman'>\n\ + <FEncoding `FrameRoman'>\n\ + <FSize 11.0 pt>\n\ + <FUnderlining FNoUnderlining>\n\ + <FOverline No>\n\ + <FStrike No>\n\ + <FChangeBar No>\n\ + <FOutline No>\n\ + <FShadow No>\n\ + <FPairKern Yes>\n\ + <FTsume No>\n\ + <FCase FAsTyped>\n\ + <FPosition FNormal>\n\ + <FDX 0.0%>\n\ + <FDY 0.0%>\n\ + <FDW 0.0%>\n\ + <FStretch 100.0%>\n\ + <FLanguage USEnglish>\n\ + <FLocked No>\n\ + <FSeparation 0>\n\ + <FColor `Black'>\n\ + > # end of PgfFont\n\ + <Pgf\n\ + <PgfAlignment Center>\n\ + <PgfFont \n\ + <FTag `'>\n\ + <FFamily `Times'>\n\ + <FVar `Regular'>\n\ + <FWeight `Regular'>\n\ + <FAngle `Regular'>\n\ + <FPostScriptName `Times-Roman'>\n\ + <FEncoding `FrameRoman'>\n\ + <FSize 11.0 pt>\n\ + <FUnderlining FNoUnderlining>\n\ + <FOverline No>\n\ + <FStrike No>\n\ + <FChangeBar No>\n\ + <FOutline No>\n\ + <FShadow No>\n\ + <FPairKern Yes>\n\ + <FTsume No>\n\ + <FCase FAsTyped>\n\ + <FPosition FNormal>\n\ + <FDX 0.0%>\n\ + <FDY 0.0%>\n\ + <FDW 0.0%>\n\ + <FStretch 100.0%>\n\ + <FLanguage USEnglish>\n\ + <FLocked No>\n\ + <FSeparation 0>\n\ + <FColor `Black'>\n\ + > # end of PgfFont\n\ + >\n\ + <ParaLine\n\ + <String `Event'>\n\ + > # end of ParaLine\n\ + > # end of Para\n\ + > # end of CellContent\n\ + > # end of Cell\n\ + <Cell\n\ + <CellLRuling `Medium'>\n\ + <CellBRuling `Medium'>\n\ + <CellRRuling `Medium'>\n\ + <CellTRuling `Medium'>\n\ + <CellContent\n\ + <Para\n\ + <PgfTag `CellHeading'>\n\ + <ParaLine\n\ + <String `Description'>\n\ + > # end of ParaLine\n\ + > # end of Para\n\ + > # end of CellContent\n\ + > # end of Cell\n\ + > # end of Row\n\ + > # end of TblH\n\ +\n\ + <TblBody\n\ +"; + + const string row_before_event = +" <Row\n\ + <RowMaxHeight 14.0\">\n\ + <RowHeight 0.22222\">\n\ + <Cell\n\ + <CellContent\n\ + <Para\n\ + <PgfTag `CellBody'>\n\ + <Pgf\n\ + <PgfAlignment Center>\n\ + <PgfFont \n\ + <FTag `'>\n\ + <FFamily `Times'>\n\ + <FVar `Regular'>\n\ + <FWeight `Regular'>\n\ + <FAngle `Regular'>\n\ + <FPostScriptName `Times-Roman'>\n\ + <FEncoding `FrameRoman'>\n\ + <FSize 11.0 pt>\n\ + <FUnderlining FNoUnderlining>\n\ + <FOverline No>\n\ + <FStrike No>\n\ + <FChangeBar No>\n\ + <FOutline No>\n\ + <FShadow No>\n\ + <FPairKern Yes>\n\ + <FTsume No>\n\ + <FCase FAsTyped>\n\ + <FPosition FNormal>\n\ + <FDX 0.0%>\n\ + <FDY 0.0%>\n\ + <FDW 0.0%>\n\ + <FStretch 100.0%>\n\ + <FLanguage USEnglish>\n\ + <FLocked No>\n\ + <FSeparation 0>\n\ + <FColor `Black'>\n\ + > # end of PgfFont\n\ + >\n\ + <ParaLine\n\ + <String `"; + + const string row_between_event_desc = + "'>\n\ + > # end of ParaLine\n\ + > # end of Para\n\ + > # end of CellContent\n\ + > # end of Cell\n\ + <Cell\n\ + <CellContent\n\ + <Para\n\ + <PgfTag `CellBody'>\n\ + <ParaLine\n\ + <String `"; + + const string row_after_desc = + "'>\n\ + > # end of ParaLine\n\ + > # end of Para\n\ + > # end of CellContent\n\ + > # end of Cell\n\ + > # end of Row\n\ +"; + + const string mif_epilog = +" > # end of TblBody\n\ + > # end of Tbl\n\ +> # end of Tbls\n\ +\n\ + <Para\n\ + <ParaLine\n\ + <ATbl 1>\n\ + > # end of ParaLine\n\ + > # end of Para\n\ +\n\ +# End of MIFFile\n\ +"; + + out << mif_prolog1; + out << formatShorthand( sm.getShorthand() ); + out << " events"; + out << mif_prolog2; + + for( int i = 0; i < sm.numEvents(); i++ ) + { + out << row_before_event; + out << formatShorthand( sm.getEvent( i ).getShorthand() ); + out << row_between_event_desc; + out << sm.getEvent( i ).getDescription(); + out << row_after_desc; + } + + out << mif_epilog; +} + + +void printActionTableMIF(const StateMachine& sm, ostream& out) +{ + const string mif_prolog1 = +"<MIFFile 5.50> # Generated by Multifacet MIF Mungers Inc\n\ +<Tbls\n\ + <Tbl\n\ + <TblID 1>\n\ + <TblTag `Format A'>\n\ + <TblFormat\n\ +\n\ + <TblAlignment Center>\n\ +\n\ + # <TblXColumnNum 0>\n\ + <TblXColumnRuling `Medium'>\n\ +\n\ + <TblLRuling `Medium'>\n\ + <TblRRuling `Medium'>\n\ + <TblTRuling `Medium'>\n\ + <TblBRuling `Medium'>\n\ +\n\ + <TblColumn\n\ + <TblColumnNum 0>\n\ + <TblColumnWidth 0.51\">\n\ + <TblColumnH\n\ + <PgfTag `CellHeading'>\n\ + > # end of TblColumnH\n\ + <TblColumnBody\n\ + <PgfTag `CellBody'>\n\ + > # end of TblColumnBody\n\ + <TblColumnF\n\ + <PgfTag `CellHeading'>\n\ + > # end of TblColumnF\n\ + > # end of TblColumn\n\ + <TblColumn\n\ + <TblColumnNum 1>\n\ + <TblColumnWidth 0.51\">\n\ + <TblColumnH\n\ + <PgfTag `CellHeading'>\n\ + > # end of TblColumnH\n\ + <TblColumnBody\n\ + <PgfTag `CellBody'>\n\ + > # end of TblColumnBody\n\ + <TblColumnF\n\ + <PgfTag `CellHeading'>\n\ + > # end of TblColumnF\n\ + > # end of TblColumn\n\ + > # end of TblFormat\n\ +\n\ + <TblNumColumns 2>\n\ + <TblColumnWidth 0.51\">\n\ + <TblColumnWidth 6.00\">\n\ + <TblTitle\n\ + <TblTitleContent\n\ + <Para\n\ + <PgfTag `TableTitle'>\n\ + <Pgf\n\ + <PgfAlignment Center>\n\ + <PgfFont \n\ + <FTag `'>\n\ + <FFamily `Times'>\n\ + <FVar `Regular'>\n\ + <FWeight `Regular'>\n\ + <FAngle `Regular'>\n\ + <FPostScriptName `Times-Roman'>\n\ + <FEncoding `FrameRoman'>\n\ + <FSize 11.0 pt>\n\ + <FUnderlining FNoUnderlining>\n\ + <FOverline No>\n\ + <FStrike No>\n\ + <FChangeBar No>\n\ + <FOutline No>\n\ + <FShadow No>\n\ + <FPairKern Yes>\n\ + <FTsume No>\n\ + <FCase FAsTyped>\n\ + <FPosition FNormal>\n\ + <FDX 0.0%>\n\ + <FDY 0.0%>\n\ + <FDW 0.0%>\n\ + <FStretch 100.0%>\n\ + <FLanguage USEnglish>\n\ + <FLocked No>\n\ + <FSeparation 0>\n\ + <FColor `Black'>\n\ + > # end of PgfFont\n\ + > # end of Pgf\n\ + <PgfNumString `TABLE 1. '>\n\ + <ParaLine\n\ + <Marker\n\ + <MType 9>\n\ + <MTypeName `Cross-Ref'>\n\ + <MCurrPage `1'>\n\ + > # end of Marker\n\ + <String `"; + const string mif_prolog2 = +"'>\n\ + > # end of ParaLine\n\ + > # end of Para\n\ + > # end of TblTitleContent\n\ + > # end of TblTitle\n\ +\n\ + <TblH\n\ + <Row\n\ + <RowMaxHeight 14.0\">\n\ + <RowHeight 0.44444\">\n\ + <Cell\n\ + <CellLRuling `Medium'>\n\ + <CellBRuling `Medium'>\n\ + <CellRRuling `Medium'>\n\ + <CellTRuling `Medium'>\n\ + <CellContent\n\ + <Para\n\ + <PgfTag `CellHeading'>\n\ + <Pgf\n\ + <PgfAlignment Center>\n\ + <PgfFont \n\ + <FTag `'>\n\ + <FFamily `Times'>\n\ + <FVar `Regular'>\n\ + <FWeight `Regular'>\n\ + <FAngle `Regular'>\n\ + <FPostScriptName `Times-Roman'>\n\ + <FEncoding `FrameRoman'>\n\ + <FSize 11.0 pt>\n\ + <FUnderlining FNoUnderlining>\n\ + <FOverline No>\n\ + <FStrike No>\n\ + <FChangeBar No>\n\ + <FOutline No>\n\ + <FShadow No>\n\ + <FPairKern Yes>\n\ + <FTsume No>\n\ + <FCase FAsTyped>\n\ + <FPosition FNormal>\n\ + <FDX 0.0%>\n\ + <FDY 0.0%>\n\ + <FDW 0.0%>\n\ + <FStretch 100.0%>\n\ + <FLanguage USEnglish>\n\ + <FLocked No>\n\ + <FSeparation 0>\n\ + <FColor `Black'>\n\ + > # end of PgfFont\n\ + >\n\ + <ParaLine\n\ + <String `Action'>\n\ + > # end of ParaLine\n\ + > # end of Para\n\ + > # end of CellContent\n\ + > # end of Cell\n\ + <Cell\n\ + <CellLRuling `Medium'>\n\ + <CellBRuling `Medium'>\n\ + <CellRRuling `Medium'>\n\ + <CellTRuling `Medium'>\n\ + <CellContent\n\ + <Para\n\ + <PgfTag `CellHeading'>\n\ + <ParaLine\n\ + <String `Description'>\n\ + > # end of ParaLine\n\ + > # end of Para\n\ + > # end of CellContent\n\ + > # end of Cell\n\ + > # end of Row\n\ + > # end of TblH\n\ +\n\ + <TblBody\n\ +"; + + const string row_before_action = +" <Row\n\ + <RowMaxHeight 14.0\">\n\ + <RowHeight 0.22222\">\n\ + <Cell\n\ + <CellContent\n\ + <Para\n\ + <PgfTag `CellBody'>\n\ + <Pgf\n\ + <PgfAlignment Center>\n\ + <PgfFont \n\ + <FTag `'>\n\ + <FFamily `Times'>\n\ + <FVar `Regular'>\n\ + <FWeight `Regular'>\n\ + <FAngle `Regular'>\n\ + <FPostScriptName `Times-Roman'>\n\ + <FEncoding `FrameRoman'>\n\ + <FSize 11.0 pt>\n\ + <FUnderlining FNoUnderlining>\n\ + <FOverline No>\n\ + <FStrike No>\n\ + <FChangeBar No>\n\ + <FOutline No>\n\ + <FShadow No>\n\ + <FPairKern Yes>\n\ + <FTsume No>\n\ + <FCase FAsTyped>\n\ + <FPosition FNormal>\n\ + <FDX 0.0%>\n\ + <FDY 0.0%>\n\ + <FDW 0.0%>\n\ + <FStretch 100.0%>\n\ + <FLanguage USEnglish>\n\ + <FLocked No>\n\ + <FSeparation 0>\n\ + <FColor `Black'>\n\ + > # end of PgfFont\n\ + >\n\ + <ParaLine\n\ + <String `"; + + const string row_between_action_desc = + "'>\n\ + > # end of ParaLine\n\ + > # end of Para\n\ + > # end of CellContent\n\ + > # end of Cell\n\ + <Cell\n\ + <CellContent\n\ + <Para\n\ + <PgfTag `CellBody'>\n\ + <ParaLine\n\ + <String `"; + + const string row_after_desc = + "'>\n\ + > # end of ParaLine\n\ + > # end of Para\n\ + > # end of CellContent\n\ + > # end of Cell\n\ + > # end of Row\n\ +"; + + const string mif_epilog = +" > # end of TblBody\n\ + > # end of Tbl\n\ +> # end of Tbls\n\ +\n\ + <Para\n\ + <ParaLine\n\ + <ATbl 1>\n\ + > # end of ParaLine\n\ + > # end of Para\n\ +\n\ +# End of MIFFile\n\ +"; + + out << mif_prolog1; + out << formatShorthand( sm.getShorthand() ); + out << " actions"; + out << mif_prolog2; + + for( int i = 0; i < sm.numActions(); i++ ) + { + out << row_before_action; + out << formatShorthand( sm.getAction( i ).getShorthand() ); + out << row_between_action_desc; + out << sm.getAction( i ).getDescription(); + out << row_after_desc; + } + + out << mif_epilog; +} + + +void printTransitionTableMIF(const StateMachine& sm, ostream& out) +{ + const string mif_prolog = +"<MIFFile 5.50> # Generated by Multifacet MIF Mungers Inc\n\ +<Tbls\n\ + <Tbl\n\ + <TblID 1>\n\ + <TblTag `Format A'>\n\ + <TblFormat\n\ +\n\ + <TblAlignment Center>\n\ +\n\ + # <TblXColumnNum 0>\n\ + <TblXColumnRuling `Medium'>\n\ +\n\ + <TblLRuling `Medium'>\n\ + <TblRRuling `Medium'>\n\ + <TblTRuling `Medium'>\n\ + <TblBRuling `Medium'>\n\ + \n\ +"; + + const string tbl_fmt_before_col_num = +" <TblColumn\n\ + <TblColumnNum "; + + const string tbl_fmt_after_col_num = + ">\n\ + <TblColumnWidth 0.51\">\n\ + <TblColumnH\n\ + <PgfTag `CellHeading'>\n\ + > # end of TblColumnH\n\ + <TblColumnBody\n\ + <PgfTag `CellBody'>\n\ + > # end of TblColumnBody\n\ + <TblColumnF\n\ + <PgfTag `CellHeading'>\n\ + > # end of TblColumnF\n\ + > # end of TblColumn\n\ +"; + + const string tbl_fmt_before_num_cols = +" > # end of TblFormat\n\ +\n\ + <TblNumColumns "; + + const string tbl_fmt_each_col_width_begin = + ">\n\ + <TblColumnWidth "; + + const string tbl_fmt_each_col_width_end = "\""; + + const string tbl_before_first_header1 = + ">\n\ + <TblTitle\n\ + <TblTitleContent\n\ + <Para\n\ + <PgfTag `TableTitle'>\n\ + <Pgf\n\ + <PgfAlignment Center>\n\ + <PgfFont \n\ + <FTag `'>\n\ + <FFamily `Times'>\n\ + <FVar `Regular'>\n\ + <FWeight `Regular'>\n\ + <FAngle `Regular'>\n\ + <FPostScriptName `Times-Roman'>\n\ + <FEncoding `FrameRoman'>\n\ + <FSize 11.0 pt>\n\ + <FUnderlining FNoUnderlining>\n\ + <FOverline No>\n\ + <FStrike No>\n\ + <FChangeBar No>\n\ + <FOutline No>\n\ + <FShadow No>\n\ + <FPairKern Yes>\n\ + <FTsume No>\n\ + <FCase FAsTyped>\n\ + <FPosition FNormal>\n\ + <FDX 0.0%>\n\ + <FDY 0.0%>\n\ + <FDW 0.0%>\n\ + <FStretch 100.0%>\n\ + <FLanguage USEnglish>\n\ + <FLocked No>\n\ + <FSeparation 0>\n\ + <FColor `Black'>\n\ + > # end of PgfFont\n\ + > # end of Pgf\n\ + <PgfNumString `TABLE 1. '>\n\ + <ParaLine\n\ + <Marker\n\ + <MType 9>\n\ + <MTypeName `Cross-Ref'>\n\ + <MCurrPage `1'>\n\ + > # end of Marker\n\ + <String `"; + + const string tbl_before_first_header2 = + "'>\n\ + > # end of ParaLine\n\ + > # end of Para\n\ + > # end of TblTitleContent\n\ + > # end of TblTitle\n\ +\n\ + <TblH\n\ + <Row\n\ + <RowMaxHeight 14.0\">\n\ + <RowHeight 0.44444\">"; + + const string tbl_before_each_header = +" <Cell\n\ + <CellLRuling `Medium'>\n\ + <CellBRuling `Medium'>\n\ + <CellRRuling `Medium'>\n\ + <CellTRuling `Medium'>\n\ + <CellContent\n\ + <Para\n\ + <PgfTag `CellHeading'>\n\ + <Pgf\n\ + <PgfAlignment Center>\n\ + <PgfFont \n\ + <FTag `'>\n\ + <FFamily `Times'>\n\ + <FVar `Regular'>\n\ + <FWeight `Regular'>\n\ + <FAngle `Regular'>\n\ + <FPostScriptName `Times-Roman'>\n\ + <FEncoding `FrameRoman'>\n\ + <FSize 11.0 pt>\n\ + <FUnderlining FNoUnderlining>\n\ + <FOverline No>\n\ + <FStrike No>\n\ + <FChangeBar No>\n\ + <FOutline No>\n\ + <FShadow No>\n\ + <FPairKern Yes>\n\ + <FTsume No>\n\ + <FCase FAsTyped>\n\ + <FPosition FNormal>\n\ + <FDX 0.0%>\n\ + <FDY 0.0%>\n\ + <FDW 0.0%>\n\ + <FStretch 100.0%>\n\ + <FLanguage USEnglish>\n\ + <FLocked No>\n\ + <FSeparation 0>\n\ + <FColor `Black'>\n\ + > # end of PgfFont\n\ + >\n\ + <ParaLine\n\ + <String `"; + + const string tbl_before_each_rot_header = +" <Cell\n\ + <CellLRuling `Medium'>\n\ + <CellBRuling `Medium'>\n\ + <CellRRuling `Medium'>\n\ + <CellTRuling `Medium'>\n\ + <CellAngle 270>\n\ + <CellContent\n\ + <Para\n\ + <PgfTag `CellHeading'>\n\ + <ParaLine\n\ + <String `"; + + const string tbl_after_each_header = + "'>\n\ + > # end of ParaLine\n\ + > # end of Para\n\ + > # end of CellContent\n\ + > # end of Cell\n\ +"; + + const string before_first_row = +" > # end of Row\n\ + > # end of TblH\n\ +\n\ + <TblBody\n\ +"; + + const string row_before_first_cell = +" <Row\n\ + <RowMaxHeight 14.0\">\n\ + <RowHeight 0.22222\">"; + + const string row_cell_before_ruling = +" <Cell\n\ +"; + + const string row_cell_before_contents = +" <CellContent\n\ + <Para\n\ + <PgfTag `CellBody'>\n\ + <Pgf\n\ + <PgfAlignment Center>\n\ + <PgfFont \n\ + <FTag `'>\n\ + <FFamily `Times'>\n\ + <FVar `Regular'>\n\ + <FWeight `Regular'>\n\ + <FAngle `Regular'>\n\ + <FPostScriptName `Times-Roman'>\n\ + <FEncoding `FrameRoman'>\n\ + <FSize 11.0 pt>\n\ + <FUnderlining FNoUnderlining>\n\ + <FOverline No>\n\ + <FStrike No>\n\ + <FChangeBar No>\n\ + <FOutline No>\n\ + <FShadow No>\n\ + <FPairKern Yes>\n\ + <FTsume No>\n\ + <FCase FAsTyped>\n\ + <FPosition FNormal>\n\ + <FDX 0.0%>\n\ + <FDY 0.0%>\n\ + <FDW 0.0%>\n\ + <FStretch 100.0%>\n\ + <FLanguage USEnglish>\n\ + <FLocked No>\n\ + <FSeparation 0>\n\ + <FColor `Black'>\n\ + > # end of PgfFont\n\ + >\n\ + <ParaLine\n\ + <String `"; + + const string row_cell_after_contents = + "'>\n\ + > # end of ParaLine\n\ + > # end of Para\n\ + > # end of CellContent\n\ + > # end of Cell\n\ +"; + + const string row_empty_cell = +" <CellFill 5>\n\ + <CellColor `Cyan'>\n\ + <CellContent\n\ + <Para\n\ + <PgfTag `CellBody'>\n\ + <ParaLine\n\ + <String `'>\n\ + > # end of ParaLine\n\ + > # end of Para\n\ + > # end of CellContent\n\ + > # end of Cell\n\ +"; + + const string row_after_last_cell = +" > # end of Row\n\ +"; + + + const string mif_epilog = +" > # end of TblBody\n\ + > # end of Tbl\n\ +> # end of Tbls\n\ +\n\ + <Para\n\ + <ParaLine\n\ + <ATbl 1>\n\ + > # end of ParaLine\n\ + > # end of Para\n\ +\n\ +# End of MIFFile\n\ +"; + + int i, j, num_rows, num_cols; + string row_ruling; + string col_ruling; + + num_rows = sm.numStates(); + num_cols = sm.numEvents() + 1; + + // -- Prolog + out << mif_prolog; + + // -- Table format (for each column) + for( i = 0; i < num_cols; i++ ) + { + out << tbl_fmt_before_col_num; + out << i; + out << tbl_fmt_after_col_num; + } + + // -- Spell out width of each column + + // -- FIXME: make following constants into parameters + const float total_table_width = 7.5; // -- Total page width = 7.5" (portrait mode) + const float min_col_width = 0.35; // -- Min col width (for legibility) + const float max_col_width = 0.75; // -- Max col width (for aesthetics) + float column_width; + + // -- Calculate column width and clamp it within a range + column_width = total_table_width / num_cols; + column_width = ((column_width < min_col_width) + ? min_col_width + : ((column_width > max_col_width) + ? max_col_width + : column_width)); + + out << tbl_fmt_before_num_cols; + out << num_cols; + for( i = 0; i < num_cols; i++ ) + { + out << tbl_fmt_each_col_width_begin << column_width << tbl_fmt_each_col_width_end; + } + + // -- Column headers + out << tbl_before_first_header1; + out << formatShorthand( sm.getShorthand() ); + out << " transitions"; + out << tbl_before_first_header2; + + out << tbl_before_each_header; + out << "State"; + out << tbl_after_each_header; + + for( i = 0; i < sm.numEvents(); i++ ) + { + out << tbl_before_each_rot_header; + out << formatShorthand( sm.getEvent(i).getShorthand() ); + out << tbl_after_each_header; + } + out << before_first_row; + + + // -- Body of table + for( i = 0; i < num_rows; i++ ) + { + // -- Each row + out << row_before_first_cell; + + // -- Figure out ruling + if (sm.getState(i).existPair("format")) { + row_ruling = formatCellRuling( sm.getState(i).lookupPair("format")); + } else { + row_ruling = ""; + } + + // -- First column = state + out << row_cell_before_ruling; + out << row_ruling; + out << row_cell_before_contents; + out << formatShorthand( sm.getState(i).getShorthand() ); + out << row_cell_after_contents; + + // -- One column for each event + for( j = 0; j < sm.numEvents(); j++ ) + { + const Transition* trans_ptr = sm.getTransPtr( i, j ); + + // -- Figure out ruling + if (sm.getEvent(j).existPair("format")) { + col_ruling = formatCellRuling(sm.getEvent(j).lookupPair("format")); + } else { + col_ruling = ""; + } + + out << row_cell_before_ruling; + out << row_ruling; + out << col_ruling; + + if( trans_ptr != NULL ) + { + string actions; + string nextState; + + // -- Get the actions + actions = formatShorthand( trans_ptr->getActionShorthands() ); + + // -- Get the next state + // FIXME: should compare index, not the string + if (trans_ptr->getNextStateShorthand() != + sm.getState(i).getShorthand() ) + { + nextState = formatShorthand( trans_ptr->getNextStateShorthand() ); + } else + { + nextState = ""; + } + + // -- Print out "actions/next-state" + out << row_cell_before_contents; + out << actions; + if ((nextState.length() != 0) && (actions.length() != 0)) { + out << "/"; + } + out << nextState; + out << row_cell_after_contents; + } + else + { + out << row_empty_cell; + } + + } + + out << row_after_last_cell; + } + + // -- Epilog + out << mif_epilog; + +} +/* +void printTBETableMIF(const StateMachine& sm, const Vector<Field>& fields, ostream& out) +{ + const string mif_prolog1 = +"<MIFFile 5.50> # Generated by Multifacet MIF Mungers Inc\n\ +<Tbls\n\ + <Tbl\n\ + <TblID 1>\n\ + <TblTag `Format A'>\n\ + <TblFormat\n\ +\n\ + <TblAlignment Center>\n\ +\n\ + # # <TblXColumnNum 0>\n\ + <TblXColumnRuling `Medium'>\n\ +\n\ + <TblLRuling `Medium'>\n\ + <TblRRuling `Medium'>\n\ + <TblTRuling `Medium'>\n\ + <TblBRuling `Medium'>\n\ +\n\ + <TblColumn\n\ + <TblColumnNum 0>\n\ + <TblColumnWidth 0.51\">\n\ + <TblColumnH\n\ + <PgfTag `CellHeading'>\n\ + > # end of TblColumnH\n\ + <TblColumnBody\n\ + <PgfTag `CellBody'>\n\ + > # end of TblColumnBody\n\ + <TblColumnF\n\ + <PgfTag `CellHeading'>\n\ + > # end of TblColumnF\n\ + > # end of TblColumn\n\ + <TblColumn\n\ + <TblColumnNum 1>\n\ + <TblColumnWidth 0.51\">\n\ + <TblColumnH\n\ + <PgfTag `CellHeading'>\n\ + > # end of TblColumnH\n\ + <TblColumnBody\n\ + <PgfTag `CellBody'>\n\ + > # end of TblColumnBody\n\ + <TblColumnF\n\ + <PgfTag `CellHeading'>\n\ + > # end of TblColumnF\n\ + > # end of TblColumn\n\ + > # end of TblFormat\n\ +\n\ + <TblNumColumns 2>\n\ + <TblColumnWidth 0.51\">\n\ + <TblColumnWidth 6.00\">\n\ + <TblTitle\n\ + <TblTitleContent\n\ + <Para\n\ + <PgfTag `TableTitle'>\n\ + <Pgf\n\ + <PgfAlignment Center>\n\ + <PgfFont \n\ + <FTag `'>\n\ + <FFamily `Times'>\n\ + <FVar `Regular'>\n\ + <FWeight `Regular'>\n\ + <FAngle `Regular'>\n\ + <FPostScriptName `Times-Roman'>\n\ + <FEncoding `FrameRoman'>\n\ + <FSize 11.0 pt>\n\ + <FUnderlining FNoUnderlining>\n\ + <FOverline No>\n\ + <FStrike No>\n\ + <FChangeBar No>\n\ + <FOutline No>\n\ + <FShadow No>\n\ + <FPairKern Yes>\n\ + <FTsume No>\n\ + <FCase FAsTyped>\n\ + <FPosition FNormal>\n\ + <FDX 0.0%>\n\ + <FDY 0.0%>\n\ + <FDW 0.0%>\n\ + <FStretch 100.0%>\n\ + <FLanguage USEnglish>\n\ + <FLocked No>\n\ + <FSeparation 0>\n\ + <FColor `Black'>\n\ + > # end of PgfFont\n\ + > # end of Pgf\n\ + <PgfNumString `TABLE 1. '>\n\ + <ParaLine\n\ + <Marker\n\ + <MType 9>\n\ + <MTypeName `Cross-Ref'>\n\ + <MCurrPage `1'>\n\ + > # end of Marker\n\ + <String `"; + + const string mif_prolog2 = + "'>\n\ + > # end of ParaLine\n\ + > # end of Para\n\ + > # end of TblTitleContent\n\ + > # end of TblTitle\n\ +\n\ + <TblH\n\ + <Row\n\ + <RowMaxHeight 14.0\">\n\ + <RowHeight 0.44444\">\n\ + <Cell\n\ + <CellLRuling `Medium'>\n\ + <CellBRuling `Medium'>\n\ + <CellRRuling `Medium'>\n\ + <CellTRuling `Medium'>\n\ + <CellContent\n\ + <Para\n\ + <PgfTag `CellHeading'>\n\ + <Pgf\n\ + <PgfAlignment Center>\n\ + <PgfFont \n\ + <FTag `'>\n\ + <FFamily `Times'>\n\ + <FVar `Regular'>\n\ + <FWeight `Regular'>\n\ + <FAngle `Regular'>\n\ + <FPostScriptName `Times-Roman'>\n\ + <FEncoding `FrameRoman'>\n\ + <FSize 11.0 pt>\n\ + <FUnderlining FNoUnderlining>\n\ + <FOverline No>\n\ + <FStrike No>\n\ + <FChangeBar No>\n\ + <FOutline No>\n\ + <FShadow No>\n\ + <FPairKern Yes>\n\ + <FTsume No>\n\ + <FCase FAsTyped>\n\ + <FPosition FNormal>\n\ + <FDX 0.0%>\n\ + <FDY 0.0%>\n\ + <FDW 0.0%>\n\ + <FStretch 100.0%>\n\ + <FLanguage USEnglish>\n\ + <FLocked No>\n\ + <FSeparation 0>\n\ + <FColor `Black'>\n\ + > # end of PgfFont\n\ + >\n\ + <ParaLine\n\ + <String `Field'>\n\ + > # end of ParaLine\n\ + > # end of Para\n\ + > # end of CellContent\n\ + > # end of Cell\n\ + <Cell\n\ + <CellLRuling `Medium'>\n\ + <CellBRuling `Medium'>\n\ + <CellRRuling `Medium'>\n\ + <CellTRuling `Medium'>\n\ + <CellContent\n\ + <Para\n\ + <PgfTag `CellHeading'>\n\ + <PgfFont \n\ + <FTag `'>\n\ + <FFamily `Times'>\n\ + <FVar `Regular'>\n\ + <FWeight `Regular'>\n\ + <FAngle `Regular'>\n\ + <FPostScriptName `Times-Roman'>\n\ + <FEncoding `FrameRoman'>\n\ + <FSize 11.0 pt>\n\ + <FUnderlining FNoUnderlining>\n\ + <FOverline No>\n\ + <FStrike No>\n\ + <FChangeBar No>\n\ + <FOutline No>\n\ + <FShadow No>\n\ + <FPairKern Yes>\n\ + <FTsume No>\n\ + <FCase FAsTyped>\n\ + <FPosition FNormal>\n\ + <FDX 0.0%>\n\ + <FDY 0.0%>\n\ + <FDW 0.0%>\n\ + <FStretch 100.0%>\n\ + <FLanguage USEnglish>\n\ + <FLocked No>\n\ + <FSeparation 0>\n\ + <FColor `Black'>\n\ + > # end of PgfFont\n\ + <ParaLine\n\ + <String `Description'>\n\ + > # end of ParaLine\n\ + > # end of Para\n\ + > # end of CellContent\n\ + > # end of Cell\n\ + > # end of Row\n\ + > # end of TblH\n\ +\n\ + <TblBody\n\ +"; + + const string row_before_state = +" <Row\n\ + <RowMaxHeight 14.0\">\n\ + <RowHeight 0.22222\">\n\ + <Cell\n\ + <CellContent\n\ + <Para\n\ + <PgfTag `CellBody'>\n\ + <Pgf\n\ + <PgfAlignment Center>\n\ + <PgfFont \n\ + <FTag `'>\n\ + <FFamily `Times'>\n\ + <FVar `Regular'>\n\ + <FWeight `Regular'>\n\ + <FAngle `Regular'>\n\ + <FPostScriptName `Times-Roman'>\n\ + <FEncoding `FrameRoman'>\n\ + <FSize 11.0 pt>\n\ + <FUnderlining FNoUnderlining>\n\ + <FOverline No>\n\ + <FStrike No>\n\ + <FChangeBar No>\n\ + <FOutline No>\n\ + <FShadow No>\n\ + <FPairKern Yes>\n\ + <FTsume No>\n\ + <FCase FAsTyped>\n\ + <FPosition FNormal>\n\ + <FDX 0.0%>\n\ + <FDY 0.0%>\n\ + <FDW 0.0%>\n\ + <FStretch 100.0%>\n\ + <FLanguage USEnglish>\n\ + <FLocked No>\n\ + <FSeparation 0>\n\ + <FColor `Black'>\n\ + > # end of PgfFont\n\ + >\n\ + <ParaLine\n\ + <String `"; + + const string row_between_state_desc = + "'>\n\ + > # end of ParaLine\n\ + > # end of Para\n\ + > # end of CellContent\n\ + > # end of Cell\n\ + <Cell\n\ + <CellContent\n\ + <Para\n\ + <PgfTag `CellBody'>\n\ + <ParaLine\n\ + <String `"; + + const string row_after_desc = + "'>\n\ + > # end of ParaLine\n\ + > # end of Para\n\ + > # end of CellContent\n\ + > # end of Cell\n\ + > # end of Row\n\ +"; + + const string mif_epilog = +" > # end of TblBody\n\ + > # end of Tbl\n\ +> # end of Tbls\n\ +\n\ + <Para\n\ + <ParaLine\n\ + <ATbl 1>\n\ + > # end of ParaLine\n\ + > # end of Para\n\ +\n\ +# End of MIFFile\n\ +"; + + out << mif_prolog1; + out << sm.getShorthand(); + out << " TBE"; + out << mif_prolog2; + + for( int i = 0; i < fields.size(); i++ ) { + out << row_before_state; + out << formatShorthand(fields[i].getShorthand()); + out << row_between_state_desc; + out << fields[i].getDescription(); + out << row_after_desc; + } + + out << mif_epilog; +} +*/ +// -- +// -- Helper function to do some shorthand formatting (kludge before we +// -- get the tuple attributes into the state machine language. +// -- Current convention: +// -- - each `_' indicates a toggle between normal mode and superscript +// -- - each escaped (using `\') character indicates a letter formatted +// -- using the Symbol character set. \a = alpha, \b = beta, \c = chi etc. +// -- See the FrameMaker character sets manual in the Online Manuals. +// -- - a `!' indicates extra stuff at the end which can be ignored (used +// -- for determining cell ruling and so on) +// -- +string formatShorthand(const string shorthand) +{ + string munged_shorthand = ""; + bool mode_is_normal = true; + const string mif_superscript = "'> <Font <FPosition FSuperscript> <FLocked No> > <String `"; + const string mif_normal = "'> <Font <FPosition FNormal> <FLocked No> > <String `"; + const string mif_symbol = "'> <Font <FFamily `Symbol'> <FPostScriptName `Symbol'> <FEncoding `FrameRoman'> <FLocked No> > <String `"; + const string mif_times = "'> <Font <FFamily `Times'> <FPostScriptName `Times-Roman'> <FEncoding `FrameRoman'> <FLocked No> > <String `"; + + + // -- Walk over the string, processing superscript directives + for( unsigned int i = 0; i < shorthand.length(); i++ ) + { + if( shorthand[i] == '!' ) + { + // -- Reached logical end of shorthand name + break; + } + else if( shorthand[i] == '^' ) + { + // -- Process super/subscript formatting + + mode_is_normal = !mode_is_normal; + if( mode_is_normal ) + { + // -- Back to normal mode + munged_shorthand += mif_normal; + } + else + { + // -- Going to superscript mode + munged_shorthand += mif_superscript; + } + + } + else if( shorthand[i] == '\\' ) + { + // -- Process Symbol character set + if( (i + 1) < shorthand.length() ) + { + i++; // -- Proceed to next char. Yes I know that changing the loop var is ugly! + munged_shorthand += mif_symbol; + munged_shorthand += shorthand[i]; + munged_shorthand += mif_times; + } + else + { + // -- FIXME: Add line number info later + cerr << "Encountered a `\\` without anything following it!" << endl; + exit( -1 ); + } + + } + else + { + // -- Pass on un-munged + munged_shorthand += shorthand[i]; + } + + } // -- end for all characters in shorthand + + // -- Do any other munging + + // -- Return the formatted shorthand name + return munged_shorthand; +} + + +// -- +// -- Helper function to figure out where to put rules in the table (kludge before we +// -- get the tuple attributes into the shorthand machine language. +// -- Current convention: +// -- - a `!' in the shorthand indicates the beginning of ruling information +// -- - `b' => bottom of this row is ruled +// -- - `r' => right of this column is ruled +// -- +string formatCellRuling( const string shorthand) +{ + for( unsigned int i = 0; i < shorthand.length(); i++ ) + { + if( shorthand[i] == '!' ) + { + // -- OK, found beginning of ruling information + for( unsigned int j = i+1; j < shorthand.length(); j++ ) + { + if( shorthand[j] == 'b') + { + // -- Rule the bottom + return "<CellBRuling `Medium'>\n"; + } + else if( shorthand[j] == 'r') + { + // -- Rule the bottom + return "<CellRRuling `Medium'>\n"; + } + + } + + // -- No ruling directives recognized, return default ruling + return ""; + } + + } + + // -- No ruling information found, return default ruling + return ""; +} diff --git a/src/mem/slicc/generator/mif_gen.hh b/src/mem/slicc/generator/mif_gen.hh new file mode 100644 index 000000000..ba1dc0b0b --- /dev/null +++ b/src/mem/slicc/generator/mif_gen.hh @@ -0,0 +1,45 @@ + +/* + * Copyright (c) 1999-2008 Mark D. Hill and David A. Wood + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer; + * redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution; + * neither the name of the copyright holders nor the names of its + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +/* + * $Id: mif_gen.h,v 3.1 2001/12/12 01:00:35 milo Exp $ + * + */ + +#ifndef MIF_GEN_H +#define MIF_GEN_H + +#include "StateMachine.hh" + +void printStateTableMIF(const StateMachine& sm, ostream& out); +void printEventTableMIF(const StateMachine& sm, ostream& out); +void printActionTableMIF(const StateMachine& sm, ostream& out); +void printTransitionTableMIF(const StateMachine& sm, ostream& out); + +#endif //MIF_GEN_H diff --git a/src/mem/slicc/main.cc b/src/mem/slicc/main.cc new file mode 100644 index 000000000..acd9e73f9 --- /dev/null +++ b/src/mem/slicc/main.cc @@ -0,0 +1,246 @@ + +/* + * Copyright (c) 1999-2008 Mark D. Hill and David A. Wood + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer; + * redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution; + * neither the name of the copyright holders nor the names of its + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +/* + * $Id$ + * + * */ + +#include "main.hh" +#include "StateMachine.hh" +#include "mif_gen.hh" +#include "html_gen.hh" +#include "fileio.hh" +#include "DeclListAST.hh" +#include "Type.hh" +#include "SymbolTable.hh" +#include "Event.hh" +#include "State.hh" +#include "Action.hh" +#include "Transition.hh" + +// -- Main conversion functions + +void printDotty(const StateMachine& sm, ostream& out); +void printTexTable(const StateMachine& sm, ostream& out); + +DeclListAST* g_decl_list_ptr; +DeclListAST* parse(string filename); + +int main(int argc, char *argv[]) +{ + cerr << "SLICC v0.3" << endl; + + if (argc < 5) { + cerr << " Usage: generator.exec <code path> <html path> <ident> <html direction> files ... " << endl; + exit(1); + } + + // The path we should place the generated code + string code_path(argv[1]); + code_path += "/"; + + // The path we should place the generated html + string html_path(argv[2]); + html_path += "/"; + + string ident(argv[3]); + + string html_generate(argv[4]); + + Vector<DeclListAST*> decl_list_vec; + + // Parse + cerr << "Parsing..." << endl; + for(int i=5; i<argc; i++) { + cerr << " " << argv[i] << endl; + DeclListAST* decl_list_ptr = parse(argv[i]); + decl_list_vec.insertAtBottom(decl_list_ptr); + } + + // Find machines + cerr << "Generator pass 1..." << endl; + int size = decl_list_vec.size(); + for(int i=0; i<size; i++) { + DeclListAST* decl_list_ptr = decl_list_vec[i]; + decl_list_ptr->findMachines(); + } + + // Generate Code + cerr << "Generator pass 2..." << endl; + for(int i=0; i<size; i++) { + DeclListAST* decl_list_ptr = decl_list_vec[i]; + decl_list_ptr->generate(); + delete decl_list_ptr; + } + + // Generate C/C++ files + cerr << "Writing C files..." << endl; + + { + // Generate the name of the protocol + ostringstream sstr; + sstr << "// Auto generated C++ code started by "<<__FILE__<<":"<<__LINE__<<endl; + sstr << endl; + sstr << "#ifndef PROTOCOL_NAME_H" << endl; + sstr << "#define PROTOCOL_NAME_H" << endl; + sstr << endl; + sstr << "const char CURRENT_PROTOCOL[] = \""; + sstr << ident << "\";\n"; + sstr << "#endif // PROTOCOL_NAME_H" << endl; + conditionally_write_file(code_path + "/protocol_name.hh", sstr); + } + + g_sym_table.writeCFiles(code_path); + + // Generate HTML files + if (html_generate == "html") { + cerr << "Writing HTML files..." << endl; + g_sym_table.writeHTMLFiles(html_path); + } else if (html_generate == "no_html") { + cerr << "No HTML files generated" << endl; + } else { + cerr << "ERROR, unidentified html direction" << endl; + } + + cerr << "Done..." << endl; + + // Generate MIF files + cerr << "Writing MIF files..." << endl; + g_sym_table.writeMIFFiles(html_path); + + cerr << "Done..." << endl; + +} + /* + if(!strcmp(argv[2], "parse")) { + // Parse only + } else if(!strcmp(argv[2], "state")) { + printStateTableMIF(s, cout); + } else if(!strcmp( argv[2], "event")) { + printEventTableMIF(s, cout); + } else if(!strcmp( argv[2], "action")) { + printActionTableMIF(s, cout); + } else if(!strcmp( argv[2], "transition")) { + printTransitionTableMIF(s, cout); + } else if(!strcmp( argv[2], "tbe")) { + for(int i=0; i<s.numTypes(); i++) { + if (s.getType(i).getIdent() == "TBE") { + printTBETableMIF(s, s.getTypeFields(i), cout); + } + } + } else if(!strcmp( argv[2], "dot")) { + printDotty(s, cout); + } else if(!strcmp( argv[2], "latex")) { + printTexTable(s, cout); + } else if (!strcmp( argv[2], "murphi")) { + printMurphi(s, cout); + } else if (!strcmp( argv[2], "html")) { + printHTML(s); + } else if(!strcmp( argv[2], "code")) { + if (argc < 4) { + cerr << "Error: Wrong number of command line parameters!" << endl; + exit(1); + } + */ + + +void printDotty(const StateMachine& sm, ostream& out) +{ + out << "digraph " << sm.getIdent() << " {" << endl; + for(int i=0; i<sm.numTransitions(); i++) { + const Transition& t = sm.getTransition(i); + // Don't print ignored transitions + if ((t.getActionShorthands() != "--") && (t.getActionShorthands() != "z")) { + // if (t.getStateShorthand() != t.getNextStateShorthand()) { + out << " " << t.getStateShorthand() << " -> "; + out << t.getNextStateShorthand() << "[label=\""; + out << t.getEventShorthand() << "/" + << t.getActionShorthands() << "\"]" << endl; + } + } + out << "}" << endl; +} + +void printTexTable(const StateMachine& sm, ostream& out) +{ + const Transition* trans_ptr; + int stateIndex, eventIndex; + string actions; + string nextState; + + out << "%& latex" << endl; + out << "\\documentclass[12pt]{article}" << endl; + out << "\\usepackage{graphics}" << endl; + out << "\\begin{document}" << endl; + // out << "{\\large" << endl; + out << "\\begin{tabular}{|l||"; + for(eventIndex=0; eventIndex < sm.numEvents(); eventIndex++) { + out << "l"; + } + out << "|} \\hline" << endl; + + for(eventIndex=0; eventIndex < sm.numEvents(); eventIndex++) { + out << " & \\rotatebox{90}{"; + out << sm.getEvent(eventIndex).getShorthand(); + out << "}"; + } + out << "\\\\ \\hline \\hline" << endl; + + for(stateIndex=0; stateIndex < sm.numStates(); stateIndex++) { + out << sm.getState(stateIndex).getShorthand(); + for(eventIndex=0; eventIndex < sm.numEvents(); eventIndex++) { + out << " & "; + trans_ptr = sm.getTransPtr(stateIndex, eventIndex); + if (trans_ptr == NULL) { + } else { + actions = trans_ptr->getActionShorthands(); + // FIXME: should compare index, not the string + if (trans_ptr->getNextStateShorthand() != + sm.getState(stateIndex).getShorthand() ) { + nextState = trans_ptr->getNextStateShorthand(); + } else { + nextState = ""; + } + + out << actions; + if ((nextState.length() != 0) && (actions.length() != 0)) { + out << "/"; + } + out << nextState; + } + } + out << "\\\\" << endl; + } + out << "\\hline" << endl; + out << "\\end{tabular}" << endl; + // out << "}" << endl; + out << "\\end{document}" << endl; +} + diff --git a/src/mem/slicc/main.hh b/src/mem/slicc/main.hh new file mode 100644 index 000000000..e9fdee034 --- /dev/null +++ b/src/mem/slicc/main.hh @@ -0,0 +1,48 @@ + +/* + * Copyright (c) 1999-2008 Mark D. Hill and David A. Wood + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer; + * redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution; + * neither the name of the copyright holders nor the names of its + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +/* + * main.h + * + * Description: + * + * $Id: main.h,v 3.2 2003/03/17 01:50:01 xu Exp $ + * + * */ + +#ifndef MAIN_H +#define MAIN_H + +#include "slicc_global.hh" +#include "DeclListAST.hh" +#include "Map.hh" + +extern DeclListAST* g_decl_list_ptr; + +#endif //MAIN_H diff --git a/src/mem/slicc/parser/lexer.ll b/src/mem/slicc/parser/lexer.ll new file mode 100644 index 000000000..7903b0ee7 --- /dev/null +++ b/src/mem/slicc/parser/lexer.ll @@ -0,0 +1,118 @@ +/* + * Copyright (c) 1999-2008 Mark D. Hill and David A. Wood + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer; + * redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution; + * neither the name of the copyright holders nor the names of its + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +%{ + +#include <assert.h> +#include "ASTs.hh" +#include "parser.h" +#include <string> + +extern "C" int yylex(); +extern "C" void yyerror(); +extern "C" int yywrap() +{ + return 1; +} + +%} +%x CMNT +%x IMBEDED +%% + +[\t ]+ /* Ignore whitespace */ +[\n] { g_line_number++; } +"//".*[\n] { g_line_number++; } /* C++ style comments */ + +"/*" BEGIN CMNT; +<CMNT>. ; +<CMNT>\n { g_line_number++; } +<CMNT>"*/" { BEGIN INITIAL; } + +true { yylval.str_ptr = new string(yytext); return LIT_BOOL; } +false { yylval.str_ptr = new string(yytext); return LIT_BOOL; } +global { return GLOBAL_DECL; } +machine { return MACHINE_DECL; } +in_port { return IN_PORT_DECL; } +out_port { return OUT_PORT_DECL; } +action { return ACTION_DECL; } +transition { return TRANSITION_DECL; } +structure { return STRUCT_DECL; } +external_type { return EXTERN_TYPE_DECL; } +enumeration { return ENUM_DECL; } +peek { return PEEK; } +enqueue { return ENQUEUE; } +copy_head { return COPY_HEAD; } +check_allocate { return CHECK_ALLOCATE; } +check_stop_slots { return CHECK_STOP_SLOTS; } +if { return IF; } +else { return ELSE; } +return { return RETURN; } +THIS { return THIS; } +CHIP { return CHIP; } +void { yylval.str_ptr = new string(yytext); return VOID; } + +== { yylval.str_ptr = new string(yytext); return EQ; } +!= { yylval.str_ptr = new string(yytext); return NE; } +[<] { yylval.str_ptr = new string(yytext); return '<'; } +[>] { yylval.str_ptr = new string(yytext); return '>'; } +[<][<] { yylval.str_ptr = new string(yytext); return LEFTSHIFT; } +[>][>] { yylval.str_ptr = new string(yytext); return RIGHTSHIFT; } +[<][=] { yylval.str_ptr = new string(yytext); return LE; } +[>][=] { yylval.str_ptr = new string(yytext); return GE; } +[!] { yylval.str_ptr = new string(yytext); return NOT; } +[&][&] { yylval.str_ptr = new string(yytext); return AND; } +[|][|] { yylval.str_ptr = new string(yytext); return OR; } +[+] { yylval.str_ptr = new string(yytext); return PLUS; } +[-] { yylval.str_ptr = new string(yytext); return DASH; } +[*] { yylval.str_ptr = new string(yytext); return STAR; } +[/] { yylval.str_ptr = new string(yytext); return SLASH; } +:: { return DOUBLE_COLON; } +[:] { return ':'; } +[;] { return SEMICOLON; } +[[] { return '['; } +[]] { return ']'; } +[{] { return '{'; } +[}] { return '}'; } +[(] { return '('; } +[)] { return ')'; } +[,] { return ','; } +[=] { return '='; } +:= { return ASSIGN; } +[.] { return DOT; } + +[0-9]*[.][0-9]* { yylval.str_ptr = new string(yytext); return FLOATNUMBER; } +[0-9]* { yylval.str_ptr = new string(yytext); return NUMBER; } +[a-zA-Z_][a-zA-Z_0-9]{0,50} { yylval.str_ptr = new string(yytext); return IDENT; } +\"[^"\n]*\" { yytext[strlen(yytext)-1] = '\0'; yylval.str_ptr = new string(yytext+1); return STRING; } +\'[^'\n]*\' { yytext[strlen(yytext)-1] = '\0'; yylval.str_ptr = new string(yytext+1); return STRING; } + +. { return OTHER; } /* Need so that we handle all characters */ + +%% + diff --git a/src/mem/slicc/parser/parser.yy b/src/mem/slicc/parser/parser.yy new file mode 100644 index 000000000..f4d9a1a62 --- /dev/null +++ b/src/mem/slicc/parser/parser.yy @@ -0,0 +1,352 @@ +/* + * Copyright (c) 1999-2008 Mark D. Hill and David A. Wood + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer; + * redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution; + * neither the name of the copyright holders nor the names of its + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +%{ +#include <string> +#include <stdio.h> +#include <assert.h> +#include "ASTs.hh" + +#define YYMAXDEPTH 100000 +#define YYERROR_VERBOSE + +extern char* yytext; + +extern "C" void yyerror(char*); +extern "C" int yylex(); + +%} + +%union { + string* str_ptr; + Vector<string>* string_vector_ptr; + + // Decls + DeclAST* decl_ptr; + DeclListAST* decl_list_ptr; + Vector<DeclAST*>* decl_vector_ptr; + + // TypeField + TypeFieldAST* type_field_ptr; + Vector<TypeFieldAST*>* type_field_vector_ptr; + + // Type + TypeAST* type_ptr; + Vector<TypeAST*>* type_vector_ptr; + + // Formal Params + FormalParamAST* formal_param_ptr; + Vector<FormalParamAST*>* formal_param_vector_ptr; + + // Statements + StatementAST* statement_ptr; + StatementListAST* statement_list_ptr; + Vector<StatementAST*>* statement_vector_ptr; + + // Pairs + PairAST* pair_ptr; + PairListAST* pair_list_ptr; + + // Expressions + VarExprAST* var_expr_ptr; + ExprAST* expr_ptr; + Vector<ExprAST*>* expr_vector_ptr; +} + +%type <type_ptr> type void type_or_void +%type <type_vector_ptr> types type_list + + // Formal Params +%type <formal_param_ptr> formal_param +%type <formal_param_vector_ptr> formal_params formal_param_list + +%type <str_ptr> ident field +%type <string_vector_ptr> ident_list idents + +%type <statement_ptr> statement if_statement +%type <statement_list_ptr> statement_list +%type <statement_vector_ptr> statements + +%type <decl_ptr> decl +%type <decl_list_ptr> decl_list +%type <decl_vector_ptr> decls + +%type <type_field_vector_ptr> type_members type_enums type_methods +%type <type_field_ptr> type_member type_enum type_method + +%type <var_expr_ptr> var +%type <expr_ptr> expr literal enumeration +%type <expr_vector_ptr> expr_list + +%type <pair_ptr> pair +%type <pair_list_ptr> pair_list pairs + +%token <str_ptr> IDENT STRING NUMBER FLOATNUMBER LIT_BOOL VOID +%token <str_ptr> IMBED IMBED_TYPE +%token CHIP THIS +%token ASSIGN DOUBLE_COLON DOT SEMICOLON COLON +%token GLOBAL_DECL MACHINE_DECL IN_PORT_DECL OUT_PORT_DECL +%token PEEK ENQUEUE COPY_HEAD CHECK_ALLOCATE CHECK_STOP_SLOTS +//%token DEQUEUE REMOVE_EARLY SKIP_EARLY PEEK_EARLY +%token DEBUG_EXPR_TOKEN DEBUG_MSG_TOKEN +%token ACTION_DECL TRANSITION_DECL TYPE_DECL STRUCT_DECL EXTERN_TYPE_DECL ENUM_DECL +%token TYPE_FIELD OTHER IF ELSE RETURN + +%token <str_ptr> EQ NE '<' '>' LE GE NOT AND OR PLUS DASH STAR SLASH RIGHTSHIFT LEFTSHIFT + +%left OR +%left AND +%nonassoc EQ NE +%nonassoc '<' '>' GE LE +%left PLUS DASH +%left STAR SLASH +%nonassoc NOT +%nonassoc DOUBLE_COLON DOT '[' + +%% + +file: decl_list { g_decl_list_ptr = $1; } + +decl_list: decls { $$ = new DeclListAST($1); } + +decls: decl decls { $2->insertAtTop($1); $$ = $2; } + | { $$ = new Vector<DeclAST*>; } + ; + +decl: MACHINE_DECL '(' ident pair_list ')' '{' decl_list '}' { $$ = new MachineAST($3, $4, $7); } + | ACTION_DECL '(' ident pair_list ')' statement_list { $$ = new ActionDeclAST($3, $4, $6); } + | IN_PORT_DECL '(' ident ',' type ',' var pair_list ')' statement_list { $$ = new InPortDeclAST($3, $5, $7, $8, $10); } + | OUT_PORT_DECL '(' ident ',' type ',' var pair_list ')' SEMICOLON { $$ = new OutPortDeclAST($3, $5, $7, $8); } + | TRANSITION_DECL '(' ident_list ',' ident_list ',' ident pair_list ')' ident_list { $$ = new TransitionDeclAST($3, $5, $7, $8, $10); } + | TRANSITION_DECL '(' ident_list ',' ident_list pair_list ')' ident_list { $$ = new TransitionDeclAST($3, $5, NULL, $6, $8); } + | EXTERN_TYPE_DECL '(' type pair_list ')' SEMICOLON { $4->addPair(new PairAST("external", "yes")); $$ = new TypeDeclAST($3, $4, NULL); } + | EXTERN_TYPE_DECL '(' type pair_list ')' '{' type_methods '}' { $4->addPair(new PairAST("external", "yes")); $$ = new TypeDeclAST($3, $4, $7); } + | GLOBAL_DECL '(' type pair_list ')' '{' type_members '}' { $4->addPair(new PairAST("global", "yes"));$$ = new TypeDeclAST($3, $4, $7); } + | STRUCT_DECL '(' type pair_list ')' '{' type_members '}' { $$ = new TypeDeclAST($3, $4, $7); } + | ENUM_DECL '(' type pair_list ')' '{' type_enums '}' { $4->addPair(new PairAST("enumeration", "yes")); $$ = new EnumDeclAST($3, $4, $7); } + | type ident pair_list SEMICOLON { $$ = new ObjDeclAST($1, $2, $3); } + | type ident '(' formal_param_list ')' pair_list SEMICOLON { $$ = new FuncDeclAST($1, $2, $4, $6, NULL); } // non-void function + | void ident '(' formal_param_list ')' pair_list SEMICOLON { $$ = new FuncDeclAST($1, $2, $4, $6, NULL); } // void function + | type ident '(' formal_param_list ')' pair_list statement_list { $$ = new FuncDeclAST($1, $2, $4, $6, $7); } // non-void function + | void ident '(' formal_param_list ')' pair_list statement_list { $$ = new FuncDeclAST($1, $2, $4, $6, $7); } // void function + ; + +// Type fields + +type_members: type_member type_members { $2->insertAtTop($1); $$ = $2; } + | { $$ = new Vector<TypeFieldAST*>; } + ; + +type_member: type ident pair_list SEMICOLON { $$ = new TypeFieldMemberAST($1, $2, $3, NULL); } + | type ident ASSIGN expr SEMICOLON { $$ = new TypeFieldMemberAST($1, $2, new PairListAST(), $4); } + ; + +// Methods +type_methods: type_method type_methods { $2->insertAtTop($1); $$ = $2; } + | { $$ = new Vector<TypeFieldAST*>; } + ; + +type_method: type_or_void ident '(' type_list ')' pair_list SEMICOLON { $$ = new TypeFieldMethodAST($1, $2, $4, $6); } + ; + +// Enum fields +type_enums: type_enum type_enums { $2->insertAtTop($1); $$ = $2; } + | { $$ = new Vector<TypeFieldAST*>; } + ; + +type_enum: ident pair_list SEMICOLON { $$ = new TypeFieldEnumAST($1, $2); } + ; + +// Type +type_list : types { $$ = $1; } + | { $$ = new Vector<TypeAST*>; } + ; + +types : type ',' types { $3->insertAtTop($1); $$ = $3; } + | type { $$ = new Vector<TypeAST*>; $$->insertAtTop($1); } + ; + +type: ident { $$ = new TypeAST($1); } + ; + +void: VOID { $$ = new TypeAST($1); } + ; + +type_or_void: type { $$ = $1; } + | void { $$ = $1; } + ; + +// Formal Param +formal_param_list : formal_params { $$ = $1; } + | { $$ = new Vector<FormalParamAST*>; } + ; + +formal_params : formal_param ',' formal_params { $3->insertAtTop($1); $$ = $3; } + | formal_param { $$ = new Vector<FormalParamAST*>; $$->insertAtTop($1); } + ; + +formal_param : type ident { $$ = new FormalParamAST($1, $2); } + ; + +// Idents and lists +ident: IDENT { $$ = $1; } ; + +ident_list: '{' idents '}' { $$ = $2; } + | ident { $$ = new Vector<string>; $$->insertAtTop(*($1)); delete $1; } + ; + +idents: ident SEMICOLON idents { $3->insertAtTop(*($1)); $$ = $3; delete $1; } + | ident ',' idents { $3->insertAtTop(*($1)); $$ = $3; delete $1; } + | ident idents { $2->insertAtTop(*($1)); $$ = $2; delete $1; } + | { $$ = new Vector<string>; } + ; + +// Pair and pair lists +pair_list: ',' pairs { $$ = $2; } + | { $$ = new PairListAST(); } + +pairs : pair ',' pairs { $3->addPair($1); $$ = $3; } + | pair { $$ = new PairListAST(); $$->addPair($1); } + ; + +pair : ident '=' STRING { $$ = new PairAST($1, $3); } + | ident '=' ident { $$ = new PairAST($1, $3); } + | STRING { $$ = new PairAST(new string("short"), $1); } + ; + +// Below are the rules for action descriptions + +statement_list: '{' statements '}' { $$ = new StatementListAST($2); } + ; + +statements: statement statements { $2->insertAtTop($1); $$ = $2; } + | { $$ = new Vector<StatementAST*>; } + ; + +expr_list: expr ',' expr_list { $3->insertAtTop($1); $$ = $3; } + | expr { $$ = new Vector<ExprAST*>; $$->insertAtTop($1); } + | { $$ = new Vector<ExprAST*>; } + ; + +statement: expr SEMICOLON { $$ = new ExprStatementAST($1); } + | expr ASSIGN expr SEMICOLON { $$ = new AssignStatementAST($1, $3); } + | ENQUEUE '(' var ',' type pair_list ')' statement_list { $$ = new EnqueueStatementAST($3, $5, $6, $8); } + | PEEK '(' var ',' type ')' statement_list { $$ = new PeekStatementAST($3, $5, $7, "peek"); } +// | PEEK_EARLY '(' var ',' type ')' statement_list { $$ = new PeekStatementAST($3, $5, $7, "peekEarly"); } + | COPY_HEAD '(' var ',' var pair_list ')' SEMICOLON { $$ = new CopyHeadStatementAST($3, $5, $6); } + | CHECK_ALLOCATE '(' var ')' SEMICOLON { $$ = new CheckAllocateStatementAST($3); } + | CHECK_STOP_SLOTS '(' var ',' STRING ',' STRING ')' SEMICOLON { $$ = new CheckStopSlotsStatementAST($3, $5, $7); } + | if_statement { $$ = $1; } + | RETURN expr SEMICOLON { $$ = new ReturnStatementAST($2); } + ; + +if_statement: IF '(' expr ')' statement_list ELSE statement_list { $$ = new IfStatementAST($3, $5, $7); } + | IF '(' expr ')' statement_list { $$ = new IfStatementAST($3, $5, NULL); } + | IF '(' expr ')' statement_list ELSE if_statement { $$ = new IfStatementAST($3, $5, new StatementListAST($7)); } + ; + +expr: var { $$ = $1; } + | literal { $$ = $1; } + | enumeration { $$ = $1; } + | ident '(' expr_list ')' { $$ = new FuncCallExprAST($1, $3); } + + +// globally access a local chip component and call a method + | THIS DOT var '[' expr ']' DOT var DOT ident '(' expr_list ')' { $$ = new ChipComponentAccessAST($3, $5, $8, $10, $12 ); } +// globally access a local chip component and access a data member + | THIS DOT var '[' expr ']' DOT var DOT field { $$ = new ChipComponentAccessAST($3, $5, $8, $10 ); } +// globally access a specified chip component and call a method + | CHIP '[' expr ']' DOT var '[' expr ']' DOT var DOT ident '(' expr_list ')' { $$ = new ChipComponentAccessAST($3, $6, $8, $11, $13, $15 ); } +// globally access a specified chip component and access a data member + | CHIP '[' expr ']' DOT var '[' expr ']' DOT var DOT field { $$ = new ChipComponentAccessAST($3, $6, $8, $11, $13 ); } + + + | expr DOT field { $$ = new MemberExprAST($1, $3); } + | expr DOT ident '(' expr_list ')' { $$ = new MethodCallExprAST($1, $3, $5); } + | type DOUBLE_COLON ident '(' expr_list ')' { $$ = new MethodCallExprAST($1, $3, $5); } + | expr '[' expr_list ']' { $$ = new MethodCallExprAST($1, new string("lookup"), $3); } + | expr STAR expr { $$ = new InfixOperatorExprAST($1, $2, $3); } + | expr SLASH expr { $$ = new InfixOperatorExprAST($1, $2, $3); } + | expr PLUS expr { $$ = new InfixOperatorExprAST($1, $2, $3); } + | expr DASH expr { $$ = new InfixOperatorExprAST($1, $2, $3); } + | expr '<' expr { $$ = new InfixOperatorExprAST($1, $2, $3); } + | expr '>' expr { $$ = new InfixOperatorExprAST($1, $2, $3); } + | expr LE expr { $$ = new InfixOperatorExprAST($1, $2, $3); } + | expr GE expr { $$ = new InfixOperatorExprAST($1, $2, $3); } + | expr EQ expr { $$ = new InfixOperatorExprAST($1, $2, $3); } + | expr NE expr { $$ = new InfixOperatorExprAST($1, $2, $3); } + | expr AND expr { $$ = new InfixOperatorExprAST($1, $2, $3); } + | expr OR expr { $$ = new InfixOperatorExprAST($1, $2, $3); } + | expr RIGHTSHIFT expr { $$ = new InfixOperatorExprAST($1, $2, $3); } + | expr LEFTSHIFT expr { $$ = new InfixOperatorExprAST($1, $2, $3); } +// | NOT expr { $$ = NULL; } // FIXME - unary not +// | DASH expr %prec NOT { $$ = NULL; } // FIXME - unary minus + | '(' expr ')' { $$ = $2; } + ; + +literal: STRING { $$ = new LiteralExprAST($1, "string"); } + | NUMBER { $$ = new LiteralExprAST($1, "int"); } + | FLOATNUMBER { $$ = new LiteralExprAST($1, "int"); } + | LIT_BOOL { $$ = new LiteralExprAST($1, "bool"); } + ; + +enumeration: ident ':' ident { $$ = new EnumExprAST(new TypeAST($1), $3); } + ; + +var: ident { $$ = new VarExprAST($1); } + ; + +field: ident { $$ = $1; } + ; + +%% + +extern FILE *yyin; + +DeclListAST* parse(string filename) +{ + FILE *file; + file = fopen(filename.c_str(), "r"); + if (!file) { + cerr << "Error: Could not open file: " << filename << endl; + exit(1); + } + g_line_number = 1; + g_file_name = filename; + yyin = file; + g_decl_list_ptr = NULL; + yyparse(); + return g_decl_list_ptr; +} + +extern "C" void yyerror(char* s) +{ + fprintf(stderr, "%s:%d: %s at %s\n", g_file_name.c_str(), g_line_number, s, yytext); + exit(1); +} + diff --git a/src/mem/slicc/slicc_global.hh b/src/mem/slicc/slicc_global.hh new file mode 100644 index 000000000..72af5be58 --- /dev/null +++ b/src/mem/slicc/slicc_global.hh @@ -0,0 +1,127 @@ + +/* + * Copyright (c) 1999-2008 Mark D. Hill and David A. Wood + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer; + * redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution; + * neither the name of the copyright holders nor the names of its + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef SLICC_GLOBAL_H +#define SLICC_GLOBAL_H + +#include <assert.h> /* slicc needs to include this in order to use classes in + * ../common directory. + */ + +#include "std-includes.hh" +#include "Map.hh" + +typedef unsigned char uint8; +typedef unsigned int uint32; +typedef unsigned long long uint64; + +typedef signed char int8; +typedef int int32; +typedef long long int64; + +typedef long long integer_t; +typedef unsigned long long uinteger_t; + +const bool ASSERT_FLAG = true; + +// when CHECK_RESOURCE_DEADLOCK is enabled, slicc will generate additional code +// that works in conjuction with the resources rank value specified in the protocol +// to detect invalid resource stalls as soon as they occur. +const bool CHECK_INVALID_RESOURCE_STALLS = false; + +#undef assert +#define assert(EXPR) ASSERT(EXPR) + +#define ASSERT(EXPR)\ +{\ + if (ASSERT_FLAG) {\ + if (!(EXPR)) {\ + cerr << "failed assertion '"\ + << #EXPR << "' at fn "\ + << __PRETTY_FUNCTION__ << " in "\ + << __FILE__ << ":"\ + << __LINE__ << endl;\ + if(isatty(STDIN_FILENO)) {\ + cerr << "At this point you might want to attach a debug to ";\ + cerr << "the running and get to the" << endl;\ + cerr << "crash site; otherwise press enter to continue" << endl;\ + cerr << "PID: " << getpid();\ + cerr << endl << flush; \ + char c; \ + cin.get(c); \ + }\ + abort();\ + }\ + }\ +} + +class State; +class Event; +class Symbol; +class Var; + +namespace __gnu_cxx { + template <> struct hash<State*> + { + size_t operator()(State* s) const { return (size_t) s; } + }; + template <> struct hash<Event*> + { + size_t operator()(Event* s) const { return (size_t) s; } + }; + template <> struct hash<Symbol*> + { + size_t operator()(Symbol* s) const { return (size_t) s; } + }; + template <> struct hash<Var*> + { + size_t operator()(Var* s) const { return (size_t) s; } + }; +} // namespace __gnu_cxx + +namespace std { + template <> struct equal_to<Event*> + { + bool operator()(Event* s1, Event* s2) const { return s1 == s2; } + }; + template <> struct equal_to<State*> + { + bool operator()(State* s1, State* s2) const { return s1 == s2; } + }; + template <> struct equal_to<Symbol*> + { + bool operator()(Symbol* s1, Symbol* s2) const { return s1 == s2; } + }; + template <> struct equal_to<Var*> + { + bool operator()(Var* s1, Var* s2) const { return s1 == s2; } + }; +} // namespace std + +#endif //SLICC_GLOBAL_H diff --git a/src/mem/slicc/symbols/Action.hh b/src/mem/slicc/symbols/Action.hh new file mode 100644 index 000000000..0f6e49290 --- /dev/null +++ b/src/mem/slicc/symbols/Action.hh @@ -0,0 +1,52 @@ + +/* + * Copyright (c) 1999-2008 Mark D. Hill and David A. Wood + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer; + * redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution; + * neither the name of the copyright holders nor the names of its + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +/* + * $Id$ + */ + +#ifndef ACTION_H +#define ACTION_H + +#include "Symbol.hh" + +class Action : public Symbol { +public: + Action(string id, + const Map<Var*, string>& resources, + const Location& location, + const Map<string, string>& pairs) : Symbol(id, location, pairs) { m_resources = resources; } + const Map<Var*, string>& getResources() const { return m_resources; } + void print(ostream& out) const { out << "[Action: " << getIdent() << "]"; } + +private: + Map<Var*, string> m_resources; +}; + +#endif //ACTION_H diff --git a/src/mem/slicc/symbols/Event.hh b/src/mem/slicc/symbols/Event.hh new file mode 100644 index 000000000..f272e8eb1 --- /dev/null +++ b/src/mem/slicc/symbols/Event.hh @@ -0,0 +1,45 @@ + +/* + * Copyright (c) 1999-2008 Mark D. Hill and David A. Wood + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer; + * redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution; + * neither the name of the copyright holders nor the names of its + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +/* + * $Id$ + */ + +#ifndef EVENT_H +#define EVENT_H + +#include "Symbol.hh" + +class Event : public Symbol { +public: + Event(string id, const Location& location, const Map<string, string>& pairs) : Symbol(id, location, pairs) {} + void print(ostream& out) const { out << "[Event: " << getIdent() << "]"; } +}; + +#endif //EVENT_H diff --git a/src/mem/slicc/symbols/Func.cc b/src/mem/slicc/symbols/Func.cc new file mode 100644 index 000000000..1af1e299c --- /dev/null +++ b/src/mem/slicc/symbols/Func.cc @@ -0,0 +1,144 @@ + +/* + * Copyright (c) 1999-2008 Mark D. Hill and David A. Wood + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer; + * redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution; + * neither the name of the copyright holders nor the names of its + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +/* + * Func.C + * + * Description: See Func.h + * + * $Id$ + * + */ + +#include "Func.hh" +#include "SymbolTable.hh" +#include "fileio.hh" +#include "StateMachine.hh" + +Func::Func(string id, const Location& location, + Type* type_ptr, const Vector<Type*>& param_type_vec, + const Vector<string>& param_string_vec, string body, + const Map<string, string>& pairs, StateMachine* machine_ptr) + : Symbol(id, location, pairs) +{ + m_type_ptr = type_ptr; + m_param_type_vec = param_type_vec; + m_param_string_vec = param_string_vec; + m_body = body; + m_isInternalMachineFunc = false; + + if (machine_ptr == NULL) { + m_c_ident = id; + } else if (existPair("external") || existPair("primitive")) { + m_c_ident = id; + } else { + m_machineStr = machine_ptr->toString(); + m_c_ident = m_machineStr + "_" + id; // Append with machine name + m_isInternalMachineFunc = true; + } +} + +void Func::funcPrototype(string& code) const +{ + if (isExternal()) { + // Do nothing + } else { + string return_type = m_type_ptr->cIdent(); + Type* void_type_ptr = g_sym_table.getType("void"); + if (existPair("return_by_ref") && (m_type_ptr != void_type_ptr)) { + return_type += "&"; + } + code += return_type + " " + cIdent() + "("; + int size = m_param_string_vec.size(); + for(int i=0; i<size; i++) { + // Generate code + if (i != 0) { + code += ", "; + } + code += m_param_string_vec[i]; + } + code += ");\n"; + } +} + +// This write a function of object Chip +void Func::writeCFiles(string path) const +{ + if (isExternal()) { + // Do nothing + } else { + ostringstream out; + + // Header + out << "/** Auto generated C++ code started by "<<__FILE__<<":"<<__LINE__<< " */" << endl; + out << endl; + out << "#include \"Types.hh\"" << endl; + out << "#include \"Chip.hh\"" << endl; + if (m_isInternalMachineFunc) { + out << "#include \"" << m_machineStr << "_Controller.hh\"" << endl; + } + out << endl; + + // Generate function header + string code; + Type* void_type_ptr = g_sym_table.getType("void"); + string return_type = m_type_ptr->cIdent(); + code += return_type; + if (existPair("return_by_ref") && m_type_ptr != void_type_ptr) { + code += "&"; + } + if (!m_isInternalMachineFunc) { + code += " Chip::" + cIdent() + "("; + } else { + code += " " + m_machineStr + "_Controller::" + cIdent() + "("; + } + int size = m_param_type_vec.size(); + for(int i=0; i<size; i++) { + // Generate code + if (i != 0) { + code += ", "; + } + code += m_param_string_vec[i]; + } + code += ")"; + + // Function body + code += "\n{\n"; + code += m_body; + code += "}\n"; + out << code << endl; + + // Write it out + conditionally_write_file(path + cIdent() + ".cc", out); + } +} + +void Func::print(ostream& out) const +{ +} diff --git a/src/mem/slicc/symbols/Func.hh b/src/mem/slicc/symbols/Func.hh new file mode 100644 index 000000000..763827701 --- /dev/null +++ b/src/mem/slicc/symbols/Func.hh @@ -0,0 +1,96 @@ + +/* + * Copyright (c) 1999-2008 Mark D. Hill and David A. Wood + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer; + * redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution; + * neither the name of the copyright holders nor the names of its + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +/* + * Func.h + * + * Description: + * + * $Id$ + * + */ + +#ifndef FUNC_H +#define FUNC_H + +#include "slicc_global.hh" +#include "Type.hh" +class StateMachine; + +class Func : public Symbol { +public: + // Constructors + Func(string id, const Location& location, + Type* type_ptr, const Vector<Type*>& param_type_vec, const Vector<string>& param_string_vec, + string body, const Map<string, string>& pairs, StateMachine* machine_ptr); + + // Destructor + ~Func() {} + + // Public Methods + string cIdent() const { return m_c_ident; } + const Vector<Type*>& getParamTypes() const { return m_param_type_vec; } + Type* getReturnType() const { return m_type_ptr; } + void writeCFiles(string path) const; + void funcPrototype(string& code) const; + bool isExternal() const { return existPair("external"); } + bool isInternalMachineFunc() const { return m_isInternalMachineFunc; } + void print(ostream& out) const; +private: + // Private Methods + + // Private copy constructor and assignment operator + Func(const Func& obj); + Func& operator=(const Func& obj); + + // Data Members (m_ prefix) + Type* m_type_ptr; + Vector<Type*> m_param_type_vec; + Vector<string> m_param_string_vec; + string m_body; + string m_c_ident; + string m_machineStr; + bool m_isInternalMachineFunc; +}; + +// Output operator declaration +ostream& operator<<(ostream& out, const Func& obj); + +// ******************* Definitions ******************* + +// Output operator definition +extern inline +ostream& operator<<(ostream& out, const Func& obj) +{ + obj.print(out); + out << flush; + return out; +} + +#endif //FUNC_H diff --git a/src/mem/slicc/symbols/State.hh b/src/mem/slicc/symbols/State.hh new file mode 100644 index 000000000..cac743e57 --- /dev/null +++ b/src/mem/slicc/symbols/State.hh @@ -0,0 +1,45 @@ + +/* + * Copyright (c) 1999-2008 Mark D. Hill and David A. Wood + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer; + * redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution; + * neither the name of the copyright holders nor the names of its + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +/* + * $Id$ + */ + +#ifndef STATE_H +#define STATE_H + +#include "Symbol.hh" + +class State : public Symbol { +public: + State(string id, const Location& location, const Map<string, string>& pairs) : Symbol(id, location, pairs) {} + void print(ostream& out) const { out << "[State: " << getIdent() << "]"; } +}; + +#endif //STATE_H diff --git a/src/mem/slicc/symbols/StateMachine.cc b/src/mem/slicc/symbols/StateMachine.cc new file mode 100644 index 000000000..d4436870e --- /dev/null +++ b/src/mem/slicc/symbols/StateMachine.cc @@ -0,0 +1,993 @@ + +/* + * Copyright (c) 1999-2008 Mark D. Hill and David A. Wood + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer; + * redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution; + * neither the name of the copyright holders nor the names of its + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +/* + * $Id$ + * + * */ + +#include "StateMachine.hh" +#include "fileio.hh" +#include "html_gen.hh" +#include "Action.hh" +#include "Event.hh" +#include "State.hh" +#include "Transition.hh" +#include "Var.hh" +#include "SymbolTable.hh" +#include "util.hh" +#include "Vector.hh" + +StateMachine::StateMachine(string ident, const Location& location, const Map<string, string>& pairs) + : Symbol(ident, location, pairs) +{ + m_table_built = false; +} + +StateMachine::~StateMachine() +{ + // FIXME + // assert(0); +} + +void StateMachine::addState(State* state_ptr) +{ + assert(m_table_built == false); + m_state_map.add(state_ptr, m_states.size()); + m_states.insertAtBottom(state_ptr); +} + +void StateMachine::addEvent(Event* event_ptr) +{ + assert(m_table_built == false); + m_event_map.add(event_ptr, m_events.size()); + m_events.insertAtBottom(event_ptr); +} + +void StateMachine::addAction(Action* action_ptr) +{ + assert(m_table_built == false); + + // Check for duplicate action + int size = m_actions.size(); + for(int i=0; i<size; i++) { + if (m_actions[i]->getIdent() == action_ptr->getIdent()) { + m_actions[i]->warning("Duplicate action definition: " + m_actions[i]->getIdent()); + action_ptr->error("Duplicate action definition: " + action_ptr->getIdent()); + } + if (m_actions[i]->getShorthand() == action_ptr->getShorthand()) { + m_actions[i]->warning("Duplicate action shorthand: " + m_actions[i]->getIdent()); + m_actions[i]->warning(" shorthand = " + m_actions[i]->getShorthand()); + action_ptr->warning("Duplicate action shorthand: " + action_ptr->getIdent()); + action_ptr->error(" shorthand = " + action_ptr->getShorthand()); + } + } + + m_actions.insertAtBottom(action_ptr); +} + +void StateMachine::addTransition(Transition* trans_ptr) +{ + assert(m_table_built == false); + trans_ptr->checkIdents(m_states, m_events, m_actions); + m_transitions.insertAtBottom(trans_ptr); +} + +void StateMachine::addFunc(Func* func_ptr) +{ + // register func in the symbol table + g_sym_table.registerSym(func_ptr->toString(), func_ptr); + m_internal_func_vec.insertAtBottom(func_ptr); +} + +void StateMachine::buildTable() +{ + assert(m_table_built == false); + int numStates = m_states.size(); + int numEvents = m_events.size(); + int numTransitions = m_transitions.size(); + int stateIndex, eventIndex; + + for(stateIndex=0; stateIndex < numStates; stateIndex++) { + m_table.insertAtBottom(Vector<Transition*>()); + for(eventIndex=0; eventIndex < numEvents; eventIndex++) { + m_table[stateIndex].insertAtBottom(NULL); + } + } + + for(int i=0; i<numTransitions; i++) { + Transition* trans_ptr = m_transitions[i]; + + // Track which actions we touch so we know if we use them all -- + // really this should be done for all symbols as part of the + // symbol table, then only trigger it for Actions, States, Events, + // etc. + + Vector<Action*> actions = trans_ptr->getActions(); + for(int actionIndex=0; actionIndex < actions.size(); actionIndex++) { + actions[actionIndex]->markUsed(); + } + + stateIndex = getStateIndex(trans_ptr->getStatePtr()); + eventIndex = getEventIndex(trans_ptr->getEventPtr()); + if (m_table[stateIndex][eventIndex] != NULL) { + m_table[stateIndex][eventIndex]->warning("Duplicate transition: " + m_table[stateIndex][eventIndex]->toString()); + trans_ptr->error("Duplicate transition: " + trans_ptr->toString()); + } + m_table[stateIndex][eventIndex] = trans_ptr; + } + + // Look at all actions to make sure we used them all + for(int actionIndex=0; actionIndex < m_actions.size(); actionIndex++) { + Action* action_ptr = m_actions[actionIndex]; + if (!action_ptr->wasUsed()) { + string error_msg = "Unused action: " + action_ptr->getIdent(); + if (action_ptr->existPair("desc")) { + error_msg += ", " + action_ptr->getDescription(); + } + action_ptr->warning(error_msg); + } + } + + m_table_built = true; +} + +const Transition* StateMachine::getTransPtr(int stateIndex, int eventIndex) const +{ + return m_table[stateIndex][eventIndex]; +} + +// *********************** // +// ******* C Files ******* // +// *********************** // + +void StateMachine::writeCFiles(string path) const +{ + string comp = getIdent(); + string filename; + + // Output switch statement for transition table + { + ostringstream sstr; + printCSwitch(sstr, comp); + conditionally_write_file(path + comp + "_Transitions.cc", sstr); + } + + // Output the actions for performing the actions + { + ostringstream sstr; + printControllerC(sstr, comp); + conditionally_write_file(path + comp + "_Controller.cc", sstr); + } + + // Output the method declarations for the class declaration + { + ostringstream sstr; + printControllerH(sstr, comp); + conditionally_write_file(path + comp + "_Controller.hh", sstr); + } + + // Output the wakeup loop for the events + { + ostringstream sstr; + printCWakeup(sstr, comp); + conditionally_write_file(path + comp + "_Wakeup.cc", sstr); + } + + // Profiling + { + ostringstream sstr; + printProfilerC(sstr, comp); + conditionally_write_file(path + comp + "_Profiler.cc", sstr); + } + { + ostringstream sstr; + printProfilerH(sstr, comp); + conditionally_write_file(path + comp + "_Profiler.hh", sstr); + } + + // Write internal func files + for(int i=0; i<m_internal_func_vec.size(); i++) { + m_internal_func_vec[i]->writeCFiles(path); + } + +} + +void StateMachine::printControllerH(ostream& out, string component) const +{ + out << "/** \\file " << getIdent() << ".hh" << endl; + out << " * " << endl; + out << " * Auto generated C++ code started by "<<__FILE__<<":"<<__LINE__<< endl; + out << " * Created by slicc definition of Module \"" << getShorthand() << "\"" << endl; + out << " */" << endl; + out << endl; + out << "#ifndef " << component << "_CONTROLLER_H" << endl; + out << "#define " << component << "_CONTROLLER_H" << endl; + out << endl; + out << "#include \"Global.hh\"" << endl; + out << "#include \"Consumer.hh\"" << endl; + out << "#include \"TransitionResult.hh\"" << endl; + out << "#include \"Types.hh\"" << endl; + out << "#include \"" << component << "_Profiler.hh\"" << endl; + out << endl; + + // for adding information to the protocol debug trace + out << "extern stringstream " << component << "_" << "transitionComment;" << endl; + + out << "class " << component << "_Controller : public Consumer {" << endl; + + /* the coherence checker needs to call isBlockExclusive() and isBlockShared() + making the Chip a friend class is an easy way to do this for now */ + out << "#ifdef CHECK_COHERENCE" << endl; + out << " friend class Chip;" << endl; + out << "#endif /* CHECK_COHERENCE */" << endl; + + out << "public:" << endl; + out << " " << component << "_Controller(Chip* chip_ptr, int version);" << endl; + out << " void print(ostream& out) const;" << endl; + out << " void wakeup();" << endl; + out << " static void dumpStats(ostream& out) { s_profiler.dumpStats(out); }" << endl; + out << " static void clearStats() { s_profiler.clearStats(); }" << endl; + out << "private:" << endl; + out << " TransitionResult doTransition(" << component << "_Event event, " << component + << "_State state, const Address& addr"; + if(CHECK_INVALID_RESOURCE_STALLS) { + out << ", int priority"; + } + out << "); // in " << component << "_Transitions.cc" << endl; + out << " TransitionResult doTransitionWorker(" << component << "_Event event, " << component + << "_State state, " << component << "_State& next_state, const Address& addr"; + if(CHECK_INVALID_RESOURCE_STALLS) { + out << ", int priority"; + } + out << "); // in " << component << "_Transitions.cc" << endl; + out << " Chip* m_chip_ptr;" << endl; + out << " NodeID m_id;" << endl; + out << " NodeID m_version;" << endl; + out << " MachineID m_machineID;" << endl; + out << " static " << component << "_Profiler s_profiler;" << endl; + + // internal function protypes + out << " // Internal functions" << endl; + for(int i=0; i<m_internal_func_vec.size(); i++) { + Func* func = m_internal_func_vec[i]; + string proto; + func->funcPrototype(proto); + if (proto != "") { + out << " " << proto; + } + } + + out << " // Actions" << endl; + for(int i=0; i < numActions(); i++) { + const Action& action = getAction(i); + out << "/** \\brief " << action.getDescription() << "*/" << endl; + out << " void " << action.getIdent() << "(const Address& addr);" << endl; + } + out << "};" << endl; + out << "#endif // " << component << "_CONTROLLER_H" << endl; +} + +void StateMachine::printControllerC(ostream& out, string component) const +{ + out << "/** \\file " << getIdent() << ".cc" << endl; + out << " * " << endl; + out << " * Auto generated C++ code started by "<<__FILE__<<":"<<__LINE__<< endl; + out << " * Created by slicc definition of Module \"" << getShorthand() << "\"" << endl; + out << " */" << endl; + out << endl; + out << "#include \"Global.hh\"" << endl; + out << "#include \"RubySlicc_includes.hh\"" << endl; + out << "#include \"" << component << "_Controller.hh\"" << endl; + out << "#include \"" << component << "_State.hh\"" << endl; + out << "#include \"" << component << "_Event.hh\"" << endl; + out << "#include \"Types.hh\"" << endl; + out << "#include \"System.hh\"" << endl; + out << "#include \"Chip.hh\"" << endl; + out << endl; + + // for adding information to the protocol debug trace + out << "stringstream " << component << "_" << "transitionComment;" << endl; + out << "#define APPEND_TRANSITION_COMMENT(str) (" << component << "_" << "transitionComment << str)" << endl; + + out << "/** \\brief static profiler defn */" << endl; + out << component << "_Profiler " << component << "_Controller::s_profiler;" << endl; + out << endl; + + out << "/** \\brief constructor */" << endl; + out << component << "_Controller::" << component + << "_Controller(Chip* chip_ptr, int version)" << endl; + out << "{" << endl; + out << " m_chip_ptr = chip_ptr;" << endl; + out << " m_id = m_chip_ptr->getID();" << endl; + out << " m_version = version;" << endl; + out << " m_machineID.type = MachineType_" << component << ";" << endl; + out << " m_machineID.num = m_id*RubyConfig::numberOf"<< component << "PerChip()+m_version;" << endl; + + // Set the queue consumers + for(int i=0; i < m_in_ports.size(); i++) { + const Var* port = m_in_ports[i]; + out << " " << port->getCode() << ".setConsumer(this);" << endl; + } + + out << endl; + // Set the queue descriptions + for(int i=0; i < m_in_ports.size(); i++) { + const Var* port = m_in_ports[i]; + out << " " << port->getCode() + << ".setDescription(\"[Chip \" + int_to_string(m_chip_ptr->getID()) + \" \" + int_to_string(m_version) + \", " + << component << ", " << port->toString() << "]\");" << endl; + } + + // Initialize the transition profiling + out << endl; + for(int i=0; i<numTransitions(); i++) { + const Transition& t = getTransition(i); + const Vector<Action*>& action_vec = t.getActions(); + int numActions = action_vec.size(); + + // Figure out if we stall + bool stall = false; + for (int i=0; i<numActions; i++) { + if(action_vec[i]->getIdent() == "z_stall") { + stall = true; + } + } + + // Only possible if it is not a 'z' case + if (!stall) { + out << " s_profiler.possibleTransition(" << component << "_State_" + << t.getStatePtr()->getIdent() << ", " << component << "_Event_" + << t.getEventPtr()->getIdent() << ");" << endl; + } + } + + out << "}" << endl; + + out << endl; + + out << "void " << component << "_Controller::print(ostream& out) const { out << \"[" << component + << "_Controller \" << m_chip_ptr->getID() << \" \" << m_version << \"]\"; }" << endl; + + out << endl; + out << "// Actions" << endl; + out << endl; + + for(int i=0; i < numActions(); i++) { + const Action& action = getAction(i); + if (action.existPair("c_code")) { + out << "/** \\brief " << action.getDescription() << "*/" << endl; + out << "void " << component << "_Controller::" + << action.getIdent() << "(const Address& addr)" << endl; + out << "{" << endl; + out << " DEBUG_MSG(GENERATED_COMP, HighPrio,\"executing\");" << endl; + out << action.lookupPair("c_code"); + out << "}" << endl; + } + out << endl; + } +} + +void StateMachine::printCWakeup(ostream& out, string component) const +{ + out << "// Auto generated C++ code started by "<<__FILE__<<":"<<__LINE__<< endl; + out << "// " << getIdent() << ": " << getShorthand() << endl; + out << endl; + out << "#include \"Global.hh\"" << endl; + out << "#include \"RubySlicc_includes.hh\"" << endl; + out << "#include \"" << component << "_Controller.hh\"" << endl; + out << "#include \"" << component << "_State.hh\"" << endl; + out << "#include \"" << component << "_Event.hh\"" << endl; + out << "#include \"Types.hh\"" << endl; + out << "#include \"System.hh\"" << endl; + out << "#include \"Chip.hh\"" << endl; + out << endl; + out << "void " << component << "_Controller::wakeup()" << endl; + out << "{" << endl; + // out << " DEBUG_EXPR(GENERATED_COMP, MedPrio,*this);" << endl; + // out << " DEBUG_EXPR(GENERATED_COMP, MedPrio,g_eventQueue_ptr->getTime());" << endl; + out << endl; + out << "int counter = 0;" << endl; + out << " while (true) {" << endl; + out << " // Some cases will put us into an infinite loop without this limit" << endl; + out << " assert(counter <= RubyConfig::" << getIdent() << "TransitionsPerCycle());" << endl; + out << " if (counter == RubyConfig::" << getIdent() << "TransitionsPerCycle()) {" << endl; + out << " g_system_ptr->getProfiler()->controllerBusy(m_machineID); // Count how often we're fully utilized" << endl; + out << " g_eventQueue_ptr->scheduleEvent(this, 1); // Wakeup in another cycle and try again" << endl; + out << " break;" << endl; + out << " }" << endl; + + // InPorts + for(int i=0; i < m_in_ports.size(); i++) { + const Var* port = m_in_ports[i]; + assert(port->existPair("c_code_in_port")); + out << " // " + << component << "InPort " << port->toString() + << endl; + out << port->lookupPair("c_code_in_port"); + out << endl; + } + + out << " break; // If we got this far, we have nothing left todo" << endl; + out << " }" << endl; + // out << " g_eventQueue_ptr->scheduleEvent(this, 1);" << endl; + // out << " DEBUG_NEWLINE(GENERATED_COMP, MedPrio);" << endl; + out << "}" << endl; + out << endl; +} + +void StateMachine::printCSwitch(ostream& out, string component) const +{ + out << "// Auto generated C++ code started by "<<__FILE__<<":"<<__LINE__<< endl; + out << "// " << getIdent() << ": " << getShorthand() << endl; + out << endl; + out << "#include \"Global.hh\"" << endl; + out << "#include \"" << component << "_Controller.hh\"" << endl; + out << "#include \"" << component << "_State.hh\"" << endl; + out << "#include \"" << component << "_Event.hh\"" << endl; + out << "#include \"Types.hh\"" << endl; + out << "#include \"System.hh\"" << endl; + out << "#include \"Chip.hh\"" << endl; + out << endl; + out << "#define HASH_FUN(state, event) ((int(state)*" << component + << "_Event_NUM)+int(event))" << endl; + out << endl; + out << "#define GET_TRANSITION_COMMENT() (" << component << "_" << "transitionComment.str())" << endl; + out << "#define CLEAR_TRANSITION_COMMENT() (" << component << "_" << "transitionComment.str(\"\"))" << endl; + out << endl; + out << "TransitionResult " << component << "_Controller::doTransition(" + << component << "_Event event, " + << component << "_State state, " + << "const Address& addr" << endl; + if(CHECK_INVALID_RESOURCE_STALLS) { + out << ", int priority"; + } + out << ")" << endl; + + out << "{" << endl; + out << " " << component << "_State next_state = state;" << endl; + out << endl; + out << " DEBUG_NEWLINE(GENERATED_COMP, MedPrio);" << endl; + out << " DEBUG_MSG(GENERATED_COMP, MedPrio,*this);" << endl; + out << " DEBUG_EXPR(GENERATED_COMP, MedPrio,g_eventQueue_ptr->getTime());" << endl; + out << " DEBUG_EXPR(GENERATED_COMP, MedPrio,state);" << endl; + out << " DEBUG_EXPR(GENERATED_COMP, MedPrio,event);" << endl; + out << " DEBUG_EXPR(GENERATED_COMP, MedPrio,addr);" << endl; + out << endl; + out << " TransitionResult result = doTransitionWorker(event, state, next_state, addr"; + if(CHECK_INVALID_RESOURCE_STALLS) { + out << ", priority"; + } + out << ");" << endl; + out << endl; + out << " if (result == TransitionResult_Valid) {" << endl; + out << " DEBUG_EXPR(GENERATED_COMP, MedPrio, next_state);" << endl; + out << " DEBUG_NEWLINE(GENERATED_COMP, MedPrio);" << endl; + out << " s_profiler.countTransition(state, event);" << endl; + out << " if (PROTOCOL_DEBUG_TRACE) {" << endl + << " g_system_ptr->getProfiler()->profileTransition(\"" << component + << "\", m_chip_ptr->getID(), m_version, addr, " << endl + << " " << component << "_State_to_string(state), " << endl + << " " << component << "_Event_to_string(event), " << endl + << " " << component << "_State_to_string(next_state), GET_TRANSITION_COMMENT());" << endl + << " }" << endl; + out << " CLEAR_TRANSITION_COMMENT();" << endl; + out << " " << component << "_setState(addr, next_state);" << endl; + out << " " << endl; + out << " } else if (result == TransitionResult_ResourceStall) {" << endl; + out << " if (PROTOCOL_DEBUG_TRACE) {" << endl + << " g_system_ptr->getProfiler()->profileTransition(\"" << component + << "\", m_chip_ptr->getID(), m_version, addr, " << endl + << " " << component << "_State_to_string(state), " << endl + << " " << component << "_Event_to_string(event), " << endl + << " " << component << "_State_to_string(next_state), " << endl + << " \"Resource Stall\");" << endl + << " }" << endl; + out << " } else if (result == TransitionResult_ProtocolStall) {" << endl; + out << " DEBUG_MSG(GENERATED_COMP,HighPrio,\"stalling\");" << endl + << " DEBUG_NEWLINE(GENERATED_COMP, MedPrio);" << endl; + out << " if (PROTOCOL_DEBUG_TRACE) {" << endl + << " g_system_ptr->getProfiler()->profileTransition(\"" << component + << "\", m_chip_ptr->getID(), m_version, addr, " << endl + << " " << component << "_State_to_string(state), " << endl + << " " << component << "_Event_to_string(event), " << endl + << " " << component << "_State_to_string(next_state), " << endl + << " \"Protocol Stall\");" << endl + << " }" << endl + << " }" << endl; + out << " return result;" << endl; + out << "}" << endl; + out << endl; + out << "TransitionResult " << component << "_Controller::doTransitionWorker(" + << component << "_Event event, " + << component << "_State state, " + << component << "_State& next_state, " + << "const Address& addr" << endl; + if(CHECK_INVALID_RESOURCE_STALLS) { + out << ", int priority" << endl; + } + out << ")" << endl; + + out << "{" << endl; + out << "" << endl; + + out << " switch(HASH_FUN(state, event)) {" << endl; + + Map<string, Vector<string> > code_map; // This map will allow suppress generating duplicate code + Vector<string> code_vec; + + for(int i=0; i<numTransitions(); i++) { + const Transition& t = getTransition(i); + string case_string = component + "_State_" + t.getStatePtr()->getIdent() + + ", " + component + "_Event_" + t.getEventPtr()->getIdent(); + + string code; + + code += " {\n"; + // Only set next_state if it changes + if (t.getStatePtr() != t.getNextStatePtr()) { + code += " next_state = " + component + "_State_" + t.getNextStatePtr()->getIdent() + ";\n"; + } + + const Vector<Action*>& action_vec = t.getActions(); + int numActions = action_vec.size(); + + // Check for resources + Vector<string> code_sorter; + const Map<Var*, string>& res = t.getResources(); + Vector<Var*> res_keys = res.keys(); + for (int i=0; i<res_keys.size(); i++) { + string temp_code; + if (res_keys[i]->getType()->cIdent() == "DNUCAStopTable") { + temp_code += res.lookup(res_keys[i]); + } else { + temp_code += " if (!" + (res_keys[i]->getCode()) + ".areNSlotsAvailable(" + res.lookup(res_keys[i]) + ")) {\n"; + if(CHECK_INVALID_RESOURCE_STALLS) { + // assert that the resource stall is for a resource of equal or greater priority + temp_code += " assert(priority >= "+ (res_keys[i]->getCode()) + ".getPriority());\n"; + } + temp_code += " return TransitionResult_ResourceStall;\n"; + temp_code += " }\n"; + } + code_sorter.insertAtBottom(temp_code); + } + + // Emit the code sequences in a sorted order. This makes the + // output deterministic (without this the output order can vary + // since Map's keys() on a vector of pointers is not deterministic + code_sorter.sortVector(); + for (int i=0; i<code_sorter.size(); i++) { + code += code_sorter[i]; + } + + // Figure out if we stall + bool stall = false; + for (int i=0; i<numActions; i++) { + if(action_vec[i]->getIdent() == "z_stall") { + stall = true; + } + } + + if (stall) { + code += " return TransitionResult_ProtocolStall;\n"; + } else { + for (int i=0; i<numActions; i++) { + code += " " + action_vec[i]->getIdent() + "(addr);\n"; + } + code += " return TransitionResult_Valid;\n"; + } + code += " }\n"; + + + // Look to see if this transition code is unique. + if (code_map.exist(code)) { + code_map.lookup(code).insertAtBottom(case_string); + } else { + Vector<string> vec; + vec.insertAtBottom(case_string); + code_map.add(code, vec); + code_vec.insertAtBottom(code); + } + } + + // Walk through all of the unique code blocks and spit out the + // corresponding case statement elements + for (int i=0; i<code_vec.size(); i++) { + string code = code_vec[i]; + + // Iterative over all the multiple transitions that share the same code + for (int case_num=0; case_num<code_map.lookup(code).size(); case_num++) { + string case_string = code_map.lookup(code)[case_num]; + out << " case HASH_FUN(" << case_string << "):" << endl; + } + out << code; + } + + out << " default:" << endl; + out << " WARN_EXPR(m_id);" << endl; + out << " WARN_EXPR(m_version);" << endl; + out << " WARN_EXPR(g_eventQueue_ptr->getTime());" << endl; + out << " WARN_EXPR(addr);" << endl; + out << " WARN_EXPR(event);" << endl; + out << " WARN_EXPR(state);" << endl; + out << " ERROR_MSG(\"Invalid transition\");" << endl; + out << " }" << endl; + out << " return TransitionResult_Valid;" << endl; + out << "}" << endl; +} + +void StateMachine::printProfilerH(ostream& out, string component) const +{ + out << "// Auto generated C++ code started by "<<__FILE__<<":"<<__LINE__<< endl; + out << "// " << getIdent() << ": " << getShorthand() << endl; + out << endl; + out << "#ifndef " << component << "_PROFILER_H" << endl; + out << "#define " << component << "_PROFILER_H" << endl; + out << endl; + out << "#include \"Global.hh\"" << endl; + out << "#include \"" << component << "_State.hh\"" << endl; + out << "#include \"" << component << "_Event.hh\"" << endl; + out << endl; + out << "class " << component << "_Profiler {" << endl; + out << "public:" << endl; + out << " " << component << "_Profiler();" << endl; + out << " void countTransition(" << component << "_State state, " << component << "_Event event);" << endl; + out << " void possibleTransition(" << component << "_State state, " << component << "_Event event);" << endl; + out << " void dumpStats(ostream& out) const;" << endl; + out << " void clearStats();" << endl; + out << "private:" << endl; + out << " int m_counters[" << component << "_State_NUM][" << component << "_Event_NUM];" << endl; + out << " int m_event_counters[" << component << "_Event_NUM];" << endl; + out << " bool m_possible[" << component << "_State_NUM][" << component << "_Event_NUM];" << endl; + out << "};" << endl; + out << "#endif // " << component << "_PROFILER_H" << endl; +} + +void StateMachine::printProfilerC(ostream& out, string component) const +{ + out << "// Auto generated C++ code started by "<<__FILE__<<":"<<__LINE__<< endl; + out << "// " << getIdent() << ": " << getShorthand() << endl; + out << endl; + out << "#include \"" << component << "_Profiler.hh\"" << endl; + out << endl; + + // Constructor + out << component << "_Profiler::" << component << "_Profiler()" << endl; + out << "{" << endl; + out << " for (int state = 0; state < " << component << "_State_NUM; state++) {" << endl; + out << " for (int event = 0; event < " << component << "_Event_NUM; event++) {" << endl; + out << " m_possible[state][event] = false;" << endl; + out << " m_counters[state][event] = 0;" << endl; + out << " }" << endl; + out << " }" << endl; + out << " for (int event = 0; event < " << component << "_Event_NUM; event++) {" << endl; + out << " m_event_counters[event] = 0;" << endl; + out << " }" << endl; + out << "}" << endl; + + // Clearstats + out << "void " << component << "_Profiler::clearStats()" << endl; + out << "{" << endl; + out << " for (int state = 0; state < " << component << "_State_NUM; state++) {" << endl; + out << " for (int event = 0; event < " << component << "_Event_NUM; event++) {" << endl; + out << " m_counters[state][event] = 0;" << endl; + out << " }" << endl; + out << " }" << endl; + out << " for (int event = 0; event < " << component << "_Event_NUM; event++) {" << endl; + out << " m_event_counters[event] = 0;" << endl; + out << " }" << endl; + out << "}" << endl; + + // Count Transition + out << "void " << component << "_Profiler::countTransition(" << component << "_State state, " << component << "_Event event)" << endl; + out << "{" << endl; + out << " assert(m_possible[state][event]);" << endl; + out << " m_counters[state][event]++;" << endl; + out << " m_event_counters[event]++;" << endl; + out << "}" << endl; + + // Possible Transition + out << "void " << component << "_Profiler::possibleTransition(" << component << "_State state, " << component << "_Event event)" << endl; + out << "{" << endl; + out << " m_possible[state][event] = true;" << endl; + out << "}" << endl; + + // dumpStats + out << "void " << component << "_Profiler::dumpStats(ostream& out) const" << endl; + out << "{" << endl; + out << " out << \" --- " << component << " ---\" << endl;" << endl; + out << " out << \" - Event Counts -\" << endl;" << endl; + out << " for (int event = 0; event < " << component << "_Event_NUM; event++) {" << endl; + out << " int count = m_event_counters[event];" << endl; + out << " out << (" << component << "_Event) event << \" \" << count << endl;" << endl; + out << " }" << endl; + out << " out << endl;" << endl; + out << " out << \" - Transitions -\" << endl;" << endl; + out << " for (int state = 0; state < " << component << "_State_NUM; state++) {" << endl; + out << " for (int event = 0; event < " << component << "_Event_NUM; event++) {" << endl; + out << " if (m_possible[state][event]) {" << endl; + out << " int count = m_counters[state][event];" << endl; + out << " out << (" << component << "_State) state << \" \" << (" << component << "_Event) event << \" \" << count;" << endl; + out << " if (count == 0) {" << endl; + out << " out << \" <-- \";" << endl; + out << " }" << endl; + out << " out << endl;" << endl; + out << " }" << endl; + out << " }" << endl; + out << " out << endl;" << endl; + out << " }" << endl; + out << "}" << endl; +} + + + +// ************************** // +// ******* HTML Files ******* // +// ************************** // + +string frameRef(string click_href, string click_target, string over_href, string over_target_num, string text) +{ + string temp; + temp += "<A href=\"" + click_href + "\" "; + temp += "target=\"" + click_target + "\" "; + string javascript = "if (parent.frames[" + over_target_num + "].location != parent.location + '" + over_href + "') { parent.frames[" + over_target_num + "].location='" + over_href + "' }"; + // string javascript = "parent." + target + ".location='" + href + "'"; + temp += "onMouseOver=\"" + javascript + "\" "; + temp += ">" + text + "</A>"; + return temp; +} + +string frameRef(string href, string target, string target_num, string text) +{ + return frameRef(href, target, href, target_num, text); +} + + +void StateMachine::writeHTMLFiles(string path) const +{ + string filename; + string component = getIdent(); + + /* + { + ostringstream out; + out << "<html>" << endl; + out << "<head>" << endl; + out << "<title>" << component << "</title>" << endl; + out << "</head>" << endl; + out << "<frameset rows=\"30,30,*\" frameborder=\"1\">" << endl; + out << " <frame name=\"Status\" src=\"empty.html\" marginheight=\"1\">" << endl; + out << " <frame name=\"Table\" src=\"" << component << "_table.html\" marginheight=\"1\">" << endl; + out << "</frameset>" << endl; + out << "</html>" << endl; + conditionally_write_file(path + component + ".html", out); + } + */ + + // Create table with no row hilighted + { + ostringstream out; + printHTMLTransitions(out, numStates()+1); + + // -- Write file + filename = component + "_table.html"; + conditionally_write_file(path + filename, out); + } + + // Generate transition tables + for(int i=0; i<numStates(); i++) { + ostringstream out; + printHTMLTransitions(out, i); + + // -- Write file + filename = component + "_table_" + getState(i).getIdent() + ".html"; + conditionally_write_file(path + filename, out); + } + + // Generate action descriptions + for(int i=0; i<numActions(); i++) { + ostringstream out; + createHTMLSymbol(getAction(i), "Action", out); + + // -- Write file + filename = component + "_action_" + getAction(i).getIdent() + ".html"; + conditionally_write_file(path + filename, out); + } + + // Generate state descriptions + for(int i=0; i<numStates(); i++) { + ostringstream out; + createHTMLSymbol(getState(i), "State", out); + + // -- Write file + filename = component + "_State_" + getState(i).getIdent() + ".html"; + conditionally_write_file(path + filename, out); + } + + // Generate event descriptions + for(int i=0; i<numEvents(); i++) { + ostringstream out; + createHTMLSymbol(getEvent(i), "Event", out); + + // -- Write file + filename = component + "_Event_" + getEvent(i).getIdent() + ".html"; + conditionally_write_file(path + filename, out); + } +} + +void StateMachine::printHTMLTransitions(ostream& out, int active_state) const +{ + // -- Prolog + out << "<HTML><BODY link=\"blue\" vlink=\"blue\">" << endl; + + // -- Header + out << "<H1 align=\"center\">" << formatHTMLShorthand(getShorthand()) << ": " << endl; + Vector<StateMachine*> machine_vec = g_sym_table.getStateMachines(); + for (int i=0; i<machine_vec.size(); i++) { + StateMachine* type = machine_vec[i]; + if (i != 0) { + out << " - "; + } + if (type == this) { + out << type->getIdent() << endl; + } else { + out << "<A target=\"Table\"href=\"" + type->getIdent() + "_table.html\">" + type->getIdent() + "</A> " << endl; + } + } + out << "</H1>" << endl; + + // -- Table header + out << "<TABLE border=1>" << endl; + + // -- Column headers + out << "<TR>" << endl; + + // -- First column header + out << " <TH> </TH>" << endl; + + for(int event = 0; event < numEvents(); event++ ) { + out << " <TH bgcolor=white>"; + out << frameRef(getIdent() + "_Event_" + getEvent(event).getIdent() + ".html", "Status", "1", formatHTMLShorthand(getEvent(event).getShorthand())); + out << "</TH>" << endl; + } + + out << "</TR>" << endl; + + // -- Body of table + for(int state = 0; state < numStates(); state++ ) { + out << "<TR>" << endl; + + // -- Each row + if (state == active_state) { + out << " <TH bgcolor=yellow>"; + } else { + out << " <TH bgcolor=white>"; + } + + string click_href = getIdent() + "_table_" + getState(state).getIdent() + ".html"; + string text = formatHTMLShorthand(getState(state).getShorthand()); + + out << frameRef(click_href, "Table", getIdent() + "_State_" + getState(state).getIdent() + ".html", "1", formatHTMLShorthand(getState(state).getShorthand())); + out << "</TH>" << endl; + + // -- One column for each event + for(int event = 0; event < numEvents(); event++ ) { + const Transition* trans_ptr = getTransPtr(state, event); + + if( trans_ptr != NULL ) { + bool stall_action = false; + string nextState; + string actions_str; + + // -- Get the actions + // actions = trans_ptr->getActionShorthands(); + const Vector<Action*> actions = trans_ptr->getActions(); + for (int action=0; action < actions.size(); action++) { + if ((actions[action]->getIdent() == "z_stall") || + (actions[action]->getIdent() == "zz_recycleMandatoryQueue")) { + stall_action = true; + } + actions_str += " "; + actions_str += frameRef(getIdent() + "_action_" + actions[action]->getIdent() + ".html", "Status", "1", + formatHTMLShorthand(actions[action]->getShorthand())); + actions_str += "\n"; + } + + // -- Get the next state + if (trans_ptr->getNextStatePtr()->getIdent() != getState(state).getIdent()) { + string click_href = getIdent() + "_table_" + trans_ptr->getNextStatePtr()->getIdent() + ".html"; + nextState = frameRef(click_href, "Table", getIdent() + "_State_" + trans_ptr->getNextStatePtr()->getIdent() + ".html", "1", + formatHTMLShorthand(trans_ptr->getNextStateShorthand())); + } else { + nextState = ""; + } + + // -- Print out "actions/next-state" + if (stall_action) { + if (state == active_state) { + out << " <TD bgcolor=#C0C000>"; + } else { + out << " <TD bgcolor=lightgrey>"; + } + } else if (active_state < numStates() && (trans_ptr->getNextStatePtr()->getIdent() == getState(active_state).getIdent())) { + out << " <TD bgcolor=aqua>"; + } else if (state == active_state) { + out << " <TD bgcolor=yellow>"; + } else { + out << " <TD bgcolor=white>"; + } + + out << actions_str; + if ((nextState.length() != 0) && (actions_str.length() != 0)) { + out << "/"; + } + out << nextState; + out << "</TD>" << endl; + } else { + // This is the no transition case + if (state == active_state) { + out << " <TD bgcolor=#C0C000> </TD>" << endl; + } else { + out << " <TD bgcolor=lightgrey> </TD>" << endl; + } + } + } + // -- Each row + if (state == active_state) { + out << " <TH bgcolor=yellow>"; + } else { + out << " <TH bgcolor=white>"; + } + + click_href = getIdent() + "_table_" + getState(state).getIdent() + ".html"; + text = formatHTMLShorthand(getState(state).getShorthand()); + + out << frameRef(click_href, "Table", getIdent() + "_State_" + getState(state).getIdent() + ".html", "1", formatHTMLShorthand(getState(state).getShorthand())); + out << "</TH>" << endl; + + out << "</TR>" << endl; + } + + // -- Column footer + out << "<TR>" << endl; + out << " <TH> </TH>" << endl; + + for(int i = 0; i < numEvents(); i++ ) { + out << " <TH bgcolor=white>"; + out << frameRef(getIdent() + "_Event_" + getEvent(i).getIdent() + ".html", "Status", "1", formatHTMLShorthand(getEvent(i).getShorthand())); + out << "</TH>" << endl; + } + out << "</TR>" << endl; + + // -- Epilog + out << "</TABLE>" << endl; + out << "</BODY></HTML>" << endl; +} + + diff --git a/src/mem/slicc/symbols/StateMachine.hh b/src/mem/slicc/symbols/StateMachine.hh new file mode 100644 index 000000000..9f3663ed4 --- /dev/null +++ b/src/mem/slicc/symbols/StateMachine.hh @@ -0,0 +1,141 @@ + +/* + * Copyright (c) 1999-2008 Mark D. Hill and David A. Wood + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer; + * redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution; + * neither the name of the copyright holders nor the names of its + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +/* + * $Id$ + * + * */ + +#ifndef STATEMACHINE_H +#define STATEMACHINE_H + +#include "slicc_global.hh" +#include "Vector.hh" +#include "Map.hh" +#include "Symbol.hh" + +class Transition; +class Event; +class State; +class Action; +class Var; +class Func; + +class StateMachine : public Symbol { +public: + // Constructors + StateMachine(string ident, const Location& location, const Map<string, string>& pairs); + + // Destructor + ~StateMachine(); + + // Public Methods + + // Add items to the state machine + // void setMachine(string ident, const Map<string, string>& pairs); + void addState(State* state_ptr); + void addEvent(Event* event_ptr); + void addAction(Action* action_ptr); + void addTransition(Transition* trans_ptr); + void addInPort(Var* var) { m_in_ports.insertAtBottom(var); } + void addFunc(Func* func); + + // Accessors to vectors + const State& getState(int index) const { return *m_states[index]; } + const Event& getEvent(int index) const { return *m_events[index]; } + const Action& getAction(int index) const { return *m_actions[index]; } + const Transition& getTransition(int index) const { return *m_transitions[index]; } + const Transition* getTransPtr(int stateIndex, int eventIndex) const; + + // Accessors for size of vectors + int numStates() const { return m_states.size(); } + int numEvents() const { return m_events.size(); } + int numActions() const { return m_actions.size(); } + int numTransitions() const { return m_transitions.size(); } + + void buildTable(); // Needs to be called before accessing the table + + // Code generator methods + void writeCFiles(string path) const; + void writeHTMLFiles(string path) const; + + void print(ostream& out) const { out << "[StateMachine: " << toString() << "]" << endl; } +private: + // Private Methods + void checkForDuplicate(const Symbol& sym) const; + + int getStateIndex(State* state_ptr) const { return m_state_map.lookup(state_ptr); } + int getEventIndex(Event* event_ptr) const { return m_event_map.lookup(event_ptr); } + + // Private copy constructor and assignment operator + // StateMachine(const StateMachine& obj); + // StateMachine& operator=(const StateMachine& obj); + + void printControllerH(ostream& out, string component) const; + void printControllerC(ostream& out, string component) const; + void printCWakeup(ostream& out, string component) const; + void printCSwitch(ostream& out, string component) const; + void printProfilerH(ostream& out, string component) const; + void printProfilerC(ostream& out, string component) const; + + void printHTMLTransitions(ostream& out, int active_state) const; + + // Data Members (m_ prefix) + Vector<State*> m_states; + Vector<Event*> m_events; + Vector<Action*> m_actions; + Vector<Transition*> m_transitions; + Vector<Func*> m_internal_func_vec; + + Map<State*, int> m_state_map; + Map<Event*, int> m_event_map; + + Vector<Var*> m_in_ports; + + // Table variables + bool m_table_built; + Vector<Vector<Transition*> > m_table; + +}; + +// Output operator declaration +ostream& operator<<(ostream& out, const StateMachine& obj); + +// ******************* Definitions ******************* + +// Output operator definition +extern inline +ostream& operator<<(ostream& out, const StateMachine& obj) +{ + obj.print(out); + out << flush; + return out; +} + +#endif //STATEMACHINE_H diff --git a/src/mem/slicc/symbols/Symbol.cc b/src/mem/slicc/symbols/Symbol.cc new file mode 100644 index 000000000..3365c94eb --- /dev/null +++ b/src/mem/slicc/symbols/Symbol.cc @@ -0,0 +1,72 @@ + +/* + * Copyright (c) 1999-2008 Mark D. Hill and David A. Wood + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer; + * redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution; + * neither the name of the copyright holders nor the names of its + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +/* + * $Id$ + * + */ + +#include "Symbol.hh" + +Symbol::Symbol(string id, const Location& location, const Map<string, string>& pairs) +{ + m_id = id; + m_location = location; + m_pairs = pairs; + if (!existPair("short")) { + addPair("short", m_id); + } + m_used = false; +} + +Symbol::Symbol(string id, const Location& location) +{ + m_id = id; + m_location = location; + if (!existPair("short")) { + addPair("short", m_id); + } + m_used = false; +} + +const string& Symbol::lookupPair(const string& key) const +{ + if (!existPair(key)) { + error("Value for pair '" + key + "' missing."); + } + return m_pairs.lookup(key); +} + +void Symbol::addPair(const string& key, const string& value) +{ + if (existPair(key)) { + warning("Pair key '" + key + "' re-defined. new: '" + value + "' old: '" + lookupPair(key) + "'"); + } + m_pairs.add(key, value); +} diff --git a/src/mem/slicc/symbols/Symbol.hh b/src/mem/slicc/symbols/Symbol.hh new file mode 100644 index 000000000..bca7d32db --- /dev/null +++ b/src/mem/slicc/symbols/Symbol.hh @@ -0,0 +1,100 @@ + +/* + * Copyright (c) 1999-2008 Mark D. Hill and David A. Wood + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer; + * redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution; + * neither the name of the copyright holders nor the names of its + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +/* + * $Id$ + */ + +#ifndef SYMBOL_H +#define SYMBOL_H + +#include "slicc_global.hh" +#include "Map.hh" +#include "Location.hh" + +class Symbol { +public: + // Constructors + Symbol(string id, const Location& location, const Map<string, string>& pairs); + Symbol(string id, const Location& location); + // Destructor + virtual ~Symbol() { } + + // Public Methods + void error(string err_msg) const { m_location.error(err_msg); } + void warning(string err_msg) const { m_location.warning(err_msg); } + const Location& getLocation() const { return m_location; } + + const string& toString() const { return m_id; } + + const string& getIdent() const { return m_id; } + const string& getShorthand() const { return lookupPair("short"); } + const string& getDescription() const { return lookupPair("desc"); } + + void markUsed() { m_used = true; } + bool wasUsed() { return m_used; } + + bool existPair(const string& key) const { return m_pairs.exist(key); } + const string& lookupPair(const string& key) const; + void addPair(const string& key, const string& value); + + // virtual string getCode() const = 0; + virtual void writeCFiles(string path) const {} + virtual void writeHTMLFiles(string path) const {} + virtual void print(ostream& out) const { out << "[Symbol: " << getIdent() << "]"; } + +private: + // Private Methods + + // Private copy constructor and assignment operator + // Symbol(const Symbol& obj); + // Symbol& operator=(const Symbol& obj); + + // Data Members (m_ prefix) + string m_id; + Map<string, string> m_pairs; + Location m_location; + bool m_used; +}; + +// Output operator declaration +ostream& operator<<(ostream& out, const Symbol& obj); + +// ******************* Definitions ******************* + +// Output operator definition +extern inline +ostream& operator<<(ostream& out, const Symbol& obj) +{ + obj.print(out); + out << flush; + return out; +} + +#endif //SYMBOL_H diff --git a/src/mem/slicc/symbols/SymbolTable.cc b/src/mem/slicc/symbols/SymbolTable.cc new file mode 100644 index 000000000..37e233e88 --- /dev/null +++ b/src/mem/slicc/symbols/SymbolTable.cc @@ -0,0 +1,934 @@ + +/* + * Copyright (c) 1999-2008 Mark D. Hill and David A. Wood + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer; + * redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution; + * neither the name of the copyright holders nor the names of its + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#include "SymbolTable.hh" +#include "fileio.hh" +#include "html_gen.hh" +#include "mif_gen.hh" +#include "Action.hh" + +SymbolTable g_sym_table; + +SymbolTable::SymbolTable() +{ + m_sym_map_vec.setSize(1); + m_depth = 0; + + { + Map<string, string> pairs; + pairs.add("enumeration", "yes"); + newSym(new Type("MachineType", Location(), pairs)); + } + + { + Map<string, string> pairs; + pairs.add("primitive", "yes"); + pairs.add("external", "yes"); + newSym(new Type("void", Location(), pairs)); + } +} + +SymbolTable::~SymbolTable() +{ + int size = m_sym_vec.size(); + for(int i=0; i<size; i++) { + delete m_sym_vec[i]; + } +} + +void SymbolTable::newSym(Symbol* sym_ptr) +{ + registerSym(sym_ptr->toString(), sym_ptr); + m_sym_vec.insertAtBottom(sym_ptr); // Holder for the allocated Sym objects. +} + +void SymbolTable::newMachComponentSym(Symbol* sym_ptr) +{ + // used to cheat-- that is, access components in other machines + StateMachine* mach_ptr = getStateMachine("current_machine"); + if (mach_ptr != NULL) { + m_machine_component_map_vec.lookup(mach_ptr->toString()).add(sym_ptr->toString(), sym_ptr); + } +} + +Var* SymbolTable::getMachComponentVar(string mach, string ident) +{ + Symbol* s = m_machine_component_map_vec.lookup(mach).lookup(ident); + return dynamic_cast<Var*>(s); +} + + +void SymbolTable::registerSym(string id, Symbol* sym_ptr) +{ + + // Check for redeclaration (in the current frame only) + if (m_sym_map_vec[m_depth].exist(id)) { + sym_ptr->error("Symbol '" + id + "' redeclared in same scope."); + } + // FIXME - warn on masking of a declaration in a previous frame + m_sym_map_vec[m_depth].add(id, sym_ptr); +} + +void SymbolTable::registerGlobalSym(string id, Symbol* sym_ptr) +{ + // Check for redeclaration (global frame only) + if (m_sym_map_vec[0].exist(id)) { + sym_ptr->error("Global symbol '" + id + "' redeclared in global scope."); + } + m_sym_map_vec[0].add(id, sym_ptr); +} + +Symbol* SymbolTable::getSym(string ident) const +{ + for (int i=m_depth; i>=0; i--) { + if (m_sym_map_vec[i].exist(ident)) { + return m_sym_map_vec[i].lookup(ident); + } + } + return NULL; +} + +void SymbolTable::newCurrentMachine(StateMachine* sym_ptr) +{ + registerGlobalSym(sym_ptr->toString(), sym_ptr); + registerSym("current_machine", sym_ptr); + m_sym_vec.insertAtBottom(sym_ptr); // Holder for the allocated Sym objects. + + Map<string, Symbol*> m; + m_machine_component_map_vec.add(sym_ptr->toString(),m); + +} + +Type* SymbolTable::getType(string ident) const +{ + return dynamic_cast<Type*>(getSym(ident)); +} + +Var* SymbolTable::getVar(string ident) const +{ + return dynamic_cast<Var*>(getSym(ident)); +} + +Func* SymbolTable::getFunc(string ident) const +{ + return dynamic_cast<Func*>(getSym(ident)); +} + +StateMachine* SymbolTable::getStateMachine(string ident) const +{ + return dynamic_cast<StateMachine*>(getSym(ident)); +} + +void SymbolTable::pushFrame() +{ + m_depth++; + m_sym_map_vec.expand(1); + m_sym_map_vec[m_depth].clear(); +} + +void SymbolTable::popFrame() +{ + m_depth--; + assert(m_depth >= 0); + m_sym_map_vec.expand(-1); +} + +void SymbolTable::writeCFiles(string path) const +{ + int size = m_sym_vec.size(); + { + // Write the Types.hh include file for the types + ostringstream sstr; + sstr << "/** Auto generated C++ code started by "<<__FILE__<<":"<<__LINE__<< " */" << endl; + sstr << endl; + sstr << "#include \"RubySlicc_includes.hh\"" << endl; + for(int i=0; i<size; i++) { + Type* type = dynamic_cast<Type*>(m_sym_vec[i]); + if (type != NULL && !type->isPrimitive()) { + sstr << "#include \"" << type->cIdent() << ".hh" << "\"" << endl; + } + } + conditionally_write_file(path + "/Types.hh", sstr); + } + + // Write all the symbols + for(int i=0; i<size; i++) { + m_sym_vec[i]->writeCFiles(path + '/'); + } + + writeChipFiles(path); +} + +void SymbolTable::writeChipFiles(string path) const +{ + // Create Chip.cc and Chip.hh + + // FIXME - Note: this method is _really_ ugly. Most of this + // functionality should be pushed into each type of symbol and use + // virtual methods to get the right behavior for each type of + // symbol. This is also more flexible, and much cleaner. + + int size = m_sym_vec.size(); + + // Create Chip.h + { + ostringstream sstr; + sstr << "/** \\file Chip.h " << endl; + sstr << " * Auto generated C++ code started by "<<__FILE__<<":"<<__LINE__<<endl; + sstr << " */ " <<endl<<endl; + + sstr << "#ifndef CHIP_H" << endl; + sstr << "#define CHIP_H" << endl; + sstr << endl; + + // Includes + sstr << "#include \"Global.hh\"" << endl; + sstr << "#include \"Types.hh\"" << endl; + sstr << "#include \"AbstractChip.hh\"" << endl; + sstr << "class Network;" << endl; + sstr << endl; + + // Class declarations for all Machines/Controllers + for(int i=0; i<size; i++) { + StateMachine* machine = dynamic_cast<StateMachine*>(m_sym_vec[i]); + if (machine != NULL) { + sstr << "class " << machine->getIdent() << "_Controller;" << endl; + } + } + + sstr << "class Chip : public AbstractChip {" << endl; + sstr << "public:" << endl; + sstr << endl; + sstr << " // Constructors" << endl; + sstr << " Chip(NodeID chip_number, Network* net_ptr);" << endl; + sstr << endl; + sstr << " // Destructor" << endl; + sstr << " ~Chip();" << endl; + sstr << endl; + sstr << " // Public Methods" << endl; + sstr << " void recordCacheContents(CacheRecorder& tr) const;" << endl; + sstr << " void dumpCaches(ostream& out) const;" << endl; + sstr << " void dumpCacheData(ostream& out) const;" << endl; + sstr << " static void printStats(ostream& out);" << endl; + sstr << " static void clearStats();" << endl; + sstr << " void printConfig(ostream& out);" << endl; + sstr << " void print(ostream& out) const;" << endl; + + // Used by coherence checker + sstr << "#ifdef CHECK_COHERENCE" << endl; + sstr << " bool isBlockShared(const Address& addr) const;" << endl; + sstr << " bool isBlockExclusive(const Address& addr) const;" << endl; + sstr << "#endif /* CHECK_COHERENCE */" << endl; + + sstr << endl; + sstr << "private:" << endl; + sstr << " // Private copy constructor and assignment operator" << endl; + sstr << " Chip(const Chip& obj);" << endl; + sstr << " Chip& operator=(const Chip& obj);" << endl; + sstr << endl; + sstr << "public: // FIXME - these should not be public" << endl; + sstr << " // Data Members (m_ prefix)" << endl; + sstr << endl; + sstr << " Chip* m_chip_ptr;" << endl; + sstr << endl; + sstr << " // SLICC object variables" << endl; + sstr << endl; + + // Look at all 'Vars' + for(int i=0; i<size; i++) { + Var* var = dynamic_cast<Var*>(m_sym_vec[i]); + if (var != NULL) { + if (var->existPair("chip_object")) { + if (var->existPair("no_chip_object")) { + // Do nothing + } else { + string template_hack = ""; + if (var->existPair("template_hack")) { + template_hack = var->lookupPair("template_hack"); + } + if (// var->existPair("network") || var->getType()->existPair("cache") || +// var->getType()->existPair("tbe") || var->getType()->existPair("newtbe") || +// var->getType()->existPair("dir") || var->getType()->existPair("persistent") || +// var->getType()->existPair("filter") || var->getType()->existPair("timer") || +// var->existPair("trigger_queue") + var->existPair("no_vector") + ) { + sstr << " " << var->getType()->cIdent() << template_hack << "* m_" + << var->cIdent() << "_ptr;" << endl; + } else { + // create pointer except those created in AbstractChip + if (!(var->existPair("abstract_chip_ptr"))) { + sstr << " Vector < " << var->getType()->cIdent() << template_hack + << "* > m_" << var->cIdent() << "_vec;" << endl; + } + } + } + } + } + } + + sstr << endl; + sstr << " // SLICC machine/controller variables" << endl; + + // Look at all 'Machines' + for(int i=0; i<size; i++) { + StateMachine* machine = dynamic_cast<StateMachine*>(m_sym_vec[i]); + if (machine != NULL) { + string ident = machine->getIdent() + "_Controller"; + sstr << " Vector < " << ident << "* > m_" << ident << "_vec;\n"; + } + } + + sstr << endl; + + sstr << " // machine external SLICC function decls\n"; + + // Look at all 'Functions' + for(int i=0; i<size; i++) { + Func* func = dynamic_cast<Func*>(m_sym_vec[i]); + if (func != NULL) { + string proto; + func->funcPrototype(proto); + if (proto != "") { + sstr << " " << proto; + } + } + } + + sstr << "};" << endl; + sstr << endl; + sstr << "#endif // CHIP_H" << endl; + + conditionally_write_file(path + "/Chip.hh", sstr); + } + // Create Chip.cc + { + ostringstream sstr; + sstr << "// Auto generated C++ code started by "<<__FILE__<<":"<<__LINE__<<endl<<endl; + sstr << "#include \"Chip.hh\"" << endl; + sstr << "#include \"Network.hh\"" << endl; + sstr << "#include \"CacheRecorder.hh\"" << endl; + sstr << "" << endl; + + sstr << "// Includes for controllers" << endl; + for(int i=0; i<size; i++) { + StateMachine* machine = dynamic_cast<StateMachine*>(m_sym_vec[i]); + if (machine != NULL) { + sstr << "#include \"" << machine->getIdent() << "_Controller.hh\"" << endl; + } + } + + sstr << "" << endl; + sstr << "Chip::Chip(NodeID id, Network* net_ptr):AbstractChip(id, net_ptr)" << endl; + sstr << "{" << endl; + sstr << " m_chip_ptr = this;" << endl; + + // FIXME - WHY IS THIS LOOP HERE? + // WE SEEM TO BE CREATING A SEQUENCER HERE THEN OVERWRITTING THAT INSTANITATION + // IN THE NEXT LOOP +// // find sequencer's type +// for(int i=0; i<size; i++) { +// Var* var = dynamic_cast<Var*>(m_sym_vec[i]); +// if(var && var->cIdent() == "sequencer") +// sstr << " m_sequencer_ptr = new " << var->getType()->cIdent() << "(this);\n"; +// } + + // Look at all 'Vars' + for(int i=0; i<size; i++) { + Var* var = dynamic_cast<Var*>(m_sym_vec[i]); + if (var != NULL && var->existPair("chip_object") && !var->existPair("no_chip_object")) { + + sstr << " // " << var->cIdent() << endl; + if (!var->existPair("network")) { + // Not a network port object + if (var->getType()->existPair("primitive")) { + // Normal non-object + // sstr << " m_" << var->cIdent() << "_ptr = new " << var->getType()->cIdent() << ";\n"; + + sstr << " m_" << var->cIdent(); + sstr << "_vec.setSize(RubyConfig::numberOf"; + sstr << var->getMachine()->getIdent() << "PerChip(m_id));" << endl; + sstr << " for (int i = 0; i < RubyConfig::numberOf" << var->getMachine()->getIdent() + << "PerChip(m_id); i++) {" << endl; + sstr << " m_" << var->cIdent() << "_vec[i] = new " << var->getType()->cIdent() << ";\n"; + if (var->existPair("default")) { + sstr << " *(m_" << var->cIdent() << "_vec[i]) = " << var->lookupPair("default") << ";\n"; + } + sstr << " }\n"; + + } else { + + // Normal Object + string template_hack = ""; + if (var->existPair("template_hack")) { + template_hack = var->lookupPair("template_hack"); + } + if (// var->getType()->existPair("cache") || var->getType()->existPair("tbe") || +// var->getType()->existPair("newtbe") || var->getType()->existPair("timer") || +// var->getType()->existPair("dir") || var->getType()->existPair("persistent") || +// var->getType()->existPair("filter") || var->existPair("trigger_queue") + var->existPair("no_vector")) { + sstr << " m_" << var->cIdent() << "_ptr = new " << var->getType()->cIdent() << template_hack; + if (!var->getType()->existPair("non_obj") && (!var->getType()->isEnumeration())) { + if (var->existPair("constructor_hack")) { + string constructor_hack = var->lookupPair("constructor_hack"); + sstr << "(this, " << constructor_hack << ")"; + } else { + sstr << "(this)"; + } + } + sstr << ";\n"; + sstr << " assert(m_" << var->cIdent() << "_ptr != NULL);" << endl; + + if (var->existPair("default")) { + sstr << " (*m_" << var->cIdent() << "_ptr) = " << var->lookupPair("default") + << "; // Object default" << endl; + } else if (var->getType()->hasDefault()) { + sstr << " (*m_" << var->cIdent() << "_ptr) = " << var->getType()->getDefault() + << "; // Type " << var->getType()->getIdent() << " default" << endl; + } + + // Set ordering + if (var->existPair("ordered") && !var->existPair("trigger_queue")) { + // A buffer + string ordered = var->lookupPair("ordered"); + sstr << " m_" << var->cIdent() << "_ptr->setOrdering(" << ordered << ");\n"; + } + + // Set randomization + if (var->existPair("random")) { + // A buffer + string value = var->lookupPair("random"); + sstr << " m_" << var->cIdent() << "_ptr->setRandomization(" << value << ");\n"; + } + + // Set Priority + if (var->getType()->isBuffer() && var->existPair("rank") && !var->existPair("trigger_queue")) { + string rank = var->lookupPair("rank"); + sstr << " m_" << var->cIdent() << "_ptr->setPriority(" << rank << ");\n"; + } + } else if ((var->getType()->existPair("mover")) && (var->getMachine()->getIdent() == "L2Cache")) { + // FIXME - dnuca mover is a special case + sstr << " m_" << var->cIdent() << "_ptr = NULL;" << endl; + sstr << " if (RubyConfig::isL2CacheDNUCAMoverChip(m_id)) {" << endl; + sstr << " m_" << var->cIdent() << "_ptr = new " << var->getType()->cIdent() << template_hack; + if (!var->getType()->existPair("non_obj") && (!var->getType()->isEnumeration())) { + if (var->existPair("constructor_hack")) { + string constructor_hack = var->lookupPair("constructor_hack"); + sstr << "(this, " << constructor_hack << ")"; + } else { + sstr << "(this)"; + } + } + sstr << ";\n"; + sstr << " }\n"; + } else if (var->getType()->existPair("mover") && ((var->getMachine()->getIdent() == "L1Cache") || (var->getMachine()->getIdent() == "Collector"))) { + sstr << " m_" << var->cIdent() << "_ptr = NULL;" << endl; + sstr << " \n"; + } else { + sstr << " m_" << var->cIdent(); + sstr << "_vec.setSize(RubyConfig::numberOf"; + sstr << var->getMachine()->getIdent() << "PerChip(m_id));" << endl; + sstr << " for (int i = 0; i < RubyConfig::numberOf" << var->getMachine()->getIdent() + << "PerChip(m_id); i++) {" << endl; + + + ostringstream tail; + tail << template_hack; + if (!var->getType()->existPair("non_obj") && (!var->getType()->isEnumeration())) { + if (var->existPair("constructor_hack")) { + string constructor_hack = var->lookupPair("constructor_hack"); + tail << "(this, " << constructor_hack << ")"; + } else { + tail << "(this)"; + } + } + tail << ";\n"; + + + if(var->existPair("child_selector")){ + string child_selector = var->lookupPair("child_selector"); + string child_types = var->lookupPair("child_types"); + string::iterator it = child_types.begin(); + + uint num_types = 0; + for(uint t=0;t<child_types.size();t++){ + if(child_types.at(t) == '<'){ + num_types++; + } + } + + string* types = new string[num_types]; + string* ids = new string[num_types]; + int type_idx = 0; + bool id_done = false; + for(uint t=0;t<child_types.size();t++){ + if(child_types[t] == '<'){ + id_done = false; + uint r; + for(r=t+1;child_types.at(r)!='>';r++){ + if(r == child_types.size()){ + cerr << "Parse error in child_types" << endl; + exit(EXIT_FAILURE); + } + if(child_types.at(r) == ' ') continue; //ignore whitespace + if(child_types.at(r) == ',') {id_done = true;continue;} + if(id_done == true) + types[type_idx].push_back(child_types.at(r)); + else + ids[type_idx].push_back(child_types.at(r)); + } + type_idx++; + t = r; + } + } + + for(uint t=0;t<num_types;t++){ + if(t==0) + sstr << " if(strcmp(" << child_selector << ", \"" << ids[t] << "\") == 0)" << endl; + else + sstr << " else if(strcmp(" << child_selector << ", \"" << ids[t] << "\") == 0)" << endl; + sstr << " m_" << var->cIdent() << "_vec[i] = new " << types[t] << tail.str() << endl; + } + } + else { + sstr << " m_" << var->cIdent() << "_vec[i] = new " << var->getType()->cIdent() << tail.str() << endl; + } + + sstr << " assert(m_" << var->cIdent() << "_vec[i] != NULL);" << endl; + if (var->existPair("ordered")) { + string ordered = var->lookupPair("ordered"); + sstr << " m_" << var->cIdent() << "_vec[i]->setOrdering(" << ordered << ");\n"; + } + if (var->existPair("rank")) { + string rank = var->lookupPair("rank"); + sstr << " m_" << var->cIdent() << "_vec[i]->setPriority(" << rank << ");\n"; + } + + // Set buffer size + if (var->getType()->isBuffer() && !var->existPair("infinite")) { + sstr << " if (FINITE_BUFFERING) {\n"; + sstr << " m_" << var->cIdent() << "_vec[i]->setSize(PROCESSOR_BUFFER_SIZE);\n"; + sstr << " }\n"; + } + + sstr << " }\n"; + } + } + + sstr << endl; + + } else { + // Network port object + string network = var->lookupPair("network"); + string ordered = var->lookupPair("ordered"); + string vnet = var->lookupPair("virtual_network"); + + if (var->getMachine() != NULL) { + sstr << " m_" << var->cIdent() << "_vec.setSize(RubyConfig::numberOf" + << var->getMachine()->getIdent() << "PerChip(m_id));" << endl; + sstr << " for (int i = 0; i < RubyConfig::numberOf" << var->getMachine()->getIdent() + << "PerChip(m_id); i++) {" << endl; + sstr << " m_" << var->cIdent() << "_vec[i] = m_net_ptr->get" + << network << "NetQueue(i+m_id*RubyConfig::numberOf" <<var->getMachine()->getIdent() + << "PerChip()+MachineType_base_number(string_to_MachineType(\"" + << var->getMachine()->getIdent() << "\")), " + << ordered << ", " << vnet << ");\n"; + sstr << " assert(m_" << var->cIdent() << "_vec[i] != NULL);" << endl; + } else { // old protocol + sstr << " m_" << var->cIdent() << "_vec.setSize(1);" << endl; + sstr << " for (int i = 0; i < 1; i++) {" << endl; + sstr << " m_" << var->cIdent() << "_vec[i] = m_net_ptr->get" + << network << "NetQueue(m_id, " + << ordered << ", " << vnet << ");\n"; + sstr << " assert(m_" << var->cIdent() << "_vec[i] != NULL);" << endl; + } + + // Set ordering + if (var->existPair("ordered")) { + // A buffer + string ordered = var->lookupPair("ordered"); + sstr << " m_" << var->cIdent() << "_vec[i]->setOrdering(" << ordered << ");\n"; + } + + // Set randomization + if (var->existPair("random")) { + // A buffer + string value = var->lookupPair("random"); + sstr << " m_" << var->cIdent() << "_vec[i]->setRandomization(" << value << ");\n"; + } + + // Set Priority + if (var->existPair("rank")) { + string rank = var->lookupPair("rank"); + sstr << " m_" << var->cIdent() << "_vec[i]->setPriority(" << rank << ");\n"; + } + + // Set buffer size + if (var->getType()->isBuffer()) { + sstr << " if (FINITE_BUFFERING) {\n"; + sstr << " m_" << var->cIdent() << "_vec[i]->setSize(PROTOCOL_BUFFER_SIZE);\n"; + sstr << " }\n"; + } + + sstr << " }\n"; + } + } + } + // Look at all 'Machines' + for(int i=0; i<size; i++) { + StateMachine* machine = dynamic_cast<StateMachine*>(m_sym_vec[i]); + if (machine != NULL) { + string ident = machine->getIdent() + "_Controller"; + sstr << " m_" << ident << "_vec.setSize(RubyConfig::numberOf" << machine->getIdent() + << "PerChip(m_id));" << endl; + sstr << " for (int i = 0; i < RubyConfig::numberOf" << machine->getIdent() + << "PerChip(m_id); i++) {" << endl; + sstr << " m_" << ident << "_vec[i] = new " << ident << "(this, i);\n"; + sstr << " assert(m_" << ident << "_vec[i] != NULL);" << endl; + sstr << " }\n"; + sstr << endl; + } + } + + sstr << "}" << endl; + sstr << endl; + sstr << "Chip::~Chip()\n"; + sstr << "{\n"; + +// // FIXME: sequencer shouldn' be manually handled +// sstr << " delete m_sequencer_ptr;" << endl; + + // Look at all 'Vars' + for(int i=0; i<size; i++) { + Var* var = dynamic_cast<Var*>(m_sym_vec[i]); + if (var != NULL) { + if (var->existPair("chip_object")) { + if (var->existPair("no_chip_object")) { + // Do nothing + } else { + string template_hack = ""; + if (var->existPair("template_hack")) { + template_hack = var->lookupPair("template_hack"); + } + if (// var->getType()->existPair("cache") || var->getType()->existPair("tbe") || +// var->getType()->existPair("newtbe") || var->getType()->existPair("timer") || +// var->getType()->existPair("dir") || var->getType()->existPair("persistent") || +// var->getType()->existPair("filter") || var->existPair("trigger_queue") + var->existPair("no_vector")) { + sstr << " delete m_" << var->cIdent() << "_ptr;\n"; + } else if ((var->getType()->existPair("mover")) && (var->getMachine()->getIdent() == "L2Cache")) { + sstr << " if (RubyConfig::isL2CacheDNUCAMoverChip(m_id)) {" << endl; + sstr << " delete m_" << var->cIdent() << "_ptr;\n"; + sstr << " }\n"; + } else if (var->getType()->existPair("mover") && ((var->getMachine()->getIdent() == "L1Cache") || (var->getMachine()->getIdent() == "Collector"))) { + sstr << " m_" << var->cIdent() << "_ptr = NULL;" << endl; + } else if (!var->existPair("network")) { + // Normal Object + sstr << " for (int i = 0; i < RubyConfig::numberOf" << var->getMachine()->getIdent() + << "PerChip(m_id); i++) {" << endl; + sstr << " delete m_" << var->cIdent() << "_vec[i];\n"; + sstr << " }\n"; + } + } + } + } + } + + // Look at all 'Machines' + for(int i=0; i<size; i++) { + StateMachine* machine = dynamic_cast<StateMachine*>(m_sym_vec[i]); + if (machine != NULL) { + string ident = machine->getIdent() + "_Controller"; + sstr << " for (int i = 0; i < RubyConfig::numberOf" << machine->getIdent() + << "PerChip(m_id); i++) {" << endl; + sstr << " delete m_" << ident << "_vec[i];\n"; + sstr << " }\n"; + } + } + sstr << "}\n"; + + sstr << "\n"; + sstr << "void Chip::clearStats()\n"; + sstr << "{\n"; + + + // Look at all 'Machines' + for(int i=0; i<size; i++) { + StateMachine* machine = dynamic_cast<StateMachine*>(m_sym_vec[i]); + if (machine != NULL) { + string ident = machine->getIdent() + "_Controller"; + sstr << " " << ident << "::clearStats();\n"; + } + } + + sstr << "}\n"; + + sstr << "\n"; + sstr << "void Chip::printStats(ostream& out)\n"; + sstr << "{\n"; + sstr << " out << endl;\n"; + sstr << " out << \"Chip Stats\" << endl;\n"; + sstr << " out << \"----------\" << endl << endl;\n"; + + // Look at all 'Machines' + for(int i=0; i<size; i++) { + StateMachine* machine = dynamic_cast<StateMachine*>(m_sym_vec[i]); + if (machine != NULL) { + string ident = machine->getIdent() + "_Controller"; + sstr << " " << ident << "::dumpStats(out);\n"; + } + } + + sstr << "}" << endl; + sstr << endl; + sstr << "void Chip::printConfig(ostream& out)\n"; + sstr << "{\n"; + sstr << " out << \"Chip Config\" << endl;\n"; + sstr << " out << \"-----------\" << endl;\n"; + sstr << " out << \"Total_Chips: \" << RubyConfig::numberOfChips() << endl;\n"; + + // Look at all 'Vars' + for(int i=0; i<size; i++) { + Var* var = dynamic_cast<Var*>(m_sym_vec[i]); + if (var != NULL) { + if (var->existPair("chip_object")) { + if (var->existPair("no_chip_object")) { + // Do nothing + } else { + string template_hack = ""; + if (var->existPair("template_hack")) { + template_hack = var->lookupPair("template_hack"); + } + + if (!var->existPair("network") && (!var->getType()->existPair("primitive"))) { + // Normal Object + if (!var->getType()->existPair("non_obj") && (!var->getType()->isEnumeration())) { + if (var->existPair("no_vector")) { + sstr << " m_" << var->cIdent() << "_ptr->printConfig(out);\n"; + } else { + sstr << " out << \"\\n" << var->cIdent() << " numberPerChip: \" << RubyConfig::numberOf" << var->getMachine()->getIdent() + << "PerChip() << endl;\n"; + sstr << " m_" << var->cIdent() << "_vec[0]->printConfig(out);\n"; +// sstr << " for (int i = 0; i < RubyConfig::numberOf" << var->getMachine()->getIdent() +// << "PerChip(m_id); i++) {" << endl; +// sstr << " m_" << var->cIdent() << "_vec[i]->printConfig(out);\n"; +// sstr << " }\n"; + } + } + } + } + } + } + } + + sstr << " out << endl;\n"; + sstr << "}" << endl; + + sstr << endl; + sstr << "void Chip::print(ostream& out) const\n"; + sstr << "{\n"; + sstr << " out << \"Ruby Chip\" << endl;\n"; + sstr << "}" << endl; + + sstr << "#ifdef CHECK_COHERENCE" << endl; + sstr << endl; + sstr << "bool Chip::isBlockShared(const Address& addr) const" << endl; + sstr << "{" << endl; + + // Look at all 'Machines' + for(int i=0; i<size; i++) { + StateMachine* machine = dynamic_cast<StateMachine*>(m_sym_vec[i]); + if (machine != NULL) { + string ident = machine->getIdent() + "_Controller"; + sstr << " for (int i = 0; i < RubyConfig::numberOf" << machine->getIdent() + << "PerChip(m_id); i++) {" << endl; + sstr << " if (m_" << ident << "_vec[i]->" << machine->getIdent() << "_isBlockShared(addr)) {\n"; + sstr << " return true; \n"; + sstr << " }\n"; + sstr << " }\n"; + } + } + sstr << " return false;" << endl; + sstr << "}" << endl; + sstr << endl; + + sstr << endl; + sstr << "bool Chip::isBlockExclusive(const Address& addr) const" << endl; + sstr << "{" << endl; + + // Look at all 'Machines' + for(int i=0; i<size; i++) { + StateMachine* machine = dynamic_cast<StateMachine*>(m_sym_vec[i]); + if (machine != NULL) { + string ident = machine->getIdent() + "_Controller"; + sstr << " for (int i = 0; i < RubyConfig::numberOf" << machine->getIdent() + << "PerChip(m_id); i++) {" << endl; + sstr << " if (m_" << ident << "_vec[i]->" << machine->getIdent() << "_isBlockExclusive(addr)) {\n"; + sstr << " return true; \n"; + sstr << " }\n"; + sstr << " }\n"; + } + } + + sstr << " return false;" << endl; + sstr << "}" << endl; + sstr << endl; + + sstr << "#endif /* CHECK_COHERENCE */ " << endl; + + + sstr << endl; + sstr << "void Chip::dumpCaches(ostream& out) const" << endl; + sstr << "{" << endl; + + // Look at all 'Vars' + for(int i=0; i<size; i++) { + Var* var = dynamic_cast<Var*>(m_sym_vec[i]); + if (var != NULL) { + if (var->getType()->existPair("cache")){ // caches are partitioned one per controller instaniation + sstr << " for (int i = 0; i < RubyConfig::numberOf" << var->getMachine()->getIdent() + << "PerChip(m_id); i++) {" << endl; + sstr << " m_" << var->cIdent() << "_vec[i]->print(out);\n"; + sstr << " }\n"; + } + } + } + sstr << "}" << endl; + sstr << endl; + + // Function to dump cache tag and data information + sstr << "void Chip::dumpCacheData(ostream& out) const" << endl; + sstr << "{" << endl; + + // Look at all 'Vars' + for(int i=0; i<size; i++) { + Var* var = dynamic_cast<Var*>(m_sym_vec[i]); + if (var != NULL) { + if (var->getType()->existPair("cache")){ // caches are partitioned one per controller instaniation + sstr << " for (int i = 0; i < RubyConfig::numberOf" << var->getMachine()->getIdent() + << "PerChip(m_id); i++) {" << endl; + sstr << " m_" << var->cIdent() << "_vec[i]->printData(out);\n"; + sstr << " }\n"; + } + } + } + sstr << "}" << endl; + sstr << endl; + + sstr << "void Chip::recordCacheContents(CacheRecorder& tr) const" << endl; + sstr << "{" << endl; + + // Look at all 'Vars' + for(int i=0; i<size; i++) { + Var* var = dynamic_cast<Var*>(m_sym_vec[i]); + if (var != NULL) { + if (var->getType()->existPair("cache")){ // caches are partitioned one per controller instaniation + sstr << " for (int i = 0; i < RubyConfig::numberOf" << var->getMachine()->getIdent() + << "PerChip(m_id); i++) {" << endl; + sstr << " m_" << var->cIdent() << "_vec[i]->recordCacheContents(tr);\n"; + sstr << " }\n"; + } + } + } + sstr << "}" << endl; + + conditionally_write_file(path + "/Chip.cc", sstr); + } +} + +Vector<StateMachine*> SymbolTable::getStateMachines() const +{ + Vector<StateMachine*> machine_vec; + int size = m_sym_vec.size(); + for(int i=0; i<size; i++) { + StateMachine* type = dynamic_cast<StateMachine*>(m_sym_vec[i]); + if (type != NULL) { + machine_vec.insertAtBottom(type); + } + } + return machine_vec; +} + +void SymbolTable::writeHTMLFiles(string path) const +{ + // Create index.html + { + ostringstream out; + createHTMLindex(path, out); + conditionally_write_file(path + "index.html", out); + } + + // Create empty.html + { + ostringstream out; + out << "<HTML></HTML>"; + conditionally_write_file(path + "empty.html", out); + } + + // Write all the symbols + int size = m_sym_vec.size(); + for(int i=0; i<size; i++) { + m_sym_vec[i]->writeHTMLFiles(path); + } +} + +void write_file(string filename, ostringstream& sstr) +{ + ofstream out; + + out.open(filename.c_str()); + out << sstr.str(); + out.close(); +} + +void SymbolTable::writeMIFFiles(string path) const +{ + int size = m_sym_vec.size(); + for(int i=0; i<size; i++) { + ostringstream states, events, actions, transitions; + StateMachine* machine = dynamic_cast<StateMachine*>(m_sym_vec[i]); + if (machine != NULL) { + printStateTableMIF(*machine, states); + write_file(path + machine->getIdent() + "_states.mif", states); + printEventTableMIF(*machine, events); + write_file(path + machine->getIdent() + "_events.mif", events); + printActionTableMIF(*machine, actions); + write_file(path + machine->getIdent() + "_actions.mif", actions); + printTransitionTableMIF(*machine, transitions); + write_file(path + machine->getIdent() + "_transitions.mif", transitions); + } + } +} + + +void SymbolTable::print(ostream& out) const +{ + out << "[SymbolTable]"; // FIXME +} diff --git a/src/mem/slicc/symbols/SymbolTable.hh b/src/mem/slicc/symbols/SymbolTable.hh new file mode 100644 index 000000000..8f40fe8c5 --- /dev/null +++ b/src/mem/slicc/symbols/SymbolTable.hh @@ -0,0 +1,121 @@ + +/* + * Copyright (c) 1999-2008 Mark D. Hill and David A. Wood + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer; + * redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution; + * neither the name of the copyright holders nor the names of its + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +/* + * SymbolTable.h + * + * Description: + * + * $Id$ + * + * */ + +#ifndef SYMBOLTABLE_H +#define SYMBOLTABLE_H + +#include "slicc_global.hh" +#include "Map.hh" +#include "Vector.hh" + +#include "Symbol.hh" +#include "Type.hh" +#include "Var.hh" +#include "Func.hh" +#include "StateMachine.hh" + +class SymbolTable; + +extern SymbolTable g_sym_table; + +class SymbolTable { +public: + // Constructors + SymbolTable(); + + // Destructor + ~SymbolTable(); + + // Public Methods + void newSym(Symbol* sym_ptr); + void registerSym(string id, Symbol* sym_ptr); + Symbol* getSym(string id) const; + + // used to cheat-- that is, access components in other machines + void newMachComponentSym(Symbol* sym_ptr); + Var* getMachComponentVar(string mach, string ident); + + void newCurrentMachine(StateMachine* machine_ptr); + StateMachine* getStateMachine(string ident) const; + StateMachine* getStateMachine() const { return getStateMachine("current_machine"); } + Type* getType(string ident) const; + + Var* getVar(string ident) const; + Func* getFunc(string ident) const; + + void pushFrame(); + void popFrame(); + + Vector<StateMachine*> getStateMachines() const; + + void writeCFiles(string path) const; + void writeHTMLFiles(string path) const; + void writeMIFFiles(string path) const; + + void print(ostream& out) const; +private: + // Private Methods + void registerGlobalSym(string id, Symbol* sym_ptr); + void writeChipFiles(string path) const; + + // Private copy constructor and assignment operator + SymbolTable(const SymbolTable& obj); + SymbolTable& operator=(const SymbolTable& obj); + + // Data Members (m_ prefix) + Vector<Symbol*> m_sym_vec; + Vector<Map<string, Symbol*> > m_sym_map_vec; + Map<string, Map<string, Symbol*> > m_machine_component_map_vec; + int m_depth; +}; + +// Output operator declaration +ostream& operator<<(ostream& out, const SymbolTable& obj); + +// ******************* Definitions ******************* + +// Output operator definition +extern inline +ostream& operator<<(ostream& out, const SymbolTable& obj) +{ + obj.print(out); + out << flush; + return out; +} + +#endif //SYMBOLTABLE_H diff --git a/src/mem/slicc/symbols/Transition.cc b/src/mem/slicc/symbols/Transition.cc new file mode 100644 index 000000000..7c144c101 --- /dev/null +++ b/src/mem/slicc/symbols/Transition.cc @@ -0,0 +1,173 @@ + +/* + * Copyright (c) 1999-2008 Mark D. Hill and David A. Wood + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer; + * redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution; + * neither the name of the copyright holders nor the names of its + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +/* + * $Id$ + * + * */ + +#include "Transition.hh" +#include "State.hh" +#include "Event.hh" +#include "Action.hh" +#include "util.hh" +#include "Var.hh" + +Transition::Transition(string state, string event, string nextState, + const Vector<string>& actionList, + const Location& location, + const Map<string, string>& pairMap) + : Symbol(state + "|" + event, location, pairMap) +{ + m_state = state; + m_event = event; + m_nextState = nextState; + m_actionList = actionList; + + // Ptrs are undefined at this point + m_statePtr = NULL; + m_eventPtr = NULL; + m_nextStatePtr = NULL; + m_actionPtrsValid = false; +} + +void Transition::checkIdents(const Vector<State*>& states, + const Vector<Event*>& events, + const Vector<Action*>& actions) +{ + m_statePtr = findIndex(states, m_state); + m_eventPtr = findIndex(events, m_event); + m_nextStatePtr = findIndex(states, m_nextState); + + for(int i=0; i < m_actionList.size(); i++) { + Action* action_ptr = findIndex(actions, m_actionList[i]); + int size = action_ptr->getResources().keys().size(); + for (int j=0; j < size; j++) { + Var* var_ptr = action_ptr->getResources().keys()[j]; + if (var_ptr->getType()->cIdent() != "DNUCAStopTable") { + int num = atoi((action_ptr->getResources().lookup(var_ptr)).c_str()); + if (m_resources.exist(var_ptr)) { + num += atoi((m_resources.lookup(var_ptr)).c_str()); + } + m_resources.add(var_ptr, int_to_string(num)); + } else { + m_resources.add(var_ptr, action_ptr->getResources().lookup(var_ptr)); + } + } + m_actionPtrs.insertAtBottom(action_ptr); + } + m_actionPtrsValid = true; +} + +const string& Transition::getStateShorthand() const +{ + assert(m_statePtr != NULL); + return m_statePtr->getShorthand(); +} + +const string& Transition::getEventShorthand() const +{ + assert(m_eventPtr != NULL); + return m_eventPtr->getShorthand(); +} + +const string& Transition::getNextStateShorthand() const +{ + assert(m_nextStatePtr != NULL); + return m_nextStatePtr->getShorthand(); +} + +string Transition::getActionShorthands() const +{ + assert(m_actionPtrsValid); + string str; + int numActions = m_actionPtrs.size(); + for (int i=0; i<numActions; i++) { + str += m_actionPtrs[i]->getShorthand(); + } + return str; +} + +void Transition::print(ostream& out) const +{ + out << "[Transition: "; + out << "(" << m_state; + if (m_statePtr != NULL) { + out << ":" << *m_statePtr; + } + out << ", " << m_event; + if (m_eventPtr != NULL) { + out << ":" << *m_eventPtr; + } + out << ") -> "; + out << m_nextState; + if (m_nextStatePtr != NULL) { + out << ":" << *m_nextStatePtr; + } + out << ", "; + out << m_actionList; + out << "]"; +} + +Event* Transition::findIndex(const Vector<Event*>& vec, string ident) +{ + int size = vec.size(); + for(int i=0; i<size; i++) { + if (ident == vec[i]->getIdent()) { + return vec[i]; + } + } + error("Event not found: " + ident); + return NULL; +} + +State* Transition::findIndex(const Vector<State*>& vec, string ident) +{ + int size = vec.size(); + for(int i=0; i<size; i++) { + if (ident == vec[i]->getIdent()) { + return vec[i]; + } + } + error("State not found: " + ident); + return NULL; +} + +Action* Transition::findIndex(const Vector<Action*>& vec, string ident) +{ + int size = vec.size(); + for(int i=0; i<size; i++) { + if (ident == vec[i]->getIdent()) { + return vec[i]; + } + } + error("Action not found: " + ident); + return NULL; +} + diff --git a/src/mem/slicc/symbols/Transition.hh b/src/mem/slicc/symbols/Transition.hh new file mode 100644 index 000000000..af8eb3a05 --- /dev/null +++ b/src/mem/slicc/symbols/Transition.hh @@ -0,0 +1,120 @@ + +/* + * Copyright (c) 1999-2008 Mark D. Hill and David A. Wood + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer; + * redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution; + * neither the name of the copyright holders nor the names of its + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +/* + * Transition.h + * + * Description: + * + * $Id$ + * + * */ + +#ifndef TRANSITION_H +#define TRANSITION_H + +#include "slicc_global.hh" +#include "Vector.hh" +#include "Symbol.hh" + +class State; +class Event; +class Action; +class Var; + +class Transition : public Symbol { +public: + // Constructors + Transition(string state, string event, string nextState, + const Vector<string>& actionList, + const Location& location, + const Map<string, string>& pairMap); + // Destructor + ~Transition() { } + + // Public Methods + State* getStatePtr() const { assert(m_statePtr != NULL); return m_statePtr; } + Event* getEventPtr() const { assert(m_eventPtr != NULL); return m_eventPtr; } + State* getNextStatePtr() const { assert(m_nextStatePtr != NULL); return m_nextStatePtr; } + + // int getStateIndex() const { assert(m_statePtr != NULL); return m_statePtr->getIndex(); } + // int getEventIndex() const { assert(m_eventPtr != NULL); return m_eventPtr->getIndex(); } + // int getNextStateIndex() const { assert(m_nextStatePtr != NULL); return m_nextStatePtr->getIndex(); } + void checkIdents(const Vector<State*>& states, + const Vector<Event*>& events, + const Vector<Action*>& actions); + + const string& getStateShorthand() const; + const string& getEventShorthand() const; + const string& getNextStateShorthand() const; + string getActionShorthands() const; + const Vector<Action*>& getActions() const { assert(m_actionPtrsValid); return m_actionPtrs; } + const Map<Var*, string>& getResources() const { assert(m_actionPtrsValid); return m_resources; } + + void print(ostream& out) const; + + // Default copy constructor and assignment operator + // Transition(const Transition& obj); + // Transition& operator=(const Transition& obj); +private: + // Private Methods + Event* findIndex(const Vector<Event*>& vec, string ident); + State* findIndex(const Vector<State*>& vec, string ident); + Action* findIndex(const Vector<Action*>& vec, string ident); + + // Data Members (m_ prefix) + string m_state; + string m_event; + string m_nextState; + + State* m_statePtr; + Event* m_eventPtr; + State* m_nextStatePtr; + + Vector<string> m_actionList; + Vector<Action*> m_actionPtrs; + Map<Var*, string> m_resources; + bool m_actionPtrsValid; +}; + +// Output operator declaration +ostream& operator<<(ostream& out, const Transition& obj); + +// ******************* Definitions ******************* + +// Output operator definition +extern inline +ostream& operator<<(ostream& out, const Transition& obj) +{ + obj.print(out); + out << flush; + return out; +} + +#endif //TRANSITION_H diff --git a/src/mem/slicc/symbols/Type.cc b/src/mem/slicc/symbols/Type.cc new file mode 100644 index 000000000..a49e9d7ba --- /dev/null +++ b/src/mem/slicc/symbols/Type.cc @@ -0,0 +1,746 @@ + +/* + * Copyright (c) 1999-2008 Mark D. Hill and David A. Wood + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer; + * redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution; + * neither the name of the copyright holders nor the names of its + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#include "Type.hh" +#include "fileio.hh" +#include "Map.hh" +#include "StateMachine.hh" + +Type::Type(string id, const Location& location, + const Map<string, string>& pairs, + StateMachine* machine_ptr) + : Symbol(id, location, pairs) +{ + if (machine_ptr == NULL) { + m_c_id = id; + } else if (isExternal() || isPrimitive()) { + if (existPair("external_name")) { + m_c_id = lookupPair("external_name"); + } else { + m_c_id = id; + } + } else { + m_c_id = machine_ptr->toString() + "_" + id; // Append with machine name + } + + if(existPair("desc")){ + m_desc = lookupPair("desc"); + } else { + m_desc = "No description avaliable"; + } + + // check for interface that this Type implements + if(existPair("interface")) { + string interface = lookupPair("interface"); + if(interface == "Message" || interface == "NetworkMessage") { + addPair("message", "yes"); + } + if(interface == "NetworkMessage") { + addPair("networkmessage", "yes"); + } + } + + // FIXME - all of the following id comparisons are fragile hacks + if ((getIdent() == "CacheMemory") || (getIdent() == "NewCacheMemory") || + (getIdent() == "TLCCacheMemory") || (getIdent() == "DNUCACacheMemory") || + (getIdent() == "DNUCABankCacheMemory") || (getIdent() == "L2BankCacheMemory") || + (getIdent() == "CompressedCacheMemory") || (getIdent() == "PrefetchCacheMemory")) { + addPair("cache", "yes"); + } + + if ((getIdent() == "TBETable") || (getIdent() == "DNUCATBETable") || (getIdent() == "DNUCAStopTable")) { + addPair("tbe", "yes"); + } + + if ((getIdent() == "NewTBETable")) { + addPair("newtbe", "yes"); + } + + if ((getIdent() == "TimerTable")) { + addPair("timer", "yes"); + } + + if ((getIdent() == "DirectoryMemory")) { + addPair("dir", "yes"); + } + + if ((getIdent() == "PersistentTable")) { + addPair("persistent", "yes"); + } + + if ((getIdent() == "Prefetcher")) { + addPair("prefetcher", "yes"); + } + + if ((getIdent() == "DNUCA_Movement")) { + addPair("mover", "yes"); + } + + if (id == "MachineType") { + m_isMachineType = true; + } else { + m_isMachineType = false; + } +} + +// Return false on error +bool Type::dataMemberAdd(string id, Type* type_ptr, Map<string, string>& pairs, + string* init_code) +{ + if (dataMemberExist(id)) { + return false; // Error + } else { + m_data_member_map.add(id, type_ptr); + m_data_member_ident_vec.insertAtBottom(id); + m_data_member_type_vec.insertAtBottom(type_ptr); + m_data_member_pairs_vec.insertAtBottom(pairs); + m_data_member_init_code_vec.insertAtBottom(init_code); + } + + return true; +} + +string Type::methodId(string name, + const Vector<Type*>& param_type_vec) +{ + string paramStr = ""; + for (int i = 0; i < param_type_vec.size(); i++) { + paramStr += "_"+param_type_vec[i]->cIdent(); + } + return name+paramStr; +} + +bool Type::methodAdd(string name, + Type* return_type_ptr, + const Vector<Type*>& param_type_vec) +{ + string id = methodId(name, param_type_vec); + if (methodExist(id)) { + return false; // Error + } else { + m_method_return_type_map.add(id, return_type_ptr); + m_method_param_type_map.add(id, param_type_vec); + return true; + } +} + +bool Type::enumAdd(string id, Map<string, string> pairs_map) +{ + if (enumExist(id)) { + return false; + } else { + m_enum_map.add(id, true); + m_enum_vec.insertAtBottom(id); + m_enum_pairs.insertAtBottom(pairs_map); + + // Add default + if (!existPair("default")) { + addPair("default", cIdent()+"_NUM"); + } + + return true; + } +} + +void Type::writeCFiles(string path) const +{ + if (isExternal()) { + // Do nothing + } else if (isEnumeration()) { + printEnumH(path); + printEnumC(path); + } else { // User defined structs and messages + printTypeH(path); + printTypeC(path); + } +} + +void Type::printTypeH(string path) const +{ + ostringstream out; + int size = m_data_member_type_vec.size(); + string type_name = cIdent(); // Identifier for the type in C + + // Header + out << "/** \\file " << type_name << ".hh" << endl; + out << " * " << endl; + out << " * Auto generated C++ code started by "<<__FILE__<<":"<<__LINE__<< endl; + out << " */" << endl; + out << endl; + out << "#ifndef " << type_name << "_H" << endl; + out << "#define " << type_name << "_H" << endl; + out << endl; + + // Include all of the #includes needed + out << "#include \"Global.hh\"" << endl; + out << "#include \"Allocator.hh\"" << endl; + for (int i=0; i < size; i++) { + Type* type = m_data_member_type_vec[i]; + if (!type->isPrimitive()) { + out << "#include \"" << type->cIdent() << ".hh" << "\"" << endl; + } + } + string interface = ""; + if(existPair("interface")) { + interface = lookupPair("interface"); + out << "#include \"" << interface << ".hh\"" << endl; + } + + // Class definition + out << "class " << type_name; + + if(interface != "") { + out << " : public " << interface ; + } + + out << " {" << endl; + out << "public:" << endl; + + // ******** Default constructor ******** + + out << " " << type_name << "() " << endl; + + // Call superclass constructor + if (interface != "") { + out << " : " << interface << "()" << endl; + } + + out << " {" << endl; + + if(!isGlobal()) { + for (int i=0; i < size; i++) { + + Type* type_ptr = m_data_member_type_vec[i]; + string id = m_data_member_ident_vec[i]; + if (m_data_member_pairs_vec[i].exist("default")) { + // look for default value + string default_value = m_data_member_pairs_vec[i].lookup("default"); + out << " m_" << id << " = " << default_value << "; // default for this field " << endl; + } else if (type_ptr->hasDefault()) { + // Look for the type default + string default_value = type_ptr->getDefault(); + out << " m_" << id << " = " << default_value << "; // default value of " << type_ptr->cIdent() << endl; + } else { + out << " // m_" << id << " has no default" << endl; + } + } + } // end of if(!isGlobal()) + out << " }" << endl; + + // ******** Default destructor ******** + out << " "; + out << "~" << type_name << "() { };" << endl; + + // ******** Full init constructor ******** + if(! isGlobal()) { + out << " " << type_name << "("; + + for (int i=0; i < size; i++) { + if (i != 0) { + out << ", "; + } + Type* type = m_data_member_type_vec[i]; + string id = m_data_member_ident_vec[i]; + out << "const " << type->cIdent() << "& local_" << id; + } + out << ")" << endl; + + // Call superclass constructor + if (interface != "") { + out << " : " << interface << "()" << endl; + } + + out << " {" << endl; + for (int i=0; i < size; i++) { + Type* type_ptr = m_data_member_type_vec[i]; + string id = m_data_member_ident_vec[i]; + out << " m_" << id << " = local_" << id << ";" << endl; + if (m_data_member_pairs_vec[i].exist("nextLineCallHack")) { + string next_line_value = m_data_member_pairs_vec[i].lookup("nextLineCallHack"); + out << " m_" << id << next_line_value << ";" << endl; + } + + } + out << " }" << endl; + } // end of if(!isGlobal()) + + // bobba - + //******** Partial init constructor ******** + //** Constructor needs only the first n-1 data members for init + //** HACK to create objects with partially specified data members + //** Need to get rid of this and use hierarchy instead +// if(! isGlobal()) { +// out << " " << type_name << "("; + +// for (int i=0; i < size-1; i++) { +// if (i != 0) { +// out << ", "; +// } +// Type* type = m_data_member_type_vec[i]; +// string id = m_data_member_ident_vec[i]; +// out << "const " << type->cIdent() << "& local_" << id; +// } +// out << ")" << endl; + +// // Call superclass constructor +// if (interface != "") { +// out << " : " << interface << "()" << endl; +// } + +// out << " {" << endl; +// for (int i=0; i < size-1; i++) { +// Type* type_ptr = m_data_member_type_vec[i]; +// string id = m_data_member_ident_vec[i]; +// out << " m_" << id << " = local_" << id << ";" << endl; +// if (m_data_member_pairs_vec[i].exist("nextLineCallHack")) { +// string next_line_value = m_data_member_pairs_vec[i].lookup("nextLineCallHack"); +// out << " m_" << id << next_line_value << ";" << endl; +// } + +// } +// out << " }" << endl; +// } // end of if(!isGlobal()) + + // ******** Message member functions ******** + // FIXME: those should be moved into slicc file, slicc should support more of + // the c++ class inheritance + + if (isMessage()) { + out << " Message* clone() const { checkAllocator(); return s_allocator_ptr->allocate(*this); }" << endl; + out << " void destroy() { checkAllocator(); s_allocator_ptr->deallocate(this); }" << endl; + out << " static Allocator<" << type_name << ">* s_allocator_ptr;" << endl; + out << " static void checkAllocator() { if (s_allocator_ptr == NULL) { s_allocator_ptr = new Allocator<" << type_name << ">; }}" << endl; + } + + if(!isGlobal()) { + // const Get methods for each field + out << " // Const accessors methods for each field" << endl; + for (int i=0; i < size; i++) { + Type* type_ptr = m_data_member_type_vec[i]; + string type = type_ptr->cIdent(); + string id = m_data_member_ident_vec[i]; + out << "/** \\brief Const accessor method for " << id << " field." << endl; + out << " * \\return " << id << " field" << endl; + out << " */" << endl; + out << " const " << type << "& get" << id + << "() const { return m_" << id << "; }" << endl; + } + + out << endl; + + // Non-const Get methods for each field + out << " // Non const Accessors methods for each field" << endl; + for (int i=0; i < size; i++) { + Type* type_ptr = m_data_member_type_vec[i]; + string type = type_ptr->cIdent(); + string id = m_data_member_ident_vec[i]; + out << "/** \\brief Non-const accessor method for " << id << " field." << endl; + out << " * \\return " << id << " field" << endl; + out << " */" << endl; + out << " " << type << "& get" << id + << "() { return m_" << id << "; }" << endl; + } + + out << endl; + + // Set methods for each field + out << " // Mutator methods for each field" << endl; + for (int i=0; i < size; i++) { + Type* type_ptr = m_data_member_type_vec[i]; + string type = type_ptr->cIdent(); + string id = m_data_member_ident_vec[i]; + out << "/** \\brief Mutator method for " << id << " field */" << endl; + out << " void set" << id << "(const " << type << "& local_" + << id << ") { m_" << id << " = local_" << id << "; }" << endl; + } + + out << endl; + } // end of if(!isGlobal()) + + out << " void print(ostream& out) const;" << endl; + out << "//private:" << endl; + + // Data members for each field + for (int i=0; i < size; i++) { + if (!m_data_member_pairs_vec[i].exist("abstract")) { + out << " "; + // global structure + if(isGlobal()) out << "static const "; + + Type* type = m_data_member_type_vec[i]; + string id = m_data_member_ident_vec[i]; + out << type->cIdent() << " m_" << id; + + // init value + string* init_code = m_data_member_init_code_vec[i]; + if(init_code) { + // only global structure can have init value here + assert(isGlobal()); + out << " = " << *init_code << " "; + } + out << ";"; + if (m_data_member_pairs_vec[i].exist("desc")) { + string desc = m_data_member_pairs_vec[i].lookup("desc"); + out << " /**< " << desc << "*/"; + } + out << endl; + } + } + + out << "};" << endl; // End class + + out << "// Output operator declaration" << endl; + out << "ostream& operator<<(ostream& out, const " << type_name << "& obj);" << endl; + out << endl; + out << "// Output operator definition" << endl; + out << "extern inline" << endl; + out << "ostream& operator<<(ostream& out, const " << type_name << "& obj)" << endl; + out << "{" << endl; + out << " obj.print(out);" << endl; + out << " out << flush;" << endl; + out << " return out;" << endl; + out << "}" << endl; + out << endl; + out << "#endif // " << type_name << "_H" << endl; + + // Write it out + conditionally_write_file(path + type_name + ".hh", out); +} + +void Type::printTypeC(string path) const +{ + ostringstream out; + int size = m_data_member_type_vec.size(); + string type_name = cIdent(); // Identifier for the type in C + + // Header + out << "/** \\file " << type_name << ".cc" << endl; + out << " * " << endl; + out << " * Auto generated C++ code started by "<<__FILE__<<":"<<__LINE__<< endl; + out << " */" << endl; + out << endl; + out << "#include \"" << type_name << ".hh\"" << endl; + out << endl; + if (isMessage()) { + out << "Allocator<" << type_name << ">* " << type_name << "::s_allocator_ptr = NULL;" << endl; + } + out << "/** \\brief Print the state of this object */" << endl; + out << "void " << type_name << "::print(ostream& out) const" << endl; + out << "{" << endl; + out << " out << \"[" << type_name << ": \";" << endl; + + // For each field + for (int i=0; i < size; i++) { + string id = m_data_member_ident_vec[i]; + out << " out << \"" << id << "=\" << m_" << id << " << \" \";" << endl; + } + + if (isMessage()) { + out << " out << \"" << "Time" << "=\" << getTime()" << " << \" \";" << endl; + } + + // Trailer + out << " out << \"]\";" << endl; + out << "}" << endl; + + // Write it out + conditionally_write_file(path + type_name + ".cc", out); +} + +void Type::printEnumH(string path) const +{ + ostringstream out; + int size = m_enum_vec.size(); + string type_name = cIdent(); // Identifier for the type in C + string type_desc = desc(); + + // Header + out << "/** \\file " << type_name << ".hh" << endl; + out << " * " << endl; + out << " * Auto generated C++ code started by "<<__FILE__<<":"<<__LINE__<< endl; + out << " */" << endl; + + out << "#ifndef " << type_name << "_H" << endl; + out << "#define " << type_name << "_H" << endl; + out << endl; + // Include all of the #includes needed + out << "#include \"Global.hh\"" << endl; + if (m_isMachineType) { + out << "#include \"RubyConfig.hh\"" << endl << endl; + } + out << endl; + + // Class definition + out << "/** \\enum " << type_name << endl; + out << " * \\brief " << type_desc << endl; + out << " */" << endl; + out << "enum " << type_name << " {" << endl; + + out << " " << type_name << "_FIRST," << endl; + + // For each field + for(int i = 0; i < size; i++ ) { + string id = m_enum_vec[i]; + string description; + if(m_enum_pairs[i].exist("desc")){ + description = m_enum_pairs[i].lookup("desc"); + } else { + description = "No description avaliable"; + } + if (i == 0) { + out << " " << type_name << "_" << id << " = " << type_name << "_FIRST, /**< " << description << " */" << endl; + } + else { + out << " " << type_name << "_" << id << ", /**< " << description << " */" << endl; + } + } + out << " " << type_name << "_NUM" << endl; + out << "};" << endl; + + // Code to convert from a string to the enumeration + out << type_name << " string_to_" << type_name << "(const string& str);" << endl; + + // Code to convert state to a string + out << "string " << type_name << "_to_string(const " << type_name << "& obj);" << endl; + + // Code to increment an enumeration type + out << type_name << " &operator++( " << type_name << " &e);" << endl; + + // MachineType hack used to set the base component id for each Machine + if (m_isMachineType) { + out << "int " << type_name << "_base_level(const " << type_name << "& obj);" << endl; + out << "int " << type_name << "_base_number(const " << type_name << "& obj);" << endl; + out << "int " << type_name << "_base_count(const " << type_name << "& obj);" << endl; + out << "int " << type_name << "_chip_count(const " << type_name << "& obj, NodeID chipID);" << endl; + + for(int i = 0; i < size; i++ ) { + string id = m_enum_vec[i]; + out << "#define MACHINETYPE_" << id << " 1" << endl; + } + cout << endl; + } + + // Trailer + out << "ostream& operator<<(ostream& out, const " << type_name << "& obj);" << endl; + out << endl; + out << "#endif // " << type_name << "_H" << endl; + + // Write the file + conditionally_write_file(path + type_name + ".hh", out); +} + +void Type::printEnumC(string path) const +{ + ostringstream out; + int size = m_enum_vec.size(); + string type_name = cIdent(); // Identifier for the type in C + + // Header + out << "/** \\file " << type_name << ".hh" << endl; + out << " * " << endl; + out << " * Auto generated C++ code started by "<<__FILE__<<":"<<__LINE__<< endl; + out << " */" << endl; + + out << endl; + out << "#include \"" << type_name << ".hh\"" << endl; + out << endl; + + // Code for output operator + out << "ostream& operator<<(ostream& out, const " << type_name << "& obj)" << endl; + out << "{" << endl; + out << " out << " << type_name << "_to_string(obj);" << endl; + out << " out << flush;" << endl; + out << " return out;" << endl; + out << "}" << endl; + + // Code to convert state to a string + out << endl; + out << "string " << type_name << "_to_string(const " << type_name << "& obj)" << endl; + out << "{" << endl; + out << " switch(obj) {" << endl; + + // For each field + for( int i = 0; i<size; i++ ) { + out << " case " << type_name << "_" << m_enum_vec[i] << ":" << endl; + out << " return \"" << m_enum_vec[i] << "\";" << endl; + } + + // Trailer + out << " default:" << endl; + out << " ERROR_MSG(\"Invalid range for type " << type_name << "\");" << endl; + out << " return \"\";" << endl; + out << " }" << endl; + out << "}" << endl; + + // Code to convert from a string to the enumeration + out << endl; + out << type_name << " string_to_" << type_name << "(const string& str)" << endl; + out << "{" << endl; + out << " if (false) {" << endl; + + // For each field + for( int i = 0; i<size; i++ ) { + out << " } else if (str == \"" << m_enum_vec[i] << "\") {" << endl; + out << " return " << type_name << "_" << m_enum_vec[i] << ";" << endl; + } + + out << " } else {" << endl; + out << " WARN_EXPR(str);" << endl; + out << " ERROR_MSG(\"Invalid string conversion for type " << type_name << "\");" << endl; + out << " }" << endl; + out << "}" << endl; + + // Code to increment an enumeration type + out << endl; + out << type_name << "& operator++( " << type_name << "& e) {" << endl; + out << " assert(e < " << type_name << "_NUM);" << endl; + out << " return e = " << type_name << "(e+1);" << endl; + out << "}" << endl; + + // MachineType hack used to set the base level and number of components for each Machine + if (m_isMachineType) { + out << endl; + out << "/** \\brief returns the base vector index for each machine type to be used by NetDest " << endl; + out << " * " << endl; + out << " * \\return the base vector index for each machine type to be used by NetDest" << endl; + out << " * \\see NetDest.hh" << endl; + out << " */" << endl; + out << "int " << type_name << "_base_level(const " << type_name << "& obj)" << endl; + out << "{" << endl; + out << " switch(obj) {" << endl; + + // For each field + Vector < string > MachineNames; + for( int i = 0; i<size; i++ ) { + out << " case " << type_name << "_" << m_enum_vec[i] << ":" << endl; + out << " return " << MachineNames.size() << ";" << endl; + MachineNames.insertAtBottom(m_enum_vec[i]); + } + + // total num + out << " case " << type_name << "_NUM:" << endl; + out << " return " << MachineNames.size() << ";" << endl; + + // Trailer + out << " default:" << endl; + out << " ERROR_MSG(\"Invalid range for type " << type_name << "\");" << endl; + out << " return -1;" << endl; + out << " }" << endl; + out << "}" << endl; + + out << endl; + out << "/** \\brief The return value indicates the number of components created" << endl; + out << " * before a particular machine's components" << endl; + out << " * " << endl; + out << " * \\return the base number of components for each machine" << endl; + out << " */" << endl; + out << "int " << type_name << "_base_number(const " << type_name << "& obj)" << endl; + out << "{" << endl; + out << " switch(obj) {" << endl; + + // For each field + MachineNames.clear(); + for( int i = 0; i<size; i++ ) { + out << " case " << type_name << "_" << m_enum_vec[i] << ":" << endl; + out << " return 0"; + for ( int m = 0; m<MachineNames.size(); m++) { + out << "+RubyConfig::numberOf" << MachineNames[m] << "()"; + } + out << ";" << endl; + MachineNames.insertAtBottom(m_enum_vec[i]); + } + + // total num + out << " case " << type_name << "_NUM:" << endl; + out << " return 0"; + for ( int m = 0; m<MachineNames.size(); m++) { + out << "+RubyConfig::numberOf" << MachineNames[m] << "()"; + } + out << ";" << endl; + + // Trailer + out << " default:" << endl; + out << " ERROR_MSG(\"Invalid range for type " << type_name << "\");" << endl; + out << " return -1;" << endl; + out << " }" << endl; + out << "}" << endl; + + + out << endl; + out << "/** \\brief returns the total number of components for each machine" << endl; + out << " * \\return the total number of components for each machine" << endl; + out << " */" << endl; + out << "int " << type_name << "_base_count(const " << type_name << "& obj)" << endl; + out << "{" << endl; + out << " switch(obj) {" << endl; + + // For each field + for( int i = 0; i<size; i++ ) { + out << " case " << type_name << "_" << m_enum_vec[i] << ":" << endl; + out << " return RubyConfig::numberOf" << m_enum_vec[i] << "();" << endl; + } + + // total num + out << " case " << type_name << "_NUM:" << endl; + // Trailer + out << " default:" << endl; + out << " ERROR_MSG(\"Invalid range for type " << type_name << "\");" << endl; + out << " return -1;" << endl; + out << " }" << endl; + out << "}" << endl; + + out << endl; + out << "/** \\brief returns the total number of components for each machine" << endl; + out << " * \\return the total number of components for each machine" << endl; + out << " */" << endl; + out << "int " << type_name << "_chip_count(const " << type_name << "& obj, NodeID chipID)" << endl; + out << "{" << endl; + out << " switch(obj) {" << endl; + + // For each field + for( int i = 0; i<size; i++ ) { + out << " case " << type_name << "_" << m_enum_vec[i] << ":" << endl; + out << " return RubyConfig::numberOf" << m_enum_vec[i] << "PerChip(chipID);" << endl; + } + + // total num + out << " case " << type_name << "_NUM:" << endl; + // Trailer + out << " default:" << endl; + out << " ERROR_MSG(\"Invalid range for type " << type_name << "\");" << endl; + out << " return -1;" << endl; + out << " }" << endl; + out << "}" << endl; + + + } + + // Write the file + conditionally_write_file(path + type_name + ".cc", out); +} diff --git a/src/mem/slicc/symbols/Type.hh b/src/mem/slicc/symbols/Type.hh new file mode 100644 index 000000000..c6f891326 --- /dev/null +++ b/src/mem/slicc/symbols/Type.hh @@ -0,0 +1,154 @@ + +/* + * Copyright (c) 1999-2008 Mark D. Hill and David A. Wood + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer; + * redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution; + * neither the name of the copyright holders nor the names of its + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +/* + * Type.h + * + * Description: + * + * $Id$ + * + * */ + +#ifndef TYPE_H +#define TYPE_H + +#include "slicc_global.hh" +#include "Map.hh" +#include "Symbol.hh" + +class StateMachine; + +class Type : public Symbol { +public: + // Constructors + Type(string id, const Location& location, + const Map<string, string>& pairs, + StateMachine* machine_ptr = NULL); + + // Destructor + ~Type() {} + + // Public Methods + string cIdent() const { return m_c_id; } + string desc() const { return m_desc; } + + bool isPrimitive() const { return existPair("primitive"); } + bool isNetworkMessage() const { return existPair("networkmessage"); } + bool isMessage() const { return existPair("message"); } + bool isBuffer() const { return existPair("buffer"); } + bool isInPort() const { return existPair("inport"); } + bool isOutPort() const { return existPair("outport"); } + bool isEnumeration() const { return existPair("enumeration"); } + bool isExternal() const { return existPair("external"); } + bool isGlobal() const { return existPair("global"); } + + // The data members of this type - only valid for messages and SLICC + // declared structures + // Return false on error + bool dataMemberAdd(string id, Type* type_ptr, Map<string, string>& pairs, + string* init_code); + bool dataMemberExist(string id) const { return m_data_member_map.exist(id); } + Type* dataMemberType(string id) const { return m_data_member_map.lookup(id); } + + // The methods of this type - only valid for external types + // Return false on error + bool methodAdd(string name, Type* return_type_ptr, const Vector<Type*>& param_type_vec); + bool methodExist(string id) const { return m_method_return_type_map.exist(id); } + + string methodId(string name, const Vector<Type*>& param_type_vec); + Type* methodReturnType(string id) const { return m_method_return_type_map.lookup(id); } + const Vector<Type*>& methodParamType(string id) const { return m_method_param_type_map.lookup(id); } + + // The enumeration idents of this type - only valid for enums + // Return false on error + bool enumAdd(string id, Map<string, string> pairs); + bool enumExist(string id) const { return m_enum_map.exist(id); } + + // Write the C output files + void writeCFiles(string path) const; + + bool hasDefault() const { return existPair("default"); } + string getDefault() const { return lookupPair("default"); } + + void print(ostream& out) const {} +private: + // Private Methods + + void printTypeH(string path) const; + void printTypeC(string path) const; + void printEnumC(string path) const; + void printEnumH(string path) const; + + // Private copy constructor and assignment operator + Type(const Type& obj); + Type& operator=(const Type& obj); + + // Data Members (m_ prefix) + string m_c_id; + string m_desc; + + // Data Members + Map<string, Type*> m_data_member_map; + Vector<string> m_data_member_ident_vec; + Vector<Type*> m_data_member_type_vec; + Vector<Map<string, string> > m_data_member_pairs_vec; + Vector<string*> m_data_member_init_code_vec; + // Needs pairs here + + // Methods + Map<string, Type*> m_method_return_type_map; + Map<string, Vector<Type*> > m_method_param_type_map; + // Needs pairs here + + // Enum + Map<string, bool> m_enum_map; + Vector<string> m_enum_vec; + Vector< Map < string, string > > m_enum_pairs; + + // MachineType Hack + bool m_isMachineType; + +}; + +// Output operator declaration +ostream& operator<<(ostream& out, const Type& obj); + +// ******************* Definitions ******************* + +// Output operator definition +extern inline +ostream& operator<<(ostream& out, const Type& obj) +{ + obj.print(out); + out << flush; + return out; +} + +#endif //TYPE_H diff --git a/src/mem/slicc/symbols/Var.cc b/src/mem/slicc/symbols/Var.cc new file mode 100644 index 000000000..a16c86967 --- /dev/null +++ b/src/mem/slicc/symbols/Var.cc @@ -0,0 +1,57 @@ + +/* + * Copyright (c) 1999-2008 Mark D. Hill and David A. Wood + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer; + * redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution; + * neither the name of the copyright holders nor the names of its + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +/* + * $Id$ + * + * */ + +#include "Var.hh" +#include "StateMachine.hh" + +Var::Var(string id, const Location& location, + Type* type_ptr, string code, + const Map<string, string>& pairs, + StateMachine* machine_ptr) : Symbol(id, location, pairs) +{ + if (machine_ptr == NULL) { + m_c_id = id; + } else { + m_c_id = machine_ptr->toString() + "_" + id; // Append with machine name + } + + m_machine_ptr = machine_ptr; + m_type_ptr = type_ptr; + m_code = code; +} + +void Var::print(ostream& out) const +{ + out << "[Var id: " << m_c_id << "]" << endl; +} diff --git a/src/mem/slicc/symbols/Var.hh b/src/mem/slicc/symbols/Var.hh new file mode 100644 index 000000000..277be0f74 --- /dev/null +++ b/src/mem/slicc/symbols/Var.hh @@ -0,0 +1,98 @@ + +/* + * Copyright (c) 1999-2008 Mark D. Hill and David A. Wood + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer; + * redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution; + * neither the name of the copyright holders nor the names of its + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +/* + * Var.h + * + * Description: + * + * $Id$ + * + * */ + +#ifndef VAR_H +#define VAR_H + +#include "slicc_global.hh" +#include "Symbol.hh" +#include "Type.hh" + +class StateMachine; + +class Var : public Symbol { +public: + // Constructors + Var(string id, const Location& location, + Type* type_ptr, string code, + const Map<string, string>& pairs, + StateMachine* machine_ptr = NULL); + + // Var(string id, const Location& location, + // Type* type_ptr, string code) : Symbol(id, location) { m_type_ptr = type_ptr; m_code = code; } + + // Destructor + ~Var() {} + + // Public Methods + string cIdent() const { return m_c_id; } + void writeCFiles(string path) const {} + string getCode() const { return m_code; } + Type* getType() const { return m_type_ptr; } + StateMachine* getMachine() const { return m_machine_ptr; } + + void print(ostream& out) const; +private: + // Private Methods + + // Private copy constructor and assignment operator + Var(const Var& obj); + Var& operator=(const Var& obj); + + // Data Members (m_ prefix) + string m_c_id; + Type* m_type_ptr; + string m_code; + StateMachine* m_machine_ptr; +}; + +// Output operator declaration +ostream& operator<<(ostream& out, const Var& obj); + +// ******************* Definitions ******************* + +// Output operator definition +extern inline +ostream& operator<<(ostream& out, const Var& obj) +{ + obj.print(out); + out << flush; + return out; +} + +#endif //VAR_H |