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

Subversion Repositories forwardcom

[/] [forwardcom/] [bintools/] [cmdline.h] - Blame information for rev 106

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

Line No. Rev Author Line
1 66 Agner
/****************************  cmdline.h   ***********************************
2
* Author:        Agner Fog
3
* Date created:  2017-04-17
4
* Last modified: 2021-04-25
5
* Version:       1.11
6
* Project:       Binary tools for ForwardCom instruction set
7
* Module:        cmdline.h
8
* Description:
9
* Header file for command line interpreter cmdline.cpp
10
*
11
* Copyright 2006-2021 GNU General Public License http://www.gnu.org/licenses
12
*****************************************************************************/
13
#pragma once
14
 
15
/**************************  Define constants  ******************************/
16
// Max number of response files on command line
17
const int MAX_COMMAND_FILES = 10;
18
 
19
// Constants for output file type
20
const int CMDL_OUTPUT_DUMP =          0x80;      // No output file, just dump contents
21
const int CMDL_OUTPUT_ELF =   FILETYPE_ELF;      // ELF file
22
const int CMDL_OUTPUT_ASM =   FILETYPE_ASM;      // Assembly file
23
 
24
// Constants for job
25
const int CMDL_JOB_ASS =                1;       // Assemble
26
const int CMDL_JOB_DIS =                2;       // Disassemble
27
const int CMDL_JOB_DUMP =               3;       // Dump
28
const int CMDL_JOB_LINK =               4;       // Link
29
const int CMDL_JOB_RELINK =             5;       // Relink
30
const int CMDL_JOB_LIB =                6;       // Library
31
const int CMDL_JOB_EMU =                8;       // Emulate/Debug
32
const int CMDL_JOB_HELP =          0x1000;       // Show help
33
 
34
// Constants for verbose or silent console output
35
const int CMDL_VERBOSE_NO =             0;     // Silent. No console output if no errors or warnings
36
const int CMDL_VERBOSE_YES =            1;     // Output messages about file names and types
37
const int CMDL_VERBOSE_DIAGNOSTICS =    2;     // Output more messages
38
 
39
// Constants for dump options
40
const int DUMP_NONE =              0x0000;     // Dump nothing
41
const int DUMP_LINKMAP =           0x0001;     // Dump link map
42
const int DUMP_FILEHDR =           0x0002;     // Dump file header
43
const int DUMP_SECTHDR =           0x0004;     // Dump section headers
44
const int DUMP_SYMTAB =            0x0010;     // Dump symbol table
45
const int DUMP_RELTAB =            0x0020;     // Dump relocation table
46
const int DUMP_STRINGTB =          0x0040;     // Dump string table
47
const int DUMP_COMMENT =           0x0080;     // Dump comment records
48
const int DUMP_RELINKABLE =        0x0100;     // Show names of relinkable modules and libraries
49
 
50
// Constants for file input/output options
51
const int CMDL_FILE_INPUT =             1;     // Input file required
52
const int CMDL_FILE_SEARCH_PATH =       2;     // Search for file in path
53
const int CMDL_FILE_IN_IF_EXISTS =      4;     // Read input file if it exists
54
const int CMDL_FILE_OUTPUT =         0x10;     // Write output file required
55
const int CMDL_FILE_IN_OUT_SAME =    0x20;     // Input and output files may have the same name
56
const int CMDL_FILE_INCOMPLETE =   0x1000;     // Allow output executable file to be incomplete, i.e. have unresolved references
57
const int CMDL_FILE_RELINKABLE =  0x10000;     // Output executable file is relinkable
58
 
59
// Constants for library options
60
const int CMDL_LIBRARY_PRESERVEMEMBER = 1;     // preserve object file in library
61
const int CMDL_LIBRARY_ADDMEMBER =      2;     // add object file to library
62
const int CMDL_LIBRARY_DELETEMEMBER =   4;     // delete object file to library
63
const int CMDL_LIBRARY_LISTMEMBERS =    8;     // list library members
64
const int CMDL_LIBRARY_EXTRACTMEM = 0x100;     // extract specified object file(s) from library
65
const int CMDL_LIBRARY_EXTRACTALL = 0x300;     // extract all object files from library
66
 
67
// Constants for linker options
68
const int CMDL_LINK_EXEFILE =            1;    // expecting executable file name
69
const int CMDL_LINK_ADDMODULE =          2;    // add the following object files or library files
70
const int CMDL_LINK_ADDLIBRARY =         4;    // add the following library files
71
const int CMDL_LINK_ADDLIBMODULE =       6;    // add a member of a previously specified library
72
const int CMDL_LINK_EXTRACT =            8;    // extract relinkable module
73
const int CMDL_LINK_REMOVE =          0x10;    // remove relinkable modules
74
const int CMDL_LINK_REPLACE =         0x20;    // replace relinkable modules
75
const int CMDL_LINK_LIST =            0x80;    // list relinkable modules
76
const int CMDL_LINK_EXTRACT_ALL =    0x100;    // extract all relinkable modules
77
const int CMDL_LINK_STACKSIZE =      0x200;    // size of call stack, data stack, additional vectors
78
const int CMDL_LINK_HEAPSIZE =       0x400;    // size of heap
79
const int CMDL_LINK_DYNLINKSIZE =    0x800;    // extra size for dynamic linking: readonly, executable, writeable data
80
const int CMDL_LINK_RELINKABLE =   0x10000;    // add as relinkable the following object files and library files
81
const int CMD_NAME_FOUND =       0x1000000;    // mark name found in rnames record
82
 
83
 
84
// Structure for storing library or linker commands from command line
85
struct SLCommand {
86
    uint32_t filename;                           // full file name, as index into cmd.fileNameBuffer
87
    uint32_t command;                            // library commands or linker commands
88
    uint64_t value;                              // value or library member name = filename without path
89
};
90
 
91
 
92
// Class for interpreting command line
93
class CCommandLineInterpreter {
94
public:
95
    CCommandLineInterpreter();                // Default constructor
96
    void readCommandLine(int argc, char * argv[]);     // Read and interpret command line
97
    void reportStatistics();                  // Report statistics about name changes etc.
98
    uint32_t inputFile;                       // Input file name. index into fileNameBuffer
99
    uint32_t outputFile;                      // Output file name. index into fileNameBuffer
100
    uint32_t instructionListFile;             // File name of instruction list. index into fileNameBuffer
101
    uint32_t outputListFile;                  // File name of assembler or emulator or linker output list file. index into fileNameBuffer
102
    int  job;                                 // Job to do: ass, dis, dump, link, lib, emu
103
    int  inputType;                           // Input file type (detected from file)
104
    int  outputType;                          // Output type (file type or dump)
105
    int  optiLevel;                           // Optimization level (asm)
106
    uint32_t maxErrors;                       // Maximum number of errors before assembler or emulator aborts
107
    uint32_t maxLines;                        // Maximum number of lines in emulator output list
108
    uint32_t verbose;                         // How much diagnostics to print on screen
109
    uint32_t dumpOptions;                     // Options for dumping file
110
    uint32_t fileOptions;                     // Options for input and output files
111
    uint32_t libraryOptions;                  // Options for library operations
112
    uint32_t linkOptions;                     // Options for linking
113
    uint32_t debugOptions;                    // Options for debug info in assembly. not fully supported yet
114
    uint64_t codeSizeOption;                  // Option specifying max code size
115
    uint64_t dataSizeOption;                  // Option specifying max data size
116
    const char * programName;                 // Path and name of this program
117
    void checkExtractSuccess();               // Check if library members to extract were found
118
    const char * getFilename(uint32_t n);     // Get file name from index
119
    int mainReturnValue;                      // Return value for program main
120
protected:
121
    int  libmode;                             // lib option has been encountered
122
    int  linkmode;                            // link option has been encountered
123
    int  emumode;                             // emulation option has been encountered
124
    int  numBuffers;                          // Number of response file buffers
125
    void readCommandItem(char *);             // Read one option from command line
126
    void readCommandFile(char *);             // Read commands from file
127
    void interpretFileName(char *);           // Interpret input or output filename from command line
128
    void interpretCommandOption(char *);      // Interpret one option from command line
129
    void interpretAssembleOption(char *);     // Interpret assemble option from command line
130
    void interpretDisassembleOption(char *);  // Interpret disassemble option from command line
131
    void interpretLibraryCommand(char*string);// Interpret -lib command
132
    void interpretLibraryOption(char*string); // Interpret library option from command line
133
    void interpretLinkCommand(char * string); // Interpret -link command
134
    void interpretLinkOption(char * string);  // Interpret linking option from command line
135
    void interpretEmulateOption(char *);      // Interpret emulate option from command line
136
    void interpretMaxErrorsOption(char * string); // Interpret maxerrors option from command line    
137
    void interpretCodeSizeOption(char * string);  // Interpret codesize option from command line
138
    void interpretDataSizeOption(char * string);  // Interpret datasize option from command line
139
    void interpretDebugOption(char * string); // Interpret debug option from command line
140
    void interpretIlistOption(char *);        // Interpret instruction list file option
141
    void interpretListOption(char *);         // Interpret output list file option for assembler
142
    void interpretOptimizationOption(char *); // Interpret optimization option for assembler
143
    void interpretStackOption(char *);        // Interpret stack size option for linker
144
    void interpretHeapOption(char *);         // Interpret heap size option for linker
145
    void interpretHexfileOption(char *);      // Interpret hex file option for linker
146
    void interpretDynlinkOption(char *);      // Interpret dynamic link size option for linker
147
    void interpretVerboseOption(char * string);// Interpret silent/verbose option from command line
148
    void interpretDumpOption(char *);         // Interpret dump option from command line
149
    void interpretErrorOption(char *);        // Interpret error option from command line
150
    void interpretMaxLinesOption(char * string);// Interpret maxlines option from command line
151
    void checkOutputFileName();               // Make output file name or check that requested name is valid
152
    uint32_t setFileNameExtension(uint32_t fn, int filetype);   // Set file name extension according to FileType
153
    void help();                              // Print help message
154
public:
155
    CMemoryBuffer fileNameBuffer;             // Buffer containing names of files from command line
156
    CDynamicArray<SLCommand> lcommands;       // List of linker or library commands from command line
157
};
158
 
159
int strncasecmp_(const char *s1, const char *s2, uint32_t n); // compare strings, ignore case for a-z
160
 
161
extern CCommandLineInterpreter cmd;          // Command line interpreter
162
 
163
// operator < for sorting command line commands by name
164
static inline bool operator < (SLCommand const & a, SLCommand const & b) {
165
    return strcmp(cmd.getFilename((uint32_t)a.value), cmd.getFilename((uint32_t)b.value)) < 0;
166
}

powered by: WebSVN 2.1.0

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