12345678910111213141516171819202122232425262728293031323334353637383940 |
- #include <stdio.h>
- #include <string.h>
- #include <assert.h>
- #include "as_tokenizer.h"
- #include "as_parser.h"
- #include "utils.h"
- char *input_buffer =
- "start:\n"
- " add 1\n"
- " sub start\n"
- " div\n"
- "end: eq\n";
- int main(int argc, char** argv) {
- printf("[TEST] assembler parser\n");
- // make a memory buffer to FILE*
- FILE *fp = fmemopen(input_buffer, strlen(input_buffer), "r");
- allocator_t alct = new_allocator();
- token_stream_t ts = new_token_stream(alct, fp);
- prog_t prog = parse_prog(alct, ts);
-
- // compare output
- stmt_t * stmts = prog->stmts->stmts;
- assert(stmts[0]->instr == NULL);
- assert(strcmp("start", stmts[0]->label->name) == 0);
- assert(stmts[1]->label == NULL);
- assert(stmts[1]->instr->op == OP_ADD);
- assert(stmts[1]->instr->arg->ival == 1);
- assert(strcmp("end", stmts[4]->label->name) == 0);
- assert(stmts[4]->instr->op == OP_EQ);
- printf("[PASS] assembler parser\n");
- delete_allocator(alct);
- return 0;
- }
|