Skip to content

Commit

Permalink
Implemented Single session (#1797)
Browse files Browse the repository at this point in the history
* Still working

* Implemented single-session and configurations for session type

* Finalizaing single-session

* Resolved comments

* Got rid of dead code
  • Loading branch information
kadenlei committed Dec 5, 2023
1 parent 7550493 commit dfd45c6
Show file tree
Hide file tree
Showing 5 changed files with 135 additions and 131 deletions.
191 changes: 84 additions & 107 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
@@ -1,108 +1,85 @@
{
"version": "0.2.0",
"configurations": [
{
"type": "cider-dap",
"request": "launch",
"name": "Launch Program (Multi Session)",
"program": "${file}",
"stopOnEntry": true,
},
{
"type": "cider-dap",
"request": "launch",
"name": "Launch Program",
"program": "${workspaceFolder}/Program"
},
{
"name": "Python: Current File",
"type": "python",
"request": "launch",
"program": "${file}",
"console": "integratedTerminal",
"justMyCode": false
},
{
"type": "lldb",
"request": "launch",
"name": "Debug Compiler",
"args": [
"${input:target}",
"-l",
"${workspaceFolder}",
"-p",
"${input:pass}",
"-b",
"${input:backend}",
],
"program": "${workspaceFolder}/target/debug/calyx",
"cwd": "${workspaceFolder}",
"stopOnEntry": false,
"sourceLanguages": [
"rust"
],
"preLaunchTask": "Cargo Build",
"console": "integratedTerminal",
},
{
"type": "lldb",
"request": "launch",
"name": "Debug Interpreter",
"args": [
"${input:target}",
"-l",
"${workspaceFolder}"
],
"program": "${workspaceFolder}/target/debug/cider",
"windows": {
"program": "${workspaceFolder}/target/debug/cider.exe"
},
"cwd": "${workspaceFolder}",
"stopOnEntry": false,
"sourceLanguages": [
"rust"
],
},
{
"type": "lldb",
"request": "launch",
"name": "Debug Interpreter on current file",
"args": [
"${file}",
"-l",
"${workspaceFolder}"
],
"program": "${workspaceFolder}/target/debug/cider",
"windows": {
"program": "${workspaceFolder}/target/debug/cider.exe"
},
"cwd": "${workspaceFolder}",
"stopOnEntry": false,
"sourceLanguages": [
"rust"
],
}
],
"inputs": [
{
"id": "target",
"type": "promptString",
"description": "Target file"
},
{
"id": "pass",
"type": "promptString",
"description": "Pass to be executed by the compiler (only one allowed)",
"default": "all"
},
{
"id": "backend",
"type": "pickString",
"description": "Backend to be used by the compiler",
"options": [
"verilog",
"calyx",
],
}
]
}
"version": "0.2.0",
"configurations": [
{
"type": "cider-dap",
"request": "launch",
"name": "Debug w/ Cider",
"program": "${file}",
"stopOnEntry": true
},
{
"name": "Python: Current File",
"type": "python",
"request": "launch",
"program": "${file}",
"console": "integratedTerminal",
"justMyCode": false
},
{
"type": "lldb",
"request": "launch",
"name": "Debug Compiler",
"args": [
"${input:target}",
"-l",
"${workspaceFolder}",
"-p",
"${input:pass}",
"-b",
"${input:backend}"
],
"program": "${workspaceFolder}/target/debug/calyx",
"cwd": "${workspaceFolder}",
"stopOnEntry": false,
"sourceLanguages": ["rust"],
"preLaunchTask": "Cargo Build",
"console": "integratedTerminal"
},
{
"type": "lldb",
"request": "launch",
"name": "Debug Interpreter",
"args": ["${input:target}", "-l", "${workspaceFolder}"],
"program": "${workspaceFolder}/target/debug/cider",
"windows": {
"program": "${workspaceFolder}/target/debug/cider.exe"
},
"cwd": "${workspaceFolder}",
"stopOnEntry": false,
"sourceLanguages": ["rust"]
},
{
"type": "lldb",
"request": "launch",
"name": "Debug Interpreter on current file",
"args": ["${file}", "-l", "${workspaceFolder}"],
"program": "${workspaceFolder}/target/debug/cider",
"windows": {
"program": "${workspaceFolder}/target/debug/cider.exe"
},
"cwd": "${workspaceFolder}",
"stopOnEntry": false,
"sourceLanguages": ["rust"]
}
],
"inputs": [
{
"id": "target",
"type": "promptString",
"description": "Target file"
},
{
"id": "pass",
"type": "promptString",
"description": "Pass to be executed by the compiler (only one allowed)",
"default": "all"
},
{
"id": "backend",
"type": "pickString",
"description": "Backend to be used by the compiler",
"options": ["verilog", "calyx"]
}
]
}
4 changes: 2 additions & 2 deletions cider-dap/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ the cider-dap binary somewhere on your path. From some directory on your PATH:
ln -s <PATH TO CALYX ROOT>/target/debug/cider-dap
```

You will have to configure user settings of cider-dap in VSCode and input your cider binary path and port number. You can then launch the adapter with the Launch Program (Multi Session) action
You will have to configure user settings of cider-dap in VSCode and input your cider binary path, session type, and port number (if debug adapter is started as a server). You can then launch the adapter with the Launch Program (Multi Session) action.

## Known issues

Expand All @@ -40,7 +40,7 @@ This project primarily leverages the Debug Adapter Protocol (DAP) for its functi
&nbsp; &nbsp; &nbsp; &nbsp; `adapter.rs`: Defines the primary adapter structure for the project and its associated functionalities. Not just any adapter, this file structures the fundamental protocols, handling the translation of high-level debugging commands into actionable, low-level instructions. <br>
&nbsp; &nbsp; &nbsp; &nbsp; `error.rs`: Contains custom error definitions and types for better error handling. <br>
&nbsp; &nbsp; &nbsp; &nbsp; `main.rs`: The entry point for the project, it integrates functionalities from the other source files and provides the main execution logic. <br> 4. `calyxDebug` directory: <br>
&nbsp; &nbsp; &nbsp; &nbsp; `extension.js`: JavaScript file for VSCode extension integration. It provides functions to interface between the VSCode environment and the Rust backend. <br>
&nbsp; &nbsp; &nbsp; &nbsp; `extension.ts`: TypeScript file for VSCode extension integration. It provides functions to interface between the VSCode environment and the Rust backend. <br>

### About main.rs: the Main File

Expand Down
47 changes: 36 additions & 11 deletions cider-dap/calyxDebug/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,8 @@ async function getProgramName() {
}
}

class CiderDebugAdapterDescriptorFactory {
// Factory for multi-session
class CiderDebugAdapterDescriptorFactoryServer {
adapter: CiderDebugAdapter;
adapterPath: string;
workspace: string;
Expand Down Expand Up @@ -97,7 +98,7 @@ class CiderDebugAdapter {
// Include the port as a command line argument
this.adapterProcess = cp.spawn(
this.adapterPath,
[programName, "--port", port, "--tcp"],
["--port", port, "--tcp"],
{ cwd: this.cwd }
);

Expand Down Expand Up @@ -128,25 +129,49 @@ class CiderDebugAdapter {
}
}

// Factory for single-session
class CiderDebugAdapterDescriptorFactoryExecutable {
createDebugAdapterDescriptor(_session) {
// Use the DebugAdapterExecutable as the debug adapter descriptor
console.log("inside adapter factory");
console.log(vscode.workspace.getConfiguration("cider-dap").path);

return new vscode.DebugAdapterExecutable(
vscode.workspace.getConfiguration("cider-dap").path,
[programName],
{ cwd: vscode.workspace.rootPath }
);
}
}

function activate(context) {
logToPanel("Extension activated!");

// Start the debug server explicitly
const factory = new CiderDebugAdapterDescriptorFactory(
vscode.workspace.getConfiguration("cider-dap").path,
vscode.workspace.rootPath,
outputChannel
);
let factory: vscode.DebugAdapterDescriptorFactory;

// Get session type (multi or single) from package.json configuration
switch (vscode.workspace.getConfiguration("cider-dap").sessionType) {
case "Multi-Session":
factory = new CiderDebugAdapterDescriptorFactoryServer(
vscode.workspace.getConfiguration("cider-dap").path,
vscode.workspace.rootPath,
outputChannel
);
break;

case "Single-Session":
default:
factory = new CiderDebugAdapterDescriptorFactoryExecutable();
break;
}

context.subscriptions.push(
vscode.debug.registerDebugAdapterDescriptorFactory("cider-dap", factory)
);
logToPanel("after start server");

// Update the adapter path with the serverPort and use it for starting the debug adapter
logToPanel("before startDebugging");
/* context.subscriptions.push(vscode.commands.registerCommand('cider.startDebugging', startDebugging));
context.subscriptions.push(vscode.commands.registerCommand('cider.stopDebugging', stopDebugging));
*/
logToPanel("Hello, your extension is now activated!");
}

Expand Down
12 changes: 12 additions & 0 deletions cider-dap/calyxDebug/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,18 @@
"scope": "machine",
"default": 8888,
"description": "Port number"
},
"cider-dap.sessionType": {
"type": "string",
"default": "Single-Session",
"enum": [
"Single-Session",
"Multi-Session"
],
"enumDescriptions": [
"Runs the debugger in single-session",
"Runs the debugger in multi-session"
]
}
}
}
Expand Down
12 changes: 1 addition & 11 deletions cider-dap/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,28 +14,20 @@ use error::AdapterResult;
use std::fs::File;
use std::io::{stdin, stdout, BufReader, BufWriter, Read, Write};
use std::net::TcpListener;
use std::path::PathBuf;

#[derive(argh::FromArgs)]
/// Positional arguments for file path
struct Opts {
/// input file
#[argh(positional, from_str_fn(read_path))]
file: Option<PathBuf>,
#[argh(switch, long = "tcp")]
/// runs in tcp mode
is_multi_session: bool,
#[argh(option, short = 'p', long = "port", default = "8080")]
/// port for the TCP server
port: u16,
}
fn read_path(path: &str) -> Result<PathBuf, String> {
Ok(PathBuf::from(path))
}

fn main() -> Result<(), MyAdapterError> {
let opts: Opts = argh::from_env();

if opts.is_multi_session {
eprintln!("running multi-session");
let listener = TcpListener::bind(("127.0.0.1", opts.port))?;
Expand All @@ -52,13 +44,11 @@ fn main() -> Result<(), MyAdapterError> {
// Run the server using the adapter
run_server(&mut server, adapter)?;
} else {
let path = opts.file.ok_or(MyAdapterError::MissingFile)?;
let file = File::open(path)?;
let adapter = MyAdapter::new(file);
eprintln!("running single-session");
let write = BufWriter::new(stdout());
let read = BufReader::new(stdin());
let mut server = Server::new(read, write);
let adapter = multi_session_init(&mut server)?;
run_server(&mut server, adapter)?;
}
eprintln!("exited run_Server");
Expand Down

0 comments on commit dfd45c6

Please sign in to comment.