Refactor mcg.h as it's getting a bit big; keep track of register variables.

This commit is contained in:
David Given 2016-10-02 00:30:33 +02:00
parent 06059233da
commit b298c27c63
4 changed files with 31 additions and 14 deletions

View file

@ -17,12 +17,14 @@
#include "em_flag.h"
#include "em_ptyp.h"
#include "array.h"
#include "imap.h"
#include "pmap.h"
#include "diagnostics.h"
#include "astring.h"
#include "ir.h"
#include "mcgg.h"
#include "hop.h"
#include "procedure.h"
extern char em_pseu[][4];
extern char em_mnem[][4];
@ -71,14 +73,6 @@ struct em
} u;
};
struct procedure
{
const char* name;
struct basicblock* root_bb;
size_t nlocals;
ARRAYOF(struct basicblock) blocks;
};
struct basicblock
{
const char* name;
@ -118,7 +112,7 @@ extern void bb_print(char k, struct basicblock* block);
extern void tb_filestart(void);
extern void tb_fileend(void);
extern void tb_procedure(struct procedure* proc);
extern void tb_regvar(arith offset, int size, int type, int priority);
extern void tb_regvar(struct procedure* proc, arith offset, int size, int type, int priority);
extern void pass_convert_stack_ops(struct procedure* proc);
extern void pass_remove_dead_blocks(struct procedure* proc);
@ -127,8 +121,6 @@ extern void pass_instruction_selector(struct procedure* proc);
extern void pass_promote_float_ops(struct procedure* proc);
extern void pass_group_irs(struct procedure* proc);
extern void procedure_compile(struct procedure* proc);
#endif
/* vim: set sw=4 ts=4 expandtab : */

View file

@ -338,7 +338,7 @@ static void parse_mes(void)
int size = mes_get_cst();
int type = mes_get_cst();
int priority = mes_get_cst();
tb_regvar(offset, size, type, priority);
tb_regvar(current_proc, offset, size, type, priority);
}
break;
}

View file

@ -0,0 +1,22 @@
#ifndef PROCEDURE_H
#define PROCEDURE_H
struct local
{
bool is_register;
};
struct procedure
{
const char* name;
struct basicblock* root_bb;
size_t nlocals;
ARRAYOF(struct basicblock) blocks;
IMAPOF(struct local) locals;
};
extern void procedure_compile(struct procedure* proc);
#endif
/* vim: set sw=4 ts=4 expandtab : */

View file

@ -107,9 +107,12 @@ void tb_fileend(void)
{
}
void tb_regvar(arith offset, int size, int type, int priority)
void tb_regvar(struct procedure* procedure, arith offset, int size, int type, int priority)
{
/* ignored */
struct local* local = calloc(1, sizeof(*local));
local->size = size;
local->is_register = true;
imap_put(&procedure->locals, offset, local);
}
static struct ir* address_of_external(const char* label, arith offset)