summaryrefslogtreecommitdiff
path: root/core/atas.c
blob: d650a55f327fe5225981a35c73143ab9a64b162b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
/*
 * Copyright (c) 2026, Apollo Telephone Laboratories.
 * Provided under the BSD-3 clause.
 */

#include <stdio.h>
#include <unistd.h>
#include <atas/state.h>
#include <atas/parser.h>

/*
 * Display help options
 */
static void
help(void)
{
    printf("-- AT ISA assembler --\n");
    printf("usage: ./atas [flags] [input file]\n");
    printf("[-h]    Display this help menu\n");
}

/*
 * Begin assembling a specified input file
 *
 * @in_file:   Path to input file to assemble
 */
static void
atas_assemble(const char *in_file)
{
    struct atas_state state;
    int error;

    if (in_file == NULL) {
        return;
    }

    error = atas_state_init(in_file, &state);
    if (error < 0) {
        perror("atas_state_init");
        return;
    }

    error = atas_parse(&state);
    if (error < 0) {
        printf("failure occured in %s\n", in_file);
        atas_state_destroy(&state);
        return;
    }

    atas_state_destroy(&state);
}

int
main(int argc, char **argv)
{
    const char *in_path;
    int opt;

    if (argc < 2) {
        printf("fatal: too few arguments\n");
        return -1;
    }

    while ((opt = getopt(argc, argv, "hv")) != -1) {
        switch (opt) {
        case 'h':
            help();
            return 0;
        }
    }

    if (optind == argc) {
        printf("fatal: expected input file\n");
        return -1;
    }

    in_path = argv[optind];
    atas_assemble(in_path);
    return 0;
}