Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
cs24-19fa
project03
Commits
a440a0d0
Commit
a440a0d0
authored
4 years ago
by
Caleb C. Sander
Browse files
Options
Download
Email Patches
Plain Diff
Add clang-format
parent
467487ec
Pipeline
#38898
failed with stage
Changes
10
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
10 changed files
.clang-format
+19
-0
.clang-format
.githooks/pre-commit
+12
-0
.githooks/pre-commit
include/ast.h
+1
-10
include/ast.h
include/parser.h
+2
-0
include/parser.h
runtime/print_int.c
+5
-4
runtime/print_int.c
runtime/timing.c
+4
-6
runtime/timing.c
src/ast.c
+2
-2
src/ast.c
src/compile.c
+3
-3
src/compile.c
src/compiler.c
+4
-7
src/compiler.c
src/parser.c
+6
-6
src/parser.c
with
58 additions
and
38 deletions
+58
-38
.clang-format
0 → 100644
View file @
a440a0d0
---
# We'll use defaults from the Google style, but with 4 columns indentation.
BasedOnStyle: Google
# Never allow single-line functions
AllowShortFunctionsOnASingleLine: None
# Put "else" on a new line
BreakBeforeBraces: Custom
BraceWrapping:
BeforeElse: true
# Allow lines up to 90 characters
ColumnLimit: 90
# Indent each block by 4 spaces
IndentWidth: 4
TabWidth: 4
# Require 1 space before a comment on the same line
SpacesBeforeTrailingComments: 1
# Put a space after a cast, e.g. `(void) arg;`
SpaceAfterCStyleCast: true
---
This diff is collapsed.
Click to expand it.
.githooks/pre-commit
0 → 100755
View file @
a440a0d0
#!/bin/bash
if
loc
=
"
$(
type
-p
"clang-format"
)
"
&&
[[
-x
$loc
]]
;
then
for
name
in
$(
git diff
--cached
--name-only
--diff-filter
=
ACM
)
;
do
if
echo
$name
|
grep
-Eq
"
\.
[ch]$"
;
then
echo
"Formatting
${
name
}
..."
clang-format
-i
$name
fi
done
else
echo
"You do not have clang-format installed; so, we were unable to unify the formatting in your files."
fi
This diff is collapsed.
Click to expand it.
include/ast.h
View file @
a440a0d0
...
...
@@ -11,16 +11,7 @@
#include <stdint.h>
/** The types of AST nodes */
typedef
enum
{
NUM
,
BINARY_OP
,
VAR
,
SEQUENCE
,
PRINT
,
LET
,
IF
,
WHILE
}
node_type_t
;
typedef
enum
{
NUM
,
BINARY_OP
,
VAR
,
SEQUENCE
,
PRINT
,
LET
,
IF
,
WHILE
}
node_type_t
;
/** The type of a TeenyBASIC variable name */
typedef
char
var_name_t
;
...
...
This diff is collapsed.
Click to expand it.
include/parser.h
View file @
a440a0d0
#ifndef PARSER_H
#define PARSER_H
#include <stdio.h>
#include "ast.h"
/** Parses the next statement from the provided TeenyBASIC file into an AST */
...
...
This diff is collapsed.
Click to expand it.
runtime/print_int.c
View file @
a440a0d0
#include <inttypes.h>
#include <stdio.h>
#include "ast.h"
// A function that can be called from assembly to print an integer
void
print_int
(
value_t
value
)
{
printf
(
"%"
PRId64
"
\n
"
,
value
);
// Clobber all caller-save registers
asm
(
"movq $0x6A2CFE91073BD845, %%rax
\n
"
asm
(
"movq $0x6A2CFE91073BD845, %%rax
\n
"
"movq $0x03BAD7C14F2E6589, %%rdi
\n
"
"movq $0x5D41EA960C72F8B3, %%rsi
\n
"
"movq $0xEC364B2D5A7F9810, %%rdx
\n
"
...
...
@@ -16,6 +16,7 @@ void print_int(value_t value) {
"movq $0x92E1587A4BDCF630, %%r9
\n
"
"movq $0x47DC36501F89AEB2, %%r10
\n
"
"movq $0xAF4B29785C61ED30, %%r11
\n
"
:
:
:
"rax"
,
"rdi"
,
"rsi"
,
"rdx"
,
"rcx"
,
"r8"
,
"r9"
,
"r10"
,
"r11"
);
:
:
:
"rax"
,
"rdi"
,
"rsi"
,
"rdx"
,
"rcx"
,
"r8"
,
"r9"
,
"r10"
,
"r11"
);
}
This diff is collapsed.
Click to expand it.
runtime/timing.c
View file @
a440a0d0
#include <assert.h>
#include <math.h>
#include <stdint.h>
#include <stdlib.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>
...
...
@@ -51,9 +51,7 @@ int main(int argc, char *argv[]) {
printf
(
"test_name,mean_log_duration,variance_log_duration
\n
"
"%s,%f,%e
\n
"
,
test_name
,
mean_log_duration
,
variance_log_duration
);
fprintf
(
stderr
,
"%s mean duration: %e seconds (+/- %e x)
\n
"
,
test_name
,
exp
(
mean_log_duration
),
expm1
(
sqrt
(
variance_log_duration
))
);
test_name
,
mean_log_duration
,
variance_log_duration
);
fprintf
(
stderr
,
"%s mean duration: %e seconds (+/- %e x)
\n
"
,
test_name
,
exp
(
mean_log_duration
),
expm1
(
sqrt
(
variance_log_duration
)));
}
This diff is collapsed.
Click to expand it.
src/ast.c
View file @
a440a0d0
#include "ast.h"
#include <assert.h>
#include <inttypes.h>
#include <stdbool.h>
#include <stdio.h>
#include <stdlib.h>
#include "ast.h"
node_t
*
init_num_node
(
value_t
value
)
{
num_node_t
*
node
=
malloc
(
sizeof
(
num_node_t
));
assert
(
node
!=
NULL
);
...
...
This diff is collapsed.
Click to expand it.
src/compile.c
View file @
a440a0d0
#include <stdlib.h>
#include <stdio.h>
#include "compile.h"
#include <stdio.h>
#include <stdlib.h>
bool
compile_ast
(
node_t
*
node
)
{
/* You should remove this cast to void in your solution.
* It is just here so the code compiles without warnings. */
...
...
This diff is collapsed.
Click to expand it.
src/compiler.c
View file @
a440a0d0
#include <stdlib.h>
#include <stdio.h>
#include <stdlib.h>
#include "parser.h"
#include "compile.h"
#include "parser.h"
void
usage
(
char
*
program
)
{
fprintf
(
stderr
,
"USAGE: %s <program file>
\n
"
,
program
);
...
...
@@ -20,8 +20,7 @@ void header(void) {
".text
\n
"
".globl basic_main
\n
"
"basic_main:
\n
"
" # The main() function
\n
"
);
" # The main() function
\n
"
);
}
/**
...
...
@@ -30,9 +29,7 @@ void header(void) {
* goes between the header and the footer.
*/
void
footer
(
void
)
{
printf
(
" ret
\n
"
);
printf
(
" ret
\n
"
);
}
int
main
(
int
argc
,
char
*
argv
[])
{
...
...
This diff is collapsed.
Click to expand it.
src/parser.c
View file @
a440a0d0
#include "parser.h"
#include <assert.h>
#include <ctype.h>
#include <errno.h>
...
...
@@ -6,8 +8,6 @@
#include <stdlib.h>
#include <string.h>
#include "parser.h"
// maxint = -9223372036854775808
const
size_t
MAX_KEYWORD_LENGTH
=
100
;
const
value_t
DEFAULT_STEP
=
1
;
...
...
@@ -35,8 +35,8 @@ bool is_comparison_op(char c) {
return
c
==
'<'
||
c
==
'='
||
c
==
'>'
;
}
bool
is_operator
(
char
c
)
{
return
is_open_paren
(
c
)
||
is_close_paren
(
c
)
||
is_factor_op
(
c
)
||
is_term_op
(
c
)
||
is_comparison_op
(
c
);
return
is_open_paren
(
c
)
||
is_close_paren
(
c
)
||
is_factor_op
(
c
)
||
is_term_op
(
c
)
||
is_comparison_op
(
c
);
}
bool
is_comment_start
(
char
c
)
{
return
c
==
'#'
;
...
...
@@ -340,7 +340,7 @@ node_t *sequence(parser_state_t *state) {
if
(
statement_count
==
statement_capacity
)
{
statement_capacity
=
statement_capacity
>
0
?
statement_capacity
*
2
:
1
;
statements
=
realloc
(
statements
,
sizeof
(
node_t
*
[
statement_capacity
]));
statements
=
realloc
(
statements
,
sizeof
(
node_t
*
[
statement_capacity
]));
assert
(
statements
!=
NULL
);
}
statements
[
statement_count
++
]
=
next
;
...
...
@@ -354,7 +354,7 @@ node_t *sequence(parser_state_t *state) {
}
if
(
statement_count
>
0
)
{
statements
=
realloc
(
statements
,
sizeof
(
node_t
*
[
statement_count
]));
statements
=
realloc
(
statements
,
sizeof
(
node_t
*
[
statement_count
]));
assert
(
statements
!=
NULL
);
}
return
init_sequence_node
(
statement_count
,
statements
);
...
...
This diff is collapsed.
Click to expand it.
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment
Menu
Projects
Groups
Snippets
Help