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

Subversion Repositories lxp32

[/] [lxp32/] [trunk/] [tools/] [src/] [lxp32asm/] [linkableobject.h] - Blame information for rev 2

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 LinkableObject class which represents
7
 * compiled LXP32 binary code.
8
 */
9
 
10
#ifndef LINKABLEOBJECT_H_INCLUDED
11
#define LINKABLEOBJECT_H_INCLUDED
12
 
13
#include <iostream>
14
#include <vector>
15
#include <map>
16
#include <string>
17
#include <cstdint>
18
 
19
class LinkableObject {
20
public:
21
        typedef unsigned char Byte;
22
        typedef std::uint32_t Word;
23
 
24
        enum SymbolType {Unknown,Local,External};
25
        struct Reference {
26
                std::string source;
27
                int line;
28
                Word rva;
29
        };
30
        struct SymbolData {
31
                SymbolType type=Unknown;
32
                Word rva;
33
                std::vector<Reference> refs;
34
        };
35
        typedef std::map<std::string,SymbolData> SymbolTable;
36
 
37
private:
38
        std::string _name;
39
        std::vector<Byte> _code;
40
        SymbolTable _symbols;
41
        Word _virtualAddress=0;
42
 
43
public:
44
        std::string name() const;
45
        void setName(const std::string &str);
46
 
47
        Word virtualAddress() const;
48
        void setVirtualAddress(Word addr);
49
 
50
        Byte *code();
51
        const Byte *code() const;
52
        std::size_t codeSize() const;
53
 
54
        Word addWord(Word w);
55
        Word addByte(Byte b);
56
        Word addBytes(const Byte *p,std::size_t n);
57
        Word addZeros(std::size_t n);
58
 
59
        Word addPadding(std::size_t size=sizeof(LinkableObject::Word));
60
 
61
        Word getWord(Word rva) const;
62
        void replaceWord(Word rva,Word value);
63
 
64
        void addLocalSymbol(const std::string &name,Word rva);
65
        void addExternalSymbol(const std::string &name);
66
        void addReference(const std::string &symbolName,const std::string &source,int line,Word rva);
67
 
68
        SymbolData &symbol(const std::string &name);
69
        const SymbolData &symbol(const std::string &name) const;
70
        const SymbolTable &symbols() const;
71
 
72
        void serialize(const std::string &filename) const;
73
        void deserialize(const std::string &filename);
74
 
75
private:
76
        void deserializeCode(std::istream &in);
77
        void deserializeSymbol(std::istream &in);
78
        static std::vector<std::string> tokenize(const std::string &str);
79
};
80
 
81
#endif

powered by: WebSVN 2.1.0

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