Path: blob/aarch64-shenandoah-jdk8u272-b10/hotspot/src/share/vm/adlc/filebuff.hpp
32285 views
/*1* Copyright (c) 1997, 2014, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation.7*8* This code is distributed in the hope that it will be useful, but WITHOUT9* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or10* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License11* version 2 for more details (a copy is included in the LICENSE file that12* accompanied this code).13*14* You should have received a copy of the GNU General Public License version15* 2 along with this work; if not, write to the Free Software Foundation,16* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.17*18* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA19* or visit www.oracle.com if you need additional information or have any20* questions.21*22*/2324#ifndef SHARE_VM_ADLC_FILEBUFF_HPP25#define SHARE_VM_ADLC_FILEBUFF_HPP2627// FILEBUFF.HPP - Definitions for parser file buffering routines28#include <iostream>2930using namespace std;3132// STRUCTURE FOR HANDLING INPUT AND OUTPUT FILES3334class BufferedFile {35public:36const char *_name;37FILE *_fp;38inline BufferedFile() { _name = NULL; _fp = NULL; };39inline ~BufferedFile() {};40};4142class ArchDesc;4344//------------------------------FileBuff--------------------------------------45// This class defines a nicely behaved buffer of text. Entire file of text46// is read into buffer at creation, with sentinels at start and end.47class FileBuff {48private:49long _bufferSize; // Size of text holding buffer.50long _offset; // Expected filepointer offset.51long _bufoff; // Start of buffer file offset5253char *_buf; // The buffer itself.54char *_bigbuf; // The buffer plus sentinels; actual heap area55char *_bufmax; // A pointer to the buffer end sentinel56char *_bufeol; // A pointer to the last complete line end5758int _err; // Error flag for file seek/read operations59long _filepos; // Current offset from start of file60int _linenum;6162ArchDesc& _AD; // Reference to Architecture Description6364// Error reporting function65void file_error(int flag, int linenum, const char *fmt, ...);6667public:68const BufferedFile *_fp; // File to be buffered6970FileBuff(BufferedFile *fp, ArchDesc& archDesc); // Constructor71~FileBuff(); // Destructor7273// This returns a pointer to the start of the current line in the buffer,74// and increments bufeol and filepos to point at the end of that line.75char *get_line(void);76int linenum() const { return _linenum; }77void set_linenum(int line) { _linenum = line; }7879// This converts a pointer into the buffer to a file offset. It only works80// when the pointer is valid (i.e. just obtained from getline()).81long getoff(const char* s) { return _bufoff + (long)(s - _buf); }82};83#endif // SHARE_VM_ADLC_FILEBUFF_HPP848586