Skip to content

Commit 35c653d

Browse files
author
Daniel Kroening
authored
Merge pull request #81 from tautschnig/goto-gcc_native-compiler-linker
goto-gcc options parsing and new goto-cc specific options for large-scale builds
2 parents 86dbc83 + dddab58 commit 35c653d

27 files changed

+1804
-627
lines changed

src/ansi-c/parser.y

+4
Original file line numberDiff line numberDiff line change
@@ -2705,6 +2705,10 @@ asm_definition:
27052705
{
27062706
// Not obvious what to do with this.
27072707
}
2708+
| '{' TOK_ASM_STRING '}'
2709+
{
2710+
// Not obvious what to do with this.
2711+
}
27082712
;
27092713

27102714
function_definition:

src/ansi-c/scanner.l

+43-11
Original file line numberDiff line numberDiff line change
@@ -290,8 +290,7 @@ void ansi_c_scanner_init()
290290
<GRAMMAR,GCC_ATTRIBUTE3>{string_lit} {
291291
PARSER.string_literal.clear();
292292
PARSER.string_literal.append(yytext);
293-
newstack(yyansi_clval);
294-
PARSER.set_source_location(stack(yyansi_clval));
293+
loc();
295294
// String literals can be continued in
296295
// the next line
297296
yy_push_state(STRING_LITERAL);
@@ -381,6 +380,23 @@ void ansi_c_scanner_init()
381380
<GRAMMAR>{cppstart}"define"{ws}.* { /* ignore */ }
382381
<GRAMMAR>{cppstart}"undef"{ws}.* { /* ignore */ }
383382

383+
<GRAMMAR>{cppstart}"asm" {
384+
if(PARSER.mode==configt::ansi_ct::flavourt::GCC) // really, this is BCC
385+
{
386+
BEGIN(ASM_BLOCK);
387+
PARSER.string_literal.clear();
388+
loc();
389+
return '{';
390+
}
391+
else
392+
return make_identifier();
393+
}
394+
395+
<GRAMMAR>{cppstart}"endasm" {
396+
loc();
397+
return '}';
398+
}
399+
384400
<GRAMMAR>{cppdirective} {
385401
yyansi_cerror("Preprocessor directive found");
386402
return TOK_SCANNER_ERROR;
@@ -1374,7 +1390,11 @@ __decltype { if(PARSER.cpp98 &&
13741390

13751391
"{" {
13761392
PARSER.tag_following=false;
1377-
if(PARSER.asm_block_following) { BEGIN(ASM_BLOCK); }
1393+
if(PARSER.asm_block_following)
1394+
{
1395+
BEGIN(ASM_BLOCK);
1396+
PARSER.string_literal.clear();
1397+
}
13781398
loc();
13791399
return yytext[0];
13801400
}
@@ -1392,7 +1412,12 @@ __decltype { if(PARSER.cpp98 &&
13921412
<MSC_ANNOTATION>"]" { BEGIN(GRAMMAR); }
13931413
<MSC_ANNOTATION>. { /* ignore */ }
13941414

1395-
<MSC_ASM>{ws}"{" { BEGIN(ASM_BLOCK); loc(); return '{'; }
1415+
<MSC_ASM>{ws}"{" {
1416+
BEGIN(ASM_BLOCK);
1417+
PARSER.string_literal.clear();
1418+
loc();
1419+
return '{';
1420+
}
13961421
<MSC_ASM>[^{^}^\n]* { loc();
13971422
source_locationt l=stack(yyansi_clval).source_location();
13981423
stack(yyansi_clval)=string_constantt(yytext);
@@ -1401,13 +1426,20 @@ __decltype { if(PARSER.cpp98 &&
14011426
return TOK_ASM_STRING;
14021427
}
14031428

1404-
<ASM_BLOCK>[^}]* { loc();
1405-
source_locationt l=stack(yyansi_clval).source_location();
1406-
stack(yyansi_clval)=string_constantt(yytext);
1407-
stack(yyansi_clval).add_source_location()=l;
1408-
return TOK_ASM_STRING; }
1409-
<ASM_BLOCK>"}" { PARSER.asm_block_following=false;
1410-
BEGIN(GRAMMAR); loc(); return '}'; }
1429+
<ASM_BLOCK>{
1430+
{ws} { /* ignore */ }
1431+
{newline} { /* ignore */ }
1432+
[^#}\n][^\n}]*[\n] { PARSER.string_literal.append(yytext); }
1433+
[^#}\n][^\n}]* { PARSER.string_literal.append(yytext); }
1434+
. { // anything else: back to normal
1435+
PARSER.asm_block_following=false;
1436+
loc();
1437+
stack(yyansi_clval)=string_constantt(PARSER.string_literal);
1438+
BEGIN(GRAMMAR);
1439+
yyless(0); // put back
1440+
return TOK_ASM_STRING;
1441+
}
1442+
}
14111443

14121444
<IGNORE_PARENS>")" { PARSER.parenthesis_counter--;
14131445
if(PARSER.parenthesis_counter==0)

src/goto-cc/Makefile

+2-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@ SRC = goto_cc_main.cpp goto_cc_mode.cpp gcc_mode.cpp \
22
gcc_cmdline.cpp ms_cl_cmdline.cpp ld_cmdline.cpp \
33
compile.cpp armcc_cmdline.cpp \
44
goto_cc_languages.cpp goto_cc_cmdline.cpp \
5-
ms_cl_mode.cpp armcc_mode.cpp cw_mode.cpp ld_mode.cpp
5+
ms_cl_mode.cpp armcc_mode.cpp cw_mode.cpp bcc_cmdline.cpp \
6+
as_mode.cpp as_cmdline.cpp as86_cmdline.cpp
67

78
OBJ += ../big-int/big-int$(LIBEXT) \
89
../goto-programs/goto-programs$(LIBEXT) \

src/goto-cc/armcc_mode.h

+4-2
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,10 @@ class armcc_modet:public goto_cc_modet
2020
virtual int doit();
2121
virtual void help_mode();
2222

23-
explicit armcc_modet(armcc_cmdlinet &_armcc_cmdline):
24-
goto_cc_modet(_armcc_cmdline),
23+
armcc_modet(
24+
armcc_cmdlinet &_armcc_cmdline,
25+
const std::string &_base_name):
26+
goto_cc_modet(_armcc_cmdline, _base_name),
2527
cmdline(_armcc_cmdline)
2628
{
2729
}

src/goto-cc/as86_cmdline.cpp

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

src/goto-cc/as86_cmdline.h

+27
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
/*******************************************************************\
2+
3+
Module: A special command line object for as86 (of Bruce's C Compiler)
4+
5+
Author: Michael Tautschnig
6+
7+
Date: July 2016
8+
9+
\*******************************************************************/
10+
11+
#ifndef CPROVER_GOTO_CC_AS86_CMDLINE_H
12+
#define CPROVER_GOTO_CC_AS86_CMDLINE_H
13+
14+
#include "goto_cc_cmdline.h"
15+
16+
class as86_cmdlinet:public goto_cc_cmdlinet
17+
{
18+
public:
19+
// overload
20+
virtual bool parse(int, const char**);
21+
22+
as86_cmdlinet()
23+
{
24+
}
25+
};
26+
27+
#endif // CPROVER_GOTO_CC_AS86_CMDLINE_H

0 commit comments

Comments
 (0)