Initial, non-functional, version of llvm-upgrade. This version just echos

its input. Committed for safekeeping purposes. Don't use this yet.

llvm-svn: 32030
This commit is contained in:
Reid Spencer 2006-11-30 06:36:44 +00:00
parent 983ac81fb0
commit 8e60eec519
13 changed files with 15223 additions and 0 deletions

View File

@ -0,0 +1,22 @@
##===- tools/llvm-upgrade/Makefile -------------------------*- Makefile -*-===##
#
# The LLVM Compiler Infrastructure
#
# This file was developed by Reid Spencer and is distributed under the
# University of Illinois Open Source License. See LICENSE.TXT for details.
#
##===----------------------------------------------------------------------===##
LEVEL = ../..
TOOLNAME = llvm-upgrade
LINK_COMPONENTS := support system
include $(LEVEL)/Makefile.common
# Make the object code file for the lexer depend upon the header file generated
# by the Bison parser. This prevents the Lexer from being compiled before the
# header file it needs is built.
$(ObjDir)/upgradeLexer.o: $(PROJ_SRC_DIR)/UpgradeParser.h
test:
../../Debug/bin/llvm-upgrade -o - ../../test/Feature/basictest.ll

View File

@ -0,0 +1,37 @@
//===-- ParserInternals.h - Definitions internal to the parser --*- C++ -*-===//
//
// The LLVM Compiler Infrastructure
//
// This file was developed by Reid Spencer and is distributed under
// the University of Illinois Open Source License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
//
// This header file defines the variables that are shared between the lexer,
// the parser, and the main program.
//
//===----------------------------------------------------------------------===//
#ifndef PARSER_INTERNALS_H
#define PARSER_INTERNALS_H
#include <string>
// Global variables exported from the lexer...
extern std::string CurFileName;
extern std::string Textin;
extern int Upgradelineno;
// functions exported from the lexer
void set_scan_bytes (const char * str, size_t len);
void UpgradeAssembly(const std::string & infile, std::ostream &out);
// Globals exported by the parser...
extern char* Upgradetext;
extern int Upgradeleng;
int yyerror(const char *ErrorMsg) ;
#endif

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,229 @@
/*===-- UpgradeLexer.l - Scanner for 1.9 assembly files --------*- C++ -*--===//
//
// The LLVM Compiler Infrastructure
//
// This file was developed by Reid Spencer and is distributed under the
// University of Illinois Open Source License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
//
// This file implements the flex scanner for LLVM 1.9 assembly languages files.
//
//===----------------------------------------------------------------------===*/
%option prefix="Upgrade"
%option yylineno
%option nostdinit
%option never-interactive
%option batch
%option noyywrap
%option nodefault
%option 8bit
%option outfile="UpgradeLexer.cpp"
%option ecs
%option noreject
%option noyymore
%{
#include "ParserInternals.h"
#define YYSTYPE std::string*
#include "UpgradeParser.h"
#include <cctype>
#include <cstdlib>
void set_scan_bytes (const char * str, size_t len) {
Upgrade_scan_bytes (str, len);
}
static void trim(std::string& str) {
size_t startpos = str.find_first_not_of(" \t\n\r",0);
if (startpos != std::string::npos)
str.erase(0,startpos);
}
// Construct a token value for a non-obsolete token
#define RET_TOK(sym) \
Upgradelval = new std::string(yytext); \
trim(*Upgradelval); \
return sym
#define YY_NEVER_INTERACTIVE 1
%}
/* Comments start with a ; and go till end of line */
Comment ;.*
/* Variable(Value) 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]+:
QuoteLabel \"[^\"]+\":
/* 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]+
/* FPConstant - A Floating point constant.
*/
FPConstant [-+]?[0-9]+[.][0-9]*([eE][-+]?[0-9]+)?
/* HexFPConstant - Floating point constant represented in IEEE format as a
* hexadecimal number for when exponential notation is not precise enough.
*/
HexFPConstant 0x[0-9A-Fa-f]+
/* HexIntConstant - Hexadecimal constant generated by the CFE to avoid forcing
* it to deal with 64 bit numbers.
*/
HexIntConstant [us]0x[0-9A-Fa-f]+
%%
{Comment} { /* Ignore comments for now */ }
begin { RET_TOK( BEGINTOK); }
end { RET_TOK( ENDTOK); }
true { RET_TOK( TRUETOK); }
false { RET_TOK( FALSETOK); }
declare { RET_TOK( DECLARE); }
global { RET_TOK( GLOBAL); }
constant { RET_TOK( CONSTANT); }
internal { RET_TOK( INTERNAL); }
linkonce { RET_TOK( LINKONCE); }
weak { RET_TOK( WEAK); }
appending { RET_TOK( APPENDING); }
dllimport { RET_TOK( DLLIMPORT); }
dllexport { RET_TOK( DLLEXPORT); }
extern_weak { RET_TOK( EXTERN_WEAK); }
external { RET_TOK( EXTERNAL); }
implementation { RET_TOK( IMPLEMENTATION); }
zeroinitializer { RET_TOK( ZEROINITIALIZER); }
\.\.\. { RET_TOK( DOTDOTDOT); }
undef { RET_TOK( UNDEF); }
null { RET_TOK( NULL_TOK); }
to { RET_TOK( TO); }
tail { RET_TOK( TAIL); }
target { RET_TOK( TARGET); }
triple { RET_TOK( TRIPLE); }
deplibs { RET_TOK( DEPLIBS); }
endian { RET_TOK( ENDIAN); }
pointersize { RET_TOK( POINTERSIZE); }
datalayout { RET_TOK( DATALAYOUT); }
little { RET_TOK( LITTLE); }
big { RET_TOK( BIG); }
volatile { RET_TOK( VOLATILE); }
align { RET_TOK( ALIGN); }
section { RET_TOK( SECTION); }
module { RET_TOK( MODULE); }
asm { RET_TOK( ASM_TOK); }
sideeffect { RET_TOK( SIDEEFFECT); }
cc { RET_TOK( CC_TOK); }
ccc { RET_TOK( CCC_TOK); }
csretcc { RET_TOK( CSRETCC_TOK); }
fastcc { RET_TOK( FASTCC_TOK); }
coldcc { RET_TOK( COLDCC_TOK); }
x86_stdcallcc { RET_TOK( X86_STDCALLCC_TOK); }
x86_fastcallcc { RET_TOK( X86_FASTCALLCC_TOK); }
void { RET_TOK( VOID); }
bool { RET_TOK( BOOL); }
sbyte { RET_TOK( SBYTE); }
ubyte { RET_TOK( UBYTE); }
short { RET_TOK( SHORT); }
ushort { RET_TOK( USHORT); }
int { RET_TOK( INT); }
uint { RET_TOK( UINT); }
long { RET_TOK( LONG); }
ulong { RET_TOK( ULONG); }
float { RET_TOK( FLOAT); }
double { RET_TOK( DOUBLE); }
label { RET_TOK( LABEL); }
type { RET_TOK( TYPE); }
opaque { RET_TOK( OPAQUE); }
add { RET_TOK( ADD); }
sub { RET_TOK( SUB); }
mul { RET_TOK( MUL); }
div { RET_TOK( UDIV); }
udiv { RET_TOK( UDIV); }
sdiv { RET_TOK( SDIV); }
fdiv { RET_TOK( FDIV); }
rem { RET_TOK( UREM); }
urem { RET_TOK( UREM); }
srem { RET_TOK( SREM); }
frem { RET_TOK( FREM); }
and { RET_TOK( AND); }
or { RET_TOK( OR); }
xor { RET_TOK( XOR); }
setne { RET_TOK( SETNE); }
seteq { RET_TOK( SETEQ); }
setlt { RET_TOK( SETLT); }
setgt { RET_TOK( SETGT); }
setle { RET_TOK( SETLE); }
setge { RET_TOK( SETGE); }
phi { RET_TOK( PHI_TOK); }
call { RET_TOK( CALL); }
cast { RET_TOK( TRUNC); }
select { RET_TOK( SELECT); }
shl { RET_TOK( SHL); }
lshr { RET_TOK( LSHR); }
ashr { RET_TOK( ASHR); }
va_arg { RET_TOK( VAARG); }
ret { RET_TOK( RET); }
br { RET_TOK( BR); }
switch { RET_TOK( SWITCH); }
invoke { RET_TOK( INVOKE); }
unwind { RET_TOK( UNWIND); }
unreachable { RET_TOK( UNREACHABLE); }
malloc { RET_TOK( MALLOC); }
alloca { RET_TOK( ALLOCA); }
free { RET_TOK( FREE); }
load { RET_TOK( LOAD); }
store { RET_TOK( STORE); }
getelementptr { RET_TOK( GETELEMENTPTR); }
extractelement { RET_TOK( EXTRACTELEMENT); }
insertelement { RET_TOK( INSERTELEMENT); }
shufflevector { RET_TOK( SHUFFLEVECTOR); }
{VarID} { RET_TOK( VAR_ID); }
{Label} { RET_TOK( LABELSTR); }
{QuoteLabel} { RET_TOK( LABELSTR); }
{StringConstant} { RET_TOK( STRINGCONSTANT ); }
{PInteger} { RET_TOK( EUINT64VAL ); }
{NInteger} { RET_TOK( ESINT64VAL ); }
{HexIntConstant} { RET_TOK( yytext[0] == 's' ? ESINT64VAL : EUINT64VAL ); }
{EPInteger} { RET_TOK( UINTVAL); }
{ENInteger} { RET_TOK( SINTVAL); }
{FPConstant} { RET_TOK( FPVAL); }
{HexFPConstant} { RET_TOK( FPVAL); }
<<EOF>> {
/* Make sure to free the internal buffers for flex when we are
* done reading our input!
*/
yy_delete_buffer(YY_CURRENT_BUFFER);
return EOF;
}
[ \r\t\n] { /* Ignore whitespace */ }
. { return yytext[0]; }
%%

View File

@ -0,0 +1,229 @@
/*===-- Lexer.l - Scanner for llvm assembly files --------------*- C++ -*--===//
//
// The LLVM Compiler Infrastructure
//
// This file was developed by the LLVM research group and is distributed under
// the University of Illinois Open Source License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
//
// This file implements the flex scanner for LLVM assembly languages files.
//
//===----------------------------------------------------------------------===*/
%option prefix="Upgrade"
%option yylineno
%option nostdinit
%option never-interactive
%option batch
%option noyywrap
%option nodefault
%option 8bit
%option outfile="UpgradeLexer.cpp"
%option ecs
%option noreject
%option noyymore
%{
#include "ParserInternals.h"
#define YYSTYPE std::string*
#include "UpgradeParser.h"
#include <cctype>
#include <cstdlib>
void set_scan_bytes (const char * str, size_t len) {
Upgrade_scan_bytes (str, len);
}
static void trim(std::string& str) {
size_t startpos = str.find_first_not_of(" \t\n\r",0);
if (startpos != std::string::npos)
str.erase(0,startpos);
}
// Construct a token value for a non-obsolete token
#define RET_TOK(sym) \
Upgradelval = new std::string(yytext); \
trim(*Upgradelval); \
return sym
#define YY_NEVER_INTERACTIVE 1
%}
/* Comments start with a ; and go till end of line */
Comment ;.*
/* Variable(Value) 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]+:
QuoteLabel \"[^\"]+\":
/* 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]+
/* FPConstant - A Floating point constant.
*/
FPConstant [-+]?[0-9]+[.][0-9]*([eE][-+]?[0-9]+)?
/* HexFPConstant - Floating point constant represented in IEEE format as a
* hexadecimal number for when exponential notation is not precise enough.
*/
HexFPConstant 0x[0-9A-Fa-f]+
/* HexIntConstant - Hexadecimal constant generated by the CFE to avoid forcing
* it to deal with 64 bit numbers.
*/
HexIntConstant [us]0x[0-9A-Fa-f]+
%%
{Comment} { /* Ignore comments for now */ }
begin { RET_TOK( BEGINTOK); }
end { RET_TOK( ENDTOK); }
true { RET_TOK( TRUETOK); }
false { RET_TOK( FALSETOK); }
declare { RET_TOK( DECLARE); }
global { RET_TOK( GLOBAL); }
constant { RET_TOK( CONSTANT); }
internal { RET_TOK( INTERNAL); }
linkonce { RET_TOK( LINKONCE); }
weak { RET_TOK( WEAK); }
appending { RET_TOK( APPENDING); }
dllimport { RET_TOK( DLLIMPORT); }
dllexport { RET_TOK( DLLEXPORT); }
extern_weak { RET_TOK( EXTERN_WEAK); }
external { RET_TOK( EXTERNAL); }
implementation { RET_TOK( IMPLEMENTATION); }
zeroinitializer { RET_TOK( ZEROINITIALIZER); }
\.\.\. { RET_TOK( DOTDOTDOT); }
undef { RET_TOK( UNDEF); }
null { RET_TOK( NULL_TOK); }
to { RET_TOK( TO); }
tail { RET_TOK( TAIL); }
target { RET_TOK( TARGET); }
triple { RET_TOK( TRIPLE); }
deplibs { RET_TOK( DEPLIBS); }
endian { RET_TOK( ENDIAN); }
pointersize { RET_TOK( POINTERSIZE); }
datalayout { RET_TOK( DATALAYOUT); }
little { RET_TOK( LITTLE); }
big { RET_TOK( BIG); }
volatile { RET_TOK( VOLATILE); }
align { RET_TOK( ALIGN); }
section { RET_TOK( SECTION); }
module { RET_TOK( MODULE); }
asm { RET_TOK( ASM_TOK); }
sideeffect { RET_TOK( SIDEEFFECT); }
cc { RET_TOK( CC_TOK); }
ccc { RET_TOK( CCC_TOK); }
csretcc { RET_TOK( CSRETCC_TOK); }
fastcc { RET_TOK( FASTCC_TOK); }
coldcc { RET_TOK( COLDCC_TOK); }
x86_stdcallcc { RET_TOK( X86_STDCALLCC_TOK); }
x86_fastcallcc { RET_TOK( X86_FASTCALLCC_TOK); }
void { RET_TOK( VOID); }
bool { RET_TOK( BOOL); }
sbyte { RET_TOK( SBYTE); }
ubyte { RET_TOK( UBYTE); }
short { RET_TOK( SHORT); }
ushort { RET_TOK( USHORT); }
int { RET_TOK( INT); }
uint { RET_TOK( UINT); }
long { RET_TOK( LONG); }
ulong { RET_TOK( ULONG); }
float { RET_TOK( FLOAT); }
double { RET_TOK( DOUBLE); }
label { RET_TOK( LABEL); }
type { RET_TOK( TYPE); }
opaque { RET_TOK( OPAQUE); }
add { RET_TOK( ADD); }
sub { RET_TOK( SUB); }
mul { RET_TOK( MUL); }
div { RET_TOK( UDIV); }
udiv { RET_TOK( UDIV); }
sdiv { RET_TOK( SDIV); }
fdiv { RET_TOK( FDIV); }
rem { RET_TOK( UREM); }
urem { RET_TOK( UREM); }
srem { RET_TOK( SREM); }
frem { RET_TOK( FREM); }
and { RET_TOK( AND); }
or { RET_TOK( OR); }
xor { RET_TOK( XOR); }
setne { RET_TOK( SETNE); }
seteq { RET_TOK( SETEQ); }
setlt { RET_TOK( SETLT); }
setgt { RET_TOK( SETGT); }
setle { RET_TOK( SETLE); }
setge { RET_TOK( SETGE); }
phi { RET_TOK( PHI_TOK); }
call { RET_TOK( CALL); }
cast { RET_TOK( TRUNC); }
select { RET_TOK( SELECT); }
shl { RET_TOK( SHL); }
lshr { RET_TOK( LSHR); }
ashr { RET_TOK( ASHR); }
va_arg { RET_TOK( VAARG); }
ret { RET_TOK( RET); }
br { RET_TOK( BR); }
switch { RET_TOK( SWITCH); }
invoke { RET_TOK( INVOKE); }
unwind { RET_TOK( UNWIND); }
unreachable { RET_TOK( UNREACHABLE); }
malloc { RET_TOK( MALLOC); }
alloca { RET_TOK( ALLOCA); }
free { RET_TOK( FREE); }
load { RET_TOK( LOAD); }
store { RET_TOK( STORE); }
getelementptr { RET_TOK( GETELEMENTPTR); }
extractelement { RET_TOK( EXTRACTELEMENT); }
insertelement { RET_TOK( INSERTELEMENT); }
shufflevector { RET_TOK( SHUFFLEVECTOR); }
{VarID} { RET_TOK( VAR_ID); }
{Label} { RET_TOK( LABELSTR); }
{QuoteLabel} { RET_TOK( LABELSTR); }
{StringConstant} { RET_TOK( STRINGCONSTANT ); }
{PInteger} { RET_TOK( EUINT64VAL ); }
{NInteger} { RET_TOK( ESINT64VAL ); }
{HexIntConstant} { RET_TOK( yytext[0] == 's' ? ESINT64VAL : EUINT64VAL ); }
{EPInteger} { RET_TOK( UINTVAL); }
{ENInteger} { RET_TOK( SINTVAL); }
{FPConstant} { RET_TOK( FPVAL); }
{HexFPConstant} { RET_TOK( FPVAL); }
<<EOF>> {
/* Make sure to free the internal buffers for flex when we are
* done reading our input!
*/
yy_delete_buffer(YY_CURRENT_BUFFER);
return EOF;
}
[ \r\t\n] { /* Ignore whitespace */ }
. { return yytext[0]; }
%%

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,291 @@
/* A Bison parser, made by GNU Bison 2.1. */
/* Skeleton parser for Yacc-like parsing with Bison,
Copyright (C) 1984, 1989, 1990, 2000, 2001, 2002, 2003, 2004, 2005 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., 51 Franklin Street, Fifth Floor,
Boston, MA 02110-1301, 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. */
/* Tokens. */
#ifndef YYTOKENTYPE
# define YYTOKENTYPE
/* Put the tokens into the symbol table, so that GDB and other debuggers
know about them. */
enum yytokentype {
ESINT64VAL = 258,
EUINT64VAL = 259,
SINTVAL = 260,
UINTVAL = 261,
FPVAL = 262,
VOID = 263,
BOOL = 264,
SBYTE = 265,
UBYTE = 266,
SHORT = 267,
USHORT = 268,
INT = 269,
UINT = 270,
LONG = 271,
ULONG = 272,
FLOAT = 273,
DOUBLE = 274,
TYPE = 275,
LABEL = 276,
VAR_ID = 277,
LABELSTR = 278,
STRINGCONSTANT = 279,
IMPLEMENTATION = 280,
ZEROINITIALIZER = 281,
TRUETOK = 282,
FALSETOK = 283,
BEGINTOK = 284,
ENDTOK = 285,
DECLARE = 286,
GLOBAL = 287,
CONSTANT = 288,
SECTION = 289,
VOLATILE = 290,
TO = 291,
DOTDOTDOT = 292,
NULL_TOK = 293,
UNDEF = 294,
CONST = 295,
INTERNAL = 296,
LINKONCE = 297,
WEAK = 298,
APPENDING = 299,
DLLIMPORT = 300,
DLLEXPORT = 301,
EXTERN_WEAK = 302,
OPAQUE = 303,
NOT = 304,
EXTERNAL = 305,
TARGET = 306,
TRIPLE = 307,
ENDIAN = 308,
POINTERSIZE = 309,
LITTLE = 310,
BIG = 311,
ALIGN = 312,
DEPLIBS = 313,
CALL = 314,
TAIL = 315,
ASM_TOK = 316,
MODULE = 317,
SIDEEFFECT = 318,
CC_TOK = 319,
CCC_TOK = 320,
CSRETCC_TOK = 321,
FASTCC_TOK = 322,
COLDCC_TOK = 323,
X86_STDCALLCC_TOK = 324,
X86_FASTCALLCC_TOK = 325,
DATALAYOUT = 326,
RET = 327,
BR = 328,
SWITCH = 329,
INVOKE = 330,
UNWIND = 331,
UNREACHABLE = 332,
ADD = 333,
SUB = 334,
MUL = 335,
UDIV = 336,
SDIV = 337,
FDIV = 338,
UREM = 339,
SREM = 340,
FREM = 341,
AND = 342,
OR = 343,
XOR = 344,
SETLE = 345,
SETGE = 346,
SETLT = 347,
SETGT = 348,
SETEQ = 349,
SETNE = 350,
MALLOC = 351,
ALLOCA = 352,
FREE = 353,
LOAD = 354,
STORE = 355,
GETELEMENTPTR = 356,
TRUNC = 357,
ZEXT = 358,
SEXT = 359,
FPTRUNC = 360,
FPEXT = 361,
BITCAST = 362,
UITOFP = 363,
SITOFP = 364,
FPTOUI = 365,
FPTOSI = 366,
INTTOPTR = 367,
PTRTOINT = 368,
PHI_TOK = 369,
SELECT = 370,
SHL = 371,
LSHR = 372,
ASHR = 373,
VAARG = 374,
EXTRACTELEMENT = 375,
INSERTELEMENT = 376,
SHUFFLEVECTOR = 377,
CAST = 378
};
#endif
/* Tokens. */
#define ESINT64VAL 258
#define EUINT64VAL 259
#define SINTVAL 260
#define UINTVAL 261
#define FPVAL 262
#define VOID 263
#define BOOL 264
#define SBYTE 265
#define UBYTE 266
#define SHORT 267
#define USHORT 268
#define INT 269
#define UINT 270
#define LONG 271
#define ULONG 272
#define FLOAT 273
#define DOUBLE 274
#define TYPE 275
#define LABEL 276
#define VAR_ID 277
#define LABELSTR 278
#define STRINGCONSTANT 279
#define IMPLEMENTATION 280
#define ZEROINITIALIZER 281
#define TRUETOK 282
#define FALSETOK 283
#define BEGINTOK 284
#define ENDTOK 285
#define DECLARE 286
#define GLOBAL 287
#define CONSTANT 288
#define SECTION 289
#define VOLATILE 290
#define TO 291
#define DOTDOTDOT 292
#define NULL_TOK 293
#define UNDEF 294
#define CONST 295
#define INTERNAL 296
#define LINKONCE 297
#define WEAK 298
#define APPENDING 299
#define DLLIMPORT 300
#define DLLEXPORT 301
#define EXTERN_WEAK 302
#define OPAQUE 303
#define NOT 304
#define EXTERNAL 305
#define TARGET 306
#define TRIPLE 307
#define ENDIAN 308
#define POINTERSIZE 309
#define LITTLE 310
#define BIG 311
#define ALIGN 312
#define DEPLIBS 313
#define CALL 314
#define TAIL 315
#define ASM_TOK 316
#define MODULE 317
#define SIDEEFFECT 318
#define CC_TOK 319
#define CCC_TOK 320
#define CSRETCC_TOK 321
#define FASTCC_TOK 322
#define COLDCC_TOK 323
#define X86_STDCALLCC_TOK 324
#define X86_FASTCALLCC_TOK 325
#define DATALAYOUT 326
#define RET 327
#define BR 328
#define SWITCH 329
#define INVOKE 330
#define UNWIND 331
#define UNREACHABLE 332
#define ADD 333
#define SUB 334
#define MUL 335
#define UDIV 336
#define SDIV 337
#define FDIV 338
#define UREM 339
#define SREM 340
#define FREM 341
#define AND 342
#define OR 343
#define XOR 344
#define SETLE 345
#define SETGE 346
#define SETLT 347
#define SETGT 348
#define SETEQ 349
#define SETNE 350
#define MALLOC 351
#define ALLOCA 352
#define FREE 353
#define LOAD 354
#define STORE 355
#define GETELEMENTPTR 356
#define TRUNC 357
#define ZEXT 358
#define SEXT 359
#define FPTRUNC 360
#define FPEXT 361
#define BITCAST 362
#define UITOFP 363
#define SITOFP 364
#define FPTOUI 365
#define FPTOSI 366
#define INTTOPTR 367
#define PTRTOINT 368
#define PHI_TOK 369
#define SELECT 370
#define SHL 371
#define LSHR 372
#define ASHR 373
#define VAARG 374
#define EXTRACTELEMENT 375
#define INSERTELEMENT 376
#define SHUFFLEVECTOR 377
#define CAST 378
#if ! defined (YYSTYPE) && ! defined (YYSTYPE_IS_DECLARED)
typedef int YYSTYPE;
# define yystype YYSTYPE /* obsolescent; will be withdrawn */
# define YYSTYPE_IS_DECLARED 1
# define YYSTYPE_IS_TRIVIAL 1
#endif
extern YYSTYPE Upgradelval;

View File

@ -0,0 +1,291 @@
/* A Bison parser, made by GNU Bison 2.1. */
/* Skeleton parser for Yacc-like parsing with Bison,
Copyright (C) 1984, 1989, 1990, 2000, 2001, 2002, 2003, 2004, 2005 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., 51 Franklin Street, Fifth Floor,
Boston, MA 02110-1301, 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. */
/* Tokens. */
#ifndef YYTOKENTYPE
# define YYTOKENTYPE
/* Put the tokens into the symbol table, so that GDB and other debuggers
know about them. */
enum yytokentype {
ESINT64VAL = 258,
EUINT64VAL = 259,
SINTVAL = 260,
UINTVAL = 261,
FPVAL = 262,
VOID = 263,
BOOL = 264,
SBYTE = 265,
UBYTE = 266,
SHORT = 267,
USHORT = 268,
INT = 269,
UINT = 270,
LONG = 271,
ULONG = 272,
FLOAT = 273,
DOUBLE = 274,
TYPE = 275,
LABEL = 276,
VAR_ID = 277,
LABELSTR = 278,
STRINGCONSTANT = 279,
IMPLEMENTATION = 280,
ZEROINITIALIZER = 281,
TRUETOK = 282,
FALSETOK = 283,
BEGINTOK = 284,
ENDTOK = 285,
DECLARE = 286,
GLOBAL = 287,
CONSTANT = 288,
SECTION = 289,
VOLATILE = 290,
TO = 291,
DOTDOTDOT = 292,
NULL_TOK = 293,
UNDEF = 294,
CONST = 295,
INTERNAL = 296,
LINKONCE = 297,
WEAK = 298,
APPENDING = 299,
DLLIMPORT = 300,
DLLEXPORT = 301,
EXTERN_WEAK = 302,
OPAQUE = 303,
NOT = 304,
EXTERNAL = 305,
TARGET = 306,
TRIPLE = 307,
ENDIAN = 308,
POINTERSIZE = 309,
LITTLE = 310,
BIG = 311,
ALIGN = 312,
DEPLIBS = 313,
CALL = 314,
TAIL = 315,
ASM_TOK = 316,
MODULE = 317,
SIDEEFFECT = 318,
CC_TOK = 319,
CCC_TOK = 320,
CSRETCC_TOK = 321,
FASTCC_TOK = 322,
COLDCC_TOK = 323,
X86_STDCALLCC_TOK = 324,
X86_FASTCALLCC_TOK = 325,
DATALAYOUT = 326,
RET = 327,
BR = 328,
SWITCH = 329,
INVOKE = 330,
UNWIND = 331,
UNREACHABLE = 332,
ADD = 333,
SUB = 334,
MUL = 335,
UDIV = 336,
SDIV = 337,
FDIV = 338,
UREM = 339,
SREM = 340,
FREM = 341,
AND = 342,
OR = 343,
XOR = 344,
SETLE = 345,
SETGE = 346,
SETLT = 347,
SETGT = 348,
SETEQ = 349,
SETNE = 350,
MALLOC = 351,
ALLOCA = 352,
FREE = 353,
LOAD = 354,
STORE = 355,
GETELEMENTPTR = 356,
TRUNC = 357,
ZEXT = 358,
SEXT = 359,
FPTRUNC = 360,
FPEXT = 361,
BITCAST = 362,
UITOFP = 363,
SITOFP = 364,
FPTOUI = 365,
FPTOSI = 366,
INTTOPTR = 367,
PTRTOINT = 368,
PHI_TOK = 369,
SELECT = 370,
SHL = 371,
LSHR = 372,
ASHR = 373,
VAARG = 374,
EXTRACTELEMENT = 375,
INSERTELEMENT = 376,
SHUFFLEVECTOR = 377,
CAST = 378
};
#endif
/* Tokens. */
#define ESINT64VAL 258
#define EUINT64VAL 259
#define SINTVAL 260
#define UINTVAL 261
#define FPVAL 262
#define VOID 263
#define BOOL 264
#define SBYTE 265
#define UBYTE 266
#define SHORT 267
#define USHORT 268
#define INT 269
#define UINT 270
#define LONG 271
#define ULONG 272
#define FLOAT 273
#define DOUBLE 274
#define TYPE 275
#define LABEL 276
#define VAR_ID 277
#define LABELSTR 278
#define STRINGCONSTANT 279
#define IMPLEMENTATION 280
#define ZEROINITIALIZER 281
#define TRUETOK 282
#define FALSETOK 283
#define BEGINTOK 284
#define ENDTOK 285
#define DECLARE 286
#define GLOBAL 287
#define CONSTANT 288
#define SECTION 289
#define VOLATILE 290
#define TO 291
#define DOTDOTDOT 292
#define NULL_TOK 293
#define UNDEF 294
#define CONST 295
#define INTERNAL 296
#define LINKONCE 297
#define WEAK 298
#define APPENDING 299
#define DLLIMPORT 300
#define DLLEXPORT 301
#define EXTERN_WEAK 302
#define OPAQUE 303
#define NOT 304
#define EXTERNAL 305
#define TARGET 306
#define TRIPLE 307
#define ENDIAN 308
#define POINTERSIZE 309
#define LITTLE 310
#define BIG 311
#define ALIGN 312
#define DEPLIBS 313
#define CALL 314
#define TAIL 315
#define ASM_TOK 316
#define MODULE 317
#define SIDEEFFECT 318
#define CC_TOK 319
#define CCC_TOK 320
#define CSRETCC_TOK 321
#define FASTCC_TOK 322
#define COLDCC_TOK 323
#define X86_STDCALLCC_TOK 324
#define X86_FASTCALLCC_TOK 325
#define DATALAYOUT 326
#define RET 327
#define BR 328
#define SWITCH 329
#define INVOKE 330
#define UNWIND 331
#define UNREACHABLE 332
#define ADD 333
#define SUB 334
#define MUL 335
#define UDIV 336
#define SDIV 337
#define FDIV 338
#define UREM 339
#define SREM 340
#define FREM 341
#define AND 342
#define OR 343
#define XOR 344
#define SETLE 345
#define SETGE 346
#define SETLT 347
#define SETGT 348
#define SETEQ 349
#define SETNE 350
#define MALLOC 351
#define ALLOCA 352
#define FREE 353
#define LOAD 354
#define STORE 355
#define GETELEMENTPTR 356
#define TRUNC 357
#define ZEXT 358
#define SEXT 359
#define FPTRUNC 360
#define FPEXT 361
#define BITCAST 362
#define UITOFP 363
#define SITOFP 364
#define FPTOUI 365
#define FPTOSI 366
#define INTTOPTR 367
#define PTRTOINT 368
#define PHI_TOK 369
#define SELECT 370
#define SHL 371
#define LSHR 372
#define ASHR 373
#define VAARG 374
#define EXTRACTELEMENT 375
#define INSERTELEMENT 376
#define SHUFFLEVECTOR 377
#define CAST 378
#if ! defined (YYSTYPE) && ! defined (YYSTYPE_IS_DECLARED)
typedef int YYSTYPE;
# define yystype YYSTYPE /* obsolescent; will be withdrawn */
# define YYSTYPE_IS_DECLARED 1
# define YYSTYPE_IS_TRIVIAL 1
#endif
extern YYSTYPE Upgradelval;

View File

@ -0,0 +1,903 @@
//===-- UpgradeParser.y - Upgrade parser for llvm assmbly -------*- C++ -*-===//
//
// The LLVM Compiler Infrastructure
//
// This file was developed by Reid Spencer and is distributed under the
// University of Illinois Open Source License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
//
// This file implements the bison parser for LLVM 1.9 assembly language.
//
//===----------------------------------------------------------------------===//
%{
#define YYERROR_VERBOSE 1
#define YYSTYPE std::string*
#include "ParserInternals.h"
#include <llvm/ADT/StringExtras.h>
#include <llvm/System/MappedFile.h>
#include <algorithm>
#include <list>
#include <utility>
#include <iostream>
int yylex(); // declaration" of xxx warnings.
int yyparse();
static std::string CurFilename;
static std::ostream *O = 0;
void UpgradeAssembly(const std::string &infile, std::ostream &out)
{
Upgradelineno = 1;
CurFilename = infile;
llvm::sys::Path p(infile);
llvm::sys::MappedFile mf;
mf.open(p);
mf.map();
const char* base = mf.charBase();
size_t sz = mf.size();
set_scan_bytes(base, sz);
O = &out;
if (yyparse()) {
std::cerr << "Parse failed.\n";
exit(1);
}
}
%}
%token ESINT64VAL
%token EUINT64VAL
%token SINTVAL // Signed 32 bit ints...
%token UINTVAL // Unsigned 32 bit ints...
%token FPVAL // Float or Double constant
%token VOID BOOL SBYTE UBYTE SHORT USHORT INT UINT LONG ULONG
%token FLOAT DOUBLE TYPE LABEL
%token VAR_ID LABELSTR STRINGCONSTANT
%token IMPLEMENTATION ZEROINITIALIZER TRUETOK FALSETOK BEGINTOK ENDTOK
%token DECLARE GLOBAL CONSTANT SECTION VOLATILE
%token TO DOTDOTDOT NULL_TOK UNDEF CONST INTERNAL LINKONCE WEAK APPENDING
%token DLLIMPORT DLLEXPORT EXTERN_WEAK
%token OPAQUE NOT EXTERNAL TARGET TRIPLE ENDIAN POINTERSIZE LITTLE BIG ALIGN
%token DEPLIBS CALL TAIL ASM_TOK MODULE SIDEEFFECT
%token CC_TOK CCC_TOK CSRETCC_TOK FASTCC_TOK COLDCC_TOK
%token X86_STDCALLCC_TOK X86_FASTCALLCC_TOK
%token DATALAYOUT
%token RET BR SWITCH INVOKE UNWIND UNREACHABLE
%token ADD SUB MUL UDIV SDIV FDIV UREM SREM FREM AND OR XOR
%token SETLE SETGE SETLT SETGT SETEQ SETNE // Binary Comparators
%token MALLOC ALLOCA FREE LOAD STORE GETELEMENTPTR
%token TRUNC ZEXT SEXT FPTRUNC FPEXT BITCAST
%token UITOFP SITOFP FPTOUI FPTOSI INTTOPTR PTRTOINT
%token PHI_TOK SELECT SHL LSHR ASHR VAARG
%token EXTRACTELEMENT INSERTELEMENT SHUFFLEVECTOR
%token CAST
%start Module
%%
// Handle constant integer size restriction and conversion...
INTVAL : SINTVAL | UINTVAL
EINT64VAL : ESINT64VAL | EUINT64VAL;
// Operations that are notably excluded from this list include:
// RET, BR, & SWITCH because they end basic blocks and are treated specially.
ArithmeticOps: ADD | SUB | MUL | UDIV | SDIV | FDIV | UREM | SREM | FREM;
LogicalOps : AND | OR | XOR;
SetCondOps : SETLE | SETGE | SETLT | SETGT | SETEQ | SETNE;
CastOps : CAST;
ShiftOps : SHL | LSHR | ASHR;
// These are some types that allow classification if we only want a particular
// thing... for example, only a signed, unsigned, or integral type.
SIntType : LONG | INT | SHORT | SBYTE;
UIntType : ULONG | UINT | USHORT | UBYTE;
IntType : SIntType | UIntType;
FPType : FLOAT | DOUBLE;
// OptAssign - Value producing statements have an optional assignment component
OptAssign : Name '=' {
$1->append(" = ");
$$ = $1;
}
| /*empty*/ {
$$ = new std::string("");
};
OptLinkage
: INTERNAL | LINKONCE | WEAK | APPENDING | DLLIMPORT | DLLEXPORT
| EXTERN_WEAK
| /*empty*/ { $$ = new std::string(""); } ;
OptCallingConv
: CCC_TOK | CSRETCC_TOK | FASTCC_TOK | COLDCC_TOK | X86_STDCALLCC_TOK
| X86_FASTCALLCC_TOK | CC_TOK EUINT64VAL
| /*empty*/ { $$ = new std::string(""); } ;
// OptAlign/OptCAlign - An optional alignment, and an optional alignment with
// a comma before it.
OptAlign
: /*empty*/ { $$ = new std::string(); }
| ALIGN EUINT64VAL { *$1 += " " + *$2; delete $2; $$ = $1; };
;
OptCAlign
: /*empty*/ { $$ = new std::string(); }
| ',' ALIGN EUINT64VAL {
$2->insert(0, ", ");
*$2 += " " + *$3;
delete $3;
$$ = $2;
};
SectionString
: SECTION STRINGCONSTANT {
*$1 += " " + *$2;
delete $2;
$$ = $1;
};
OptSection : /*empty*/ { $$ = new std::string(); }
| SectionString;
GlobalVarAttributes
: /* empty */ { $$ = new std::string(); }
| ',' GlobalVarAttribute GlobalVarAttributes {
$2->insert(0, ", ");
if (!$3->empty())
*$2 += " " + *$3;
delete $3;
$$ = $2;
};
GlobalVarAttribute
: SectionString
| ALIGN EUINT64VAL {
*$1 += " " + *$2;
delete $2;
$$ = $1;
};
//===----------------------------------------------------------------------===//
// Types includes all predefined types... except void, because it can only be
// used in specific contexts (function returning void for example). To have
// access to it, a user must explicitly use TypesV.
//
// TypesV includes all of 'Types', but it also includes the void type.
TypesV : Types | VOID ;
UpRTypesV : UpRTypes | VOID ;
Types : UpRTypes ;
// Derived types are added later...
//
PrimType : BOOL | SBYTE | UBYTE | SHORT | USHORT | INT | UINT ;
PrimType : LONG | ULONG | FLOAT | DOUBLE | TYPE | LABEL;
UpRTypes : OPAQUE | PrimType | SymbolicValueRef ;
// Include derived types in the Types production.
//
UpRTypes : '\\' EUINT64VAL { // Type UpReference
$2->insert(0, "\\");
$$ = $2;
}
| UpRTypesV '(' ArgTypeListI ')' { // Function derived type?
*$1 += "( " + *$3 + " )";
delete $3;
$$ = $1;
}
| '[' EUINT64VAL 'x' UpRTypes ']' { // Sized array type?
$2->insert(0,"[ ");
*$2 += " x " + *$4 + " ]";
delete $4;
$$ = $2;
}
| '<' EUINT64VAL 'x' UpRTypes '>' { // Packed array type?
$2->insert(0,"< ");
*$2 += " x " + *$4 + " >";
delete $4;
$$ = $2;
}
| '{' TypeListI '}' { // Structure type?
$2->insert(0, "{ ");
*$2 += " }";
$$ = $2;
}
| '{' '}' { // Empty structure type?
$$ = new std::string("{ }");
}
| UpRTypes '*' { // Pointer type?
*$1 += '*';
$$ = $1;
};
// TypeList - Used for struct declarations and as a basis for function type
// declaration type lists
//
TypeListI : UpRTypes | TypeListI ',' UpRTypes {
*$1 += ", " + *$3;
delete $3;
$$ = $1;
};
// ArgTypeList - List of types for a function type declaration...
ArgTypeListI : TypeListI
| TypeListI ',' DOTDOTDOT {
*$1 += ", ...";
delete $3;
$$ = $1;
}
| DOTDOTDOT {
$$ = $1;
}
| /*empty*/ {
$$ = new std::string();
};
// ConstVal - The various declarations that go into the constant pool. This
// production is used ONLY to represent constants that show up AFTER a 'const',
// 'constant' or 'global' token at global scope. Constants that can be inlined
// into other expressions (such as integers and constexprs) are handled by the
// ResolvedVal, ValueRef and ConstValueRef productions.
//
ConstVal: Types '[' ConstVector ']' { // Nonempty unsized arr
*$1 += " [ " + *$3 + " ]";
delete $3;
$$ = $1;
}
| Types '[' ']' {
$$ = new std::string("[ ]");
}
| Types 'c' STRINGCONSTANT {
*$1 += " c" + *$3;
delete $3;
$$ = $1;
}
| Types '<' ConstVector '>' { // Nonempty unsized arr
*$1 += " < " + *$3 + " >";
delete $3;
$$ = $1;
}
| Types '{' ConstVector '}' {
*$1 += " { " + *$3 + " }";
delete $3;
$$ = $1;
}
| Types '{' '}' {
$$ = new std::string("[ ]");
}
| Types NULL_TOK {
*$1 += " " + *$2;
delete $2;
$$ = $1;
}
| Types UNDEF {
*$1 += " " + *$2;
delete $2;
$$ = $1;
}
| Types SymbolicValueRef {
*$1 += " " + *$2;
delete $2;
$$ = $1;
}
| Types ConstExpr {
*$1 += " " + *$2;
delete $2;
$$ = $1;
}
| Types ZEROINITIALIZER {
*$1 += " " + *$2;
delete $2;
$$ = $1;
};
ConstVal : SIntType EINT64VAL { // integral constants
*$1 += " " + *$2;
delete $2;
$$ = $1;
}
| UIntType EUINT64VAL { // integral constants
*$1 += " " + *$2;
delete $2;
$$ = $1;
}
| BOOL TRUETOK { // Boolean constants
*$1 += " " + *$2;
delete $2;
$$ = $1;
}
| BOOL FALSETOK { // Boolean constants
*$1 += " " + *$2;
delete $2;
$$ = $1;
}
| FPType FPVAL { // Float & Double constants
*$1 += " " + *$2;
delete $2;
$$ = $1;
};
ConstExpr: CastOps '(' ConstVal TO Types ')' {
*$1 += " (" + *$3 + " " + *$4 + " " + *$5 + ")";
delete $3; delete $4; delete $5;
$$ = $1;
}
| GETELEMENTPTR '(' ConstVal IndexList ')' {
}
| SELECT '(' ConstVal ',' ConstVal ',' ConstVal ')' {
}
| ArithmeticOps '(' ConstVal ',' ConstVal ')' {
}
| LogicalOps '(' ConstVal ',' ConstVal ')' {
}
| SetCondOps '(' ConstVal ',' ConstVal ')' {
}
| ShiftOps '(' ConstVal ',' ConstVal ')' {
}
| EXTRACTELEMENT '(' ConstVal ',' ConstVal ')' {
}
| INSERTELEMENT '(' ConstVal ',' ConstVal ',' ConstVal ')' {
}
| SHUFFLEVECTOR '(' ConstVal ',' ConstVal ',' ConstVal ')' {
};
// ConstVector - A list of comma separated constants.
ConstVector : ConstVector ',' ConstVal {
}
| ConstVal {
};
// GlobalType - Match either GLOBAL or CONSTANT for global declarations...
GlobalType : GLOBAL { } | CONSTANT { };
//===----------------------------------------------------------------------===//
// Rules to match Modules
//===----------------------------------------------------------------------===//
// Module rule: Capture the result of parsing the whole file into a result
// variable...
//
Module : DefinitionList {
};
// DefinitionList - Top level definitions
//
DefinitionList : DefinitionList Function {
$$ = 0;
}
| DefinitionList FunctionProto {
*O << *$2 << "\n";
delete $2;
$$ = 0;
}
| DefinitionList MODULE ASM_TOK AsmBlock {
*O << "module asm " << " " << *$4 << "\n";
}
| DefinitionList IMPLEMENTATION {
*O << "implementation\n";
}
| ConstPool {
};
// ConstPool - Constants with optional names assigned to them.
ConstPool : ConstPool OptAssign TYPE TypesV {
*O << *$2 << " " << *$3 << " " << *$4 << "\n";
delete $2; delete $3; delete $4;
$$ = 0;
}
| ConstPool FunctionProto { // Function prototypes can be in const pool
*O << *$2 << "\n";
delete $2;
$$ = 0;
}
| ConstPool MODULE ASM_TOK AsmBlock { // Asm blocks can be in the const pool
*O << *$2 << " " << *$3 << " " << *$4 << "\n";
delete $2; delete $3; delete $4;
$$ = 0;
}
| ConstPool OptAssign OptLinkage GlobalType ConstVal GlobalVarAttributes {
*O << *$2 << " " << *$3 << " " << *$4 << " " << *$5 << " " << *$6 << "\n";
delete $2; delete $3; delete $4; delete $5; delete $6;
$$ = 0;
}
| ConstPool OptAssign EXTERNAL GlobalType Types GlobalVarAttributes {
*O << *$2 << " " << *$3 << " " << *$4 << " " << *$5 << " " << *$6 << "\n";
delete $2; delete $3; delete $4; delete $5; delete $6;
$$ = 0;
}
| ConstPool OptAssign DLLIMPORT GlobalType Types GlobalVarAttributes {
*O << *$2 << " " << *$3 << " " << *$4 << " " << *$5 << " " << *$6 << "\n";
delete $2; delete $3; delete $4; delete $5; delete $6;
$$ = 0;
}
| ConstPool OptAssign EXTERN_WEAK GlobalType Types GlobalVarAttributes {
*O << *$2 << " " << *$3 << " " << *$4 << " " << *$5 << " " << *$6 << "\n";
delete $2; delete $3; delete $4; delete $5; delete $6;
$$ = 0;
}
| ConstPool TARGET TargetDefinition {
*O << *$2 << " " << *$3 << "\n";
delete $2; delete $3;
$$ = 0;
}
| ConstPool DEPLIBS '=' LibrariesDefinition {
*O << *$2 << " = " << *$4 << "\n";
delete $2; delete $4;
$$ = 0;
}
| /* empty: end of list */ {
$$ = 0;
};
AsmBlock : STRINGCONSTANT ;
BigOrLittle : BIG | LITTLE
TargetDefinition
: ENDIAN '=' BigOrLittle {
*$1 += " = " + *$2;
delete $2;
$$ = $1;
}
| POINTERSIZE '=' EUINT64VAL {
*$1 += " = " + *$2;
delete $2;
$$ = $1;
}
| TRIPLE '=' STRINGCONSTANT {
*$1 += " = " + *$2;
delete $2;
$$ = $1;
}
| DATALAYOUT '=' STRINGCONSTANT {
*$1 += " = " + *$2;
delete $2;
$$ = $1;
};
LibrariesDefinition
: '[' LibList ']' {
$2->insert(0, "[ ");
*$2 += " ]";
$$ = $2;
};
LibList
: LibList ',' STRINGCONSTANT {
*$1 += ", " + *$3;
delete $3;
$$ = $1;
}
| STRINGCONSTANT
| /* empty: end of list */ {
$$ = new std::string();
};
//===----------------------------------------------------------------------===//
// Rules to match Function Headers
//===----------------------------------------------------------------------===//
Name : VAR_ID | STRINGCONSTANT;
OptName : Name | /*empty*/ { $$ = new std::string(); };
ArgVal : Types OptName {
$$ = $1;
if (!$2->empty())
*$$ += " " + *$2;
};
ArgListH : ArgListH ',' ArgVal {
*$1 += ", " + *$3;
}
| ArgVal {
$$ = $1;
};
ArgList : ArgListH {
$$ = $1;
}
| ArgListH ',' DOTDOTDOT {
*$1 += ", ...";
$$ = $1;
}
| DOTDOTDOT {
$$ = $1;
}
| /* empty */ {
$$ = new std::string();
};
FunctionHeaderH : OptCallingConv TypesV Name '(' ArgList ')'
OptSection OptAlign {
if (!$1->empty()) {
$2->insert(0, *$1 + " ");
}
*$2 += " " + *$3 + "( " + *$5 + " )";
if (!$7->empty()) {
*$2 += " " + *$7;
}
if (!$8->empty()) {
*$2 += " " + *$8;
}
$$ = $2;
};
BEGIN : BEGINTOK {
$$ = new std::string("begin");
}
| '{' {
$$ = new std::string ("{");
}
FunctionHeader : OptLinkage FunctionHeaderH BEGIN {
if (!$1->empty()) {
*O << *$1 << " ";
}
*O << *$2 << " " << *$3 << "\n";
delete $1; delete $2; delete $3;
$$ = 0;
};
END : ENDTOK { $$ = new std::string("end"); }
| '}' { $$ = new std::string("}"); };
Function : FunctionHeader BasicBlockList END {
if ($2)
*O << *$2;
*O << '\n' << *$3 << "\n";
};
FnDeclareLinkage: /*default*/
| DLLIMPORT
| EXTERN_WEAK
;
FunctionProto
: DECLARE FnDeclareLinkage FunctionHeaderH {
*$1 += " " + *$2 + " " + *$3;
delete $2; delete $3;
$$ = $1;
};
//===----------------------------------------------------------------------===//
// Rules to match Basic Blocks
//===----------------------------------------------------------------------===//
OptSideEffect : /* empty */ {
}
| SIDEEFFECT {
};
ConstValueRef : ESINT64VAL | EUINT64VAL | FPVAL | TRUETOK | FALSETOK
| NULL_TOK | UNDEF | ZEROINITIALIZER
| '<' ConstVector '>' {
$2->insert(0, "<");
*$2 += ">";
$$ = $2;
}
| ConstExpr
| ASM_TOK OptSideEffect STRINGCONSTANT ',' STRINGCONSTANT {
if (!$2->empty()) {
*$1 += " " + *$2;
}
*$1 += " " + *$3 + ", " + *$4;
delete $2; delete $3; delete $4;
$$ = $1;
};
SymbolicValueRef : INTVAL | Name ;
// ValueRef - A reference to a definition... either constant or symbolic
ValueRef : SymbolicValueRef | ConstValueRef;
// ResolvedVal - a <type> <value> pair. This is used only in cases where the
// type immediately preceeds the value reference, and allows complex constant
// pool references (for things like: 'ret [2 x int] [ int 12, int 42]')
ResolvedVal : Types ValueRef {
*$1 += " " + *$2;
delete $2;
$$ = $1;
};
BasicBlockList : BasicBlockList BasicBlock {
}
| BasicBlock { // Do not allow functions with 0 basic blocks
};
// Basic blocks are terminated by branching instructions:
// br, br/cc, switch, ret
//
BasicBlock : InstructionList OptAssign BBTerminatorInst {
*O << *$2 ;
};
InstructionList : InstructionList Inst {
*O << " " << *$2 << "\n";
delete $2;
$$ = 0;
}
| /* empty */ {
$$ = 0;
}
| LABELSTR {
*O << *$1 << "\n";
delete $1;
$$ = 0;
};
BBTerminatorInst : RET ResolvedVal { // Return with a result...
*O << " " << *$1 << " " << *$2 << "\n";
delete $1; delete $2;
$$ = 0;
}
| RET VOID { // Return with no result...
*O << " " << *$1 << " " << *$2 << "\n";
delete $1; delete $2;
$$ = 0;
}
| BR LABEL ValueRef { // Unconditional Branch...
*O << " " << *$1 << " " << *$2 << " " << *$3 << "\n";
delete $1; delete $2; delete $3;
$$ = 0;
} // Conditional Branch...
| BR BOOL ValueRef ',' LABEL ValueRef ',' LABEL ValueRef {
*O << " " << *$1 << " " << *$2 << " " << *$3 << ", " << *$5 << " "
<< *$6 << ", " << *$8 << " " << *$9 << "\n";
delete $1; delete $2; delete $3; delete $5; delete $6; delete $8; delete $9;
$$ = 0;
}
| SWITCH IntType ValueRef ',' LABEL ValueRef '[' JumpTable ']' {
*O << " " << *$1 << " " << *$2 << " " << *$3 << ", " << *$5 << " "
<< *$6 << " [" << *$8 << " ]\n";
delete $1; delete $2; delete $3; delete $5; delete $6; delete $8;
$$ = 0;
}
| SWITCH IntType ValueRef ',' LABEL ValueRef '[' ']' {
*O << " " << *$1 << " " << *$2 << " " << *$3 << ", " << *$5 << " "
<< *$6 << "[]\n";
delete $1; delete $2; delete $3; delete $5; delete $6;
$$ = 0;
}
| INVOKE OptCallingConv TypesV ValueRef '(' ValueRefListE ')'
TO LABEL ValueRef UNWIND LABEL ValueRef {
*O << " " << *$1 << " " << *$2 << " " << *$3 << " " << *$4 << " ("
<< *$6 << ") " << *$8 << " " << *$9 << " " << *$10 << " " << *$11 << " "
<< *$12 << " " << *$13 << "\n";
delete $1; delete $2; delete $3; delete $4; delete $6; delete $8; delete $9;
delete $10; delete $11; delete $12; delete $13;
$$ = 0;
}
| UNWIND {
*O << " " << *$1 << "\n";
delete $1;
$$ = 0;
}
| UNREACHABLE {
*O << " " << *$1 << "\n";
delete $1;
$$ = 0;
};
JumpTable : JumpTable IntType ConstValueRef ',' LABEL ValueRef {
*$1 += *$2 + " " + *$3 + ", " + *$5 + " " + *$6;
delete $2; delete $3; delete $5; delete $6;
$$ = $1;
}
| IntType ConstValueRef ',' LABEL ValueRef {
*$1 += *$2 + ", " + *$4 + " " + *$5;
delete $2; delete $4; delete $5;
$$ = $1;
};
Inst
: OptAssign InstVal {
*$1 += *$2;
delete $2;
$$ = $1;
};
PHIList
: Types '[' ValueRef ',' ValueRef ']' { // Used for PHI nodes
*$1 += " [" + *$3 + "," + *$5 + "]";
delete $3; delete $5;
$$ = $1;
}
| PHIList ',' '[' ValueRef ',' ValueRef ']' {
*$1 += ", [" + *$4 + "," + *$6 + "]";
delete $4; delete $6;
$$ = $1;
};
ValueRefList
: ResolvedVal
| ValueRefList ',' ResolvedVal {
*$1 += ", " + *$3;
delete $3;
$$ = $1;
};
// ValueRefListE - Just like ValueRefList, except that it may also be empty!
ValueRefListE
: ValueRefList
| /*empty*/ { $$ = new std::string(); }
;
OptTailCall
: TAIL CALL {
*$1 += " " + *$2;
delete $2;
$$ = $1;
}
| CALL
;
InstVal : ArithmeticOps Types ValueRef ',' ValueRef {
*$1 += " " + *$2 + " " + *$3 + ", " + *$5;
delete $2; delete $3; delete $5;
$$ = $1;
}
| LogicalOps Types ValueRef ',' ValueRef {
*$1 += " " + *$2 + " " + *$3 + ", " + *$5;
delete $2; delete $3; delete $5;
$$ = $1;
}
| SetCondOps Types ValueRef ',' ValueRef {
*$1 += " " + *$2 + " " + *$3 + ", " + *$5;
delete $2; delete $3; delete $5;
$$ = $1;
}
| NOT ResolvedVal {
*$1 += " " + *$2;
delete $2;
$$ = $1;
}
| ShiftOps ResolvedVal ',' ResolvedVal {
*$1 += " " + *$2 + ", " + *$4;
delete $2; delete $4;
$$ = $1;
}
| CastOps ResolvedVal TO Types {
*$1 += " " + *$2 + " " + *$3 + ", " + *$4;
delete $2; delete $3; delete $4;
$$ = $1;
}
| SELECT ResolvedVal ',' ResolvedVal ',' ResolvedVal {
*$1 += " " + *$2 + ", " + *$4 + ", " + *$6;
delete $2; delete $4; delete $6;
$$ = $1;
}
| VAARG ResolvedVal ',' Types {
*$1 += " " + *$2 + ", " + *$4;
delete $2; delete $4;
$$ = $1;
}
| EXTRACTELEMENT ResolvedVal ',' ResolvedVal {
*$1 += " " + *$2 + ", " + *$4;
delete $2; delete $4;
$$ = $1;
}
| INSERTELEMENT ResolvedVal ',' ResolvedVal ',' ResolvedVal {
*$1 += " " + *$2 + ", " + *$4 + ", " + *$6;
delete $2; delete $4; delete $6;
$$ = $1;
}
| SHUFFLEVECTOR ResolvedVal ',' ResolvedVal ',' ResolvedVal {
*$1 += " " + *$2 + ", " + *$4 + ", " + *$6;
delete $2; delete $4; delete $6;
$$ = $1;
}
| PHI_TOK PHIList {
*$1 += " " + *$2;
delete $2;
$$ = $1;
}
| OptTailCall OptCallingConv TypesV ValueRef '(' ValueRefListE ')' {
if (!$2->empty())
*$1 += " " + *$2;
if (!$1->empty())
*$1 += " ";
*$1 += *$3 += " " + *$4 + "(" + *$5 + ")";
delete $2; delete $3; delete $4; delete $6;
$$ = $1;
}
| MemoryInst ;
// IndexList - List of indices for GEP based instructions...
IndexList
: ',' ValueRefList {
$2->insert(0, ", ");
$$ = $2;
}
| /* empty */ { $$ = new std::string(); }
;
OptVolatile
: VOLATILE
| /* empty */ { $$ = new std::string(); }
;
MemoryInst : MALLOC Types OptCAlign {
*$1 += " " + *$2;
if (!$3->empty())
*$1 += " " + *$3;
delete $2; delete $3;
$$ = $1;
}
| MALLOC Types ',' UINT ValueRef OptCAlign {
*$1 += " " + *$2 + ", " + *$4 + " " + *$5;
if (!$6->empty())
*$1 += " " + *$6;
delete $2; delete $4; delete $5; delete $6;
$$ = $1;
}
| ALLOCA Types OptCAlign {
*$1 += " " + *$2;
if (!$3->empty())
*$1 += " " + *$3;
delete $2; delete $3;
$$ = $1;
}
| ALLOCA Types ',' UINT ValueRef OptCAlign {
*$1 += " " + *$2 + ", " + *$4 + " " + *$5;
if (!$6->empty())
*$1 += " " + *$6;
delete $2; delete $4; delete $5; delete $6;
$$ = $1;
}
| FREE ResolvedVal {
*$1 += " " + *$2;
delete $2;
$$ = $1;
}
| OptVolatile LOAD Types ValueRef {
if (!$1->empty())
*$1 += " ";
*$1 += *$2 + " " + *$3 + " " + *$4;
delete $2; delete $3; delete $4;
$$ = $1;
}
| OptVolatile STORE ResolvedVal ',' Types ValueRef {
if (!$1->empty())
*$1 += " ";
*$1 += *$2 + " " + *$3 + ", " + *$5 + " " + *$6;
delete $2; delete $3; delete $5; delete $6;
$$ = $1;
}
| GETELEMENTPTR Types ValueRef IndexList {
*$1 += *$2 + " " + *$3 + " " + *$4;
delete $2; delete $3; delete $4;
$$ = $1;
};
%%
int yyerror(const char *ErrorMsg) {
std::string where
= std::string((CurFilename == "-") ? std::string("<stdin>") : CurFilename)
+ ":" + llvm::utostr((unsigned) Upgradelineno) + ": ";
std::string errMsg = std::string(ErrorMsg) + "\n" + where + " while reading ";
if (yychar == YYEMPTY || yychar == 0)
errMsg += "end-of-file.";
else
errMsg += "token: '" + std::string(Upgradetext, Upgradeleng) + "'";
std::cerr << errMsg << '\n';
exit(1);
}

View File

@ -0,0 +1,903 @@
//===-- upgradeParser.y - Upgrade parser for llvm assmbly -------*- C++ -*-===//
//
// The LLVM Compiler Infrastructure
//
// This file was developed by Reid Spencer and is distributed under the
// University of Illinois Open Source License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
//
// This file implements the bison parser for LLVM assembly language upgrade.
//
//===----------------------------------------------------------------------===//
%{
#define YYERROR_VERBOSE 1
#define YYSTYPE std::string*
#include "ParserInternals.h"
#include <llvm/ADT/StringExtras.h>
#include <llvm/System/MappedFile.h>
#include <algorithm>
#include <list>
#include <utility>
#include <iostream>
int yylex(); // declaration" of xxx warnings.
int yyparse();
static std::string CurFilename;
static std::ostream *O = 0;
void UpgradeAssembly(const std::string &infile, std::ostream &out)
{
Upgradelineno = 1;
CurFilename = infile;
llvm::sys::Path p(infile);
llvm::sys::MappedFile mf;
mf.open(p);
mf.map();
const char* base = mf.charBase();
size_t sz = mf.size();
set_scan_bytes(base, sz);
O = &out;
if (yyparse()) {
std::cerr << "Parse failed.\n";
exit(1);
}
}
%}
%token ESINT64VAL
%token EUINT64VAL
%token SINTVAL // Signed 32 bit ints...
%token UINTVAL // Unsigned 32 bit ints...
%token FPVAL // Float or Double constant
%token VOID BOOL SBYTE UBYTE SHORT USHORT INT UINT LONG ULONG
%token FLOAT DOUBLE TYPE LABEL
%token VAR_ID LABELSTR STRINGCONSTANT
%token IMPLEMENTATION ZEROINITIALIZER TRUETOK FALSETOK BEGINTOK ENDTOK
%token DECLARE GLOBAL CONSTANT SECTION VOLATILE
%token TO DOTDOTDOT NULL_TOK UNDEF CONST INTERNAL LINKONCE WEAK APPENDING
%token DLLIMPORT DLLEXPORT EXTERN_WEAK
%token OPAQUE NOT EXTERNAL TARGET TRIPLE ENDIAN POINTERSIZE LITTLE BIG ALIGN
%token DEPLIBS CALL TAIL ASM_TOK MODULE SIDEEFFECT
%token CC_TOK CCC_TOK CSRETCC_TOK FASTCC_TOK COLDCC_TOK
%token X86_STDCALLCC_TOK X86_FASTCALLCC_TOK
%token DATALAYOUT
%token RET BR SWITCH INVOKE UNWIND UNREACHABLE
%token ADD SUB MUL UDIV SDIV FDIV UREM SREM FREM AND OR XOR
%token SETLE SETGE SETLT SETGT SETEQ SETNE // Binary Comparators
%token MALLOC ALLOCA FREE LOAD STORE GETELEMENTPTR
%token TRUNC ZEXT SEXT FPTRUNC FPEXT BITCAST
%token UITOFP SITOFP FPTOUI FPTOSI INTTOPTR PTRTOINT
%token PHI_TOK SELECT SHL LSHR ASHR VAARG
%token EXTRACTELEMENT INSERTELEMENT SHUFFLEVECTOR
%token CAST
%start Module
%%
// Handle constant integer size restriction and conversion...
INTVAL : SINTVAL | UINTVAL
EINT64VAL : ESINT64VAL | EUINT64VAL;
// Operations that are notably excluded from this list include:
// RET, BR, & SWITCH because they end basic blocks and are treated specially.
ArithmeticOps: ADD | SUB | MUL | UDIV | SDIV | FDIV | UREM | SREM | FREM;
LogicalOps : AND | OR | XOR;
SetCondOps : SETLE | SETGE | SETLT | SETGT | SETEQ | SETNE;
CastOps : CAST;
ShiftOps : SHL | LSHR | ASHR;
// These are some types that allow classification if we only want a particular
// thing... for example, only a signed, unsigned, or integral type.
SIntType : LONG | INT | SHORT | SBYTE;
UIntType : ULONG | UINT | USHORT | UBYTE;
IntType : SIntType | UIntType;
FPType : FLOAT | DOUBLE;
// OptAssign - Value producing statements have an optional assignment component
OptAssign : Name '=' {
$1->append(" = ");
$$ = $1;
}
| /*empty*/ {
$$ = new std::string("");
};
OptLinkage
: INTERNAL | LINKONCE | WEAK | APPENDING | DLLIMPORT | DLLEXPORT
| EXTERN_WEAK
| /*empty*/ { $$ = new std::string(""); } ;
OptCallingConv
: CCC_TOK | CSRETCC_TOK | FASTCC_TOK | COLDCC_TOK | X86_STDCALLCC_TOK
| X86_FASTCALLCC_TOK | CC_TOK EUINT64VAL
| /*empty*/ { $$ = new std::string(""); } ;
// OptAlign/OptCAlign - An optional alignment, and an optional alignment with
// a comma before it.
OptAlign
: /*empty*/ { $$ = new std::string(); }
| ALIGN EUINT64VAL { *$1 += " " + *$2; delete $2; $$ = $1; };
;
OptCAlign
: /*empty*/ { $$ = new std::string(); }
| ',' ALIGN EUINT64VAL {
$2->insert(0, ", ");
*$2 += " " + *$3;
delete $3;
$$ = $2;
};
SectionString
: SECTION STRINGCONSTANT {
*$1 += " " + *$2;
delete $2;
$$ = $1;
};
OptSection : /*empty*/ { $$ = new std::string(); }
| SectionString;
GlobalVarAttributes
: /* empty */ { $$ = new std::string(); }
| ',' GlobalVarAttribute GlobalVarAttributes {
$2->insert(0, ", ");
if (!$3->empty())
*$2 += " " + *$3;
delete $3;
$$ = $2;
};
GlobalVarAttribute
: SectionString
| ALIGN EUINT64VAL {
*$1 += " " + *$2;
delete $2;
$$ = $1;
};
//===----------------------------------------------------------------------===//
// Types includes all predefined types... except void, because it can only be
// used in specific contexts (function returning void for example). To have
// access to it, a user must explicitly use TypesV.
//
// TypesV includes all of 'Types', but it also includes the void type.
TypesV : Types | VOID ;
UpRTypesV : UpRTypes | VOID ;
Types : UpRTypes ;
// Derived types are added later...
//
PrimType : BOOL | SBYTE | UBYTE | SHORT | USHORT | INT | UINT ;
PrimType : LONG | ULONG | FLOAT | DOUBLE | TYPE | LABEL;
UpRTypes : OPAQUE | PrimType | SymbolicValueRef ;
// Include derived types in the Types production.
//
UpRTypes : '\\' EUINT64VAL { // Type UpReference
$2->insert(0, "\\");
$$ = $2;
}
| UpRTypesV '(' ArgTypeListI ')' { // Function derived type?
*$1 += "( " + *$3 + " )";
delete $3;
$$ = $1;
}
| '[' EUINT64VAL 'x' UpRTypes ']' { // Sized array type?
$2->insert(0,"[ ");
*$2 += " x " + *$4 + " ]";
delete $4;
$$ = $2;
}
| '<' EUINT64VAL 'x' UpRTypes '>' { // Packed array type?
$2->insert(0,"< ");
*$2 += " x " + *$4 + " >";
delete $4;
$$ = $2;
}
| '{' TypeListI '}' { // Structure type?
$2->insert(0, "{ ");
*$2 += " }";
$$ = $2;
}
| '{' '}' { // Empty structure type?
$$ = new std::string("{ }");
}
| UpRTypes '*' { // Pointer type?
*$1 += '*';
$$ = $1;
};
// TypeList - Used for struct declarations and as a basis for function type
// declaration type lists
//
TypeListI : UpRTypes | TypeListI ',' UpRTypes {
*$1 += ", " + *$3;
delete $3;
$$ = $1;
};
// ArgTypeList - List of types for a function type declaration...
ArgTypeListI : TypeListI
| TypeListI ',' DOTDOTDOT {
*$1 += ", ...";
delete $3;
$$ = $1;
}
| DOTDOTDOT {
$$ = $1;
}
| /*empty*/ {
$$ = new std::string();
};
// ConstVal - The various declarations that go into the constant pool. This
// production is used ONLY to represent constants that show up AFTER a 'const',
// 'constant' or 'global' token at global scope. Constants that can be inlined
// into other expressions (such as integers and constexprs) are handled by the
// ResolvedVal, ValueRef and ConstValueRef productions.
//
ConstVal: Types '[' ConstVector ']' { // Nonempty unsized arr
*$1 += " [ " + *$3 + " ]";
delete $3;
$$ = $1;
}
| Types '[' ']' {
$$ = new std::string("[ ]");
}
| Types 'c' STRINGCONSTANT {
*$1 += " c" + *$3;
delete $3;
$$ = $1;
}
| Types '<' ConstVector '>' { // Nonempty unsized arr
*$1 += " < " + *$3 + " >";
delete $3;
$$ = $1;
}
| Types '{' ConstVector '}' {
*$1 += " { " + *$3 + " }";
delete $3;
$$ = $1;
}
| Types '{' '}' {
$$ = new std::string("[ ]");
}
| Types NULL_TOK {
*$1 += " " + *$2;
delete $2;
$$ = $1;
}
| Types UNDEF {
*$1 += " " + *$2;
delete $2;
$$ = $1;
}
| Types SymbolicValueRef {
*$1 += " " + *$2;
delete $2;
$$ = $1;
}
| Types ConstExpr {
*$1 += " " + *$2;
delete $2;
$$ = $1;
}
| Types ZEROINITIALIZER {
*$1 += " " + *$2;
delete $2;
$$ = $1;
};
ConstVal : SIntType EINT64VAL { // integral constants
*$1 += " " + *$2;
delete $2;
$$ = $1;
}
| UIntType EUINT64VAL { // integral constants
*$1 += " " + *$2;
delete $2;
$$ = $1;
}
| BOOL TRUETOK { // Boolean constants
*$1 += " " + *$2;
delete $2;
$$ = $1;
}
| BOOL FALSETOK { // Boolean constants
*$1 += " " + *$2;
delete $2;
$$ = $1;
}
| FPType FPVAL { // Float & Double constants
*$1 += " " + *$2;
delete $2;
$$ = $1;
};
ConstExpr: CastOps '(' ConstVal TO Types ')' {
*$1 += " (" + *$3 + " " + *$4 + " " + *$5 + ")";
delete $3; delete $4; delete $5;
$$ = $1;
}
| GETELEMENTPTR '(' ConstVal IndexList ')' {
}
| SELECT '(' ConstVal ',' ConstVal ',' ConstVal ')' {
}
| ArithmeticOps '(' ConstVal ',' ConstVal ')' {
}
| LogicalOps '(' ConstVal ',' ConstVal ')' {
}
| SetCondOps '(' ConstVal ',' ConstVal ')' {
}
| ShiftOps '(' ConstVal ',' ConstVal ')' {
}
| EXTRACTELEMENT '(' ConstVal ',' ConstVal ')' {
}
| INSERTELEMENT '(' ConstVal ',' ConstVal ',' ConstVal ')' {
}
| SHUFFLEVECTOR '(' ConstVal ',' ConstVal ',' ConstVal ')' {
};
// ConstVector - A list of comma separated constants.
ConstVector : ConstVector ',' ConstVal {
}
| ConstVal {
};
// GlobalType - Match either GLOBAL or CONSTANT for global declarations...
GlobalType : GLOBAL { } | CONSTANT { };
//===----------------------------------------------------------------------===//
// Rules to match Modules
//===----------------------------------------------------------------------===//
// Module rule: Capture the result of parsing the whole file into a result
// variable...
//
Module : DefinitionList {
};
// DefinitionList - Top level definitions
//
DefinitionList : DefinitionList Function {
$$ = 0;
}
| DefinitionList FunctionProto {
*O << *$2 << "\n";
delete $2;
$$ = 0;
}
| DefinitionList MODULE ASM_TOK AsmBlock {
*O << "module asm " << " " << *$4 << "\n";
}
| DefinitionList IMPLEMENTATION {
*O << "implementation\n";
}
| ConstPool {
};
// ConstPool - Constants with optional names assigned to them.
ConstPool : ConstPool OptAssign TYPE TypesV {
*O << *$2 << " " << *$3 << " " << *$4 << "\n";
delete $2; delete $3; delete $4;
$$ = 0;
}
| ConstPool FunctionProto { // Function prototypes can be in const pool
*O << *$2 << "\n";
delete $2;
$$ = 0;
}
| ConstPool MODULE ASM_TOK AsmBlock { // Asm blocks can be in the const pool
*O << *$2 << " " << *$3 << " " << *$4 << "\n";
delete $2; delete $3; delete $4;
$$ = 0;
}
| ConstPool OptAssign OptLinkage GlobalType ConstVal GlobalVarAttributes {
*O << *$2 << " " << *$3 << " " << *$4 << " " << *$5 << " " << *$6 << "\n";
delete $2; delete $3; delete $4; delete $5; delete $6;
$$ = 0;
}
| ConstPool OptAssign EXTERNAL GlobalType Types GlobalVarAttributes {
*O << *$2 << " " << *$3 << " " << *$4 << " " << *$5 << " " << *$6 << "\n";
delete $2; delete $3; delete $4; delete $5; delete $6;
$$ = 0;
}
| ConstPool OptAssign DLLIMPORT GlobalType Types GlobalVarAttributes {
*O << *$2 << " " << *$3 << " " << *$4 << " " << *$5 << " " << *$6 << "\n";
delete $2; delete $3; delete $4; delete $5; delete $6;
$$ = 0;
}
| ConstPool OptAssign EXTERN_WEAK GlobalType Types GlobalVarAttributes {
*O << *$2 << " " << *$3 << " " << *$4 << " " << *$5 << " " << *$6 << "\n";
delete $2; delete $3; delete $4; delete $5; delete $6;
$$ = 0;
}
| ConstPool TARGET TargetDefinition {
*O << *$2 << " " << *$3 << "\n";
delete $2; delete $3;
$$ = 0;
}
| ConstPool DEPLIBS '=' LibrariesDefinition {
*O << *$2 << " = " << *$4 << "\n";
delete $2; delete $4;
$$ = 0;
}
| /* empty: end of list */ {
$$ = 0;
};
AsmBlock : STRINGCONSTANT ;
BigOrLittle : BIG | LITTLE
TargetDefinition
: ENDIAN '=' BigOrLittle {
*$1 += " = " + *$2;
delete $2;
$$ = $1;
}
| POINTERSIZE '=' EUINT64VAL {
*$1 += " = " + *$2;
delete $2;
$$ = $1;
}
| TRIPLE '=' STRINGCONSTANT {
*$1 += " = " + *$2;
delete $2;
$$ = $1;
}
| DATALAYOUT '=' STRINGCONSTANT {
*$1 += " = " + *$2;
delete $2;
$$ = $1;
};
LibrariesDefinition
: '[' LibList ']' {
$2->insert(0, "[ ");
*$2 += " ]";
$$ = $2;
};
LibList
: LibList ',' STRINGCONSTANT {
*$1 += ", " + *$3;
delete $3;
$$ = $1;
}
| STRINGCONSTANT
| /* empty: end of list */ {
$$ = new std::string();
};
//===----------------------------------------------------------------------===//
// Rules to match Function Headers
//===----------------------------------------------------------------------===//
Name : VAR_ID | STRINGCONSTANT;
OptName : Name | /*empty*/ { $$ = new std::string(); };
ArgVal : Types OptName {
$$ = $1;
if (!$2->empty())
*$$ += " " + *$2;
};
ArgListH : ArgListH ',' ArgVal {
*$1 += ", " + *$3;
}
| ArgVal {
$$ = $1;
};
ArgList : ArgListH {
$$ = $1;
}
| ArgListH ',' DOTDOTDOT {
*$1 += ", ...";
$$ = $1;
}
| DOTDOTDOT {
$$ = $1;
}
| /* empty */ {
$$ = new std::string();
};
FunctionHeaderH : OptCallingConv TypesV Name '(' ArgList ')'
OptSection OptAlign {
if (!$1->empty()) {
$2->insert(0, *$1 + " ");
}
*$2 += " " + *$3 + "( " + *$5 + " )";
if (!$7->empty()) {
*$2 += " " + *$7;
}
if (!$8->empty()) {
*$2 += " " + *$8;
}
$$ = $2;
};
BEGIN : BEGINTOK {
$$ = new std::string("begin");
}
| '{' {
$$ = new std::string ("{");
}
FunctionHeader : OptLinkage FunctionHeaderH BEGIN {
if (!$1->empty()) {
*O << *$1 << " ";
}
*O << *$2 << " " << *$3 << "\n";
delete $1; delete $2; delete $3;
$$ = 0;
};
END : ENDTOK { $$ = new std::string("end"); }
| '}' { $$ = new std::string("}"); };
Function : FunctionHeader BasicBlockList END {
if ($2)
*O << *$2;
*O << '\n' << *$3 << "\n";
};
FnDeclareLinkage: /*default*/
| DLLIMPORT
| EXTERN_WEAK
;
FunctionProto
: DECLARE FnDeclareLinkage FunctionHeaderH {
*$1 += " " + *$2 + " " + *$3;
delete $2; delete $3;
$$ = $1;
};
//===----------------------------------------------------------------------===//
// Rules to match Basic Blocks
//===----------------------------------------------------------------------===//
OptSideEffect : /* empty */ {
}
| SIDEEFFECT {
};
ConstValueRef : ESINT64VAL | EUINT64VAL | FPVAL | TRUETOK | FALSETOK
| NULL_TOK | UNDEF | ZEROINITIALIZER
| '<' ConstVector '>' {
$2->insert(0, "<");
*$2 += ">";
$$ = $2;
}
| ConstExpr
| ASM_TOK OptSideEffect STRINGCONSTANT ',' STRINGCONSTANT {
if (!$2->empty()) {
*$1 += " " + *$2;
}
*$1 += " " + *$3 + ", " + *$4;
delete $2; delete $3; delete $4;
$$ = $1;
};
SymbolicValueRef : INTVAL | Name ;
// ValueRef - A reference to a definition... either constant or symbolic
ValueRef : SymbolicValueRef | ConstValueRef;
// ResolvedVal - a <type> <value> pair. This is used only in cases where the
// type immediately preceeds the value reference, and allows complex constant
// pool references (for things like: 'ret [2 x int] [ int 12, int 42]')
ResolvedVal : Types ValueRef {
*$1 += " " + *$2;
delete $2;
$$ = $1;
};
BasicBlockList : BasicBlockList BasicBlock {
}
| BasicBlock { // Do not allow functions with 0 basic blocks
};
// Basic blocks are terminated by branching instructions:
// br, br/cc, switch, ret
//
BasicBlock : InstructionList OptAssign BBTerminatorInst {
*O << *$2 ;
};
InstructionList : InstructionList Inst {
*O << " " << *$2 << "\n";
delete $2;
$$ = 0;
}
| /* empty */ {
$$ = 0;
}
| LABELSTR {
*O << *$1 << "\n";
delete $1;
$$ = 0;
};
BBTerminatorInst : RET ResolvedVal { // Return with a result...
*O << " " << *$1 << " " << *$2 << "\n";
delete $1; delete $2;
$$ = 0;
}
| RET VOID { // Return with no result...
*O << " " << *$1 << " " << *$2 << "\n";
delete $1; delete $2;
$$ = 0;
}
| BR LABEL ValueRef { // Unconditional Branch...
*O << " " << *$1 << " " << *$2 << " " << *$3 << "\n";
delete $1; delete $2; delete $3;
$$ = 0;
} // Conditional Branch...
| BR BOOL ValueRef ',' LABEL ValueRef ',' LABEL ValueRef {
*O << " " << *$1 << " " << *$2 << " " << *$3 << ", " << *$5 << " "
<< *$6 << ", " << *$8 << " " << *$9 << "\n";
delete $1; delete $2; delete $3; delete $5; delete $6; delete $8; delete $9;
$$ = 0;
}
| SWITCH IntType ValueRef ',' LABEL ValueRef '[' JumpTable ']' {
*O << " " << *$1 << " " << *$2 << " " << *$3 << ", " << *$5 << " "
<< *$6 << " [" << *$8 << " ]\n";
delete $1; delete $2; delete $3; delete $5; delete $6; delete $8;
$$ = 0;
}
| SWITCH IntType ValueRef ',' LABEL ValueRef '[' ']' {
*O << " " << *$1 << " " << *$2 << " " << *$3 << ", " << *$5 << " "
<< *$6 << "[]\n";
delete $1; delete $2; delete $3; delete $5; delete $6;
$$ = 0;
}
| INVOKE OptCallingConv TypesV ValueRef '(' ValueRefListE ')'
TO LABEL ValueRef UNWIND LABEL ValueRef {
*O << " " << *$1 << " " << *$2 << " " << *$3 << " " << *$4 << " ("
<< *$6 << ") " << *$8 << " " << *$9 << " " << *$10 << " " << *$11 << " "
<< *$12 << " " << *$13 << "\n";
delete $1; delete $2; delete $3; delete $4; delete $6; delete $8; delete $9;
delete $10; delete $11; delete $12; delete $13;
$$ = 0;
}
| UNWIND {
*O << " " << *$1 << "\n";
delete $1;
$$ = 0;
}
| UNREACHABLE {
*O << " " << *$1 << "\n";
delete $1;
$$ = 0;
};
JumpTable : JumpTable IntType ConstValueRef ',' LABEL ValueRef {
*$1 += *$2 + " " + *$3 + ", " + *$5 + " " + *$6;
delete $2; delete $3; delete $5; delete $6;
$$ = $1;
}
| IntType ConstValueRef ',' LABEL ValueRef {
*$1 += *$2 + ", " + *$4 + " " + *$5;
delete $2; delete $4; delete $5;
$$ = $1;
};
Inst
: OptAssign InstVal {
*$1 += *$2;
delete $2;
$$ = $1;
};
PHIList
: Types '[' ValueRef ',' ValueRef ']' { // Used for PHI nodes
*$1 += " [" + *$3 + "," + *$5 + "]";
delete $3; delete $5;
$$ = $1;
}
| PHIList ',' '[' ValueRef ',' ValueRef ']' {
*$1 += ", [" + *$4 + "," + *$6 + "]";
delete $4; delete $6;
$$ = $1;
};
ValueRefList
: ResolvedVal
| ValueRefList ',' ResolvedVal {
*$1 += ", " + *$3;
delete $3;
$$ = $1;
};
// ValueRefListE - Just like ValueRefList, except that it may also be empty!
ValueRefListE
: ValueRefList
| /*empty*/ { $$ = new std::string(); }
;
OptTailCall
: TAIL CALL {
*$1 += " " + *$2;
delete $2;
$$ = $1;
}
| CALL
;
InstVal : ArithmeticOps Types ValueRef ',' ValueRef {
*$1 += " " + *$2 + " " + *$3 + ", " + *$5;
delete $2; delete $3; delete $5;
$$ = $1;
}
| LogicalOps Types ValueRef ',' ValueRef {
*$1 += " " + *$2 + " " + *$3 + ", " + *$5;
delete $2; delete $3; delete $5;
$$ = $1;
}
| SetCondOps Types ValueRef ',' ValueRef {
*$1 += " " + *$2 + " " + *$3 + ", " + *$5;
delete $2; delete $3; delete $5;
$$ = $1;
}
| NOT ResolvedVal {
*$1 += " " + *$2;
delete $2;
$$ = $1;
}
| ShiftOps ResolvedVal ',' ResolvedVal {
*$1 += " " + *$2 + ", " + *$4;
delete $2; delete $4;
$$ = $1;
}
| CastOps ResolvedVal TO Types {
*$1 += " " + *$2 + " " + *$3 + ", " + *$4;
delete $2; delete $3; delete $4;
$$ = $1;
}
| SELECT ResolvedVal ',' ResolvedVal ',' ResolvedVal {
*$1 += " " + *$2 + ", " + *$4 + ", " + *$6;
delete $2; delete $4; delete $6;
$$ = $1;
}
| VAARG ResolvedVal ',' Types {
*$1 += " " + *$2 + ", " + *$4;
delete $2; delete $4;
$$ = $1;
}
| EXTRACTELEMENT ResolvedVal ',' ResolvedVal {
*$1 += " " + *$2 + ", " + *$4;
delete $2; delete $4;
$$ = $1;
}
| INSERTELEMENT ResolvedVal ',' ResolvedVal ',' ResolvedVal {
*$1 += " " + *$2 + ", " + *$4 + ", " + *$6;
delete $2; delete $4; delete $6;
$$ = $1;
}
| SHUFFLEVECTOR ResolvedVal ',' ResolvedVal ',' ResolvedVal {
*$1 += " " + *$2 + ", " + *$4 + ", " + *$6;
delete $2; delete $4; delete $6;
$$ = $1;
}
| PHI_TOK PHIList {
*$1 += " " + *$2;
delete $2;
$$ = $1;
}
| OptTailCall OptCallingConv TypesV ValueRef '(' ValueRefListE ')' {
if (!$2->empty())
*$1 += " " + *$2;
if (!$1->empty())
*$1 += " ";
*$1 += *$3 += " " + *$4 + "(" + *$5 + ")";
delete $2; delete $3; delete $4; delete $6;
$$ = $1;
}
| MemoryInst ;
// IndexList - List of indices for GEP based instructions...
IndexList
: ',' ValueRefList {
$2->insert(0, ", ");
$$ = $2;
}
| /* empty */ { $$ = new std::string(); }
;
OptVolatile
: VOLATILE
| /* empty */ { $$ = new std::string(); }
;
MemoryInst : MALLOC Types OptCAlign {
*$1 += " " + *$2;
if (!$3->empty())
*$1 += " " + *$3;
delete $2; delete $3;
$$ = $1;
}
| MALLOC Types ',' UINT ValueRef OptCAlign {
*$1 += " " + *$2 + ", " + *$4 + " " + *$5;
if (!$6->empty())
*$1 += " " + *$6;
delete $2; delete $4; delete $5; delete $6;
$$ = $1;
}
| ALLOCA Types OptCAlign {
*$1 += " " + *$2;
if (!$3->empty())
*$1 += " " + *$3;
delete $2; delete $3;
$$ = $1;
}
| ALLOCA Types ',' UINT ValueRef OptCAlign {
*$1 += " " + *$2 + ", " + *$4 + " " + *$5;
if (!$6->empty())
*$1 += " " + *$6;
delete $2; delete $4; delete $5; delete $6;
$$ = $1;
}
| FREE ResolvedVal {
*$1 += " " + *$2;
delete $2;
$$ = $1;
}
| OptVolatile LOAD Types ValueRef {
if (!$1->empty())
*$1 += " ";
*$1 += *$2 + " " + *$3 + " " + *$4;
delete $2; delete $3; delete $4;
$$ = $1;
}
| OptVolatile STORE ResolvedVal ',' Types ValueRef {
if (!$1->empty())
*$1 += " ";
*$1 += *$2 + " " + *$3 + ", " + *$5 + " " + *$6;
delete $2; delete $3; delete $5; delete $6;
$$ = $1;
}
| GETELEMENTPTR Types ValueRef IndexList {
*$1 += *$2 + " " + *$3 + " " + *$4;
delete $2; delete $3; delete $4;
$$ = $1;
};
%%
int yyerror(const char *ErrorMsg) {
std::string where
= std::string((CurFilename == "-") ? std::string("<stdin>") : CurFilename)
+ ":" + llvm::utostr((unsigned) Upgradelineno) + ": ";
std::string errMsg = std::string(ErrorMsg) + "\n" + where + " while reading ";
if (yychar == YYEMPTY || yychar == 0)
errMsg += "end-of-file.";
else
errMsg += "token: '" + std::string(Upgradetext, Upgradeleng) + "'";
std::cerr << errMsg << '\n';
exit(1);
}

View File

@ -0,0 +1,114 @@
//===--- llvm-upgrade.cpp - The LLVM Assembly Upgrader --------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file was developed by Reid Spencer and is distributed under the
// University of Illinois Open Source License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
//
// This utility will upgrade LLVM 1.9 Assembly to 2.0 format. It may be
// invoked as a filter, like this:
// llvm-1.9/bin/llvm-dis < 1.9.bc | llvm-upgrade | llvm-as > 2.0.bc
//
// or, you can directly upgrade, like this:
// llvm-upgrade -o 2.0.ll < 1.9.ll
//
// llvm-upgrade won't overwrite files by default. Use -f to force it to
// overwrite the output file.
//
//===----------------------------------------------------------------------===//
#include "ParserInternals.h"
#include "llvm/Support/CommandLine.h"
#include "llvm/Support/Streams.h"
#include "llvm/Support/SystemUtils.h"
#include "llvm/System/Signals.h"
#include <fstream>
#include <iostream>
#include <memory>
using namespace llvm;
static cl::opt<std::string>
InputFilename(cl::Positional, cl::desc("<input .llvm file>"), cl::init("-"));
static cl::opt<std::string>
OutputFilename("o", cl::desc("Override output filename"),
cl::value_desc("filename"));
static cl::opt<bool>
Force("f", cl::desc("Overwrite output files"));
int main(int argc, char **argv) {
cl::ParseCommandLineOptions(argc, argv, " llvm .ll -> .bc assembler\n");
sys::PrintStackTraceOnErrorSignal();
int exitCode = 0;
std::ostream *Out = 0;
try {
if (OutputFilename != "") { // Specified an output filename?
if (OutputFilename != "-") { // Not stdout?
if (!Force && std::ifstream(OutputFilename.c_str())) {
// If force is not specified, make sure not to overwrite a file!
llvm_cerr << argv[0] << ": error opening '" << OutputFilename
<< "': file exists!\n"
<< "Use -f command line argument to force output\n";
return 1;
}
Out = new std::ofstream(OutputFilename.c_str(), std::ios::out |
std::ios::trunc);
} else { // Specified stdout
Out = &std::cout;
}
} else {
if (InputFilename == "-") {
OutputFilename = "-";
Out = &std::cout;
} else {
std::string IFN = InputFilename;
int Len = IFN.length();
if (IFN[Len-3] == '.' && IFN[Len-2] == 'l' && IFN[Len-1] == 'l') {
// Source ends in .ll
OutputFilename = std::string(IFN.begin(), IFN.end()-3);
} else {
OutputFilename = IFN; // Append to it
}
OutputFilename += ".llu";
if (!Force && std::ifstream(OutputFilename.c_str())) {
// If force is not specified, make sure not to overwrite a file!
llvm_cerr << argv[0] << ": error opening '" << OutputFilename
<< "': file exists!\n"
<< "Use -f command line argument to force output\n";
return 1;
}
Out = new std::ofstream(OutputFilename.c_str(), std::ios::out |
std::ios::trunc | std::ios::binary);
// Make sure that the Out file gets unlinked from the disk if we get a
// SIGINT
sys::RemoveFileOnSignal(sys::Path(OutputFilename));
}
}
if (!Out->good()) {
llvm_cerr << argv[0] << ": error opening " << OutputFilename << "!\n";
return 1;
}
UpgradeAssembly(InputFilename, *Out);
/*
} catch (const std::string& caught_message) {
llvm_cerr << argv[0] << ": " << caught_message << "\n";
exitCode = 1;
*/
} catch (...) {
llvm_cerr << argv[0] << ": Unexpected unknown exception occurred.\n";
exitCode = 1;
}
if (Out != &std::cout) delete Out;
return exitCode;
}