-
Notifications
You must be signed in to change notification settings - Fork 1
/
cirm.h
49 lines (44 loc) · 1.52 KB
/
cirm.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
#ifndef CIRM_H
#define CIRM_H
#include <stdlib.h>
#include "cir.h"
static CirVarId
CirM_varid(CirCodeId codeId)
{
if (CirCode_getFirstStmt(codeId))
cir_fatal("CirM_varid: code is non-empty");
if (CirCode_getNumVars(codeId))
cir_fatal("CirM_varid: code owns vars");
const CirValue *value = CirCode_getValue(codeId);
if (!value)
cir_fatal("CirM_varid: code has no value");
return CirValue_getVar(value);
}
static CirCodeId
CirM_type(CirCodeId codeId)
{
const CirType *dummyVar;
if (CirCode_getFirstStmt(codeId))
cir_fatal("CirM_type: code is non-empty");
if (CirCode_getNumVars(codeId))
cir_fatal("CirM_type: code owns vars");
const CirValue *value = CirCode_getValue(codeId);
if (!value)
cir_fatal("CirM_type: code has no value");
const CirType *type = CirValue_getTypeValue(value);
const CirType *typeType = CirVar_getType(@CirM_varid(dummyVar));
return CirCode_ofExpr(CirValue_withCastType(CirValue_ofU64(CIR_IULONG, (uint64_t)type), typeType));
}
static CirCodeId
CirM_value(CirCodeId codeId)
{
if (CirCode_getFirstStmt(codeId))
cir_fatal("CirM_value: code is non-empty");
if (CirCode_getNumVars(codeId))
cir_fatal("CirM_value: code owns vars");
const CirValue *value = CirCode_getValue(codeId);
if (!value)
cir_fatal("CirM_value: code has no value");
return CirCode_ofExpr(CirValue_withCastType(CirValue_ofU64(CIR_IULONG, (uint64_t)value), @CirM_type(__typeval(const CirValue *))));
}
#endif // CIRM_H