diff options
| author | Mengchi Zhang <[email protected]> | 2019-07-03 14:54:16 -0400 |
|---|---|---|
| committer | Mengchi Zhang <[email protected]> | 2019-07-03 14:54:16 -0400 |
| commit | 60c38b0f77378eb111e88f632702d19dc3746cc7 (patch) | |
| tree | 36ce48f9e23cd20797b765c04b4161b08edf8398 /src/cuda-sim | |
| parent | cb60ae4893086175fee49dc6088d46665a7f088b (diff) | |
Remove g_filename
Signed-off-by: Mengchi Zhang <[email protected]>
Diffstat (limited to 'src/cuda-sim')
| -rw-r--r-- | src/cuda-sim/ptx.l | 5 | ||||
| -rw-r--r-- | src/cuda-sim/ptx.y | 5 | ||||
| -rw-r--r-- | src/cuda-sim/ptx_loader.h | 5 | ||||
| -rw-r--r-- | src/cuda-sim/ptx_parser.cc | 26 | ||||
| -rw-r--r-- | src/cuda-sim/ptx_parser.h | 7 | ||||
| -rw-r--r-- | src/cuda-sim/ptxinfo.l | 4 |
6 files changed, 28 insertions, 24 deletions
diff --git a/src/cuda-sim/ptx.l b/src/cuda-sim/ptx.l index 18952a9..3a2a839 100644 --- a/src/cuda-sim/ptx.l +++ b/src/cuda-sim/ptx.l @@ -40,6 +40,7 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #include "ptx_parser.h" #include "ptx.tab.h" #include <string.h> +#include "../../libcuda/gpgpu_context.h" #define LINEBUF_SIZE (4*1024) #define TC recognizer->col+=strlen(yytext); @@ -452,8 +453,6 @@ breakaddr TC; yylval->int_value = BREAKADDR_OP; return OPCODE; <INITIAL,NOT_OPCODE,IN_FUNC_DECL>. TC; ptx_error(yyscanner, recognizer, (const char*)NULL); %% -extern const char *g_filename; - int ptx_error( yyscan_t yyscanner, ptx_recognizer* recognizer, const char *s ) { struct yyguts_t * yyg = (struct yyguts_t*)yyscanner; @@ -461,7 +460,7 @@ int ptx_error( yyscan_t yyscanner, ptx_recognizer* recognizer, const char *s ) recognizer->g_error_detected = 1; fflush(stdout); if( s != NULL ) - printf("%s:%u Syntax error:\n\n", g_filename, yylineno ); + printf("%s:%u Syntax error:\n\n", recognizer->gpgpu_ctx->g_filename, yylineno ); printf(" %s\n", recognizer->linebuf ); printf(" "); for( i=0; i < recognizer->col-1; i++ ) { diff --git a/src/cuda-sim/ptx.y b/src/cuda-sim/ptx.y index 837fbe9..a01c3c6 100644 --- a/src/cuda-sim/ptx.y +++ b/src/cuda-sim/ptx.y @@ -30,6 +30,7 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. %{ typedef void * yyscan_t; class ptx_recognizer; +#include "../../libcuda/gpgpu_context.h" %} %define api.pure full @@ -628,11 +629,9 @@ address_expression: IDENTIFIER { recognizer->add_address_operand($1,0); } %% -extern const char *g_filename; - void syntax_not_implemented(yyscan_t yyscanner, ptx_recognizer* recognizer) { - printf("Parse error (%s): this syntax is not (yet) implemented:\n",g_filename); + printf("Parse error (%s): this syntax is not (yet) implemented:\n", recognizer->gpgpu_ctx->g_filename); ptx_error(yyscanner, recognizer, NULL); abort(); } diff --git a/src/cuda-sim/ptx_loader.h b/src/cuda-sim/ptx_loader.h index 77f27c8..c214b95 100644 --- a/src/cuda-sim/ptx_loader.h +++ b/src/cuda-sim/ptx_loader.h @@ -30,13 +30,18 @@ #include <string> #define PTXINFO_LINEBUF_SIZE 1024 +class gpgpu_context; typedef void * yyscan_t; class ptxinfo_data{ public: + ptxinfo_data(gpgpu_context* ctx) { + gpgpu_ctx = ctx; + } yyscan_t scanner; char linebuf[PTXINFO_LINEBUF_SIZE]; unsigned col; const char *g_ptxinfo_filename; + class gpgpu_context* gpgpu_ctx; void ptxinfo_addinfo(); }; diff --git a/src/cuda-sim/ptx_parser.cc b/src/cuda-sim/ptx_parser.cc index 09bc15d..05fc618 100644 --- a/src/cuda-sim/ptx_parser.cc +++ b/src/cuda-sim/ptx_parser.cc @@ -47,14 +47,12 @@ void ptx_recognizer::set_ptx_warp_size(const struct core_config * warp_size) g_shader_core_config=warp_size; } -const char *g_filename; - // the program intermediate representation... std::map<std::string,symbol_table*> g_sym_name_to_symbol_table; #define PTX_PARSE_DPRINTF(...) \ if( g_debug_ir_generation ) { \ - printf(" %s:%u => ",g_filename,ptx_get_lineno(scanner)); \ + printf(" %s:%u => ",gpgpu_ctx->g_filename,ptx_get_lineno(scanner)); \ printf(" (%s:%u) ", __FILE__, __LINE__); \ printf(__VA_ARGS__); \ printf("\n"); \ @@ -70,7 +68,7 @@ const char *decode_token( int type ) void ptx_recognizer::read_parser_environment_variables() { - g_filename = getenv("PTX_SIM_KERNELFILE"); + gpgpu_ctx->g_filename = getenv("PTX_SIM_KERNELFILE"); char *dbg_level = getenv("PTX_SIM_DEBUG"); if ( dbg_level && strlen(dbg_level) ) { int debug_execution=0; @@ -180,7 +178,7 @@ void ptx_recognizer::add_function_name( const char *name ) if( prior_decl ) { g_func_info->remove_args(); } - g_global_symbol_table->add_function( g_func_info, g_filename, ptx_get_lineno(scanner) ); + g_global_symbol_table->add_function( g_func_info, gpgpu_ctx->g_filename, ptx_get_lineno(scanner) ); } //Jin: handle instruction group for cdp @@ -229,7 +227,7 @@ void ptx_recognizer::parse_error_impl( const char *file, unsigned line, const ch va_end(ap); g_error_detected = 1; - printf("%s:%u: Parse error: %s (%s:%u)\n\n", g_filename, ptx_get_lineno(scanner), buf, file, line); + printf("%s:%u: Parse error: %s (%s:%u)\n\n", gpgpu_ctx->g_filename, ptx_get_lineno(scanner), buf, file, line); ptx_error(scanner, NULL); abort(); exit(1); @@ -284,12 +282,12 @@ void ptx_recognizer::add_instruction() g_wmma_options, g_scalar_type, g_space_spec, - g_filename, + gpgpu_ctx->g_filename, ptx_get_lineno(scanner), linebuf, g_shader_core_config ); g_instructions.push_back(i); - g_inst_lookup[g_filename][ptx_get_lineno(scanner)] = i; + g_inst_lookup[gpgpu_ctx->g_filename][ptx_get_lineno(scanner)] = i; init_instruction_state(); } @@ -391,7 +389,7 @@ void ptx_recognizer::add_identifier( const char *identifier, int array_dim, unsi default: break; } - g_last_symbol = g_current_symbol_table->add_variable(identifier,type,num_bits/8,g_filename,ptx_get_lineno(scanner)); + g_last_symbol = g_current_symbol_table->add_variable(identifier,type,num_bits/8,gpgpu_ctx->g_filename,ptx_get_lineno(scanner)); switch ( ti.get_memory_space().get_type() ) { case reg_space: { regnum = g_current_symbol_table->next_reg_num(); @@ -654,7 +652,7 @@ void ptx_recognizer::add_label( const char *identifier ) if ( s != NULL ) { g_label = s; } else { - g_label = g_current_symbol_table->add_variable(identifier,NULL,0,g_filename,ptx_get_lineno(scanner)); + g_label = g_current_symbol_table->add_variable(identifier,NULL,0,gpgpu_ctx->g_filename,ptx_get_lineno(scanner)); } } @@ -912,7 +910,7 @@ void ptx_recognizer::add_scalar_operand( const char *identifier ) if ( s == NULL ) { if ( g_opcode == BRA_OP || g_opcode == CALLP_OP) { // forward branch target... - s = g_current_symbol_table->add_variable(identifier,NULL,0,g_filename,ptx_get_lineno(scanner)); + s = g_current_symbol_table->add_variable(identifier,NULL,0,gpgpu_ctx->g_filename,ptx_get_lineno(scanner)); } else { std::string msg = std::string("operand \"") + identifier + "\" has no declaration."; parse_error( msg.c_str() ); @@ -926,7 +924,7 @@ void ptx_recognizer::add_neg_pred_operand( const char *identifier ) PTX_PARSE_DPRINTF("add_neg_pred_operand"); const symbol *s = g_current_symbol_table->lookup(identifier); if ( s == NULL ) { - s = g_current_symbol_table->add_variable(identifier,NULL,1,g_filename,ptx_get_lineno(scanner)); + s = g_current_symbol_table->add_variable(identifier,NULL,1,gpgpu_ctx->g_filename,ptx_get_lineno(scanner)); } operand_info op(s); op.set_neg_pred(); @@ -962,7 +960,7 @@ void ptx_recognizer::add_version_info( float ver, unsigned ext ) void ptx_recognizer::add_file( unsigned num, const char *filename ) { - if( g_filename == NULL ) { + if( gpgpu_ctx->g_filename == NULL ) { char *b = strdup(filename); char *l=b; char *n=b; @@ -978,7 +976,7 @@ void ptx_recognizer::add_file( unsigned num, const char *filename ) char *q = strtok(NULL,"."); if( q && !strcmp(q,"cu") ) { - g_filename = strdup(buf); + gpgpu_ctx->g_filename = strdup(buf); } free( b ); diff --git a/src/cuda-sim/ptx_parser.h b/src/cuda-sim/ptx_parser.h index ec300a1..e09aab1 100644 --- a/src/cuda-sim/ptx_parser.h +++ b/src/cuda-sim/ptx_parser.h @@ -30,17 +30,17 @@ #include "../abstract_hardware_model.h" #include "ptx_ir.h" -extern const char *g_filename; extern int g_error_detected; #ifdef __cplusplus const class ptx_instruction *ptx_instruction_lookup( const char *filename, unsigned linenumber ); #endif +class gpgpu_context; typedef void * yyscan_t; class ptx_recognizer { public: - ptx_recognizer() { + ptx_recognizer( gpgpu_context* ctx ) { scanner = NULL; g_size = -1; g_add_identifier_cached__identifier = NULL; @@ -63,6 +63,7 @@ class ptx_recognizer { g_entry_func_param_index=0; g_func_info = NULL; g_debug_ir_generation=false; + gpgpu_ctx = ctx; } // global list yyscan_t scanner; @@ -107,6 +108,8 @@ class ptx_recognizer { bool g_debug_ir_generation; int g_entry_point; const struct core_config *g_shader_core_config; + // backward pointer + class gpgpu_context* gpgpu_ctx; // member function list void init_directive_state(); diff --git a/src/cuda-sim/ptxinfo.l b/src/cuda-sim/ptxinfo.l index b0ada09..3a152b0 100644 --- a/src/cuda-sim/ptxinfo.l +++ b/src/cuda-sim/ptxinfo.l @@ -39,6 +39,7 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #include "ptx_loader.h" #include "ptxinfo.tab.h" #include <string.h> +#include "../../libcuda/gpgpu_context.h" #define LINEBUF_SIZE 1024 #define TC if( (yylineno == 1) && (ptxinfo->col + strlen(yytext) < LINEBUF_SIZE) ) { \ @@ -88,7 +89,6 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. %% extern int g_ptxinfo_error_detected; -extern const char *g_filename; int ptxinfo_error(yyscan_t yyscanner, ptxinfo_data* ptxinfo, const char* msg) { @@ -98,7 +98,7 @@ int ptxinfo_error(yyscan_t yyscanner, ptxinfo_data* ptxinfo, const char* msg) fflush(stdout); printf("GPGPU-Sim: ERROR while parsing output of ptxas (used to capture resource usage information)\n"); if( msg != NULL ) - printf("GPGPU-Sim: %s (%s:%u) Syntax error:\n\n", g_filename, ptxinfo->g_ptxinfo_filename, yylineno ); + printf("GPGPU-Sim: %s (%s:%u) Syntax error:\n\n", ptxinfo->gpgpu_ctx->g_filename, ptxinfo->g_ptxinfo_filename, yylineno ); printf(" %s\n", ptxinfo->linebuf ); printf(" "); for( i=0; i < ptxinfo->col-1; i++ ) { |
