diff options
Diffstat (limited to 'src/parser/memory_mapped_input_buffer.h')
-rw-r--r-- | src/parser/memory_mapped_input_buffer.h | 64 |
1 files changed, 8 insertions, 56 deletions
diff --git a/src/parser/memory_mapped_input_buffer.h b/src/parser/memory_mapped_input_buffer.h index e1639a072..88ba2183a 100644 --- a/src/parser/memory_mapped_input_buffer.h +++ b/src/parser/memory_mapped_input_buffer.h @@ -14,69 +14,21 @@ #ifndef __CVC4__PARSER__MEMORY_MAPPED_INPUT_BUFFER_H #define __CVC4__PARSER__MEMORY_MAPPED_INPUT_BUFFER_H -#include <cstdio> -#include <cerrno> - -#include <fcntl.h> -#include <stdint.h> -#include <string.h> - -#include <sys/mman.h> -#include <sys/stat.h> - -#include <antlr/InputBuffer.hpp> - -#include "util/Assert.h" -#include "util/exception.h" +#include <antlr3input.h> +#include <string> namespace CVC4 { namespace parser { -class MemoryMappedInputBuffer : public antlr::InputBuffer { - -public: - MemoryMappedInputBuffer(const std::string& filename) { - struct stat st; - if( stat(filename.c_str(), &st) == -1 ) { - char buf[80]; - const char* errMsg = strerror_r(errno, buf, sizeof(buf)); - throw Exception("unable to stat() file `" + filename + "': " + errMsg); - } - d_size = st.st_size; - - int fd = open(filename.c_str(), O_RDONLY); - if( fd == -1 ) { - char buf[80]; - const char* errMsg = strerror_r(errno, buf, sizeof(buf)); - throw Exception("unable to fopen() file `" + filename + "': " + errMsg); - } - - d_start = static_cast< const char * >( - mmap( 0, d_size, PROT_READ, MAP_FILE | MAP_PRIVATE, fd, 0 ) ); - if( intptr_t( d_start ) == -1 ) { - char buf[80]; - const char* errMsg = strerror_r(errno, buf, sizeof(buf)); - throw Exception("unable to mmap() file `" + filename + "': " + errMsg); - } - d_cur = d_start; - d_end = d_start + d_size; - } +extern "C" { - ~MemoryMappedInputBuffer() { - munmap((void*) d_start, d_size); - } +pANTLR3_INPUT_STREAM +MemoryMappedInputBufferNew(const std::string& filename); - 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; -}; +} +} -}/* CVC4::parser namespace */ -}/* CVC4 namespace */ #endif /* __CVC4__PARSER__MEMORY_MAPPED_INPUT_BUFFER_H */ |