diff options
Diffstat (limited to 'src')
| -rw-r--r-- | src/cuda-sim/Makefile | 8 | ||||
| -rw-r--r-- | src/cuda-sim/ptx.y | 23 | ||||
| -rw-r--r-- | src/cuda-sim/ptx_parser.cc | 26 | ||||
| -rw-r--r-- | src/cuda-sim/ptx_parser.h | 38 |
4 files changed, 53 insertions, 42 deletions
diff --git a/src/cuda-sim/Makefile b/src/cuda-sim/Makefile index 999dad7..85d1c8c 100644 --- a/src/cuda-sim/Makefile +++ b/src/cuda-sim/Makefile @@ -79,16 +79,16 @@ libgpgpu_ptx_sim.a: $(OBJS) ar rcs $(OUTPUT_DIR)/libgpgpu_ptx_sim.a $(OUTPUT_DIR)/ptx.tab.o $(OUTPUT_DIR)/lex.ptx_.o $(OUTPUT_DIR)/ptxinfo.tab.o $(OUTPUT_DIR)/lex.ptxinfo_.o $(OBJS) $(OUTPUT_DIR)/ptx.tab.o: $(OUTPUT_DIR)/ptx.tab.c - $(CPP) -c $(OPT) -DYYDEBUG $(OUTPUT_DIR)/ptx.tab.c -o $(OUTPUT_DIR)/ptx.tab.o + $(CPP) -c $(CXX_OPT) -DYYDEBUG $(OUTPUT_DIR)/ptx.tab.c -o $(OUTPUT_DIR)/ptx.tab.o $(OUTPUT_DIR)/lex.ptx_.o: $(OUTPUT_DIR)/lex.ptx_.c - $(CPP) -c $(OPT) $(OUTPUT_DIR)/lex.ptx_.c -o $(OUTPUT_DIR)/lex.ptx_.o + $(CPP) -c $(CXX_OPT) $(OUTPUT_DIR)/lex.ptx_.c -o $(OUTPUT_DIR)/lex.ptx_.o $(OUTPUT_DIR)/ptxinfo.tab.o: $(OUTPUT_DIR)/ptxinfo.tab.c - $(CPP) -c $(OPT) -DYYDEBUG $(OUTPUT_DIR)/ptxinfo.tab.c -o $(OUTPUT_DIR)/ptxinfo.tab.o + $(CPP) -c $(CXX_OPT) -DYYDEBUG $(OUTPUT_DIR)/ptxinfo.tab.c -o $(OUTPUT_DIR)/ptxinfo.tab.o $(OUTPUT_DIR)/lex.ptxinfo_.o: $(OUTPUT_DIR)/lex.ptxinfo_.c $(OUTPUT_DIR)/ptxinfo.tab.c - $(CPP) -c $(OPT) $(OUTPUT_DIR)/lex.ptxinfo_.c -o $(OUTPUT_DIR)/lex.ptxinfo_.o + $(CPP) -c $(CXX_OPT) $(OUTPUT_DIR)/lex.ptxinfo_.c -o $(OUTPUT_DIR)/lex.ptxinfo_.o $(OUTPUT_DIR)/ptx.tab.c: ptx.y bison --name-prefix=ptx_ -v -d ptx.y --file-prefix=$(OUTPUT_DIR)/ptx diff --git a/src/cuda-sim/ptx.y b/src/cuda-sim/ptx.y index 8447693..837fbe9 100644 --- a/src/cuda-sim/ptx.y +++ b/src/cuda-sim/ptx.y @@ -229,7 +229,6 @@ class ptx_recognizer; #include <string.h> #include <math.h> void syntax_not_implemented(yyscan_t yyscanner, ptx_recognizer* recognizer); - extern int g_func_decl; int ptx_lex(YYSTYPE * yylval_param, yyscan_t yyscanner, ptx_recognizer* recognizer); int ptx_error( yyscan_t yyscanner, ptx_recognizer* recognizer, const char *s ); %} @@ -260,21 +259,21 @@ block_spec_list: block_spec function_decl: function_decl_header LEFT_PAREN { recognizer->start_function($1); recognizer->func_header_info("(");} param_entry RIGHT_PAREN {recognizer->func_header_info(")");} function_ident_param { $$ = recognizer->reset_symtab(); } | function_decl_header { recognizer->start_function($1); } function_ident_param { $$ = recognizer->reset_symtab(); } - | function_decl_header { recognizer->start_function($1); recognizer->add_function_name(""); g_func_decl=0; $$ = recognizer->reset_symtab(); } + | function_decl_header { recognizer->start_function($1); recognizer->add_function_name(""); recognizer->g_func_decl=0; $$ = recognizer->reset_symtab(); } ; -function_ident_param: IDENTIFIER { recognizer->add_function_name($1); } LEFT_PAREN {recognizer->func_header_info("(");} param_list RIGHT_PAREN { g_func_decl=0; recognizer->func_header_info(")"); } - | IDENTIFIER { recognizer->add_function_name($1); g_func_decl=0; } +function_ident_param: IDENTIFIER { recognizer->add_function_name($1); } LEFT_PAREN {recognizer->func_header_info("(");} param_list RIGHT_PAREN { recognizer->g_func_decl=0; recognizer->func_header_info(")"); } + | IDENTIFIER { recognizer->add_function_name($1); recognizer->g_func_decl=0; } ; -function_decl_header: ENTRY_DIRECTIVE { $$ = 1; g_func_decl=1; recognizer->func_header(".entry"); } - | VISIBLE_DIRECTIVE ENTRY_DIRECTIVE { $$ = 1; g_func_decl=1; recognizer->func_header(".entry"); } - | WEAK_DIRECTIVE ENTRY_DIRECTIVE { $$ = 1; g_func_decl=1; recognizer->func_header(".entry"); } - | FUNC_DIRECTIVE { $$ = 0; g_func_decl=1; recognizer->func_header(".func"); } - | VISIBLE_DIRECTIVE FUNC_DIRECTIVE { $$ = 0; g_func_decl=1; recognizer->func_header(".func"); } - | WEAK_DIRECTIVE FUNC_DIRECTIVE { $$ = 0; g_func_decl=1; recognizer->func_header(".func"); } - | EXTERN_DIRECTIVE FUNC_DIRECTIVE { $$ = 2; g_func_decl=1; recognizer->func_header(".func"); } - | WEAK_DIRECTIVE FUNC_DIRECTIVE { $$ = 0; g_func_decl=1; recognizer->func_header(".func"); } +function_decl_header: ENTRY_DIRECTIVE { $$ = 1; recognizer->g_func_decl=1; recognizer->func_header(".entry"); } + | VISIBLE_DIRECTIVE ENTRY_DIRECTIVE { $$ = 1; recognizer->g_func_decl=1; recognizer->func_header(".entry"); } + | WEAK_DIRECTIVE ENTRY_DIRECTIVE { $$ = 1; recognizer->g_func_decl=1; recognizer->func_header(".entry"); } + | FUNC_DIRECTIVE { $$ = 0; recognizer->g_func_decl=1; recognizer->func_header(".func"); } + | VISIBLE_DIRECTIVE FUNC_DIRECTIVE { $$ = 0; recognizer->g_func_decl=1; recognizer->func_header(".func"); } + | WEAK_DIRECTIVE FUNC_DIRECTIVE { $$ = 0; recognizer->g_func_decl=1; recognizer->func_header(".func"); } + | EXTERN_DIRECTIVE FUNC_DIRECTIVE { $$ = 2; recognizer->g_func_decl=1; recognizer->func_header(".func"); } + | WEAK_DIRECTIVE FUNC_DIRECTIVE { $$ = 0; recognizer->g_func_decl=1; recognizer->func_header(".func"); } ; param_list: /*empty*/ diff --git a/src/cuda-sim/ptx_parser.cc b/src/cuda-sim/ptx_parser.cc index a61dc16..897beaf 100644 --- a/src/cuda-sim/ptx_parser.cc +++ b/src/cuda-sim/ptx_parser.cc @@ -49,7 +49,6 @@ void set_ptx_warp_size(const struct core_config * warp_size) static bool g_debug_ir_generation=false; const char *g_filename; -unsigned g_max_regs_per_thread = 0; // the program intermediate representation... static symbol_table *g_global_allfiles_symbol_table = NULL; @@ -61,27 +60,6 @@ static symbol *g_last_symbol = NULL; int g_error_detected = 0; -// type specifier stuff: -memory_space_t g_space_spec = undefined_space; -memory_space_t g_ptr_spec = undefined_space; -int g_scalar_type_spec = -1; -int g_vector_spec = -1; -int g_alignment_spec = -1; -int g_extern_spec = 0; - -// variable declaration stuff: -type_info *g_var_type = NULL; - -// instruction definition stuff: -const symbol *g_pred; -int g_neg_pred; -int g_pred_mod; -symbol *g_label; -int g_opcode = -1; -std::list<operand_info> g_operands; -std::list<int> g_options; -std::list<int> g_wmma_options; -std::list<int> g_scalar_type; #define PTX_PARSE_DPRINTF(...) \ if( g_debug_ir_generation ) { \ @@ -362,10 +340,6 @@ bool check_for_duplicates( const char *identifier ) extern std::set<std::string> g_globals; extern std::set<std::string> g_constants; -int g_func_decl = 0; -int g_ident_add_uid = 0; -unsigned g_const_alloc = 1; - // Returns padding that needs to be inserted ahead of address to make it aligned to min(size, maxalign) /* * @param address the address in bytes diff --git a/src/cuda-sim/ptx_parser.h b/src/cuda-sim/ptx_parser.h index fb1b7f2..c52fe20 100644 --- a/src/cuda-sim/ptx_parser.h +++ b/src/cuda-sim/ptx_parser.h @@ -29,6 +29,7 @@ #define ptx_parser_INCLUDED #include "../abstract_hardware_model.h" +#include "ptx_ir.h" extern const char *g_filename; extern int g_error_detected; @@ -44,7 +45,20 @@ class ptx_recognizer { scanner = NULL; g_size = -1; g_add_identifier_cached__identifier = NULL; + g_alignment_spec = -1; + g_var_type = NULL; + g_opcode = -1; + g_space_spec = undefined_space; + g_ptr_spec = undefined_space; + g_scalar_type_spec = -1; + g_vector_spec = -1; + g_extern_spec = 0; + g_func_decl = 0; + g_ident_add_uid = 0; + g_const_alloc = 1; + g_max_regs_per_thread = 0; } + // global list yyscan_t scanner; #define LINEBUF_SIZE (4*1024) char linebuf[LINEBUF_SIZE]; @@ -53,7 +67,31 @@ class ptx_recognizer { char *g_add_identifier_cached__identifier; int g_add_identifier_cached__array_dim; int g_add_identifier_cached__array_ident; + int g_alignment_spec; + // variable declaration stuff: + type_info *g_var_type; + // instruction definition stuff: + const symbol *g_pred; + int g_neg_pred; + int g_pred_mod; + symbol *g_label; + int g_opcode; + std::list<operand_info> g_operands; + std::list<int> g_options; + std::list<int> g_wmma_options; + std::list<int> g_scalar_type; + // type specifier stuff: + memory_space_t g_space_spec; + memory_space_t g_ptr_spec; + int g_scalar_type_spec; + int g_vector_spec; + int g_extern_spec; + int g_func_decl; + int g_ident_add_uid; + unsigned g_const_alloc; + unsigned g_max_regs_per_thread; + // member function list void init_directive_state(); void init_instruction_state(); void start_function( int entry_point ); |
