meke.py 使用命令行传入源文件
This commit is contained in:
@@ -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;
|
||||
}
|
||||
|
@@ -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);
|
||||
|
@@ -7,7 +7,6 @@
|
||||
|
||||
|
||||
|
||||
|
||||
const uint32_t iot_crc32_table[256] =
|
||||
{
|
||||
0x00000000, 0x77073096, 0xEE0E612C, 0x990951BA, 0x076DC419, 0x706AF48F,
|
||||
|
Reference in New Issue
Block a user