#include #include #include #include #include "../executable.h" #include "../utils/error.h" #include "../utils/source.h" #include "../utils/labellist.h" typedef struct { const char *str; size_t len; size_t cur; int *error_offset; } Context; static void skipIdentifier(Context *ctx) { while(ctx->cur < ctx->len && (isalpha(ctx->str[ctx->cur]) || isdigit(ctx->str[ctx->cur]) || ctx->str[ctx->cur] == '_')) ctx->cur += 1; } static void skipSpaces(Context *ctx) { while(ctx->cur < ctx->len && isspace(ctx->str[ctx->cur])) ctx->cur += 1; } typedef struct { size_t offset; size_t length; } Slice; static bool parseLabelAndOpcode(Context *ctx, bool *no_label, Slice *label, Slice *opcode, Error *error) { assert(ctx != NULL && no_label != NULL && label != NULL && opcode != NULL); // NOTE: This function must start at // the first byte of the label or // opcode. All whitespace must be // consumed by the caller. // Now we expect either a label and an // opcode, or just an opcode // //