From c146d3707216f235a1dde3bd978239fd55b111ed Mon Sep 17 00:00:00 2001 From: Mengchi Zhang Date: Wed, 12 Jun 2019 18:17:45 -0400 Subject: Move all ptx_parser inside gpgpu_context Signed-off-by: Mengchi Zhang --- src/cuda-sim/ptx_parser.h | 1 - 1 file changed, 1 deletion(-) (limited to 'src/cuda-sim/ptx_parser.h') diff --git a/src/cuda-sim/ptx_parser.h b/src/cuda-sim/ptx_parser.h index c52fe20..5293c2e 100644 --- a/src/cuda-sim/ptx_parser.h +++ b/src/cuda-sim/ptx_parser.h @@ -34,7 +34,6 @@ extern const char *g_filename; extern int g_error_detected; #ifdef __cplusplus -class symbol_table* init_parser(const char*); const class ptx_instruction *ptx_instruction_lookup( const char *filename, unsigned linenumber ); #endif -- cgit v1.3 From 5530b51c7c572d25717ad7f5d81196011dfcb540 Mon Sep 17 00:00:00 2001 From: Mengchi Zhang Date: Wed, 12 Jun 2019 18:49:58 -0400 Subject: Move symbol table globals Signed-off-by: Mengchi Zhang --- libcuda/gpgpu_context.h | 2 ++ src/cuda-sim/ptx_parser.cc | 10 +++------- src/cuda-sim/ptx_parser.h | 7 +++++++ 3 files changed, 12 insertions(+), 7 deletions(-) (limited to 'src/cuda-sim/ptx_parser.h') diff --git a/libcuda/gpgpu_context.h b/libcuda/gpgpu_context.h index b586e47..fa5d02b 100644 --- a/libcuda/gpgpu_context.h +++ b/libcuda/gpgpu_context.h @@ -7,11 +7,13 @@ class gpgpu_context { public: gpgpu_context() { + g_global_allfiles_symbol_table = NULL; api = new cuda_runtime_api(); ptxinfo = new ptxinfo_data(); ptx_parser = new ptx_recognizer(); } // global list + symbol_table *g_global_allfiles_symbol_table; // objects pointers for each file cuda_runtime_api* api; ptxinfo_data* ptxinfo; diff --git a/src/cuda-sim/ptx_parser.cc b/src/cuda-sim/ptx_parser.cc index 7080ee9..32e12a1 100644 --- a/src/cuda-sim/ptx_parser.cc +++ b/src/cuda-sim/ptx_parser.cc @@ -52,12 +52,8 @@ static bool g_debug_ir_generation=false; const char *g_filename; // the program intermediate representation... -static symbol_table *g_global_allfiles_symbol_table = NULL; -static symbol_table *g_global_symbol_table = NULL; std::map g_sym_name_to_symbol_table; -static symbol_table *g_current_symbol_table = NULL; static std::list g_instructions; -static symbol *g_last_symbol = NULL; int g_error_detected = 0; @@ -128,7 +124,7 @@ symbol_table * gpgpu_context::init_parser( const char *ptx_filename ) g_filename = strdup(ptx_filename); if (g_global_allfiles_symbol_table == NULL) { g_global_allfiles_symbol_table = new symbol_table("global_allfiles", 0, NULL); - g_global_symbol_table = g_current_symbol_table = g_global_allfiles_symbol_table; + ptx_parser->g_global_symbol_table = ptx_parser->g_current_symbol_table = g_global_allfiles_symbol_table; } /*else { g_global_symbol_table = g_current_symbol_table = new symbol_table("global",0,g_global_allfiles_symbol_table); @@ -163,7 +159,7 @@ symbol_table * gpgpu_context::init_parser( const char *ptx_filename ) ptx_in = ptx_get_in(ptx_parser->scanner); ptx_lex_destroy(ptx_parser->scanner); fclose(ptx_in); - return g_global_symbol_table; + return ptx_parser->g_global_symbol_table; } static int g_entry_point; @@ -331,7 +327,7 @@ void ptx_recognizer::set_variable_type() g_extern_spec ); } -bool check_for_duplicates( const char *identifier ) +bool ptx_recognizer::check_for_duplicates( const char *identifier ) { const symbol *s = g_current_symbol_table->lookup(identifier); return ( s != NULL ); diff --git a/src/cuda-sim/ptx_parser.h b/src/cuda-sim/ptx_parser.h index 5293c2e..cc8fe18 100644 --- a/src/cuda-sim/ptx_parser.h +++ b/src/cuda-sim/ptx_parser.h @@ -56,6 +56,9 @@ class ptx_recognizer { g_ident_add_uid = 0; g_const_alloc = 1; g_max_regs_per_thread = 0; + g_global_symbol_table = NULL; + g_current_symbol_table = NULL; + symbol *g_last_symbol = NULL; } // global list yyscan_t scanner; @@ -89,6 +92,9 @@ class ptx_recognizer { int g_ident_add_uid; unsigned g_const_alloc; unsigned g_max_regs_per_thread; + symbol_table *g_global_symbol_table; + symbol_table *g_current_symbol_table; + symbol *g_last_symbol; // member function list void init_directive_state(); @@ -154,6 +160,7 @@ class ptx_recognizer { //Jin: handle instructino group for cdp void start_inst_group(); void end_inst_group(); + bool check_for_duplicates( const char *identifier ); }; -- cgit v1.3 From e5447646aaca133f2cc5cbafcaf7aeef4b384c62 Mon Sep 17 00:00:00 2001 From: Mengchi Zhang Date: Wed, 12 Jun 2019 19:13:55 -0400 Subject: Add some vars in ptx_parser Signed-off-by: Mengchi Zhang --- src/cuda-sim/ptx.l | 3 +-- src/cuda-sim/ptx_parser.cc | 5 ----- src/cuda-sim/ptx_parser.h | 5 +++++ 3 files changed, 6 insertions(+), 7 deletions(-) (limited to 'src/cuda-sim/ptx_parser.h') diff --git a/src/cuda-sim/ptx.l b/src/cuda-sim/ptx.l index 2546a99..18952a9 100644 --- a/src/cuda-sim/ptx.l +++ b/src/cuda-sim/ptx.l @@ -452,14 +452,13 @@ breakaddr TC; yylval->int_value = BREAKADDR_OP; return OPCODE; . TC; ptx_error(yyscanner, recognizer, (const char*)NULL); %% -extern int g_error_detected; 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; int i; - g_error_detected = 1; + recognizer->g_error_detected = 1; fflush(stdout); if( s != NULL ) printf("%s:%u Syntax error:\n\n", g_filename, yylineno ); diff --git a/src/cuda-sim/ptx_parser.cc b/src/cuda-sim/ptx_parser.cc index 32e12a1..a01d1e3 100644 --- a/src/cuda-sim/ptx_parser.cc +++ b/src/cuda-sim/ptx_parser.cc @@ -53,10 +53,6 @@ const char *g_filename; // the program intermediate representation... std::map g_sym_name_to_symbol_table; -static std::list g_instructions; - -int g_error_detected = 0; - #define PTX_PARSE_DPRINTF(...) \ if( g_debug_ir_generation ) { \ @@ -67,7 +63,6 @@ int g_error_detected = 0; fflush(stdout); \ } -static unsigned g_entry_func_param_index=0; static function_info *g_func_info = NULL; static std::map g_ptx_token_decode; static operand_info g_return_var; diff --git a/src/cuda-sim/ptx_parser.h b/src/cuda-sim/ptx_parser.h index cc8fe18..c4e0b89 100644 --- a/src/cuda-sim/ptx_parser.h +++ b/src/cuda-sim/ptx_parser.h @@ -59,6 +59,8 @@ class ptx_recognizer { g_global_symbol_table = NULL; g_current_symbol_table = NULL; symbol *g_last_symbol = NULL; + g_error_detected = 0; + g_entry_func_param_index=0; } // global list yyscan_t scanner; @@ -95,6 +97,9 @@ class ptx_recognizer { symbol_table *g_global_symbol_table; symbol_table *g_current_symbol_table; symbol *g_last_symbol; + std::list g_instructions; + int g_error_detected; + unsigned g_entry_func_param_index; // member function list void init_directive_state(); -- cgit v1.3 From 632bdaab79b9c1fd51ef8152aa00209f76c03101 Mon Sep 17 00:00:00 2001 From: Mengchi Zhang Date: Wed, 12 Jun 2019 19:55:35 -0400 Subject: Fix some compiler warning Signed-off-by: Mengchi Zhang --- src/cuda-sim/ptx_loader.h | 4 ++-- src/cuda-sim/ptx_parser.cc | 2 -- src/cuda-sim/ptx_parser.h | 9 ++++++--- 3 files changed, 8 insertions(+), 7 deletions(-) (limited to 'src/cuda-sim/ptx_parser.h') diff --git a/src/cuda-sim/ptx_loader.h b/src/cuda-sim/ptx_loader.h index 3637bff..ee09e16 100644 --- a/src/cuda-sim/ptx_loader.h +++ b/src/cuda-sim/ptx_loader.h @@ -29,12 +29,12 @@ #define PTX_LOADER_H_INCLUDED #include -#define LINEBUF_SIZE 1024 +#define PTXINFO_LINEBUF_SIZE 1024 typedef void * yyscan_t; class ptxinfo_data{ public: yyscan_t scanner; - char linebuf[LINEBUF_SIZE]; + char linebuf[PTXINFO_LINEBUF_SIZE]; unsigned col; const char *g_ptxinfo_filename; diff --git a/src/cuda-sim/ptx_parser.cc b/src/cuda-sim/ptx_parser.cc index a01d1e3..2872b84 100644 --- a/src/cuda-sim/ptx_parser.cc +++ b/src/cuda-sim/ptx_parser.cc @@ -63,9 +63,7 @@ std::map g_sym_name_to_symbol_table; fflush(stdout); \ } -static function_info *g_func_info = NULL; static std::map g_ptx_token_decode; -static operand_info g_return_var; const char *decode_token( int type ) { diff --git a/src/cuda-sim/ptx_parser.h b/src/cuda-sim/ptx_parser.h index c4e0b89..25c01fe 100644 --- a/src/cuda-sim/ptx_parser.h +++ b/src/cuda-sim/ptx_parser.h @@ -58,14 +58,15 @@ class ptx_recognizer { g_max_regs_per_thread = 0; g_global_symbol_table = NULL; g_current_symbol_table = NULL; - symbol *g_last_symbol = NULL; + g_last_symbol = NULL; g_error_detected = 0; g_entry_func_param_index=0; + g_func_info = NULL; } // global list yyscan_t scanner; -#define LINEBUF_SIZE (4*1024) - char linebuf[LINEBUF_SIZE]; +#define PTX_LINEBUF_SIZE (4*1024) + char linebuf[PTX_LINEBUF_SIZE]; unsigned col; int g_size; char *g_add_identifier_cached__identifier; @@ -100,6 +101,8 @@ class ptx_recognizer { std::list g_instructions; int g_error_detected; unsigned g_entry_func_param_index; + function_info *g_func_info; + operand_info g_return_var; // member function list void init_directive_state(); -- cgit v1.3