Search in sources :

Example 6 with FbasicType

use of claw.tatsu.xcodeml.xnode.fortran.FbasicType in project claw-compiler by C2SM-RCM.

the class XtypeTable method readTable.

/**
 * Read the type table.
 */
private void readTable() {
    List<Xnode> elements = children();
    for (Xnode n : elements) {
        switch(n.opcode()) {
            case F_BASIC_TYPE:
                FbasicType bt = new FbasicType(n);
                _table.put(bt.getType(), bt);
                break;
            case F_FUNCTION_TYPE:
                FfunctionType ft = new FfunctionType(n);
                _table.put(ft.getType(), ft);
                break;
            case F_STRUCT_TYPE:
                FstructType st = new FstructType(n);
                _table.put(st.getType(), st);
                break;
            default:
                break;
        }
    }
}
Also used : FfunctionType(claw.tatsu.xcodeml.xnode.fortran.FfunctionType) FstructType(claw.tatsu.xcodeml.xnode.fortran.FstructType) FbasicType(claw.tatsu.xcodeml.xnode.fortran.FbasicType)

Example 7 with FbasicType

use of claw.tatsu.xcodeml.xnode.fortran.FbasicType in project claw-compiler by C2SM-RCM.

the class XmlHelper method createXbasicTypeFromString.

public static FbasicType createXbasicTypeFromString(String xml) {
    Xnode n = XmlHelper.getElementFromString(xml);
    assertNotNull(n);
    return new FbasicType(n);
}
Also used : Xnode(claw.tatsu.xcodeml.xnode.common.Xnode) FbasicType(claw.tatsu.xcodeml.xnode.fortran.FbasicType)

Example 8 with FbasicType

use of claw.tatsu.xcodeml.xnode.fortran.FbasicType in project claw-compiler by C2SM-RCM.

the class Kcaching method generateInferredOffsets.

/**
 * Generate correct offset inferred by the dimension of the variable.
 *
 * @param xcodeml The current program
 * @param fctDef  The function definition which holds the variable information.
 * @param var     The variable on which the offset are inferred.
 * @return List of integer representing the offset for the given variable.
 * @throws IllegalTransformationException if symbol id is not found.
 */
private List<Integer> generateInferredOffsets(XcodeProgram xcodeml, FfunctionDefinition fctDef, String var) throws IllegalTransformationException {
    Xid id = fctDef.getSymbolTable().get(var);
    if (id == null) {
        throw new IllegalTransformationException("Variable " + var + " defined in the data clause has not been found", _claw.getPragma().lineNo());
    }
    FbasicType basicType = xcodeml.getTypeTable().getBasicType(id);
    int dim = basicType.getDimensions();
    List<Integer> offsets = new ArrayList<>();
    for (int i = 0; i < dim; ++i) {
        offsets.add(0);
    }
    return offsets;
}
Also used : IllegalTransformationException(claw.tatsu.xcodeml.exception.IllegalTransformationException) ArrayList(java.util.ArrayList) FbasicType(claw.tatsu.xcodeml.xnode.fortran.FbasicType)

Example 9 with FbasicType

use of claw.tatsu.xcodeml.xnode.fortran.FbasicType in project claw-compiler by C2SM-RCM.

the class Kcaching method generateCacheVarAndAssignStmt.

/**
 * Generate the necessary intermediate code to create the new cache variable and
 * set its assignment.
 *
 * @param xcodeml The current program.
 * @param var     The original variable name.
 * @param type    The original variable type.
 * @param fctDef  The function definition holding the variable.
 * @param rhs     The element that will be set as the rhs of the assignment.
 * @param stmt    The assign statement including the array ref.
 * @return The new created Xvar element.
 */
private Xnode generateCacheVarAndAssignStmt(XcodeProgram xcodeml, String var, String type, FfunctionDefinition fctDef, Xnode rhs, Xnode stmt) {
    // TODO getType
    FbasicType t = xcodeml.getTypeTable().getBasicType(type);
    if (t.getIntent() != null || t.isAllocatable()) {
        // Type has an intent ... duplicate it and remove it
        FbasicType newType = t.cloneNode();
        type = xcodeml.getTypeTable().generateHash(FortranType.REAL);
        newType.setType(type);
        newType.removeAttribute(Xattr.INTENT);
        newType.removeAttribute(Xattr.IS_ALLOCATABLE);
        FbasicType ref = xcodeml.getTypeTable().getBasicType(newType.getRef());
        if (ref != null && (ref.isAllocatable() || ref.hasIntent())) {
            // TODO is there several level to reach ref ? Check if ref is Freal ...
            FbasicType newRef = ref.cloneNode();
            // TODO generate appropriate type
            String refType = xcodeml.getTypeTable().generateHash(FortranType.REAL);
            newRef.setType(refType);
            newRef.removeAttribute(Xattr.INTENT);
            newRef.removeAttribute(Xattr.IS_ALLOCATABLE);
            newType.setRef(refType);
            xcodeml.getTypeTable().add(newRef);
        }
        xcodeml.getTypeTable().add(newType);
    }
    String cacheName = generateNameWithOffsetInfo(var, _claw.getOffsets());
    // 2.2 inject a new entry in the symbol table
    if (!fctDef.getSymbolTable().contains(cacheName)) {
        Xid cacheVarId = xcodeml.createId(type, XstorageClass.F_LOCAL, cacheName);
        fctDef.getSymbolTable().add(cacheVarId, false);
    }
    // 2.3 inject a new entry in the declaration table
    if (!fctDef.getDeclarationTable().contains(cacheName)) {
        Xnode cacheVarDecl = xcodeml.createVarDecl(type, cacheName);
        fctDef.getDeclarationTable().add(cacheVarDecl);
    }
    // 2.4 Prepare the new variable that is used for caching
    Xnode cacheVar = xcodeml.createVar(type, cacheName, Xscope.LOCAL);
    if (stmt == null) {
        Xnode cache1 = xcodeml.createNode(Xcode.F_ASSIGN_STATEMENT);
        cache1.append(cacheVar, false);
        cache1.append(rhs, true);
        _claw.getPragma().insertAfter(cache1);
    } else {
        /*
             * We replace an assignment of type A = B by cache_A = B A = cache_A
             */
        Xnode cache1 = xcodeml.createNode(Xcode.F_ASSIGN_STATEMENT);
        cache1.append(cacheVar);
        cache1.append(stmt.child(1), true);
        Xnode cache2 = xcodeml.createNode(Xcode.F_ASSIGN_STATEMENT);
        cache2.append(stmt.child(0), true);
        cache2.append(cacheVar, true);
        stmt.insertAfter(cache1);
        cache1.insertAfter(cache2);
    }
    return cacheVar;
}
Also used : FbasicType(claw.tatsu.xcodeml.xnode.fortran.FbasicType)

Example 10 with FbasicType

use of claw.tatsu.xcodeml.xnode.fortran.FbasicType in project claw-compiler by C2SM-RCM.

the class Xmod method updateSignature.

/**
 * Update the function signature in the module file to reflects local changes.
 *
 * @param moduleName    Xmod name to update.
 * @param xcodeml       Current XcodeML file unit.
 * @param fctDef        Function definition that has been changed.
 * @param fctType       Function type that has been changed.
 * @param importFctType If true, import the functionType.
 * @throws IllegalTransformationException If the module file or the function
 *                                        cannot be located
 */
public static void updateSignature(String moduleName, XcodeProgram xcodeml, FfunctionDefinition fctDef, FfunctionType fctType, boolean importFctType) throws IllegalTransformationException {
    final Context context = xcodeml.context();
    FortranModule mod;
    if (context.getModuleCache().isModuleLoaded(moduleName)) {
        mod = context.getModuleCache().get(moduleName);
    } else {
        mod = fctDef.findContainingXmod(context);
        if (mod == null) {
            throw new IllegalTransformationException("Unable to locate module file for: " + moduleName);
        }
        context.getModuleCache().add(moduleName, mod);
    }
    FfunctionType fctTypeMod;
    if (importFctType) {
        // TODO should be part of XcodeML
        Xnode importedNode = mod.importNode(fctType);
        mod.getTypeTable().append(importedNode);
        FfunctionType importedFctType = new FfunctionType(importedNode);
        Xid importedFctTypeId = mod.createId(importedFctType.getType(), XstorageClass.F_FUNC, fctDef.getName());
        mod.getIdentifiers().add(importedFctTypeId);
        // check if params need to be imported as well
        if (!importedFctType.getParameters().isEmpty()) {
            for (Xnode param : importedFctType.getParameters()) {
                mod.importType(xcodeml, param.getType());
            }
        }
        return;
    } else {
        fctTypeMod = mod.findFunctionType(fctDef.getName());
    }
    if (fctTypeMod == null) {
        /*
             * Workaround for a bug in OMNI Compiler. Look at test case claw/abstraction12.
             * In this test case, the XcodeML/F intermediate representation for the function
             * call points to a FfunctionType element with no parameters. Thus, we have to
             * matchSeq the correct FfunctionType for the same function/subroutine with the
             * same name in the module symbol table.
             */
        String errorMsg = "Unable to locate fct " + fctDef.getName() + " in module " + moduleName;
        /*
             * If not, try to matchSeq the correct FfunctionType in the module definitions
             */
        fctTypeMod = mod.findFunctionType(fctDef.getName());
        if (fctTypeMod == null) {
            throw new IllegalTransformationException(errorMsg);
        }
    }
    FbasicType modIntTypeIntentIn = mod.createBasicType(FortranType.INTEGER, Intent.IN);
    mod.getTypeTable().add(modIntTypeIntentIn);
    List<Xnode> paramsLocal = fctType.getParameters();
    List<Xnode> paramsMod = fctTypeMod.getParameters();
    if (paramsLocal.size() < paramsMod.size()) {
        throw new IllegalTransformationException("Local function has more parameters than module counterpart.");
    }
    for (int i = 0; i < paramsLocal.size(); ++i) {
        Xnode pLocal = paramsLocal.get(i);
        // Number of parameters in the module function as been
        if (pLocal.getBooleanAttribute(Xattr.IS_INSERTED)) {
            // new parameter
            Xnode param = mod.createAndAddParamIfNotExists(pLocal.value(), modIntTypeIntentIn.getType(), fctTypeMod);
            if (param != null) {
                param.setBooleanAttribute(Xattr.IS_INSERTED, true);
            }
        } else {
            Xnode pMod = paramsMod.get(i);
            String localType = pLocal.getType();
            String modType = pMod.getType();
            if (!localType.equals(modType)) {
                // Param has been updated so have to replicate the change to mod file
                FbasicType lType = xcodeml.getTypeTable().getBasicType(pLocal);
                FbasicType crtType = mod.getTypeTable().getBasicType(pMod);
                if (pLocal.hasAttribute(Xattr.PROMOTION_INFO)) {
                    PromotionInfo promotionInfo = new PromotionInfo();
                    promotionInfo.readDimensionsFromString(pLocal.getAttribute(Xattr.PROMOTION_INFO));
                    if (lType.isArray()) {
                        FbasicType newType = Type.duplicateWithDimension(lType, crtType, xcodeml, mod, promotionInfo.getDimensions());
                        pMod.setType(newType);
                    }
                }
            }
            // Copy the promotion information
            pLocal.copyAttribute(pMod, Xattr.PROMOTION_INFO);
        }
    }
    // Sync attribute between local fct type and module fct type.
    for (Xattr attr : SYNCABLE_ATTR) {
        fctType.syncBooleanAttribute(fctTypeMod, attr);
    }
}
Also used : Context(claw.tatsu.common.Context) Xnode(claw.tatsu.xcodeml.xnode.common.Xnode) FortranModule(claw.tatsu.xcodeml.xnode.fortran.FortranModule) Xid(claw.tatsu.xcodeml.xnode.common.Xid) FfunctionType(claw.tatsu.xcodeml.xnode.fortran.FfunctionType) IllegalTransformationException(claw.tatsu.xcodeml.exception.IllegalTransformationException) PromotionInfo(claw.tatsu.xcodeml.abstraction.PromotionInfo) Xattr(claw.tatsu.xcodeml.xnode.common.Xattr) FbasicType(claw.tatsu.xcodeml.xnode.fortran.FbasicType)

Aggregations

FbasicType (claw.tatsu.xcodeml.xnode.fortran.FbasicType)17 Xnode (claw.tatsu.xcodeml.xnode.common.Xnode)8 IllegalTransformationException (claw.tatsu.xcodeml.exception.IllegalTransformationException)7 PromotionInfo (claw.tatsu.xcodeml.abstraction.PromotionInfo)4 Xid (claw.tatsu.xcodeml.xnode.common.Xid)4 FfunctionType (claw.tatsu.xcodeml.xnode.fortran.FfunctionType)4 Context (claw.tatsu.common.Context)3 DimensionDefinition (claw.tatsu.xcodeml.abstraction.DimensionDefinition)2 FfunctionDefinition (claw.tatsu.xcodeml.xnode.fortran.FfunctionDefinition)2 ClawTranslator (claw.wani.x2t.translator.ClawTranslator)2 ArrayList (java.util.ArrayList)2 Xblock (claw.tatsu.xcodeml.abstraction.Xblock)1 Xattr (claw.tatsu.xcodeml.xnode.common.Xattr)1 XdeclTable (claw.tatsu.xcodeml.xnode.common.XdeclTable)1 XsymbolTable (claw.tatsu.xcodeml.xnode.common.XsymbolTable)1 FmoduleDefinition (claw.tatsu.xcodeml.xnode.fortran.FmoduleDefinition)1 FortranModule (claw.tatsu.xcodeml.xnode.fortran.FortranModule)1 FstructType (claw.tatsu.xcodeml.xnode.fortran.FstructType)1 ClawMapping (claw.wani.language.ClawMapping)1 ClawMappingVar (claw.wani.language.ClawMappingVar)1