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

Subversion Repositories lxp32

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

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 9 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
        typedef std::int_least64_t Integer;
24
 
25
        enum SymbolType {Unknown,Local,Exported,Imported};
26
        enum RefType {Regular,Short};
27
 
28
        struct Reference {
29
                std::string source;
30
                int line;
31
                Word rva;
32
                Integer offset;
33
                RefType type;
34
        };
35
        struct SymbolData {
36
                SymbolType type=Unknown;
37
                Word rva;
38
                std::vector<Reference> refs;
39
        };
40
 
41
        typedef std::map<std::string,SymbolData> SymbolTable;
42
 
43
private:
44
        std::string _name;
45
        std::vector<Byte> _code;
46
        SymbolTable _symbols;
47
        Word _virtualAddress=0;
48
 
49
public:
50
        std::string name() const;
51
        void setName(const std::string &str);
52
 
53
        Word virtualAddress() const;
54
        void setVirtualAddress(Word addr);
55
 
56
        Byte *code();
57
        const Byte *code() const;
58
        std::size_t codeSize() const;
59
 
60
        Word addWord(Word w);
61
        Word addByte(Byte b);
62
        Word addBytes(const Byte *p,std::size_t n);
63
        Word addZeros(std::size_t n);
64
 
65
        Word addPadding(std::size_t size=sizeof(LinkableObject::Word));
66
 
67
        Word getWord(Word rva) const;
68
        void replaceWord(Word rva,Word value);
69
 
70
        void addSymbol(const std::string &name,Word rva);
71
        void addImportedSymbol(const std::string &name);
72
        void exportSymbol(const std::string &name);
73
        void addReference(const std::string &symbolName,const Reference &ref);
74
 
75
        SymbolData &symbol(const std::string &name);
76
        const SymbolData &symbol(const std::string &name) const;
77
        const SymbolTable &symbols() const;
78
 
79
        void serialize(const std::string &filename) const;
80
        void deserialize(const std::string &filename);
81
 
82
private:
83
        void deserializeCode(std::istream &in);
84
        void deserializeSymbol(std::istream &in);
85
        static std::vector<std::string> tokenize(const std::string &str);
86
};
87
 
88
#endif

powered by: WebSVN 2.1.0

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