123456789101112131415161718192021222324252627282930313233343536373839404142434445 |
- #include <stdio.h>
- #include <string.h>
- #include <assert.h>
- #include "as_tokenizer.h"
- #include "as_parser.h"
- #include "as_analyzer.h"
- #include "utils.h"
- char *input_buffer =
- "start:\n"
- " imm 1\n"
- "mid: add\n"
- " call start\n"
- " sub\n"
- ".insec: add\n"
- " div\n"
- "end: eq\n";
- int main(int argc, char** argv) {
- struct result result;
- printf("[TEST] assembler analyzer\n");
- // make a memory buffer to FILE*
- FILE *fp = fmemopen(input_buffer, strlen(input_buffer), "r");
- struct allocator * alct = new_allocator();
- struct token_stream * ts = new_token_stream(alct, fp);
- result = parse_prog(alct, ts);
- assert(result.errmsg == NULL);
- struct prog* prog = result.value;
- struct sym_table sym_table = analyze_prog(alct, prog);
- assert(strcmp(sym_table.buf[0].name, "start") == 0);
- assert(strcmp(sym_table.buf[1].name, "mid") == 0);
- assert(strcmp(sym_table.buf[2].name, "mid.insec") == 0);
- assert(strcmp(sym_table.buf[3].name, "end") == 0);
- assert(sym_table.buf[0].offset == 0);
- assert(sym_table.buf[1].offset == 9);
- assert(sym_table.buf[2].offset == 21);
- assert(sym_table.buf[3].offset == 23);
- printf("[PASS] assembler analyzer\n");
- delete_allocator(alct);
- return 0;
- }
|