Skip to content

Commit

Permalink
Merge pull request #214 from aegoroff/develop
Browse files Browse the repository at this point in the history
Develop
  • Loading branch information
aegoroff authored Jul 17, 2024
2 parents 5509a78 + 7ae3898 commit 7c6ce0a
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 9 deletions.
18 changes: 12 additions & 6 deletions src/l2h/backend.c
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,11 @@ void bend_emit(fend_node_t *node, apr_pool_t *pool) {
}

if (instruction != NULL) {
if (instruction->code == opcode_type && instruction->op1->type == type_def_custom) {
// remove type string from stack
triple_t *algorithm = *(triple_t **)apr_array_pop(bend_instructions);
}

*(triple_t **)apr_array_push(bend_instructions) = instruction;
}
}
Expand Down Expand Up @@ -228,14 +233,11 @@ triple_t *prbend_create_internal_type_triple(fend_node_t *node, apr_pool_t *pool
instruction = (triple_t *)apr_pcalloc(pool, sizeof(triple_t));
instruction->code = opcode_type;

instruction->op1 = (op_value_t *)apr_pcalloc(pool, sizeof(op_value_t));
instruction->op1->type = node->value.type;
if (node->value.type == type_def_custom) {
instruction->op1 = (op_value_t *)apr_pcalloc(pool, sizeof(op_value_t));
instruction->op1->type = node->value.type;
instruction->op2 = (op_value_t *)apr_pcalloc(pool, sizeof(op_value_t));
instruction->op2->string = node->left->value.string;
} else {
instruction->op1 = (op_value_t *)apr_pcalloc(pool, sizeof(op_value_t));
instruction->op1->type = node->value.type;
}

return instruction;
Expand Down Expand Up @@ -271,7 +273,11 @@ triple_t *prbend_create_identifier_triple(fend_node_t *node, apr_pool_t *pool) {
if (prev->code == opcode_type) {
prev = *(triple_t **)apr_array_pop(bend_instructions);
instruction->code = opcode_def;
instruction->op1 = prev->op1;
if (prev->op1->type == type_def_custom) {
instruction->op1 = prev->op2;
} else {
instruction->op1 = prev->op1;
}
} else if (prev->code == opcode_select) {
instruction->code = opcode_into;
instruction->op1 = (op_value_t *)apr_pcalloc(pool, sizeof(op_value_t));
Expand Down
17 changes: 14 additions & 3 deletions src/l2h/processor.c
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ static char *proc_cond_op_names[] = {"==", "!=", "~", "!~", ">", "<", ">=", "<="

static const char *proc_type_names[] = {"hash", "file", "dir", "string"};

static const char* hash_value_to_restore = "digest";
static const char *hash_value_to_restore = "digest";

static void (*proc_processors[])(triple_t *) = {
&prproc_on_from, // opcode_from
Expand Down Expand Up @@ -176,7 +176,14 @@ void proc_run(apr_array_header_t *instructions) {

const char *proc_get_cond_op_name(cond_op_t op) { return proc_cond_op_names[op]; }

const char *proc_get_type_name(type_def_t type) { return proc_type_names[type]; }
const char *proc_get_type_name(type_def_t type) {
size_t n = sizeof(proc_type_names) / sizeof(proc_type_names[0]);
if (type >= n) {
return NULL;
}

return proc_type_names[type];
}

void prproc_print_op(triple_t *triple, int i) {
char *type;
Expand Down Expand Up @@ -219,7 +226,11 @@ const char *prproc_to_string(opcode_t code, op_value_t *value, int position) {
if (position) {
return value->string;
}
return proc_get_type_name(value->type);
const char *name = proc_get_type_name(value->type);
if (name == NULL) {
return value->string;
}
return name;
default:
return "";
}
Expand Down

0 comments on commit 7c6ce0a

Please sign in to comment.