+1
This commit is contained in:
@@ -1,4 +1,4 @@
|
|||||||
all: dePTX
|
all: dePTX ptxc
|
||||||
|
|
||||||
ptxgrammar.cc : ptxgrammar.yy
|
ptxgrammar.cc : ptxgrammar.yy
|
||||||
bison -d -v -t ptxgrammar.yy -o ptxgrammar.cc
|
bison -d -v -t ptxgrammar.yy -o ptxgrammar.cc
|
||||||
@@ -12,15 +12,19 @@ ptx.cc: ptx.ll ptxgrammar.cc
|
|||||||
%.o: %.cpp
|
%.o: %.cpp
|
||||||
clang++ -O3 -c $< -o $@ -I/opt/local/include
|
clang++ -O3 -c $< -o $@ -I/opt/local/include
|
||||||
|
|
||||||
OBJ= dePTX.o \
|
OBJ= ptx.o \
|
||||||
ptx.o \
|
|
||||||
ptxgrammar.o
|
ptxgrammar.o
|
||||||
|
|
||||||
dePTX: $(OBJ)
|
dePTX: dePTX.o $(OBJ)
|
||||||
|
clang++ $^ -o $@ -L/opt/local/lib
|
||||||
|
|
||||||
|
ptxc: ptxc.o $(OBJ)
|
||||||
clang++ $^ -o $@ -L/opt/local/lib
|
clang++ $^ -o $@ -L/opt/local/lib
|
||||||
|
|
||||||
clean:
|
clean:
|
||||||
/bin/rm -f dePTX $(OBJ) ptxgrammar.hh ptxgrammar.cc ptx.cc ptxgrammar.output
|
/bin/rm -f dePTX $(OBJ) ptxgrammar.hh ptxgrammar.cc ptx.cc ptxgrammar.output
|
||||||
|
|
||||||
$(OBJ): ptxgrammar.cc ptx.cc PTXParser.h PTXLexer.h
|
$(OBJ): ptxgrammar.cc ptx.cc PTXParser.h PTXLexer.h
|
||||||
|
dePTX.o: PTXParser.h PTXLexer.h
|
||||||
|
ptxc.o: PTXParser.h PTXLexer.h
|
||||||
|
|
||||||
|
|||||||
@@ -71,7 +71,7 @@ namespace parser
|
|||||||
s << "typedef float f32_t; \n";
|
s << "typedef float f32_t; \n";
|
||||||
s << "typedef double f64_t; \n";
|
s << "typedef double f64_t; \n";
|
||||||
s << " \n";
|
s << " \n";
|
||||||
std::cout << s.str();
|
out << s.str();
|
||||||
}
|
}
|
||||||
|
|
||||||
#define LOC YYLTYPE& location
|
#define LOC YYLTYPE& location
|
||||||
@@ -166,7 +166,7 @@ namespace parser
|
|||||||
s << "\n";
|
s << "\n";
|
||||||
argumentList.clear();
|
argumentList.clear();
|
||||||
|
|
||||||
std::cout << s.str();
|
out << s.str();
|
||||||
}
|
}
|
||||||
|
|
||||||
void visibleFunctionDeclaration(const std::string &calleeName, LOC)
|
void visibleFunctionDeclaration(const std::string &calleeName, LOC)
|
||||||
@@ -193,7 +193,7 @@ namespace parser
|
|||||||
argumentList.clear();
|
argumentList.clear();
|
||||||
returnArgumentList.clear();
|
returnArgumentList.clear();
|
||||||
|
|
||||||
std::cout << s.str();
|
out << s.str();
|
||||||
}
|
}
|
||||||
|
|
||||||
void visibleInitializableDeclaration(const std::string &name, LOC)
|
void visibleInitializableDeclaration(const std::string &name, LOC)
|
||||||
@@ -208,7 +208,7 @@ namespace parser
|
|||||||
s << name << ";\n\n";
|
s << name << ";\n\n";
|
||||||
else
|
else
|
||||||
s << name << "[" << arrayDimensionsList[0] << "] = {0};\n\n";
|
s << name << "[" << arrayDimensionsList[0] << "] = {0};\n\n";
|
||||||
std::cout << s.str();
|
out << s.str();
|
||||||
arrayDimensionsList.clear();
|
arrayDimensionsList.clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -6,7 +6,7 @@
|
|||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
#include "PTXParser.h"
|
#include "PTXParser.h"
|
||||||
|
|
||||||
static char lRandomChar()
|
static char lRandomAlNum()
|
||||||
{
|
{
|
||||||
const char charset[] =
|
const char charset[] =
|
||||||
"0123456789"
|
"0123456789"
|
||||||
@@ -19,11 +19,10 @@ static char lRandomChar()
|
|||||||
static std::string lRandomString(const size_t length)
|
static std::string lRandomString(const size_t length)
|
||||||
{
|
{
|
||||||
std::string str(length,0);
|
std::string str(length,0);
|
||||||
std::generate_n( str.begin(), length, lRandomChar);
|
std::generate_n( str.begin(), length, lRandomAlNum);
|
||||||
return str;
|
return str;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
static void lGetAllArgs(int Argc, char *Argv[], int &argc, char *argv[128])
|
static void lGetAllArgs(int Argc, char *Argv[], int &argc, char *argv[128])
|
||||||
{
|
{
|
||||||
// Copy over the command line arguments (passed in)
|
// Copy over the command line arguments (passed in)
|
||||||
@@ -49,8 +48,14 @@ static std::vector<std::string> lSplitString(const std::string &s, char delim)
|
|||||||
return elems;
|
return elems;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void usage(const int ret)
|
static void lUsage(const int ret)
|
||||||
{
|
{
|
||||||
|
fprintf(stderr, "\nusage: ptxc\n");
|
||||||
|
fprintf(stderr, " [--help]\t\t\t\t This help\n");
|
||||||
|
fprintf(stderr, " [--arch={%s}]\t\t\t GPU target architecture\n", "sm_35");
|
||||||
|
fprintf(stderr, " [-o <name>]\t\t\t\t Output file name\n");
|
||||||
|
fprintf(stderr, " [-Xnvcc=<arguments>]\t\t Arguments to pass through to \"nvcc\"\n");
|
||||||
|
fprintf(stderr, " \n");
|
||||||
exit(ret);
|
exit(ret);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -65,38 +70,39 @@ int main(int _argc, char * _argv[])
|
|||||||
std::string fileOBJ;
|
std::string fileOBJ;
|
||||||
std::string extString = ".ptx";
|
std::string extString = ".ptx";
|
||||||
bool keepTemporaries = false;
|
bool keepTemporaries = false;
|
||||||
|
std::string nvccArguments;
|
||||||
std::vector<std::string> nvccArgumentList;
|
|
||||||
|
|
||||||
for (int i = 1; i < argc; ++i)
|
for (int i = 1; i < argc; ++i)
|
||||||
{
|
{
|
||||||
if (!strcmp(argv[i], "--help"))
|
if (!strcmp(argv[i], "--help"))
|
||||||
usage(0);
|
lUsage(0);
|
||||||
else if (!strncmp(argv[i], "--arch=", 7))
|
else if (!strncmp(argv[i], "--arch=", 7))
|
||||||
arch = std::string(argv[i]+7);
|
arch = std::string(argv[i]+7);
|
||||||
else if (!strncmp(argv[i], "--keep-temporaries", 11))
|
else if (!strncmp(argv[i], "--keep-temporaries", 11))
|
||||||
keepTemporaries = true;
|
keepTemporaries = true;
|
||||||
|
else if (!strncmp(argv[i], "-Xnvcc=", 7))
|
||||||
|
nvccArguments = std::string(argv[i]+7);
|
||||||
else if (!strcmp(argv[i], "-o"))
|
else if (!strcmp(argv[i], "-o"))
|
||||||
{
|
{
|
||||||
if (++i == argc)
|
if (++i == argc)
|
||||||
{
|
{
|
||||||
fprintf(stderr, "No output file specified after -o option.\n");
|
fprintf(stderr, "No output file specified after -o option.\n");
|
||||||
usage(1);
|
lUsage(1);
|
||||||
}
|
}
|
||||||
fileOBJ = std::string(argv[i]);
|
fileOBJ = std::string(argv[i]);
|
||||||
}
|
}
|
||||||
else if (strncmp(argv[i], "-", 1))
|
else
|
||||||
{
|
{
|
||||||
const char * ext = strrchr(argv[i], '.');
|
const char * ext = strrchr(argv[i], '.');
|
||||||
if (ext == NULL)
|
if (ext == NULL)
|
||||||
{
|
{
|
||||||
fprintf(stderr, " Unknown argument: %s \n", argv[i]);
|
fprintf(stderr, " Unknown argument: %s \n", argv[i]);
|
||||||
exit(1);
|
lUsage(1);
|
||||||
}
|
}
|
||||||
else if (strncmp(ext, extString.c_str(), 4))
|
else if (strncmp(ext, extString.c_str(), 4))
|
||||||
{
|
{
|
||||||
fprintf(stderr, " Unkown extension of the input file: %s \n", ext);
|
fprintf(stderr, " Unkown extension of the input file: %s \n", ext);
|
||||||
exit(1);
|
lUsage(1);
|
||||||
}
|
}
|
||||||
else if (filePTX.empty())
|
else if (filePTX.empty())
|
||||||
{
|
{
|
||||||
@@ -110,8 +116,6 @@ int main(int _argc, char * _argv[])
|
|||||||
fileOBJ += ".o";
|
fileOBJ += ".o";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
|
||||||
nvccArgumentList.push_back(argv[i]);
|
|
||||||
}
|
}
|
||||||
#if 0
|
#if 0
|
||||||
fprintf(stderr, " fileOBJ= %s\n", fileOBJ.c_str());
|
fprintf(stderr, " fileOBJ= %s\n", fileOBJ.c_str());
|
||||||
@@ -172,8 +176,7 @@ int main(int _argc, char * _argv[])
|
|||||||
nvccCmd += "-dc ";
|
nvccCmd += "-dc ";
|
||||||
nvccCmd += std::string("-arch=") + arch + std::string(" ");
|
nvccCmd += std::string("-arch=") + arch + std::string(" ");
|
||||||
nvccCmd += "-dryrun ";
|
nvccCmd += "-dryrun ";
|
||||||
for (int i = 0; i < (int)nvccArgumentList.size(); i++)
|
nvccCmd += nvccArguments + std::string(" ");
|
||||||
nvccCmd += nvccArgumentList[i] + std::string(" ");
|
|
||||||
nvccCmd += std::string("-o ") + fileOBJ + std::string(" ");
|
nvccCmd += std::string("-o ") + fileOBJ + std::string(" ");
|
||||||
nvccCmd += fileCU + std::string(" ");
|
nvccCmd += fileCU + std::string(" ");
|
||||||
nvccCmd += std::string("2> ") + fileSH;
|
nvccCmd += std::string("2> ") + fileSH;
|
||||||
|
|||||||
@@ -74,16 +74,16 @@ ptxsource:
|
|||||||
header:
|
header:
|
||||||
version target address_size
|
version target address_size
|
||||||
{
|
{
|
||||||
std::cerr << "Done reading PTX \n" << std::endl;
|
// std::cerr << "Done reading PTX \n" << std::endl;
|
||||||
state.printHeader();
|
state.printHeader();
|
||||||
};
|
};
|
||||||
|
|
||||||
version:
|
version:
|
||||||
TOKEN_VERSION TOKEN_FLOAT { std::cerr << "Reading PTX version " << $2 << std::endl; };
|
TOKEN_VERSION TOKEN_FLOAT { assert($2 >= 3.0); } ;//std::cerr << "Reading PTX version " << $2 << std::endl; };
|
||||||
target:
|
target:
|
||||||
TOKEN_TARGET TOKEN_STRING { std::cerr << "Target " << $2 << std::endl; };
|
TOKEN_TARGET TOKEN_STRING { assert(std::string($2) == std::string("sm_35")); } //std::cerr << "Target " << $2 << std::endl; };
|
||||||
address_size:
|
address_size:
|
||||||
TOKEN_ADDRESS_SIZE TOKEN_INT { std::cerr << "Address_Size " << $2 << std::endl; };
|
TOKEN_ADDRESS_SIZE TOKEN_INT { assert($2 == 64); } //std::cerr << "Address_Size " << $2 << std::endl; };
|
||||||
|
|
||||||
|
|
||||||
dataTypeId :
|
dataTypeId :
|
||||||
@@ -208,8 +208,8 @@ void yyerror( YYLTYPE* location, parser::PTXLexer& lexer,
|
|||||||
std::stringstream stream;
|
std::stringstream stream;
|
||||||
stream << toString( *location, state )
|
stream << toString( *location, state )
|
||||||
<< " " << message;
|
<< " " << message;
|
||||||
fprintf(stderr, "--ERROR-- %s %s \n", toString(*location, state).c_str(), message);
|
fprintf(stderr, "--Parser ERROR-- %s %s \n", toString(*location, state).c_str(), message);
|
||||||
assert(0);
|
exit(-1);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user