builtin: add diag definitions and parser callbacks
This commit is contained in:
@@ -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;
|
||||
}
|
||||
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
|
||||
@@ -5,6 +5,7 @@
|
||||
#include <mie/attribute/attribute.h>
|
||||
#include <mie/interface/interface.h>
|
||||
#include <mie/misc.h>
|
||||
#include <mie/parse/file-span.h>
|
||||
#include <mie/trait/trait.h>
|
||||
#include <mie/vector.h>
|
||||
|
||||
@@ -17,18 +18,51 @@ struct mie_float_type;
|
||||
|
||||
enum mie_builtin_diag {
|
||||
MIE_BUILTIN_E_UNRECOGNISED_TOKEN,
|
||||
MIE_BUILTIN_E_UNEXPECTED_TOKEN,
|
||||
MIE_BUILTIN_E_UNRESOLVED_TYPE,
|
||||
MIE_BUILTIN_E_UNRESOLVED_VALUE,
|
||||
MIE_BUILTIN_E_UNRESOLVED_SUCCESSOR,
|
||||
MIE_BUILTIN_E_UNKNOWN_OP,
|
||||
MIE_BUILTIN_E_OP_REQUIRES_PARENT_SCOPE,
|
||||
MIE_BUILTIN_E_INCORRECT_NUMBER_OF_ARGUMENTS,
|
||||
MIE_BUILTIN_E_INCORRECT_NUMBER_OF_RESULTS,
|
||||
MIE_BUILTIN_E_INCORRECT_NUMBER_OF_TYPES,
|
||||
MIE_BUILTIN_E_INCORRECT_TYPE,
|
||||
MIE_BUILTIN_E_INVALID_TYPE,
|
||||
MIE_BUILTIN_E_NAME_ALREADY_IN_USE,
|
||||
MIE_BUILTIN_E_INTERNAL_ERROR,
|
||||
};
|
||||
|
||||
enum mie_builtin_msg {
|
||||
MIE_BUILTIN_MSG_UNRECOGNISED_TOKEN,
|
||||
MIE_BUILTIN_MSG_UNEXPECTED_TOKEN,
|
||||
MIE_BUILTIN_MSG_UNRESOLVED_VALUE,
|
||||
MIE_BUILTIN_MSG_UNRESOLVED_BUILTIN_TYPE,
|
||||
MIE_BUILTIN_MSG_UNRESOLVED_DIALECT_TYPE,
|
||||
MIE_BUILTIN_MSG_CANNOT_FIND_BLOCK,
|
||||
MIE_BUILTIN_MSG_VALUE_DEFINED_IN_NON_DOMINANT_BLOCK,
|
||||
MIE_BUILTIN_MSG_VALUE_DEFINED_AFTER_USE,
|
||||
MIE_BUILTIN_MSG_VALUE_DEFINED_OUTSIDE_ISOLATED_REGION,
|
||||
MIE_BUILTIN_MSG_VALUE_DEFINED_IN_BLOCK,
|
||||
MIE_BUILTIN_MSG_UNKNOWN_OP,
|
||||
MIE_BUILTIN_MSG_OP_REQUIRES_PARENT_SCOPE,
|
||||
MIE_BUILTIN_MSG_OP_PARENT_SCOPE_EXAMPLE,
|
||||
MIE_BUILTIN_MSG_USE_GENERIC_OP_SYNTAX,
|
||||
MIE_BUILTIN_MSG_OP_HAS_NO_PARSER,
|
||||
MIE_BUILTIN_MSG_DIALECT_INTERNAL_ERROR,
|
||||
MIE_BUILTIN_MSG_COMPILER_INTERNAL_ERROR,
|
||||
MIE_BUILTIN_MSG_OP_INCORRECT_NUMBER_OF_ARGS,
|
||||
MIE_BUILTIN_MSG_OP_INCORRECT_NUMBER_OF_RESULTS,
|
||||
MIE_BUILTIN_MSG_OP_NR_TYPES_DOESNT_MATCH_NR_ARGS,
|
||||
MIE_BUILTIN_MSG_OP_NR_TYPES_DOESNT_MATCH_NR_RESULTS,
|
||||
MIE_BUILTIN_MSG_OP_EXPECTS_X_RESULTS,
|
||||
MIE_BUILTIN_MSG_NR_RESULT_NAME_OUTPUT_MISMATCH,
|
||||
MIE_BUILTIN_MSG_NAME_ALREADY_IN_USE,
|
||||
MIE_BUILTIN_MSG_NAME_ALREADY_USED_HERE,
|
||||
MIE_BUILTIN_MSG_CANNOT_USE_FUNCTION_TYPE_HERE,
|
||||
MIE_BUILTIN_MSG_CANNOT_USE_STORAGE_TYPE_HERE,
|
||||
MIE_BUILTIN_MSG_MUST_USE_FUNCTION_TYPE_HERE,
|
||||
MIE_BUILTIN_MSG_MUST_USE_STORAGE_TYPE_HERE,
|
||||
};
|
||||
|
||||
enum mie_float_width {
|
||||
@@ -36,6 +70,12 @@ enum mie_float_width {
|
||||
MIE_FLOAT_64 = 64,
|
||||
};
|
||||
|
||||
enum mie_memref_rank_type {
|
||||
MIE_MEMREF_RANK_UNKNOWN = 0,
|
||||
MIE_MEMREF_RANK_STATIC,
|
||||
MIE_MEMREF_RANK_TYPE,
|
||||
};
|
||||
|
||||
struct mie_string {
|
||||
struct mie_attribute str_base;
|
||||
char *str_val;
|
||||
@@ -90,6 +130,15 @@ struct mie_symbol_table {
|
||||
struct mie_trait tab_base;
|
||||
};
|
||||
|
||||
struct mie_memref_rank {
|
||||
enum mie_memref_rank_type r_ranktype;
|
||||
struct mie_file_span r_span;
|
||||
union {
|
||||
size_t r_static;
|
||||
const struct mie_type *r_type;
|
||||
};
|
||||
};
|
||||
|
||||
struct mie_int_cache;
|
||||
struct mie_float_cache;
|
||||
struct mie_string_cache;
|
||||
@@ -136,6 +185,8 @@ MIE_API bool mie_float_get_value(const struct mie_attribute *attrib, double *out
|
||||
MIE_API struct mie_type *mie_ctx_get_int_type(struct mie_ctx *ctx, size_t bit_width);
|
||||
MIE_API struct mie_type *mie_ctx_get_float_type(
|
||||
struct mie_ctx *ctx, size_t bit_width);
|
||||
MIE_API struct mie_type *mie_ctx_get_memref_type(
|
||||
struct mie_ctx *ctx, const struct mie_memref_rank *ranks, size_t nr_ranks);
|
||||
|
||||
MIE_API struct mie_attribute *mie_type_attr_create(
|
||||
struct mie_ctx *ctx, const struct mie_type *ty);
|
||||
@@ -143,4 +194,8 @@ MIE_API struct mie_attribute *mie_type_attr_create(
|
||||
MIE_API size_t mie_int_type_get_width(const struct mie_type *type);
|
||||
MIE_API size_t mie_float_type_get_width(const struct mie_type *type);
|
||||
|
||||
MIE_API size_t mie_memref_type_get_nr_ranks(const struct mie_type *type);
|
||||
MIE_API const struct mie_memref_rank *mie_memref_type_get_rank(
|
||||
const struct mie_type *type, size_t i);
|
||||
|
||||
#endif
|
||||
|
||||
Reference in New Issue
Block a user