Ver1.3 && alignment size could be set by argument
This commit is contained in:
parent
ee707fda1a
commit
8f9dc89b9a
@ -1,7 +1,7 @@
|
|||||||
#ifndef __CONFIG_HPP__
|
#ifndef __CONFIG_HPP__
|
||||||
#define __CONFIG_HPP__
|
#define __CONFIG_HPP__
|
||||||
|
|
||||||
#define ADDR_ALIGNMENT_SIZE 4 // 地址对齐方式
|
#define DEFAULT_ADDR_ALIGNMENT_SIZE 4 // 默认地址对齐长度
|
||||||
|
|
||||||
#define VARIABLE_NAME_STR_LENGTH_MAX 100 // 名称字符串最大长度
|
#define VARIABLE_NAME_STR_LENGTH_MAX 100 // 名称字符串最大长度
|
||||||
|
|
||||||
|
@ -7,6 +7,9 @@ extern "C"
|
|||||||
#include "stdio.h"
|
#include "stdio.h"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 地址对齐长度
|
||||||
|
extern size_t addr_alignment_size;
|
||||||
|
|
||||||
// 类型列表
|
// 类型列表
|
||||||
extern type_node *type_list_head;
|
extern type_node *type_list_head;
|
||||||
|
|
||||||
|
@ -25,6 +25,28 @@ void solve_args(int argc, char *argv[])
|
|||||||
if (argv[count][0] == '-')
|
if (argv[count][0] == '-')
|
||||||
{
|
{
|
||||||
|
|
||||||
|
// -a 字节对齐长度设置
|
||||||
|
if (!strcmp(argv[count], "-a"))
|
||||||
|
{
|
||||||
|
// 错误输入处理
|
||||||
|
if (count + 1 == argc)
|
||||||
|
break;
|
||||||
|
if (argv[count + 1][0] == '-')
|
||||||
|
continue;
|
||||||
|
|
||||||
|
size_t value = 0;
|
||||||
|
sscanf(argv[count + 1], "%u", &value);
|
||||||
|
if ((value % 2 == 0 && value != 0) || value == 1)
|
||||||
|
{
|
||||||
|
log_printf(LOG_SUCCESS, "Alignment size set to %u.", value);
|
||||||
|
addr_alignment_size = value;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
log_printf(LOG_FAILURE, "Illegal alignment arg \"%s\", set to default %u.", argv[count + 1], addr_alignment_size);
|
||||||
|
count++;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
// -r 参考A2L输入
|
// -r 参考A2L输入
|
||||||
if (!strcmp(argv[count], "-r"))
|
if (!strcmp(argv[count], "-r"))
|
||||||
{
|
{
|
||||||
@ -175,6 +197,7 @@ void solve_args(int argc, char *argv[])
|
|||||||
{
|
{
|
||||||
printf("\n");
|
printf("\n");
|
||||||
log_printf(LOG_INFO, "Workflow details:");
|
log_printf(LOG_INFO, "Workflow details:");
|
||||||
|
printf(" ├─Alignment size: %u\n", addr_alignment_size);
|
||||||
printf(" ├─Source or header files:\n");
|
printf(" ├─Source or header files:\n");
|
||||||
|
|
||||||
// 遍历文件链表
|
// 遍历文件链表
|
||||||
|
@ -5,6 +5,9 @@ extern "C"
|
|||||||
#include "stdio.h"
|
#include "stdio.h"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 地址对齐长度
|
||||||
|
size_t addr_alignment_size = DEFAULT_ADDR_ALIGNMENT_SIZE;
|
||||||
|
|
||||||
// 类型列表
|
// 类型列表
|
||||||
type_node *type_list_head = nullptr;
|
type_node *type_list_head = nullptr;
|
||||||
|
|
||||||
|
@ -14,7 +14,7 @@ extern "C"
|
|||||||
int main(int argc, char *argv[])
|
int main(int argc, char *argv[])
|
||||||
{
|
{
|
||||||
printf("\n\n");
|
printf("\n\n");
|
||||||
log_printf(LOG_SYS_INFO, "SrcToA2L Ver1.2");
|
log_printf(LOG_SYS_INFO, "SrcToA2L Ver1.3");
|
||||||
log_printf(LOG_SYS_INFO, "Auther: LuChiChick");
|
log_printf(LOG_SYS_INFO, "Auther: LuChiChick");
|
||||||
log_printf(LOG_SYS_INFO, "%s\n%s\n%s\n\n", "Open source links:",
|
log_printf(LOG_SYS_INFO, "%s\n%s\n%s\n\n", "Open source links:",
|
||||||
" ├─Github: https://git.luchichick.cn/LuChiChick/SrcToA2L",
|
" ├─Github: https://git.luchichick.cn/LuChiChick/SrcToA2L",
|
||||||
|
@ -664,12 +664,12 @@ void f_print_calibration(FILE *file, variable_info v_info)
|
|||||||
for (size_t sub_count = 0; sub_count < sub_element_count; sub_count++)
|
for (size_t sub_count = 0; sub_count < sub_element_count; sub_count++)
|
||||||
{
|
{
|
||||||
// 计算出现的最大对齐
|
// 计算出现的最大对齐
|
||||||
if (alignment_max < (type_size[out_type] < ADDR_ALIGNMENT_SIZE ? type_size[out_type] : ADDR_ALIGNMENT_SIZE))
|
if (alignment_max < (type_size[out_type] < addr_alignment_size ? type_size[out_type] : addr_alignment_size))
|
||||||
alignment_max = (type_size[out_type] < ADDR_ALIGNMENT_SIZE ? type_size[out_type] : ADDR_ALIGNMENT_SIZE);
|
alignment_max = (type_size[out_type] < addr_alignment_size ? type_size[out_type] : addr_alignment_size);
|
||||||
|
|
||||||
// 地址对齐
|
// 地址对齐
|
||||||
if (addr_offset % (type_size[out_type] < ADDR_ALIGNMENT_SIZE ? type_size[out_type] : ADDR_ALIGNMENT_SIZE) != 0)
|
if (addr_offset % (type_size[out_type] < addr_alignment_size ? type_size[out_type] : addr_alignment_size) != 0)
|
||||||
addr_offset += (type_size[out_type] < ADDR_ALIGNMENT_SIZE ? type_size[out_type] : ADDR_ALIGNMENT_SIZE) - (addr_offset % (type_size[out_type] < ADDR_ALIGNMENT_SIZE ? type_size[out_type] : ADDR_ALIGNMENT_SIZE));
|
addr_offset += (type_size[out_type] < addr_alignment_size ? type_size[out_type] : addr_alignment_size) - (addr_offset % (type_size[out_type] < addr_alignment_size ? type_size[out_type] : addr_alignment_size));
|
||||||
|
|
||||||
// 拼接输出名称
|
// 拼接输出名称
|
||||||
if (v_info.type == STRUCTURE)
|
if (v_info.type == STRUCTURE)
|
||||||
@ -721,8 +721,8 @@ void f_print_calibration(FILE *file, variable_info v_info)
|
|||||||
|
|
||||||
// 补齐结构体末尾的空余字节偏移
|
// 补齐结构体末尾的空余字节偏移
|
||||||
if (v_info.type == STRUCTURE)
|
if (v_info.type == STRUCTURE)
|
||||||
if (addr_offset % (alignment_max < ADDR_ALIGNMENT_SIZE ? alignment_max : ADDR_ALIGNMENT_SIZE) != 0)
|
if (addr_offset % (alignment_max < addr_alignment_size ? alignment_max : addr_alignment_size) != 0)
|
||||||
addr_offset += (alignment_max < ADDR_ALIGNMENT_SIZE ? alignment_max : ADDR_ALIGNMENT_SIZE) - (addr_offset % (alignment_max < ADDR_ALIGNMENT_SIZE ? alignment_max : ADDR_ALIGNMENT_SIZE));
|
addr_offset += (alignment_max < addr_alignment_size ? alignment_max : addr_alignment_size) - (addr_offset % (alignment_max < addr_alignment_size ? alignment_max : addr_alignment_size));
|
||||||
}
|
}
|
||||||
|
|
||||||
// 输出日志
|
// 输出日志
|
||||||
@ -849,12 +849,12 @@ void f_print_measurement(FILE *file, variable_info v_info)
|
|||||||
for (size_t sub_count = 0; sub_count < sub_element_count; sub_count++)
|
for (size_t sub_count = 0; sub_count < sub_element_count; sub_count++)
|
||||||
{
|
{
|
||||||
// 计算出现的最大对齐
|
// 计算出现的最大对齐
|
||||||
if (alignment_max < (type_size[out_type] < ADDR_ALIGNMENT_SIZE ? type_size[out_type] : ADDR_ALIGNMENT_SIZE))
|
if (alignment_max < (type_size[out_type] < addr_alignment_size ? type_size[out_type] : addr_alignment_size))
|
||||||
alignment_max = (type_size[out_type] < ADDR_ALIGNMENT_SIZE ? type_size[out_type] : ADDR_ALIGNMENT_SIZE);
|
alignment_max = (type_size[out_type] < addr_alignment_size ? type_size[out_type] : addr_alignment_size);
|
||||||
|
|
||||||
// 地址对齐
|
// 地址对齐
|
||||||
if (addr_offset % (type_size[out_type] < ADDR_ALIGNMENT_SIZE ? type_size[out_type] : ADDR_ALIGNMENT_SIZE) != 0)
|
if (addr_offset % (type_size[out_type] < addr_alignment_size ? type_size[out_type] : addr_alignment_size) != 0)
|
||||||
addr_offset += (type_size[out_type] < ADDR_ALIGNMENT_SIZE ? type_size[out_type] : ADDR_ALIGNMENT_SIZE) - (addr_offset % (type_size[out_type] < ADDR_ALIGNMENT_SIZE ? type_size[out_type] : ADDR_ALIGNMENT_SIZE));
|
addr_offset += (type_size[out_type] < addr_alignment_size ? type_size[out_type] : addr_alignment_size) - (addr_offset % (type_size[out_type] < addr_alignment_size ? type_size[out_type] : addr_alignment_size));
|
||||||
|
|
||||||
// 拼接输出名称
|
// 拼接输出名称
|
||||||
if (v_info.type == STRUCTURE)
|
if (v_info.type == STRUCTURE)
|
||||||
@ -906,8 +906,8 @@ void f_print_measurement(FILE *file, variable_info v_info)
|
|||||||
|
|
||||||
// 补齐结构体末尾的空余字节偏移
|
// 补齐结构体末尾的空余字节偏移
|
||||||
if (v_info.type == STRUCTURE)
|
if (v_info.type == STRUCTURE)
|
||||||
if (addr_offset % (alignment_max < ADDR_ALIGNMENT_SIZE ? alignment_max : ADDR_ALIGNMENT_SIZE) != 0)
|
if (addr_offset % (alignment_max < addr_alignment_size ? alignment_max : addr_alignment_size) != 0)
|
||||||
addr_offset += (alignment_max < ADDR_ALIGNMENT_SIZE ? alignment_max : ADDR_ALIGNMENT_SIZE) - (addr_offset % (alignment_max < ADDR_ALIGNMENT_SIZE ? alignment_max : ADDR_ALIGNMENT_SIZE));
|
addr_offset += (alignment_max < addr_alignment_size ? alignment_max : addr_alignment_size) - (addr_offset % (alignment_max < addr_alignment_size ? alignment_max : addr_alignment_size));
|
||||||
}
|
}
|
||||||
|
|
||||||
// 输出日志
|
// 输出日志
|
||||||
|
Loading…
x
Reference in New Issue
Block a user