Search in sources :

Example 6 with ProgramFile

use of org.wso2.ballerinalang.programfile.CompiledBinaryFile.ProgramFile in project ballerina by ballerina-lang.

the class LauncherUtils method compile.

/**
 * Compile and get the executable program file.
 *
 * @param sourceRootPath Path to the source root
 * @param sourcePath Path to the source from the source root
 * @param offline Should the build call remote repos
 * @return Executable program
 */
public static ProgramFile compile(Path sourceRootPath, Path sourcePath, boolean offline) {
    CompilerContext context = new CompilerContext();
    CompilerOptions options = CompilerOptions.getInstance(context);
    options.put(PROJECT_DIR, sourceRootPath.toString());
    options.put(COMPILER_PHASE, CompilerPhase.CODE_GEN.toString());
    options.put(PRESERVE_WHITESPACE, "false");
    options.put(OFFLINE, Boolean.toString(offline));
    // compile
    Compiler compiler = Compiler.getInstance(context);
    BLangPackage entryPkgNode = compiler.compile(sourcePath.toString());
    CompiledBinaryFile.ProgramFile programFile = compiler.getExecutableProgram(entryPkgNode);
    if (programFile == null) {
        throw createLauncherException("compilation contains errors");
    }
    ProgramFile progFile = getExecutableProgram(programFile);
    progFile.setProgramFilePath(sourcePath);
    return progFile;
}
Also used : Compiler(org.wso2.ballerinalang.compiler.Compiler) BLangPackage(org.wso2.ballerinalang.compiler.tree.BLangPackage) CompiledBinaryFile(org.wso2.ballerinalang.programfile.CompiledBinaryFile) CompilerContext(org.wso2.ballerinalang.compiler.util.CompilerContext) CompilerOptions(org.wso2.ballerinalang.compiler.util.CompilerOptions) ProgramFile(org.ballerinalang.util.codegen.ProgramFile)

Example 7 with ProgramFile

use of org.wso2.ballerinalang.programfile.CompiledBinaryFile.ProgramFile in project ballerina by ballerina-lang.

the class BCompileUtil method compile.

public static CompileResult compile(String sourceRoot, String packageName, CompilerPhase compilerPhase, SourceDirectory sourceDirectory) {
    CompilerContext context = new CompilerContext();
    CompilerOptions options = CompilerOptions.getInstance(context);
    options.put(PROJECT_DIR, sourceRoot);
    options.put(COMPILER_PHASE, compilerPhase.toString());
    options.put(PRESERVE_WHITESPACE, "false");
    context.put(SourceDirectory.class, sourceDirectory);
    CompileResult comResult = new CompileResult();
    // catch errors
    DiagnosticListener listener = comResult::addDiagnostic;
    context.put(DiagnosticListener.class, listener);
    // compile
    Compiler compiler = Compiler.getInstance(context);
    BLangPackage packageNode = compiler.compile(packageName);
    comResult.setAST(packageNode);
    CompiledBinaryFile.ProgramFile programFile = compiler.getExecutableProgram(packageNode);
    if (programFile != null) {
        comResult.setProgFile(LauncherUtils.getExecutableProgram(programFile));
    }
    return comResult;
}
Also used : Compiler(org.wso2.ballerinalang.compiler.Compiler) BLangPackage(org.wso2.ballerinalang.compiler.tree.BLangPackage) CompiledBinaryFile(org.wso2.ballerinalang.programfile.CompiledBinaryFile) CompilerContext(org.wso2.ballerinalang.compiler.util.CompilerContext) CompilerOptions(org.wso2.ballerinalang.compiler.util.CompilerOptions) DiagnosticListener(org.ballerinalang.util.diagnostic.DiagnosticListener)

Example 8 with ProgramFile

use of org.wso2.ballerinalang.programfile.CompiledBinaryFile.ProgramFile in project ballerina by ballerina-lang.

the class ProgramFile method addAttributeInfo.

@Override
public void addAttributeInfo(AttributeInfo.Kind attributeKind, AttributeInfo attributeInfo) {
    attributeInfoMap.put(attributeKind, attributeInfo);
    if (attributeKind == AttributeInfo.Kind.VARIABLE_TYPE_COUNT_ATTRIBUTE) {
        // TODO Move this out of the program file to a program context.. Runtime representation of a program.
        // TODO ProgramFile is the static program data.
        VarTypeCountAttributeInfo varTypeCountAttribInfo = (VarTypeCountAttributeInfo) attributeInfo;
        int[] globalVarCount = varTypeCountAttribInfo.getVarTypeCount();
    // // Initialize global memory block
    // BStructType dummyType = new BStructType("", "");
    // dummyType.setFieldTypeCount(globalVarCount);
    // this.globalMemoryBlock = new BStruct(dummyType);
    }
}
Also used : VarTypeCountAttributeInfo(org.wso2.ballerinalang.programfile.attributes.VarTypeCountAttributeInfo)

Aggregations

Compiler (org.wso2.ballerinalang.compiler.Compiler)4 BLangPackage (org.wso2.ballerinalang.compiler.tree.BLangPackage)4 CompilerContext (org.wso2.ballerinalang.compiler.util.CompilerContext)4 CompilerOptions (org.wso2.ballerinalang.compiler.util.CompilerOptions)4 CompiledBinaryFile (org.wso2.ballerinalang.programfile.CompiledBinaryFile)4 DiagnosticListener (org.ballerinalang.util.diagnostic.DiagnosticListener)3 ProgramFile (org.ballerinalang.util.codegen.ProgramFile)2 ProgramFile (org.wso2.ballerinalang.programfile.CompiledBinaryFile.ProgramFile)2 ByteArrayInputStream (java.io.ByteArrayInputStream)1 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1 IOException (java.io.IOException)1 Path (java.nio.file.Path)1 BLangCompilerException (org.ballerinalang.compiler.BLangCompilerException)1 CompilerPlugin (org.ballerinalang.compiler.plugins.CompilerPlugin)1 Diagnostic (org.ballerinalang.util.diagnostic.Diagnostic)1 BPackageSymbol (org.wso2.ballerinalang.compiler.semantics.model.symbols.BPackageSymbol)1 PackageFile (org.wso2.ballerinalang.programfile.CompiledBinaryFile.PackageFile)1 VarTypeCountAttributeInfo (org.wso2.ballerinalang.programfile.attributes.VarTypeCountAttributeInfo)1