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