Skip to content

Commit

Permalink
fix quartus path, formatter and schematic
Browse files Browse the repository at this point in the history
  • Loading branch information
qarlosalberto committed Sep 27, 2024
1 parent 8727d6b commit 85802fb
Show file tree
Hide file tree
Showing 17 changed files with 2,021 additions and 46 deletions.
2 changes: 1 addition & 1 deletion auto_package/templates/info.nj
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"displayName": "TerosHDL",
"publisher": "teros-technology",
"description": "Powerful toolbox for ASIC/FPGA: state machine viewer, linter, documentation, snippets... and more! ",
"version": "6.0.6",
"version": "6.0.7",
"engines": {
"vscode": "^1.74.0"
},
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"displayName": "TerosHDL",
"publisher": "teros-technology",
"description": "Powerful toolbox for ASIC/FPGA: state machine viewer, linter, documentation, snippets... and more! ",
"version": "6.0.6",
"version": "6.0.7",
"engines": {
"vscode": "^1.74.0"
},
Expand Down
2 changes: 1 addition & 1 deletion src/colibri/commands/teroshdl/formatter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,7 @@ export default class MyCLI extends Command {
const current_code = file_utils.read_file_sync(filename);
const formatted_code =
(await formatter_manager.format_from_code(get_formatter_name(formatter_name), current_code,
formatter_options)).code_formatted;
formatter_options, python_path)).code_formatted;
let error = false;
if (current_code !== formatted_code) {
error = true;
Expand Down
4 changes: 2 additions & 2 deletions src/colibri/formatter/base_formatter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,12 @@ import * as cfg from "../config/config_declaration";
export abstract class Base_formatter {
abstract format_from_code(code: string, opt: cfg.e_formatter_istyle |
cfg.e_formatter_standalone | cfg.e_formatter_s3sv | cfg.e_formatter_svg |
common.e_formatter_verible_full
common.e_formatter_verible_full, python_path: string
): Promise<common.f_result>;

abstract format(file: string, opt: cfg.e_formatter_istyle |
cfg.e_formatter_standalone | cfg.e_formatter_s3sv | cfg.e_formatter_svg |
common.e_formatter_verible_full
common.e_formatter_verible_full, python_path: string
): Promise<common.f_result>;
}

1,273 changes: 1,273 additions & 0 deletions src/colibri/formatter/bin/s3sv/verilog_beautifier.py

Large diffs are not rendered by default.

643 changes: 643 additions & 0 deletions src/colibri/formatter/bin/s3sv/verilogutil.py

Large diffs are not rendered by default.

8 changes: 4 additions & 4 deletions src/colibri/formatter/formatter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,15 +55,15 @@ export class Formatter {
* @param {string} code Code to format
* @param {any} opt Formatter options
*/
async format_from_code(formatter_name: common.t_formatter_name, code: string, opt: any)
async format_from_code(formatter_name: common.t_formatter_name, code: string, opt: any, python_path: string)
: Promise<common.f_result> {
const formatter = this.get_formatter(formatter_name);
return formatter.format_from_code(code, opt);
return formatter.format_from_code(code, opt, python_path);
}

async format_from_file(formatter_name: common.t_formatter_name, file_path: string, opt: any)
async format_from_file(formatter_name: common.t_formatter_name, file_path: string, opt: any, python_path: string)
: Promise<common.f_result> {
const formatter = this.get_formatter(formatter_name);
return formatter.format(file_path, opt);
return formatter.format(file_path, opt, python_path);
}
}
6 changes: 3 additions & 3 deletions src/colibri/formatter/istyle.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,9 @@ export class Istyle extends Base_formatter {
super();
}

public async format_from_code(code: string, opt: cfg.e_formatter_istyle): Promise<common.f_result> {
public async format_from_code(code: string, opt: cfg.e_formatter_istyle, python_path: string): Promise<common.f_result> {
const temp_file = await utils.create_temp_file(code);
const formatted_code = await this.format(temp_file, opt);
const formatted_code = await this.format(temp_file, opt, python_path);
file_utils.remove_file(temp_file);
return formatted_code;
}
Expand All @@ -57,7 +57,7 @@ export class Istyle extends Base_formatter {
}
}

public async format(file: string, opt: cfg.e_formatter_istyle) {
public async format(file: string, opt: cfg.e_formatter_istyle, _python_path: string) {
const binary_name = this.get_binary();
const path_bin = path_lib.join(__dirname, 'bin', 'svistyle', binary_name);
const path_bin_norm = file_utils.normalize_path(path_bin);
Expand Down
53 changes: 49 additions & 4 deletions src/colibri/formatter/s3sv.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,59 @@ import * as common from "./common";
import * as cfg from "../config/config_declaration";
import * as logger from "../logger/logger";
import {Pyodide} from "../process/pyodide";
import * as python from "../process/python";
import * as fs from 'fs';
import { create_temp_file, } from "../process/utils";
import { remove_file } from "../utils/file_utils";

export class S3sv extends Base_formatter {
constructor() {
super();
}

public async format_from_code(code: string, opt: cfg.e_formatter_s3sv): Promise<common.f_result> {
return await this.format_from_code_with_pyodide(code, opt);
public async format_from_code(code: string, opt: cfg.e_formatter_s3sv, python_path: string): Promise<common.f_result> {
const tempFile = create_temp_file(code);
const result = await this.format_from_file_with_python(tempFile, opt, python_path);
remove_file(tempFile);
return result;
}

public async format_from_file_with_python(file: string, opt: cfg.e_formatter_s3sv, python_path: string) {
const python_script = path_lib.join(__dirname, 'bin', 's3sv', 'verilog_beautifier.py');
//Argument construction from members parameters
let args = " ";

args += `-s ${opt.indentation_size} `;
if (opt.use_tabs) {
args += "--use-tabs ";
}
if (!opt.one_bind_per_line) {
args += "--no-oneBindPerLine ";
}

if (opt.one_declaration_per_line) {
args += "--oneDeclPerLine ";
}
args += `-i ${file}`;

const command = `${python_path} ${python_script} ${args}`;
const msg = `Formatting with command: ${command} `;
logger.Logger.log(msg);

const result_p = await python.exec_python_script(python_path, python_script, args);

const result_f: common.f_result = {
code_formatted: "",
command: result_p.command,
successful: result_p.successful,
message: ""
};

if (result_p.successful === true) {
const code_formatted = fs.readFileSync(file, 'utf8');
result_f.code_formatted = code_formatted;
}
return result_f;
}

public async format_from_code_with_pyodide(code: string, opt: cfg.e_formatter_s3sv): Promise<common.f_result> {
Expand Down Expand Up @@ -64,12 +109,12 @@ export class S3sv extends Base_formatter {
return formatter_result;
}

public async format(file: string, opt: cfg.e_formatter_s3sv) {
public async format(file: string, opt: cfg.e_formatter_s3sv, python_path: string) {
const msg = `Formatting with command s3sv `;
logger.Logger.log(msg);

const code = read_file_sync(file);
const result_f = await this.format_from_code(code, opt);
const result_f = await this.format_from_code(code, opt, python_path);

return result_f;
}
Expand Down
6 changes: 3 additions & 3 deletions src/colibri/formatter/standalone_vhdl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ export class Standalone_vhdl extends Base_formatter {
super();
}

public async format_from_code(code: string, opt: cfg.e_formatter_standalone): Promise<common.f_result> {
public async format_from_code(code: string, opt: cfg.e_formatter_standalone, _python_path: string): Promise<common.f_result> {
try {
const code_formatted = <string>beautify(code, this.get_settings(opt));
const result: common.f_result = {
Expand All @@ -49,9 +49,9 @@ export class Standalone_vhdl extends Base_formatter {
}
}

public async format(file: string, opt: cfg.e_formatter_standalone): Promise<common.f_result> {
public async format(file: string, opt: cfg.e_formatter_standalone, python_path: string): Promise<common.f_result> {
const file_content = file_utils.read_file_sync(file);
const result = this.format_from_code(file_content, opt);
const result = this.format_from_code(file_content, opt, python_path);
return result;
}

Expand Down
6 changes: 3 additions & 3 deletions src/colibri/formatter/verible.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,9 @@ export class Verible extends Base_formatter {
super();
}

async format_from_code(code: string, opt: common.e_formatter_verible_full): Promise<common.f_result> {
async format_from_code(code: string, opt: common.e_formatter_verible_full, python_path: string): Promise<common.f_result> {
const temp_file = await utils.create_temp_file(code);
const formatted_code = await this.format(temp_file, opt);
const formatted_code = await this.format(temp_file, opt, python_path);
file_utils.remove_file(temp_file);
return formatted_code;
}
Expand All @@ -58,7 +58,7 @@ export class Verible extends Base_formatter {
return '';
}

public async format(file: string, opt: common.e_formatter_verible_full) {
public async format(file: string, opt: common.e_formatter_verible_full, _python_path: string) {
const path_bin = await this.get_path(opt.path);
const command = `${path_bin} --inplace ${opt.format_args} "${file}"`;

Expand Down
6 changes: 3 additions & 3 deletions src/colibri/formatter/vsg.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,14 +33,14 @@ export class Vsg extends Base_formatter {
super();
}

async format_from_code(code: string, opt: cfg.e_formatter_svg): Promise<common.f_result> {
async format_from_code(code: string, opt: cfg.e_formatter_svg, python_path: string): Promise<common.f_result> {
const temp_file = await utils.create_temp_file(code);
const formatted_code = await this.format(temp_file, opt);
const formatted_code = await this.format(temp_file, opt, python_path);
file_utils.remove_file(temp_file);
return formatted_code;
}

public async format(file: string, opt: cfg.e_formatter_svg) {
public async format(file: string, opt: cfg.e_formatter_svg, _python_path: string) {
let command = `${this.binary} ${opt.aditional_arguments} -p ${opt.core_number} --fix -f ${file}`;
if (opt.configuration !== ""){
// eslint-disable-next-line max-len
Expand Down
13 changes: 9 additions & 4 deletions src/colibri/project_manager/tool/quartus/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ function getBinFolder(): string {
* Get Quartus binary directory.
* @returns Quartus binary directory.
**/
export function getQuartusPath(config: e_config): string {
export function getQuartusPath(config: e_config, emitterProject?: ProjectEmitter): string {
// Try with config installation path
let quartusInstallationPath = config.tools.quartus.installation_path;
if (quartusInstallationPath !== "") {
Expand All @@ -84,11 +84,16 @@ export function getQuartusPath(config: e_config): string {
}

const quartusBinPath = path_lib.join(quartusInstallationPath, "quartus");
if (file_utils.check_if_path_exist(quartusBinPath)) {
if (file_utils.check_if_path_exist(quartusBinPath) || file_utils.check_if_path_exist(quartusBinPath + ".exe")) {
return normalizePath(quartusInstallationPath);
}

if (emitterProject !== undefined) {
emitterProject.emitEventLog(`Checking if quartus bin available at ${quartusBinPath}`, e_event.STDOUT_INFO);
}
}


// Try with environment variable QUARTUS_ROOTDIR
const QUARTUS_ROOTDIR = process.env.QUARTUS_ROOTDIR;
if (QUARTUS_ROOTDIR !== undefined && QUARTUS_ROOTDIR !== "") {
Expand Down Expand Up @@ -133,7 +138,7 @@ async function executeQuartusTcl(is_sta: boolean, config: e_config, tcl_file: st
if (is_sta) {
binaryName = "quartus_sta";
}
const quartus_bin = path_lib.join(getQuartusPath(config), binaryName);
const quartus_bin = path_lib.join(getQuartusPath(config, emitterProject), binaryName);

// Create temp file for out.csv
const csv_file = process_utils.create_temp_file("");
Expand Down Expand Up @@ -516,7 +521,7 @@ export function cleanProject(projectName: string, config: e_config, projectPath:
const tclFile = process_utils.create_temp_file(templateRender);
const args = `"${projectPath}"`;

const quartus_bin = path_lib.join(getQuartusPath(config), "quartus_sh");
const quartus_bin = path_lib.join(getQuartusPath(config, emitter), "quartus_sh");

// Create temp file for out.csv
const csv_file = process_utils.create_temp_file("");
Expand Down
24 changes: 16 additions & 8 deletions src/colibri/yosys/yosys.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,10 @@ export type e_schematic_result = {
empty: boolean
};

function removeEmptyCommands(cmd: string): string {
return cmd.replace(/; ;/g, ";");
}

export async function getSchematic(config: e_config, topTevel: string, sources: t_file[],
callback_stream: (stream_c: e_schematic_result) => void) : Promise<any>{

Expand Down Expand Up @@ -68,18 +72,19 @@ export function runYosysRaw(config: e_config, topTevel: string, sources: t_file[
const topLevelCmd = getToplevelCommand(topTevel);

// Command for custom arguments
const customArguments = config.schematic.general.args;
const customArguments = config.schematic.general.args.trim();

// Command for pre arguments
const preArguments = config.schematic.general.extra;

const outputPathFilename = config.schematic.general.backend === e_schematic_general_backend.yowasp ?
process_utils.createTempFileInHome("") : process_utils.create_temp_file("");

const cmd =
let cmd =
// eslint-disable-next-line max-len
`${preArguments} ${yosysPath} -p '${cmdFiles}; ${topLevelCmd}; proc; ${customArguments}; write_json ${outputPathFilename}; stat'`;

cmd = removeEmptyCommands(cmd);

const opt_exec = { cwd: get_directory(topTevel) };

const p = new Process();
Expand Down Expand Up @@ -122,19 +127,20 @@ export function runYosysGhdl(config: e_config, topTevel: string, sources: t_file
const topLevelCmd = getToplevelCommand(topTevel);

// Command for custom arguments
const customArguments = config.schematic.general.args;
const customArguments = config.schematic.general.args.trim();

// Command for pre arguments
const preArguments = config.schematic.general.extra;

// GHDL arguments
const ghdlArguments = config.schematic.general.args_ghdl;
const ghdlArguments = config.schematic.general.args_ghdl.trim();

const outputPathFilename = process_utils.createTempFileInHome("");

const cmd =
let cmd =
// eslint-disable-next-line max-len
`${preArguments} ${yosysPath} -m ghdl -p 'ghdl --std=08 -fsynopsys ${ghdlArguments} ${cmdFiles} --work=work -e ${topTevel}; ${topLevelCmd}; proc; ${customArguments}; write_json ${outputPathFilename}; stat'`;
cmd = removeEmptyCommands(cmd);

const opt_exec = { cwd: process_utils.get_home_directory() };

Expand Down Expand Up @@ -183,11 +189,13 @@ export async function runYosysStandalone(config: e_config, topTevel: string, sou
const topLevelCmd = getToplevelCommand(topTevel);

// Command for custom arguments
const customArguments = config.schematic.general.args;
const customArguments = config.schematic.general.args.trim();

const outputFilename = "schematic.json";

const cmd = `${cmdFiles}; ${topLevelCmd}; proc; ${customArguments}; write_json ${outputFilename}; stat`;
let cmd = `${cmdFiles}; ${topLevelCmd}; proc; ${customArguments}; write_json ${outputFilename}; stat`;
cmd = removeEmptyCommands(cmd);

const cmdList = ['-p'].concat([cmd]);

const result = await runYosys(cmdList, fileDeclaration, { decodeASCII: true });
Expand Down
3 changes: 2 additions & 1 deletion src/teroshdl/features/formatter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,8 @@ class Formatter {
const formatter_name = this.get_formatter_name();
const formater_config = this.get_formatter_config();
const formatter = new FormatterManager.Formatter();
const result = await formatter.format_from_code(formatter_name, code, formater_config);
const pypath = utils.getConfig(this.manager).general.general.pypath;
const result = await formatter.format_from_code(formatter_name, code, formater_config, pypath);
if (result.successful === false){
globalLogger.info("Error format code.");
globalLogger.debug(result.command);
Expand Down
2 changes: 1 addition & 1 deletion tests/formatter/s3sv.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ describe('s3sv', () => {
};

const formatter = new S3sv();
const result = await formatter.format_from_code(code, config);
const result = await formatter.format_from_code(code, config, "");

const output_path = path_lib.join(C_OUTPUT_BASE_PATH, 'sample.v');
save_file_sync(output_path, result.code_formatted);
Expand Down
Loading

0 comments on commit 85802fb

Please sign in to comment.