scale.common
Class PragmaStk

java.lang.Object
  extended by scale.common.PragmaStk

public final class PragmaStk
extends java.lang.Object

This class is used to hold and process #pragma information.

$Id: PragmaStk.java,v 1.5 2007-08-16 17:27:39 burrill Exp $

Copyright 2007 by the Scale Compiler Group,
Department of Computer Science
University of Massachusetts,
Amherst MA. 01003, USA
All Rights Reserved.

This implementation allows multiple pragma stacks which, in turn, allows multiple threads to compile separate source files.

The parser allocates a new PragmaStk and uses the newPragma() method to obtain the pragma that contains the appropriate information. The AST nodes can then link to this Pragma instance.

Pragmas have the following syntax:

   pragma := "#pragma" text
   text   := ["push" | "pop"] [cmd]
   cmd    := switch | unroll 
   switch := sw {"on" | "off" | "default"} 
   sw     := "STDC FP_CONTRACT" | "STDC FENV_ACCESS" |
             "STDC CX_LIMITED_RANGE" | "LOOP_PERMUTE" |
             "LOOP_TEST_AT_END"
   unroll := "UNROLL" integer
 
The push prefix causes the current pragma values to be pushed on a stack and a copy made that is then changed. The pop prefix causes the pragma values on the top of the stack to be poped off and used as the current values before being changed.


Nested Class Summary
static class PragmaStk.Pragma
           
 
Field Summary
static int CX_LIMITED_RANGE
           
static PragmaStk.Pragma defaultPragma
          The default prama contains the defaults switch settings and values.
static int FENV_ACCESS
           
static int FP_CONTRACT
           
static int JUST_TO_HAVE_2
          Not used.
static int LOOP_PERMUTE
           
static int LOOP_TEST_AT_END
           
static int UNROLL
          The user specified loop unrolling factor.
 
Constructor Summary
PragmaStk(java.lang.String filename)
          Create a pragma stack to be used in processing pragma information.
 
Method Summary
 PragmaStk.Pragma getTop()
          Return the current (top) pragma entry.
 boolean newPragma(java.lang.String pragmaText, int lineno)
          Obtain the pragma information to be used.
static void setDefaultFlag(int flag, boolean on)
          Specify the default for the specified flag.
static void setDefaultValue(int index, int value)
          Specify the default for the specified value.
 java.lang.String toString()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

FP_CONTRACT

public static final int FP_CONTRACT
See Also:
Constant Field Values

FENV_ACCESS

public static final int FENV_ACCESS
See Also:
Constant Field Values

CX_LIMITED_RANGE

public static final int CX_LIMITED_RANGE
See Also:
Constant Field Values

LOOP_PERMUTE

public static final int LOOP_PERMUTE
See Also:
Constant Field Values

LOOP_TEST_AT_END

public static final int LOOP_TEST_AT_END
See Also:
Constant Field Values

UNROLL

public static final int UNROLL
The user specified loop unrolling factor. The default is 0 which means that the compiler is to determine the unroll factor. An unroll factor of 1 inhibits unrolling.

See Also:
Constant Field Values

JUST_TO_HAVE_2

public static final int JUST_TO_HAVE_2
Not used. It's here to show how new ones should be added.

See Also:
Constant Field Values

defaultPragma

public static final PragmaStk.Pragma defaultPragma
The default prama contains the defaults switch settings and values. Some are set by compiler command line switches. This pragma is used when no pragmas have been provided. For example, Fortran has no pragma-like facility.

Constructor Detail

PragmaStk

public PragmaStk(java.lang.String filename)
Create a pragma stack to be used in processing pragma information.

Parameters:
filename - is the filename of the source code that will be parsed
Method Detail

getTop

public PragmaStk.Pragma getTop()
Return the current (top) pragma entry.


setDefaultFlag

public static void setDefaultFlag(int flag,
                                  boolean on)
Specify the default for the specified flag.


setDefaultValue

public static void setDefaultValue(int index,
                                   int value)
Specify the default for the specified value.


toString

public java.lang.String toString()
Overrides:
toString in class java.lang.Object

newPragma

public boolean newPragma(java.lang.String pragmaText,
                         int lineno)
Obtain the pragma information to be used. The text is parsed. It must be of the form (whitespace required between elements):
   text   := ["push" | "pop"] [cmd]
   cmd    := switch | unroll 
   switch := sw {"on" | "off" | "default"} 
   sw     := "STDC FP_CONTRACT" | "STDC FENV_ACCESS" |
             "STDC CX_LIMITED_RANGE" | "LOOP_PERMUTE" |
             "LOOP_TEST_AT_END"
   unroll := "UNROLL" integer
 
The push prefix causes the current pragma values to be pushed on a stack and a copy made that is then changed. The pop prefix causes the pragma values on the top of the stack to be poped off and used as the current values before being changed.

Parameters:
pragmaText - is the pragma text to be processed
lineno - is the current line in the source code
Returns:
true if the pragma was not valid