OpenCores
URL https://opencores.org/ocsvn/marca/marca/trunk

Subversion Repositories marca

[/] [marca/] [trunk/] [spar/] [emit.c] - Blame information for rev 8

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 2 jeunes2
/* This file is part of the assembler "spar" for marca.
2
   Copyright (C) 2007 Wolfgang Puffitsch
3
 
4
   This program is free software; you can redistribute it and/or modify it
5
   under the terms of the GNU Library General Public License as published
6
   by the Free Software Foundation; either version 2, or (at your option)
7
   any later version.
8
 
9
   This program is distributed in the hope that it will be useful,
10
   but WITHOUT ANY WARRANTY; without even the implied warranty of
11
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
12
   Library General Public License for more details.
13
 
14
   You should have received a copy of the GNU Library General Public
15
   License along with this program; if not, write to the Free Software
16
   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA */
17
 
18
#include <stdint.h>
19
 
20
#include <stdlib.h>
21
#include <stdio.h>
22
 
23
#include "spar.h"
24
#include "optab.h"
25
#include "code.h"
26
#include "emit.h"
27
#include "exprs.h"
28
#include "segtab.h"
29
 
30
void emit_op(struct seg *seg, struct op op)
31
{
32
  adjust_segsize(seg, seg->pos+1);
33
  seg->code[seg->pos] = op;
34
  seg->pos++;
35
}
36
 
37
void emit_nop(struct seg *seg)
38
{
39
  adjust_segsize(seg, seg->pos+1);
40
  set_op(seg, seg->pos, NOP);
41
 
42
  trace_listing(seg, seg->pos, "nop");
43
 
44
  seg->pos++;
45
}
46
 
47
void emit_zero(struct seg *seg)
48
{
49
  adjust_segsize(seg, seg->pos+1);
50
  set_op(seg, seg->pos, DATA);
51
  set_expr(seg, seg->pos, 0, "0");
52
  set_mode(seg, seg->pos, 0, 'n');
53
 
54
  trace_listing(seg, seg->pos, "data 0");
55
 
56
  seg->pos++;
57
}
58
 
59
void emit_data(struct seg *seg, char *expr)
60
{
61
  char *buf = xmalloc(CODE_MAX_LISTLEN);
62
 
63
  adjust_segsize(seg, seg->pos+1);
64
  set_op(seg, seg->pos, DATA);
65
  set_expr(seg, seg->pos, 0, expr);
66
  set_mode(seg, seg->pos, 0, 'n');
67
 
68
  snprintf(buf, CODE_MAX_LISTLEN, "data\t%s", expr);
69
  trace_listing(seg, seg->pos, buf);
70
 
71
  seg->pos++;
72
 
73
  free(buf);
74
}
75
 
76
void emit_ldil(struct seg *seg, uint16_t reg, char *expr)
77
{
78
  char *buf = xmalloc(CODE_MAX_LISTLEN);
79
 
80
  adjust_segsize(seg, seg->pos+1);
81
  set_op(seg, seg->pos, LDIL);
82
  set_regnum(seg, seg->pos, 0, reg);
83
  set_mode(seg, seg->pos, 0, 'r');
84
  set_expr(seg, seg->pos, 1, expr);
85
  set_mode(seg, seg->pos, 1, 'n');
86
 
87
  snprintf(buf, CODE_MAX_LISTLEN, "ldil\tr%d, %s", reg, expr);
88
  trace_listing(seg, seg->pos, buf);
89
  seg->pos++;
90
 
91
  free(buf);
92
}
93
 
94
void emit_ldih(struct seg *seg, uint16_t reg, char *expr)
95
{
96
  char *buf = xmalloc(CODE_MAX_LISTLEN);
97
 
98
  adjust_segsize(seg, seg->pos+1);
99
  set_op(seg, seg->pos, LDIH);
100
  set_regnum(seg, seg->pos, 0, reg);
101
  set_mode(seg, seg->pos, 0, 'r');
102
  set_expr(seg, seg->pos, 1, expr);
103
  set_mode(seg, seg->pos, 2, 'n');
104
 
105
  snprintf(buf, CODE_MAX_LISTLEN, "ldih\tr%d, %s", reg, expr);
106
  trace_listing(seg, seg->pos, buf);
107
  seg->pos++;
108
 
109
  free(buf);
110
}
111
 
112
void emit_ldib(struct seg *seg, uint16_t reg, char *expr)
113
{
114
  char *buf = xmalloc(CODE_MAX_LISTLEN);
115
 
116
  adjust_segsize(seg, seg->pos+1);
117
  set_op(seg, seg->pos, LDIB);
118
  set_regnum(seg, seg->pos, 0, reg);
119
  set_mode(seg, seg->pos, 0, 'r');
120
  set_expr(seg, seg->pos, 1, expr);
121
  set_mode(seg, seg->pos, 1, 'n');
122
 
123
  snprintf(buf, CODE_MAX_LISTLEN, "ldib\tr%d, %s", reg, expr);
124
  trace_listing(seg, seg->pos, buf);
125
  seg->pos++;
126
 
127
  free(buf);
128
}
129
 
130
void emit_addi(struct seg *seg, uint16_t reg, char *expr)
131
{
132
  char *buf = xmalloc(CODE_MAX_LISTLEN);
133
 
134
  adjust_segsize(seg, seg->pos+1);
135
  set_op(seg, seg->pos, ADDI);
136
  set_regnum(seg, seg->pos, 0, reg);
137
  set_mode(seg, seg->pos, 0, 'r');
138
  set_expr(seg, seg->pos, 1, expr);
139
  set_mode(seg, seg->pos, 1, 'n');
140
 
141
  snprintf(buf, CODE_MAX_LISTLEN, "addi\tr%d, %s", reg, expr);
142
  trace_listing(seg, seg->pos, buf);
143
  seg->pos++;
144
 
145
  free(buf);
146
}
147
 
148
void emit_cmp(struct seg *seg, uint16_t reg1, uint16_t reg2)
149
{
150
  char *buf = xmalloc(CODE_MAX_LISTLEN);
151
 
152
  adjust_segsize(seg, seg->pos+1);
153
  set_op(seg, seg->pos, CMP);
154
  set_regnum(seg, seg->pos, 0, reg1);
155
  set_mode(seg, seg->pos, 0, 'r');
156
  set_regnum(seg, seg->pos, 1, reg2);
157
  set_mode(seg, seg->pos, 1, 'r');
158
 
159
  snprintf(buf, CODE_MAX_LISTLEN, "cmp\tr%d, r%d", reg1, reg2);
160
  trace_listing(seg, seg->pos, buf);
161
  seg->pos++;
162
 
163
  free(buf);
164
}
165
 
166
void emit_load(struct seg *seg, uint16_t reg1, uint16_t reg2)
167
{
168
  char *buf = xmalloc(CODE_MAX_LISTLEN);
169
 
170
  adjust_segsize(seg, seg->pos+1);
171
  set_op(seg, seg->pos, LOAD);
172
  set_regnum(seg, seg->pos, 0, reg1);
173
  set_mode(seg, seg->pos, 0, 'r');
174
  set_regnum(seg, seg->pos, 1, reg2);
175
  set_mode(seg, seg->pos, 1, 'r');
176
 
177
  snprintf(buf, CODE_MAX_LISTLEN, "load\tr%d, r%d", reg1, reg2);
178
  trace_listing(seg, seg->pos, buf);
179
  seg->pos++;
180
 
181
  free(buf);
182
}
183
 
184
void emit_store(struct seg *seg, uint16_t reg1, uint16_t reg2)
185
{
186
  char *buf = xmalloc(CODE_MAX_LISTLEN);
187
 
188
  adjust_segsize(seg, seg->pos+1);
189
  set_op(seg, seg->pos, STORE);
190
  set_regnum(seg, seg->pos, 0, reg1);
191
  set_mode(seg, seg->pos, 0, 'r');
192
  set_regnum(seg, seg->pos, 1, reg2);
193
  set_mode(seg, seg->pos, 1, 'r');
194
 
195
  snprintf(buf, CODE_MAX_LISTLEN, "store\tr%d, r%d", reg1, reg2);
196
  trace_listing(seg, seg->pos, buf);
197
  seg->pos++;
198
 
199
  free(buf);
200
}
201
 
202
void emit_jmp(struct seg *seg, uint16_t reg)
203
{
204
  char *buf = xmalloc(CODE_MAX_LISTLEN);
205
 
206
  adjust_segsize(seg, seg->pos+1);
207
  set_op(seg, seg->pos, JMP);
208
  set_regnum(seg, seg->pos, 0, reg);
209
  set_mode(seg, seg->pos, 0, 'r');
210
 
211
  snprintf(buf, CODE_MAX_LISTLEN, "jmp\tr%d", reg);
212
  trace_listing(seg, seg->pos, buf);
213
  seg->pos++;
214
 
215
  free(buf);
216
}
217
 
218
void emit_brnz(struct seg *seg, char *expr)
219
{
220
  char *buf = xmalloc(CODE_MAX_LISTLEN);
221
 
222
  adjust_segsize(seg, seg->pos+1);
223
  set_op(seg, seg->pos, BRNZ);
224
  set_expr(seg, seg->pos, 0, expr);
225
  set_mode(seg, seg->pos, 0, 'a');
226
 
227
  snprintf(buf, CODE_MAX_LISTLEN, "brnz\t%s", expr);
228
  trace_listing(seg, seg->pos, buf);
229
  seg->pos++;
230
 
231
  free(buf);
232
}

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.