summaryrefslogtreecommitdiffhomepage
path: root/mixlib/testsuite/mix_parser_t.c
blob: 40083091d4c6a8d1de09f263b039cc9da7be7ec7 (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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
/* -*-c-*- -------------- mix_parser_t.c :
 * Test of mix_parser_t
 * ------------------------------------------------------------------
 * Copyright (C) 2000, 2006 Free Software Foundation, Inc.
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
 *
 */



#include <stdlib.h>
#include <mix_parser.h>

/* Define VERBOSE_TEST if you want to get prints of the test */
/* #define VERBOSE_TEST */
#include "test.h"

static const gchar * const FILES_[] = {MIX_TEST_MIXAL_FILES};

static const size_t FILE_NO_ = sizeof(FILES_)/sizeof(FILES_[0]);


static void
test_code_ (const gchar *name)
{

  mix_code_file_t *code;
  mix_parser_err_t err;

  gchar *real_name = g_strdup_printf ("%s/%s", MIX_TEST_SAMPLES_DIR, name);
  g_print (real_name);
  g_print ("\n");

  mix_parser_t *parser = mix_parser_new (real_name);

  g_assert (parser);

  err = mix_parser_compile (parser);

  if (err != MIX_PERR_OK)
    {
      g_print (mix_parser_err_string (err));
      g_print ("\n");
    }

  g_assert (err == MIX_PERR_OK);

  err = mix_parser_write_code (parser, real_name, FALSE);
  code = mix_code_file_new_read (real_name);
  g_assert (code);

#ifdef VERBOSE_TEST
  g_message ("%s: Version: %d.%d", name, mix_code_file_major_version (code),
             mix_code_file_minor_version (code));

  mix_short_print (mix_code_file_get_start_addr (code), "Start address: ");
  g_print ("\n");

  mix_ins_desc_t ins;
  while (mix_code_file_get_ins (code, &ins))
    {
      mix_ins_t i;
      mix_word_to_ins_uncheck (ins.ins, i);
      mix_short_print (ins.address, "addr: ");
      g_print (" : ");
      mix_ins_print (&i);
      g_print ("\n");
    }
#endif

  mix_parser_delete (parser);
  mix_code_file_delete (code);
  g_free (real_name);
}

int
main(int argc, char **argv)
{
  size_t k;

  INIT_TEST;

  for (k = 0; k < FILE_NO_; ++k)
    test_code_(FILES_[k]);

  return EXIT_SUCCESS;
}