hotspot/src/share/vm/adlc/filebuff.hpp
author ikrylov
Wed, 01 Dec 2010 18:26:32 -0500
changeset 7405 e6fc8d3926f8
parent 7397 5b173b4ca846
child 13971 3c568f3dacca
permissions -rw-r--r--
6348631: remove the use of the HPI library from Hotspot Summary: move functions from hpi library to hotspot, communicate with licensees and open source community, check jdk for dependency, file CCC request Reviewed-by: coleenp, acorn, dsamersoff
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
     1
/*
7397
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5547
diff changeset
     2
 * Copyright (c) 1997, 2010, Oracle and/or its affiliates. All rights reserved.
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
489c9b5090e2 Initial load
duke
parents:
diff changeset
     4
 *
489c9b5090e2 Initial load
duke
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
489c9b5090e2 Initial load
duke
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
489c9b5090e2 Initial load
duke
parents:
diff changeset
     7
 * published by the Free Software Foundation.
489c9b5090e2 Initial load
duke
parents:
diff changeset
     8
 *
489c9b5090e2 Initial load
duke
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
489c9b5090e2 Initial load
duke
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
489c9b5090e2 Initial load
duke
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
489c9b5090e2 Initial load
duke
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
489c9b5090e2 Initial load
duke
parents:
diff changeset
    13
 * accompanied this code).
489c9b5090e2 Initial load
duke
parents:
diff changeset
    14
 *
489c9b5090e2 Initial load
duke
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
489c9b5090e2 Initial load
duke
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
489c9b5090e2 Initial load
duke
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    18
 *
5547
f4b087cbb361 6941466: Oracle rebranding changes for Hotspot repositories
trims
parents: 2786
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
f4b087cbb361 6941466: Oracle rebranding changes for Hotspot repositories
trims
parents: 2786
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
f4b087cbb361 6941466: Oracle rebranding changes for Hotspot repositories
trims
parents: 2786
diff changeset
    21
 * questions.
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    22
 *
489c9b5090e2 Initial load
duke
parents:
diff changeset
    23
 */
489c9b5090e2 Initial load
duke
parents:
diff changeset
    24
7397
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5547
diff changeset
    25
#ifndef SHARE_VM_ADLC_FILEBUFF_HPP
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5547
diff changeset
    26
#define SHARE_VM_ADLC_FILEBUFF_HPP
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5547
diff changeset
    27
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    28
// FILEBUFF.HPP - Definitions for parser file buffering routines
775
d9c9b9cd55fb 6718830: Hotspot fails to build with gcc 4.3
xlu
parents: 1
diff changeset
    29
#include <iostream>
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    30
775
d9c9b9cd55fb 6718830: Hotspot fails to build with gcc 4.3
xlu
parents: 1
diff changeset
    31
using namespace std;
2129
e810a33b5c67 6778669: Patch from Red Hat -- fixes compilation errors
twisti
parents: 1675
diff changeset
    32
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    33
// STRUCTURE FOR HANDLING INPUT AND OUTPUT FILES
489c9b5090e2 Initial load
duke
parents:
diff changeset
    34
typedef struct {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    35
  const char *_name;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    36
  FILE *_fp;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    37
} BufferedFile;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    38
489c9b5090e2 Initial load
duke
parents:
diff changeset
    39
class ArchDesc;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    40
489c9b5090e2 Initial load
duke
parents:
diff changeset
    41
//------------------------------FileBuff--------------------------------------
489c9b5090e2 Initial load
duke
parents:
diff changeset
    42
// This class defines a nicely behaved buffer of text.  Entire file of text
2131
98f9cef66a34 6810672: Comment typos
twisti
parents: 2129
diff changeset
    43
// is read into buffer at creation, with sentinels at start and end.
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    44
class FileBuff {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    45
  friend class FileBuffRegion;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    46
 private:
489c9b5090e2 Initial load
duke
parents:
diff changeset
    47
  long  _bufferSize;            // Size of text holding buffer.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    48
  long  _offset;                // Expected filepointer offset.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    49
  long  _bufoff;                // Start of buffer file offset
489c9b5090e2 Initial load
duke
parents:
diff changeset
    50
489c9b5090e2 Initial load
duke
parents:
diff changeset
    51
  char *_buf;                   // The buffer itself.
2131
98f9cef66a34 6810672: Comment typos
twisti
parents: 2129
diff changeset
    52
  char *_bigbuf;                // The buffer plus sentinels; actual heap area
98f9cef66a34 6810672: Comment typos
twisti
parents: 2129
diff changeset
    53
  char *_bufmax;                // A pointer to the buffer end sentinel
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    54
  char *_bufeol;                // A pointer to the last complete line end
489c9b5090e2 Initial load
duke
parents:
diff changeset
    55
489c9b5090e2 Initial load
duke
parents:
diff changeset
    56
  int   _err;                   // Error flag for file seek/read operations
489c9b5090e2 Initial load
duke
parents:
diff changeset
    57
  long  _filepos;               // Current offset from start of file
1495
128fe18951ed 6754519: don't emit flag fixup for NaN when condition being tested doesn't need it
never
parents: 775
diff changeset
    58
  int   _linenum;
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    59
489c9b5090e2 Initial load
duke
parents:
diff changeset
    60
  ArchDesc& _AD;                // Reference to Architecture Description
489c9b5090e2 Initial load
duke
parents:
diff changeset
    61
489c9b5090e2 Initial load
duke
parents:
diff changeset
    62
  // Error reporting function
489c9b5090e2 Initial load
duke
parents:
diff changeset
    63
  void file_error(int flag, int linenum, const char *fmt, ...);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    64
489c9b5090e2 Initial load
duke
parents:
diff changeset
    65
 public:
489c9b5090e2 Initial load
duke
parents:
diff changeset
    66
  const BufferedFile *_fp;           // File to be buffered
489c9b5090e2 Initial load
duke
parents:
diff changeset
    67
489c9b5090e2 Initial load
duke
parents:
diff changeset
    68
  FileBuff(BufferedFile *fp, ArchDesc& archDesc); // Constructor
489c9b5090e2 Initial load
duke
parents:
diff changeset
    69
  ~FileBuff();                  // Destructor
489c9b5090e2 Initial load
duke
parents:
diff changeset
    70
489c9b5090e2 Initial load
duke
parents:
diff changeset
    71
  // This returns a pointer to the start of the current line in the buffer,
489c9b5090e2 Initial load
duke
parents:
diff changeset
    72
  // and increments bufeol and filepos to point at the end of that line.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    73
  char *get_line(void);
1495
128fe18951ed 6754519: don't emit flag fixup for NaN when condition being tested doesn't need it
never
parents: 775
diff changeset
    74
  int linenum() const { return _linenum; }
1662
76a93a5fb765 6771309: debugging AD files is difficult without #line directives in generated code
jrose
parents: 1495
diff changeset
    75
  void set_linenum(int line) { _linenum = line; }
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    76
489c9b5090e2 Initial load
duke
parents:
diff changeset
    77
  // This converts a pointer into the buffer to a file offset.  It only works
489c9b5090e2 Initial load
duke
parents:
diff changeset
    78
  // when the pointer is valid (i.e. just obtained from getline()).
2786
81833beba87f 6839126: Type error found by newer windows compiler
ohair
parents: 2154
diff changeset
    79
  long getoff(const char* s) { return _bufoff + (long)(s - _buf); }
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    80
};
489c9b5090e2 Initial load
duke
parents:
diff changeset
    81
489c9b5090e2 Initial load
duke
parents:
diff changeset
    82
//------------------------------FileBuffRegion---------------------------------
489c9b5090e2 Initial load
duke
parents:
diff changeset
    83
// A buffer region is really a region of some file, specified as a linked list
489c9b5090e2 Initial load
duke
parents:
diff changeset
    84
// of offsets and lengths.  These regions can be merged; overlapping regions
489c9b5090e2 Initial load
duke
parents:
diff changeset
    85
// will coalesce.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    86
class FileBuffRegion {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    87
 public:                        // Workaround dev-studio friend/private bug
489c9b5090e2 Initial load
duke
parents:
diff changeset
    88
  FileBuffRegion *_next;        // Linked list of regions sorted by offset.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    89
 private:
489c9b5090e2 Initial load
duke
parents:
diff changeset
    90
  FileBuff       *_bfr;         // The Buffer of the file
489c9b5090e2 Initial load
duke
parents:
diff changeset
    91
  int _offset, _length;         // The file area
489c9b5090e2 Initial load
duke
parents:
diff changeset
    92
  int             _sol;         // Start of line where the file area starts
489c9b5090e2 Initial load
duke
parents:
diff changeset
    93
  int             _line;        // First line of region
489c9b5090e2 Initial load
duke
parents:
diff changeset
    94
489c9b5090e2 Initial load
duke
parents:
diff changeset
    95
 public:
489c9b5090e2 Initial load
duke
parents:
diff changeset
    96
  FileBuffRegion(FileBuff*, int sol, int line, int offset, int len);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    97
  ~FileBuffRegion();
489c9b5090e2 Initial load
duke
parents:
diff changeset
    98
489c9b5090e2 Initial load
duke
parents:
diff changeset
    99
  FileBuffRegion *copy();                   // Deep copy
489c9b5090e2 Initial load
duke
parents:
diff changeset
   100
  FileBuffRegion *merge(FileBuffRegion*); // Merge 2 regions; delete input
489c9b5090e2 Initial load
duke
parents:
diff changeset
   101
489c9b5090e2 Initial load
duke
parents:
diff changeset
   102
  void print(ostream&);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   103
  friend ostream& operator<< (ostream&, FileBuffRegion&);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   104
};
7397
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5547
diff changeset
   105
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5547
diff changeset
   106
#endif // SHARE_VM_ADLC_FILEBUFF_HPP