issue #98 work on simple literal expressions

parser
Dibyendu Majumdar 4 years ago
parent 0fe4d1a5b1
commit ed4e86cdae

@ -301,7 +301,7 @@ DECLARE_PTR_LIST(proc_list, struct proc);
#define container_of(ptr, type, member) ((type *)((char *)(ptr)-offsetof(type, member)))
enum opcode { OP_NOP, OP_RET };
enum opcode { op_nop, op_ret, op_loadk};
enum pseudo_type { PSEUDO_LOCAL, PSEUDO_TEMP, PSEUDO_TEMP_INT, PSEUDO_TEMP_ANY, PSEUDO_CONSTANT };
@ -317,11 +317,8 @@ struct pseudo {
/* single instruction */
struct instruction {
unsigned opcode : 8;
union {
struct {
struct pseudo_list* expr_list;
} ret_instruction;
};
struct pseudo_list* operands;
struct pseudo_list* targets;
};
struct edge {

@ -77,7 +77,7 @@ static int compare_constants(const void *a, const void *b) {
static uint32_t hash_constant(const void *c) {
const struct constant *c1 = (const struct constant *)c;
if (c1->type == RAVI_TNUMINT)
return c1->i;
return (int)c1->i;
else if (c1->type == RAVI_TNUMFLT)
return (int)c1->n; // FIXME maybe use Lua's hash gen
else
@ -186,7 +186,11 @@ static struct pseudo *linearize_literal(struct proc *proc, struct ast_node *expr
assert(expr->type == AST_LITERAL_EXPR);
if (expr->literal_expr.type.type_code == RAVI_TNUMFLT || expr->literal_expr.type.type_code == RAVI_TNUMINT ||
expr->literal_expr.type.type_code == RAVI_TSTRING) {
return allocate_constant_pseudo(proc, allocate_constant(proc, expr));
struct pseudo *pseudo = allocate_constant_pseudo(proc, allocate_constant(proc, expr));
struct instruction* insn = alloc_instruction(proc, op_loadk);
ptrlist_add((struct ptr_list**) &insn->operands, pseudo, &proc->linearizer->ptrlist_allocator);
ptrlist_add((struct ptr_list**) &proc->current_bb->insns, insn, &proc->linearizer->ptrlist_allocator);
return pseudo;
}
else {
abort();
@ -220,8 +224,9 @@ static void linearize_expr_list(struct proc *proc, struct ast_node_list *expr_li
static void linearize_return(struct proc *proc, struct ast_node *node) {
assert(node->type == AST_RETURN_STMT);
struct instruction *insn = alloc_instruction(proc, OP_RET);
linearize_expr_list(proc, node->return_stmt.expr_list, insn, &insn->ret_instruction.expr_list);
struct instruction *insn = alloc_instruction(proc, op_ret);
linearize_expr_list(proc, node->return_stmt.expr_list, insn, &insn->operands);
ptrlist_add((struct ptr_list**) & proc->current_bb->insns, insn, &proc->linearizer->ptrlist_allocator);
}
static void linearize_statement(struct proc *proc, struct ast_node *node) {

Loading…
Cancel
Save