My Project
lc3.h
Go to the documentation of this file.
1 #ifndef __LC3_H__
2 #define __LC3_H__
3 
4 /*
5  * "Copyright (c) 2014 by Fritz Sieker."
6  * based on ideas/code by Steven S. Lumetta
7  *
8  * Permission to use, copy, modify, and distribute this software and its
9  * documentation for any purpose, without fee, and without written
10  * agreement is hereby granted, provided that the above copyright notice
11  * and the following two paragraphs appear in all copies of this software.
12  *
13  * IN NO EVENT SHALL THE AUTHOR BE LIABLE TO ANY PARTY FOR DIRECT,
14  * INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES ARISING OUT
15  * OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF THE AUTHOR
16  * HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
17  *
18  * THE AUTHOR SPECIFICALLY DISCLAIMS ANY WARRANTIES, INCLUDING, BUT NOT
19  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
20  * A PARTICULAR PURPOSE. THE SOFTWARE PROVIDED HEREUNDER IS ON AN "AS IS"
21  * BASIS, AND THE AUTHOR NO OBLIGATION TO PROVIDE MAINTENANCE, SUPPORT,
22  * UPDATES, ENHANCEMENTS, OR MODIFICATIONS."
23  */
24 
34 #include <stdio.h>
35 #include <stdbool.h>
36 
37 #include "symbol.h"
38 
40 #ifndef LC3_VAR
41 #define LC3_VAR extern
42 #endif
43 
48 char* strdup(const char *);
49 
51 #define LC3_WORD unsigned short
52 
54 #define LC3_MEM_SIZE (1 << 16)
55 
57 #define LC3_NUM_REGS 8
58 
60 #define RETURN_ADDR_REG 7
61 
64 
69 typedef enum opcode {
70  OP_INVALID = -1,
106 } opcode_t;
107 
115 typedef enum operand {
116  OPN_DR = 0x0001,
117  OPN_SR1 = 0x0002,
118  OPN_SR2 = 0x0004,
119  OPN_CC = 0x0008,
120  OPN_IMM5 = 0x0010,
121  OPN_OFF6 = 0x0020,
122  OPN_VEC8 = 0x0040,
123  OPN_ASC8 = 0x0080,
124  OPN_PCO9 = 0x0100,
125  OPN_PCO11 = 0x0200,
126  OPN_IMM16 = 0x0400,
127  OPN_STR = 0x0800,
128  OPN_FILL = 0x1000
129 } operand_t;
130 
143 typedef enum format {
144  FMT_ = 0,
145  FMT_RRR = (OPN_DR | OPN_SR1 | OPN_SR2),
146  FMT_RRI5 = (OPN_DR | OPN_SR1 | OPN_IMM5),
147  FMT_CL = (OPN_CC | OPN_PCO9),
148  FMT_R1 = OPN_DR,
149  FMT_R2 = OPN_SR1,
150  FMT_I11 = OPN_PCO11,
151  FMT_RL = (OPN_DR | OPN_PCO9),
152  FMT_RRI6 = (OPN_DR | OPN_SR1 | OPN_OFF6),
153  FMT_RR = (OPN_DR | OPN_SR1),
154  FMT_V = OPN_VEC8,
155  FMT_A = OPN_ASC8,
156  FMT_16 = OPN_IMM16,
157  FMT_S = OPN_STR,
158  FMT_FILL = OPN_FILL
159 } format_t;
160 
164 typedef struct inst_format {
165  char* name;
167  int prototype;
168 } inst_format_t;
169 
175 typedef struct LC3_inst {
176  int formBit;
186 } LC3_inst_t;
187 
192 char lc3_escaped_char (char c);
193 
201 
207 char* lc3_get_suffix (char* file_name);
208 
214 bool lc3_file_has_suffix (const char* file_name, const char* suffix);
215 
222 char* lc3_replace_suffix (char* file_name, char* new_suffix);
223 
228 const char* lc3_get_format_name (format_t format);
229 
234 const char* lc3_get_opcode_name (opcode_t op);
235 
241 
246 void lc3_set_obj_file_mode (const char* name);
247 
252 int lc3_read_LC3_word (FILE *f);
253 
259 void lc3_read_sym_table (FILE* sym_file);
260 
265 void lc3_write_LC3_word (FILE* f, int value);
266 
270 void lc3_write_sym_table (FILE* sym_file);
271 
280 bool lc3_get_int (const char* token, int* value);
281 
289 bool lc3_get_address (const char* token, int* value);
290 
291 #endif /* __LC3_H__ */
292 
Definition: lc3.h:122
bool lc3_get_int(const char *token, int *value)
Definition: lc3.c:182
Definition: lc3.h:81
Definition: lc3.h:89
Definition: lc3.h:125
Definition: lc3.h:70
int formBit
Definition: lc3.h:176
Definition: lc3.h:93
Definition: lc3.h:116
#define LC3_VAR
Definition: lc3.h:41
Definition: lc3.h:96
Defines the interface to symbol.c functions (do not modify)
void lc3_read_sym_table(FILE *sym_file)
Definition: lc3.c:252
Definition: lc3.h:123
Definition: lc3.h:99
Definition: lc3.h:164
Definition: lc3.h:121
char * lc3_replace_suffix(char *file_name, char *new_suffix)
Definition: lc3.c:116
void lc3_write_sym_table(FILE *sym_file)
Definition: lc3.c:280
char * lc3_get_suffix(char *file_name)
Definition: lc3.c:100
Definition: lc3.h:124
bool lc3_file_has_suffix(const char *file_name, const char *suffix)
Definition: lc3.c:109
Definition: lc3.h:75
Definition: lc3.h:79
Definition: lc3.h:73
enum operand operand_t
Definition: lc3.h:104
Definition: lc3.h:105
Definition: lc3.h:120
void lc3_set_obj_file_mode(const char *name)
Definition: lc3.c:128
Definition: lc3.h:97
struct inst_format inst_format_t
Definition: lc3.h:77
LC3_inst_t * lc3_get_inst_info(opcode_t opcode)
Definition: lc3.c:91
opcode
Definition: lc3.h:69
Definition: lc3.h:119
operand
Definition: lc3.h:115
Definition: lc3.h:175
Definition: lc3.h:102
Definition: lc3.h:128
Definition: lc3.h:118
Definition: lc3.h:127
enum opcode opcode_t
struct LC3_inst LC3_inst_t
Definition: lc3.h:72
format_t operands
Definition: lc3.h:166
LC3_VAR sym_table_t * lc3_sym_tab
Definition: lc3.h:63
Definition: lc3.h:82
Definition: lc3.h:98
const char * lc3_get_operand_name(operand_t operand)
Definition: lc3.c:331
Definition: lc3.h:103
char * strdup(const char *)
Definition: lc3.h:117
Definition: lc3.h:90
Definition: lc3.h:86
const char * lc3_get_opcode_name(opcode_t op)
Definition: lc3.c:326
Definition: lc3.h:126
inst_format_t forms[2]
Definition: lc3.h:181
char * name
Definition: lc3.h:165
Definition: lc3.h:101
bool lc3_get_address(const char *token, int *value)
Definition: lc3.c:236
enum format format_t
Definition: lc3.h:78
char lc3_escaped_char(char c)
Definition: lc3.c:166
Definition: lc3.h:74
Definition: lc3.h:71
format
Definition: lc3.h:143
void lc3_write_LC3_word(FILE *f, int value)
Definition: lc3.c:151
Definition: lc3.h:85
Definition: lc3.h:100
Definition: lc3.h:91
int prototype
Definition: lc3.h:167
Definition: lc3.h:76
Definition: lc3.h:88
Definition: symbol.c:35
const char * lc3_get_format_name(format_t format)
Definition: lc3.c:349
Definition: lc3.h:87
Definition: lc3.h:95
int lc3_read_LC3_word(FILE *f)
Definition: lc3.c:132
Definition: lc3.h:83
Definition: lc3.h:94
Definition: lc3.h:84
Definition: lc3.h:80