From b26dda933fe84d54cad47762ae80be3acdfda91b Mon Sep 17 00:00:00 2001 From: Tor Aamodt Date: Sun, 8 Aug 2010 14:28:20 -0800 Subject: refactoring: moving PTX parsing functions into ptx_parser.* [git-p4: depot-paths = "//depot/gpgpu_sim_research/fermi/distribution/": change = 7167] --- src/cuda-sim/Makefile | 156 ++++++++- src/cuda-sim/cuda-sim.cc | 11 +- src/cuda-sim/cuda-sim.h | 4 +- src/cuda-sim/instructions.cc | 1 - src/cuda-sim/ptx.y | 2 +- src/cuda-sim/ptx_ir.cc | 675 +-------------------------------------- src/cuda-sim/ptx_ir.h | 78 +---- src/cuda-sim/ptx_loader.cc | 29 +- src/cuda-sim/ptx_parser.cc | 742 +++++++++++++++++++++++++++++++++++++++++++ src/cuda-sim/ptx_parser.h | 122 +++++++ src/gpgpu-sim/shader.cc | 1 - src/gpgpusim_entrypoint.cc | 2 + 12 files changed, 1055 insertions(+), 768 deletions(-) create mode 100644 src/cuda-sim/ptx_parser.cc create mode 100644 src/cuda-sim/ptx_parser.h diff --git a/src/cuda-sim/Makefile b/src/cuda-sim/Makefile index 6140048..597f7c4 100644 --- a/src/cuda-sim/Makefile +++ b/src/cuda-sim/Makefile @@ -91,7 +91,7 @@ ifeq ($(GNUC_CPP0X),1) endif endif -OBJS := ptx_loader.o cuda_device_printf.o instructions.o cuda-sim.o ptx_ir.o ptx_sim.o memory.o ptx-stats.o ptx.tab.o lex.ptx_.o ptxinfo.tab.o lex.ptxinfo_.o +OBJS := ptx_parser.o ptx_loader.o cuda_device_printf.o instructions.o cuda-sim.o ptx_ir.o ptx_sim.o memory.o ptx-stats.o ptx.tab.o lex.ptx_.o ptxinfo.tab.o lex.ptxinfo_.o CUDART_VERSION:=$(shell nvcc --version | awk '/release/ {print $$5;}' | sed 's/,//' | sed 's/\./ /' | awk '{printf("%02u%02u", 10*int($$1), 10*$$2);}') @@ -166,7 +166,159 @@ depend: instructions.o: instructions.h ptx.tab.c cuda_device_printf.o: ptx.tab.c ptx_ir.o: ptx.tab.c ptx_parser_decode.def -ptx_loader.o: ptx.tab.c +ptx_loader.o: ptx.tab.c ptx_parser_decode.def +ptx_parser.o: ptx.tab.c ptx_parser_decode.def # DO NOT DELETE +cuda_device_printf.o: ptx_ir.h ../abstract_hardware_model.h +cuda_device_printf.o: /usr/include/assert.h /usr/include/features.h +cuda_device_printf.o: /usr/include/sys/cdefs.h /usr/include/bits/wordsize.h +cuda_device_printf.o: /usr/include/gnu/stubs.h /usr/include/gnu/stubs-64.h +cuda_device_printf.o: ptx_sim.h /usr/include/stdlib.h +cuda_device_printf.o: /usr/include/sys/types.h /usr/include/bits/types.h +cuda_device_printf.o: /usr/include/bits/typesizes.h /usr/include/time.h +cuda_device_printf.o: /usr/include/endian.h /usr/include/bits/endian.h +cuda_device_printf.o: /usr/include/bits/byteswap.h /usr/include/sys/select.h +cuda_device_printf.o: /usr/include/bits/select.h /usr/include/bits/sigset.h +cuda_device_printf.o: /usr/include/bits/time.h /usr/include/sys/sysmacros.h +cuda_device_printf.o: /usr/include/bits/pthreadtypes.h /usr/include/alloca.h +cuda_device_printf.o: dram_callback.h opcodes.h opcodes.def memory.h +cuda_device_printf.o: /usr/include/string.h /usr/include/stdio.h +cuda_device_printf.o: /usr/include/libio.h /usr/include/_G_config.h +cuda_device_printf.o: /usr/include/wchar.h /usr/include/bits/stdio_lim.h +cuda_device_printf.o: /usr/include/bits/sys_errlist.h ../option_parser.h +cuda-sim.o: cuda-sim.h ../abstract_hardware_model.h /usr/include/stdlib.h +cuda-sim.o: /usr/include/features.h /usr/include/sys/cdefs.h +cuda-sim.o: /usr/include/bits/wordsize.h /usr/include/gnu/stubs.h +cuda-sim.o: /usr/include/gnu/stubs-64.h /usr/include/sys/types.h +cuda-sim.o: /usr/include/bits/types.h /usr/include/bits/typesizes.h +cuda-sim.o: /usr/include/time.h /usr/include/endian.h +cuda-sim.o: /usr/include/bits/endian.h /usr/include/bits/byteswap.h +cuda-sim.o: /usr/include/sys/select.h /usr/include/bits/select.h +cuda-sim.o: /usr/include/bits/sigset.h /usr/include/bits/time.h +cuda-sim.o: /usr/include/sys/sysmacros.h /usr/include/bits/pthreadtypes.h +cuda-sim.o: /usr/include/alloca.h ptx_ir.h /usr/include/assert.h ptx_sim.h +cuda-sim.o: dram_callback.h opcodes.h opcodes.def memory.h +cuda-sim.o: /usr/include/string.h /usr/include/stdio.h /usr/include/libio.h +cuda-sim.o: /usr/include/_G_config.h /usr/include/wchar.h +cuda-sim.o: /usr/include/bits/stdio_lim.h /usr/include/bits/sys_errlist.h +cuda-sim.o: ../option_parser.h ../intersim/statwraper.h ptx-stats.h +cuda-sim.o: ptx_loader.h ptx_parser.h +instructions.o: ptx_ir.h ../abstract_hardware_model.h /usr/include/assert.h +instructions.o: /usr/include/features.h /usr/include/sys/cdefs.h +instructions.o: /usr/include/bits/wordsize.h /usr/include/gnu/stubs.h +instructions.o: /usr/include/gnu/stubs-64.h ptx_sim.h /usr/include/stdlib.h +instructions.o: /usr/include/sys/types.h /usr/include/bits/types.h +instructions.o: /usr/include/bits/typesizes.h /usr/include/time.h +instructions.o: /usr/include/endian.h /usr/include/bits/endian.h +instructions.o: /usr/include/bits/byteswap.h /usr/include/sys/select.h +instructions.o: /usr/include/bits/select.h /usr/include/bits/sigset.h +instructions.o: /usr/include/bits/time.h /usr/include/sys/sysmacros.h +instructions.o: /usr/include/bits/pthreadtypes.h /usr/include/alloca.h +instructions.o: dram_callback.h opcodes.h opcodes.def memory.h +instructions.o: /usr/include/string.h /usr/include/stdio.h +instructions.o: /usr/include/libio.h /usr/include/_G_config.h +instructions.o: /usr/include/wchar.h /usr/include/bits/stdio_lim.h +instructions.o: /usr/include/bits/sys_errlist.h ../option_parser.h +instructions.o: /usr/include/math.h /usr/include/bits/huge_val.h +instructions.o: /usr/include/bits/mathdef.h /usr/include/bits/mathcalls.h +instructions.o: /usr/include/fenv.h /usr/include/bits/fenv.h cuda-math.h +instructions.o: ptx_loader.h +memory.o: memory.h ../abstract_hardware_model.h /usr/include/assert.h +memory.o: /usr/include/features.h /usr/include/sys/cdefs.h +memory.o: /usr/include/bits/wordsize.h /usr/include/gnu/stubs.h +memory.o: /usr/include/gnu/stubs-64.h /usr/include/string.h +memory.o: /usr/include/stdio.h /usr/include/bits/types.h +memory.o: /usr/include/bits/typesizes.h /usr/include/libio.h +memory.o: /usr/include/_G_config.h /usr/include/wchar.h +memory.o: /usr/include/bits/stdio_lim.h /usr/include/bits/sys_errlist.h +memory.o: /usr/include/stdlib.h /usr/include/sys/types.h /usr/include/time.h +memory.o: /usr/include/endian.h /usr/include/bits/endian.h +memory.o: /usr/include/bits/byteswap.h /usr/include/sys/select.h +memory.o: /usr/include/bits/select.h /usr/include/bits/sigset.h +memory.o: /usr/include/bits/time.h /usr/include/sys/sysmacros.h +memory.o: /usr/include/bits/pthreadtypes.h /usr/include/alloca.h ../debug.h +memory.o: ../abstract_hardware_model.h +ptx_ir.o: ptx_parser.h ../abstract_hardware_model.h ptx_ir.h +ptx_ir.o: /usr/include/assert.h /usr/include/features.h +ptx_ir.o: /usr/include/sys/cdefs.h /usr/include/bits/wordsize.h +ptx_ir.o: /usr/include/gnu/stubs.h /usr/include/gnu/stubs-64.h ptx_sim.h +ptx_ir.o: /usr/include/stdlib.h /usr/include/sys/types.h +ptx_ir.o: /usr/include/bits/types.h /usr/include/bits/typesizes.h +ptx_ir.o: /usr/include/time.h /usr/include/endian.h +ptx_ir.o: /usr/include/bits/endian.h /usr/include/bits/byteswap.h +ptx_ir.o: /usr/include/sys/select.h /usr/include/bits/select.h +ptx_ir.o: /usr/include/bits/sigset.h /usr/include/bits/time.h +ptx_ir.o: /usr/include/sys/sysmacros.h /usr/include/bits/pthreadtypes.h +ptx_ir.o: /usr/include/alloca.h dram_callback.h opcodes.h opcodes.def +ptx_ir.o: memory.h /usr/include/string.h /usr/include/stdio.h +ptx_ir.o: /usr/include/libio.h /usr/include/_G_config.h /usr/include/wchar.h +ptx_ir.o: /usr/include/bits/stdio_lim.h /usr/include/bits/sys_errlist.h +ptx_ir.o: ../option_parser.h cuda-sim.h +ptx_loader.o: ptx_loader.h ptx_ir.h ../abstract_hardware_model.h +ptx_loader.o: /usr/include/assert.h /usr/include/features.h +ptx_loader.o: /usr/include/sys/cdefs.h /usr/include/bits/wordsize.h +ptx_loader.o: /usr/include/gnu/stubs.h /usr/include/gnu/stubs-64.h ptx_sim.h +ptx_loader.o: /usr/include/stdlib.h /usr/include/sys/types.h +ptx_loader.o: /usr/include/bits/types.h /usr/include/bits/typesizes.h +ptx_loader.o: /usr/include/time.h /usr/include/endian.h +ptx_loader.o: /usr/include/bits/endian.h /usr/include/bits/byteswap.h +ptx_loader.o: /usr/include/sys/select.h /usr/include/bits/select.h +ptx_loader.o: /usr/include/bits/sigset.h /usr/include/bits/time.h +ptx_loader.o: /usr/include/sys/sysmacros.h /usr/include/bits/pthreadtypes.h +ptx_loader.o: /usr/include/alloca.h dram_callback.h opcodes.h opcodes.def +ptx_loader.o: memory.h /usr/include/string.h /usr/include/stdio.h +ptx_loader.o: /usr/include/libio.h /usr/include/_G_config.h +ptx_loader.o: /usr/include/wchar.h /usr/include/bits/stdio_lim.h +ptx_loader.o: /usr/include/bits/sys_errlist.h ../option_parser.h cuda-sim.h +ptx_loader.o: ptx_parser.h /usr/include/dirent.h /usr/include/bits/dirent.h +ptx_loader.o: /usr/include/bits/posix1_lim.h /usr/include/bits/local_lim.h +ptx_loader.o: /usr/include/linux/limits.h +ptx_parser.o: ptx_parser.h ../abstract_hardware_model.h ptx_ir.h +ptx_parser.o: /usr/include/assert.h /usr/include/features.h +ptx_parser.o: /usr/include/sys/cdefs.h /usr/include/bits/wordsize.h +ptx_parser.o: /usr/include/gnu/stubs.h /usr/include/gnu/stubs-64.h ptx_sim.h +ptx_parser.o: /usr/include/stdlib.h /usr/include/sys/types.h +ptx_parser.o: /usr/include/bits/types.h /usr/include/bits/typesizes.h +ptx_parser.o: /usr/include/time.h /usr/include/endian.h +ptx_parser.o: /usr/include/bits/endian.h /usr/include/bits/byteswap.h +ptx_parser.o: /usr/include/sys/select.h /usr/include/bits/select.h +ptx_parser.o: /usr/include/bits/sigset.h /usr/include/bits/time.h +ptx_parser.o: /usr/include/sys/sysmacros.h /usr/include/bits/pthreadtypes.h +ptx_parser.o: /usr/include/alloca.h dram_callback.h opcodes.h opcodes.def +ptx_parser.o: memory.h /usr/include/string.h /usr/include/stdio.h +ptx_parser.o: /usr/include/libio.h /usr/include/_G_config.h +ptx_parser.o: /usr/include/wchar.h /usr/include/bits/stdio_lim.h +ptx_parser.o: /usr/include/bits/sys_errlist.h ../option_parser.h +ptx_sim.o: ptx_sim.h /usr/include/stdlib.h /usr/include/features.h +ptx_sim.o: /usr/include/sys/cdefs.h /usr/include/bits/wordsize.h +ptx_sim.o: /usr/include/gnu/stubs.h /usr/include/gnu/stubs-64.h +ptx_sim.o: /usr/include/sys/types.h /usr/include/bits/types.h +ptx_sim.o: /usr/include/bits/typesizes.h /usr/include/time.h +ptx_sim.o: /usr/include/endian.h /usr/include/bits/endian.h +ptx_sim.o: /usr/include/bits/byteswap.h /usr/include/sys/select.h +ptx_sim.o: /usr/include/bits/select.h /usr/include/bits/sigset.h +ptx_sim.o: /usr/include/bits/time.h /usr/include/sys/sysmacros.h +ptx_sim.o: /usr/include/bits/pthreadtypes.h /usr/include/alloca.h +ptx_sim.o: dram_callback.h ../abstract_hardware_model.h /usr/include/assert.h +ptx_sim.o: opcodes.h opcodes.def ptx_ir.h memory.h /usr/include/string.h +ptx_sim.o: /usr/include/stdio.h /usr/include/libio.h /usr/include/_G_config.h +ptx_sim.o: /usr/include/wchar.h /usr/include/bits/stdio_lim.h +ptx_sim.o: /usr/include/bits/sys_errlist.h ../option_parser.h +ptx-stats.o: ptx_ir.h ../abstract_hardware_model.h /usr/include/assert.h +ptx-stats.o: /usr/include/features.h /usr/include/sys/cdefs.h +ptx-stats.o: /usr/include/bits/wordsize.h /usr/include/gnu/stubs.h +ptx-stats.o: /usr/include/gnu/stubs-64.h ptx_sim.h /usr/include/stdlib.h +ptx-stats.o: /usr/include/sys/types.h /usr/include/bits/types.h +ptx-stats.o: /usr/include/bits/typesizes.h /usr/include/time.h +ptx-stats.o: /usr/include/endian.h /usr/include/bits/endian.h +ptx-stats.o: /usr/include/bits/byteswap.h /usr/include/sys/select.h +ptx-stats.o: /usr/include/bits/select.h /usr/include/bits/sigset.h +ptx-stats.o: /usr/include/bits/time.h /usr/include/sys/sysmacros.h +ptx-stats.o: /usr/include/bits/pthreadtypes.h /usr/include/alloca.h +ptx-stats.o: dram_callback.h opcodes.h opcodes.def memory.h +ptx-stats.o: /usr/include/string.h /usr/include/stdio.h /usr/include/libio.h +ptx-stats.o: /usr/include/_G_config.h /usr/include/wchar.h +ptx-stats.o: /usr/include/bits/stdio_lim.h /usr/include/bits/sys_errlist.h +ptx-stats.o: ../option_parser.h ptx-stats.h diff --git a/src/cuda-sim/cuda-sim.cc b/src/cuda-sim/cuda-sim.cc index f5c283e..6a0ee36 100644 --- a/src/cuda-sim/cuda-sim.cc +++ b/src/cuda-sim/cuda-sim.cc @@ -78,6 +78,7 @@ #include "memory.h" #include "ptx-stats.h" #include "ptx_loader.h" +#include "ptx_parser.h" extern bool g_interactive_debugger_enabled; @@ -90,8 +91,6 @@ int g_debug_execution = 0; int g_debug_thread_uid = 0; addr_t g_debug_pc = 0xBEEF1518; -const char *g_filename; -bool g_debug_ir_generation = false; unsigned g_ptx_sim_num_insn = 0; std::map TextureToArrayMap; // texture bindings @@ -1113,7 +1112,6 @@ void init_inst_classification_stat() { g_inst_op_classification_stat[g_ptx_kernel_count] = StatCreate(kernelname,1,100); } -unsigned g_max_regs_per_thread = 0; std::map *g_kernel_name_to_function_lookup=NULL; std::map g_kernel_name_to_symtab_lookup; @@ -1211,8 +1209,6 @@ void gpgpu_ptx_sim_register_kernel(const char *hostFun, const char *deviceFun) printf("GPGPU-Sim PTX: __cudaRegisterFunction %s : 0x%Lx\n", deviceFun, (unsigned long long)hostFun); } -extern int ptx_lineno; - void register_ptx_function( const char *name, function_info *impl, symbol_table *symtab ) { printf("GPGPU-Sim PTX: parsing function %s\n", name ); @@ -1328,7 +1324,6 @@ void read_sim_environment_variables() { ptx_debug = 0; g_debug_execution = 0; - g_debug_ir_generation = false; g_interactive_debugger_enabled = false; char *mode = getenv("PTX_SIM_MODE_FUNC"); @@ -1336,7 +1331,6 @@ void read_sim_environment_variables() sscanf(mode,"%u", &g_ptx_sim_mode); printf("GPGPU-Sim PTX: simulation mode %d (can change with PTX_SIM_MODE_FUNC environment variable:\n", g_ptx_sim_mode); printf(" 1=functional simulation only, 0=detailed performance simulator)\n"); - g_filename = getenv("PTX_SIM_KERNELFILE"); char *dbg_inter = getenv("GPGPUSIM_DEBUG"); if ( dbg_inter && strlen(dbg_inter) ) { printf("GPGPU-Sim PTX: enabling interactive debugger\n"); @@ -1377,9 +1371,6 @@ void read_sim_environment_variables() if ( g_debug_execution >= 40 ) { ptx_debug = 1; } - if ( g_debug_execution >= 30 ) { - g_debug_ir_generation = true; - } } diff --git a/src/cuda-sim/cuda-sim.h b/src/cuda-sim/cuda-sim.h index 2e67e15..6662b4c 100644 --- a/src/cuda-sim/cuda-sim.h +++ b/src/cuda-sim/cuda-sim.h @@ -15,9 +15,6 @@ extern int g_ptx_sim_mode; extern memory_space *g_global_mem; extern int g_debug_execution; extern int g_debug_thread_uid; -extern unsigned g_max_regs_per_thread; -extern bool g_debug_ir_generation; -extern const char *g_filename; extern std::map *g_kernel_name_to_function_lookup; extern std::map g_kernel_name_to_symtab_lookup; @@ -42,5 +39,6 @@ extern int gpgpu_ptx_sim_sizeofTexture(const char* name); extern const char* gpgpu_ptx_sim_findNamefromTexture(const struct textureReference* texref); extern const struct textureReference* gpgpu_ptx_sim_accessTextureofName(const char* name); extern void read_sim_environment_variables(); +extern void register_ptx_function( const char *name, function_info *impl, symbol_table *symtab ); #endif diff --git a/src/cuda-sim/instructions.cc b/src/cuda-sim/instructions.cc index b3a0342..0924eab 100644 --- a/src/cuda-sim/instructions.cc +++ b/src/cuda-sim/instructions.cc @@ -87,7 +87,6 @@ const char *g_opcode_string[NUM_OPCODES] = { #undef OP_DEF }; -extern std::map g_ptx_token_decode; extern std::map TextureToArrayMap; // texture bindings extern std::map TextureToInfoMap; // texture bindings extern std::map NameToTextureMap; diff --git a/src/cuda-sim/ptx.y b/src/cuda-sim/ptx.y index f788e01..a1e1428 100644 --- a/src/cuda-sim/ptx.y +++ b/src/cuda-sim/ptx.y @@ -206,7 +206,7 @@ %type function_decl %{ - #include "ptx_ir.h" + #include "ptx_parser.h" #include #include #include diff --git a/src/cuda-sim/ptx_ir.cc b/src/cuda-sim/ptx_ir.cc index 51ad05f..cd70daf 100644 --- a/src/cuda-sim/ptx_ir.cc +++ b/src/cuda-sim/ptx_ir.cc @@ -61,6 +61,7 @@ * Vancouver, BC V6T 1Z4 */ +#include "ptx_parser.h" #include "ptx_ir.h" #include "ptx.tab.h" #include "opcodes.h" @@ -69,612 +70,8 @@ #include #include #include -#include #include "cuda-sim.h" -#include "../option_parser.h" - -extern "C" int ptx_error( const char *s ); -extern int ptx_lineno; - -// the program intermediate representation... -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; - -// type specifier stuff: -memory_space_t g_space_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; -symbol *g_label; -int g_opcode = -1; -std::list g_operands; -std::list g_options; -std::list g_scalar_type; - -#define DPRINTF(...) \ - if( g_debug_ir_generation ) { \ - printf(" %s:%u => ",g_filename,ptx_lineno); \ - printf(" (%s:%u) ", __FILE__, __LINE__); \ - printf(__VA_ARGS__); \ - printf("\n"); \ - fflush(stdout); \ - } - -unsigned g_entry_func_param_index=0; -function_info *g_func_info = NULL; -function_info *g_entrypoint_func_info = NULL; -symbol_table *g_entrypoint_symbol_table = NULL; -std::map g_ptx_token_decode; -operand_info g_return_var; - -void init_parser() -{ - g_global_symbol_table = g_current_symbol_table = new symbol_table("global",0,NULL); - ptx_lineno = 1; - -#define DEF(X,Y) g_ptx_token_decode[X] = Y; -#include "ptx_parser_decode.def" -#undef DEF -} - -void init_directive_state() -{ - DPRINTF("init_directive_state"); - g_space_spec=undefined_space; - g_scalar_type_spec=-1; - g_vector_spec=-1; - g_opcode=-1; - g_alignment_spec = -1; - g_extern_spec = 0; - g_scalar_type.clear(); - g_operands.clear(); - g_last_symbol = NULL; -} - -void init_instruction_state() -{ - DPRINTF("init_instruction_state"); - g_pred = NULL; - g_neg_pred = 0; - g_label = NULL; - g_opcode = -1; - g_options.clear(); - g_return_var = operand_info(); - init_directive_state(); -} - -extern void register_ptx_function( const char *name, function_info *impl, symbol_table *symtab ); - -static int g_entry_point; - -void start_function( int entry_point ) -{ - DPRINTF("start_function"); - init_directive_state(); - init_instruction_state(); - g_entry_point = entry_point; - g_func_info = NULL; - g_entry_func_param_index=0; -} - -char *g_add_identifier_cached__identifier = NULL; -int g_add_identifier_cached__array_dim; -int g_add_identifier_cached__array_ident; - -void add_function_name( const char *name ) -{ - DPRINTF("add_function_name %s %s", name, ((g_entry_point==1)?"(entrypoint)":((g_entry_point==2)?"(extern)":""))); - bool prior_decl = g_global_symbol_table->add_function_decl( name, g_entry_point, &g_func_info, &g_current_symbol_table ); - if( g_entry_point ) { - g_entrypoint_func_info = g_func_info; - g_entrypoint_symbol_table = g_current_symbol_table; - } - if( g_add_identifier_cached__identifier ) { - add_identifier( g_add_identifier_cached__identifier, - g_add_identifier_cached__array_dim, - g_add_identifier_cached__array_ident ); - free( g_add_identifier_cached__identifier ); - g_add_identifier_cached__identifier = NULL; - g_func_info->add_return_var( g_last_symbol ); - init_directive_state(); - } - if( prior_decl ) { - g_func_info->remove_args(); - } - g_global_symbol_table->add_function( g_func_info ); -} - -void add_directive() -{ - DPRINTF("add_directive"); - init_directive_state(); -} - -#define mymax(a,b) ((a)>(b)?(a):(b)) - -void end_function() -{ - DPRINTF("end_function"); - - init_directive_state(); - init_instruction_state(); - g_max_regs_per_thread = mymax( g_max_regs_per_thread, (g_current_symbol_table->next_reg_num()-1)); - g_func_info->add_inst( g_instructions ); - g_instructions.clear(); - gpgpu_ptx_assemble( g_func_info->get_name(), g_func_info ); - g_current_symbol_table = g_global_symbol_table; - - DPRINTF("function %s, PC = %d\n", g_func_info->get_name().c_str(), g_func_info->get_start_PC()); -} - -#define parse_error(msg, ...) parse_error_impl(__FILE__,__LINE__, msg, ##__VA_ARGS__) -#define parse_assert(cond,msg, ...) parse_assert_impl((cond),__FILE__,__LINE__, msg, ##__VA_ARGS__) - -void parse_error_impl( const char *file, unsigned line, const char *msg, ... ) -{ - va_list ap; - char buf[1024]; - va_start(ap,msg); - vsnprintf(buf,1024,msg,ap); - va_end(ap); - - g_error_detected = 1; - printf("%s:%u: Parse error: %s (%s:%u)\n\n", g_filename, ptx_lineno, buf, file, line); - ptx_error(NULL); - abort(); - exit(1); -} - -void parse_assert_impl( int test_value, const char *file, unsigned line, const char *msg, ... ) -{ - va_list ap; - char buf[1024]; - va_start(ap,msg); - vsnprintf(buf,1024,msg,ap); - va_end(ap); - - if ( test_value == 0 ) - parse_error_impl(file,line, msg); -} - -extern "C" char linebuf[1024]; - - -void set_return() -{ - parse_assert( (g_opcode == CALL_OP), "only call can have return value"); - g_operands.front().set_return(); - g_return_var = g_operands.front(); -} - -std::map > g_inst_lookup; - -const ptx_instruction *ptx_instruction_lookup( const char *filename, unsigned linenumber ) -{ - std::map >::iterator f=g_inst_lookup.find(filename); - if( f == g_inst_lookup.end() ) - return NULL; - std::map::iterator l=f->second.find(linenumber); - if( l == f->second.end() ) - return NULL; - return l->second; -} - -void add_instruction() -{ - DPRINTF("add_instruction: %s", ((g_opcode>0)?g_opcode_string[g_opcode]:"