builtin: add diag definitions and parser callbacks

This commit is contained in:
2026-03-16 11:58:56 +00:00
parent 000a9c2671
commit fe1e7d81c4
6 changed files with 135 additions and 4 deletions

View File

@@ -59,7 +59,7 @@ static enum mie_status parse(
}
const struct mie_type *type = NULL;
if (!mie_parser_parse_type(ctx, &type)) {
if (!mie_parser_parse_type(ctx, NULL, &type, NULL)) {
return MIE_ERR_BAD_SYNTAX;
}

View File

@@ -64,7 +64,7 @@ static enum mie_status parse(
if (!mie_parser_parse_symbol(ctx, MIE_SYM_COLON)) {
width = 64;
} else if (!mie_parser_parse_type(ctx, &type)) {
} else if (!mie_parser_parse_type(ctx, NULL, &type, NULL)) {
return false;
} else {
width = mie_int_type_get_width(type);

View File

@@ -53,7 +53,7 @@ static enum mie_status parse(
const struct mie_type *type = NULL;
if (!mie_parser_parse_type(ctx, &type)) {
if (!mie_parser_parse_type(ctx, NULL, &type, NULL)) {
free(ty);
return MIE_ERR_BAD_FORMAT;
}

View File

@@ -8,13 +8,36 @@
MIE_DIAG_CLASS_LIST_BEGIN(mie_builtin_diag)
MIE_DIAG_CLASS(UNRECOGNISED_TOKEN, ERROR, "Unrecognised token")
MIE_DIAG_CLASS(UNEXPECTED_TOKEN, ERROR, "Unexpected token")
MIE_DIAG_CLASS(UNRESOLVED_TYPE, ERROR, "Unresolved type")
MIE_DIAG_CLASS(UNRESOLVED_VALUE, ERROR, "Unresolved value")
MIE_DIAG_CLASS(UNRESOLVED_SUCCESSOR, ERROR, "Unresolved successor")
MIE_DIAG_CLASS(UNKNOWN_OP, ERROR, "Unknown op")
MIE_DIAG_CLASS(
OP_REQUIRES_PARENT_SCOPE, ERROR, "Op requires parent scope")
MIE_DIAG_CLASS(
INCORRECT_NUMBER_OF_RESULTS, ERROR,
"Incorrect number of results")
MIE_DIAG_CLASS(
INCORRECT_NUMBER_OF_ARGUMENTS, ERROR,
"Incorrect number of arguments")
MIE_DIAG_CLASS(
INCORRECT_NUMBER_OF_TYPES, ERROR, "Incorrect number of types")
MIE_DIAG_CLASS(INCORRECT_TYPE, ERROR, "Incorrect type")
MIE_DIAG_CLASS(INVALID_TYPE, ERROR, "Invalid type")
MIE_DIAG_CLASS(NAME_ALREADY_IN_USE, ERROR, "Name already in use")
MIE_DIAG_CLASS(INTERNAL_ERROR, ERROR, "Internal error")
MIE_DIAG_CLASS_LIST_END(mie_builtin_diag)
MIE_DIAG_MSG_LIST_BEGIN(mie_builtin_msg)
MIE_DIAG_MSG(UNRECOGNISED_TOKEN, "encountered an unrecognised token.")
MIE_DIAG_MSG(UNRESOLVED_VALUE, "cannot resolve this value reference.")
MIE_DIAG_MSG(
UNRESOLVED_BUILTIN_TYPE,
"cannot resolve this builtin type reference.")
MIE_DIAG_MSG(
UNRESOLVED_DIALECT_TYPE,
"cannot resolve this dialect type reference.")
MIE_DIAG_MSG(
CANNOT_FIND_BLOCK,
"cannot find a block with this name in this region.")
@@ -33,4 +56,43 @@ MIE_DIAG_MSG_LIST_BEGIN(mie_builtin_msg)
"outside of this region.")
MIE_DIAG_MSG(
VALUE_DEFINED_IN_BLOCK, "the value is defined in this block.")
MIE_DIAG_MSG(UNKNOWN_OP, "encountered an unknown operation.")
MIE_DIAG_MSG(
OP_REQUIRES_PARENT_SCOPE,
"this operation requires a parent scope.")
MIE_DIAG_MSG(
OP_PARENT_SCOPE_EXAMPLE,
"operations that require a parent scope cannot be used as a "
"top-level operation. try wrapping this operation in a "
"[blue]module[reset].")
MIE_DIAG_MSG(
USE_GENERIC_OP_SYNTAX,
"if this op belongs to an unknown dialect, you can use generic "
"op syntax to represent it.")
MIE_DIAG_MSG(
OP_HAS_NO_PARSER,
"this operation has no associated parser functionality.")
MIE_DIAG_MSG(
DIALECT_INTERNAL_ERROR,
"this error is caused by an internal problem with the relevant "
"dialect. please report the issue to the dialect vendor.")
MIE_DIAG_MSG(
COMPILER_INTERNAL_ERROR,
"this error is caused by an internal compiler issue. please "
"report the issue to the compiler vendor.")
MIE_DIAG_MSG(
NR_RESULT_NAME_OUTPUT_MISMATCH,
"the number of [red]output value names[reset] does not match "
"the number of results.")
MIE_DIAG_MSG(
OP_INCORRECT_NUMBER_OF_ARGS,
"this operation does not have the correct number of arguments.")
MIE_DIAG_MSG(
OP_NR_TYPES_DOESNT_MATCH_NR_ARGS,
"the number of types specified does not match the number of "
"arguments.")
MIE_DIAG_MSG(
OP_NR_TYPES_DOESNT_MATCH_NR_RESULTS,
"the number of types specified does not match the number of "
"results.")
MIE_DIAG_MSG_LIST_END(mie_builtin_msg)

View File

@@ -4,6 +4,7 @@
#include <mie/ir/op.h>
#include <mie/ir/region.h>
#include <mie/macros.h>
#include <mie/parse/parser.h>
#include <mie/print/printer.h>
static enum mie_status print(struct mie_printer *out, const struct mie_op *op)
@@ -18,8 +19,21 @@ static enum mie_status print(struct mie_printer *out, const struct mie_op *op)
return MIE_SUCCESS;
}
static enum mie_status parse(struct mie_parser *parser, struct mie_op *out)
static enum mie_status parse(
struct mie_parser *parser, struct mie_parser_scope *scope,
struct mie_op *out)
{
struct mie_region *region = mie_op_add_region(out);
if (mie_parser_peek_symbol(parser) != MIE_SYM_LEFT_BRACE) {
mie_parser_report_unexpected_token_s(
parser, "region", "module body");
return MIE_ERR_BAD_SYNTAX;
}
if (!mie_parser_parse_region(parser, out, region, NULL)) {
return MIE_ERR_BAD_SYNTAX;
}
return MIE_SUCCESS;
}