From 262d5d3f90ec2a580f27f4967afa3f089d3fb64a Mon Sep 17 00:00:00 2001 From: andy <1414772332@qq.com> Date: Thu, 26 Jun 2025 16:15:07 +0800 Subject: [PATCH] =?UTF-8?q?meke.py=20=E4=BD=BF=E7=94=A8=E5=91=BD=E4=BB=A4?= =?UTF-8?q?=E8=A1=8C=E4=BC=A0=E5=85=A5=E6=BA=90=E6=96=87=E4=BB=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- create_signal_fun.py | 9 ++++++++- main.c | 2 +- make.py | 5 +++-- soft/clexical.c | 2 +- soft/debug.c | 22 +++++++++++----------- soft/mythread.c | 2 +- test/lambda_test.c | 19 ++++++++++--------- test/riscv_test.c | 17 +++++++++-------- test/test_fun.c | 1 - 9 files changed, 44 insertions(+), 35 deletions(-) diff --git a/create_signal_fun.py b/create_signal_fun.py index 03512d3..0c13599 100644 --- a/create_signal_fun.py +++ b/create_signal_fun.py @@ -122,12 +122,19 @@ void {signal_fun}({','.join(pars)}){'{'} # 生成一个槽函数描述 def def_slot_fun_str(slot_fun:str,pars:list): pars_str="" - for index,item in enumerate(get_pars_names(pars)): + pars_names=get_pars_names(pars) + for index,item in enumerate(pars_names): if(index{item}," else: pars_str+=f"a->{item}" + unsued_pars="" + for item in pars_names: + unsued_pars+=f" (void){item};\n" slot_fun_str=f""" +__attribute__((weak)) void {slot_fun}({','.join(pars)}){'{'} +{unsued_pars}{'}'} + static void {slot_fun}_caller(void *args){'{'} {slot_fun}_args *a = args; {slot_fun}({pars_str}); diff --git a/main.c b/main.c index 8fd9d87..ad8599e 100644 --- a/main.c +++ b/main.c @@ -24,7 +24,7 @@ const char g_str[] = __attribute__((weak)) int thread_fun(void* t) { - DBG_INFO("run in thread_fun.\n"); + DBG_LOG("run in default thread_fun.\n"); // lex_analysis(g_str , strlen(g_str)); return 0; diff --git a/make.py b/make.py index 849494e..845b3d7 100644 --- a/make.py +++ b/make.py @@ -25,7 +25,7 @@ CC = 'gcc' # HEX = 'C:\\ARM_GCC\\bin\\arm-none-eabi-objcopy' + ' -O ihex' # BIN = 'C:\\ARM_GCC\\bin\\arm-none-eabi-objcopy' + ' -O binary -S' -CSRC = ["main.c","test/riscv_test.c","test/signal_test.c"] +CSRC = ["main.c"] CINC = ['-Isoft',"-Iriscv_cpu", "-I./","-Itest"] @@ -192,7 +192,8 @@ def main(): global ASRC if(not os.path.exists(BUILD_DIR)): os.makedirs(BUILD_DIR) - + # 在命令行中传入的源文件 + CSRC+=sys.argv[1:] CSRC+=find_type('soft',['c','C']) CSRC+=find_type('riscv_cpu',['c','C']) CSRC=search_lambda(CSRC) diff --git a/soft/clexical.c b/soft/clexical.c index 8de941c..2a24be6 100644 --- a/soft/clexical.c +++ b/soft/clexical.c @@ -238,7 +238,7 @@ int lex_print_token_list(lex_def* lex) { token_list_node_def* t; t = l->head; while (t) { - printf("%4d[%3d,%3d],token=%4d \"%s\"\n" , t->token.line , t->token.pos , + DBG_LOG("%4d[%3d,%3d],token=%4d \"%s\"\n" , t->token.line , t->token.pos , t->token.used , t->token.token, t->token.buff ); t = t->next; } diff --git a/soft/debug.c b/soft/debug.c index f38957f..32012ae 100644 --- a/soft/debug.c +++ b/soft/debug.c @@ -8,6 +8,7 @@ #include #include "errno.h" #include "pthread.h" +#include "lambda.h" #define CONSOLEBUF_SIZE 1024 @@ -23,19 +24,18 @@ typedef struct{ static self_def g_data; +lambda_use -static int dev_init(){ - return 0; -} -static int dev_write(const uint8_t *data,size_t len){ - size_t rb; - rb=fwrite(data,sizeof(uint8_t),len,stdout); - return (int)rb; -} -static dbg_dev g_dev_default={ - .init=dev_init, - .write=dev_write, +static dbg_dev g_dev_default = { + .init = lambda(int() { + return 0; + }), + .write = lambda(int(const uint8_t * data,size_t len) { + size_t rb; + rb=fwrite(data,sizeof(uint8_t),len,stdout); + return (int)rb; + }) }; diff --git a/soft/mythread.c b/soft/mythread.c index 012a00d..6030c8a 100644 --- a/soft/mythread.c +++ b/soft/mythread.c @@ -93,7 +93,7 @@ myth_def *myth_self(){ } myth=myth->next; } - printf("can not find myth.\n"); + DBG_WARN("can not find myth.\n"); return NULL; } diff --git a/test/lambda_test.c b/test/lambda_test.c index a3d4386..fdb1d64 100644 --- a/test/lambda_test.c +++ b/test/lambda_test.c @@ -6,6 +6,7 @@ #include "string.h" #include "main.h" #include "lambda.h" +#include "debug.h" typedef struct test_struct{ int a; @@ -24,7 +25,7 @@ lambda_use void run_callback(int (*fun)(int a, int b)) { int a = fun(1, 2); - printf("a = %d\n", a); + DBG_LOG("a = %d\n", a); } @@ -50,30 +51,30 @@ int thread_fun(void* t) { void (*fun1)(int a, int b); fun1 = lambda(void(int a, int b) { - printf("a = %d, b = %d\n", a, b); + DBG_LOG("a = %d, b = %d\n", a, b); }); fun1(1, 2); void (*fun2)(int a, int b); fun2 = lambda(void(int a, int b) { - printf("a = %d, b = %d a*b=%d\n", a, b, a * b); + DBG_LOG("a = %d, b = %d a*b=%d\n", a, b, a * b); }); fun2(3, 4); void (*fun3)(void); fun3 = lambda(void(void) { int a = 3; int b = 4; - printf("a = %d, b = %d a*b=%d\n", a, b, a * b); + DBG_LOG("a = %d, b = %d a*b=%d\n", a, b, a * b); }); fun3(); void (*fun4)(); fun4 = lambda(void() { int a = 5, b = 6; - printf("a = %d, b = %d a*b=%d\n", a, b, a * b); + DBG_LOG("a = %d, b = %d a*b=%d\n", a, b, a * b); }); fun4(); unsigned int (*fun5)(int a, int b); fun5 = lambda(unsigned int (int a,int b) { - printf("a = %d, b = %d a*b=%d\n", a, b, a * b); + DBG_LOG("a = %d, b = %d a*b=%d\n", a, b, a * b); return 6; }); fun5(3, 4); @@ -85,9 +86,9 @@ int thread_fun(void* t) return a * b * 10; })); - printf("test_struct_var.sub(1,2) = %d\n", test_struct_var.sub(1, 2)); - printf("test_struct_var.add(1,2) = %d\n", test_struct_var.add(1, 2)); - printf("test_struct_var.sum(&test_struct_var) = %d\n", test_struct_var.sum(&test_struct_var)); + DBG_LOG("test_struct_var.sub(1,2) = %d\n", test_struct_var.sub(1, 2)); + DBG_LOG("test_struct_var.add(1,2) = %d\n", test_struct_var.add(1, 2)); + DBG_LOG("test_struct_var.sum(&test_struct_var) = %d\n", test_struct_var.sum(&test_struct_var)); return 0; } diff --git a/test/riscv_test.c b/test/riscv_test.c index dcaf65e..5f35c98 100644 --- a/test/riscv_test.c +++ b/test/riscv_test.c @@ -3,6 +3,7 @@ #include "errno.h" #include "stdlib.h" #include "string.h" +#include "debug.h" #include "../main.h" #include "../riscv_cpu/riscv.h" @@ -16,19 +17,19 @@ long get_file_size(FILE *stream) long file_size = -1; long cur_offset = ftell(stream); // 获取当前偏移位置 if (cur_offset == -1) { - printf("ftell failed :%s\n", strerror(errno)); + DBG_LOG("ftell failed :%s\n", strerror(errno)); return -1; } if (fseek(stream, 0, SEEK_END) != 0) { // 移动文件指针到文件末尾 - printf("fseek failed: %s\n", strerror(errno)); + DBG_LOG("fseek failed: %s\n", strerror(errno)); return -1; } file_size = ftell(stream); // 获取此时偏移值,即文件大小 if (file_size == -1) { - printf("ftell failed :%s\n", strerror(errno)); + DBG_LOG("ftell failed :%s\n", strerror(errno)); } if (fseek(stream, cur_offset, SEEK_SET) != 0) { // 将文件指针恢复初始位置 - printf("fseek failed: %s\n", strerror(errno)); + DBG_LOG("fseek failed: %s\n", strerror(errno)); return -1; } return file_size; @@ -39,7 +40,7 @@ long get_file_size(FILE *stream) riscv_t riscv = { 0 }; -int thread_fun_r(void* t) +int thread_fun(void* t) { int argc; char** argv; @@ -50,15 +51,15 @@ int thread_fun_r(void* t) bin_name=argv[1]; } - printf("riscv start\n"); + DBG_LOG("riscv start\n"); FILE *file=fopen(bin_name, "rb" ); if(file==NULL) { - printf("open file %s error\n",bin_name); + DBG_LOG("open file %s error\n",bin_name); return -1; } riscv.rom_size = get_file_size(file); - printf("rom size: %d\n", riscv.rom_size); + DBG_LOG("rom size: %d\n", riscv.rom_size); riscv.rom = calloc((riscv.rom_size + 3) / 4, 4); fread(riscv.rom, 1, riscv.rom_size, file); fclose(file); diff --git a/test/test_fun.c b/test/test_fun.c index 22c41c7..39488ce 100644 --- a/test/test_fun.c +++ b/test/test_fun.c @@ -7,7 +7,6 @@ - const uint32_t iot_crc32_table[256] = { 0x00000000, 0x77073096, 0xEE0E612C, 0x990951BA, 0x076DC419, 0x706AF48F,