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

Subversion Repositories lxp32

[/] [lxp32/] [trunk/] [tools/] [src/] [lxp32asm/] [assembler.h] - Blame information for rev 6

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 2 ring0_mipt
/*
2
 * Copyright (c) 2016 by Alex I. Kuznetsov.
3
 *
4
 * Part of the LXP32 CPU IP core.
5
 *
6
 * This module defines the Assembler class which performs
7
 * compilation of LXP32 assembly source files.
8
 */
9
 
10
#ifndef ASSEMBLER_H_INCLUDED
11
#define ASSEMBLER_H_INCLUDED
12
 
13
#include "linkableobject.h"
14
 
15
#include <vector>
16
#include <map>
17
#include <string>
18
#include <cstdint>
19
 
20
class Assembler {
21
        typedef std::vector<std::string> TokenList;
22
        typedef std::int_least64_t Integer;
23
        enum LexerState {
24
                Initial,
25
                Word,
26
                StringLiteral,
27
                BlockComment
28
        };
29
        struct Operand {
30
                enum Type {Null,Register,Identifier,NumericLiteral};
31
                Type type=Null;
32
                std::string str;
33
                Integer i=0;
34
                std::uint8_t reg=0;
35
        };
36
 
37
        LinkableObject _obj;
38
        std::map<std::string,TokenList> _macros;
39
        LexerState _state;
40
        int _line;
41
        std::vector<std::string> _currentLabels;
42
        std::string _currentFileName;
43
        std::vector<std::string> _includeSearchDirs;
44 6 ring0_mipt
        std::vector<std::string> _exportedSymbols;
45 2 ring0_mipt
public:
46
        void processFile(const std::string &filename);
47
 
48
        void addIncludeSearchDir(const std::string &dir);
49
 
50
        int line() const;
51
        std::string currentFileName() const;
52
 
53
        LinkableObject &object();
54
        const LinkableObject &object() const;
55
private:
56
        void processFileRecursive(const std::string &filename);
57
        TokenList tokenize(const std::string &str);
58
        void expand(TokenList &list);
59
        void elaborate(TokenList &list);
60
 
61
        void elaborateDirective(TokenList &list);
62
        LinkableObject::Word elaborateDataDefinition(TokenList &list);
63
        LinkableObject::Word elaborateInstruction(TokenList &list);
64
 
65
        static bool validateIdentifier(const std::string &str);
66
        static Integer numericLiteral(const std::string &str);
67
        static std::vector<Operand> getOperands(const TokenList &list);
68
 
69
// LXP32 instructions
70
        void encodeDstOperand(LinkableObject::Word &word,const Operand &arg);
71
        void encodeRd1Operand(LinkableObject::Word &word,const Operand &arg);
72
        void encodeRd2Operand(LinkableObject::Word &word,const Operand &arg);
73
 
74
        void encodeAdd(const TokenList &list);
75
        void encodeAnd(const TokenList &list);
76
        void encodeCall(const TokenList &list);
77
        void encodeCjmpxx(const TokenList &list);
78
        void encodeDivs(const TokenList &list);
79
        void encodeDivu(const TokenList &list);
80
        void encodeHlt(const TokenList &list);
81
        void encodeJmp(const TokenList &list);
82
        void encodeIret(const TokenList &list);
83
        void encodeLc(const TokenList &list);
84 6 ring0_mipt
        void encodeLcs(const TokenList &list);
85 2 ring0_mipt
        void encodeLsb(const TokenList &list);
86
        void encodeLub(const TokenList &list);
87
        void encodeLw(const TokenList &list);
88
        void encodeMods(const TokenList &list);
89
        void encodeModu(const TokenList &list);
90
        void encodeMov(const TokenList &list);
91
        void encodeMul(const TokenList &list);
92 6 ring0_mipt
        void encodeNeg(const TokenList &list);
93 2 ring0_mipt
        void encodeNop(const TokenList &list);
94
        void encodeNot(const TokenList &list);
95
        void encodeOr(const TokenList &list);
96
        void encodeRet(const TokenList &list);
97
        void encodeSb(const TokenList &list);
98
        void encodeSl(const TokenList &list);
99
        void encodeSrs(const TokenList &list);
100
        void encodeSru(const TokenList &list);
101
        void encodeSub(const TokenList &list);
102
        void encodeSw(const TokenList &list);
103
        void encodeXor(const TokenList &list);
104
};
105
 
106
#endif

powered by: WebSVN 2.1.0

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