summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
-rw-r--r--src/ast/ast.c12
-rw-r--r--src/ast/ast.h1
-rw-r--r--src/ast/ast_t.h7
-rw-r--r--src/ast/entity.c2
-rw-r--r--src/ast/entity.h1
-rw-r--r--src/ast/entity_t.h7
-rw-r--r--src/ast/walk.c1
-rw-r--r--src/firm/ast2firm.c2
-rw-r--r--src/parser/parser.c15
9 files changed, 31 insertions, 17 deletions
diff --git a/src/ast/ast.c b/src/ast/ast.c
index 2c4e1c3..d4e1f65 100644
--- a/src/ast/ast.c
+++ b/src/ast/ast.c
@@ -1035,13 +1035,18 @@ static void print_asm_clobbers(asm_clobber_t const *const clobbers)
}
}
-static void print_asm_labels(asm_label_t const *const labels)
+static void print_asm_labels(entity_t const *const labels)
{
print_string(" :");
separator_t sep = { " ", ", " };
- for (asm_label_t const *i = labels; i; i = i->next) {
+ for (entity_t const *i = labels; i; i = i->base.next) {
+ if (i->kind != ENTITY_ASM_LABEL) {
+ print_string("invalid");
+ continue;
+ }
+
print_string(sep_next(&sep));
- print_string(i->label->base.symbol->string);
+ print_string(i->base.symbol->string);
}
}
@@ -1386,6 +1391,7 @@ void print_entity(const entity_t *entity)
print_char(';');
return;
case ENTITY_ASM_ARGUMENT:
+ case ENTITY_ASM_LABEL:
print_string(entity->base.symbol->string);
return;
case ENTITY_LABEL:
diff --git a/src/ast/ast.h b/src/ast/ast.h
index 44f5e4c..f0e3d31 100644
--- a/src/ast/ast.h
+++ b/src/ast/ast.h
@@ -58,7 +58,6 @@ typedef struct case_label_statement_t case_label_statement_t;
typedef struct do_while_statement_t do_while_statement_t;
typedef struct for_statement_t for_statement_t;
typedef struct asm_clobber_t asm_clobber_t;
-typedef struct asm_label_t asm_label_t;
typedef struct asm_statement_t asm_statement_t;
typedef struct ms_try_statement_t ms_try_statement_t;
typedef struct leave_statement_t leave_statement_t;
diff --git a/src/ast/ast_t.h b/src/ast/ast_t.h
index 95e1e28..ce4201a 100644
--- a/src/ast/ast_t.h
+++ b/src/ast/ast_t.h
@@ -591,11 +591,6 @@ struct asm_clobber_t {
asm_clobber_t *next;
};
-struct asm_label_t {
- label_t *label;
- asm_label_t *next;
-};
-
struct asm_statement_t {
statement_base_t base;
position_t textpos;
@@ -605,7 +600,7 @@ struct asm_statement_t {
entity_t *inputs; /**< list of asm_argument_t entities */
entity_t *outputs; /**< list of asm_argument_t entities */
asm_clobber_t *clobbers;
- asm_label_t *labels;
+ entity_t *labels;
bool has_arguments : 1;
bool is_volatile : 1;
};
diff --git a/src/ast/entity.c b/src/ast/entity.c
index 380c602..16dd112 100644
--- a/src/ast/entity.c
+++ b/src/ast/entity.c
@@ -28,6 +28,7 @@ const char *get_entity_kind_name(entity_kind_t kind)
case ENTITY_TYPEDEF: return "typedef";
case ENTITY_NAMESPACE: return "namespace";
case ENTITY_ASM_ARGUMENT: return "asm argument";
+ case ENTITY_ASM_LABEL: return "asm label";
}
panic("invalid entity kind");
@@ -54,6 +55,7 @@ static size_t get_entity_struct_size(entity_kind_t kind)
[ENTITY_LOCAL_LABEL] = sizeof(label_t),
[ENTITY_NAMESPACE] = sizeof(namespace_t),
[ENTITY_ASM_ARGUMENT] = sizeof(asm_argument_t),
+ [ENTITY_ASM_LABEL] = sizeof(asm_label_t),
};
assert(kind < ARRAY_SIZE(sizes));
assert(sizes[kind] != 0);
diff --git a/src/ast/entity.h b/src/ast/entity.h
index 3a682d1..a4dd424 100644
--- a/src/ast/entity.h
+++ b/src/ast/entity.h
@@ -6,6 +6,7 @@
#define ENTITY_H
typedef struct asm_argument_t asm_argument_t;
+typedef struct asm_label_t asm_label_t;
typedef struct asm_operand_t asm_operand_t;
typedef struct compound_member_t compound_member_t;
typedef struct compound_t compound_t;
diff --git a/src/ast/entity_t.h b/src/ast/entity_t.h
index 36434b1..1f259b6 100644
--- a/src/ast/entity_t.h
+++ b/src/ast/entity_t.h
@@ -30,6 +30,7 @@ typedef enum {
ENTITY_LOCAL_LABEL,
ENTITY_NAMESPACE,
ENTITY_ASM_ARGUMENT,
+ ENTITY_ASM_LABEL,
} entity_kind_t;
typedef enum entity_namespace_t {
@@ -250,6 +251,11 @@ struct asm_argument_t {
bool indirect_write :1;/**< argument is address which is written */
};
+struct asm_label_t {
+ asm_operand_t base;
+ label_t *label;
+};
+
union entity_t {
ENUMBF(entity_kind_t) kind : 8;
entity_base_t base;
@@ -263,6 +269,7 @@ union entity_t {
function_t function;
compound_member_t compound_member;
asm_argument_t asm_argument;
+ asm_label_t asm_label;
asm_operand_t asm_operand;
};
diff --git a/src/ast/walk.c b/src/ast/walk.c
index 5320a8c..c440941 100644
--- a/src/ast/walk.c
+++ b/src/ast/walk.c
@@ -256,6 +256,7 @@ static void walk_entity(entity_t *entity, const walk_env_t *const env)
walk_entity(entry, env);
}
return;
+ case ENTITY_ASM_LABEL:
case ENTITY_LABEL:
case ENTITY_LOCAL_LABEL:
return;
diff --git a/src/firm/ast2firm.c b/src/firm/ast2firm.c
index e750915..dfe7de7 100644
--- a/src/firm/ast2firm.c
+++ b/src/firm/ast2firm.c
@@ -581,6 +581,7 @@ static bool declaration_is_definition(const entity_t *entity)
case ENTITY_COMPOUND_MEMBER:
return false;
case ENTITY_ASM_ARGUMENT:
+ case ENTITY_ASM_LABEL:
case ENTITY_CLASS:
case ENTITY_ENUM:
case ENTITY_ENUM_VALUE:
@@ -4959,6 +4960,7 @@ static ir_entity *get_irentity(entity_t *entity)
case ENTITY_FUNCTION: return entity->function.irentity;
case ENTITY_COMPOUND_MEMBER: return entity->compound_member.entity;
case ENTITY_ASM_ARGUMENT:
+ case ENTITY_ASM_LABEL:
case ENTITY_CLASS:
case ENTITY_ENUM:
case ENTITY_ENUM_VALUE:
diff --git a/src/parser/parser.c b/src/parser/parser.c
index f060019..ddc12b7 100644
--- a/src/parser/parser.c
+++ b/src/parser/parser.c
@@ -4747,8 +4747,8 @@ static void check_reachable(statement_t *const stmt)
goto fallthrough;
case STATEMENT_ASM:
- for (asm_label_t const *i = stmt->asms.labels; i; i = i->next) {
- statement_t *const tgt = i->label->statement;
+ for (entity_t const *i = stmt->asms.labels; i; i = i->base.next) {
+ statement_t *const tgt = i->asm_label.label->statement;
if (tgt)
check_reachable(tgt);
}
@@ -9195,20 +9195,21 @@ static void use_label(label_t *const label)
label->used = true;
}
-static void parse_asm_labels(asm_label_t **anchor)
+static void parse_asm_labels(entity_t **anchor)
{
if (peek(T_IDENTIFIER)) {
add_anchor_token(',');
do {
- label_t *const label = get_label("'asm goto' label");
+ position_t const pos = *HERE;
+ label_t *const label = get_label("'asm goto' label");
if (label) {
use_label(label);
- asm_label_t *const asm_label = allocate_ast_zero(sizeof(*asm_label));
- asm_label->label = label;
+ entity_t *const asm_label = allocate_entity_zero(ENTITY_ASM_LABEL, NAMESPACE_ASM_ARGUMENT, label->base.symbol, &pos);
+ asm_label->asm_label.label = label;
*anchor = asm_label;
- anchor = &asm_label->next;
+ anchor = &asm_label->base.next;
}
} while (accept(','));
rem_anchor_token(',');