Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
C
Chibicc
Manage
Activity
Members
Labels
Plan
Issues
0
Issue boards
Milestones
Wiki
Code
Merge requests
0
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
邓家琪
Chibicc
Commits
a1dd6213
Commit
a1dd6213
authored
4 years ago
by
Rui Ueyama
Browse files
Options
Downloads
Patches
Plain Diff
Add -I<dir> option
parent
d85fc4ff
Branches
Branches containing commit
No related merge requests found
Changes
6
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
Makefile
+2
-2
2 additions, 2 deletions
Makefile
chibicc.h
+1
-0
1 addition, 0 deletions
chibicc.h
main.c
+13
-1
13 additions, 1 deletion
main.c
preprocess.c
+16
-3
16 additions, 3 deletions
preprocess.c
self.py
+2
-0
2 additions, 0 deletions
self.py
test/driver.sh
+6
-0
6 additions, 0 deletions
test/driver.sh
with
40 additions
and
6 deletions
Makefile
+
2
−
2
View file @
a1dd6213
...
...
@@ -14,7 +14,7 @@ chibicc: $(OBJS)
$(OBJS)
:
chibicc.h
test/%.exe
:
chibicc test/%.c
./chibicc
-c
-o
test
/
$*
.o
test
/
$*
.c
./chibicc
-Itest
-c
-o
test
/
$*
.o
test
/
$*
.c
$(
CC
)
-o
$@
test
/
$*
.o
-xc
test
/common
test
:
$(TESTS)
...
...
@@ -35,7 +35,7 @@ stage2/%.o: chibicc self.py %.c
stage2/test/%.exe
:
stage2/chibicc test/%.c
mkdir
-p
stage2/test
./stage2/chibicc
-c
-o
stage2/test/
$*
.o
test
/
$*
.c
./stage2/chibicc
-Itest
-c
-o
stage2/test/
$*
.o
test
/
$*
.c
$(
CC
)
-o
$@
stage2/test/
$*
.o
-xc
test
/common
test-stage2
:
$(TESTS:test/%=stage2/test/%)
...
...
This diff is collapsed.
Click to expand it.
chibicc.h
+
1
−
0
View file @
a1dd6213
...
...
@@ -348,4 +348,5 @@ int align_to(int n, int align);
bool
file_exists
(
char
*
path
);
extern
StringArray
include_paths
;
extern
char
*
base_file
;
This diff is collapsed.
Click to expand it.
main.c
+
13
−
1
View file @
a1dd6213
#include
"chibicc.h"
StringArray
include_paths
;
static
bool
opt_E
;
static
bool
opt_S
;
static
bool
opt_c
;
...
...
@@ -19,7 +21,12 @@ static void usage(int status) {
}
static
bool
take_arg
(
char
*
arg
)
{
return
!
strcmp
(
arg
,
"-o"
);
char
*
x
[]
=
{
"-o"
,
"-I"
};
for
(
int
i
=
0
;
i
<
sizeof
(
x
)
/
sizeof
(
*
x
);
i
++
)
if
(
!
strcmp
(
arg
,
x
[
i
]))
return
true
;
return
false
;
}
static
void
parse_args
(
int
argc
,
char
**
argv
)
{
...
...
@@ -69,6 +76,11 @@ static void parse_args(int argc, char **argv) {
continue
;
}
if
(
!
strncmp
(
argv
[
i
],
"-I"
,
2
))
{
strarray_push
(
&
include_paths
,
argv
[
i
]
+
2
);
continue
;
}
if
(
!
strcmp
(
argv
[
i
],
"-cc1-input"
))
{
base_file
=
argv
[
++
i
];
continue
;
...
...
This diff is collapsed.
Click to expand it.
preprocess.c
+
16
−
3
View file @
a1dd6213
...
...
@@ -596,6 +596,19 @@ static bool expand_macro(Token **rest, Token *tok) {
return
true
;
}
static
char
*
search_include_paths
(
char
*
filename
)
{
if
(
filename
[
0
]
==
'/'
)
return
filename
;
// Search a file from the include paths.
for
(
int
i
=
0
;
i
<
include_paths
.
len
;
i
++
)
{
char
*
path
=
format
(
"%s/%s"
,
include_paths
.
data
[
i
],
filename
);
if
(
file_exists
(
path
))
return
path
;
}
return
NULL
;
}
// Read an #include argument.
static
char
*
read_include_filename
(
Token
**
rest
,
Token
*
tok
,
bool
*
is_dquote
)
{
// Pattern 1: #include "foo.h"
...
...
@@ -669,7 +682,7 @@ static Token *preprocess2(Token *tok) {
bool
is_dquote
;
char
*
filename
=
read_include_filename
(
&
tok
,
tok
->
next
,
&
is_dquote
);
if
(
filename
[
0
]
!=
'/'
)
{
if
(
filename
[
0
]
!=
'/'
&&
is_dquote
)
{
char
*
path
=
format
(
"%s/%s"
,
dirname
(
strdup
(
start
->
file
->
name
)),
filename
);
if
(
file_exists
(
path
))
{
tok
=
include_file
(
tok
,
path
,
start
->
next
->
next
);
...
...
@@ -677,8 +690,8 @@ static Token *preprocess2(Token *tok) {
}
}
// TODO: Search a file from the
include
paths
.
tok
=
include_file
(
tok
,
filename
,
start
->
next
->
next
);
char
*
path
=
search_
include
_
paths
(
filename
);
tok
=
include_file
(
tok
,
path
?
path
:
filename
,
start
->
next
->
next
);
continue
;
}
...
...
This diff is collapsed.
Click to expand it.
self.py
+
2
−
0
View file @
a1dd6213
...
...
@@ -95,6 +95,8 @@ FILE *open_memstream(char **ptr, size_t *sizeloc);
char *dirname(char *path);
char *strncpy(char *dest, char *src, long n);
int stat(char *pathname, struct stat *statbuf);
int stat(char *pathname, struct stat *statbuf);
char *dirname(char *path);
"""
)
for
path
in
sys
.
argv
[
1
:]:
...
...
This diff is collapsed.
Click to expand it.
test/driver.sh
+
6
−
0
View file @
a1dd6213
...
...
@@ -85,4 +85,10 @@ echo "#include \"$tmp/out1\"" | $chibicc -E -o $tmp/out2 -
cat
$tmp
/out2 |
grep
-q
foo
check
'-E and -o'
# -I
mkdir
$tmp
/dir
echo
foo
>
$tmp
/dir/i-option-test
echo
"#include
\"
i-option-test
\"
"
|
$chibicc
-I
$tmp
/dir
-E
- |
grep
-q
foo
check
-I
echo
OK
This diff is collapsed.
Click to expand it.
Preview
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment