Path: blob/aarch64-shenandoah-jdk8u272-b10/hotspot/src/share/vm/adlc/filebuff.cpp
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// FILEBUFF.CPP - Routines for handling a parser file buffer25#include "adlc.hpp"2627using namespace std;2829//------------------------------FileBuff---------------------------------------30// Create a new parsing buffer31FileBuff::FileBuff( BufferedFile *fptr, ArchDesc& archDesc) : _fp(fptr), _AD(archDesc) {32_err = fseek(_fp->_fp, 0, SEEK_END); // Seek to end of file33if (_err) {34file_error(SEMERR, 0, "File seek error reading input file");35exit(1); // Exit on seek error36}37_filepos = ftell(_fp->_fp); // Find offset of end of file38_bufferSize = _filepos + 5; // Filepos points to last char, so add padding39_err = fseek(_fp->_fp, 0, SEEK_SET); // Reset to beginning of file40if (_err) {41file_error(SEMERR, 0, "File seek error reading input file\n");42exit(1); // Exit on seek error43}44_filepos = ftell(_fp->_fp); // Reset current file position45_linenum = 0;4647_bigbuf = new char[_bufferSize]; // Create buffer to hold text for parser48if( !_bigbuf ) {49file_error(SEMERR, 0, "Buffer allocation failed\n");50exit(1); // Exit on allocation failure51}52*_bigbuf = '\n'; // Lead with a sentinel newline53_buf = _bigbuf+1; // Skip sentinel54_bufmax = _buf; // Buffer is empty55_bufeol = _bigbuf; // _bufeol points at sentinel56_filepos = -1; // filepos is in sync with _bufeol57_bufoff = _offset = 0L; // Offset at file start5859_bufmax += fread(_buf, 1, _bufferSize-2, _fp->_fp); // Fill buffer & set end value60if (_bufmax == _buf) {61file_error(SEMERR, 0, "File read error, no input read\n");62exit(1); // Exit on read error63}64*_bufmax = '\n'; // End with a sentinel new-line65*(_bufmax+1) = '\0'; // Then end with a sentinel NULL66}6768//------------------------------~FileBuff--------------------------------------69// Nuke the FileBuff70FileBuff::~FileBuff() {71delete _bigbuf;72}7374//------------------------------get_line----------------------------------------75char *FileBuff::get_line(void) {76char *retval;7778// Check for end of file & return NULL79if (_bufeol >= _bufmax) return NULL;8081_linenum++;82retval = ++_bufeol; // return character following end of previous line83if (*retval == '\0') return NULL; // Check for EOF sentinel84// Search for newline character which must end each line85for(_filepos++; *_bufeol != '\n'; _bufeol++)86_filepos++; // keep filepos in sync with _bufeol87// _bufeol & filepos point at end of current line, so return pointer to start88return retval;89}9091//------------------------------file_error-------------------------------------92void FileBuff::file_error(int flag, int linenum, const char *fmt, ...)93{94va_list args;9596va_start(args, fmt);97switch (flag) {98case 0: _AD._warnings += _AD.emit_msg(0, flag, linenum, fmt, args);99case 1: _AD._syntax_errs += _AD.emit_msg(0, flag, linenum, fmt, args);100case 2: _AD._semantic_errs += _AD.emit_msg(0, flag, linenum, fmt, args);101default: assert(0, ""); break;102}103va_end(args);104_AD._no_output = 1;105}106107108