meke.py 使用命令行传入源文件

This commit is contained in:
2025-06-26 16:15:07 +08:00
parent 8928998479
commit 262d5d3f90
9 changed files with 44 additions and 35 deletions

View File

@@ -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<len(pars)-1):
pars_str+=f"a->{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});

2
main.c
View File

@@ -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;

View File

@@ -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)

View File

@@ -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;
}

View File

@@ -8,6 +8,7 @@
#include <sys/types.h>
#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;
})
};

View File

@@ -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;
}

View File

@@ -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;
}

View File

@@ -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);

View File

@@ -7,7 +7,6 @@
const uint32_t iot_crc32_table[256] =
{
0x00000000, 0x77073096, 0xEE0E612C, 0x990951BA, 0x076DC419, 0x706AF48F,