SEGV_NOSPIN,
PARSE_ONLY,
NO_CHECKING,
+ USE_MMAP,
SHOW_CONFIG
};/* enum OptionValue */
{ "segv-nospin", no_argument , NULL, SEGV_NOSPIN },
{ "parse-only" , no_argument , NULL, PARSE_ONLY },
{ "no-checking", no_argument , NULL, NO_CHECKING },
+ { "mmap", no_argument , NULL, USE_MMAP },
{ "show-config", no_argument , NULL, SHOW_CONFIG }
};/* if you add things to the above, please remember to update usage.h! */
opts->semanticChecks = false;
break;
+ case USE_MMAP:
+ opts->memoryMap = true;
+ break;
+
case SHOW_CONFIG:
fputs(Configuration::about().c_str(), stdout);
printf("\n");
// Create the parser
Parser* parser;
+ istream* input = NULL;
+
if(inputFromStdin) {
- parser = Parser::getNewParser(&exprMgr, options.lang, cin);
+ parser = Parser::getNewParser(&exprMgr, options.lang, cin, "<stdin>");
+ } else if( options.memoryMap ) {
+ parser = Parser::getMemoryMappedParser(&exprMgr, options.lang, argv[firstArgIndex]);
} else {
- parser = Parser::getNewParser(&exprMgr, options.lang, argv[firstArgIndex]);
+ string filename = argv[firstArgIndex];
+ input = new ifstream(filename.c_str());
+ if(input == NULL) {
+ throw Exception("file does not exist or is unreadable: " + filename);
+ }
+ parser = Parser::getNewParser(&exprMgr, options.lang, *input, filename);
}
if(!options.semanticChecks) {
// Remove the parser
delete parser;
+ delete input;
switch(lastResult.asSatisfiabilityResult().isSAT()) {
--stats give statistics on exit\n\
--segv-nospin (debug builds only) don't spin on segfault waiting for gdb\n\
--parse-only exit after parsing input\n\
+ --no-checking disable semantic checks in the parser\n\
+ --mmap memory map file input\n\
--show-config show CVC4 static configuration\n\
";
parser_exception.h \
symbol_table.h \
antlr_parser.h \
- antlr_parser.cpp
+ antlr_parser.cpp \
+ memory_mapped_input_buffer.h
--- /dev/null
+/********************* */
+/** memory_mapped_input_buffer.cpp
+ ** Original author: cconway
+ ** This file is part of the CVC4 prototype.
+ ** Copyright (c) 2009, 2010 The Analysis of Computer Systems Group (ACSys)
+ ** Courant Institute of Mathematical Sciences
+ ** New York University
+ ** See the file COPYING in the top-level source directory for licensing
+ ** information.
+ **
+ ** ANTLR input buffer from a memory-mapped file.
+ **/
+
+#ifndef MEMORY_MAPPED_INPUT_BUFFER_H_
+#define MEMORY_MAPPED_INPUT_BUFFER_H_
+
+#include <fcntl.h>
+#include <stdio.h>
+#include <stdint.h>
+
+#include <sys/errno.h>
+#include <sys/mman.h>
+#include <sys/stat.h>
+#include <antlr/InputBuffer.hpp>
+
+#include "util/Assert.h"
+#include "util/exception.h"
+
+namespace CVC4 {
+namespace parser {
+
+class MemoryMappedInputBuffer : public antlr::InputBuffer {
+
+public:
+ MemoryMappedInputBuffer(const std::string& filename) {
+ errno = 0;
+ struct stat st;
+ if( stat(filename.c_str(), &st) == -1 ) {
+ throw Exception("unable to stat() file");
+// throw Exception( "unable to stat() file " << filename << " errno " << errno );
+ }
+ d_size = st.st_size;
+
+ int fd = open(filename.c_str(), O_RDONLY);
+ if( fd == -1 ) {
+ throw Exception("unable to fopen() file");
+ }
+
+ d_start = static_cast< const char * >(
+ mmap( 0, d_size, PROT_READ, MAP_FILE | MAP_PRIVATE, fd, 0 ) );
+ errno = 0;
+ if( intptr_t( d_start ) == -1 ) {
+ throw Exception("unable to mmap() file");
+// throw Exception( "unable to mmap() file " << filename << " errno " << errno );
+ }
+ d_cur = d_start;
+ d_end = d_start + d_size;
+ }
+
+ ~MemoryMappedInputBuffer() {
+ munmap((void*)d_start,d_size);
+ }
+
+ inline int getChar() {
+ Assert( d_cur >= d_start && d_cur <= d_end );
+ return d_cur == d_end ? EOF : *d_cur++;
+ }
+
+private:
+ unsigned long int d_size;
+ const char *d_start, *d_end, *d_cur;
+};
+
+}
+}
+
+
+#endif /* MEMORY_MAPPED_INPUT_BUFFER_H_ */
#include <iostream>
#include <fstream>
#include <antlr/CharScanner.hpp>
+#include <antlr/CharBuffer.hpp>
#include "parser.h"
+#include "memory_mapped_input_buffer.h"
#include "expr/command.h"
#include "util/output.h"
#include "util/Assert.h"
Parser::~Parser() {
delete d_antlrParser;
delete d_antlrLexer;
- if(d_deleteInput) {
- delete d_input;
- }
+ delete d_inputBuffer;
}
-Parser::Parser(istream* input, AntlrParser* antlrParser,
- CharScanner* antlrLexer, bool deleteInput) :
- d_done(false), d_antlrParser(antlrParser), d_antlrLexer(antlrLexer),
- d_input(input), d_deleteInput(deleteInput) {
+Parser::Parser(InputBuffer* inputBuffer, AntlrParser* antlrParser,
+ CharScanner* antlrLexer) :
+ d_done(false),
+ d_antlrParser(antlrParser),
+ d_antlrLexer(antlrLexer),
+ d_inputBuffer(inputBuffer) {
}
Parser* Parser::getNewParser(ExprManager* em, InputLanguage lang,
- istream* input, string filename, bool deleteInput) {
+ InputBuffer* inputBuffer, string filename) {
AntlrParser* antlrParser = 0;
antlr::CharScanner* antlrLexer = 0;
switch(lang) {
case LANG_CVC4: {
- antlrLexer = new AntlrCvcLexer(*input);
- antlrLexer->setFilename(filename);
+ antlrLexer = new AntlrCvcLexer(*inputBuffer);
antlrParser = new AntlrCvcParser(*antlrLexer);
- antlrParser->setFilename(filename);
- antlrParser->setExpressionManager(em);
break;
}
case LANG_SMTLIB: {
- antlrLexer = new AntlrSmtLexer(*input);
- antlrLexer->setFilename(filename);
+// MemoryMappedInputBuffer inputBuffer(filename);
+// antlrLexer = new AntlrSmtLexer(inputBuffer);
+ antlrLexer = new AntlrSmtLexer(*inputBuffer);
antlrParser = new AntlrSmtParser(*antlrLexer);
- antlrParser->setFilename(filename);
- antlrParser->setExpressionManager(em);
break;
}
default:
Unhandled("Unknown Input language!");
}
- return new Parser(input, antlrParser, antlrLexer, deleteInput);
+ antlrLexer->setFilename(filename);
+ antlrParser->setFilename(filename);
+ antlrParser->setExpressionManager(em);
+
+ return new Parser(inputBuffer, antlrParser, antlrLexer);
}
-Parser* Parser::getNewParser(ExprManager* em, InputLanguage lang,
- string filename) {
- istream* input = new ifstream(filename.c_str());
- if(!*input) {
- throw Exception("file does not exist or is unreadable: " + filename);
- }
- return getNewParser(em, lang, input, filename, true);
+Parser* Parser::getMemoryMappedParser(ExprManager* em, InputLanguage lang, string filename) {
+ MemoryMappedInputBuffer* inputBuffer = new MemoryMappedInputBuffer(filename);
+ return getNewParser(em,lang,inputBuffer,filename);
}
Parser* Parser::getNewParser(ExprManager* em, InputLanguage lang,
- istream& input) {
- return getNewParser(em, lang, &input, "", false);
+ istream& input, string filename) {
+ antlr::CharBuffer* inputBuffer = new CharBuffer(input);
+ return getNewParser(em, lang, inputBuffer, filename);
}
void Parser::disableChecks() {
namespace antlr {
class CharScanner;
+ class InputBuffer;
}
namespace CVC4 {
LANG_AUTO
};
- static Parser* getNewParser(ExprManager* em, InputLanguage lang, std::string filename);
- static Parser* getNewParser(ExprManager* em, InputLanguage lang, std::istream& input);
+ static Parser* getMemoryMappedParser(ExprManager* em, InputLanguage lang, std::string filename);
+ static Parser* getNewParser(ExprManager* em, InputLanguage lang, std::istream& input, std::string filename);
/**
* Destructor.
* Create a new parser.
* @param em the expression manager to usee
* @param lang the language to parse
- * @param input the input stream to parse
+ * @param inputBuffer the input buffer to parse
* @param filename the filename to attach to the stream
* @param deleteInput wheather to delete the input
* @return the parser
*/
- static Parser* getNewParser(ExprManager* em, InputLanguage lang, std::istream* input, std::string filename, bool deleteInput);
+ static Parser* getNewParser(ExprManager* em, InputLanguage lang, antlr::InputBuffer* inputBuffer, std::string filename);
/**
* Create a new parser given the actual antlr parser.
* @param antlrParser the antlr parser to user
*/
- Parser(std::istream* input, AntlrParser* antlrParser, antlr::CharScanner* antlrLexer, bool deleteInput);
+ Parser(antlr::InputBuffer* inputBuffer, AntlrParser* antlrParser, antlr::CharScanner* antlrLexer);
/** Sets the done flag */
void setDone(bool done = true);
antlr::CharScanner* d_antlrLexer;
/** The input stream we are using */
- std::istream* d_input;
+ antlr::InputBuffer* d_inputBuffer;
/** Wherther to de-allocate the input */
bool d_deleteInput;
/** Should the parser do semantic checks? */
bool semanticChecks;
+ /** Should the parser memory-map file input? */
+ bool memoryMap;
+
Options() : binary_name(),
smtcomp_mode(false),
statistics(false),
lang(parser::Parser::LANG_AUTO),
d_cnfConversion(CVC4::CNF_VAR_INTRODUCTION),
parseOnly(false),
- semanticChecks(true)
+ semanticChecks(true),
+ memoryMap(false)
{}
};/* struct Options */