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
#include <stdio.h>

#include "asm.h"
#include "fmt.h"
#include "fmt_parser.h"
#include "instr.h"
#include "lexer.h"

int
main(int argc, char **argv)
{
    enum
    {
        IN_FMT_TXT,
        FMT_ENCODE_C,
        INSTR_C,
        INSTR_ASM_C,
        REF_FIELDS_CPP,
        REF_FORMAT_CPP,
        REF_INSTR_CPP,
        MNEM_TOKEN,
        ASM_PARSE,
        NUM_IO,
    };

    if (argc != NUM_IO + 1) {
        fprintf(stderr,
                "usage: %s isa.txt fmt_instr_encoding.c instr.c "
                "instr_asm.c refman_fields.cpp refman_format.cpp"
                "refman_instr.cpp mnemonic_tokens.txt parse_functions\n",
                argv[0]);
        return 1;
    }

    FILE *fd[NUM_IO];
    for (size_t i = 0; i < NUM_IO; ++i) {
        fd[i] = fopen(argv[i + 1], i == 0 ? "r" : "w");
        if (!fd[i]) {
            fprintf(stderr, "can not open %s file '%s'\n",
                    i == 0 ? "input" : "output", argv[i + 1]);
            return 1;
        }
    }
    setLexerIn(fd[IN_FMT_TXT], argv[IN_FMT_TXT + 1]);
    parseFmt();
    printFmtInstrEncoding(fd[FMT_ENCODE_C]);
    printRefmanFieldsDescription(fd[REF_FIELDS_CPP]);
    printRefmanFormatDescription(fd[REF_FORMAT_CPP]);
    instrPrintInstrList(fd[INSTR_C]);
    instrPrintAsmNotation(fd[INSTR_ASM_C]);
    instrPrintInstrRefman(fd[REF_INSTR_CPP]);
    asmPrintMnemonicDescription(fd[REF_INSTR_CPP]);

    asmPrintParseFunctions(fd[ASM_PARSE]);
    asmPrintMnemonicList(fd[MNEM_TOKEN]);

    parseFmtDestroy();
    for (size_t i = 0; i < NUM_IO; ++i) {
        fclose(fd[i]);
    }
}