Skip to content

Commit

Permalink
add many stmts
Browse files Browse the repository at this point in the history
  • Loading branch information
LFYSec committed May 30, 2020
1 parent 9711246 commit 220f9e2
Show file tree
Hide file tree
Showing 35 changed files with 548 additions and 660 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
test
.idea

.DS_Store
6 changes: 6 additions & 0 deletions .idea/vcs.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

59 changes: 34 additions & 25 deletions .idea/workspace.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Binary file modified Compiler
Binary file not shown.
35 changes: 0 additions & 35 deletions clangtest/1.c

This file was deleted.

35 changes: 0 additions & 35 deletions clangtest/1.l

This file was deleted.

18 changes: 0 additions & 18 deletions clangtest/t.c

This file was deleted.

1 change: 0 additions & 1 deletion main.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package main

import ini "Compiler/src/init"

// TODO add exception handler
func main() {
ini.Parse()
}
2 changes: 1 addition & 1 deletion src/ast/expression/rvalue/literal/charLiteral.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ func (c CharLiteral) GetType() global.SymbolType {
return c.Type
}

func CreateStrLiteral(value uint8) CharLiteral {
func CreateCharLiteral(value uint8) CharLiteral {
var charLiteral CharLiteral
charLiteral.Value = value
charLiteral.Type = global.CHAR_LITERAL
Expand Down
2 changes: 1 addition & 1 deletion src/ast/expression/rvalue/literal/doubleLiteral.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package doubleLiteral
package literal

import (
"Compiler/src/ast/expression/rvalue"
Expand Down
2 changes: 1 addition & 1 deletion src/ast/expression/rvalue/literal/intLiteral.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package intLiteral
package literal

import (
"Compiler/src/ast/expression/rvalue"
Expand Down
6 changes: 3 additions & 3 deletions src/ast/statement/function/funcall.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import (
"Compiler/src/ast/expression/lvalue"
"Compiler/src/ast/expression/lvalue/reference"
"Compiler/src/ast/expression/rvalue"
"Compiler/src/ast/expression/rvalue/intLiteral"
"Compiler/src/ast/expression/rvalue/literal"
stmt "Compiler/src/ast/statement"
st "Compiler/src/symbolTable"
"fmt"
Expand Down Expand Up @@ -33,8 +33,8 @@ func (f Funcall) GeneCode() {
// arg := i.(intLiteral.IntLiteral)
// funcArgs += fmt.Sprintf(argFormat, st.TypeString(arg.Type), strconv.Itoa(arg.Value))
//}
case intLiteral.IntLiteral:
arg := i.(intLiteral.IntLiteral)
case literal.IntLiteral:
arg := i.(literal.IntLiteral)
funcArgs += fmt.Sprintf(argFormat, st.TypeString(arg.Type), strconv.Itoa(arg.Value))
}
}
Expand Down
5 changes: 5 additions & 0 deletions src/ast/statement/print.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,11 @@ func (p PrintStmt) GeneCode() {
case global.DOUBLE_LITERAL:
fmt.Printf("call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.double, i32 0, i32 0), double %s)\n", ir)
break
case global.CHAR_LITERAL:
p := ir + "_c"
fmt.Printf("%s = sext i8 %s to i32\n", p, ir)
fmt.Printf("call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i32 0, i32 0), i32 %s)\n", p)
break
default:
break
}
Expand Down
36 changes: 36 additions & 0 deletions src/ast/statement/scan.go
Original file line number Diff line number Diff line change
@@ -1 +1,37 @@
package stmt

import (
"Compiler/src/ast/expression/rvalue"
"Compiler/src/global"
"fmt"
)

type ScanStmt struct {
Stmt
Expr rvalue.RValue
}

func (s ScanStmt) GeneCode() {
s.Expr.GeneRVCode()
ir := s.Expr.RvalueIR()
switch s.Expr.GetType() {
case global.INT_LITERAL:
fmt.Printf("call i32 (i8*, ...) @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.scan.int, i32 0, i32 0), i32* %s)\n", ir)
break
case global.DOUBLE_LITERAL:
fmt.Printf("call i32 (i8*, ...) @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.scan.double, i32 0, i32 0), double* %s)\n", ir)
break
case global.CHAR_LITERAL:
p := ir + "_c"
fmt.Printf("call i32 (i8*, ...) @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.scan, i32 0, i32 0), i8* %s)\n", p)
break
default:
break
}
}

func CreateScanStmt(rhs rvalue.RValue) ScanStmt {
var s ScanStmt
s.Expr = rhs
return s
}
70 changes: 36 additions & 34 deletions src/global/const.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,37 +6,39 @@ const TYPE = 57346
const IDENTIFY = 57347
const INT_LITERAL = 57348
const DOUBLE_LITERAL = 57349
const ARRAY = 57350
const STRING = 57351
const INT = 57352
const DOUBLE = 57353
const CHAR = 57354
const BOOL = 57355
const VOID = 57356
const IF = 57357
const ELSE = 57358
const WHILE = 57359
const FOR = 57360
const PRINT = 57361
const EOL = 57362
const RETURN = 57363
const EOS = 57364
const EQ = 57365
const NE = 57366
const LT = 57367
const LE = 57368
const GT = 57369
const GE = 57370
const ASSIGN = 57371
const COMMA = 57372
const ADD = 57373
const SUB = 57374
const MUL = 57375
const DIV = 57376
const NOT = 57377
const LBRACKET = 57378
const RBRACKET = 57379
const LPARENTHESIS = 57380
const RPARENTHESIS = 57381
const LBRACE = 57382
const RBRACE = 57383
const CHAR_LITERAL = 57350
const ARRAY = 57351
const STRING = 57352
const INT = 57353
const DOUBLE = 57354
const CHAR = 57355
const BOOL = 57356
const VOID = 57357
const IF = 57358
const ELSE = 57359
const WHILE = 57360
const FOR = 57361
const PRINT = 57362
const EOL = 57363
const RETURN = 57364
const EOS = 57365
const SCAN = 57366
const EQ = 57367
const NE = 57368
const LT = 57369
const LE = 57370
const GT = 57371
const GE = 57372
const ASSIGN = 57373
const COMMA = 57374
const ADD = 57375
const SUB = 57376
const MUL = 57377
const DIV = 57378
const NOT = 57379
const LBRACKET = 57380
const RBRACKET = 57381
const LPARENTHESIS = 57382
const RPARENTHESIS = 57383
const LBRACE = 57384
const RBRACE = 57385
Loading

0 comments on commit 220f9e2

Please sign in to comment.