summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTing-Wei Lan <lantw44@gmail.com>2016-01-18 16:16:17 +0800
committerTing-Wei Lan <lantw44@gmail.com>2016-01-18 16:21:57 +0800
commite4d4fe5e44579536f3d060ad841636928d0e0bc6 (patch)
tree9e69d102a57a6c7a5fba585f013e1cfb6caf6cbd
parent266d16765321ed3424cbc9b355dbe2c0f56b24e2 (diff)
downloadcompiler2015-e4d4fe5e44579536f3d060ad841636928d0e0bc6.tar
compiler2015-e4d4fe5e44579536f3d060ad841636928d0e0bc6.tar.gz
compiler2015-e4d4fe5e44579536f3d060ad841636928d0e0bc6.tar.bz2
compiler2015-e4d4fe5e44579536f3d060ad841636928d0e0bc6.tar.lz
compiler2015-e4d4fe5e44579536f3d060ad841636928d0e0bc6.tar.xz
compiler2015-e4d4fe5e44579536f3d060ad841636928d0e0bc6.tar.zst
compiler2015-e4d4fe5e44579536f3d060ad841636928d0e0bc6.zip
Use bool to store lock information of a register
There are only two state: locked and unlocked.
-rw-r--r--src/register.c16
-rw-r--r--src/register.h9
2 files changed, 13 insertions, 12 deletions
diff --git a/src/register.c b/src/register.c
index 00280c0..3ee36a5 100644
--- a/src/register.c
+++ b/src/register.c
@@ -24,7 +24,7 @@ CcmmcRegPool *ccmmc_register_init(FILE *asm_output)
for (int i = 0; i < pool->num; i++) {
pool->list[i] = malloc(sizeof(CcmmcReg));
pool->list[i]->tmp = NULL;
- pool->list[i]->lock = 0;
+ pool->list[i]->lock = false;
pool->list[i]->name = reg_name[i];
}
pool->spill = malloc(sizeof(CcmmcTmp*) * SPILL_MAX);
@@ -45,7 +45,7 @@ CcmmcTmp *ccmmc_register_alloc(CcmmcRegPool *pool, uint64_t *offset)
// reg
tmp->reg->tmp = tmp;
- tmp->reg->lock = 0;
+ tmp->reg->lock = false;
// pool
pool->top++;
@@ -76,9 +76,9 @@ const char *ccmmc_register_lock(CcmmcRegPool *pool, CcmmcTmp *tmp)
const char *reg = NULL;
if (pool->lock_cnt < pool->lock_max) {
if (tmp->reg !=NULL) {
- if (tmp->reg->lock == 0) {
+ if (!tmp->reg->lock) {
// reg
- tmp->reg->lock = 1;
+ tmp->reg->lock = true;
// pool
pool->lock_cnt++;
@@ -88,7 +88,7 @@ const char *ccmmc_register_lock(CcmmcRegPool *pool, CcmmcTmp *tmp)
else {
// find a unlocked reg
int i, j;
- for (i = 0; i < pool->num && pool->list[i]->lock == 1; i++);
+ for (i = 0; i < pool->num && pool->list[i]->lock; i++);
assert(i < pool->num); //must found
// gen code to swap the tmp in the register and the tmp on the stack
@@ -119,7 +119,7 @@ const char *ccmmc_register_lock(CcmmcRegPool *pool, CcmmcTmp *tmp)
// register
tmp->reg->tmp = tmp;
- tmp->reg->lock = 1;
+ tmp->reg->lock = true;
// pool
pool->lock_cnt++;
@@ -132,9 +132,9 @@ const char *ccmmc_register_lock(CcmmcRegPool *pool, CcmmcTmp *tmp)
void ccmmc_register_unlock(CcmmcRegPool *pool, CcmmcTmp *tmp)
{
- if (tmp->reg != NULL && tmp->reg->lock == 1) {
+ if (tmp->reg != NULL && tmp->reg->lock) {
// reg
- tmp->reg->lock = 0;
+ tmp->reg->lock = false;
// pool
pool->lock_cnt--;
diff --git a/src/register.h b/src/register.h
index e218b66..1172714 100644
--- a/src/register.h
+++ b/src/register.h
@@ -1,9 +1,10 @@
-#include <inttypes.h>
-#include <stdio.h>
-
#ifndef CCMMC_HEADER_REGISTER_H
#define CCMMC_HEADER_REGISTER_H
+#include <inttypes.h>
+#include <stdbool.h>
+#include <stdio.h>
+
typedef struct CcmmcRegStruct CcmmcReg;
typedef struct CcmmcTmpStruct {
CcmmcReg *reg;
@@ -12,7 +13,7 @@ typedef struct CcmmcTmpStruct {
typedef struct CcmmcRegStruct {
CcmmcTmp *tmp;
- int lock;
+ bool lock;
const char *name;
} CcmmcReg;