summaryrefslogtreecommitdiffhomepage
path: root/mixutils/mixasm_comp.c
blob: 3a31363309f09bd6720218305fdc24bd34585302 (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
/* -*-c-*- -------------- mixasm_comp.c :
 * Implementation of the functions declared in mixasm_comp.h
 * ------------------------------------------------------------------
 * Copyright (C) 2000 jose antonio ortega ruiz <jaortega@acm.org>
 *  
 * 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
 *  
 */

#include <mixlib/mix.h>
#include <stdlib.h>
#include <stdio.h>
#include <mixlib/mix_parser.h>
#include "mixasm_comp.h"

int
mix_asm_compile(const gchar *src, const gchar *out, gboolean use_list,
		const gchar *list, gboolean debug)
{
  int result = EXIT_SUCCESS;
  mix_parser_t *parser;
  mix_parser_err_t error;
  
  if ( (parser = mix_parser_new(src)) == NULL )
    {
      fprintf(stderr, _("*** Unable to open source file %s\n"), src);
      return EXIT_FAILURE;
    }
  if ( mix_parser_compile(parser) == MIX_PERR_OK )
    {
      guint k;
      if ( ( k = mix_parser_warning_count(parser) ) != 0 )
	fprintf(stderr, _("(%d warning(s))\n"), k);
      if ( (error = mix_parser_write_code(parser, out, debug)) != MIX_PERR_OK )
	{
	  fprintf(stderr, _("*** Error writing output code file: %s\n"),
		  mix_parser_err_string(error));
	  result = EXIT_FAILURE;
	}
      else if ( use_list 
		&& (error = mix_parser_write_listing(parser, list)) != 
		MIX_PERR_OK)
	{
	  fprintf(stderr, _("*** Error writing listing file: %s\n"),
		  mix_parser_err_string(error));
	  result = EXIT_FAILURE;
	}
    }
  else
    {
      fprintf(stderr, _("(%d warning(s), %d error(s))\n"), 
	      mix_parser_warning_count(parser), mix_parser_err_count(parser));
      result = EXIT_FAILURE;
    }
  
  mix_parser_delete(parser);
  return result;
}