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

/**
 * @file
 * @brief       Interface for text output.
 * @author      Matthias Braun
 * @date        12.03.2007
 *
 * This is a framework for emitting line base text used by most backends to
 * emit assembly code.
 */
#ifndef FIRM_BE_BEEMITTER_H
#define FIRM_BE_BEEMITTER_H

#include <stdio.h>
#include "obst.h"

/* don't use the following vars directly, they're only here for the inlines */
extern struct obstack  emit_obst;

/**
 * Emit a character to the (assembler) output.
 */
static inline void be_emit_char(char c)
{
	obstack_1grow(&emit_obst, c);
}

/**
 * Emit a string to the (assembler) output.
 *
 * @param str  the string
 * @param l    the length of the given string
 */
static inline void be_emit_string_len(const char *str, size_t l)
{
	obstack_grow(&emit_obst, str, l);
}

/**
 * Emit a null-terminated string to the (assembler) output.
 *
 * @param str  the null-terminated string
 */
static inline void be_emit_string(const char *str)
{
	size_t len = strlen(str);
	be_emit_string_len(str, len);
}

/**
 * Emit a C string-constant to the (assembler) output.
 *
 * @param str  the null-terminated string constant
 */
#define be_emit_cstring(str) \
	be_emit_string_len(str, sizeof(str) - 1)

/**
 * Initializes an emitter environment.
 *
 * @param F    a file handle where the emitted file is written to.
 */
void be_emit_init(FILE *F);

/**
 * Destroys the given emitter environment.
 */
void be_emit_exit(void);

/**
 * Emit the output of an ir_printf.
 *
 * @param fmt  the ir_printf format
 */
void be_emit_irprintf(const char *fmt, ...);

/**
 * Emit the output of an ir_vprintf.
 *
 * @param fmt  the ir_printf format
 */
void be_emit_irvprintf(const char *fmt, va_list args);

/**
 * Flush the line in the current line buffer to the emitter file.
 */
void be_emit_write_line(void);

/** Return column in current line. Counting starts at 0. */
static inline size_t be_emit_get_column(void)
{
	return obstack_object_size(&emit_obst);
}

#endif