Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

llvm-js/llvm-project

Folders and files

NameName
Last commit message
Last commit date

Latest commit

History

20 Commits

Repository files navigation

LLVM.JS (llvm.js)

Install

npm

npm i llvm.js

Note

URL npm

git

git clone https://github.com/llvm-js/llvm-project.git

Require

const llvm = require('llvm.js/llvm');
const exceptions = require('llvm.js/exceptions');
const expression = require('llvm.js/expression');
const codeGen = require('llvm.js/codegen');

Quick start

const llvm = require('llvm.js/llvm');
const language = new llvm.llvm();
// config (Optional)
let file_c = fs.readFileSync(src).toString('utf8').split('\n');
const lexer = new llvm.Lexer();
let ast = lexer.lexer(file_c);
// console.log(ast); // example
language.run(); // view the characteristics of the programming language and the project 

REPL

language.repl((data) => {
 console.log(data);
});

Example JavaScript compile

Windows

cd ./tests
node language.js

Input file:

// JavaScript --> AsmX MachineCode
let text = "Hello MachineCode AsmX!";
const example = 'this constant section';
// optimized
console.log('call 1');
console.log('call 2');

Output file:

segment variable:
 text: "Hello MachineCode AsmX!"
segment const:
 example: 'this constant section'
print:
 push 1ドル
 call 0x04
main code:
 mov 1ドル 'call 1'
 func print
 mov 1ドル 'call 2'
 func print

An example of using llvm.js in RunKit + npm

JavaScript code:

const fs = require('fs');
const Expression = require('llvm.js/expression');
const codeGen = require('llvm.js/codegen');
let expression = new Expression('2 + 4');
console.log(expression.answer());
codeGen.genSLFunction('print');
codeGen.callFunction('print', '1');
codeGen.codegen('output');
fs.readFileSync('output.bytex').toString('utf8');

Output:

6
print:
 push 1ドル
 call 0x04
main code:
 mov 1ドル 1
 func print

Documentation

  • Config
    • set(object: IConfig)
    • setCommentLine(string: string)
    • forbiddenSymbol(char: string)
    • setCommentBlock(string: string)
    • setCommentBlock(string: string[])
    • clearCommentLine( )
    • clearCommentBlock( )
    • setSupportNumberSnake(bool: boolean)
    • clearSupportNumberSnake( )
  • Grammar
    • verifyGrammar(current: number, ast: Array, grammar: Array, strict: boolean): object
    • verifyGrammarNoStrict(current: number, ast: Array, grammar: Array): object

About

🚀 A powerful tool for creating programming languages, interpreters/compilers.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

AltStyle によって変換されたページ (->オリジナル) /