summaryrefslogtreecommitdiff
path: root/asm/asm.ml
blob: 47f5f7b9ad90b7b308580cf4f27f5eef2e25379f (plain) (blame)
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
100
type reg = int

type imm =
	| Imm of int
	| Lab of string

type fmt_r =
	| Add
	| Sub
	| Mul
	| Div
	| Addu
	| Subu
	| Mulu
	| Divu
	| Or
	| And
	| Xor
	| Nor
	| Lsl
	| Lsr
	| Asr
	| Se
	| Sne
	| Sle
	| Slt
	| Sltu
	| Sleu
	| Jer
	| Jner
	| Jltr
	| Jler
	| Jltru
	| Jleru
	| Lwr
	| Swr
	| Lbr
	| Sbr

type instr =
	| R of (fmt_r * reg * reg * reg)
	| Incri of (reg * int)
	| Shi of (reg * int)
	| J of imm
	| Jal of imm
	| Jr of reg
	| Jalr of reg
	| Lw of (reg * reg * int)
	| Sw of (reg * reg * int)
	| Lb of (reg * reg * int)
	| Sb of (reg * reg * int)
	| Lil of (reg * imm)
	| Lilz of (reg * imm)
	| Liu of (reg * imm)
	| Liuz of (reg * imm)
	| Lra of imm
	| Byte of int
	| Word of int
	| Hlt

module Imap = Map.Make(String)

type program = { text : instr list;
	lbls : (int * bool) Imap.t }

let keywords_r = [
		"add",Add;
		"sub",Sub;
		"mul",Mul;
		"div",Div;
		"addu",Addu;
		"subu",Subu;
		"mulu",Mulu;
		"divu",Divu;
		"or",Or;
		"and",And;
		"xor",Xor;
		"nor",Nor;
		"lsl",Lsl;
		"Asr",Asr;
		"Lsr",Lsr;
		"se",Se;
		"sne",Sne;
		"sle",Sle;
		"slt",Slt;
		"sltu",Sltu;
		"sleu",Sleu;
		"jer",Jer;
		"jner",Jner;
		"jltr",Jltr;
		"jler",Jler;
		"jltru",Jltru;
		"jleru",Jleru;
		"lwr",Lwr;
		"lbr",Lbr;
		"swr",Swr;
		"sbr",Sbr
	]
	
exception Lexer_error