made struct registration single pass
This commit is contained in:
parent
02dea8d3b8
commit
8f19852746
2 changed files with 8 additions and 13 deletions
20
sema.c
20
sema.c
|
|
@ -2,7 +2,6 @@
|
||||||
#include "sema.h"
|
#include "sema.h"
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <stdbool.h>
|
|
||||||
|
|
||||||
typedef struct _res_node {
|
typedef struct _res_node {
|
||||||
struct _res_node **in;
|
struct _res_node **in;
|
||||||
|
|
@ -140,23 +139,16 @@ static void register_struct(sema *s, char *name, type *t)
|
||||||
{
|
{
|
||||||
usize alignment = 0;
|
usize alignment = 0;
|
||||||
member *m = t->data.structure.members;
|
member *m = t->data.structure.members;
|
||||||
while (m) {
|
|
||||||
type *m_type = get_type(s, m->type);
|
|
||||||
if (alignment < m_type->alignment) {
|
|
||||||
alignment = m_type->alignment;
|
|
||||||
}
|
|
||||||
|
|
||||||
m = m->next;
|
|
||||||
}
|
|
||||||
|
|
||||||
t->alignment = alignment;
|
|
||||||
|
|
||||||
m = t->data.structure.members;
|
|
||||||
|
|
||||||
usize offset = 0;
|
usize offset = 0;
|
||||||
type *m_type = NULL;
|
type *m_type = NULL;
|
||||||
while (m) {
|
while (m) {
|
||||||
m_type = get_type(s, m->type);
|
m_type = get_type(s, m->type);
|
||||||
|
|
||||||
|
if (alignment < m_type->alignment) {
|
||||||
|
alignment = m_type->alignment;
|
||||||
|
}
|
||||||
|
|
||||||
usize padding = (m_type->alignment - (offset % m_type->alignment)) % m_type->alignment;
|
usize padding = (m_type->alignment - (offset % m_type->alignment)) % m_type->alignment;
|
||||||
offset += padding;
|
offset += padding;
|
||||||
m->offset = offset;
|
m->offset = offset;
|
||||||
|
|
@ -165,6 +157,8 @@ static void register_struct(sema *s, char *name, type *t)
|
||||||
m = m->next;
|
m = m->next;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
t->alignment = alignment;
|
||||||
|
|
||||||
if (t->alignment > 0) {
|
if (t->alignment > 0) {
|
||||||
usize trailing_padding = (t->alignment - (offset % t->alignment)) % t->alignment;
|
usize trailing_padding = (t->alignment - (offset % t->alignment)) % t->alignment;
|
||||||
offset += trailing_padding;
|
offset += trailing_padding;
|
||||||
|
|
|
||||||
1
sema.h
1
sema.h
|
|
@ -1,6 +1,7 @@
|
||||||
#ifndef SEMA_H
|
#ifndef SEMA_H
|
||||||
#define SEMA_H
|
#define SEMA_H
|
||||||
|
|
||||||
|
#include <stdbool.h>
|
||||||
#include "parser.h"
|
#include "parser.h"
|
||||||
#include "stb_ds.h"
|
#include "stb_ds.h"
|
||||||
#include "utils.h"
|
#include "utils.h"
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue