-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.go
More file actions
95 lines (77 loc) · 2.44 KB
/
main.go
File metadata and controls
95 lines (77 loc) · 2.44 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
package main
import (
controllers "architecture/ws/services/IO"
"architecture/ws/services/alu"
"architecture/ws/services/bus"
"architecture/ws/services/controlunit"
"architecture/ws/services/memory"
"log"
"github.com/gin-gonic/gin"
)
func main() {
// Initialize registers, memory, ALU, and bus
registers := memory.NewRegister()
memory := memory.NewMemory()
alu := alu.NewALU()
dataBus := bus.NewDataBus()
controlUnit := controlunit.NewControlUnit(dataBus, registers, memory, alu)
// Initialize Gin router
r := gin.Default()
controller := controllers.NewController(controlUnit)
// Define routes
r.GET("/fetch", controller.Fetch)
r.GET("/decode", controller.Decode)
r.GET("/execute", controller.Execute)
r.GET("/run_cycle", controller.RunCycle)
r.POST("/load_instruction", controller.LoadInstruction)
r.POST("/load_instructions", controller.LoadInstructions)
r.POST("/write/register", controller.WriteRegister)
r.GET("/memory/read/:address", controller.ReadMemory)
// curl -X GET "http://localhost:8080/register/read?register=AC"
r.GET("/register/read", controller.ReadRegister)
// Run the server
if err := r.Run(":8080"); err != nil {
log.Fatal("Unable to start the server: ", err)
}
}
// package main
// import (
// "architecture/initializers"
// controllers "architecture/ws/services/IO"
// "architecture/ws/services/alu"
// "architecture/ws/services/bus"
// "architecture/ws/services/controlunit"
// "architecture/ws/services/memory"
// "log"
// "os"
// "github.com/gin-gonic/gin"
// )
// func init() {
// initializers.LoadEnvVariables()
// }
// func main() {
// registers := memory.NewRegister()
// memory := memory.NewMemory()
// alu := alu.NewALU()
// dataBus := bus.NewDataBus()
// controlUnit := controlunit.NewControlUnit(dataBus, registers, memory, alu)
// controller := controllers.NewController(controlUnit)
// port := os.Getenv("PORT")
// if port == "" {
// port = "3001"
// }
// r := gin.Default()
// r.GET("/fetch", controller.Fetch)
// r.GET("/decode", controller.Decode)
// r.GET("/execute", controller.Execute)
// r.GET("/run_cycle", controller.RunCycle)
// r.POST("/load_instruction", controller.LoadInstruction)
// r.POST("/load_instructions", controller.LoadInstructions)
// // r := gin.Default()
// router := gin.New()
// router.Use(gin.Logger())
// // io.BulkWriteInMemoryRoutes(router)
// if err := router.Run(":" + port); err != nil {
// log.Fatalf("Error starting server: %v", err)
// }
// }