Skip to content

Commit

Permalink
Adding debug options to vhdl parser generator
Browse files Browse the repository at this point in the history
JavaCC contains by default options to get more information about the parser paths used (analogous to the -d option of flex).
- Makefile
  - adding option (JAVACC_FLAGS) for easier use of JavaCC options
  - adding possibility to reset generated files to their git versions.
- vhdlstring.h adding functions required by debug options (debug_token_manager)
  • Loading branch information
albert-github committed Mar 26, 2018
1 parent 7e2fcd3 commit 6ad7854
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 5 deletions.
42 changes: 37 additions & 5 deletions vhdlparser/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,48 @@
# for any purpose. It is provided "as is" without express or implied warranty.
# See the GNU General Public License for more details.
#
# Documents produced by Doxygen are derivative works derived from the
# Documents produced by doxygen are derivative works derived from the
# input used in their production; they are not affected by this license.
#

regenerate:
rm -f CharStream.cc CharStream.h ErrorHandler.h ParseException.cc ParseException.h \
#
# Files generated by javacc
#
GEN_FILES=CharStream.cc CharStream.h ErrorHandler.h ParseException.cc ParseException.h \
Token.cc Token.h TokenManager.h TokenMgrError.cc TokenMgrError.h VhdlParser.cc VhdlParser.h \
VhdlParserConstants.h VhdlParserTokenManager.cc VhdlParserTokenManager.h \
JavaCC.h
javacc vhdlparser.jj
cp JavaCC.h.in JavaCC.h
#
# Generate parser (default target)
#
# when generating the parser with debug options it will look like:
# make JAVACC_FLAGS=-debug_parser
# or
# make JAVACC_FLAGS="-debug_parser -debug_lookahead"
#
# Available debug options:
# -debug_parser
# -debug_token_manager
# -debug_lookahead
#
# For other javacc settings / options consult the documentation of javacc.

regenerate:
@rm -f $(GEN_FILES)
@javacc $(JAVACC_FLAGS) vhdlparser.jj
@cp JavaCC.h.in JavaCC.h

#
# reset the generated files back to their versions from git.
#

reset_gen_files:
@rm -f $(GEN_FILES)
@git checkout $(GEN_FILES)

help:
@echo "Targets:"
@echo " regenerate (default)"
@echo " reset_gen_files"

FORCE:
8 changes: 8 additions & 0 deletions vhdlparser/vhdlstring.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
/** @brief Minimal string class with std::string like behaviour that fulfills the JavaCC
* string requirements.
*/

class VhdlString
{
public:
Expand Down Expand Up @@ -93,11 +94,18 @@ class VhdlString
void clear() { free(m_str); init(); }
VhdlString &operator+=(char c) { char s[2]; s[0]=c; s[1]=0; return append(s); }
VhdlString &operator+=(const char *s) { return append(s); }
VhdlString &operator+=(VhdlString s) { return append(s); }
VhdlString operator+ (const char *s) { return append(s); }

private:
void init() { m_str=(char*)calloc(1,1); m_len=0; }
char *m_str;
int m_len;
};

// declare it static otherwise we will get:
// multiple definition of `operator+(char const*, VhdlString)'
// as we are in an include file
static VhdlString operator+ (const char *s, VhdlString v) { return VhdlString(s).append(v); }

#endif

0 comments on commit 6ad7854

Please sign in to comment.