Commit 6e8f53ca authored by Nathan Pittet's avatar Nathan Pittet

wip: port to new ghdl version

parent a09ca352
......@@ -47,6 +47,6 @@ setup(
packages=['vhdllint', 'vhdllint.filerules', 'vhdllint.lexrules',
'vhdllint.semrules', 'vhdllint.syntaxrules',
'vhdllint.synthrules'],
install_requires=['libghdl'],
install_requires=['pyGHDL'],
**kwargs
)
import libghdl.thin as thin
import libghdl.thinutils as thinutils
import libghdl.tokens as tokens
import libghdl.iirs as iirs
from utils import Location, TokLocation, fatal
from filerules import FileRule
from lexrules import LexRule
from syntaxrules import SyntaxRule, SyntaxNodeRule
from semrules import SemRule, SemNodeRule
from synthrules import SynthesisRule
import pyGHDL.libghdl.vhdl.tokens as tokens
import pyGHDL.libghdl.vhdl.nodes as nodes
import pyGHDL.libghdl.libraries as libraries
import pyGHDL.libghdl.vhdl.scanner as scanner
from pyGHDL.libghdl.utils import chain_iter, nodes_iter
import pyGHDL.libghdl.vhdl.nodes
from vhdllint.utils import Location, TokLocation, fatal
from vhdllint.filerules import FileRule
from vhdllint.lexrules import LexRule
from vhdllint.syntaxrules import SyntaxRule, SyntaxNodeRule
from vhdllint.semrules import SemRule, SemNodeRule
from vhdllint.synthrules import SynthesisRule
import ctypes
import os.path
import sys
......@@ -116,26 +118,26 @@ class RulesExec(object):
r.check(loc, flines)
# Then tokens
thin.Scanner.Flag_Comment.value = True
scanner.Flag_Comment.value = True
for input in inputs:
if 'import' not in input.props:
thin.Scanner.Set_File(input.fe)
scanner.Set_File(input.fe)
filebuf = input.filebuf
while True:
thin.Scanner.Scan()
tok = thin.Scanner.Current_Token.value
scanner.Scan()
tok = scanner.Current_Token.value
loc = TokLocation(input.filename,
thin.Scanner.Get_Current_Line(),
thin.Scanner.Get_Token_Column(),
thin.Scanner.Get_Token_Position(),
thin.Scanner.Get_Position())
scanner.Get_Current_Line(),
scanner.Get_Token_Column(),
scanner.Get_Token_Position(),
scanner.Get_Position())
if tok == tokens.Tok.Comment:
input.comments[loc.line] = (loc.start, loc.end)
for r in self._lex_rules:
r.check(loc, filebuf, tok)
if tok == tokens.Tok.Eof:
break
thin.Scanner.Close_File()
scanner.Close_File()
if not (self._syntax_rules or self._syntax_node_rules
or self._sem_rules or self._sem_node_rules
or self._synth_rules):
......@@ -143,27 +145,27 @@ class RulesExec(object):
# Then syntax
# The parser doesn't handle comments
thin.Scanner.Flag_Comment.value = False
scanner.Flag_Comment.value = False
# Keep extra locations
thin.Flags.Flag_Elocations.value = True
# Keep all parenthesis
thin.Parse.Flag_Parse_Parenthesis.value = True
# Be sure to initialize std and work (and only once).
# Humm, not very elegant.
if thin.Get_Libraries_Chain() == thin.Null_Iir:
if thin.Get_Libraries_Chain() == nodes.Null_Iir:
thin.analyze_init()
for input in inputs:
thin.Scanner.Set_File(input.fe)
scanner.Set_File(input.fe)
loc = Location(input.filename)
input.ast = thin.Parse.Parse_Design_File()
if 'import' not in input.props:
for r in self._syntax_rules:
r.check(input, input.ast)
if self._syntax_node_rules:
for n in thinutils.nodes_iter(input.ast):
for n in nodes_iter(input.ast):
for r in self._syntax_node_rules:
r.check(loc, n)
thin.Scanner.Close_File()
scanner.Close_File()
# Then semantic
if self._sem_rules or self._sem_node_rules or self._synth_rules:
......@@ -174,11 +176,11 @@ class RulesExec(object):
# First add all units in the work library, so that they they are
# known by the analyzer.
for input in inputs:
unit_ast = iirs.Get_First_Design_Unit(input.ast)
while unit_ast != thin.Null_Iir:
unit_ast = Get_First_Design_Unit(input.ast)
while unit_ast != nodes.Null_Iir:
# Detach the unit from its design file
next_unit_ast = iirs.Get_Chain(unit_ast)
iirs.Set_Chain(unit_ast, thin.Null_Iir)
next_unit_ast = Get_Chain(unit_ast)
Set_Chain(unit_ast, nodes.Null_Iir)
# Add
thin.Add_Design_Unit_Into_Library(unit_ast, False)
input.units_ast.append(unit_ast)
......@@ -187,26 +189,26 @@ class RulesExec(object):
for input in inputs:
if 'import' not in input.props:
for unit in input.units_ast:
if iirs.Get_Library_Unit(unit) == thin.Null_Iir:
if Get_Library_Unit(unit) == nodes.Null_Iir:
# Over-written.
# FIXME: remove from the list ?
continue
# Be sure the unit was analyzed. It could have been
# already analyzed if referenced. And a unit cannot be
# analyzed twice.
if iirs.Get_Date_State(unit) == iirs.Date_State.Parse:
if Get_Date_State(unit) == Date_State.Parse:
thin.Finish_Compilation(unit, False)
iirs.Set_Date_State(unit, iirs.Date_State.Analyze)
Set_Date_State(unit, Date_State.Analyze)
for r in self._sem_rules:
r.check(input, unit)
for n in thinutils.nodes_iter(unit):
for n in nodes_iter(unit):
for r in self._sem_node_rules:
r.check(input, n)
for input in inputs:
if 'synth' in input.props:
for unit in input.units_ast:
if iirs.Get_Library_Unit(unit) == thin.Null_Iir:
if Get_Library_Unit(unit) == nodes.Null_Iir:
# Over-written.
continue
for r in self._synth_rules:
......@@ -271,10 +273,10 @@ class TestRun(RulesExec):
os.path.join(basedir, f), files)
# Be sure the work library is empty. This is brut force.
work = thin.Work_Library.value
if work != thin.Null_Iir:
for f in thinutils.chain_iter(iirs.Get_Design_File_Chain(work)):
thin.Purge_Design_File(f)
iirs.Set_Design_File_Chain(work, thin.Null_Iir)
if work != nodes.Null_Iir:
for f in chain_iter(Get_Design_File_Chain(work)):
libraries.Purge_Design_File(f)
Set_Design_File_Chain(work, nodes.Null_Iir)
self.add(rule)
self.execute(files)
if not self.is_ok():
......
import sys
import libghdl.iirs as iirs
import libghdl.thin as thin
import pyGHDL.libghdl.vhdl.nodes
def Location_To_File_Line_Col(loc):
......@@ -27,7 +26,7 @@ class Location(object):
@classmethod
def from_node(cls, n):
return Location.from_location(iirs.Get_Location(n))
return Location.from_location(Get_Location(n))
class TokLocation(Location):
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment