summaryrefslogtreecommitdiffhomepage
path: root/ir/be/beemitter.c
blob: 5e22da28111d27ba1548d6d42667c7ea26e9d444 (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
/*
 * This file is part of libFirm.
 * Copyright (C) 2012 University of Karlsruhe.
 */

/**
 * @file
 * @brief       Interface for assembler output.
 * @author      Matthias Braun
 * @date        12.03.2007
 */
#include "beemitter.h"

#include "irprintf.h"
#include "panic.h"

static FILE    *emit_file;
struct obstack  emit_obst;

void be_emit_init(FILE *file)
{
	emit_file = file;
	obstack_init(&emit_obst);
}

void be_emit_exit(void)
{
	obstack_free(&emit_obst, NULL);
}

void be_emit_irvprintf(const char *fmt, va_list args)
{
	ir_obst_vprintf(&emit_obst, fmt, args);
}

void be_emit_irprintf(const char *fmt, ...)
{
	va_list ap;
	va_start(ap, fmt);
	be_emit_irvprintf(fmt, ap);
	va_end(ap);
}

void be_emit_write_line(void)
{
	size_t const len  = obstack_object_size(&emit_obst);
	char  *const line = (char*)obstack_finish(&emit_obst);
	fwrite(line, 1, len, emit_file);
	obstack_free(&emit_obst, line);
}