cprover
Toggle main menu visibility
Loading...
Searching...
No Matches
as86_cmdline.cpp
Go to the documentation of this file.
1
/*******************************************************************\
2
3
Module: A special command line object for as86 (of Bruce's C Compiler)
4
5
Author: Michael Tautschnig
6
7
\*******************************************************************/
8
11
12
#include "
as86_cmdline.h
"
13
14
#include <
util/invariant.h
>
15
#include <
util/prefix.h
>
16
17
#include <iostream>
18
19
// non-as86 options
20
const
char
*
goto_as86_options_with_argument
[]=
21
{
22
"--verbosity"
,
23
"--function"
,
24
"--native-assembler"
,
25
"--print-rejected-preprocessed-source"
,
26
nullptr
27
};
28
29
const
char
*
as86_options_without_argument
[]=
30
{
31
"-0"
,
32
"-1"
,
33
"-2"
,
34
"-3"
,
35
"-a"
,
36
"-g"
,
37
"-j"
,
38
"-O"
,
39
"-u"
,
40
"-u-"
,
// both -u and -u- seem to be accepted
41
"-v"
,
42
"-w-"
,
43
nullptr
44
};
45
46
const
char
*
as86_options_with_argument
[]=
47
{
48
"-lm"
,
49
"-l"
,
50
"-n"
,
51
"-o"
,
52
"-b"
,
53
"-s"
,
54
"-t"
,
55
nullptr
56
};
57
58
bool
as86_cmdlinet::parse
(
int
argc,
const
char
**argv)
59
{
60
PRECONDITION
(argc > 0);
61
add_arg
(argv[0]);
62
63
for
(
int
i=1; i<argc; i++)
64
{
65
std::string argv_i=argv[i];
66
67
// file?
68
if
(argv_i==
"-"
|| !
has_prefix
(argv_i,
"-"
))
69
{
70
add_infile_arg
(argv_i);
71
continue
;
72
}
73
74
bool
found=
false
;
75
76
// separated only, and also allow concatenation with "="
77
for
(
const
char
**o=
goto_as86_options_with_argument
;
78
*o!=
nullptr
&& !found;
79
++o)
80
{
81
std::string os(*o);
82
83
if
(argv_i==os)
// separated
84
{
85
found=
true
;
86
if
(i!=argc-1)
87
{
88
set
(argv_i, argv[i+1]);
89
++i;
90
}
91
else
92
set
(argv_i,
""
);
93
}
94
else
if
(
has_prefix
(argv_i, os+
"="
))
// concatenated with "="
95
{
96
found=
true
;
97
set
(os, argv_i.substr(os.size()+1));
98
}
99
}
100
101
// goto-as86-only command line argument found
102
if
(found)
103
continue
;
104
105
// add to new_argv
106
add_arg
(argv_i);
107
108
// without argument; also store in cmdlinet
109
if
(
in_list
(argv_i.c_str(),
as86_options_without_argument
))
110
{
111
set
(argv_i);
112
continue
;
113
}
114
115
for
(
const
char
**o=
as86_options_with_argument
;
116
*o!=
nullptr
&& !found;
117
++o)
118
{
119
std::string os(*o);
120
121
if
(argv_i==os)
// separated
122
{
123
found=
true
;
124
if
(i!=argc-1)
125
{
126
set
(argv_i, argv[i+1]);
127
add_arg
(argv[i+1]);
128
++i;
129
}
130
else
131
set
(argv_i,
""
);
132
}
133
else
if
(
has_prefix
(argv_i, os))
134
{
135
found=
true
;
136
set
(os, argv[i]+os.size());
137
}
138
}
139
140
if
(!found)
141
{
142
// unrecognized option
143
std::cerr <<
"Warning: uninterpreted as86 option '"
<< argv_i
144
<<
"'\n"
;
145
}
146
}
147
148
return
false
;
149
}
as86_options_without_argument
const char * as86_options_without_argument[]
Definition
as86_cmdline.cpp:29
goto_as86_options_with_argument
const char * goto_as86_options_with_argument[]
Definition
as86_cmdline.cpp:20
as86_options_with_argument
const char * as86_options_with_argument[]
Definition
as86_cmdline.cpp:46
as86_cmdline.h
A special command line object for as86 (of Bruce's C Compiler) Author: Michael Tautschnig Date: July ...
as86_cmdlinet::parse
virtual bool parse(int, const char **)
Definition
as86_cmdline.cpp:58
goto_cc_cmdlinet::set
void set(const std::string &opt, const char *value) override
Set option option to value.
Definition
goto_cc_cmdline.h:33
goto_cc_cmdlinet::add_infile_arg
void add_infile_arg(const std::string &arg)
Definition
goto_cc_cmdline.cpp:102
goto_cc_cmdlinet::in_list
static bool in_list(const char *option, const char **list)
Definition
goto_cc_cmdline.cpp:38
goto_cc_cmdlinet::add_arg
void add_arg(const std::string &arg)
Definition
goto_cc_cmdline.h:71
has_prefix
bool has_prefix(const std::string &s, const std::string &prefix)
Definition
converter.cpp:13
prefix.h
invariant.h
PRECONDITION
#define PRECONDITION(CONDITION)
Definition
invariant.h:463
goto-cc
as86_cmdline.cpp
Generated by
1.17.0