Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
509 changes: 71 additions & 438 deletions fontes/compilador-llvm.ts

Large diffs are not rendered by default.

8 changes: 8 additions & 0 deletions fontes/interfaces/entrada-funcao-modulo.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import llvm from '@designliquido/llvm-bindings';

// Entrada no mapaModulos: associa um FunctionCallee LLVM à assinatura da função.
export interface EntradaFuncaoModulo {
callee: llvm.FunctionCallee;
tiposParametros: string[];
tipoRetorno: string;
}
33 changes: 33 additions & 0 deletions fontes/registro-modulos/arquivos.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import llvm from '@designliquido/llvm-bindings';
import type { CompiladorLLVM } from '../compilador-llvm';
import { EntradaFuncaoModulo } from '../interfaces/entrada-funcao-modulo';

export function registrarModuloArquivos(this: CompiladorLLVM): void {
const ptr = this.montador.getPtrTy();
const i32 = this.montador.getInt32Ty();
const vazio = llvm.Type.getVoidTy(this.contexto);

const reg = (nomeCFunc: string, tiposParametros: string[], tipoRetorno: string): EntradaFuncaoModulo => {
const tiposLlvm = tiposParametros.map(t => t === 'inteiro' ? i32 : ptr);
const tipoRetLlvm = tipoRetorno === 'inteiro' ? i32 : tipoRetorno === 'vazio' ? vazio : ptr;
const tipo = llvm.FunctionType.get(tipoRetLlvm, tiposLlvm, false);
const callee = this.modulo.getOrInsertFunction(nomeCFunc, tipo);
return { callee, tiposParametros, tipoRetorno };
};

const funcoes = new Map<string, EntradaFuncaoModulo>([
['abrir', reg('delegua_arq_abrir', ['texto'], 'texto')],
['diretorioAtual', reg('delegua_arq_diretorio_atual', [], 'texto')],
['diretorioExiste', reg('delegua_arq_diretorio_existe', ['texto'], 'inteiro')],
['eArquivo', reg('delegua_arq_e_arquivo', ['texto'], 'inteiro')],
['eDiretorio', reg('delegua_arq_e_diretorio', ['texto'], 'inteiro')],
['paraTexto', reg('delegua_arq_para_texto', ['texto'], 'texto')],
['escrever', reg('delegua_arq_escrever', ['texto', 'texto'], 'vazio')],
['sobrescrever', reg('delegua_arq_sobrescrever', ['texto', 'texto'], 'vazio')],
['recarregar', reg('delegua_arq_recarregar', ['texto'], 'vazio')],
['instanciaEArquivo', reg('delegua_arq_instancia_e_arquivo', ['texto'], 'inteiro')],
['instanciaEDiretorio',reg('delegua_arq_instancia_e_diretorio', ['texto'], 'inteiro')],
]);

this.mapaModulos.set('arquivos', funcoes);
}
53 changes: 53 additions & 0 deletions fontes/registro-modulos/criptografia.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
import llvm from '@designliquido/llvm-bindings';
import type { CompiladorLLVM } from '../compilador-llvm';
import { EntradaFuncaoModulo } from '../interfaces/entrada-funcao-modulo';

export function registrarModuloCriptografia(this: CompiladorLLVM): void {
const ptr = this.montador.getPtrTy();
const i32 = this.montador.getInt32Ty();

const reg = (nomeCFunc: string, tiposParametros: string[]): EntradaFuncaoModulo => {
const tiposLlvm = tiposParametros.map(t => t === 'inteiro' ? i32 : ptr);
const tipo = llvm.FunctionType.get(ptr, tiposLlvm, false);
const callee = this.modulo.getOrInsertFunction(nomeCFunc, tipo);
return { callee, tiposParametros, tipoRetorno: 'texto' };
};
const regInt = (nomeCFunc: string, tiposParametros: string[]): EntradaFuncaoModulo => {
const tiposLlvm = tiposParametros.map(t => t === 'inteiro' ? i32 : ptr);
const tipo = llvm.FunctionType.get(i32, tiposLlvm, false);
const callee = this.modulo.getOrInsertFunction(nomeCFunc, tipo);
return { callee, tiposParametros, tipoRetorno: 'inteiro' };
};

const funcoes = new Map<string, EntradaFuncaoModulo>([
['cifrarXor', reg('delegua_cript_cifrar_xor', ['texto', 'texto'])],
['decifrarXor', reg('delegua_cript_decifrar_xor', ['texto', 'texto'])],
['rot13', reg('delegua_cript_rot13', ['texto'])],
['rotN', reg('delegua_cript_rot_n', ['texto', 'inteiro'])],
['decifrarRotN', reg('delegua_cript_decifrar_rot_n', ['texto', 'inteiro'])],
['codificarBase64', reg('delegua_cript_base64_codificar', ['texto'])],
['decodificarBase64', reg('delegua_cript_base64_decodificar', ['texto'])],
['criptografarEmMeninoDoAcre', reg('delegua_cript_menino_do_acre_cif', ['texto'])],
['descriptografarDeMeninoDoAcre',reg('delegua_cript_menino_do_acre_dec', ['texto'])],
['md5', reg('delegua_cript_md5', ['texto'])],
['sha1', reg('delegua_cript_sha1', ['texto'])],
['sha256', reg('delegua_cript_sha256', ['texto'])],
['sha512', reg('delegua_cript_sha512', ['texto'])],
['hmacSha256', reg('delegua_cript_hmac_sha256', ['texto', 'texto'])],
['hmacSha512', reg('delegua_cript_hmac_sha512', ['texto', 'texto'])],
['gerarBytesAleatorios', reg('delegua_cript_bytes_aleatorios', ['inteiro'])],
['gerarTextoAleatorio', reg('delegua_cript_texto_aleatorio', ['inteiro'])],
['gerarUuid', reg('delegua_cript_uuid', [])],
['derivarChavePbkdf2', reg('delegua_cript_pbkdf2', ['texto', 'texto', 'inteiro', 'inteiro'])],
['criptografarAes256', reg('delegua_cript_aes256_cifrar', ['texto', 'texto', 'texto'])],
['descriptografarAes256', reg('delegua_cript_aes256_decifrar', ['texto', 'texto', 'texto'])],
['gerarChavePrivadaRsa', reg('delegua_cript_rsa_gerar_privada', ['inteiro'])],
['derivarChavePublicaRsa', reg('delegua_cript_rsa_derivar_publica', ['texto'])],
['criptografarRsa', reg('delegua_cript_rsa_cifrar', ['texto', 'texto'])],
['descriptografarRsa', reg('delegua_cript_rsa_decifrar', ['texto', 'texto'])],
['assinarRsa', reg('delegua_cript_rsa_assinar', ['texto', 'texto'])],
['verificarAssinaturaRsa', regInt('delegua_cript_rsa_verificar', ['texto', 'texto', 'texto'])],
]);

this.mapaModulos.set('criptografia', funcoes);
}
31 changes: 31 additions & 0 deletions fontes/registro-modulos/csv.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import llvm from '@designliquido/llvm-bindings';
import type { CompiladorLLVM } from '../compilador-llvm';
import { EntradaFuncaoModulo } from '../interfaces/entrada-funcao-modulo';

export function registrarModuloCsv(this: CompiladorLLVM): void {
const ptr = this.montador.getPtrTy();
const i8 = llvm.Type.getInt8Ty(this.contexto);
const i32 = this.montador.getInt32Ty();
const vazio = llvm.Type.getVoidTy(this.contexto);

const reg = (nomeCFunc: string, tiposParametros: string[], tipoRetorno: string): EntradaFuncaoModulo => {
const tiposLlvm = tiposParametros.map(t => t === 'inteiro' ? i32 : t === 'char' ? i8 : ptr);
const tipoRetLlvm = tipoRetorno === 'inteiro' ? i32 : tipoRetorno === 'vazio' ? vazio : ptr;
const tipo = llvm.FunctionType.get(tipoRetLlvm, tiposLlvm, false);
const callee = this.modulo.getOrInsertFunction(nomeCFunc, tipo);
return { callee, tiposParametros, tipoRetorno };
};

const funcoes = new Map<string, EntradaFuncaoModulo>([
['textoParaObjetoCsv', reg('delegua_csv_texto_para_tabela', ['texto', 'inteiro'], 'texto')],
['objetoCsvParaTexto', reg('delegua_csv_tabela_para_texto', ['texto', 'inteiro'], 'texto')],
['lerCsv', reg('delegua_csv_ler', ['texto', 'inteiro'], 'texto')],
['escreverCsv', reg('delegua_csv_escrever', ['texto', 'texto', 'inteiro'], 'vazio')],
['totalLinhas', reg('delegua_csv_total_linhas', ['texto'], 'inteiro')],
['totalColunas', reg('delegua_csv_total_colunas', ['texto'], 'inteiro')],
['obterCelula', reg('delegua_csv_obter_celula', ['texto', 'inteiro', 'inteiro'],'texto')],
['liberar', reg('delegua_csv_liberar', ['texto'], 'vazio')],
]);

this.mapaModulos.set('csv', funcoes);
}
44 changes: 44 additions & 0 deletions fontes/registro-modulos/dados.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
import llvm from '@designliquido/llvm-bindings';
import type { CompiladorLLVM } from '../compilador-llvm';
import { EntradaFuncaoModulo } from '../interfaces/entrada-funcao-modulo';

export function registrarModuloDados(this: CompiladorLLVM): void {
const ptr = this.montador.getPtrTy();
const i32 = this.montador.getInt32Ty();
const d = this.montador.getDoubleTy();

const reg = (nomeCFunc: string, tiposParametros: string[]): EntradaFuncaoModulo => {
const tiposLlvm = tiposParametros.map(t => t === 'inteiro' ? i32 : ptr);
const tipo = llvm.FunctionType.get(ptr, tiposLlvm, false);
const callee = this.modulo.getOrInsertFunction(nomeCFunc, tipo);
return { callee, tiposParametros, tipoRetorno: 'texto' };
};
const regInt = (nomeCFunc: string, tiposParametros: string[]): EntradaFuncaoModulo => {
const tiposLlvm = tiposParametros.map(t => t === 'inteiro' ? i32 : ptr);
const tipo = llvm.FunctionType.get(i32, tiposLlvm, false);
const callee = this.modulo.getOrInsertFunction(nomeCFunc, tipo);
return { callee, tiposParametros, tipoRetorno: 'inteiro' };
};
const regDouble = (nomeCFunc: string, tiposParametros: string[]): EntradaFuncaoModulo => {
const tiposLlvm = tiposParametros.map(t => t === 'inteiro' ? i32 : (t === 'numero' ? d : ptr));
const tipo = llvm.FunctionType.get(d, tiposLlvm, false);
const callee = this.modulo.getOrInsertFunction(nomeCFunc, tipo);
return { callee, tiposParametros, tipoRetorno: 'numero' };
};

const funcoes = new Map<string, EntradaFuncaoModulo>([
['lerCSV', reg('delegua_dados_ler_csv', ['texto'])],
['cabeca', reg('delegua_dados_cabeca', ['texto', 'inteiro'])],
['cauda', reg('delegua_dados_cauda', ['texto', 'inteiro'])],
['info', reg('delegua_dados_info', ['texto'])],
['paraTexto', reg('delegua_dados_para_texto', ['texto'])],
['removerNulo', reg('delegua_dados_remover_nulo', ['texto'])],
['selecionarColuna', reg('delegua_dados_selecionar_coluna', ['texto', 'texto'])],
['serieMax', regDouble('delegua_dados_serie_max', ['texto'])],
['serieMin', regDouble('delegua_dados_serie_min', ['texto'])],
['serieMedia', regDouble('delegua_dados_serie_media', ['texto'])],
['serieTamanho', regInt('delegua_dados_serie_tamanho', ['texto'])],
]);

this.mapaModulos.set('dados', funcoes);
}
30 changes: 30 additions & 0 deletions fontes/registro-modulos/estatistica.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import llvm from '@designliquido/llvm-bindings';
import type { CompiladorLLVM } from '../compilador-llvm';
import { EntradaFuncaoModulo } from '../interfaces/entrada-funcao-modulo';

export function registrarModuloEstatistica(this: CompiladorLLVM): void {
const d = this.montador.getDoubleTy();
const ptr = this.montador.getPtrTy();

const reg1 = (nomeCFunc: string): EntradaFuncaoModulo => {
const tipo = llvm.FunctionType.get(d, [ptr], false);
const callee = this.modulo.getOrInsertFunction(nomeCFunc, tipo);
return { callee, tiposParametros: ['vetor'], tipoRetorno: 'numero' };
};
const reg2 = (nomeCFunc: string): EntradaFuncaoModulo => {
const tipo = llvm.FunctionType.get(d, [ptr, ptr], false);
const callee = this.modulo.getOrInsertFunction(nomeCFunc, tipo);
return { callee, tiposParametros: ['vetor', 'vetor'], tipoRetorno: 'numero' };
};

const funcoes = new Map<string, EntradaFuncaoModulo>([
['max', reg1('delegua_est_max')],
['min', reg1('delegua_est_min')],
['media', reg1('delegua_est_media')],
['mediana', reg1('delegua_est_mediana')],
['ve', reg1('delegua_est_variancia')],
['covariancia', reg2('delegua_est_covariancia')],
]);

this.mapaModulos.set('estatistica', funcoes);
}
23 changes: 23 additions & 0 deletions fontes/registro-modulos/fisica.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import llvm from '@designliquido/llvm-bindings';
import type { CompiladorLLVM } from '../compilador-llvm';
import { EntradaFuncaoModulo } from '../interfaces/entrada-funcao-modulo';

export function registrarModuloFisica(this: CompiladorLLVM): void {
const d = this.montador.getDoubleTy();

const reg = (nomeCFunc: string, tiposParametros: string[]): EntradaFuncaoModulo => {
const tiposLlvm = tiposParametros.map(() => d);
const tipo = llvm.FunctionType.get(d, tiposLlvm, false);
const callee = this.modulo.getOrInsertFunction(nomeCFunc, tipo);
return { callee, tiposParametros, tipoRetorno: 'numero' };
};

const funcoes = new Map<string, EntradaFuncaoModulo>([
['velocidadeMedia', reg('delegua_fis_velocidade_media', ['numero', 'numero'])],
['deltaS', reg('delegua_fis_delta_s', ['numero', 'numero'])],
['deltaT', reg('delegua_fis_delta_t', ['numero', 'numero'])],
['aceleracao', reg('delegua_fis_aceleracao', ['numero', 'numero', 'numero', 'numero'])],
]);

this.mapaModulos.set('fisica', funcoes);
}
34 changes: 34 additions & 0 deletions fontes/registro-modulos/http.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import llvm from '@designliquido/llvm-bindings';
import type { CompiladorLLVM } from '../compilador-llvm';
import { EntradaFuncaoModulo } from '../interfaces/entrada-funcao-modulo';

export function registrarModuloHttp(this: CompiladorLLVM): void {
const ptr = this.montador.getPtrTy();
const i32 = this.montador.getInt32Ty();
const vazio = llvm.Type.getVoidTy(this.contexto);

const reg = (nomeCFunc: string, tiposParametros: string[], tipoRetorno: string): EntradaFuncaoModulo => {
const tiposLlvm = tiposParametros.map(t => t === 'inteiro' ? i32 : ptr);
const tipoRetLlvm = tipoRetorno === 'inteiro' ? i32 : tipoRetorno === 'vazio' ? vazio : ptr;
const tipo = llvm.FunctionType.get(tipoRetLlvm, tiposLlvm, false);
const callee = this.modulo.getOrInsertFunction(nomeCFunc, tipo);
return { callee, tiposParametros, tipoRetorno };
};

const funcoes = new Map<string, EntradaFuncaoModulo>([
['novoClienteHttp', reg('delegua_http_novo_cliente', ['texto', 'inteiro'], 'texto')],
['adicionarCabecalho', reg('delegua_http_add_cabecalho', ['texto', 'texto'], 'vazio')],
['requisicaoGet', reg('delegua_http_get', ['texto', 'texto'], 'texto')],
['requisicaoPost', reg('delegua_http_post', ['texto', 'texto', 'texto'], 'texto')],
['requisicaoPut', reg('delegua_http_put', ['texto', 'texto', 'texto'], 'texto')],
['requisicaoDelete', reg('delegua_http_delete', ['texto', 'texto'], 'texto')],
['requisicaoPatch', reg('delegua_http_patch', ['texto', 'texto', 'texto'], 'texto')],
['codigoStatus', reg('delegua_http_codigo_status', ['texto'], 'inteiro')],
['dados', reg('delegua_http_dados', ['texto'], 'texto')],
['mensagemStatus', reg('delegua_http_mensagem', ['texto'], 'texto')],
['liberarResposta', reg('delegua_http_liberar_resp', ['texto'], 'vazio')],
['liberarCliente', reg('delegua_http_liberar_cliente',['texto'], 'vazio')],
]);

this.mapaModulos.set('http', funcoes);
}
9 changes: 9 additions & 0 deletions fontes/registro-modulos/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
export { registrarModuloMatematica } from './matematica';
export { registrarModuloFisica } from './fisica';
export { registrarModuloEstatistica } from './estatistica';
export { registrarModuloArquivos } from './arquivos';
export { registrarModuloCsv } from './csv';
export { registrarModuloJson } from './json';
export { registrarModuloHttp } from './http';
export { registrarModuloCriptografia } from './criptografia';
export { registrarModuloDados } from './dados';
33 changes: 33 additions & 0 deletions fontes/registro-modulos/json.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import llvm from '@designliquido/llvm-bindings';
import type { CompiladorLLVM } from '../compilador-llvm';
import { EntradaFuncaoModulo } from '../interfaces/entrada-funcao-modulo';

export function registrarModuloJson(this: CompiladorLLVM): void {
const ptr = this.montador.getPtrTy();
const i32 = this.montador.getInt32Ty();
const d = this.montador.getDoubleTy();
const vazio = llvm.Type.getVoidTy(this.contexto);

const reg = (nomeCFunc: string, tiposParametros: string[], tipoRetorno: string): EntradaFuncaoModulo => {
const tiposLlvm = tiposParametros.map(t => t === 'inteiro' ? i32 : ptr);
const tipoRetLlvm = tipoRetorno === 'inteiro' ? i32 : tipoRetorno === 'numero' ? d : tipoRetorno === 'vazio' ? vazio : ptr;
const tipo = llvm.FunctionType.get(tipoRetLlvm, tiposLlvm, false);
const callee = this.modulo.getOrInsertFunction(nomeCFunc, tipo);
return { callee, tiposParametros, tipoRetorno };
};

const funcoes = new Map<string, EntradaFuncaoModulo>([
['textoParaJson', reg('delegua_json_texto_para_objeto', ['texto'], 'texto')],
['objetoParaTextoJson', reg('delegua_json_objeto_para_texto', ['texto'], 'texto')],
['importarArquivoJson', reg('delegua_json_importar_arquivo', ['texto'], 'texto')],
['exportarObjetoParaArquivoJson', reg('delegua_json_exportar_arquivo', ['texto', 'texto'], 'vazio')],
['obterCampo', reg('delegua_json_obter_campo', ['texto', 'texto'], 'texto')],
['obterItem', reg('delegua_json_obter_item', ['texto', 'inteiro'],'texto')],
['tamanho', reg('delegua_json_tamanho', ['texto'], 'inteiro')],
['valorTexto', reg('delegua_json_valor_texto', ['texto'], 'texto')],
['valorNumero', reg('delegua_json_valor_numero', ['texto'], 'numero')],
['liberar', reg('delegua_json_liberar', ['texto'], 'vazio')],
]);

this.mapaModulos.set('json', funcoes);
}
Loading
Loading