diff options
Diffstat (limited to 'lib/AsmParser')
-rw-r--r-- | lib/AsmParser/Lexer.cpp | 2058 | ||||
-rw-r--r-- | lib/AsmParser/Lexer.l | 184 | ||||
-rw-r--r-- | lib/AsmParser/Makefile | 7 | ||||
-rw-r--r-- | lib/AsmParser/Parser.cpp | 84 | ||||
-rw-r--r-- | lib/AsmParser/ParserInternals.h | 159 | ||||
-rw-r--r-- | lib/AsmParser/llvmAsmParser.cpp | 2202 | ||||
-rw-r--r-- | lib/AsmParser/llvmAsmParser.h | 87 | ||||
-rw-r--r-- | lib/AsmParser/llvmAsmParser.y | 954 |
8 files changed, 5735 insertions, 0 deletions
diff --git a/lib/AsmParser/Lexer.cpp b/lib/AsmParser/Lexer.cpp new file mode 100644 index 0000000..9edd3bf --- /dev/null +++ b/lib/AsmParser/Lexer.cpp @@ -0,0 +1,2058 @@ +#define yy_create_buffer llvmAsm_create_buffer +#define yy_delete_buffer llvmAsm_delete_buffer +#define yy_scan_buffer llvmAsm_scan_buffer +#define yy_scan_string llvmAsm_scan_string +#define yy_scan_bytes llvmAsm_scan_bytes +#define yy_flex_debug llvmAsm_flex_debug +#define yy_init_buffer llvmAsm_init_buffer +#define yy_flush_buffer llvmAsm_flush_buffer +#define yy_load_buffer_state llvmAsm_load_buffer_state +#define yy_switch_to_buffer llvmAsm_switch_to_buffer +#define yyin llvmAsmin +#define yyleng llvmAsmleng +#define yylex llvmAsmlex +#define yyout llvmAsmout +#define yyrestart llvmAsmrestart +#define yytext llvmAsmtext +#define yylineno llvmAsmlineno + +#line 20 "Lexer.cpp" +/* A lexical scanner generated by flex */ + +/* Scanner skeleton version: + * $Header$ + */ + +#define FLEX_SCANNER +#define YY_FLEX_MAJOR_VERSION 2 +#define YY_FLEX_MINOR_VERSION 5 + +#include <stdio.h> + + +/* cfront 1.2 defines "c_plusplus" instead of "__cplusplus" */ +#ifdef c_plusplus +#ifndef __cplusplus +#define __cplusplus +#endif +#endif + + +#ifdef __cplusplus + +#include <stdlib.h> +#include <unistd.h> + +/* Use prototypes in function declarations. */ +#define YY_USE_PROTOS + +/* The "const" storage-class-modifier is valid. */ +#define YY_USE_CONST + +#else /* ! __cplusplus */ + +#if __STDC__ + +#define YY_USE_PROTOS +#define YY_USE_CONST + +#endif /* __STDC__ */ +#endif /* ! __cplusplus */ + +#ifdef __TURBOC__ + #pragma warn -rch + #pragma warn -use +#include <io.h> +#include <stdlib.h> +#define YY_USE_CONST +#define YY_USE_PROTOS +#endif + +#ifdef YY_USE_CONST +#define yyconst const +#else +#define yyconst +#endif + + +#ifdef YY_USE_PROTOS +#define YY_PROTO(proto) proto +#else +#define YY_PROTO(proto) () +#endif + +/* Returned upon end-of-file. */ +#define YY_NULL 0 + +/* Promotes a possibly negative, possibly signed char to an unsigned + * integer for use as an array index. If the signed char is negative, + * we want to instead treat it as an 8-bit unsigned char, hence the + * double cast. + */ +#define YY_SC_TO_UI(c) ((unsigned int) (unsigned char) c) + +/* Enter a start condition. This macro really ought to take a parameter, + * but we do it the disgusting crufty way forced on us by the ()-less + * definition of BEGIN. + */ +#define BEGIN yy_start = 1 + 2 * + +/* Translate the current start state into a value that can be later handed + * to BEGIN to return to the state. The YYSTATE alias is for lex + * compatibility. + */ +#define YY_START ((yy_start - 1) / 2) +#define YYSTATE YY_START + +/* Action number for EOF rule of a given start state. */ +#define YY_STATE_EOF(state) (YY_END_OF_BUFFER + state + 1) + +/* Special action meaning "start processing a new file". */ +#define YY_NEW_FILE yyrestart( yyin ) + +#define YY_END_OF_BUFFER_CHAR 0 + +/* Size of default input buffer. */ +#define YY_BUF_SIZE 16384 + +typedef struct yy_buffer_state *YY_BUFFER_STATE; + +extern int yyleng; +extern FILE *yyin, *yyout; + +#define EOB_ACT_CONTINUE_SCAN 0 +#define EOB_ACT_END_OF_FILE 1 +#define EOB_ACT_LAST_MATCH 2 + +/* The funky do-while in the following #define is used to turn the definition + * int a single C statement (which needs a semi-colon terminator). This + * avoids problems with code like: + * + * if ( condition_holds ) + * yyless( 5 ); + * else + * do_something_else(); + * + * Prior to using the do-while the compiler would get upset at the + * "else" because it interpreted the "if" statement as being all + * done when it reached the ';' after the yyless() call. + */ + +/* Return all but the first 'n' matched characters back to the input stream. */ + +#define yyless(n) \ + do \ + { \ + /* Undo effects of setting up yytext. */ \ + *yy_cp = yy_hold_char; \ + YY_RESTORE_YY_MORE_OFFSET \ + yy_c_buf_p = yy_cp = yy_bp + n - YY_MORE_ADJ; \ + YY_DO_BEFORE_ACTION; /* set up yytext again */ \ + } \ + while ( 0 ) + +#define unput(c) yyunput( c, yytext_ptr ) + +/* The following is because we cannot portably get our hands on size_t + * (without autoconf's help, which isn't available because we want + * flex-generated scanners to compile on their own). + */ +typedef unsigned int yy_size_t; + + +struct yy_buffer_state + { + FILE *yy_input_file; + + char *yy_ch_buf; /* input buffer */ + char *yy_buf_pos; /* current position in input buffer */ + + /* Size of input buffer in bytes, not including room for EOB + * characters. + */ + yy_size_t yy_buf_size; + + /* Number of characters read into yy_ch_buf, not including EOB + * characters. + */ + int yy_n_chars; + + /* Whether we "own" the buffer - i.e., we know we created it, + * and can realloc() it to grow it, and should free() it to + * delete it. + */ + int yy_is_our_buffer; + + /* Whether this is an "interactive" input source; if so, and + * if we're using stdio for input, then we want to use getc() + * instead of fread(), to make sure we stop fetching input after + * each newline. + */ + int yy_is_interactive; + + /* Whether we're considered to be at the beginning of a line. + * If so, '^' rules will be active on the next match, otherwise + * not. + */ + int yy_at_bol; + + /* Whether to try to fill the input buffer when we reach the + * end of it. + */ + int yy_fill_buffer; + + int yy_buffer_status; +#define YY_BUFFER_NEW 0 +#define YY_BUFFER_NORMAL 1 + /* When an EOF's been seen but there's still some text to process + * then we mark the buffer as YY_EOF_PENDING, to indicate that we + * shouldn't try reading from the input source any more. We might + * still have a bunch of tokens to match, though, because of + * possible backing-up. + * + * When we actually see the EOF, we change the status to "new" + * (via yyrestart()), so that the user can continue scanning by + * just pointing yyin at a new input file. + */ +#define YY_BUFFER_EOF_PENDING 2 + }; + +static YY_BUFFER_STATE yy_current_buffer = 0; + +/* We provide macros for accessing buffer states in case in the + * future we want to put the buffer states in a more general + * "scanner state". + */ +#define YY_CURRENT_BUFFER yy_current_buffer + + +/* yy_hold_char holds the character lost when yytext is formed. */ +static char yy_hold_char; + +static int yy_n_chars; /* number of characters read into yy_ch_buf */ + + +int yyleng; + +/* Points to current character in buffer. */ +static char *yy_c_buf_p = (char *) 0; +static int yy_init = 1; /* whether we need to initialize */ +static int yy_start = 0; /* start state number */ + +/* Flag which is used to allow yywrap()'s to do buffer switches + * instead of setting up a fresh yyin. A bit of a hack ... + */ +static int yy_did_buffer_switch_on_eof; + +void yyrestart YY_PROTO(( FILE *input_file )); + +void yy_switch_to_buffer YY_PROTO(( YY_BUFFER_STATE new_buffer )); +void yy_load_buffer_state YY_PROTO(( void )); +YY_BUFFER_STATE yy_create_buffer YY_PROTO(( FILE *file, int size )); +void yy_delete_buffer YY_PROTO(( YY_BUFFER_STATE b )); +void yy_init_buffer YY_PROTO(( YY_BUFFER_STATE b, FILE *file )); +void yy_flush_buffer YY_PROTO(( YY_BUFFER_STATE b )); +#define YY_FLUSH_BUFFER yy_flush_buffer( yy_current_buffer ) + +YY_BUFFER_STATE yy_scan_buffer YY_PROTO(( char *base, yy_size_t size )); +YY_BUFFER_STATE yy_scan_string YY_PROTO(( yyconst char *yy_str )); +YY_BUFFER_STATE yy_scan_bytes YY_PROTO(( yyconst char *bytes, int len )); + +static void *yy_flex_alloc YY_PROTO(( yy_size_t )); +static inline void *yy_flex_realloc YY_PROTO(( void *, yy_size_t )); +static void yy_flex_free YY_PROTO(( void * )); + +#define yy_new_buffer yy_create_buffer + +#define yy_set_interactive(is_interactive) \ + { \ + if ( ! yy_current_buffer ) \ + yy_current_buffer = yy_create_buffer( yyin, YY_BUF_SIZE ); \ + yy_current_buffer->yy_is_interactive = is_interactive; \ + } + +#define yy_set_bol(at_bol) \ + { \ + if ( ! yy_current_buffer ) \ + yy_current_buffer = yy_create_buffer( yyin, YY_BUF_SIZE ); \ + yy_current_buffer->yy_at_bol = at_bol; \ + } + +#define YY_AT_BOL() (yy_current_buffer->yy_at_bol) + + +#define YY_USES_REJECT + +#define yywrap() 1 +#define YY_SKIP_YYWRAP +typedef unsigned char YY_CHAR; +FILE *yyin = (FILE *) 0, *yyout = (FILE *) 0; +typedef int yy_state_type; +extern int yylineno; +int yylineno = 1; +extern char *yytext; +#define yytext_ptr yytext + +static yy_state_type yy_get_previous_state YY_PROTO(( void )); +static yy_state_type yy_try_NUL_trans YY_PROTO(( yy_state_type current_state )); +static int yy_get_next_buffer YY_PROTO(( void )); +static void yy_fatal_error YY_PROTO(( yyconst char msg[] )); + +/* Done after the current pattern has been matched and before the + * corresponding action - sets up yytext. + */ +#define YY_DO_BEFORE_ACTION \ + yytext_ptr = yy_bp; \ + yyleng = (int) (yy_cp - yy_bp); \ + yy_hold_char = *yy_cp; \ + *yy_cp = '\0'; \ + yy_c_buf_p = yy_cp; + +#define YY_NUM_RULES 58 +#define YY_END_OF_BUFFER 59 +static yyconst short int yy_acclist[113] = + { 0, + 59, 57, 58, 56, 57, 58, 56, 58, 57, 58, + 57, 58, 57, 58, 8, 57, 58, 52, 57, 58, + 1, 57, 58, 57, 58, 57, 58, 57, 58, 57, + 58, 57, 58, 57, 58, 57, 58, 57, 58, 57, + 58, 57, 58, 57, 58, 57, 58, 57, 58, 57, + 58, 57, 58, 57, 58, 57, 58, 50, 49, 54, + 53, 52, 1, 9, 40, 51, 49, 55, 28, 31, + 3, 16, 30, 24, 25, 26, 32, 39, 29, 11, + 27, 44, 45, 18, 4, 22, 17, 10, 2, 5, + 20, 23, 12, 34, 38, 36, 37, 35, 33, 14, + + 46, 13, 19, 43, 21, 42, 41, 15, 6, 47, + 48, 7 + } ; + +static yyconst short int yy_accept[199] = + { 0, + 1, 1, 1, 2, 4, 7, 9, 11, 13, 15, + 18, 21, 24, 26, 28, 30, 32, 34, 36, 38, + 40, 42, 44, 46, 48, 50, 52, 54, 56, 58, + 58, 58, 59, 60, 60, 61, 62, 63, 64, 64, + 64, 65, 65, 65, 66, 66, 66, 66, 66, 66, + 66, 66, 66, 66, 66, 66, 66, 66, 66, 66, + 66, 66, 66, 66, 66, 66, 66, 66, 66, 66, + 66, 66, 66, 66, 66, 66, 66, 66, 67, 68, + 69, 70, 70, 70, 70, 70, 70, 71, 71, 72, + 72, 72, 72, 72, 72, 73, 73, 73, 73, 73, + + 74, 75, 76, 77, 77, 78, 79, 79, 79, 79, + 79, 80, 80, 80, 80, 80, 80, 80, 80, 80, + 80, 80, 81, 82, 82, 82, 82, 82, 83, 83, + 83, 83, 84, 85, 85, 85, 85, 85, 85, 85, + 85, 85, 85, 85, 86, 87, 87, 88, 88, 88, + 89, 89, 90, 90, 90, 91, 92, 92, 92, 93, + 93, 93, 94, 95, 96, 97, 98, 99, 100, 101, + 102, 102, 103, 104, 104, 105, 105, 106, 106, 106, + 107, 107, 108, 109, 110, 110, 110, 110, 111, 111, + 112, 112, 112, 112, 112, 112, 113, 113 + + } ; + +static yyconst int yy_ec[256] = + { 0, + 1, 1, 1, 1, 1, 1, 1, 1, 2, 3, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 2, 1, 4, 1, 5, 6, 1, 1, 1, + 1, 1, 1, 1, 7, 5, 1, 8, 8, 8, + 8, 8, 8, 8, 8, 8, 8, 9, 10, 1, + 1, 1, 1, 1, 5, 5, 5, 5, 5, 5, + 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, + 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, + 1, 1, 1, 1, 5, 1, 11, 12, 13, 14, + + 15, 16, 17, 18, 19, 5, 5, 20, 21, 22, + 23, 24, 25, 26, 27, 28, 29, 30, 31, 5, + 32, 5, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1 + } ; + +static yyconst int yy_meta[33] = + { 0, + 1, 1, 2, 3, 4, 1, 5, 4, 6, 1, + 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, + 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, + 4, 4 + } ; + +static yyconst short int yy_base[203] = + { 0, + 0, 0, 389, 390, 390, 390, 0, 379, 26, 379, + 27, 0, 28, 40, 29, 35, 34, 42, 30, 38, + 56, 60, 55, 63, 65, 84, 68, 107, 52, 382, + 376, 390, 0, 376, 375, 374, 74, 0, 32, 64, + 372, 78, 67, 371, 77, 92, 76, 79, 89, 98, + 100, 95, 102, 105, 108, 112, 111, 119, 122, 123, + 116, 126, 128, 129, 132, 134, 137, 138, 139, 140, + 143, 144, 145, 149, 146, 156, 154, 390, 0, 371, + 369, 157, 166, 158, 161, 167, 368, 170, 367, 174, + 175, 179, 180, 182, 366, 183, 181, 188, 184, 365, + + 364, 363, 362, 190, 361, 360, 191, 211, 198, 199, + 359, 194, 200, 201, 202, 204, 205, 212, 203, 225, + 214, 358, 357, 228, 209, 231, 232, 356, 233, 234, + 235, 355, 354, 236, 238, 239, 241, 247, 249, 252, + 242, 254, 259, 353, 352, 256, 351, 264, 265, 350, + 267, 349, 270, 271, 348, 347, 273, 274, 346, 276, + 275, 345, 344, 343, 342, 341, 340, 335, 330, 325, + 283, 320, 319, 278, 317, 284, 316, 285, 288, 315, + 289, 313, 311, 310, 293, 291, 301, 308, 295, 244, + 303, 299, 302, 307, 309, 82, 390, 331, 334, 337, + + 342, 53 + } ; + +static yyconst short int yy_def[203] = + { 0, + 197, 1, 197, 197, 197, 197, 198, 199, 200, 197, + 199, 201, 199, 199, 199, 199, 199, 199, 199, 199, + 199, 199, 199, 199, 199, 199, 199, 199, 199, 198, + 199, 197, 202, 197, 197, 197, 199, 201, 199, 199, + 199, 199, 199, 199, 199, 199, 199, 199, 199, 199, + 199, 199, 199, 199, 199, 199, 199, 199, 199, 199, + 199, 199, 199, 199, 199, 199, 199, 199, 199, 199, + 199, 199, 199, 199, 199, 199, 199, 197, 202, 197, + 199, 199, 199, 199, 199, 199, 199, 199, 199, 199, + 199, 199, 199, 199, 199, 199, 199, 199, 199, 199, + + 199, 199, 199, 199, 199, 199, 199, 199, 199, 199, + 199, 199, 199, 199, 199, 199, 199, 199, 199, 199, + 199, 199, 199, 199, 199, 199, 199, 199, 199, 199, + 199, 199, 199, 199, 199, 199, 199, 199, 199, 199, + 199, 199, 199, 199, 199, 199, 199, 199, 199, 199, + 199, 199, 199, 199, 199, 199, 199, 199, 199, 199, + 199, 199, 199, 199, 199, 199, 199, 199, 199, 199, + 199, 199, 199, 199, 199, 199, 199, 199, 199, 199, + 199, 199, 199, 199, 199, 199, 199, 199, 199, 199, + 199, 199, 199, 199, 199, 199, 0, 197, 197, 197, + + 197, 197 + } ; + +static yyconst short int yy_nxt[423] = + { 0, + 4, 5, 6, 7, 8, 9, 10, 11, 4, 12, + 13, 14, 15, 16, 17, 18, 19, 8, 20, 21, + 22, 23, 8, 24, 8, 25, 26, 27, 28, 29, + 8, 8, 34, 35, 37, 32, 32, 32, 32, 45, + 32, 39, 32, 32, 53, 81, 32, 40, 32, 46, + 32, 41, 50, 47, 42, 49, 79, 48, 54, 55, + 32, 51, 43, 32, 32, 44, 56, 52, 32, 60, + 58, 32, 32, 32, 77, 32, 32, 61, 57, 64, + 62, 37, 32, 82, 32, 32, 32, 32, 59, 84, + 32, 63, 32, 71, 83, 65, 85, 32, 66, 72, + + 32, 67, 89, 32, 86, 87, 32, 88, 32, 92, + 32, 68, 69, 32, 70, 32, 32, 90, 73, 32, + 32, 97, 91, 96, 32, 74, 75, 32, 94, 93, + 32, 32, 98, 76, 32, 95, 32, 32, 99, 101, + 32, 100, 32, 102, 103, 32, 32, 32, 32, 105, + 111, 32, 32, 32, 32, 104, 106, 32, 112, 109, + 110, 108, 32, 107, 32, 32, 32, 114, 117, 32, + 116, 113, 119, 118, 32, 32, 115, 122, 32, 120, + 123, 125, 32, 32, 121, 127, 124, 32, 32, 32, + 32, 32, 32, 128, 132, 129, 32, 131, 32, 32, + + 126, 130, 32, 134, 133, 135, 32, 32, 32, 32, + 32, 32, 32, 32, 144, 145, 150, 32, 136, 32, + 32, 143, 32, 141, 142, 137, 148, 138, 154, 146, + 139, 147, 140, 32, 149, 152, 32, 151, 153, 32, + 32, 32, 32, 32, 32, 155, 32, 32, 158, 32, + 32, 157, 32, 162, 159, 32, 161, 32, 160, 156, + 32, 164, 32, 166, 32, 163, 168, 32, 170, 169, + 172, 171, 32, 32, 165, 32, 167, 175, 32, 32, + 173, 32, 32, 32, 32, 177, 32, 178, 180, 181, + 174, 32, 32, 32, 179, 176, 32, 32, 184, 32, + + 182, 32, 186, 32, 185, 183, 188, 32, 187, 32, + 32, 32, 189, 192, 190, 32, 32, 32, 32, 32, + 194, 32, 191, 32, 32, 32, 193, 32, 32, 195, + 196, 30, 30, 32, 30, 30, 30, 31, 32, 31, + 33, 33, 38, 32, 38, 38, 38, 38, 32, 32, + 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, + 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, + 32, 32, 32, 32, 32, 32, 32, 32, 80, 32, + 32, 36, 35, 80, 32, 78, 36, 32, 197, 3, + 197, 197, 197, 197, 197, 197, 197, 197, 197, 197, + + 197, 197, 197, 197, 197, 197, 197, 197, 197, 197, + 197, 197, 197, 197, 197, 197, 197, 197, 197, 197, + 197, 197 + } ; + +static yyconst short int yy_chk[423] = + { 0, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 9, 9, 11, 11, 13, 15, 19, 15, + 39, 13, 17, 16, 19, 39, 20, 13, 14, 16, + 18, 14, 18, 16, 14, 17, 202, 16, 20, 20, + 29, 18, 14, 23, 21, 14, 21, 18, 22, 23, + 22, 24, 40, 25, 29, 43, 27, 23, 21, 25, + 24, 37, 37, 40, 47, 45, 42, 48, 22, 43, + 196, 24, 26, 27, 42, 26, 45, 49, 26, 27, + + 46, 26, 49, 52, 46, 47, 50, 48, 51, 52, + 53, 26, 26, 54, 26, 28, 55, 50, 28, 57, + 56, 57, 51, 56, 61, 28, 28, 58, 54, 53, + 59, 60, 57, 28, 62, 55, 63, 64, 58, 60, + 65, 59, 66, 61, 62, 67, 68, 69, 70, 64, + 69, 71, 72, 73, 75, 63, 64, 74, 70, 67, + 68, 66, 77, 65, 76, 82, 84, 72, 75, 85, + 74, 71, 77, 76, 83, 86, 73, 84, 88, 82, + 85, 88, 90, 91, 83, 91, 86, 92, 93, 97, + 94, 96, 99, 92, 97, 93, 98, 96, 104, 107, + + 90, 94, 112, 99, 98, 104, 109, 110, 113, 114, + 115, 119, 116, 117, 113, 114, 119, 125, 107, 108, + 118, 112, 121, 109, 110, 108, 117, 108, 125, 115, + 108, 116, 108, 120, 118, 121, 124, 120, 124, 126, + 127, 129, 130, 131, 134, 126, 135, 136, 130, 137, + 141, 129, 190, 136, 131, 138, 135, 139, 134, 127, + 140, 138, 142, 139, 146, 137, 140, 143, 142, 141, + 146, 143, 148, 149, 138, 151, 139, 151, 153, 154, + 148, 157, 158, 161, 160, 154, 174, 157, 160, 161, + 149, 171, 176, 178, 158, 153, 179, 181, 176, 186, + + 171, 185, 179, 189, 178, 174, 185, 192, 181, 187, + 193, 191, 186, 191, 187, 194, 188, 195, 184, 183, + 193, 182, 189, 180, 177, 175, 192, 173, 172, 194, + 195, 198, 198, 170, 198, 198, 198, 199, 169, 199, + 200, 200, 201, 168, 201, 201, 201, 201, 167, 166, + 165, 164, 163, 162, 159, 156, 155, 152, 150, 147, + 145, 144, 133, 132, 128, 123, 122, 111, 106, 105, + 103, 102, 101, 100, 95, 89, 87, 81, 80, 44, + 41, 36, 35, 34, 31, 30, 10, 8, 3, 197, + 197, 197, 197, 197, 197, 197, 197, 197, 197, 197, + + 197, 197, 197, 197, 197, 197, 197, 197, 197, 197, + 197, 197, 197, 197, 197, 197, 197, 197, 197, 197, + 197, 197 + } ; + +static yy_state_type yy_state_buf[YY_BUF_SIZE + 2], *yy_state_ptr; +static char *yy_full_match; +static int yy_lp; +#define REJECT \ +{ \ +*yy_cp = yy_hold_char; /* undo effects of setting up yytext */ \ +yy_cp = yy_full_match; /* restore poss. backed-over text */ \ +++yy_lp; \ +goto find_rule; \ +} +#define yymore() yymore_used_but_not_detected +#define YY_MORE_ADJ 0 +#define YY_RESTORE_YY_MORE_OFFSET +char *yytext; +#line 1 "Lexer.l" +#define INITIAL 0 +/*===-- Lexer.l - Scanner for llvm assembly files ----------------*- C++ -*--=// +// +// This file implements the flex scanner for LLVM assembly languages files. +// +//===------------------------------------------------------------------------=*/ +#define YY_NEVER_INTERACTIVE 1 +#line 21 "Lexer.l" +#include "ParserInternals.h" +#include "llvm/BasicBlock.h" +#include "llvm/Method.h" +#include "llvm/Module.h" +#include <list> +#include "llvmAsmParser.h" + +#define RET_TOK(type, Enum, sym) \ + llvmAsmlval.type = Instruction::Enum; return sym + + +// TODO: All of the static identifiers are figured out by the lexer, +// these should be hashed. + + +// atoull - Convert an ascii string of decimal digits into the unsigned long +// long representation... this does not have to do input error checking, +// because we know that the input will be matched by a suitable regex... +// +uint64_t atoull(const char *Buffer) { + uint64_t Result = 0; + for (; *Buffer; Buffer++) { + uint64_t OldRes = Result; + Result *= 10; + Result += *Buffer-'0'; + if (Result < OldRes) { // Uh, oh, overflow detected!!! + ThrowException("constant bigger than 64 bits detected!"); + } + } + return Result; +} + + +#define YY_NEVER_INTERACTIVE 1 +/* Comments start with a ; and go till end of line */ +/* Variable(Def) identifiers start with a % sign */ +/* Label identifiers end with a colon */ +/* Quoted names can contain any character except " and \ */ +/* [PN]Integer: match positive and negative literal integer values that + * are preceeded by a '%' character. These represent unnamed variable slots. + */ +/* E[PN]Integer: match positive and negative literal integer values */ +#line 618 "Lexer.cpp" + +/* Macros after this point can all be overridden by user definitions in + * section 1. + */ + +#ifndef YY_SKIP_YYWRAP +#ifdef __cplusplus +extern "C" int yywrap YY_PROTO(( void )); +#else +extern int yywrap YY_PROTO(( void )); +#endif +#endif + +#ifndef YY_NO_UNPUT +static inline void yyunput YY_PROTO(( int c, char *buf_ptr )); +#endif + +#ifndef yytext_ptr +static void yy_flex_strncpy YY_PROTO(( char *, yyconst char *, int )); +#endif + +#ifdef YY_NEED_STRLEN +static int yy_flex_strlen YY_PROTO(( yyconst char * )); +#endif + +#ifndef YY_NO_INPUT +#ifdef __cplusplus +static int yyinput YY_PROTO(( void )); +#else +static int input YY_PROTO(( void )); +#endif +#endif + +#if YY_STACK_USED +static int yy_start_stack_ptr = 0; +static int yy_start_stack_depth = 0; +static int *yy_start_stack = 0; +#ifndef YY_NO_PUSH_STATE +static void yy_push_state YY_PROTO(( int new_state )); +#endif +#ifndef YY_NO_POP_STATE +static void yy_pop_state YY_PROTO(( void )); +#endif +#ifndef YY_NO_TOP_STATE +static int yy_top_state YY_PROTO(( void )); +#endif + +#else +#define YY_NO_PUSH_STATE 1 +#define YY_NO_POP_STATE 1 +#define YY_NO_TOP_STATE 1 +#endif + +#ifdef YY_MALLOC_DECL +YY_MALLOC_DECL +#else +#if __STDC__ +#ifndef __cplusplus +#include <stdlib.h> +#endif +#else +/* Just try to get by without declaring the routines. This will fail + * miserably on non-ANSI systems for which sizeof(size_t) != sizeof(int) + * or sizeof(void*) != sizeof(int). + */ +#endif +#endif + +/* Amount of stuff to slurp up with each read. */ +#ifndef YY_READ_BUF_SIZE +#define YY_READ_BUF_SIZE 8192 +#endif + +/* Copy whatever the last rule matched to the standard output. */ + +#ifndef ECHO +/* This used to be an fputs(), but since the string might contain NUL's, + * we now use fwrite(). + */ +#define ECHO (void) fwrite( yytext, yyleng, 1, yyout ) +#endif + +/* Gets input and stuffs it into "buf". number of characters read, or YY_NULL, + * is returned in "result". + */ +#ifndef YY_INPUT +#define YY_INPUT(buf,result,max_size) \ + if ( yy_current_buffer->yy_is_interactive ) \ + { \ + int c = '*', n; \ + for ( n = 0; n < max_size && \ + (c = getc( yyin )) != EOF && c != '\n'; ++n ) \ + buf[n] = (char) c; \ + if ( c == '\n' ) \ + buf[n++] = (char) c; \ + if ( c == EOF && ferror( yyin ) ) \ + YY_FATAL_ERROR( "input in flex scanner failed" ); \ + result = n; \ + } \ + else if ( ((result = fread( buf, 1, max_size, yyin )) == 0) \ + && ferror( yyin ) ) \ + YY_FATAL_ERROR( "input in flex scanner failed" ); +#endif + +/* No semi-colon after return; correct usage is to write "yyterminate();" - + * we don't want an extra ';' after the "return" because that will cause + * some compilers to complain about unreachable statements. + */ +#ifndef yyterminate +#define yyterminate() return YY_NULL +#endif + +/* Number of entries by which start-condition stack grows. */ +#ifndef YY_START_STACK_INCR +#define YY_START_STACK_INCR 25 +#endif + +/* Report a fatal error. */ +#ifndef YY_FATAL_ERROR +#define YY_FATAL_ERROR(msg) yy_fatal_error( msg ) +#endif + +/* Default declaration of generated scanner - a define so the user can + * easily add parameters. + */ +#ifndef YY_DECL +#define YY_DECL int yylex YY_PROTO(( void )) +#endif + +/* Code executed at the beginning of each rule, after yytext and yyleng + * have been set up. + */ +#ifndef YY_USER_ACTION +#define YY_USER_ACTION +#endif + +/* Code executed at the end of each rule. */ +#ifndef YY_BREAK +#define YY_BREAK break; +#endif + +#define YY_RULE_SETUP \ + YY_USER_ACTION + +YY_DECL + { + register yy_state_type yy_current_state; + register char *yy_cp, *yy_bp; + register int yy_act; + +#line 83 "Lexer.l" + + +#line 772 "Lexer.cpp" + + if ( yy_init ) + { + yy_init = 0; + +#ifdef YY_USER_INIT + YY_USER_INIT; +#endif + + if ( ! yy_start ) + yy_start = 1; /* first start state */ + + if ( ! yyin ) + yyin = stdin; + + if ( ! yyout ) + yyout = stdout; + + if ( ! yy_current_buffer ) + yy_current_buffer = + yy_create_buffer( yyin, YY_BUF_SIZE ); + + yy_load_buffer_state(); + } + + while ( 1 ) /* loops until end-of-file is reached */ + { + yy_cp = yy_c_buf_p; + + /* Support of yytext. */ + *yy_cp = yy_hold_char; + + /* yy_bp points to the position in yy_ch_buf of the start of + * the current run. + */ + yy_bp = yy_cp; + + yy_current_state = yy_start; + yy_state_ptr = yy_state_buf; + *yy_state_ptr++ = yy_current_state; +yy_match: + do + { + register YY_CHAR yy_c = yy_ec[YY_SC_TO_UI(*yy_cp)]; + while ( yy_chk[yy_base[yy_current_state] + yy_c] != yy_current_state ) + { + yy_current_state = (int) yy_def[yy_current_state]; + if ( yy_current_state >= 198 ) + yy_c = yy_meta[(unsigned int) yy_c]; + } + yy_current_state = yy_nxt[yy_base[yy_current_state] + (unsigned int) yy_c]; + *yy_state_ptr++ = yy_current_state; + ++yy_cp; + } + while ( yy_current_state != 197 ); + +yy_find_action: + yy_current_state = *--yy_state_ptr; + yy_lp = yy_accept[yy_current_state]; + for ( ; ; ) /* until we find what rule we matched */ + { + if ( yy_lp && yy_lp < yy_accept[yy_current_state + 1] ) + { + yy_act = yy_acclist[yy_lp]; + { + yy_full_match = yy_cp; + break; + } + } + --yy_cp; + yy_current_state = *--yy_state_ptr; + yy_lp = yy_accept[yy_current_state]; + } + + YY_DO_BEFORE_ACTION; + + if ( yy_act != YY_END_OF_BUFFER ) + { + int yyl; + for ( yyl = 0; yyl < yyleng; ++yyl ) + if ( yytext[yyl] == '\n' ) + ++yylineno; + } + +do_action: /* This label is used only to access EOF actions. */ + + + switch ( yy_act ) + { /* beginning of action switch */ +case 1: +YY_RULE_SETUP +#line 85 "Lexer.l" +{ /* Ignore comments for now */ } + YY_BREAK +case 2: +YY_RULE_SETUP +#line 87 "Lexer.l" +{ return BEGINTOK; } + YY_BREAK +case 3: +YY_RULE_SETUP +#line 88 "Lexer.l" +{ return END; } + YY_BREAK +case 4: +YY_RULE_SETUP +#line 89 "Lexer.l" +{ return TRUE; } + YY_BREAK +case 5: +YY_RULE_SETUP +#line 90 "Lexer.l" +{ return FALSE; } + YY_BREAK +case 6: +YY_RULE_SETUP +#line 91 "Lexer.l" +{ return DECLARE; } + YY_BREAK +case 7: +YY_RULE_SETUP +#line 92 "Lexer.l" +{ return IMPLEMENTATION; } + YY_BREAK +case 8: +YY_RULE_SETUP +#line 94 "Lexer.l" +{ cerr << "deprecated argument '-' used!\n"; return '-'; } + YY_BREAK +case 9: +YY_RULE_SETUP +#line 95 "Lexer.l" +{ cerr << "deprecated type 'bb' used!\n"; llvmAsmlval.TypeVal = Type::LabelTy; return LABEL;} + YY_BREAK +case 10: +YY_RULE_SETUP +#line 97 "Lexer.l" +{ llvmAsmlval.TypeVal = Type::VoidTy ; return VOID; } + YY_BREAK +case 11: +YY_RULE_SETUP +#line 98 "Lexer.l" +{ llvmAsmlval.TypeVal = Type::BoolTy ; return BOOL; } + YY_BREAK +case 12: +YY_RULE_SETUP +#line 99 "Lexer.l" +{ llvmAsmlval.TypeVal = Type::SByteTy ; return SBYTE; } + YY_BREAK +case 13: +YY_RULE_SETUP +#line 100 "Lexer.l" +{ llvmAsmlval.TypeVal = Type::UByteTy ; return UBYTE; } + YY_BREAK +case 14: +YY_RULE_SETUP +#line 101 "Lexer.l" +{ llvmAsmlval.TypeVal = Type::ShortTy ; return SHORT; } + YY_BREAK +case 15: +YY_RULE_SETUP +#line 102 "Lexer.l" +{ llvmAsmlval.TypeVal = Type::UShortTy; return USHORT; } + YY_BREAK +case 16: +YY_RULE_SETUP +#line 103 "Lexer.l" +{ llvmAsmlval.TypeVal = Type::IntTy ; return INT; } + YY_BREAK +case 17: +YY_RULE_SETUP +#line 104 "Lexer.l" +{ llvmAsmlval.TypeVal = Type::UIntTy ; return UINT; } + YY_BREAK +case 18: +YY_RULE_SETUP +#line 105 "Lexer.l" +{ llvmAsmlval.TypeVal = Type::LongTy ; return LONG; } + YY_BREAK +case 19: +YY_RULE_SETUP +#line 106 "Lexer.l" +{ llvmAsmlval.TypeVal = Type::ULongTy ; return ULONG; } + YY_BREAK +case 20: +YY_RULE_SETUP +#line 107 "Lexer.l" +{ llvmAsmlval.TypeVal = Type::FloatTy ; return FLOAT; } + YY_BREAK +case 21: +YY_RULE_SETUP +#line 108 "Lexer.l" +{ llvmAsmlval.TypeVal = Type::DoubleTy; return DOUBLE; } + YY_BREAK +case 22: +YY_RULE_SETUP +#line 110 "Lexer.l" +{ llvmAsmlval.TypeVal = Type::TypeTy ; return TYPE; } + YY_BREAK +case 23: +YY_RULE_SETUP +#line 112 "Lexer.l" +{ llvmAsmlval.TypeVal = Type::LabelTy ; return LABEL; } + YY_BREAK +case 24: +YY_RULE_SETUP +#line 114 "Lexer.l" +{ RET_TOK(UnaryOpVal, Neg, NEG); } + YY_BREAK +case 25: +YY_RULE_SETUP +#line 115 "Lexer.l" +{ RET_TOK(UnaryOpVal, Not, NOT); } + YY_BREAK +case 26: +YY_RULE_SETUP +#line 117 "Lexer.l" +{ return PHI; } + YY_BREAK +case 27: +YY_RULE_SETUP +#line 118 "Lexer.l" +{ return CALL; } + YY_BREAK +case 28: +YY_RULE_SETUP +#line 119 "Lexer.l" +{ RET_TOK(BinaryOpVal, Add, ADD); } + YY_BREAK +case 29: +YY_RULE_SETUP +#line 120 "Lexer.l" +{ RET_TOK(BinaryOpVal, Sub, SUB); } + YY_BREAK +case 30: +YY_RULE_SETUP +#line 121 "Lexer.l" +{ RET_TOK(BinaryOpVal, Mul, MUL); } + YY_BREAK +case 31: +YY_RULE_SETUP +#line 122 "Lexer.l" +{ RET_TOK(BinaryOpVal, Div, DIV); } + YY_BREAK +case 32: +YY_RULE_SETUP +#line 123 "Lexer.l" +{ RET_TOK(BinaryOpVal, Rem, REM); } + YY_BREAK +case 33: +YY_RULE_SETUP +#line 124 "Lexer.l" +{ RET_TOK(BinaryOpVal, SetNE, SETNE); } + YY_BREAK +case 34: +YY_RULE_SETUP +#line 125 "Lexer.l" +{ RET_TOK(BinaryOpVal, SetEQ, SETEQ); } + YY_BREAK +case 35: +YY_RULE_SETUP +#line 126 "Lexer.l" +{ RET_TOK(BinaryOpVal, SetLT, SETLT); } + YY_BREAK +case 36: +YY_RULE_SETUP +#line 127 "Lexer.l" +{ RET_TOK(BinaryOpVal, SetGT, SETGT); } + YY_BREAK +case 37: +YY_RULE_SETUP +#line 128 "Lexer.l" +{ RET_TOK(BinaryOpVal, SetLE, SETLE); } + YY_BREAK +case 38: +YY_RULE_SETUP +#line 129 "Lexer.l" +{ RET_TOK(BinaryOpVal, SetGE, SETGE); } + YY_BREAK +case 39: +YY_RULE_SETUP +#line 131 "Lexer.l" +{ RET_TOK(TermOpVal, Ret, RET); } + YY_BREAK +case 40: +YY_RULE_SETUP +#line 132 "Lexer.l" +{ RET_TOK(TermOpVal, Br, BR); } + YY_BREAK +case 41: +YY_RULE_SETUP +#line 133 "Lexer.l" +{ RET_TOK(TermOpVal, Switch, SWITCH); } + YY_BREAK +case 42: +YY_RULE_SETUP +#line 136 "Lexer.l" +{ RET_TOK(MemOpVal, Malloc, MALLOC); } + YY_BREAK +case 43: +YY_RULE_SETUP +#line 137 "Lexer.l" +{ RET_TOK(MemOpVal, Alloca, ALLOCA); } + YY_BREAK +case 44: +YY_RULE_SETUP +#line 138 "Lexer.l" +{ RET_TOK(MemOpVal, Free, FREE); } + YY_BREAK +case 45: +YY_RULE_SETUP +#line 139 "Lexer.l" +{ RET_TOK(MemOpVal, Load, LOAD); } + YY_BREAK +case 46: +YY_RULE_SETUP +#line 140 "Lexer.l" +{ RET_TOK(MemOpVal, Store, STORE); } + YY_BREAK +case 47: +YY_RULE_SETUP +#line 141 "Lexer.l" +{ RET_TOK(MemOpVal, GetField, GETFIELD); } + YY_BREAK +case 48: +YY_RULE_SETUP +#line 142 "Lexer.l" +{ RET_TOK(MemOpVal, PutField, PUTFIELD); } + YY_BREAK +case 49: +YY_RULE_SETUP +#line 145 "Lexer.l" +{ llvmAsmlval.StrVal = strdup(yytext+1); return VAR_ID; } + YY_BREAK +case 50: +YY_RULE_SETUP +#line 146 "Lexer.l" +{ + yytext[strlen(yytext)-1] = 0; // nuke colon + llvmAsmlval.StrVal = strdup(yytext); + return LABELSTR; + } + YY_BREAK +case 51: +YY_RULE_SETUP +#line 152 "Lexer.l" +{ + yytext[strlen(yytext)-1] = 0; // nuke end quote + llvmAsmlval.StrVal = strdup(yytext+1); // Nuke start quote + return STRINGCONSTANT; + } + YY_BREAK +case 52: +YY_RULE_SETUP +#line 159 "Lexer.l" +{ llvmAsmlval.UInt64Val = atoull(yytext); return EUINT64VAL; } + YY_BREAK +case 53: +YY_RULE_SETUP +#line 160 "Lexer.l" +{ + uint64_t Val = atoull(yytext+1); + // +1: we have bigger negative range + if (Val > (uint64_t)INT64_MAX+1) + ThrowException("Constant too large for signed 64 bits!"); + llvmAsmlval.SInt64Val = -Val; + return ESINT64VAL; + } + YY_BREAK +case 54: +YY_RULE_SETUP +#line 170 "Lexer.l" +{ llvmAsmlval.UIntVal = atoull(yytext+1); return UINTVAL; } + YY_BREAK +case 55: +YY_RULE_SETUP +#line 171 "Lexer.l" +{ + uint64_t Val = atoull(yytext+2); + // +1: we have bigger negative range + if (Val > (uint64_t)INT32_MAX+1) + ThrowException("Constant too large for signed 32 bits!"); + llvmAsmlval.SIntVal = -Val; + return SINTVAL; + } + YY_BREAK +case 56: +YY_RULE_SETUP +#line 181 "Lexer.l" +{ /* Ignore whitespace */ } + YY_BREAK +case 57: +YY_RULE_SETUP +#line 182 "Lexer.l" +{ /*printf("'%s'", yytext);*/ return yytext[0]; } + YY_BREAK +case 58: +YY_RULE_SETUP +#line 184 "Lexer.l" +YY_FATAL_ERROR( "flex scanner jammed" ); + YY_BREAK +#line 1175 "Lexer.cpp" + case YY_STATE_EOF(INITIAL): + yyterminate(); + + case YY_END_OF_BUFFER: + { + /* Amount of text matched not including the EOB char. */ + int yy_amount_of_matched_text = (int) (yy_cp - yytext_ptr) - 1; + + /* Undo the effects of YY_DO_BEFORE_ACTION. */ + *yy_cp = yy_hold_char; + YY_RESTORE_YY_MORE_OFFSET + + if ( yy_current_buffer->yy_buffer_status == YY_BUFFER_NEW ) + { + /* We're scanning a new file or input source. It's + * possible that this happened because the user + * just pointed yyin at a new source and called + * yylex(). If so, then we have to assure + * consistency between yy_current_buffer and our + * globals. Here is the right place to do so, because + * this is the first action (other than possibly a + * back-up) that will match for the new input source. + */ + yy_n_chars = yy_current_buffer->yy_n_chars; + yy_current_buffer->yy_input_file = yyin; + yy_current_buffer->yy_buffer_status = YY_BUFFER_NORMAL; + } + + /* Note that here we test for yy_c_buf_p "<=" to the position + * of the first EOB in the buffer, since yy_c_buf_p will + * already have been incremented past the NUL character + * (since all states make transitions on EOB to the + * end-of-buffer state). Contrast this with the test + * in input(). + */ + if ( yy_c_buf_p <= &yy_current_buffer->yy_ch_buf[yy_n_chars] ) + { /* This was really a NUL. */ + yy_state_type yy_next_state; + + yy_c_buf_p = yytext_ptr + yy_amount_of_matched_text; + + yy_current_state = yy_get_previous_state(); + + /* Okay, we're now positioned to make the NUL + * transition. We couldn't have + * yy_get_previous_state() go ahead and do it + * for us because it doesn't know how to deal + * with the possibility of jamming (and we don't + * want to build jamming into it because then it + * will run more slowly). + */ + + yy_next_state = yy_try_NUL_trans( yy_current_state ); + + yy_bp = yytext_ptr + YY_MORE_ADJ; + + if ( yy_next_state ) + { + /* Consume the NUL. */ + yy_cp = ++yy_c_buf_p; + yy_current_state = yy_next_state; + goto yy_match; + } + + else + { + yy_cp = yy_c_buf_p; + goto yy_find_action; + } + } + + else switch ( yy_get_next_buffer() ) + { + case EOB_ACT_END_OF_FILE: + { + yy_did_buffer_switch_on_eof = 0; + + if ( yywrap() ) + { + /* Note: because we've taken care in + * yy_get_next_buffer() to have set up + * yytext, we can now set up + * yy_c_buf_p so that if some total + * hoser (like flex itself) wants to + * call the scanner after we return the + * YY_NULL, it'll still work - another + * YY_NULL will get returned. + */ + yy_c_buf_p = yytext_ptr + YY_MORE_ADJ; + + yy_act = YY_STATE_EOF(YY_START); + goto do_action; + } + + else + { + if ( ! yy_did_buffer_switch_on_eof ) + YY_NEW_FILE; + } + break; + } + + case EOB_ACT_CONTINUE_SCAN: + yy_c_buf_p = + yytext_ptr + yy_amount_of_matched_text; + + yy_current_state = yy_get_previous_state(); + + yy_cp = yy_c_buf_p; + yy_bp = yytext_ptr + YY_MORE_ADJ; + goto yy_match; + + case EOB_ACT_LAST_MATCH: + yy_c_buf_p = + &yy_current_buffer->yy_ch_buf[yy_n_chars]; + + yy_current_state = yy_get_previous_state(); + + yy_cp = yy_c_buf_p; + yy_bp = yytext_ptr + YY_MORE_ADJ; + goto yy_find_action; + } + break; + } + + default: + YY_FATAL_ERROR( + "fatal flex scanner internal error--no action found" ); + } /* end of action switch */ + } /* end of scanning one token */ + } /* end of yylex */ + + +/* yy_get_next_buffer - try to read in a new buffer + * + * Returns a code representing an action: + * EOB_ACT_LAST_MATCH - + * EOB_ACT_CONTINUE_SCAN - continue scanning from current position + * EOB_ACT_END_OF_FILE - end of file + */ + +static int yy_get_next_buffer() + { + register char *dest = yy_current_buffer->yy_ch_buf; + register char *source = yytext_ptr; + register int number_to_move, i; + int ret_val; + + if ( yy_c_buf_p > &yy_current_buffer->yy_ch_buf[yy_n_chars + 1] ) + YY_FATAL_ERROR( + "fatal flex scanner internal error--end of buffer missed" ); + + if ( yy_current_buffer->yy_fill_buffer == 0 ) + { /* Don't try to fill the buffer, so this is an EOF. */ + if ( yy_c_buf_p - yytext_ptr - YY_MORE_ADJ == 1 ) + { + /* We matched a single character, the EOB, so + * treat this as a final EOF. + */ + return EOB_ACT_END_OF_FILE; + } + + else + { + /* We matched some text prior to the EOB, first + * process it. + */ + return EOB_ACT_LAST_MATCH; + } + } + + /* Try to read more data. */ + + /* First move last chars to start of buffer. */ + number_to_move = (int) (yy_c_buf_p - yytext_ptr) - 1; + + for ( i = 0; i < number_to_move; ++i ) + *(dest++) = *(source++); + + if ( yy_current_buffer->yy_buffer_status == YY_BUFFER_EOF_PENDING ) + /* don't do the read, it's not guaranteed to return an EOF, + * just force an EOF + */ + yy_current_buffer->yy_n_chars = yy_n_chars = 0; + + else + { + int num_to_read = + yy_current_buffer->yy_buf_size - number_to_move - 1; + + while ( num_to_read <= 0 ) + { /* Not enough room in the buffer - grow it. */ +#ifdef YY_USES_REJECT + YY_FATAL_ERROR( +"input buffer overflow, can't enlarge buffer because scanner uses REJECT" ); +#else + + /* just a shorter name for the current buffer */ + YY_BUFFER_STATE b = yy_current_buffer; + + int yy_c_buf_p_offset = + (int) (yy_c_buf_p - b->yy_ch_buf); + + if ( b->yy_is_our_buffer ) + { + int new_size = b->yy_buf_size * 2; + + if ( new_size <= 0 ) + b->yy_buf_size += b->yy_buf_size / 8; + else + b->yy_buf_size *= 2; + + b->yy_ch_buf = (char *) + /* Include room in for 2 EOB chars. */ + yy_flex_realloc( (void *) b->yy_ch_buf, + b->yy_buf_size + 2 ); + } + else + /* Can't grow it, we don't own it. */ + b->yy_ch_buf = 0; + + if ( ! b->yy_ch_buf ) + YY_FATAL_ERROR( + "fatal error - scanner input buffer overflow" ); + + yy_c_buf_p = &b->yy_ch_buf[yy_c_buf_p_offset]; + + num_to_read = yy_current_buffer->yy_buf_size - + number_to_move - 1; +#endif + } + + if ( num_to_read > YY_READ_BUF_SIZE ) + num_to_read = YY_READ_BUF_SIZE; + + /* Read in more data. */ + YY_INPUT( (&yy_current_buffer->yy_ch_buf[number_to_move]), + yy_n_chars, num_to_read ); + + yy_current_buffer->yy_n_chars = yy_n_chars; + } + + if ( yy_n_chars == 0 ) + { + if ( number_to_move == YY_MORE_ADJ ) + { + ret_val = EOB_ACT_END_OF_FILE; + yyrestart( yyin ); + } + + else + { + ret_val = EOB_ACT_LAST_MATCH; + yy_current_buffer->yy_buffer_status = + YY_BUFFER_EOF_PENDING; + } + } + + else + ret_val = EOB_ACT_CONTINUE_SCAN; + + yy_n_chars += number_to_move; + yy_current_buffer->yy_ch_buf[yy_n_chars] = YY_END_OF_BUFFER_CHAR; + yy_current_buffer->yy_ch_buf[yy_n_chars + 1] = YY_END_OF_BUFFER_CHAR; + + yytext_ptr = &yy_current_buffer->yy_ch_buf[0]; + + return ret_val; + } + + +/* yy_get_previous_state - get the state just before the EOB char was reached */ + +static yy_state_type yy_get_previous_state() + { + register yy_state_type yy_current_state; + register char *yy_cp; + + yy_current_state = yy_start; + yy_state_ptr = yy_state_buf; + *yy_state_ptr++ = yy_current_state; + + for ( yy_cp = yytext_ptr + YY_MORE_ADJ; yy_cp < yy_c_buf_p; ++yy_cp ) + { + register YY_CHAR yy_c = (*yy_cp ? yy_ec[YY_SC_TO_UI(*yy_cp)] : 1); + while ( yy_chk[yy_base[yy_current_state] + yy_c] != yy_current_state ) + { + yy_current_state = (int) yy_def[yy_current_state]; + if ( yy_current_state >= 198 ) + yy_c = yy_meta[(unsigned int) yy_c]; + } + yy_current_state = yy_nxt[yy_base[yy_current_state] + (unsigned int) yy_c]; + *yy_state_ptr++ = yy_current_state; + } + + return yy_current_state; + } + + +/* yy_try_NUL_trans - try to make a transition on the NUL character + * + * synopsis + * next_state = yy_try_NUL_trans( current_state ); + */ + +#ifdef YY_USE_PROTOS +static yy_state_type yy_try_NUL_trans( yy_state_type yy_current_state ) +#else +static yy_state_type yy_try_NUL_trans( yy_current_state ) +yy_state_type yy_current_state; +#endif + { + register int yy_is_jam; + + register YY_CHAR yy_c = 1; + while ( yy_chk[yy_base[yy_current_state] + yy_c] != yy_current_state ) + { + yy_current_state = (int) yy_def[yy_current_state]; + if ( yy_current_state >= 198 ) + yy_c = yy_meta[(unsigned int) yy_c]; + } + yy_current_state = yy_nxt[yy_base[yy_current_state] + (unsigned int) yy_c]; + yy_is_jam = (yy_current_state == 197); + if ( ! yy_is_jam ) + *yy_state_ptr++ = yy_current_state; + + return yy_is_jam ? 0 : yy_current_state; + } + + +#ifndef YY_NO_UNPUT +#ifdef YY_USE_PROTOS +static inline void yyunput( int c, register char *yy_bp ) +#else +static inline void yyunput( c, yy_bp ) +int c; +register char *yy_bp; +#endif + { + register char *yy_cp = yy_c_buf_p; + + /* undo effects of setting up yytext */ + *yy_cp = yy_hold_char; + + if ( yy_cp < yy_current_buffer->yy_ch_buf + 2 ) + { /* need to shift things up to make room */ + /* +2 for EOB chars. */ + register int number_to_move = yy_n_chars + 2; + register char *dest = &yy_current_buffer->yy_ch_buf[ + yy_current_buffer->yy_buf_size + 2]; + register char *source = + &yy_current_buffer->yy_ch_buf[number_to_move]; + + while ( source > yy_current_buffer->yy_ch_buf ) + *--dest = *--source; + + yy_cp += (int) (dest - source); + yy_bp += (int) (dest - source); + yy_current_buffer->yy_n_chars = + yy_n_chars = yy_current_buffer->yy_buf_size; + + if ( yy_cp < yy_current_buffer->yy_ch_buf + 2 ) + YY_FATAL_ERROR( "flex scanner push-back overflow" ); + } + + *--yy_cp = (char) c; + + if ( c == '\n' ) + --yylineno; + + yytext_ptr = yy_bp; + yy_hold_char = *yy_cp; + yy_c_buf_p = yy_cp; + } +#endif /* ifndef YY_NO_UNPUT */ + + +#ifdef __cplusplus +static int yyinput() +#else +static int input() +#endif + { + int c; + + *yy_c_buf_p = yy_hold_char; + + if ( *yy_c_buf_p == YY_END_OF_BUFFER_CHAR ) + { + /* yy_c_buf_p now points to the character we want to return. + * If this occurs *before* the EOB characters, then it's a + * valid NUL; if not, then we've hit the end of the buffer. + */ + if ( yy_c_buf_p < &yy_current_buffer->yy_ch_buf[yy_n_chars] ) + /* This was really a NUL. */ + *yy_c_buf_p = '\0'; + + else + { /* need more input */ + int offset = yy_c_buf_p - yytext_ptr; + ++yy_c_buf_p; + + switch ( yy_get_next_buffer() ) + { + case EOB_ACT_LAST_MATCH: + /* This happens because yy_g_n_b() + * sees that we've accumulated a + * token and flags that we need to + * try matching the token before + * proceeding. But for input(), + * there's no matching to consider. + * So convert the EOB_ACT_LAST_MATCH + * to EOB_ACT_END_OF_FILE. + */ + + /* Reset buffer status. */ + yyrestart( yyin ); + + /* fall through */ + + case EOB_ACT_END_OF_FILE: + { + if ( yywrap() ) + return EOF; + + if ( ! yy_did_buffer_switch_on_eof ) + YY_NEW_FILE; +#ifdef __cplusplus + return yyinput(); +#else + return input(); +#endif + } + + case EOB_ACT_CONTINUE_SCAN: + yy_c_buf_p = yytext_ptr + offset; + break; + } + } + } + + c = *(unsigned char *) yy_c_buf_p; /* cast for 8-bit char's */ + *yy_c_buf_p = '\0'; /* preserve yytext */ + yy_hold_char = *++yy_c_buf_p; + + if ( c == '\n' ) + ++yylineno; + + return c; + } + + +#ifdef YY_USE_PROTOS +void yyrestart( FILE *input_file ) +#else +void yyrestart( input_file ) +FILE *input_file; +#endif + { + if ( ! yy_current_buffer ) + yy_current_buffer = yy_create_buffer( yyin, YY_BUF_SIZE ); + + yy_init_buffer( yy_current_buffer, input_file ); + yy_load_buffer_state(); + } + + +#ifdef YY_USE_PROTOS +void yy_switch_to_buffer( YY_BUFFER_STATE new_buffer ) +#else +void yy_switch_to_buffer( new_buffer ) +YY_BUFFER_STATE new_buffer; +#endif + { + if ( yy_current_buffer == new_buffer ) + return; + + if ( yy_current_buffer ) + { + /* Flush out information for old buffer. */ + *yy_c_buf_p = yy_hold_char; + yy_current_buffer->yy_buf_pos = yy_c_buf_p; + yy_current_buffer->yy_n_chars = yy_n_chars; + } + + yy_current_buffer = new_buffer; + yy_load_buffer_state(); + + /* We don't actually know whether we did this switch during + * EOF (yywrap()) processing, but the only time this flag + * is looked at is after yywrap() is called, so it's safe + * to go ahead and always set it. + */ + yy_did_buffer_switch_on_eof = 1; + } + + +#ifdef YY_USE_PROTOS +void yy_load_buffer_state( void ) +#else +void yy_load_buffer_state() +#endif + { + yy_n_chars = yy_current_buffer->yy_n_chars; + yytext_ptr = yy_c_buf_p = yy_current_buffer->yy_buf_pos; + yyin = yy_current_buffer->yy_input_file; + yy_hold_char = *yy_c_buf_p; + } + + +#ifdef YY_USE_PROTOS +YY_BUFFER_STATE yy_create_buffer( FILE *file, int size ) +#else +YY_BUFFER_STATE yy_create_buffer( file, size ) +FILE *file; +int size; +#endif + { + YY_BUFFER_STATE b; + + b = (YY_BUFFER_STATE) yy_flex_alloc( sizeof( struct yy_buffer_state ) ); + if ( ! b ) + YY_FATAL_ERROR( "out of dynamic memory in yy_create_buffer()" ); + + b->yy_buf_size = size; + + /* yy_ch_buf has to be 2 characters longer than the size given because + * we need to put in 2 end-of-buffer characters. + */ + b->yy_ch_buf = (char *) yy_flex_alloc( b->yy_buf_size + 2 ); + if ( ! b->yy_ch_buf ) + YY_FATAL_ERROR( "out of dynamic memory in yy_create_buffer()" ); + + b->yy_is_our_buffer = 1; + + yy_init_buffer( b, file ); + + return b; + } + + +#ifdef YY_USE_PROTOS +void yy_delete_buffer( YY_BUFFER_STATE b ) +#else +void yy_delete_buffer( b ) +YY_BUFFER_STATE b; +#endif + { + if ( ! b ) + return; + + if ( b == yy_current_buffer ) + yy_current_buffer = (YY_BUFFER_STATE) 0; + + if ( b->yy_is_our_buffer ) + yy_flex_free( (void *) b->yy_ch_buf ); + + yy_flex_free( (void *) b ); + } + + +#ifndef YY_ALWAYS_INTERACTIVE +#ifndef YY_NEVER_INTERACTIVE +extern int isatty YY_PROTO(( int )); +#endif +#endif + +#ifdef YY_USE_PROTOS +void yy_init_buffer( YY_BUFFER_STATE b, FILE *file ) +#else +void yy_init_buffer( b, file ) +YY_BUFFER_STATE b; +FILE *file; +#endif + + + { + yy_flush_buffer( b ); + + b->yy_input_file = file; + b->yy_fill_buffer = 1; + +#if YY_ALWAYS_INTERACTIVE + b->yy_is_interactive = 1; +#else +#if YY_NEVER_INTERACTIVE + b->yy_is_interactive = 0; +#else + b->yy_is_interactive = file ? (isatty( fileno(file) ) > 0) : 0; +#endif +#endif + } + + +#ifdef YY_USE_PROTOS +void yy_flush_buffer( YY_BUFFER_STATE b ) +#else +void yy_flush_buffer( b ) +YY_BUFFER_STATE b; +#endif + + { + if ( ! b ) + return; + + b->yy_n_chars = 0; + + /* We always need two end-of-buffer characters. The first causes + * a transition to the end-of-buffer state. The second causes + * a jam in that state. + */ + b->yy_ch_buf[0] = YY_END_OF_BUFFER_CHAR; + b->yy_ch_buf[1] = YY_END_OF_BUFFER_CHAR; + + b->yy_buf_pos = &b->yy_ch_buf[0]; + + b->yy_at_bol = 1; + b->yy_buffer_status = YY_BUFFER_NEW; + + if ( b == yy_current_buffer ) + yy_load_buffer_state(); + } + + +#ifndef YY_NO_SCAN_BUFFER +#ifdef YY_USE_PROTOS +YY_BUFFER_STATE yy_scan_buffer( char *base, yy_size_t size ) +#else +YY_BUFFER_STATE yy_scan_buffer( base, size ) +char *base; +yy_size_t size; +#endif + { + YY_BUFFER_STATE b; + + if ( size < 2 || + base[size-2] != YY_END_OF_BUFFER_CHAR || + base[size-1] != YY_END_OF_BUFFER_CHAR ) + /* They forgot to leave room for the EOB's. */ + return 0; + + b = (YY_BUFFER_STATE) yy_flex_alloc( sizeof( struct yy_buffer_state ) ); + if ( ! b ) + YY_FATAL_ERROR( "out of dynamic memory in yy_scan_buffer()" ); + + b->yy_buf_size = size - 2; /* "- 2" to take care of EOB's */ + b->yy_buf_pos = b->yy_ch_buf = base; + b->yy_is_our_buffer = 0; + b->yy_input_file = 0; + b->yy_n_chars = b->yy_buf_size; + b->yy_is_interactive = 0; + b->yy_at_bol = 1; + b->yy_fill_buffer = 0; + b->yy_buffer_status = YY_BUFFER_NEW; + + yy_switch_to_buffer( b ); + + return b; + } +#endif + + +#ifndef YY_NO_SCAN_STRING +#ifdef YY_USE_PROTOS +YY_BUFFER_STATE yy_scan_string( yyconst char *yy_str ) +#else +YY_BUFFER_STATE yy_scan_string( yy_str ) +yyconst char *yy_str; +#endif + { + int len; + for ( len = 0; yy_str[len]; ++len ) + ; + + return yy_scan_bytes( yy_str, len ); + } +#endif + + +#ifndef YY_NO_SCAN_BYTES +#ifdef YY_USE_PROTOS +YY_BUFFER_STATE yy_scan_bytes( yyconst char *bytes, int len ) +#else +YY_BUFFER_STATE yy_scan_bytes( bytes, len ) +yyconst char *bytes; +int len; +#endif + { + YY_BUFFER_STATE b; + char *buf; + yy_size_t n; + int i; + + /* Get memory for full buffer, including space for trailing EOB's. */ + n = len + 2; + buf = (char *) yy_flex_alloc( n ); + if ( ! buf ) + YY_FATAL_ERROR( "out of dynamic memory in yy_scan_bytes()" ); + + for ( i = 0; i < len; ++i ) + buf[i] = bytes[i]; + + buf[len] = buf[len+1] = YY_END_OF_BUFFER_CHAR; + + b = yy_scan_buffer( buf, n ); + if ( ! b ) + YY_FATAL_ERROR( "bad buffer in yy_scan_bytes()" ); + + /* It's okay to grow etc. this buffer, and we should throw it + * away when we're done. + */ + b->yy_is_our_buffer = 1; + + return b; + } +#endif + + +#ifndef YY_NO_PUSH_STATE +#ifdef YY_USE_PROTOS +static void yy_push_state( int new_state ) +#else +static void yy_push_state( new_state ) +int new_state; +#endif + { + if ( yy_start_stack_ptr >= yy_start_stack_depth ) + { + yy_size_t new_size; + + yy_start_stack_depth += YY_START_STACK_INCR; + new_size = yy_start_stack_depth * sizeof( int ); + + if ( ! yy_start_stack ) + yy_start_stack = (int *) yy_flex_alloc( new_size ); + + else + yy_start_stack = (int *) yy_flex_realloc( + (void *) yy_start_stack, new_size ); + + if ( ! yy_start_stack ) + YY_FATAL_ERROR( + "out of memory expanding start-condition stack" ); + } + + yy_start_stack[yy_start_stack_ptr++] = YY_START; + + BEGIN(new_state); + } +#endif + + +#ifndef YY_NO_POP_STATE +static void yy_pop_state() + { + if ( --yy_start_stack_ptr < 0 ) + YY_FATAL_ERROR( "start-condition stack underflow" ); + + BEGIN(yy_start_stack[yy_start_stack_ptr]); + } +#endif + + +#ifndef YY_NO_TOP_STATE +static int yy_top_state() + { + return yy_start_stack[yy_start_stack_ptr - 1]; + } +#endif + +#ifndef YY_EXIT_FAILURE +#define YY_EXIT_FAILURE 2 +#endif + +#ifdef YY_USE_PROTOS +static void yy_fatal_error( yyconst char msg[] ) +#else +static void yy_fatal_error( msg ) +char msg[]; +#endif + { + (void) fprintf( stderr, "%s\n", msg ); + exit( YY_EXIT_FAILURE ); + } + + + +/* Redefine yyless() so it works in section 3 code. */ + +#undef yyless +#define yyless(n) \ + do \ + { \ + /* Undo effects of setting up yytext. */ \ + yytext[yyleng] = yy_hold_char; \ + yy_c_buf_p = yytext + n; \ + yy_hold_char = *yy_c_buf_p; \ + *yy_c_buf_p = '\0'; \ + yyleng = n; \ + } \ + while ( 0 ) + + +/* Internal utility routines. */ + +#ifndef yytext_ptr +#ifdef YY_USE_PROTOS +static void yy_flex_strncpy( char *s1, yyconst char *s2, int n ) +#else +static void yy_flex_strncpy( s1, s2, n ) +char *s1; +yyconst char *s2; +int n; +#endif + { + register int i; + for ( i = 0; i < n; ++i ) + s1[i] = s2[i]; + } +#endif + +#ifdef YY_NEED_STRLEN +#ifdef YY_USE_PROTOS +static int yy_flex_strlen( yyconst char *s ) +#else +static int yy_flex_strlen( s ) +yyconst char *s; +#endif + { + register int n; + for ( n = 0; s[n]; ++n ) + ; + + return n; + } +#endif + + +#ifdef YY_USE_PROTOS +static void *yy_flex_alloc( yy_size_t size ) +#else +static void *yy_flex_alloc( size ) +yy_size_t size; +#endif + { + return (void *) malloc( size ); + } + +#ifdef YY_USE_PROTOS +static inline void *yy_flex_realloc( void *ptr, yy_size_t size ) +#else +static inline void *yy_flex_realloc( ptr, size ) +void *ptr; +yy_size_t size; +#endif + { + /* The cast to (char *) in the following accommodates both + * implementations that use char* generic pointers, and those + * that use void* generic pointers. It works with the latter + * because both ANSI C and C++ allow castless assignment from + * any pointer type to void*, and deal with argument conversions + * as though doing an assignment. + */ + return (void *) realloc( (char *) ptr, size ); + } + +#ifdef YY_USE_PROTOS +static void yy_flex_free( void *ptr ) +#else +static void yy_flex_free( ptr ) +void *ptr; +#endif + { + free( ptr ); + } + +#if YY_MAIN +int main() + { + yylex(); + return 0; + } +#endif +#line 184 "Lexer.l" + diff --git a/lib/AsmParser/Lexer.l b/lib/AsmParser/Lexer.l new file mode 100644 index 0000000..89d776b --- /dev/null +++ b/lib/AsmParser/Lexer.l @@ -0,0 +1,184 @@ +/*===-- Lexer.l - Scanner for llvm assembly files ----------------*- C++ -*--=// +// +// This file implements the flex scanner for LLVM assembly languages files. +// +//===------------------------------------------------------------------------=*/ + +%option prefix="llvmAsm" +%option yylineno +%option nostdinit +%option never-interactive +%option batch +%option noyywrap +%option nodefault +%option 8bit +%option outfile="Lexer.cpp" +%option ecs +%option noreject +%option noyymore + +%{ +#include "ParserInternals.h" +#include "llvm/BasicBlock.h" +#include "llvm/Method.h" +#include "llvm/Module.h" +#include <list> +#include "llvmAsmParser.h" + +#define RET_TOK(type, Enum, sym) \ + llvmAsmlval.type = Instruction::Enum; return sym + + +// TODO: All of the static identifiers are figured out by the lexer, +// these should be hashed. + + +// atoull - Convert an ascii string of decimal digits into the unsigned long +// long representation... this does not have to do input error checking, +// because we know that the input will be matched by a suitable regex... +// +uint64_t atoull(const char *Buffer) { + uint64_t Result = 0; + for (; *Buffer; Buffer++) { + uint64_t OldRes = Result; + Result *= 10; + Result += *Buffer-'0'; + if (Result < OldRes) { // Uh, oh, overflow detected!!! + ThrowException("constant bigger than 64 bits detected!"); + } + } + return Result; +} + + +#define YY_NEVER_INTERACTIVE 1 +%} + + + +/* Comments start with a ; and go till end of line */ +Comment ;.* + +/* Variable(Def) identifiers start with a % sign */ +VarID %[a-zA-Z$._][a-zA-Z$._0-9]* + +/* Label identifiers end with a colon */ +Label [a-zA-Z$._0-9]+: + +/* Quoted names can contain any character except " and \ */ +StringConstant \"[^\"]+\" + + +/* [PN]Integer: match positive and negative literal integer values that + * are preceeded by a '%' character. These represent unnamed variable slots. + */ +EPInteger %[0-9]+ +ENInteger %-[0-9]+ + + +/* E[PN]Integer: match positive and negative literal integer values */ +PInteger [0-9]+ +NInteger -[0-9]+ + +%% + +{Comment} { /* Ignore comments for now */ } + +begin { return BEGINTOK; } +end { return END; } +true { return TRUE; } +false { return FALSE; } +declare { return DECLARE; } +implementation { return IMPLEMENTATION; } + +- { cerr << "deprecated argument '-' used!\n"; return '-'; } +bb { cerr << "deprecated type 'bb' used!\n"; llvmAsmlval.TypeVal = Type::LabelTy; return LABEL;} + +void { llvmAsmlval.TypeVal = Type::VoidTy ; return VOID; } +bool { llvmAsmlval.TypeVal = Type::BoolTy ; return BOOL; } +sbyte { llvmAsmlval.TypeVal = Type::SByteTy ; return SBYTE; } +ubyte { llvmAsmlval.TypeVal = Type::UByteTy ; return UBYTE; } +short { llvmAsmlval.TypeVal = Type::ShortTy ; return SHORT; } +ushort { llvmAsmlval.TypeVal = Type::UShortTy; return USHORT; } +int { llvmAsmlval.TypeVal = Type::IntTy ; return INT; } +uint { llvmAsmlval.TypeVal = Type::UIntTy ; return UINT; } +long { llvmAsmlval.TypeVal = Type::LongTy ; return LONG; } +ulong { llvmAsmlval.TypeVal = Type::ULongTy ; return ULONG; } +float { llvmAsmlval.TypeVal = Type::FloatTy ; return FLOAT; } +double { llvmAsmlval.TypeVal = Type::DoubleTy; return DOUBLE; } + +type { llvmAsmlval.TypeVal = Type::TypeTy ; return TYPE; } + +label { llvmAsmlval.TypeVal = Type::LabelTy ; return LABEL; } + +neg { RET_TOK(UnaryOpVal, Neg, NEG); } +not { RET_TOK(UnaryOpVal, Not, NOT); } + +phi { return PHI; } +call { return CALL; } +add { RET_TOK(BinaryOpVal, Add, ADD); } +sub { RET_TOK(BinaryOpVal, Sub, SUB); } +mul { RET_TOK(BinaryOpVal, Mul, MUL); } +div { RET_TOK(BinaryOpVal, Div, DIV); } +rem { RET_TOK(BinaryOpVal, Rem, REM); } +setne { RET_TOK(BinaryOpVal, SetNE, SETNE); } +seteq { RET_TOK(BinaryOpVal, SetEQ, SETEQ); } +setlt { RET_TOK(BinaryOpVal, SetLT, SETLT); } +setgt { RET_TOK(BinaryOpVal, SetGT, SETGT); } +setle { RET_TOK(BinaryOpVal, SetLE, SETLE); } +setge { RET_TOK(BinaryOpVal, SetGE, SETGE); } + +ret { RET_TOK(TermOpVal, Ret, RET); } +br { RET_TOK(TermOpVal, Br, BR); } +switch { RET_TOK(TermOpVal, Switch, SWITCH); } + + +malloc { RET_TOK(MemOpVal, Malloc, MALLOC); } +alloca { RET_TOK(MemOpVal, Alloca, ALLOCA); } +free { RET_TOK(MemOpVal, Free, FREE); } +load { RET_TOK(MemOpVal, Load, LOAD); } +store { RET_TOK(MemOpVal, Store, STORE); } +getfield { RET_TOK(MemOpVal, GetField, GETFIELD); } +putfield { RET_TOK(MemOpVal, PutField, PUTFIELD); } + + +{VarID} { llvmAsmlval.StrVal = strdup(yytext+1); return VAR_ID; } +{Label} { + yytext[strlen(yytext)-1] = 0; // nuke colon + llvmAsmlval.StrVal = strdup(yytext); + return LABELSTR; + } + +{StringConstant} { + yytext[strlen(yytext)-1] = 0; // nuke end quote + llvmAsmlval.StrVal = strdup(yytext+1); // Nuke start quote + return STRINGCONSTANT; + } + + +{PInteger} { llvmAsmlval.UInt64Val = atoull(yytext); return EUINT64VAL; } +{NInteger} { + uint64_t Val = atoull(yytext+1); + // +1: we have bigger negative range + if (Val > (uint64_t)INT64_MAX+1) + ThrowException("Constant too large for signed 64 bits!"); + llvmAsmlval.SInt64Val = -Val; + return ESINT64VAL; + } + + +{EPInteger} { llvmAsmlval.UIntVal = atoull(yytext+1); return UINTVAL; } +{ENInteger} { + uint64_t Val = atoull(yytext+2); + // +1: we have bigger negative range + if (Val > (uint64_t)INT32_MAX+1) + ThrowException("Constant too large for signed 32 bits!"); + llvmAsmlval.SIntVal = -Val; + return SINTVAL; + } + + +[ \t\n] { /* Ignore whitespace */ } +. { /*printf("'%s'", yytext);*/ return yytext[0]; } + +%% diff --git a/lib/AsmParser/Makefile b/lib/AsmParser/Makefile new file mode 100644 index 0000000..5bec1f4 --- /dev/null +++ b/lib/AsmParser/Makefile @@ -0,0 +1,7 @@ + +LEVEL = ../../.. + +LIBRARYNAME = asmparser + +include $(LEVEL)/Makefile.common + diff --git a/lib/AsmParser/Parser.cpp b/lib/AsmParser/Parser.cpp new file mode 100644 index 0000000..57c831e --- /dev/null +++ b/lib/AsmParser/Parser.cpp @@ -0,0 +1,84 @@ +//===- Parser.cpp - Main dispatch module for the Parser library -------------=== +// +// This library implements the functionality defined in llvm/assembly/parser.h +// +//===------------------------------------------------------------------------=== + +#include "llvm/Analysis/Verifier.h" +#include "llvm/Module.h" +#include "ParserInternals.h" +#include <stdio.h> // for sprintf + +// The useful interface defined by this file... Parse an ascii file, and return +// the internal representation in a nice slice'n'dice'able representation. +// +Module *ParseAssemblyFile(const ToolCommandLine &Opts) throw (ParseException) { + FILE *F = stdin; + + if (Opts.getInputFilename() != "-") + F = fopen(Opts.getInputFilename().c_str(), "r"); + + if (F == 0) { + throw ParseException(Opts, string("Could not open file '") + + Opts.getInputFilename() + "'"); + } + + // TODO: If this throws an exception, F is not closed. + Module *Result = RunVMAsmParser(Opts, F); + + if (F != stdin) + fclose(F); + + if (Result) { // Check to see that it is valid... + vector<string> Errors; + if (verify(Result, Errors)) { + delete Result; Result = 0; + string Message; + + for (unsigned i = 0; i < Errors.size(); i++) + Message += Errors[i] + "\n"; + + throw ParseException(Opts, Message); + } + } + return Result; +} + + +//===------------------------------------------------------------------------=== +// ParseException Class +//===------------------------------------------------------------------------=== + + +ParseException::ParseException(const ToolCommandLine &opts, + const string &message, int lineNo, int colNo) + : Opts(opts), Message(message) { + LineNo = lineNo; ColumnNo = colNo; +} + +ParseException::ParseException(const ParseException &E) + : Opts(E.Opts), Message(E.Message) { + LineNo = E.LineNo; + ColumnNo = E.ColumnNo; +} + +const string ParseException::getMessage() const { // Includes info from options + string Result; + char Buffer[10]; + + if (Opts.getInputFilename() == "-") + Result += "<stdin>"; + else + Result += Opts.getInputFilename(); + + if (LineNo != -1) { + sprintf(Buffer, "%d", LineNo); + Result += string(":") + Buffer; + if (ColumnNo != -1) { + sprintf(Buffer, "%d", ColumnNo); + Result += string(",") + Buffer; + } + } + + return Result + ": " + Message; +} diff --git a/lib/AsmParser/ParserInternals.h b/lib/AsmParser/ParserInternals.h new file mode 100644 index 0000000..2856c9b --- /dev/null +++ b/lib/AsmParser/ParserInternals.h @@ -0,0 +1,159 @@ +//===-- ParserInternals.h - Definitions internal to the parser ---*- C++ -*--=// +// +// This header file defines the various variables that are shared among the +// different components of the parser... +// +//===----------------------------------------------------------------------===// + +#ifndef PARSER_INTERNALS_H +#define PARSER_INTERNALS_H + +#include <stdio.h> +#define __STDC_LIMIT_MACROS + +#include "llvm/InstrTypes.h" +#include "llvm/BasicBlock.h" +#include "llvm/ConstPoolVals.h" +#include "llvm/iOther.h" +#include "llvm/Method.h" +#include "llvm/Type.h" +#include "llvm/Assembly/Parser.h" +#include "llvm/Tools/CommandLine.h" +#include "llvm/Tools/StringExtras.h" + +class Module; + +// Global variables exported from the lexer... +extern FILE *llvmAsmin; +extern int llvmAsmlineno; + +// Globals exported by the parser... +extern const ToolCommandLine *CurOptions; +Module *RunVMAsmParser(const ToolCommandLine &Opts, FILE *F); + + +// ThrowException - Wrapper around the ParseException class that automatically +// fills in file line number and column number and options info. +// +// This also helps me because I keep typing 'throw new ParseException' instead +// of just 'throw ParseException'... sigh... +// +static inline void ThrowException(const string &message) { + // TODO: column number in exception + throw ParseException(*CurOptions, message, llvmAsmlineno); +} + +// ValID - Represents a reference of a definition of some sort. This may either +// be a numeric reference or a symbolic (%var) reference. This is just a +// discriminated union. +// +// Note that I can't implement this class in a straight forward manner with +// constructors and stuff because it goes in a union, and GCC doesn't like +// putting classes with ctor's in unions. :( +// +struct ValID { + int Type; // 0 = number, 1 = name, 2 = const pool, + // 3 = unsigned const pool, 4 = const string + union { + int Num; // If it's a numeric reference + char *Name; // If it's a named reference. Memory must be free'd. + int64_t ConstPool64; // Constant pool reference. This is the value + uint64_t UConstPool64;// Unsigned constant pool reference. + }; + + static ValID create(int Num) { + ValID D; D.Type = 0; D.Num = Num; return D; + } + + static ValID create(char *Name) { + ValID D; D.Type = 1; D.Name = Name; return D; + } + + static ValID create(int64_t Val) { + ValID D; D.Type = 2; D.ConstPool64 = Val; return D; + } + + static ValID create(uint64_t Val) { + ValID D; D.Type = 3; D.UConstPool64 = Val; return D; + } + + static ValID create_conststr(char *Name) { + ValID D; D.Type = 4; D.Name = Name; return D; + } + + inline void destroy() { + if (Type == 1 || Type == 4) free(Name); // Free this strdup'd memory... + } + + inline ValID copy() const { + if (Type != 1 && Type != 4) return *this; + ValID Result = *this; + Result.Name = strdup(Name); + return Result; + } + + inline string getName() const { + switch (Type) { + case 0: return string("#") + itostr(Num); + case 1: return Name; + case 4: return string("\"") + Name + string("\""); + default: return string("%") + itostr(ConstPool64); + } + } +}; + + + +template<class SuperType> +class PlaceholderDef : public SuperType { + ValID D; + // TODO: Placeholder def should hold Line #/Column # of definition in case + // there is an error resolving the defintition! +public: + PlaceholderDef(const Type *Ty, const ValID &d) : SuperType(Ty), D(d) {} + ValID &getDef() { return D; } +}; + +struct InstPlaceHolderHelper : public Instruction { + InstPlaceHolderHelper(const Type *Ty) : Instruction(Ty, UserOp1, "") {} + + virtual Instruction *clone() const { abort(); } + + inline virtual void dropAllReferences() {} + virtual string getOpcode() const { return "placeholder"; } + + // No "operands"... + virtual Value *getOperand(unsigned i) { return 0; } + virtual const Value *getOperand(unsigned i) const { return 0; } + virtual bool setOperand(unsigned i, Value *Val) { return false; } + virtual unsigned getNumOperands() const { return 0; } +}; + +struct BBPlaceHolderHelper : public BasicBlock { + BBPlaceHolderHelper(const Type *Ty) : BasicBlock() { + assert(Ty->isLabelType()); + } +}; + +struct MethPlaceHolderHelper : public Method { + MethPlaceHolderHelper(const Type *Ty) + : Method((const MethodType*)Ty) { + assert(Ty->isMethodType() && "Method placeholders must be method types!"); + } +}; + +typedef PlaceholderDef<InstPlaceHolderHelper> DefPlaceHolder; +typedef PlaceholderDef<BBPlaceHolderHelper> BBPlaceHolder; +typedef PlaceholderDef<MethPlaceHolderHelper> MethPlaceHolder; +//typedef PlaceholderDef<ModulePlaceHolderHelper> ModulePlaceHolder; + +static inline ValID &getValIDFromPlaceHolder(Value *Def) { + switch (Def->getType()->getPrimitiveID()) { + case Type::LabelTyID: return ((BBPlaceHolder*)Def)->getDef(); + case Type::MethodTyID: return ((MethPlaceHolder*)Def)->getDef(); +//case Type::ModuleTyID: return ((ModulePlaceHolder*)Def)->getDef(); + default: return ((DefPlaceHolder*)Def)->getDef(); + } +} + +#endif diff --git a/lib/AsmParser/llvmAsmParser.cpp b/lib/AsmParser/llvmAsmParser.cpp new file mode 100644 index 0000000..e79f1bf --- /dev/null +++ b/lib/AsmParser/llvmAsmParser.cpp @@ -0,0 +1,2202 @@ + +/* A Bison parser, made from llvmAsmParser.y + by GNU Bison version 1.28 */ + +#define YYBISON 1 /* Identify Bison output. */ + +#define yyparse llvmAsmparse +#define yylex llvmAsmlex +#define yyerror llvmAsmerror +#define yylval llvmAsmlval +#define yychar llvmAsmchar +#define yydebug llvmAsmdebug +#define yynerrs llvmAsmnerrs +#define ESINT64VAL 257 +#define EUINT64VAL 258 +#define SINTVAL 259 +#define UINTVAL 260 +#define VOID 261 +#define BOOL 262 +#define SBYTE 263 +#define UBYTE 264 +#define SHORT 265 +#define USHORT 266 +#define INT 267 +#define UINT 268 +#define LONG 269 +#define ULONG 270 +#define FLOAT 271 +#define DOUBLE 272 +#define STRING 273 +#define TYPE 274 +#define LABEL 275 +#define VAR_ID 276 +#define LABELSTR 277 +#define STRINGCONSTANT 278 +#define IMPLEMENTATION 279 +#define TRUE 280 +#define FALSE 281 +#define BEGINTOK 282 +#define END 283 +#define DECLARE 284 +#define PHI 285 +#define CALL 286 +#define RET 287 +#define BR 288 +#define SWITCH 289 +#define NEG 290 +#define NOT 291 +#define TOINT 292 +#define TOUINT 293 +#define ADD 294 +#define SUB 295 +#define MUL 296 +#define DIV 297 +#define REM 298 +#define SETLE 299 +#define SETGE 300 +#define SETLT 301 +#define SETGT 302 +#define SETEQ 303 +#define SETNE 304 +#define MALLOC 305 +#define ALLOCA 306 +#define FREE 307 +#define LOAD 308 +#define STORE 309 +#define GETFIELD 310 +#define PUTFIELD 311 + +#line 13 "llvmAsmParser.y" + +#include "ParserInternals.h" +#include "llvm/BasicBlock.h" +#include "llvm/Method.h" +#include "llvm/SymbolTable.h" +#include "llvm/Module.h" +#include "llvm/Type.h" +#include "llvm/DerivedTypes.h" +#include "llvm/Assembly/Parser.h" +#include "llvm/ConstantPool.h" +#include "llvm/iTerminators.h" +#include "llvm/iMemory.h" +#include <list> +#include <utility> // Get definition of pair class +#include <stdio.h> // This embarasment is due to our flex lexer... + +int yyerror(char *ErrorMsg); // Forward declarations to prevent "implicit +int yylex(); // declaration" of xxx warnings. +int yyparse(); + +static Module *ParserResult; +const ToolCommandLine *CurOptions = 0; + +// This contains info used when building the body of a method. It is destroyed +// when the method is completed. +// +typedef vector<Value *> ValueList; // Numbered defs +static void ResolveDefinitions(vector<ValueList> &LateResolvers); + +static struct PerModuleInfo { + Module *CurrentModule; + vector<ValueList> Values; // Module level numbered definitions + vector<ValueList> LateResolveValues; + + void ModuleDone() { + // If we could not resolve some blocks at parsing time (forward branches) + // resolve the branches now... + ResolveDefinitions(LateResolveValues); + + Values.clear(); // Clear out method local definitions + CurrentModule = 0; + } +} CurModule; + +static struct PerMethodInfo { + Method *CurrentMethod; // Pointer to current method being created + + vector<ValueList> Values; // Keep track of numbered definitions + vector<ValueList> LateResolveValues; + + inline PerMethodInfo() { + CurrentMethod = 0; + } + + inline ~PerMethodInfo() {} + + inline void MethodStart(Method *M) { + CurrentMethod = M; + } + + void MethodDone() { + // If we could not resolve some blocks at parsing time (forward branches) + // resolve the branches now... + ResolveDefinitions(LateResolveValues); + + Values.clear(); // Clear out method local definitions + CurrentMethod = 0; + } +} CurMeth; // Info for the current method... + + +//===----------------------------------------------------------------------===// +// Code to handle definitions of all the types +//===----------------------------------------------------------------------===// + +static void InsertValue(Value *D, vector<ValueList> &ValueTab = CurMeth.Values) { + if (!D->hasName()) { // Is this a numbered definition? + unsigned type = D->getType()->getUniqueID(); + if (ValueTab.size() <= type) + ValueTab.resize(type+1, ValueList()); + //printf("Values[%d][%d] = %d\n", type, ValueTab[type].size(), D); + ValueTab[type].push_back(D); + } +} + +static Value *getVal(const Type *Type, ValID &D, + bool DoNotImprovise = false) { + switch (D.Type) { + case 0: { // Is it a numbered definition? + unsigned type = Type->getUniqueID(); + unsigned Num = (unsigned)D.Num; + + // Module constants occupy the lowest numbered slots... + if (type < CurModule.Values.size()) { + if (Num < CurModule.Values[type].size()) + return CurModule.Values[type][Num]; + + Num -= CurModule.Values[type].size(); + } + + // Make sure that our type is within bounds + if (CurMeth.Values.size() <= type) + break; + + // Check that the number is within bounds... + if (CurMeth.Values[type].size() <= Num) + break; + + return CurMeth.Values[type][Num]; + } + case 1: { // Is it a named definition? + string Name(D.Name); + SymbolTable *SymTab = 0; + if (CurMeth.CurrentMethod) + SymTab = CurMeth.CurrentMethod->getSymbolTable(); + Value *N = SymTab ? SymTab->lookup(Type, Name) : 0; + + if (N == 0) { + SymTab = CurModule.CurrentModule->getSymbolTable(); + if (SymTab) + N = SymTab->lookup(Type, Name); + if (N == 0) break; + } + + D.destroy(); // Free old strdup'd memory... + return N; + } + + case 2: // Is it a constant pool reference?? + case 3: // Is it an unsigned const pool reference? + case 4:{ // Is it a string const pool reference? + ConstPoolVal *CPV = 0; + + // Check to make sure that "Type" is an integral type, and that our + // value will fit into the specified type... + switch (D.Type) { + case 2: + if (Type == Type::BoolTy) { // Special handling for boolean data + CPV = new ConstPoolBool(D.ConstPool64 != 0); + } else { + if (!ConstPoolSInt::isValueValidForType(Type, D.ConstPool64)) + ThrowException("Symbolic constant pool reference is invalid!"); + CPV = new ConstPoolSInt(Type, D.ConstPool64); + } + break; + case 3: + if (!ConstPoolUInt::isValueValidForType(Type, D.UConstPool64)) { + if (!ConstPoolSInt::isValueValidForType(Type, D.ConstPool64)) { + ThrowException("Symbolic constant pool reference is invalid!"); + } else { // This is really a signed reference. Transmogrify. + CPV = new ConstPoolSInt(Type, D.ConstPool64); + } + } else { + CPV = new ConstPoolUInt(Type, D.UConstPool64); + } + break; + case 4: + cerr << "FIXME: TODO: String constants [sbyte] not implemented yet!\n"; + abort(); + //CPV = new ConstPoolString(D.Name); + D.destroy(); // Free the string memory + break; + } + assert(CPV && "How did we escape creating a constant??"); + + // Scan through the constant table and see if we already have loaded this + // constant. + // + ConstantPool &CP = CurMeth.CurrentMethod ? + CurMeth.CurrentMethod->getConstantPool() : + CurModule.CurrentModule->getConstantPool(); + ConstPoolVal *C = CP.find(CPV); // Already have this constant? + if (C) { + delete CPV; // Didn't need this after all, oh well. + return C; // Yup, we already have one, recycle it! + } + CP.insert(CPV); + + // Success, everything is kosher. Lets go! + return CPV; + } // End of case 2,3,4 + } // End of switch + + + // If we reached here, we referenced either a symbol that we don't know about + // or an id number that hasn't been read yet. We may be referencing something + // forward, so just create an entry to be resolved later and get to it... + // + if (DoNotImprovise) return 0; // Do we just want a null to be returned? + + // TODO: Attempt to coallecse nodes that are the same with previous ones. + Value *d = 0; + switch (Type->getPrimitiveID()) { + case Type::LabelTyID: d = new BBPlaceHolder(Type, D); break; + case Type::MethodTyID: + d = new MethPlaceHolder(Type, D); + InsertValue(d, CurModule.LateResolveValues); + return d; +//case Type::ClassTyID: d = new ClassPlaceHolder(Type, D); break; + default: d = new DefPlaceHolder(Type, D); break; + } + + assert(d != 0 && "How did we not make something?"); + InsertValue(d, CurMeth.LateResolveValues); + return d; +} + + +//===----------------------------------------------------------------------===// +// Code to handle forward references in instructions +//===----------------------------------------------------------------------===// +// +// This code handles the late binding needed with statements that reference +// values not defined yet... for example, a forward branch, or the PHI node for +// a loop body. +// +// This keeps a table (CurMeth.LateResolveValues) of all such forward references +// and back patchs after we are done. +// + +// ResolveDefinitions - If we could not resolve some defs at parsing +// time (forward branches, phi functions for loops, etc...) resolve the +// defs now... +// +static void ResolveDefinitions(vector<ValueList> &LateResolvers) { + // Loop over LateResolveDefs fixing up stuff that couldn't be resolved + for (unsigned ty = 0; ty < LateResolvers.size(); ty++) { + while (!LateResolvers[ty].empty()) { + Value *V = LateResolvers[ty].back(); + LateResolvers[ty].pop_back(); + ValID &DID = getValIDFromPlaceHolder(V); + + Value *TheRealValue = getVal(Type::getUniqueIDType(ty), DID, true); + + if (TheRealValue == 0 && DID.Type == 1) + ThrowException("Reference to an invalid definition: '" +DID.getName() + + "' of type '" + V->getType()->getName() + "'"); + else if (TheRealValue == 0) + ThrowException("Reference to an invalid definition: #" +itostr(DID.Num)+ + " of type '" + V->getType()->getName() + "'"); + + V->replaceAllUsesWith(TheRealValue); + assert(V->use_empty()); + delete V; + } + } + + LateResolvers.clear(); +} + +// addConstValToConstantPool - This code is used to insert a constant into the +// current constant pool. This is designed to make maximal (but not more than +// possible) reuse (merging) of constants in the constant pool. This means that +// multiple references to %4, for example will all get merged. +// +static ConstPoolVal *addConstValToConstantPool(ConstPoolVal *C) { + vector<ValueList> &ValTab = CurMeth.CurrentMethod ? + CurMeth.Values : CurModule.Values; + ConstantPool &CP = CurMeth.CurrentMethod ? + CurMeth.CurrentMethod->getConstantPool() : + CurModule.CurrentModule->getConstantPool(); + + if (ConstPoolVal *CPV = CP.find(C)) { + // Constant already in constant pool. Try to merge the two constants + if (CPV->hasName() && !C->hasName()) { + // Merge the two values, we inherit the existing CPV's name. + // InsertValue requires that the value have no name to insert correctly + // (because we want to fill the slot this constant would have filled) + // + string Name = CPV->getName(); + CPV->setName(""); + InsertValue(CPV, ValTab); + CPV->setName(Name); + delete C; + return CPV; + } else if (!CPV->hasName() && C->hasName()) { + // If we have a name on this value and there isn't one in the const + // pool val already, propogate it. + // + CPV->setName(C->getName()); + delete C; // Sorry, you're toast + return CPV; + } else if (CPV->hasName() && C->hasName()) { + // Both values have distinct names. We cannot merge them. + CP.insert(C); + InsertValue(C, ValTab); + return C; + } else if (!CPV->hasName() && !C->hasName()) { + // Neither value has a name, trivially merge them. + InsertValue(CPV, ValTab); + delete C; + return CPV; + } + + assert(0 && "Not reached!"); + return 0; + } else { // No duplication of value. + CP.insert(C); + InsertValue(C, ValTab); + return C; + } +} + +//===----------------------------------------------------------------------===// +// RunVMAsmParser - Define an interface to this parser +//===----------------------------------------------------------------------===// +// +Module *RunVMAsmParser(const ToolCommandLine &Opts, FILE *F) { + llvmAsmin = F; + CurOptions = &Opts; + llvmAsmlineno = 1; // Reset the current line number... + + CurModule.CurrentModule = new Module(); // Allocate a new module to read + yyparse(); // Parse the file. + Module *Result = ParserResult; + CurOptions = 0; + llvmAsmin = stdin; // F is about to go away, don't use it anymore... + ParserResult = 0; + + return Result; +} + + +#line 337 "llvmAsmParser.y" +typedef union { + Module *ModuleVal; + Method *MethodVal; + MethodArgument *MethArgVal; + BasicBlock *BasicBlockVal; + TerminatorInst *TermInstVal; + Instruction *InstVal; + ConstPoolVal *ConstVal; + const Type *TypeVal; + + list<MethodArgument*> *MethodArgList; + list<Value*> *ValueList; + list<const Type*> *TypeList; + list<pair<ConstPoolVal*, BasicBlock*> > *JumpTable; + vector<ConstPoolVal*> *ConstVector; + + int64_t SInt64Val; + uint64_t UInt64Val; + int SIntVal; + unsigned UIntVal; + + char *StrVal; // This memory is allocated by strdup! + ValID ValIDVal; // May contain memory allocated by strdup + + Instruction::UnaryOps UnaryOpVal; + Instruction::BinaryOps BinaryOpVal; + Instruction::TermOps TermOpVal; + Instruction::MemoryOps MemOpVal; +} YYSTYPE; +#include <stdio.h> + +#ifndef __cplusplus +#ifndef __STDC__ +#define const +#endif +#endif + + + +#define YYFINAL 220 +#define YYFLAG -32768 +#define YYNTBASE 68 + +#define YYTRANSLATE(x) ((unsigned)(x) <= 311 ? yytranslate[x] : 103) + +static const char yytranslate[] = { 0, + 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, + 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, + 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, + 2, 2, 2, 2, 2, 2, 2, 2, 2, 65, + 66, 67, 2, 64, 2, 2, 2, 2, 2, 2, + 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, + 58, 2, 2, 2, 2, 2, 2, 2, 2, 2, + 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, + 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, + 59, 2, 60, 2, 2, 2, 2, 2, 2, 2, + 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, + 2, 2, 2, 2, 2, 2, 2, 2, 2, 61, + 2, 2, 62, 2, 63, 2, 2, 2, 2, 2, + 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, + 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, + 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, + 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, + 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, + 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, + 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, + 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, + 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, + 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, + 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, + 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, + 2, 2, 2, 2, 2, 1, 3, 4, 5, 6, + 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, + 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, + 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, + 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, + 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, + 57 +}; + +#if YYDEBUG != 0 +static const short yyprhs[] = { 0, + 0, 2, 4, 6, 8, 10, 12, 14, 16, 18, + 20, 22, 24, 26, 28, 30, 32, 34, 36, 38, + 40, 42, 44, 46, 48, 50, 52, 54, 56, 58, + 60, 62, 64, 66, 68, 70, 72, 74, 76, 78, + 80, 82, 84, 86, 88, 90, 93, 94, 97, 100, + 103, 106, 109, 112, 119, 125, 134, 142, 149, 154, + 158, 160, 164, 165, 167, 170, 173, 175, 176, 179, + 183, 185, 187, 188, 194, 198, 201, 203, 205, 207, + 209, 211, 213, 215, 217, 219, 224, 228, 232, 238, + 242, 245, 248, 250, 254, 257, 260, 263, 267, 270, + 271, 275, 278, 282, 292, 302, 309, 315, 318, 321, + 325, 327, 328, 334, 338, 341, 348, 350, 353, 359, + 362, 368 +}; + +static const short yyrhs[] = { 5, + 0, 6, 0, 3, 0, 4, 0, 8, 0, 9, + 0, 10, 0, 11, 0, 12, 0, 13, 0, 14, + 0, 15, 0, 16, 0, 17, 0, 18, 0, 19, + 0, 20, 0, 21, 0, 70, 0, 7, 0, 36, + 0, 37, 0, 38, 0, 39, 0, 40, 0, 41, + 0, 42, 0, 43, 0, 44, 0, 45, 0, 46, + 0, 47, 0, 48, 0, 49, 0, 50, 0, 15, + 0, 13, 0, 11, 0, 9, 0, 16, 0, 14, + 0, 12, 0, 10, 0, 74, 0, 75, 0, 22, + 58, 0, 0, 74, 69, 0, 75, 4, 0, 8, + 26, 0, 8, 27, 0, 19, 24, 0, 20, 70, + 0, 59, 70, 60, 59, 79, 60, 0, 59, 70, + 60, 59, 60, 0, 59, 4, 61, 70, 60, 59, + 79, 60, 0, 59, 4, 61, 70, 60, 59, 60, + 0, 62, 92, 63, 62, 79, 63, 0, 62, 63, + 62, 63, 0, 79, 64, 78, 0, 78, 0, 80, + 77, 78, 0, 0, 82, 0, 82, 89, 0, 80, + 25, 0, 22, 0, 0, 70, 83, 0, 84, 64, + 85, 0, 84, 0, 85, 0, 0, 71, 24, 65, + 86, 66, 0, 87, 80, 28, 0, 93, 29, 0, + 3, 0, 4, 0, 26, 0, 27, 0, 24, 0, + 68, 0, 22, 0, 90, 0, 91, 0, 71, 65, + 92, 66, 0, 71, 65, 66, 0, 59, 70, 60, + 0, 59, 4, 61, 70, 60, 0, 62, 92, 63, + 0, 62, 63, 0, 70, 67, 0, 70, 0, 92, + 64, 70, 0, 93, 94, 0, 88, 94, 0, 95, + 96, 0, 23, 95, 96, 0, 95, 98, 0, 0, + 33, 70, 91, 0, 33, 7, 0, 34, 21, 91, + 0, 34, 8, 91, 64, 21, 91, 64, 21, 91, + 0, 35, 76, 91, 64, 21, 91, 59, 97, 60, + 0, 97, 76, 90, 64, 21, 91, 0, 76, 90, + 64, 21, 91, 0, 77, 101, 0, 70, 91, 0, + 99, 64, 91, 0, 99, 0, 0, 73, 70, 91, + 64, 91, 0, 72, 70, 91, 0, 31, 99, 0, + 32, 70, 91, 65, 100, 66, 0, 102, 0, 51, + 70, 0, 51, 70, 64, 14, 91, 0, 52, 70, + 0, 52, 70, 64, 14, 91, 0, 53, 70, 91, + 0 +}; + +#endif + +#if YYDEBUG != 0 +static const short yyrline[] = { 0, + 433, 434, 441, 442, 453, 453, 453, 453, 453, 453, + 453, 454, 454, 454, 454, 454, 454, 454, 457, 457, + 462, 462, 462, 462, 463, 463, 463, 463, 463, 464, + 464, 464, 464, 464, 464, 468, 468, 468, 468, 469, + 469, 469, 469, 470, 470, 472, 475, 479, 484, 489, + 492, 495, 501, 504, 517, 521, 539, 546, 554, 568, + 571, 577, 585, 596, 601, 606, 615, 615, 617, 625, + 629, 634, 637, 641, 668, 672, 681, 684, 687, 690, + 693, 698, 701, 704, 711, 719, 724, 728, 731, 734, + 739, 742, 747, 751, 756, 760, 769, 774, 783, 787, + 791, 794, 797, 800, 805, 816, 824, 834, 842, 846, + 852, 852, 854, 859, 864, 873, 910, 914, 919, 929, + 934, 944 +}; +#endif + + +#if YYDEBUG != 0 || defined (YYERROR_VERBOSE) + +static const char * const yytname[] = { "$","error","$undefined.","ESINT64VAL", +"EUINT64VAL","SINTVAL","UINTVAL","VOID","BOOL","SBYTE","UBYTE","SHORT","USHORT", +"INT","UINT","LONG","ULONG","FLOAT","DOUBLE","STRING","TYPE","LABEL","VAR_ID", +"LABELSTR","STRINGCONSTANT","IMPLEMENTATION","TRUE","FALSE","BEGINTOK","END", +"DECLARE","PHI","CALL","RET","BR","SWITCH","NEG","NOT","TOINT","TOUINT","ADD", +"SUB","MUL","DIV","REM","SETLE","SETGE","SETLT","SETGT","SETEQ","SETNE","MALLOC", +"ALLOCA","FREE","LOAD","STORE","GETFIELD","PUTFIELD","'='","'['","']'","'x'", +"'{'","'}'","','","'('","')'","'*'","INTVAL","EINT64VAL","Types","TypesV","UnaryOps", +"BinaryOps","SIntType","UIntType","IntType","OptAssign","ConstVal","ConstVector", +"ConstPool","Module","MethodList","OptVAR_ID","ArgVal","ArgListH","ArgList", +"MethodHeaderH","MethodHeader","Method","ConstValueRef","ValueRef","TypeList", +"BasicBlockList","BasicBlock","InstructionList","BBTerminatorInst","JumpTable", +"Inst","ValueRefList","ValueRefListE","InstVal","MemoryInst", NULL +}; +#endif + +static const short yyr1[] = { 0, + 68, 68, 69, 69, 70, 70, 70, 70, 70, 70, + 70, 70, 70, 70, 70, 70, 70, 70, 71, 71, + 72, 72, 72, 72, 73, 73, 73, 73, 73, 73, + 73, 73, 73, 73, 73, 74, 74, 74, 74, 75, + 75, 75, 75, 76, 76, 77, 77, 78, 78, 78, + 78, 78, 78, 78, 78, 78, 78, 78, 78, 79, + 79, 80, 80, 81, 82, 82, 83, 83, 84, 85, + 85, 86, 86, 87, 88, 89, 90, 90, 90, 90, + 90, 91, 91, 91, 70, 70, 70, 70, 70, 70, + 70, 70, 92, 92, 93, 93, 94, 94, 95, 95, + 96, 96, 96, 96, 96, 97, 97, 98, 99, 99, + 100, 100, 101, 101, 101, 101, 101, 102, 102, 102, + 102, 102 +}; + +static const short yyr2[] = { 0, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 2, 0, 2, 2, 2, + 2, 2, 2, 6, 5, 8, 7, 6, 4, 3, + 1, 3, 0, 1, 2, 2, 1, 0, 2, 3, + 1, 1, 0, 5, 3, 2, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 4, 3, 3, 5, 3, + 2, 2, 1, 3, 2, 2, 2, 3, 2, 0, + 3, 2, 3, 9, 9, 6, 5, 2, 2, 3, + 1, 0, 5, 3, 2, 6, 1, 2, 5, 2, + 5, 3 +}; + +static const short yydefact[] = { 63, + 47, 64, 0, 66, 0, 77, 78, 1, 2, 20, + 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, + 15, 16, 17, 18, 83, 81, 79, 80, 0, 0, + 82, 19, 0, 63, 100, 65, 84, 85, 100, 46, + 0, 39, 43, 38, 42, 37, 41, 36, 40, 0, + 0, 0, 0, 0, 0, 62, 78, 19, 0, 91, + 93, 0, 92, 0, 0, 47, 100, 96, 47, 76, + 95, 50, 51, 52, 53, 78, 19, 0, 0, 3, + 4, 48, 49, 0, 88, 90, 0, 73, 87, 0, + 75, 47, 0, 0, 0, 0, 97, 99, 0, 0, + 0, 0, 19, 94, 68, 71, 72, 0, 86, 98, + 102, 19, 0, 0, 44, 45, 0, 0, 0, 21, + 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, + 32, 33, 34, 35, 0, 0, 0, 0, 0, 108, + 117, 19, 0, 59, 0, 89, 67, 69, 0, 74, + 101, 0, 103, 0, 19, 115, 19, 118, 120, 19, + 19, 19, 0, 55, 61, 0, 0, 70, 0, 0, + 109, 0, 0, 0, 0, 122, 114, 0, 0, 54, + 0, 58, 0, 0, 110, 112, 0, 0, 0, 57, + 0, 60, 0, 0, 111, 0, 119, 121, 113, 56, + 0, 0, 116, 0, 0, 0, 104, 0, 105, 0, + 0, 0, 0, 0, 107, 0, 106, 0, 0, 0 +}; + +static const short yydefgoto[] = { 31, + 82, 61, 59, 138, 139, 54, 55, 117, 5, 165, + 166, 1, 218, 2, 148, 106, 107, 108, 34, 35, + 36, 37, 38, 62, 39, 68, 69, 97, 206, 98, + 156, 196, 140, 141 +}; + +static const short yypact[] = {-32768, + 59, 295, -23,-32768, 435,-32768,-32768,-32768,-32768,-32768, +-32768,-32768,-32768,-32768,-32768,-32768,-32768,-32768,-32768,-32768, +-32768,-32768,-32768,-32768,-32768,-32768,-32768,-32768, 320, 209, +-32768, -21, -20,-32768, 38,-32768,-32768,-32768, 83,-32768, + 66,-32768,-32768,-32768,-32768,-32768,-32768,-32768,-32768, 77, + 295, 380, 234, 206, 122,-32768, 107, 29, 108,-32768, + 167, 6,-32768, 111, 145, 101,-32768,-32768, 45,-32768, +-32768,-32768,-32768,-32768, 167, 142, 44, 121, 81,-32768, +-32768,-32768,-32768, 295,-32768,-32768, 295, 295,-32768, 193, +-32768, 45, 405, 1, 264, 149,-32768,-32768, 295, 205, + 202, 204, 58, 167, 10, 203,-32768, 215,-32768,-32768, + 217, 7, 116, 116,-32768,-32768, 116, 295, 295,-32768, +-32768,-32768,-32768,-32768,-32768,-32768,-32768,-32768,-32768,-32768, +-32768,-32768,-32768,-32768, 295, 295, 295, 295, 295,-32768, +-32768, 72, 28,-32768, 435,-32768,-32768,-32768, 295,-32768, +-32768, 219,-32768, 220, 7, 221, 7, -59, 141, 7, + 7, 7, 210,-32768,-32768, 110, 199,-32768, 249, 265, +-32768, 116, 222, 274, 275,-32768,-32768, 226, 43,-32768, + 435,-32768, 116, 116,-32768, 295, 116, 116, 116,-32768, + 115,-32768, 227, 233, 221, 228,-32768,-32768,-32768,-32768, + 297, 264,-32768, 116, 104, 5,-32768, 231,-32768, 104, + 299, 279, 116, 324,-32768, 116,-32768, 348, 349,-32768 +}; + +static const short yypgoto[] = {-32768, +-32768, -2, 350,-32768,-32768, -93, -92, -24, -62, -4, + -119, 316,-32768,-32768,-32768,-32768, 207,-32768,-32768,-32768, +-32768, -64, -89, 11,-32768, 312, 286, 263,-32768,-32768, + 172,-32768,-32768,-32768 +}; + + +#define YYLAST 497 + + +static const short yytable[] = { 32, + 56, 115, 116, 64, 174, -19, 96, 63, 113, 6, + 7, 8, 9, 42, 43, 44, 45, 46, 47, 48, + 49, 114, 151, 152, 153, 167, 58, 154, 25, 96, + 26, 147, 27, 28, 40, 41, 42, 43, 44, 45, + 46, 47, 48, 49, 65, 63, 50, 51, 75, 77, + 41, 42, 43, 44, 45, 46, 47, 48, 49, 191, + 67, 50, 51, 79, 209, 171, 3, 173, 86, 87, + 176, 177, 178, 63, -19, 90, 63, 93, 94, 95, + 3, 103, 185, 4, 104, 105, 52, 164, 85, 53, + 112, 72, 73, 193, 194, 63, 142, 197, 198, 199, + 74, 52, 190, 100, 53, 67, 6, 7, 115, 116, + 63, 70, 115, 116, 207, 155, 157, 146, 6, 7, + 8, 9, 3, 215, 63, 83, 217, 26, 91, 27, + 28, 163, 158, 159, 160, 161, 162, 25, 63, 26, + 208, 27, 28, 102, 87, 212, 105, 6, 7, 8, + 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, + 19, 20, 21, 22, 23, 24, 25, 84, 26, 180, + 27, 28, 65, 181, 200, 88, 192, 205, 181, 118, + 119, 210, 101, 155, 120, 121, 122, 123, 124, 125, + 126, 127, 128, 129, 130, 131, 132, 133, 134, 135, + 136, 137, 99, 29, 175, -19, 30, 63, 80, 81, + 89, 6, 7, 8, 9, 10, 11, 12, 13, 14, + 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, + 25, -19, 26, 63, 27, 28, 6, 7, 8, 9, + 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, + 20, 21, 22, 23, 24, 25, 87, 26, 109, 27, + 28, 182, 181, 143, 144, 145, 149, 29, 179, 183, + 30, 60, 42, 43, 44, 45, 46, 47, 48, 49, + 150, -20, 169, 170, 172, 184, 186, 187, 188, 189, + 201, 202, 29, 203, 211, 30, 78, 6, 7, 8, + 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, + 19, 20, 21, 22, 23, 24, 25, 204, 26, 213, + 27, 28, 6, 57, 8, 9, 10, 11, 12, 13, + 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, + 24, 25, 214, 26, 216, 27, 28, 219, 220, 66, + 71, 33, 92, 29, 110, 168, 30, 195, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 29, 0, + 0, 30, 6, 76, 8, 9, 10, 11, 12, 13, + 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, + 24, 25, 0, 26, 0, 27, 28, 6, 7, 8, + 9, 111, 11, 12, 13, 14, 15, 16, 17, 18, + 19, 20, 21, 22, 23, 24, 25, 0, 26, 0, + 27, 28, 0, 0, 0, 0, 0, 0, 29, 0, + 0, 30, 41, 42, 43, 44, 45, 46, 47, 48, + 49, 0, 0, 50, 51, 0, 0, 0, 0, 0, + 0, 0, 0, 29, 0, 0, 30, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 52, 0, 0, 53 +}; + +static const short yycheck[] = { 2, + 5, 95, 95, 24, 64, 65, 69, 67, 8, 3, + 4, 5, 6, 9, 10, 11, 12, 13, 14, 15, + 16, 21, 112, 113, 114, 145, 29, 117, 22, 92, + 24, 22, 26, 27, 58, 8, 9, 10, 11, 12, + 13, 14, 15, 16, 65, 67, 19, 20, 51, 52, + 8, 9, 10, 11, 12, 13, 14, 15, 16, 179, + 23, 19, 20, 53, 60, 155, 22, 157, 63, 64, + 160, 161, 162, 67, 65, 65, 67, 33, 34, 35, + 22, 84, 172, 25, 87, 88, 59, 60, 60, 62, + 93, 26, 27, 183, 184, 67, 99, 187, 188, 189, + 24, 59, 60, 60, 62, 23, 3, 4, 202, 202, + 67, 29, 206, 206, 204, 118, 119, 60, 3, 4, + 5, 6, 22, 213, 67, 4, 216, 24, 28, 26, + 27, 60, 135, 136, 137, 138, 139, 22, 67, 24, + 205, 26, 27, 63, 64, 210, 149, 3, 4, 5, + 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, + 16, 17, 18, 19, 20, 21, 22, 61, 24, 60, + 26, 27, 65, 64, 60, 65, 181, 202, 64, 31, + 32, 206, 62, 186, 36, 37, 38, 39, 40, 41, + 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, + 52, 53, 61, 59, 64, 65, 62, 67, 3, 4, + 66, 3, 4, 5, 6, 7, 8, 9, 10, 11, + 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, + 22, 65, 24, 67, 26, 27, 3, 4, 5, 6, + 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, + 17, 18, 19, 20, 21, 22, 64, 24, 66, 26, + 27, 63, 64, 59, 63, 62, 64, 59, 59, 21, + 62, 63, 9, 10, 11, 12, 13, 14, 15, 16, + 66, 65, 64, 64, 64, 21, 65, 14, 14, 64, + 64, 59, 59, 66, 64, 62, 63, 3, 4, 5, + 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, + 16, 17, 18, 19, 20, 21, 22, 21, 24, 21, + 26, 27, 3, 4, 5, 6, 7, 8, 9, 10, + 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, + 21, 22, 64, 24, 21, 26, 27, 0, 0, 34, + 39, 2, 67, 59, 92, 149, 62, 186, -1, -1, + -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, + -1, -1, -1, -1, -1, -1, -1, -1, 59, -1, + -1, 62, 3, 4, 5, 6, 7, 8, 9, 10, + 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, + 21, 22, -1, 24, -1, 26, 27, 3, 4, 5, + 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, + 16, 17, 18, 19, 20, 21, 22, -1, 24, -1, + 26, 27, -1, -1, -1, -1, -1, -1, 59, -1, + -1, 62, 8, 9, 10, 11, 12, 13, 14, 15, + 16, -1, -1, 19, 20, -1, -1, -1, -1, -1, + -1, -1, -1, 59, -1, -1, 62, -1, -1, -1, + -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, + -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, + -1, -1, -1, 59, -1, -1, 62 +}; +/* -*-C-*- Note some compilers choke on comments on `#line' lines. */ +#line 3 "/usr/dcs/software/supported/encap/bison-1.28/share/bison.simple" +/* This file comes from bison-1.28. */ + +/* Skeleton output parser for bison, + Copyright (C) 1984, 1989, 1990 Free Software Foundation, Inc. + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2, or (at your option) + any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 59 Temple Place - Suite 330, + Boston, MA 02111-1307, USA. */ + +/* As a special exception, when this file is copied by Bison into a + Bison output file, you may use that output file without restriction. + This special exception was added by the Free Software Foundation + in version 1.24 of Bison. */ + +/* This is the parser code that is written into each bison parser + when the %semantic_parser declaration is not specified in the grammar. + It was written by Richard Stallman by simplifying the hairy parser + used when %semantic_parser is specified. */ + +#ifndef YYSTACK_USE_ALLOCA +#ifdef alloca +#define YYSTACK_USE_ALLOCA +#else /* alloca not defined */ +#ifdef __GNUC__ +#define YYSTACK_USE_ALLOCA +#define alloca __builtin_alloca +#else /* not GNU C. */ +#if (!defined (__STDC__) && defined (sparc)) || defined (__sparc__) || defined (__sparc) || defined (__sgi) || (defined (__sun) && defined (__i386)) +#define YYSTACK_USE_ALLOCA +#include <alloca.h> +#else /* not sparc */ +/* We think this test detects Watcom and Microsoft C. */ +/* This used to test MSDOS, but that is a bad idea + since that symbol is in the user namespace. */ +#if (defined (_MSDOS) || defined (_MSDOS_)) && !defined (__TURBOC__) +#if 0 /* No need for malloc.h, which pollutes the namespace; + instead, just don't use alloca. */ +#include <malloc.h> +#endif +#else /* not MSDOS, or __TURBOC__ */ +#if defined(_AIX) +/* I don't know what this was needed for, but it pollutes the namespace. + So I turned it off. rms, 2 May 1997. */ +/* #include <malloc.h> */ + #pragma alloca +#define YYSTACK_USE_ALLOCA +#else /* not MSDOS, or __TURBOC__, or _AIX */ +#if 0 +#ifdef __hpux /* haible@ilog.fr says this works for HPUX 9.05 and up, + and on HPUX 10. Eventually we can turn this on. */ +#define YYSTACK_USE_ALLOCA +#define alloca __builtin_alloca +#endif /* __hpux */ +#endif +#endif /* not _AIX */ +#endif /* not MSDOS, or __TURBOC__ */ +#endif /* not sparc */ +#endif /* not GNU C */ +#endif /* alloca not defined */ +#endif /* YYSTACK_USE_ALLOCA not defined */ + +#ifdef YYSTACK_USE_ALLOCA +#define YYSTACK_ALLOC alloca +#else +#define YYSTACK_ALLOC malloc +#endif + +/* Note: there must be only one dollar sign in this file. + It is replaced by the list of actions, each action + as one case of the switch. */ + +#define yyerrok (yyerrstatus = 0) +#define yyclearin (yychar = YYEMPTY) +#define YYEMPTY -2 +#define YYEOF 0 +#define YYACCEPT goto yyacceptlab +#define YYABORT goto yyabortlab +#define YYERROR goto yyerrlab1 +/* Like YYERROR except do call yyerror. + This remains here temporarily to ease the + transition to the new meaning of YYERROR, for GCC. + Once GCC version 2 has supplanted version 1, this can go. */ +#define YYFAIL goto yyerrlab +#define YYRECOVERING() (!!yyerrstatus) +#define YYBACKUP(token, value) \ +do \ + if (yychar == YYEMPTY && yylen == 1) \ + { yychar = (token), yylval = (value); \ + yychar1 = YYTRANSLATE (yychar); \ + YYPOPSTACK; \ + goto yybackup; \ + } \ + else \ + { yyerror ("syntax error: cannot back up"); YYERROR; } \ +while (0) + +#define YYTERROR 1 +#define YYERRCODE 256 + +#ifndef YYPURE +#define YYLEX yylex() +#endif + +#ifdef YYPURE +#ifdef YYLSP_NEEDED +#ifdef YYLEX_PARAM +#define YYLEX yylex(&yylval, &yylloc, YYLEX_PARAM) +#else +#define YYLEX yylex(&yylval, &yylloc) +#endif +#else /* not YYLSP_NEEDED */ +#ifdef YYLEX_PARAM +#define YYLEX yylex(&yylval, YYLEX_PARAM) +#else +#define YYLEX yylex(&yylval) +#endif +#endif /* not YYLSP_NEEDED */ +#endif + +/* If nonreentrant, generate the variables here */ + +#ifndef YYPURE + +int yychar; /* the lookahead symbol */ +YYSTYPE yylval; /* the semantic value of the */ + /* lookahead symbol */ + +#ifdef YYLSP_NEEDED +YYLTYPE yylloc; /* location data for the lookahead */ + /* symbol */ +#endif + +int yynerrs; /* number of parse errors so far */ +#endif /* not YYPURE */ + +#if YYDEBUG != 0 +int yydebug; /* nonzero means print parse trace */ +/* Since this is uninitialized, it does not stop multiple parsers + from coexisting. */ +#endif + +/* YYINITDEPTH indicates the initial size of the parser's stacks */ + +#ifndef YYINITDEPTH +#define YYINITDEPTH 200 +#endif + +/* YYMAXDEPTH is the maximum size the stacks can grow to + (effective only if the built-in stack extension method is used). */ + +#if YYMAXDEPTH == 0 +#undef YYMAXDEPTH +#endif + +#ifndef YYMAXDEPTH +#define YYMAXDEPTH 10000 +#endif + +/* Define __yy_memcpy. Note that the size argument + should be passed with type unsigned int, because that is what the non-GCC + definitions require. With GCC, __builtin_memcpy takes an arg + of type size_t, but it can handle unsigned int. */ + +#if __GNUC__ > 1 /* GNU C and GNU C++ define this. */ +#define __yy_memcpy(TO,FROM,COUNT) __builtin_memcpy(TO,FROM,COUNT) +#else /* not GNU C or C++ */ +#ifndef __cplusplus + +/* This is the most reliable way to avoid incompatibilities + in available built-in functions on various systems. */ +static void +__yy_memcpy (to, from, count) + char *to; + char *from; + unsigned int count; +{ + register char *f = from; + register char *t = to; + register int i = count; + + while (i-- > 0) + *t++ = *f++; +} + +#else /* __cplusplus */ + +/* This is the most reliable way to avoid incompatibilities + in available built-in functions on various systems. */ +static void +__yy_memcpy (char *to, char *from, unsigned int count) +{ + register char *t = to; + register char *f = from; + register int i = count; + + while (i-- > 0) + *t++ = *f++; +} + +#endif +#endif + +#line 217 "/usr/dcs/software/supported/encap/bison-1.28/share/bison.simple" + +/* The user can define YYPARSE_PARAM as the name of an argument to be passed + into yyparse. The argument should have type void *. + It should actually point to an object. + Grammar actions can access the variable by casting it + to the proper pointer type. */ + +#ifdef YYPARSE_PARAM +#ifdef __cplusplus +#define YYPARSE_PARAM_ARG void *YYPARSE_PARAM +#define YYPARSE_PARAM_DECL +#else /* not __cplusplus */ +#define YYPARSE_PARAM_ARG YYPARSE_PARAM +#define YYPARSE_PARAM_DECL void *YYPARSE_PARAM; +#endif /* not __cplusplus */ +#else /* not YYPARSE_PARAM */ +#define YYPARSE_PARAM_ARG +#define YYPARSE_PARAM_DECL +#endif /* not YYPARSE_PARAM */ + +/* Prevent warning if -Wstrict-prototypes. */ +#ifdef __GNUC__ +#ifdef YYPARSE_PARAM +int yyparse (void *); +#else +int yyparse (void); +#endif +#endif + +int +yyparse(YYPARSE_PARAM_ARG) + YYPARSE_PARAM_DECL +{ + register int yystate; + register int yyn; + register short *yyssp; + register YYSTYPE *yyvsp; + int yyerrstatus; /* number of tokens to shift before error messages enabled */ + int yychar1 = 0; /* lookahead token as an internal (translated) token number */ + + short yyssa[YYINITDEPTH]; /* the state stack */ + YYSTYPE yyvsa[YYINITDEPTH]; /* the semantic value stack */ + + short *yyss = yyssa; /* refer to the stacks thru separate pointers */ + YYSTYPE *yyvs = yyvsa; /* to allow yyoverflow to reallocate them elsewhere */ + +#ifdef YYLSP_NEEDED + YYLTYPE yylsa[YYINITDEPTH]; /* the location stack */ + YYLTYPE *yyls = yylsa; + YYLTYPE *yylsp; + +#define YYPOPSTACK (yyvsp--, yyssp--, yylsp--) +#else +#define YYPOPSTACK (yyvsp--, yyssp--) +#endif + + int yystacksize = YYINITDEPTH; + int yyfree_stacks = 0; + +#ifdef YYPURE + int yychar; + YYSTYPE yylval; + int yynerrs; +#ifdef YYLSP_NEEDED + YYLTYPE yylloc; +#endif +#endif + + YYSTYPE yyval; /* the variable used to return */ + /* semantic values from the action */ + /* routines */ + + int yylen; + +#if YYDEBUG != 0 + if (yydebug) + fprintf(stderr, "Starting parse\n"); +#endif + + yystate = 0; + yyerrstatus = 0; + yynerrs = 0; + yychar = YYEMPTY; /* Cause a token to be read. */ + + /* Initialize stack pointers. + Waste one element of value and location stack + so that they stay on the same level as the state stack. + The wasted elements are never initialized. */ + + yyssp = yyss - 1; + yyvsp = yyvs; +#ifdef YYLSP_NEEDED + yylsp = yyls; +#endif + +/* Push a new state, which is found in yystate . */ +/* In all cases, when you get here, the value and location stacks + have just been pushed. so pushing a state here evens the stacks. */ +yynewstate: + + *++yyssp = yystate; + + if (yyssp >= yyss + yystacksize - 1) + { + /* Give user a chance to reallocate the stack */ + /* Use copies of these so that the &'s don't force the real ones into memory. */ + YYSTYPE *yyvs1 = yyvs; + short *yyss1 = yyss; +#ifdef YYLSP_NEEDED + YYLTYPE *yyls1 = yyls; +#endif + + /* Get the current used size of the three stacks, in elements. */ + int size = yyssp - yyss + 1; + +#ifdef yyoverflow + /* Each stack pointer address is followed by the size of + the data in use in that stack, in bytes. */ +#ifdef YYLSP_NEEDED + /* This used to be a conditional around just the two extra args, + but that might be undefined if yyoverflow is a macro. */ + yyoverflow("parser stack overflow", + &yyss1, size * sizeof (*yyssp), + &yyvs1, size * sizeof (*yyvsp), + &yyls1, size * sizeof (*yylsp), + &yystacksize); +#else + yyoverflow("parser stack overflow", + &yyss1, size * sizeof (*yyssp), + &yyvs1, size * sizeof (*yyvsp), + &yystacksize); +#endif + + yyss = yyss1; yyvs = yyvs1; +#ifdef YYLSP_NEEDED + yyls = yyls1; +#endif +#else /* no yyoverflow */ + /* Extend the stack our own way. */ + if (yystacksize >= YYMAXDEPTH) + { + yyerror("parser stack overflow"); + if (yyfree_stacks) + { + free (yyss); + free (yyvs); +#ifdef YYLSP_NEEDED + free (yyls); +#endif + } + return 2; + } + yystacksize *= 2; + if (yystacksize > YYMAXDEPTH) + yystacksize = YYMAXDEPTH; +#ifndef YYSTACK_USE_ALLOCA + yyfree_stacks = 1; +#endif + yyss = (short *) YYSTACK_ALLOC (yystacksize * sizeof (*yyssp)); + __yy_memcpy ((char *)yyss, (char *)yyss1, + size * (unsigned int) sizeof (*yyssp)); + yyvs = (YYSTYPE *) YYSTACK_ALLOC (yystacksize * sizeof (*yyvsp)); + __yy_memcpy ((char *)yyvs, (char *)yyvs1, + size * (unsigned int) sizeof (*yyvsp)); +#ifdef YYLSP_NEEDED + yyls = (YYLTYPE *) YYSTACK_ALLOC (yystacksize * sizeof (*yylsp)); + __yy_memcpy ((char *)yyls, (char *)yyls1, + size * (unsigned int) sizeof (*yylsp)); +#endif +#endif /* no yyoverflow */ + + yyssp = yyss + size - 1; + yyvsp = yyvs + size - 1; +#ifdef YYLSP_NEEDED + yylsp = yyls + size - 1; +#endif + +#if YYDEBUG != 0 + if (yydebug) + fprintf(stderr, "Stack size increased to %d\n", yystacksize); +#endif + + if (yyssp >= yyss + yystacksize - 1) + YYABORT; + } + +#if YYDEBUG != 0 + if (yydebug) + fprintf(stderr, "Entering state %d\n", yystate); +#endif + + goto yybackup; + yybackup: + +/* Do appropriate processing given the current state. */ +/* Read a lookahead token if we need one and don't already have one. */ +/* yyresume: */ + + /* First try to decide what to do without reference to lookahead token. */ + + yyn = yypact[yystate]; + if (yyn == YYFLAG) + goto yydefault; + + /* Not known => get a lookahead token if don't already have one. */ + + /* yychar is either YYEMPTY or YYEOF + or a valid token in external form. */ + + if (yychar == YYEMPTY) + { +#if YYDEBUG != 0 + if (yydebug) + fprintf(stderr, "Reading a token: "); +#endif + yychar = YYLEX; + } + + /* Convert token to internal form (in yychar1) for indexing tables with */ + + if (yychar <= 0) /* This means end of input. */ + { + yychar1 = 0; + yychar = YYEOF; /* Don't call YYLEX any more */ + +#if YYDEBUG != 0 + if (yydebug) + fprintf(stderr, "Now at end of input.\n"); +#endif + } + else + { + yychar1 = YYTRANSLATE(yychar); + +#if YYDEBUG != 0 + if (yydebug) + { + fprintf (stderr, "Next token is %d (%s", yychar, yytname[yychar1]); + /* Give the individual parser a way to print the precise meaning + of a token, for further debugging info. */ +#ifdef YYPRINT + YYPRINT (stderr, yychar, yylval); +#endif + fprintf (stderr, ")\n"); + } +#endif + } + + yyn += yychar1; + if (yyn < 0 || yyn > YYLAST || yycheck[yyn] != yychar1) + goto yydefault; + + yyn = yytable[yyn]; + + /* yyn is what to do for this token type in this state. + Negative => reduce, -yyn is rule number. + Positive => shift, yyn is new state. + New state is final state => don't bother to shift, + just return success. + 0, or most negative number => error. */ + + if (yyn < 0) + { + if (yyn == YYFLAG) + goto yyerrlab; + yyn = -yyn; + goto yyreduce; + } + else if (yyn == 0) + goto yyerrlab; + + if (yyn == YYFINAL) + YYACCEPT; + + /* Shift the lookahead token. */ + +#if YYDEBUG != 0 + if (yydebug) + fprintf(stderr, "Shifting token %d (%s), ", yychar, yytname[yychar1]); +#endif + + /* Discard the token being shifted unless it is eof. */ + if (yychar != YYEOF) + yychar = YYEMPTY; + + *++yyvsp = yylval; +#ifdef YYLSP_NEEDED + *++yylsp = yylloc; +#endif + + /* count tokens shifted since error; after three, turn off error status. */ + if (yyerrstatus) yyerrstatus--; + + yystate = yyn; + goto yynewstate; + +/* Do the default action for the current state. */ +yydefault: + + yyn = yydefact[yystate]; + if (yyn == 0) + goto yyerrlab; + +/* Do a reduction. yyn is the number of a rule to reduce with. */ +yyreduce: + yylen = yyr2[yyn]; + if (yylen > 0) + yyval = yyvsp[1-yylen]; /* implement default value of the action */ + +#if YYDEBUG != 0 + if (yydebug) + { + int i; + + fprintf (stderr, "Reducing via rule %d (line %d), ", + yyn, yyrline[yyn]); + + /* Print the symbols being reduced, and their result. */ + for (i = yyprhs[yyn]; yyrhs[i] > 0; i++) + fprintf (stderr, "%s ", yytname[yyrhs[i]]); + fprintf (stderr, " -> %s\n", yytname[yyr1[yyn]]); + } +#endif + + + switch (yyn) { + +case 2: +#line 434 "llvmAsmParser.y" +{ + if (yyvsp[0].UIntVal > (uint32_t)INT32_MAX) // Outside of my range! + ThrowException("Value too large for type!"); + yyval.SIntVal = (int32_t)yyvsp[0].UIntVal; +; + break;} +case 4: +#line 442 "llvmAsmParser.y" +{ + if (yyvsp[0].UInt64Val > (uint64_t)INT64_MAX) // Outside of my range! + ThrowException("Value too large for type!"); + yyval.SInt64Val = (int64_t)yyvsp[0].UInt64Val; +; + break;} +case 46: +#line 472 "llvmAsmParser.y" +{ + yyval.StrVal = yyvsp[-1].StrVal; + ; + break;} +case 47: +#line 475 "llvmAsmParser.y" +{ + yyval.StrVal = 0; + ; + break;} +case 48: +#line 479 "llvmAsmParser.y" +{ // integral constants + if (!ConstPoolSInt::isValueValidForType(yyvsp[-1].TypeVal, yyvsp[0].SInt64Val)) + ThrowException("Constant value doesn't fit in type!"); + yyval.ConstVal = new ConstPoolSInt(yyvsp[-1].TypeVal, yyvsp[0].SInt64Val); + ; + break;} +case 49: +#line 484 "llvmAsmParser.y" +{ // integral constants + if (!ConstPoolUInt::isValueValidForType(yyvsp[-1].TypeVal, yyvsp[0].UInt64Val)) + ThrowException("Constant value doesn't fit in type!"); + yyval.ConstVal = new ConstPoolUInt(yyvsp[-1].TypeVal, yyvsp[0].UInt64Val); + ; + break;} +case 50: +#line 489 "llvmAsmParser.y" +{ // Boolean constants + yyval.ConstVal = new ConstPoolBool(true); + ; + break;} +case 51: +#line 492 "llvmAsmParser.y" +{ // Boolean constants + yyval.ConstVal = new ConstPoolBool(false); + ; + break;} +case 52: +#line 495 "llvmAsmParser.y" +{ // String constants + cerr << "FIXME: TODO: String constants [sbyte] not implemented yet!\n"; + abort(); + //$$ = new ConstPoolString($2); + free(yyvsp[0].StrVal); + ; + break;} +case 53: +#line 501 "llvmAsmParser.y" +{ // Type constants + yyval.ConstVal = new ConstPoolType(yyvsp[0].TypeVal); + ; + break;} +case 54: +#line 504 "llvmAsmParser.y" +{ // Nonempty array constant + // Verify all elements are correct type! + const ArrayType *AT = ArrayType::getArrayType(yyvsp[-4].TypeVal); + for (unsigned i = 0; i < yyvsp[-1].ConstVector->size(); i++) { + if (yyvsp[-4].TypeVal != (*yyvsp[-1].ConstVector)[i]->getType()) + ThrowException("Element #" + utostr(i) + " is not of type '" + + yyvsp[-4].TypeVal->getName() + "' as required!\nIt is of type '" + + (*yyvsp[-1].ConstVector)[i]->getType()->getName() + "'."); + } + + yyval.ConstVal = new ConstPoolArray(AT, *yyvsp[-1].ConstVector); + delete yyvsp[-1].ConstVector; + ; + break;} +case 55: +#line 517 "llvmAsmParser.y" +{ // Empty array constant + vector<ConstPoolVal*> Empty; + yyval.ConstVal = new ConstPoolArray(ArrayType::getArrayType(yyvsp[-3].TypeVal), Empty); + ; + break;} +case 56: +#line 521 "llvmAsmParser.y" +{ + // Verify all elements are correct type! + const ArrayType *AT = ArrayType::getArrayType(yyvsp[-4].TypeVal, (int)yyvsp[-6].UInt64Val); + if (yyvsp[-6].UInt64Val != yyvsp[-1].ConstVector->size()) + ThrowException("Type mismatch: constant sized array initialized with " + + utostr(yyvsp[-1].ConstVector->size()) + " arguments, but has size of " + + itostr((int)yyvsp[-6].UInt64Val) + "!"); + + for (unsigned i = 0; i < yyvsp[-1].ConstVector->size(); i++) { + if (yyvsp[-4].TypeVal != (*yyvsp[-1].ConstVector)[i]->getType()) + ThrowException("Element #" + utostr(i) + " is not of type '" + + yyvsp[-4].TypeVal->getName() + "' as required!\nIt is of type '" + + (*yyvsp[-1].ConstVector)[i]->getType()->getName() + "'."); + } + + yyval.ConstVal = new ConstPoolArray(AT, *yyvsp[-1].ConstVector); + delete yyvsp[-1].ConstVector; + ; + break;} +case 57: +#line 539 "llvmAsmParser.y" +{ + if (yyvsp[-5].UInt64Val != 0) + ThrowException("Type mismatch: constant sized array initialized with 0" + " arguments, but has size of " + itostr((int)yyvsp[-5].UInt64Val) + "!"); + vector<ConstPoolVal*> Empty; + yyval.ConstVal = new ConstPoolArray(ArrayType::getArrayType(yyvsp[-3].TypeVal, 0), Empty); + ; + break;} +case 58: +#line 546 "llvmAsmParser.y" +{ + StructType::ElementTypes Types(yyvsp[-4].TypeList->begin(), yyvsp[-4].TypeList->end()); + delete yyvsp[-4].TypeList; + + const StructType *St = StructType::getStructType(Types); + yyval.ConstVal = new ConstPoolStruct(St, *yyvsp[-1].ConstVector); + delete yyvsp[-1].ConstVector; + ; + break;} +case 59: +#line 554 "llvmAsmParser.y" +{ + const StructType *St = + StructType::getStructType(StructType::ElementTypes()); + vector<ConstPoolVal*> Empty; + yyval.ConstVal = new ConstPoolStruct(St, Empty); + ; + break;} +case 60: +#line 568 "llvmAsmParser.y" +{ + (yyval.ConstVector = yyvsp[-2].ConstVector)->push_back(addConstValToConstantPool(yyvsp[0].ConstVal)); + ; + break;} +case 61: +#line 571 "llvmAsmParser.y" +{ + yyval.ConstVector = new vector<ConstPoolVal*>(); + yyval.ConstVector->push_back(addConstValToConstantPool(yyvsp[0].ConstVal)); + ; + break;} +case 62: +#line 577 "llvmAsmParser.y" +{ + if (yyvsp[-1].StrVal) { + yyvsp[0].ConstVal->setName(yyvsp[-1].StrVal); + free(yyvsp[-1].StrVal); + } + + addConstValToConstantPool(yyvsp[0].ConstVal); + ; + break;} +case 63: +#line 585 "llvmAsmParser.y" +{ + ; + break;} +case 64: +#line 596 "llvmAsmParser.y" +{ + yyval.ModuleVal = ParserResult = yyvsp[0].ModuleVal; + CurModule.ModuleDone(); +; + break;} +case 65: +#line 601 "llvmAsmParser.y" +{ + yyvsp[-1].ModuleVal->getMethodList().push_back(yyvsp[0].MethodVal); + CurMeth.MethodDone(); + yyval.ModuleVal = yyvsp[-1].ModuleVal; + ; + break;} +case 66: +#line 606 "llvmAsmParser.y" +{ + yyval.ModuleVal = CurModule.CurrentModule; + ; + break;} +case 68: +#line 615 "llvmAsmParser.y" +{ yyval.StrVal = 0; ; + break;} +case 69: +#line 617 "llvmAsmParser.y" +{ + yyval.MethArgVal = new MethodArgument(yyvsp[-1].TypeVal); + if (yyvsp[0].StrVal) { // Was the argument named? + yyval.MethArgVal->setName(yyvsp[0].StrVal); + free(yyvsp[0].StrVal); // The string was strdup'd, so free it now. + } +; + break;} +case 70: +#line 625 "llvmAsmParser.y" +{ + yyval.MethodArgList = yyvsp[0].MethodArgList; + yyvsp[0].MethodArgList->push_front(yyvsp[-2].MethArgVal); + ; + break;} +case 71: +#line 629 "llvmAsmParser.y" +{ + yyval.MethodArgList = new list<MethodArgument*>(); + yyval.MethodArgList->push_front(yyvsp[0].MethArgVal); + ; + break;} +case 72: +#line 634 "llvmAsmParser.y" +{ + yyval.MethodArgList = yyvsp[0].MethodArgList; + ; + break;} +case 73: +#line 637 "llvmAsmParser.y" +{ + yyval.MethodArgList = 0; + ; + break;} +case 74: +#line 641 "llvmAsmParser.y" +{ + MethodType::ParamTypes ParamTypeList; + if (yyvsp[-1].MethodArgList) + for (list<MethodArgument*>::iterator I = yyvsp[-1].MethodArgList->begin(); I != yyvsp[-1].MethodArgList->end(); I++) + ParamTypeList.push_back((*I)->getType()); + + const MethodType *MT = MethodType::getMethodType(yyvsp[-4].TypeVal, ParamTypeList); + + Method *M = new Method(MT, yyvsp[-3].StrVal); + free(yyvsp[-3].StrVal); // Free strdup'd memory! + + InsertValue(M, CurModule.Values); + + CurMeth.MethodStart(M); + + // Add all of the arguments we parsed to the method... + if (yyvsp[-1].MethodArgList) { // Is null if empty... + Method::ArgumentListType &ArgList = M->getArgumentList(); + + for (list<MethodArgument*>::iterator I = yyvsp[-1].MethodArgList->begin(); I != yyvsp[-1].MethodArgList->end(); I++) { + InsertValue(*I); + ArgList.push_back(*I); + } + delete yyvsp[-1].MethodArgList; // We're now done with the argument list + } +; + break;} +case 75: +#line 668 "llvmAsmParser.y" +{ + yyval.MethodVal = CurMeth.CurrentMethod; +; + break;} +case 76: +#line 672 "llvmAsmParser.y" +{ + yyval.MethodVal = yyvsp[-1].MethodVal; +; + break;} +case 77: +#line 681 "llvmAsmParser.y" +{ // A reference to a direct constant + yyval.ValIDVal = ValID::create(yyvsp[0].SInt64Val); + ; + break;} +case 78: +#line 684 "llvmAsmParser.y" +{ + yyval.ValIDVal = ValID::create(yyvsp[0].UInt64Val); + ; + break;} +case 79: +#line 687 "llvmAsmParser.y" +{ + yyval.ValIDVal = ValID::create((int64_t)1); + ; + break;} +case 80: +#line 690 "llvmAsmParser.y" +{ + yyval.ValIDVal = ValID::create((int64_t)0); + ; + break;} +case 81: +#line 693 "llvmAsmParser.y" +{ // Quoted strings work too... especially for methods + yyval.ValIDVal = ValID::create_conststr(yyvsp[0].StrVal); + ; + break;} +case 82: +#line 698 "llvmAsmParser.y" +{ // Is it an integer reference...? + yyval.ValIDVal = ValID::create(yyvsp[0].SIntVal); + ; + break;} +case 83: +#line 701 "llvmAsmParser.y" +{ // It must be a named reference then... + yyval.ValIDVal = ValID::create(yyvsp[0].StrVal); + ; + break;} +case 84: +#line 704 "llvmAsmParser.y" +{ + yyval.ValIDVal = yyvsp[0].ValIDVal; + ; + break;} +case 85: +#line 711 "llvmAsmParser.y" +{ + Value *D = getVal(Type::TypeTy, yyvsp[0].ValIDVal, true); + if (D == 0) ThrowException("Invalid user defined type: " + yyvsp[0].ValIDVal.getName()); + assert (D->getValueType() == Value::ConstantVal && + "Internal error! User defined type not in const pool!"); + ConstPoolType *CPT = (ConstPoolType*)D; + yyval.TypeVal = CPT->getValue(); + ; + break;} +case 86: +#line 719 "llvmAsmParser.y" +{ // Method derived type? + MethodType::ParamTypes Params(yyvsp[-1].TypeList->begin(), yyvsp[-1].TypeList->end()); + delete yyvsp[-1].TypeList; + yyval.TypeVal = MethodType::getMethodType(yyvsp[-3].TypeVal, Params); + ; + break;} +case 87: +#line 724 "llvmAsmParser.y" +{ // Method derived type? + MethodType::ParamTypes Params; // Empty list + yyval.TypeVal = MethodType::getMethodType(yyvsp[-2].TypeVal, Params); + ; + break;} +case 88: +#line 728 "llvmAsmParser.y" +{ + yyval.TypeVal = ArrayType::getArrayType(yyvsp[-1].TypeVal); + ; + break;} +case 89: +#line 731 "llvmAsmParser.y" +{ + yyval.TypeVal = ArrayType::getArrayType(yyvsp[-1].TypeVal, (int)yyvsp[-3].UInt64Val); + ; + break;} +case 90: +#line 734 "llvmAsmParser.y" +{ + StructType::ElementTypes Elements(yyvsp[-1].TypeList->begin(), yyvsp[-1].TypeList->end()); + delete yyvsp[-1].TypeList; + yyval.TypeVal = StructType::getStructType(Elements); + ; + break;} +case 91: +#line 739 "llvmAsmParser.y" +{ + yyval.TypeVal = StructType::getStructType(StructType::ElementTypes()); + ; + break;} +case 92: +#line 742 "llvmAsmParser.y" +{ + yyval.TypeVal = PointerType::getPointerType(yyvsp[-1].TypeVal); + ; + break;} +case 93: +#line 747 "llvmAsmParser.y" +{ + yyval.TypeList = new list<const Type*>(); + yyval.TypeList->push_back(yyvsp[0].TypeVal); + ; + break;} +case 94: +#line 751 "llvmAsmParser.y" +{ + (yyval.TypeList=yyvsp[-2].TypeList)->push_back(yyvsp[0].TypeVal); + ; + break;} +case 95: +#line 756 "llvmAsmParser.y" +{ + yyvsp[-1].MethodVal->getBasicBlocks().push_back(yyvsp[0].BasicBlockVal); + yyval.MethodVal = yyvsp[-1].MethodVal; + ; + break;} +case 96: +#line 760 "llvmAsmParser.y" +{ // Do not allow methods with 0 basic blocks + yyval.MethodVal = yyvsp[-1].MethodVal; // in them... + yyvsp[-1].MethodVal->getBasicBlocks().push_back(yyvsp[0].BasicBlockVal); + ; + break;} +case 97: +#line 769 "llvmAsmParser.y" +{ + yyvsp[-1].BasicBlockVal->getInstList().push_back(yyvsp[0].TermInstVal); + InsertValue(yyvsp[-1].BasicBlockVal); + yyval.BasicBlockVal = yyvsp[-1].BasicBlockVal; + ; + break;} +case 98: +#line 774 "llvmAsmParser.y" +{ + yyvsp[-1].BasicBlockVal->getInstList().push_back(yyvsp[0].TermInstVal); + yyvsp[-1].BasicBlockVal->setName(yyvsp[-2].StrVal); + free(yyvsp[-2].StrVal); // Free the strdup'd memory... + + InsertValue(yyvsp[-1].BasicBlockVal); + yyval.BasicBlockVal = yyvsp[-1].BasicBlockVal; + ; + break;} +case 99: +#line 783 "llvmAsmParser.y" +{ + yyvsp[-1].BasicBlockVal->getInstList().push_back(yyvsp[0].InstVal); + yyval.BasicBlockVal = yyvsp[-1].BasicBlockVal; + ; + break;} +case 100: +#line 787 "llvmAsmParser.y" +{ + yyval.BasicBlockVal = new BasicBlock(); + ; + break;} +case 101: +#line 791 "llvmAsmParser.y" +{ // Return with a result... + yyval.TermInstVal = new ReturnInst(getVal(yyvsp[-1].TypeVal, yyvsp[0].ValIDVal)); + ; + break;} +case 102: +#line 794 "llvmAsmParser.y" +{ // Return with no result... + yyval.TermInstVal = new ReturnInst(); + ; + break;} +case 103: +#line 797 "llvmAsmParser.y" +{ // Unconditional Branch... + yyval.TermInstVal = new BranchInst((BasicBlock*)getVal(Type::LabelTy, yyvsp[0].ValIDVal)); + ; + break;} +case 104: +#line 800 "llvmAsmParser.y" +{ + yyval.TermInstVal = new BranchInst((BasicBlock*)getVal(Type::LabelTy, yyvsp[-3].ValIDVal), + (BasicBlock*)getVal(Type::LabelTy, yyvsp[0].ValIDVal), + getVal(Type::BoolTy, yyvsp[-6].ValIDVal)); + ; + break;} +case 105: +#line 805 "llvmAsmParser.y" +{ + SwitchInst *S = new SwitchInst(getVal(yyvsp[-7].TypeVal, yyvsp[-6].ValIDVal), + (BasicBlock*)getVal(Type::LabelTy, yyvsp[-3].ValIDVal)); + yyval.TermInstVal = S; + + list<pair<ConstPoolVal*, BasicBlock*> >::iterator I = yyvsp[-1].JumpTable->begin(), + end = yyvsp[-1].JumpTable->end(); + for (; I != end; I++) + S->dest_push_back(I->first, I->second); + ; + break;} +case 106: +#line 816 "llvmAsmParser.y" +{ + yyval.JumpTable = yyvsp[-5].JumpTable; + ConstPoolVal *V = (ConstPoolVal*)getVal(yyvsp[-4].TypeVal, yyvsp[-3].ValIDVal, true); + if (V == 0) + ThrowException("May only switch on a constant pool value!"); + + yyval.JumpTable->push_back(make_pair(V, (BasicBlock*)getVal(yyvsp[-1].TypeVal, yyvsp[0].ValIDVal))); + ; + break;} +case 107: +#line 824 "llvmAsmParser.y" +{ + yyval.JumpTable = new list<pair<ConstPoolVal*, BasicBlock*> >(); + ConstPoolVal *V = (ConstPoolVal*)getVal(yyvsp[-4].TypeVal, yyvsp[-3].ValIDVal, true); + + if (V == 0) + ThrowException("May only switch on a constant pool value!"); + + yyval.JumpTable->push_back(make_pair(V, (BasicBlock*)getVal(yyvsp[-1].TypeVal, yyvsp[0].ValIDVal))); + ; + break;} +case 108: +#line 834 "llvmAsmParser.y" +{ + if (yyvsp[-1].StrVal) // Is this definition named?? + yyvsp[0].InstVal->setName(yyvsp[-1].StrVal); // if so, assign the name... + + InsertValue(yyvsp[0].InstVal); + yyval.InstVal = yyvsp[0].InstVal; +; + break;} +case 109: +#line 842 "llvmAsmParser.y" +{ // Used for PHI nodes and call statements... + yyval.ValueList = new list<Value*>(); + yyval.ValueList->push_back(getVal(yyvsp[-1].TypeVal, yyvsp[0].ValIDVal)); + ; + break;} +case 110: +#line 846 "llvmAsmParser.y" +{ + yyval.ValueList = yyvsp[-2].ValueList; + yyvsp[-2].ValueList->push_back(getVal(yyvsp[-2].ValueList->front()->getType(), yyvsp[0].ValIDVal)); + ; + break;} +case 112: +#line 852 "llvmAsmParser.y" +{ yyval.ValueList = 0; ; + break;} +case 113: +#line 854 "llvmAsmParser.y" +{ + yyval.InstVal = Instruction::getBinaryOperator(yyvsp[-4].BinaryOpVal, getVal(yyvsp[-3].TypeVal, yyvsp[-2].ValIDVal), getVal(yyvsp[-3].TypeVal, yyvsp[0].ValIDVal)); + if (yyval.InstVal == 0) + ThrowException("binary operator returned null!"); + ; + break;} +case 114: +#line 859 "llvmAsmParser.y" +{ + yyval.InstVal = Instruction::getUnaryOperator(yyvsp[-2].UnaryOpVal, getVal(yyvsp[-1].TypeVal, yyvsp[0].ValIDVal)); + if (yyval.InstVal == 0) + ThrowException("unary operator returned null!"); + ; + break;} +case 115: +#line 864 "llvmAsmParser.y" +{ + yyval.InstVal = new PHINode(yyvsp[0].ValueList->front()->getType()); + while (yyvsp[0].ValueList->begin() != yyvsp[0].ValueList->end()) { + // TODO: Ensure all types are the same... + ((PHINode*)yyval.InstVal)->addIncoming(yyvsp[0].ValueList->front()); + yyvsp[0].ValueList->pop_front(); + } + delete yyvsp[0].ValueList; // Free the list... + ; + break;} +case 116: +#line 873 "llvmAsmParser.y" +{ + if (!yyvsp[-4].TypeVal->isMethodType()) + ThrowException("Can only call methods: invalid type '" + + yyvsp[-4].TypeVal->getName() + "'!"); + + const MethodType *Ty = (const MethodType*)yyvsp[-4].TypeVal; + + Value *V = getVal(Ty, yyvsp[-3].ValIDVal); + if (V->getValueType() != Value::MethodVal || V->getType() != Ty) + ThrowException("Cannot call: " + yyvsp[-3].ValIDVal.getName() + "!"); + + // Create or access a new type that corresponds to the function call... + vector<Value *> Params; + + if (yyvsp[-1].ValueList) { + // Pull out just the arguments... + Params.insert(Params.begin(), yyvsp[-1].ValueList->begin(), yyvsp[-1].ValueList->end()); + delete yyvsp[-1].ValueList; + + // Loop through MethodType's arguments and ensure they are specified + // correctly! + // + MethodType::ParamTypes::const_iterator I = Ty->getParamTypes().begin(); + unsigned i; + for (i = 0; i < Params.size() && I != Ty->getParamTypes().end(); ++i,++I){ + if (Params[i]->getType() != *I) + ThrowException("Parameter " + utostr(i) + " is not of type '" + + (*I)->getName() + "'!"); + } + + if (i != Params.size() || I != Ty->getParamTypes().end()) + ThrowException("Invalid number of parameters detected!"); + } + + // Create the call node... + yyval.InstVal = new CallInst((Method*)V, Params); + ; + break;} +case 117: +#line 910 "llvmAsmParser.y" +{ + yyval.InstVal = yyvsp[0].InstVal; + ; + break;} +case 118: +#line 914 "llvmAsmParser.y" +{ + ConstPoolVal *TyVal = new ConstPoolType(PointerType::getPointerType(yyvsp[0].TypeVal)); + TyVal = addConstValToConstantPool(TyVal); + yyval.InstVal = new MallocInst((ConstPoolType*)TyVal); + ; + break;} +case 119: +#line 919 "llvmAsmParser.y" +{ + if (!yyvsp[-3].TypeVal->isArrayType() || ((const ArrayType*)yyvsp[-3].TypeVal)->isSized()) + ThrowException("Trying to allocate " + yyvsp[-3].TypeVal->getName() + + " as unsized array!"); + + Value *ArrSize = getVal(yyvsp[-1].TypeVal, yyvsp[0].ValIDVal); + ConstPoolVal *TyVal = new ConstPoolType(PointerType::getPointerType(yyvsp[-3].TypeVal)); + TyVal = addConstValToConstantPool(TyVal); + yyval.InstVal = new MallocInst((ConstPoolType*)TyVal, ArrSize); + ; + break;} +case 120: +#line 929 "llvmAsmParser.y" +{ + ConstPoolVal *TyVal = new ConstPoolType(PointerType::getPointerType(yyvsp[0].TypeVal)); + TyVal = addConstValToConstantPool(TyVal); + yyval.InstVal = new AllocaInst((ConstPoolType*)TyVal); + ; + break;} +case 121: +#line 934 "llvmAsmParser.y" +{ + if (!yyvsp[-3].TypeVal->isArrayType() || ((const ArrayType*)yyvsp[-3].TypeVal)->isSized()) + ThrowException("Trying to allocate " + yyvsp[-3].TypeVal->getName() + + " as unsized array!"); + + Value *ArrSize = getVal(yyvsp[-1].TypeVal, yyvsp[0].ValIDVal); + ConstPoolVal *TyVal = new ConstPoolType(PointerType::getPointerType(yyvsp[-3].TypeVal)); + TyVal = addConstValToConstantPool(TyVal); + yyval.InstVal = new AllocaInst((ConstPoolType*)TyVal, ArrSize); + ; + break;} +case 122: +#line 944 "llvmAsmParser.y" +{ + if (!yyvsp[-1].TypeVal->isPointerType()) + ThrowException("Trying to free nonpointer type " + yyvsp[-1].TypeVal->getName() + "!"); + yyval.InstVal = new FreeInst(getVal(yyvsp[-1].TypeVal, yyvsp[0].ValIDVal)); + ; + break;} +} + /* the action file gets copied in in place of this dollarsign */ +#line 543 "/usr/dcs/software/supported/encap/bison-1.28/share/bison.simple" + + yyvsp -= yylen; + yyssp -= yylen; +#ifdef YYLSP_NEEDED + yylsp -= yylen; +#endif + +#if YYDEBUG != 0 + if (yydebug) + { + short *ssp1 = yyss - 1; + fprintf (stderr, "state stack now"); + while (ssp1 != yyssp) + fprintf (stderr, " %d", *++ssp1); + fprintf (stderr, "\n"); + } +#endif + + *++yyvsp = yyval; + +#ifdef YYLSP_NEEDED + yylsp++; + if (yylen == 0) + { + yylsp->first_line = yylloc.first_line; + yylsp->first_column = yylloc.first_column; + yylsp->last_line = (yylsp-1)->last_line; + yylsp->last_column = (yylsp-1)->last_column; + yylsp->text = 0; + } + else + { + yylsp->last_line = (yylsp+yylen-1)->last_line; + yylsp->last_column = (yylsp+yylen-1)->last_column; + } +#endif + + /* Now "shift" the result of the reduction. + Determine what state that goes to, + based on the state we popped back to + and the rule number reduced by. */ + + yyn = yyr1[yyn]; + + yystate = yypgoto[yyn - YYNTBASE] + *yyssp; + if (yystate >= 0 && yystate <= YYLAST && yycheck[yystate] == *yyssp) + yystate = yytable[yystate]; + else + yystate = yydefgoto[yyn - YYNTBASE]; + + goto yynewstate; + +yyerrlab: /* here on detecting error */ + + if (! yyerrstatus) + /* If not already recovering from an error, report this error. */ + { + ++yynerrs; + +#ifdef YYERROR_VERBOSE + yyn = yypact[yystate]; + + if (yyn > YYFLAG && yyn < YYLAST) + { + int size = 0; + char *msg; + int x, count; + + count = 0; + /* Start X at -yyn if nec to avoid negative indexes in yycheck. */ + for (x = (yyn < 0 ? -yyn : 0); + x < (sizeof(yytname) / sizeof(char *)); x++) + if (yycheck[x + yyn] == x) + size += strlen(yytname[x]) + 15, count++; + msg = (char *) malloc(size + 15); + if (msg != 0) + { + strcpy(msg, "parse error"); + + if (count < 5) + { + count = 0; + for (x = (yyn < 0 ? -yyn : 0); + x < (sizeof(yytname) / sizeof(char *)); x++) + if (yycheck[x + yyn] == x) + { + strcat(msg, count == 0 ? ", expecting `" : " or `"); + strcat(msg, yytname[x]); + strcat(msg, "'"); + count++; + } + } + yyerror(msg); + free(msg); + } + else + yyerror ("parse error; also virtual memory exceeded"); + } + else +#endif /* YYERROR_VERBOSE */ + yyerror("parse error"); + } + + goto yyerrlab1; +yyerrlab1: /* here on error raised explicitly by an action */ + + if (yyerrstatus == 3) + { + /* if just tried and failed to reuse lookahead token after an error, discard it. */ + + /* return failure if at end of input */ + if (yychar == YYEOF) + YYABORT; + +#if YYDEBUG != 0 + if (yydebug) + fprintf(stderr, "Discarding token %d (%s).\n", yychar, yytname[yychar1]); +#endif + + yychar = YYEMPTY; + } + + /* Else will try to reuse lookahead token + after shifting the error token. */ + + yyerrstatus = 3; /* Each real token shifted decrements this */ + + goto yyerrhandle; + +yyerrdefault: /* current state does not do anything special for the error token. */ + +#if 0 + /* This is wrong; only states that explicitly want error tokens + should shift them. */ + yyn = yydefact[yystate]; /* If its default is to accept any token, ok. Otherwise pop it.*/ + if (yyn) goto yydefault; +#endif + +yyerrpop: /* pop the current state because it cannot handle the error token */ + + if (yyssp == yyss) YYABORT; + yyvsp--; + yystate = *--yyssp; +#ifdef YYLSP_NEEDED + yylsp--; +#endif + +#if YYDEBUG != 0 + if (yydebug) + { + short *ssp1 = yyss - 1; + fprintf (stderr, "Error: state stack now"); + while (ssp1 != yyssp) + fprintf (stderr, " %d", *++ssp1); + fprintf (stderr, "\n"); + } +#endif + +yyerrhandle: + + yyn = yypact[yystate]; + if (yyn == YYFLAG) + goto yyerrdefault; + + yyn += YYTERROR; + if (yyn < 0 || yyn > YYLAST || yycheck[yyn] != YYTERROR) + goto yyerrdefault; + + yyn = yytable[yyn]; + if (yyn < 0) + { + if (yyn == YYFLAG) + goto yyerrpop; + yyn = -yyn; + goto yyreduce; + } + else if (yyn == 0) + goto yyerrpop; + + if (yyn == YYFINAL) + YYACCEPT; + +#if YYDEBUG != 0 + if (yydebug) + fprintf(stderr, "Shifting error token, "); +#endif + + *++yyvsp = yylval; +#ifdef YYLSP_NEEDED + *++yylsp = yylloc; +#endif + + yystate = yyn; + goto yynewstate; + + yyacceptlab: + /* YYACCEPT comes here. */ + if (yyfree_stacks) + { + free (yyss); + free (yyvs); +#ifdef YYLSP_NEEDED + free (yyls); +#endif + } + return 0; + + yyabortlab: + /* YYABORT comes here. */ + if (yyfree_stacks) + { + free (yyss); + free (yyvs); +#ifdef YYLSP_NEEDED + free (yyls); +#endif + } + return 1; +} +#line 950 "llvmAsmParser.y" + +int yyerror(char *ErrorMsg) { + ThrowException(string("Parse error: ") + ErrorMsg); + return 0; +} diff --git a/lib/AsmParser/llvmAsmParser.h b/lib/AsmParser/llvmAsmParser.h new file mode 100644 index 0000000..64e460f --- /dev/null +++ b/lib/AsmParser/llvmAsmParser.h @@ -0,0 +1,87 @@ +typedef union { + Module *ModuleVal; + Method *MethodVal; + MethodArgument *MethArgVal; + BasicBlock *BasicBlockVal; + TerminatorInst *TermInstVal; + Instruction *InstVal; + ConstPoolVal *ConstVal; + const Type *TypeVal; + + list<MethodArgument*> *MethodArgList; + list<Value*> *ValueList; + list<const Type*> *TypeList; + list<pair<ConstPoolVal*, BasicBlock*> > *JumpTable; + vector<ConstPoolVal*> *ConstVector; + + int64_t SInt64Val; + uint64_t UInt64Val; + int SIntVal; + unsigned UIntVal; + + char *StrVal; // This memory is allocated by strdup! + ValID ValIDVal; // May contain memory allocated by strdup + + Instruction::UnaryOps UnaryOpVal; + Instruction::BinaryOps BinaryOpVal; + Instruction::TermOps TermOpVal; + Instruction::MemoryOps MemOpVal; +} YYSTYPE; +#define ESINT64VAL 257 +#define EUINT64VAL 258 +#define SINTVAL 259 +#define UINTVAL 260 +#define VOID 261 +#define BOOL 262 +#define SBYTE 263 +#define UBYTE 264 +#define SHORT 265 +#define USHORT 266 +#define INT 267 +#define UINT 268 +#define LONG 269 +#define ULONG 270 +#define FLOAT 271 +#define DOUBLE 272 +#define STRING 273 +#define TYPE 274 +#define LABEL 275 +#define VAR_ID 276 +#define LABELSTR 277 +#define STRINGCONSTANT 278 +#define IMPLEMENTATION 279 +#define TRUE 280 +#define FALSE 281 +#define BEGINTOK 282 +#define END 283 +#define DECLARE 284 +#define PHI 285 +#define CALL 286 +#define RET 287 +#define BR 288 +#define SWITCH 289 +#define NEG 290 +#define NOT 291 +#define TOINT 292 +#define TOUINT 293 +#define ADD 294 +#define SUB 295 +#define MUL 296 +#define DIV 297 +#define REM 298 +#define SETLE 299 +#define SETGE 300 +#define SETLT 301 +#define SETGT 302 +#define SETEQ 303 +#define SETNE 304 +#define MALLOC 305 +#define ALLOCA 306 +#define FREE 307 +#define LOAD 308 +#define STORE 309 +#define GETFIELD 310 +#define PUTFIELD 311 + + +extern YYSTYPE llvmAsmlval; diff --git a/lib/AsmParser/llvmAsmParser.y b/lib/AsmParser/llvmAsmParser.y new file mode 100644 index 0000000..01709ca --- /dev/null +++ b/lib/AsmParser/llvmAsmParser.y @@ -0,0 +1,954 @@ +//===-- llvmAsmParser.y - Parser for llvm assembly files ---------*- C++ -*--=// +// +// This file implements the bison parser for LLVM assembly languages files. +// +//===------------------------------------------------------------------------=// + +// +// TODO: Parse comments and add them to an internal node... so that they may +// be saved in the bytecode format as well as everything else. Very important +// for a general IR format. +// + +%{ +#include "ParserInternals.h" +#include "llvm/BasicBlock.h" +#include "llvm/Method.h" +#include "llvm/SymbolTable.h" +#include "llvm/Module.h" +#include "llvm/Type.h" +#include "llvm/DerivedTypes.h" +#include "llvm/Assembly/Parser.h" +#include "llvm/ConstantPool.h" +#include "llvm/iTerminators.h" +#include "llvm/iMemory.h" +#include <list> +#include <utility> // Get definition of pair class +#include <stdio.h> // This embarasment is due to our flex lexer... + +int yyerror(char *ErrorMsg); // Forward declarations to prevent "implicit +int yylex(); // declaration" of xxx warnings. +int yyparse(); + +static Module *ParserResult; +const ToolCommandLine *CurOptions = 0; + +// This contains info used when building the body of a method. It is destroyed +// when the method is completed. +// +typedef vector<Value *> ValueList; // Numbered defs +static void ResolveDefinitions(vector<ValueList> &LateResolvers); + +static struct PerModuleInfo { + Module *CurrentModule; + vector<ValueList> Values; // Module level numbered definitions + vector<ValueList> LateResolveValues; + + void ModuleDone() { + // If we could not resolve some blocks at parsing time (forward branches) + // resolve the branches now... + ResolveDefinitions(LateResolveValues); + + Values.clear(); // Clear out method local definitions + CurrentModule = 0; + } +} CurModule; + +static struct PerMethodInfo { + Method *CurrentMethod; // Pointer to current method being created + + vector<ValueList> Values; // Keep track of numbered definitions + vector<ValueList> LateResolveValues; + + inline PerMethodInfo() { + CurrentMethod = 0; + } + + inline ~PerMethodInfo() {} + + inline void MethodStart(Method *M) { + CurrentMethod = M; + } + + void MethodDone() { + // If we could not resolve some blocks at parsing time (forward branches) + // resolve the branches now... + ResolveDefinitions(LateResolveValues); + + Values.clear(); // Clear out method local definitions + CurrentMethod = 0; + } +} CurMeth; // Info for the current method... + + +//===----------------------------------------------------------------------===// +// Code to handle definitions of all the types +//===----------------------------------------------------------------------===// + +static void InsertValue(Value *D, vector<ValueList> &ValueTab = CurMeth.Values) { + if (!D->hasName()) { // Is this a numbered definition? + unsigned type = D->getType()->getUniqueID(); + if (ValueTab.size() <= type) + ValueTab.resize(type+1, ValueList()); + //printf("Values[%d][%d] = %d\n", type, ValueTab[type].size(), D); + ValueTab[type].push_back(D); + } +} + +static Value *getVal(const Type *Type, ValID &D, + bool DoNotImprovise = false) { + switch (D.Type) { + case 0: { // Is it a numbered definition? + unsigned type = Type->getUniqueID(); + unsigned Num = (unsigned)D.Num; + + // Module constants occupy the lowest numbered slots... + if (type < CurModule.Values.size()) { + if (Num < CurModule.Values[type].size()) + return CurModule.Values[type][Num]; + + Num -= CurModule.Values[type].size(); + } + + // Make sure that our type is within bounds + if (CurMeth.Values.size() <= type) + break; + + // Check that the number is within bounds... + if (CurMeth.Values[type].size() <= Num) + break; + + return CurMeth.Values[type][Num]; + } + case 1: { // Is it a named definition? + string Name(D.Name); + SymbolTable *SymTab = 0; + if (CurMeth.CurrentMethod) + SymTab = CurMeth.CurrentMethod->getSymbolTable(); + Value *N = SymTab ? SymTab->lookup(Type, Name) : 0; + + if (N == 0) { + SymTab = CurModule.CurrentModule->getSymbolTable(); + if (SymTab) + N = SymTab->lookup(Type, Name); + if (N == 0) break; + } + + D.destroy(); // Free old strdup'd memory... + return N; + } + + case 2: // Is it a constant pool reference?? + case 3: // Is it an unsigned const pool reference? + case 4:{ // Is it a string const pool reference? + ConstPoolVal *CPV = 0; + + // Check to make sure that "Type" is an integral type, and that our + // value will fit into the specified type... + switch (D.Type) { + case 2: + if (Type == Type::BoolTy) { // Special handling for boolean data + CPV = new ConstPoolBool(D.ConstPool64 != 0); + } else { + if (!ConstPoolSInt::isValueValidForType(Type, D.ConstPool64)) + ThrowException("Symbolic constant pool reference is invalid!"); + CPV = new ConstPoolSInt(Type, D.ConstPool64); + } + break; + case 3: + if (!ConstPoolUInt::isValueValidForType(Type, D.UConstPool64)) { + if (!ConstPoolSInt::isValueValidForType(Type, D.ConstPool64)) { + ThrowException("Symbolic constant pool reference is invalid!"); + } else { // This is really a signed reference. Transmogrify. + CPV = new ConstPoolSInt(Type, D.ConstPool64); + } + } else { + CPV = new ConstPoolUInt(Type, D.UConstPool64); + } + break; + case 4: + cerr << "FIXME: TODO: String constants [sbyte] not implemented yet!\n"; + abort(); + //CPV = new ConstPoolString(D.Name); + D.destroy(); // Free the string memory + break; + } + assert(CPV && "How did we escape creating a constant??"); + + // Scan through the constant table and see if we already have loaded this + // constant. + // + ConstantPool &CP = CurMeth.CurrentMethod ? + CurMeth.CurrentMethod->getConstantPool() : + CurModule.CurrentModule->getConstantPool(); + ConstPoolVal *C = CP.find(CPV); // Already have this constant? + if (C) { + delete CPV; // Didn't need this after all, oh well. + return C; // Yup, we already have one, recycle it! + } + CP.insert(CPV); + + // Success, everything is kosher. Lets go! + return CPV; + } // End of case 2,3,4 + } // End of switch + + + // If we reached here, we referenced either a symbol that we don't know about + // or an id number that hasn't been read yet. We may be referencing something + // forward, so just create an entry to be resolved later and get to it... + // + if (DoNotImprovise) return 0; // Do we just want a null to be returned? + + // TODO: Attempt to coallecse nodes that are the same with previous ones. + Value *d = 0; + switch (Type->getPrimitiveID()) { + case Type::LabelTyID: d = new BBPlaceHolder(Type, D); break; + case Type::MethodTyID: + d = new MethPlaceHolder(Type, D); + InsertValue(d, CurModule.LateResolveValues); + return d; +//case Type::ClassTyID: d = new ClassPlaceHolder(Type, D); break; + default: d = new DefPlaceHolder(Type, D); break; + } + + assert(d != 0 && "How did we not make something?"); + InsertValue(d, CurMeth.LateResolveValues); + return d; +} + + +//===----------------------------------------------------------------------===// +// Code to handle forward references in instructions +//===----------------------------------------------------------------------===// +// +// This code handles the late binding needed with statements that reference +// values not defined yet... for example, a forward branch, or the PHI node for +// a loop body. +// +// This keeps a table (CurMeth.LateResolveValues) of all such forward references +// and back patchs after we are done. +// + +// ResolveDefinitions - If we could not resolve some defs at parsing +// time (forward branches, phi functions for loops, etc...) resolve the +// defs now... +// +static void ResolveDefinitions(vector<ValueList> &LateResolvers) { + // Loop over LateResolveDefs fixing up stuff that couldn't be resolved + for (unsigned ty = 0; ty < LateResolvers.size(); ty++) { + while (!LateResolvers[ty].empty()) { + Value *V = LateResolvers[ty].back(); + LateResolvers[ty].pop_back(); + ValID &DID = getValIDFromPlaceHolder(V); + + Value *TheRealValue = getVal(Type::getUniqueIDType(ty), DID, true); + + if (TheRealValue == 0 && DID.Type == 1) + ThrowException("Reference to an invalid definition: '" +DID.getName() + + "' of type '" + V->getType()->getName() + "'"); + else if (TheRealValue == 0) + ThrowException("Reference to an invalid definition: #" +itostr(DID.Num)+ + " of type '" + V->getType()->getName() + "'"); + + V->replaceAllUsesWith(TheRealValue); + assert(V->use_empty()); + delete V; + } + } + + LateResolvers.clear(); +} + +// addConstValToConstantPool - This code is used to insert a constant into the +// current constant pool. This is designed to make maximal (but not more than +// possible) reuse (merging) of constants in the constant pool. This means that +// multiple references to %4, for example will all get merged. +// +static ConstPoolVal *addConstValToConstantPool(ConstPoolVal *C) { + vector<ValueList> &ValTab = CurMeth.CurrentMethod ? + CurMeth.Values : CurModule.Values; + ConstantPool &CP = CurMeth.CurrentMethod ? + CurMeth.CurrentMethod->getConstantPool() : + CurModule.CurrentModule->getConstantPool(); + + if (ConstPoolVal *CPV = CP.find(C)) { + // Constant already in constant pool. Try to merge the two constants + if (CPV->hasName() && !C->hasName()) { + // Merge the two values, we inherit the existing CPV's name. + // InsertValue requires that the value have no name to insert correctly + // (because we want to fill the slot this constant would have filled) + // + string Name = CPV->getName(); + CPV->setName(""); + InsertValue(CPV, ValTab); + CPV->setName(Name); + delete C; + return CPV; + } else if (!CPV->hasName() && C->hasName()) { + // If we have a name on this value and there isn't one in the const + // pool val already, propogate it. + // + CPV->setName(C->getName()); + delete C; // Sorry, you're toast + return CPV; + } else if (CPV->hasName() && C->hasName()) { + // Both values have distinct names. We cannot merge them. + CP.insert(C); + InsertValue(C, ValTab); + return C; + } else if (!CPV->hasName() && !C->hasName()) { + // Neither value has a name, trivially merge them. + InsertValue(CPV, ValTab); + delete C; + return CPV; + } + + assert(0 && "Not reached!"); + return 0; + } else { // No duplication of value. + CP.insert(C); + InsertValue(C, ValTab); + return C; + } +} + +//===----------------------------------------------------------------------===// +// RunVMAsmParser - Define an interface to this parser +//===----------------------------------------------------------------------===// +// +Module *RunVMAsmParser(const ToolCommandLine &Opts, FILE *F) { + llvmAsmin = F; + CurOptions = &Opts; + llvmAsmlineno = 1; // Reset the current line number... + + CurModule.CurrentModule = new Module(); // Allocate a new module to read + yyparse(); // Parse the file. + Module *Result = ParserResult; + CurOptions = 0; + llvmAsmin = stdin; // F is about to go away, don't use it anymore... + ParserResult = 0; + + return Result; +} + +%} + +%union { + Module *ModuleVal; + Method *MethodVal; + MethodArgument *MethArgVal; + BasicBlock *BasicBlockVal; + TerminatorInst *TermInstVal; + Instruction *InstVal; + ConstPoolVal *ConstVal; + const Type *TypeVal; + + list<MethodArgument*> *MethodArgList; + list<Value*> *ValueList; + list<const Type*> *TypeList; + list<pair<ConstPoolVal*, BasicBlock*> > *JumpTable; + vector<ConstPoolVal*> *ConstVector; + + int64_t SInt64Val; + uint64_t UInt64Val; + int SIntVal; + unsigned UIntVal; + + char *StrVal; // This memory is allocated by strdup! + ValID ValIDVal; // May contain memory allocated by strdup + + Instruction::UnaryOps UnaryOpVal; + Instruction::BinaryOps BinaryOpVal; + Instruction::TermOps TermOpVal; + Instruction::MemoryOps MemOpVal; +} + +%type <ModuleVal> Module MethodList +%type <MethodVal> Method MethodHeader BasicBlockList +%type <BasicBlockVal> BasicBlock InstructionList +%type <TermInstVal> BBTerminatorInst +%type <InstVal> Inst InstVal MemoryInst +%type <ConstVal> ConstVal +%type <ConstVector> ConstVector +%type <MethodArgList> ArgList ArgListH +%type <MethArgVal> ArgVal +%type <ValueList> ValueRefList ValueRefListE +%type <TypeList> TypeList +%type <JumpTable> JumpTable + +%type <ValIDVal> ValueRef ConstValueRef // Reference to a definition or BB + +// Tokens and types for handling constant integer values +// +// ESINT64VAL - A negative number within long long range +%token <SInt64Val> ESINT64VAL + +// EUINT64VAL - A positive number within uns. long long range +%token <UInt64Val> EUINT64VAL +%type <SInt64Val> EINT64VAL + +%token <SIntVal> SINTVAL // Signed 32 bit ints... +%token <UIntVal> UINTVAL // Unsigned 32 bit ints... +%type <SIntVal> INTVAL + +// Built in types... +%type <TypeVal> Types TypesV SIntType UIntType IntType +%token <TypeVal> VOID BOOL SBYTE UBYTE SHORT USHORT INT UINT LONG ULONG +%token <TypeVal> FLOAT DOUBLE STRING TYPE LABEL + +%token <StrVal> VAR_ID LABELSTR STRINGCONSTANT +%type <StrVal> OptVAR_ID OptAssign + + +%token IMPLEMENTATION TRUE FALSE BEGINTOK END DECLARE +%token PHI CALL + +// Basic Block Terminating Operators +%token <TermOpVal> RET BR SWITCH + +// Unary Operators +%type <UnaryOpVal> UnaryOps // all the unary operators +%token <UnaryOpVal> NEG NOT + +// Unary Conversion Operators +%token <UnaryOpVal> TOINT TOUINT + +// Binary Operators +%type <BinaryOpVal> BinaryOps // all the binary operators +%token <BinaryOpVal> ADD SUB MUL DIV REM + +// Binary Comarators +%token <BinaryOpVal> SETLE SETGE SETLT SETGT SETEQ SETNE + +// Memory Instructions +%token <MemoryOpVal> MALLOC ALLOCA FREE LOAD STORE GETFIELD PUTFIELD + +%start Module +%% + +// Handle constant integer size restriction and conversion... +// + +INTVAL : SINTVAL +INTVAL : UINTVAL { + if ($1 > (uint32_t)INT32_MAX) // Outside of my range! + ThrowException("Value too large for type!"); + $$ = (int32_t)$1; +} + + +EINT64VAL : ESINT64VAL // These have same type and can't cause problems... +EINT64VAL : EUINT64VAL { + if ($1 > (uint64_t)INT64_MAX) // Outside of my range! + ThrowException("Value too large for type!"); + $$ = (int64_t)$1; +} + +// Types includes all predefined types... except void, because you can't do +// anything with it except for certain specific things... +// +// User defined types are added latter... +// +Types : BOOL | SBYTE | UBYTE | SHORT | USHORT | INT | UINT +Types : LONG | ULONG | FLOAT | DOUBLE | STRING | TYPE | LABEL + +// TypesV includes all of 'Types', but it also includes the void type. +TypesV : Types | VOID + +// Operations that are notably excluded from this list include: +// RET, BR, & SWITCH because they end basic blocks and are treated specially. +// +UnaryOps : NEG | NOT | TOINT | TOUINT +BinaryOps : ADD | SUB | MUL | DIV | REM +BinaryOps : SETLE | SETGE | SETLT | SETGT | SETEQ | SETNE + +// Valueine some types that allow classification if we only want a particular +// thing... +SIntType : LONG | INT | SHORT | SBYTE +UIntType : ULONG | UINT | USHORT | UBYTE +IntType : SIntType | UIntType + +OptAssign : VAR_ID '=' { + $$ = $1; + } + | /*empty*/ { + $$ = 0; + } + +ConstVal : SIntType EINT64VAL { // integral constants + if (!ConstPoolSInt::isValueValidForType($1, $2)) + ThrowException("Constant value doesn't fit in type!"); + $$ = new ConstPoolSInt($1, $2); + } + | UIntType EUINT64VAL { // integral constants + if (!ConstPoolUInt::isValueValidForType($1, $2)) + ThrowException("Constant value doesn't fit in type!"); + $$ = new ConstPoolUInt($1, $2); + } + | BOOL TRUE { // Boolean constants + $$ = new ConstPoolBool(true); + } + | BOOL FALSE { // Boolean constants + $$ = new ConstPoolBool(false); + } + | STRING STRINGCONSTANT { // String constants + cerr << "FIXME: TODO: String constants [sbyte] not implemented yet!\n"; + abort(); + //$$ = new ConstPoolString($2); + free($2); + } + | TYPE Types { // Type constants + $$ = new ConstPoolType($2); + } + | '[' Types ']' '[' ConstVector ']' { // Nonempty array constant + // Verify all elements are correct type! + const ArrayType *AT = ArrayType::getArrayType($2); + for (unsigned i = 0; i < $5->size(); i++) { + if ($2 != (*$5)[i]->getType()) + ThrowException("Element #" + utostr(i) + " is not of type '" + + $2->getName() + "' as required!\nIt is of type '" + + (*$5)[i]->getType()->getName() + "'."); + } + + $$ = new ConstPoolArray(AT, *$5); + delete $5; + } + | '[' Types ']' '[' ']' { // Empty array constant + vector<ConstPoolVal*> Empty; + $$ = new ConstPoolArray(ArrayType::getArrayType($2), Empty); + } + | '[' EUINT64VAL 'x' Types ']' '[' ConstVector ']' { + // Verify all elements are correct type! + const ArrayType *AT = ArrayType::getArrayType($4, (int)$2); + if ($2 != $7->size()) + ThrowException("Type mismatch: constant sized array initialized with " + + utostr($7->size()) + " arguments, but has size of " + + itostr((int)$2) + "!"); + + for (unsigned i = 0; i < $7->size(); i++) { + if ($4 != (*$7)[i]->getType()) + ThrowException("Element #" + utostr(i) + " is not of type '" + + $4->getName() + "' as required!\nIt is of type '" + + (*$7)[i]->getType()->getName() + "'."); + } + + $$ = new ConstPoolArray(AT, *$7); + delete $7; + } + | '[' EUINT64VAL 'x' Types ']' '[' ']' { + if ($2 != 0) + ThrowException("Type mismatch: constant sized array initialized with 0" + " arguments, but has size of " + itostr((int)$2) + "!"); + vector<ConstPoolVal*> Empty; + $$ = new ConstPoolArray(ArrayType::getArrayType($4, 0), Empty); + } + | '{' TypeList '}' '{' ConstVector '}' { + StructType::ElementTypes Types($2->begin(), $2->end()); + delete $2; + + const StructType *St = StructType::getStructType(Types); + $$ = new ConstPoolStruct(St, *$5); + delete $5; + } + | '{' '}' '{' '}' { + const StructType *St = + StructType::getStructType(StructType::ElementTypes()); + vector<ConstPoolVal*> Empty; + $$ = new ConstPoolStruct(St, Empty); + } +/* + | Types '*' ConstVal { + assert(0); + $$ = 0; + } +*/ + + +ConstVector : ConstVector ',' ConstVal { + ($$ = $1)->push_back(addConstValToConstantPool($3)); + } + | ConstVal { + $$ = new vector<ConstPoolVal*>(); + $$->push_back(addConstValToConstantPool($1)); + } + + +ConstPool : ConstPool OptAssign ConstVal { + if ($2) { + $3->setName($2); + free($2); + } + + addConstValToConstantPool($3); + } + | /* empty: end of list */ { + } + + +//===----------------------------------------------------------------------===// +// Rules to match Modules +//===----------------------------------------------------------------------===// + +// Module rule: Capture the result of parsing the whole file into a result +// variable... +// +Module : MethodList { + $$ = ParserResult = $1; + CurModule.ModuleDone(); +} + +MethodList : MethodList Method { + $1->getMethodList().push_back($2); + CurMeth.MethodDone(); + $$ = $1; + } + | ConstPool IMPLEMENTATION { + $$ = CurModule.CurrentModule; + } + + +//===----------------------------------------------------------------------===// +// Rules to match Method Headers +//===----------------------------------------------------------------------===// + +OptVAR_ID : VAR_ID | /*empty*/ { $$ = 0; } + +ArgVal : Types OptVAR_ID { + $$ = new MethodArgument($1); + if ($2) { // Was the argument named? + $$->setName($2); + free($2); // The string was strdup'd, so free it now. + } +} + +ArgListH : ArgVal ',' ArgListH { + $$ = $3; + $3->push_front($1); + } + | ArgVal { + $$ = new list<MethodArgument*>(); + $$->push_front($1); + } + +ArgList : ArgListH { + $$ = $1; + } + | /* empty */ { + $$ = 0; + } + +MethodHeaderH : TypesV STRINGCONSTANT '(' ArgList ')' { + MethodType::ParamTypes ParamTypeList; + if ($4) + for (list<MethodArgument*>::iterator I = $4->begin(); I != $4->end(); I++) + ParamTypeList.push_back((*I)->getType()); + + const MethodType *MT = MethodType::getMethodType($1, ParamTypeList); + + Method *M = new Method(MT, $2); + free($2); // Free strdup'd memory! + + InsertValue(M, CurModule.Values); + + CurMeth.MethodStart(M); + + // Add all of the arguments we parsed to the method... + if ($4) { // Is null if empty... + Method::ArgumentListType &ArgList = M->getArgumentList(); + + for (list<MethodArgument*>::iterator I = $4->begin(); I != $4->end(); I++) { + InsertValue(*I); + ArgList.push_back(*I); + } + delete $4; // We're now done with the argument list + } +} + +MethodHeader : MethodHeaderH ConstPool BEGINTOK { + $$ = CurMeth.CurrentMethod; +} + +Method : BasicBlockList END { + $$ = $1; +} + + +//===----------------------------------------------------------------------===// +// Rules to match Basic Blocks +//===----------------------------------------------------------------------===// + +ConstValueRef : ESINT64VAL { // A reference to a direct constant + $$ = ValID::create($1); + } + | EUINT64VAL { + $$ = ValID::create($1); + } + | TRUE { + $$ = ValID::create((int64_t)1); + } + | FALSE { + $$ = ValID::create((int64_t)0); + } + | STRINGCONSTANT { // Quoted strings work too... especially for methods + $$ = ValID::create_conststr($1); + } + +// ValueRef - A reference to a definition... +ValueRef : INTVAL { // Is it an integer reference...? + $$ = ValID::create($1); + } + | VAR_ID { // It must be a named reference then... + $$ = ValID::create($1); + } + | ConstValueRef { + $$ = $1; + } + +// The user may refer to a user defined type by its typeplane... check for this +// now... +// +Types : ValueRef { + Value *D = getVal(Type::TypeTy, $1, true); + if (D == 0) ThrowException("Invalid user defined type: " + $1.getName()); + assert (D->getValueType() == Value::ConstantVal && + "Internal error! User defined type not in const pool!"); + ConstPoolType *CPT = (ConstPoolType*)D; + $$ = CPT->getValue(); + } + | TypesV '(' TypeList ')' { // Method derived type? + MethodType::ParamTypes Params($3->begin(), $3->end()); + delete $3; + $$ = MethodType::getMethodType($1, Params); + } + | TypesV '(' ')' { // Method derived type? + MethodType::ParamTypes Params; // Empty list + $$ = MethodType::getMethodType($1, Params); + } + | '[' Types ']' { + $$ = ArrayType::getArrayType($2); + } + | '[' EUINT64VAL 'x' Types ']' { + $$ = ArrayType::getArrayType($4, (int)$2); + } + | '{' TypeList '}' { + StructType::ElementTypes Elements($2->begin(), $2->end()); + delete $2; + $$ = StructType::getStructType(Elements); + } + | '{' '}' { + $$ = StructType::getStructType(StructType::ElementTypes()); + } + | Types '*' { + $$ = PointerType::getPointerType($1); + } + + +TypeList : Types { + $$ = new list<const Type*>(); + $$->push_back($1); + } + | TypeList ',' Types { + ($$=$1)->push_back($3); + } + + +BasicBlockList : BasicBlockList BasicBlock { + $1->getBasicBlocks().push_back($2); + $$ = $1; + } + | MethodHeader BasicBlock { // Do not allow methods with 0 basic blocks + $$ = $1; // in them... + $1->getBasicBlocks().push_back($2); + } + + +// Basic blocks are terminated by branching instructions: +// br, br/cc, switch, ret +// +BasicBlock : InstructionList BBTerminatorInst { + $1->getInstList().push_back($2); + InsertValue($1); + $$ = $1; + } + | LABELSTR InstructionList BBTerminatorInst { + $2->getInstList().push_back($3); + $2->setName($1); + free($1); // Free the strdup'd memory... + + InsertValue($2); + $$ = $2; + } + +InstructionList : InstructionList Inst { + $1->getInstList().push_back($2); + $$ = $1; + } + | /* empty */ { + $$ = new BasicBlock(); + } + +BBTerminatorInst : RET Types ValueRef { // Return with a result... + $$ = new ReturnInst(getVal($2, $3)); + } + | RET VOID { // Return with no result... + $$ = new ReturnInst(); + } + | BR LABEL ValueRef { // Unconditional Branch... + $$ = new BranchInst((BasicBlock*)getVal(Type::LabelTy, $3)); + } // Conditional Branch... + | BR BOOL ValueRef ',' LABEL ValueRef ',' LABEL ValueRef { + $$ = new BranchInst((BasicBlock*)getVal(Type::LabelTy, $6), + (BasicBlock*)getVal(Type::LabelTy, $9), + getVal(Type::BoolTy, $3)); + } + | SWITCH IntType ValueRef ',' LABEL ValueRef '[' JumpTable ']' { + SwitchInst *S = new SwitchInst(getVal($2, $3), + (BasicBlock*)getVal(Type::LabelTy, $6)); + $$ = S; + + list<pair<ConstPoolVal*, BasicBlock*> >::iterator I = $8->begin(), + end = $8->end(); + for (; I != end; I++) + S->dest_push_back(I->first, I->second); + } + +JumpTable : JumpTable IntType ConstValueRef ',' LABEL ValueRef { + $$ = $1; + ConstPoolVal *V = (ConstPoolVal*)getVal($2, $3, true); + if (V == 0) + ThrowException("May only switch on a constant pool value!"); + + $$->push_back(make_pair(V, (BasicBlock*)getVal($5, $6))); + } + | IntType ConstValueRef ',' LABEL ValueRef { + $$ = new list<pair<ConstPoolVal*, BasicBlock*> >(); + ConstPoolVal *V = (ConstPoolVal*)getVal($1, $2, true); + + if (V == 0) + ThrowException("May only switch on a constant pool value!"); + + $$->push_back(make_pair(V, (BasicBlock*)getVal($4, $5))); + } + +Inst : OptAssign InstVal { + if ($1) // Is this definition named?? + $2->setName($1); // if so, assign the name... + + InsertValue($2); + $$ = $2; +} + +ValueRefList : Types ValueRef { // Used for PHI nodes and call statements... + $$ = new list<Value*>(); + $$->push_back(getVal($1, $2)); + } + | ValueRefList ',' ValueRef { + $$ = $1; + $1->push_back(getVal($1->front()->getType(), $3)); + } + +// ValueRefListE - Just like ValueRefList, except that it may also be empty! +ValueRefListE : ValueRefList | /*empty*/ { $$ = 0; } + +InstVal : BinaryOps Types ValueRef ',' ValueRef { + $$ = Instruction::getBinaryOperator($1, getVal($2, $3), getVal($2, $5)); + if ($$ == 0) + ThrowException("binary operator returned null!"); + } + | UnaryOps Types ValueRef { + $$ = Instruction::getUnaryOperator($1, getVal($2, $3)); + if ($$ == 0) + ThrowException("unary operator returned null!"); + } + | PHI ValueRefList { + $$ = new PHINode($2->front()->getType()); + while ($2->begin() != $2->end()) { + // TODO: Ensure all types are the same... + ((PHINode*)$$)->addIncoming($2->front()); + $2->pop_front(); + } + delete $2; // Free the list... + } + | CALL Types ValueRef '(' ValueRefListE ')' { + if (!$2->isMethodType()) + ThrowException("Can only call methods: invalid type '" + + $2->getName() + "'!"); + + const MethodType *Ty = (const MethodType*)$2; + + Value *V = getVal(Ty, $3); + if (V->getValueType() != Value::MethodVal || V->getType() != Ty) + ThrowException("Cannot call: " + $3.getName() + "!"); + + // Create or access a new type that corresponds to the function call... + vector<Value *> Params; + + if ($5) { + // Pull out just the arguments... + Params.insert(Params.begin(), $5->begin(), $5->end()); + delete $5; + + // Loop through MethodType's arguments and ensure they are specified + // correctly! + // + MethodType::ParamTypes::const_iterator I = Ty->getParamTypes().begin(); + unsigned i; + for (i = 0; i < Params.size() && I != Ty->getParamTypes().end(); ++i,++I){ + if (Params[i]->getType() != *I) + ThrowException("Parameter " + utostr(i) + " is not of type '" + + (*I)->getName() + "'!"); + } + + if (i != Params.size() || I != Ty->getParamTypes().end()) + ThrowException("Invalid number of parameters detected!"); + } + + // Create the call node... + $$ = new CallInst((Method*)V, Params); + } + | MemoryInst { + $$ = $1; + } + +MemoryInst : MALLOC Types { + ConstPoolVal *TyVal = new ConstPoolType(PointerType::getPointerType($2)); + TyVal = addConstValToConstantPool(TyVal); + $$ = new MallocInst((ConstPoolType*)TyVal); + } + | MALLOC Types ',' UINT ValueRef { + if (!$2->isArrayType() || ((const ArrayType*)$2)->isSized()) + ThrowException("Trying to allocate " + $2->getName() + + " as unsized array!"); + + Value *ArrSize = getVal($4, $5); + ConstPoolVal *TyVal = new ConstPoolType(PointerType::getPointerType($2)); + TyVal = addConstValToConstantPool(TyVal); + $$ = new MallocInst((ConstPoolType*)TyVal, ArrSize); + } + | ALLOCA Types { + ConstPoolVal *TyVal = new ConstPoolType(PointerType::getPointerType($2)); + TyVal = addConstValToConstantPool(TyVal); + $$ = new AllocaInst((ConstPoolType*)TyVal); + } + | ALLOCA Types ',' UINT ValueRef { + if (!$2->isArrayType() || ((const ArrayType*)$2)->isSized()) + ThrowException("Trying to allocate " + $2->getName() + + " as unsized array!"); + + Value *ArrSize = getVal($4, $5); + ConstPoolVal *TyVal = new ConstPoolType(PointerType::getPointerType($2)); + TyVal = addConstValToConstantPool(TyVal); + $$ = new AllocaInst((ConstPoolType*)TyVal, ArrSize); + } + | FREE Types ValueRef { + if (!$2->isPointerType()) + ThrowException("Trying to free nonpointer type " + $2->getName() + "!"); + $$ = new FreeInst(getVal($2, $3)); + } + +%% +int yyerror(char *ErrorMsg) { + ThrowException(string("Parse error: ") + ErrorMsg); + return 0; +} |