Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add MIR_scan_string_s #341

Open
wants to merge 3 commits into
base: v0_master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion MIR.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
* To start work with MIR program, you should first call API function `MIR_init`
* API function `MIR_finish (MIR_context_t ctx)` should be called last. It frees all internal data used to work with MIR program and all IR (insns, functions, items, and modules) created in this context
* API function `MIR_output (MIR_context_t ctx, FILE *f)` outputs MIR textual representation of the program into given file
* API function `MIR_scan_string (MIR_context_t ctx, const char *str)` reads textual MIR representation given by a string
* API function `MIR_scan_string_s (MIR_context_t ctx, const char *str, size_t str_len)` reads textual MIR representation given by a string
* API functions `MIR_write (MIR_context_t ctx, FILE *f)` and
`MIR_read (MIR_context_t ctx, FILE *f)` outputs and reads
**binary MIR representation** to/from given file. There are also
Expand Down
10 changes: 9 additions & 1 deletion mir.c
Original file line number Diff line number Diff line change
Expand Up @@ -5267,6 +5267,7 @@ struct scan_ctx {
HTAB (insn_name_t) * insn_name_tab;
const char *input_string;
size_t input_string_char_num;
size_t input_string_char_limit;
VARR (label_name_t) * label_names;
HTAB (label_desc_t) * label_desc_tab;
};
Expand All @@ -5280,6 +5281,7 @@ struct scan_ctx {
#define insn_name_tab ctx->scan_ctx->insn_name_tab
#define input_string ctx->scan_ctx->input_string
#define input_string_char_num ctx->scan_ctx->input_string_char_num
#define input_string_char_limit ctx->scan_ctx->input_string_char_limit
#define label_names ctx->scan_ctx->label_names
#define label_desc_tab ctx->scan_ctx->label_desc_tab

Expand Down Expand Up @@ -5457,8 +5459,8 @@ static void scan_string (MIR_context_t ctx, token_t *t, int c, int get_char (MIR
}

static int get_string_char (MIR_context_t ctx) {
if (input_string_char_num >= input_string_char_limit) return EOF;
int ch = input_string[input_string_char_num];

if (ch == '\0') return EOF;
input_string_char_num++;
if (ch == '\n') curr_lno++;
Expand Down Expand Up @@ -5640,7 +5642,12 @@ static MIR_type_t str2type (const char *type_name) {

*/

void MIR_scan_string_s (MIR_context_t ctx, const char *str, size_t str_len);
void MIR_scan_string (MIR_context_t ctx, const char *str) {
MIR_scan_string_s(ctx, str, SIZE_MAX);
}

void MIR_scan_string_s (MIR_context_t ctx, const char *str, size_t str_len) {
token_t t;
const char *name;
MIR_module_t module = NULL;
Expand All @@ -5660,6 +5667,7 @@ void MIR_scan_string (MIR_context_t ctx, const char *str) {
curr_lno = 1;
input_string = str;
input_string_char_num = 0;
input_string_char_limit = str_len;
t.code = TC_NL;
for (;;) {
if (setjmp (error_jmp_buf)) {
Expand Down
2 changes: 2 additions & 0 deletions mir.h
Original file line number Diff line number Diff line change
Expand Up @@ -581,7 +581,9 @@ extern void MIR_read_with_func (MIR_context_t ctx, int (*const reader_func) (MIR
#endif

#if !MIR_NO_SCAN
/** deprecated: use MIR_scan_string_s */
extern void MIR_scan_string (MIR_context_t ctx, const char *str);
extern void MIR_scan_string_s (MIR_context_t ctx, const char *str, size_t str_len);
#endif

extern MIR_item_t MIR_get_global_item (MIR_context_t ctx, const char *name);
Expand Down