-
Notifications
You must be signed in to change notification settings - Fork 78
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Generate file with file name #100
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -33,7 +33,11 @@ def main(): | |
if any(not obj for obj in objs): | ||
return 1 | ||
else: | ||
if not link("out", objs): | ||
# set the output ELF name | ||
out = "out" | ||
if arguments.output_name is not None: | ||
out = arguments.output_name | ||
if not link(out, objs): | ||
err = "linker returned non-zero status" | ||
print(CompilerError(err)) | ||
return 1 | ||
|
@@ -118,6 +122,12 @@ def get_arguments(): | |
parser.add_argument("-z-reg-alloc-perf", | ||
help="display register allocator performance info", | ||
dest="show_reg_alloc_perf", action="store_true") | ||
parser.add_argument( | ||
"-o", | ||
nargs="?", | ||
metavar="file", | ||
help="Place output into <file>", | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nitpicky: for consistency, could you make the first letter of the help string lowercase? |
||
dest="output_name") | ||
|
||
return parser.parse_args() | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -252,10 +252,21 @@ def parse_parameter_list(index): | |
if token_is(index, token_kinds.close_paren): | ||
return params, index | ||
|
||
# argument is void and is not function declaration | ||
if token_is(index, token_kinds.void_kw) \ | ||
and token_is(index + 1, token_kinds.close_paren): | ||
if token_is(index + 2, token_kinds.open_brack): | ||
return params, index + 1 | ||
elif token_is(index + 1, token_kinds.identifier): | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm a little confused by this code. Isn't the token at I think it would be easier to implement this in the semantic stage of the compiler (i.e. in the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Fix this on new pull request #102 |
||
err = "'void' must be the only parameter" | ||
raise_error(err, index, ParserError.AT) | ||
|
||
while True: | ||
# Try parsing declaration specifiers, quit if no more exist | ||
specs, index = parse_decl_specifiers(index) | ||
decl, index = parse_declarator(index) | ||
|
||
# New ast root | ||
params.append(decl_nodes.Root(specs, [decl])) | ||
|
||
# Expect a comma, and break if there isn't one | ||
|
@@ -357,8 +368,8 @@ def _find_decl_end(index): | |
greater than the last index in this declarator. | ||
""" | ||
if (token_is(index, token_kinds.star) or | ||
token_is(index, token_kinds.identifier) or | ||
token_is(index, token_kinds.const_kw)): | ||
token_is(index, token_kinds.identifier) or | ||
token_is(index, token_kinds.const_kw)): | ||
return _find_decl_end(index + 1) | ||
elif token_is(index, token_kinds.open_paren): | ||
close = _find_pair_forward(index) | ||
|
@@ -392,7 +403,7 @@ def _parse_declarator_raw(start, end, is_typedef): | |
return decl_nodes.Identifier(None) | ||
|
||
elif (start + 1 == end and | ||
p.tokens[start].kind == token_kinds.identifier): | ||
p.tokens[start].kind == token_kinds.identifier): | ||
p.symbols.add_symbol(p.tokens[start], is_typedef) | ||
return decl_nodes.Identifier(p.tokens[start]) | ||
|
||
|
@@ -402,7 +413,8 @@ def _parse_declarator_raw(start, end, is_typedef): | |
_parse_declarator(index, end, is_typedef), const) | ||
|
||
func_decl = _try_parse_func_decl(start, end, is_typedef) | ||
if func_decl: return func_decl | ||
if func_decl: | ||
return func_decl | ||
|
||
# First and last elements make a parenthesis pair | ||
elif (p.tokens[start].kind == token_kinds.open_paren and | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -600,6 +600,8 @@ def _generate_array_ctype(self, decl, prev_ctype): | |
|
||
def _generate_func_ctype(self, decl, prev_ctype): | ||
"""Generate a function ctype from a given a decl_node.""" | ||
# save identifiers | ||
identifiers = [] | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Could you do this more easily on line 546 instead? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Do you mean checking redefinition of identifier inside make_ctype? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Fix this on #104 |
||
|
||
# Prohibit storage class specifiers in parameters. | ||
for param in decl.args: | ||
|
@@ -608,6 +610,14 @@ def _generate_func_ctype(self, decl, prev_ctype): | |
err = "storage class specified for function parameter" | ||
raise CompilerError(err, decl_info.range) | ||
|
||
if decl_info.identifier: | ||
identifier = str(decl_info.identifier) | ||
if identifier not in identifiers: | ||
identifiers.append(str(decl_info.identifier)) | ||
else: | ||
err = f"redefinition of '{identifier}'" | ||
raise CompilerError(err, decl_info.range) | ||
|
||
# Create a new scope because if we create a new struct type inside | ||
# the function parameters, it should be local to those parameters. | ||
self.symbol_table.new_scope() | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If I am not mistaken, as written this will accept the command
shivyc -o
without warning or error. However, it appears GCC prints an error here, so we should do the same.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fix this on new pull request #101 .Code review is required.